b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #include <StepSelect_WorkLibrary.ixx> |
19 | |
20 | #include <sys/stat.h> |
21 | #include <errno.h> |
22 | |
23 | #include <StepData_Protocol.hxx> |
24 | #include <StepData_StepModel.hxx> |
25 | #include <StepFile_Read.hxx> |
26 | #include <StepData_StepWriter.hxx> |
27 | #include <Interface_CheckIterator.hxx> |
28 | |
29 | #include <StepSelect_FileModifier.hxx> |
30 | |
31 | #include <StepData_UndefinedEntity.hxx> |
32 | #include <StepData_StepDumper.hxx> |
33 | |
34 | #include <TCollection_HAsciiString.hxx> |
35 | #include <TColStd_HSequenceOfInteger.hxx> |
36 | #include <IFSelect_GeneralModifier.hxx> |
37 | #include <Interface_ParamType.hxx> |
38 | #include <Interface_ReportEntity.hxx> |
39 | #include <Interface_UndefinedContent.hxx> |
40 | |
41 | #include <Message.hxx> |
42 | #include <Message_Messenger.hxx> |
43 | #include <Interface_Macros.hxx> |
44 | #include <Interface_Check.hxx> |
45 | |
46 | StepSelect_WorkLibrary::StepSelect_WorkLibrary |
47 | (const Standard_Boolean copymode) |
48 | : thecopymode (copymode) , thelabmode (0) |
49 | { |
50 | SetDumpLevels (1,2); |
51 | SetDumpHelp (0,"#id + Step Type"); |
52 | SetDumpHelp (1,"Entity as in file"); |
53 | SetDumpHelp (2,"Entity + shareds (level 1) as in file"); |
54 | } |
55 | // rq : les init sont faits par ailleurs, pas de souci a se faire |
56 | |
57 | |
58 | void StepSelect_WorkLibrary::SetDumpLabel (const Standard_Integer mode) |
59 | { |
60 | thelabmode = mode; |
61 | } |
62 | |
63 | |
64 | Standard_Integer StepSelect_WorkLibrary::ReadFile |
65 | (const Standard_CString name, |
66 | Handle(Interface_InterfaceModel)& model, |
67 | const Handle(Interface_Protocol)& protocol) const |
68 | { |
69 | long status = 1; |
70 | DeclareAndCast(StepData_Protocol,stepro,protocol); |
71 | if (stepro.IsNull()) return 1; |
72 | Handle(StepData_StepModel) stepmodel = new StepData_StepModel; |
73 | model = stepmodel; |
74 | StepFile_ReadTrace (0); |
75 | char *pName=(char *)name; |
76 | status = StepFile_Read (pName,stepmodel,stepro); |
77 | return status; |
78 | } |
79 | |
80 | |
81 | Standard_Boolean StepSelect_WorkLibrary::WriteFile |
82 | (IFSelect_ContextWrite& ctx) const |
83 | { |
84 | // Preparation |
85 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
86 | DeclareAndCast(StepData_StepModel,stepmodel,ctx.Model()); |
87 | DeclareAndCast(StepData_Protocol,stepro,ctx.Protocol()); |
88 | if (stepmodel.IsNull() || stepro.IsNull()) return Standard_False; |
89 | |
90 | ofstream fout; |
91 | fout.open(ctx.FileName(),ios::out|ios::trunc); |
92 | |
93 | if (!fout || !fout.rdbuf()->is_open()) { |
94 | ctx.CCheck(0)->AddFail("Step File could not be created"); |
95 | sout<<" Step File could not be created : " << ctx.FileName() << endl; return 0; |
96 | } |
97 | sout << " Step File Name : "<<ctx.FileName(); |
98 | StepData_StepWriter SW(stepmodel); |
99 | sout<<"("<<stepmodel->NbEntities()<<" ents) "; |
100 | |
101 | // File Modifiers |
102 | Standard_Integer nbmod = ctx.NbModifiers(); |
103 | for (Standard_Integer numod = 1; numod <= nbmod; numod ++) { |
104 | ctx.SetModifier (numod); |
105 | DeclareAndCast(StepSelect_FileModifier,filemod,ctx.FileModifier()); |
106 | if (!filemod.IsNull()) filemod->Perform(ctx,SW); |
107 | // (impressions de mise au point) |
108 | sout << " .. FileMod." << numod << filemod->Label(); |
109 | if (ctx.IsForAll()) sout << " (all model)"; |
110 | else sout << " (" << ctx.NbEntities() << " entities)"; |
111 | // sout << flush; |
112 | } |
113 | |
114 | // Envoi |
115 | SW.SendModel(stepro); |
116 | Interface_CheckIterator chl = SW.CheckList(); |
117 | for (chl.Start(); chl.More(); chl.Next()) |
118 | ctx.CCheck(chl.Number())->GetMessages(chl.Value()); |
119 | sout<<" Write "; |
120 | Standard_Boolean isGood = SW.Print(fout); |
121 | sout<<" Done"<<endl; |
122 | |
123 | errno = 0; |
124 | fout.close(); |
125 | isGood = fout.good() && isGood && !errno; |
126 | if(errno) |
127 | sout << strerror(errno) << endl; |
128 | return isGood; |
129 | } |
130 | |
131 | |
132 | Standard_Boolean StepSelect_WorkLibrary::CopyModel |
133 | (const Handle(Interface_InterfaceModel)& original, |
134 | const Handle(Interface_InterfaceModel)& newmodel, |
135 | const Interface_EntityIterator& list, |
136 | Interface_CopyTool& TC) const |
137 | { |
138 | if (thecopymode) return |
139 | IFSelect_WorkLibrary::CopyModel (original,newmodel,list,TC); |
140 | return thecopymode; |
141 | } |
142 | |
143 | |
144 | void StepSelect_WorkLibrary::DumpEntity |
145 | (const Handle(Interface_InterfaceModel)& model, |
146 | const Handle(Interface_Protocol)& protocol, |
147 | const Handle(Standard_Transient)& entity, |
148 | const Handle(Message_Messenger)& S, const Standard_Integer level) const |
149 | { |
150 | Standard_Integer nument = model->Number(entity); |
151 | if (nument <= 0 || nument > model->NbEntities()) return; |
152 | Standard_Boolean iserr = model->IsRedefinedContent(nument); |
153 | Handle(Standard_Transient) ent, con; ent = entity; |
154 | S<<" --- (STEP) Entity "; model->Print(entity,S); |
155 | if (iserr) con = model->ReportEntity(nument)->Content(); |
156 | if (entity.IsNull()) { S<<" Null"<<endl; return; } |
157 | |
158 | // On attaque le dump : d abord cas de l Erreur |
159 | S << " Type cdl : " << entity->DynamicType()->Name() << endl; |
160 | if (iserr) |
161 | S<<" *** NOT WELL LOADED : CONTENT FROM FILE ***"<<endl; |
162 | else if (model->IsUnknownEntity(nument)) |
163 | S<<" *** UNKNOWN TYPE ***"<<endl; |
164 | |
165 | StepData_StepDumper dump(GetCasted(StepData_StepModel,model), |
166 | GetCasted(StepData_Protocol,protocol),thelabmode); |
167 | dump.Dump(S,ent,level); |
168 | } |