1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //:j4 gka 16.03.99 S4134
15 // gka 05.04.99 S4136: parameters definitions changed
17 #include <APIHeaderSection_EditHeader.hxx>
18 #include <APIHeaderSection_MakeHeader.hxx>
19 #include <HeaderSection.hxx>
20 #include <IFSelect_EditForm.hxx>
21 #include <IFSelect_SelectModelRoots.hxx>
22 #include <IFSelect_SelectSignature.hxx>
23 #include <IFSelect_SignAncestor.hxx>
24 #include <IFSelect_SignCounter.hxx>
25 #include <Interface_InterfaceModel.hxx>
26 #include <Interface_Macros.hxx>
27 #include <Interface_Static.hxx>
28 #include <MoniTool_Option.hxx>
29 #include <MoniTool_Profile.hxx>
30 #include <RWHeaderSection.hxx>
31 #include <RWStepAP214.hxx>
32 #include <Standard_Type.hxx>
33 #include <Standard_Version.hxx>
34 #include <STEPControl_ActorRead.hxx>
35 #include <STEPControl_ActorWrite.hxx>
36 #include <STEPControl_Controller.hxx>
37 #include <StepData_FileProtocol.hxx>
38 #include <StepData_StepModel.hxx>
39 #include <STEPEdit.hxx>
40 #include <STEPEdit_EditContext.hxx>
41 #include <STEPEdit_EditSDR.hxx>
42 #include <StepSelect_StepType.hxx>
43 #include <StepSelect_WorkLibrary.hxx>
44 #include <STEPSelections_SelectAssembly.hxx>
45 #include <STEPSelections_SelectDerived.hxx>
46 #include <STEPSelections_SelectFaces.hxx>
47 #include <STEPSelections_SelectForTransfer.hxx>
48 #include <STEPSelections_SelectGSCurves.hxx>
49 #include <STEPSelections_SelectInstances.hxx>
50 #include <TCollection_HAsciiString.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <Transfer_ActorOfTransientProcess.hxx>
53 #include <Transfer_FinderProcess.hxx>
55 #include <XSControl_WorkSession.hxx>
57 IMPLEMENT_STANDARD_RTTIEXT(STEPControl_Controller,XSControl_Controller)
59 //#include <StepAP214.hxx>
60 // Pour NewModel et Write : definition de produit (temporaire ...)
61 STEPControl_Controller::STEPControl_Controller ()
62 : XSControl_Controller ("STEP", "step")
64 static Standard_Boolean init = Standard_False;
66 RWHeaderSection::Init(); RWStepAP214::Init();
68 Interface_Static::Init ("step","write.step.product.name",'t',"Open CASCADE STEP translator " OCC_VERSION_STRING);
69 Interface_Static::Init ("step","write.step.assembly",'e',"");
70 Interface_Static::Init ("step","write.step.assembly",'&',"enum 0");
71 Interface_Static::Init ("step","write.step.assembly",'&',"eval Off");
72 Interface_Static::Init ("step","write.step.assembly",'&',"eval On");
73 Interface_Static::Init ("step","write.step.assembly",'&',"eval Auto");
74 Interface_Static::SetCVal("write.step.assembly","Auto");
76 Interface_Static::Init("step","step.angleunit.mode", 'e',"");
77 Interface_Static::Init("step","step.angleunit.mode", '&',"enum 0");
78 Interface_Static::Init("step","step.angleunit.mode", '&',"eval File");
79 Interface_Static::Init("step","step.angleunit.mode", '&',"eval Rad");
80 Interface_Static::Init("step","step.angleunit.mode", '&',"eval Deg");
81 Interface_Static::SetCVal("step.angleunit.mode","File");
83 Interface_Static::Init("step","write.step.schema", 'e',"");
84 Interface_Static::Init("step","write.step.schema",'&',"enum 1");
85 Interface_Static::Init("step","write.step.schema",'&',"eval AP214CD");
86 Interface_Static::Init("step","write.step.schema",'&',"eval AP214DIS");
87 Interface_Static::Init("step","write.step.schema",'&',"eval AP203");
88 Interface_Static::Init("step","write.step.schema",'&',"eval AP214IS");
89 Interface_Static::SetCVal("write.step.schema","AP214IS");
91 // Type of Product Definition for reading
92 // Note: the numbers should be consistent with function FindShapeReprType()
93 // in STEPControl_ActorRead.cxx
94 Interface_Static::Init("step","read.step.shape.repr",'e',"");
95 Interface_Static::Init("step","read.step.shape.repr",'&',"enum 1");
96 Interface_Static::Init("step","read.step.shape.repr",'&',"eval All"); // 1
97 Interface_Static::Init("step","read.step.shape.repr",'&',"eval ABSR"); // 2
98 Interface_Static::Init("step","read.step.shape.repr",'&',"eval MSSR"); // 3
99 Interface_Static::Init("step","read.step.shape.repr",'&',"eval GBSSR"); // 4
100 Interface_Static::Init("step","read.step.shape.repr",'&',"eval FBSR"); // 5
101 Interface_Static::Init("step","read.step.shape.repr",'&',"eval EBWSR"); // 6
102 Interface_Static::Init("step","read.step.shape.repr",'&',"eval GBWSR"); // 7
103 Interface_Static::SetCVal("read.step.shape.repr","All");
105 // Mode for reading shapes attached to main SDR by SRR
106 // (hybrid model representation in AP203 since 1998)
107 Interface_Static::Init("step","read.step.shape.relationship",'e',"");
108 Interface_Static::Init("step","read.step.shape.relationship",'&',"enum 0");
109 Interface_Static::Init("step","read.step.shape.relationship",'&',"eval OFF");
110 Interface_Static::Init("step","read.step.shape.relationship",'&',"eval ON");
111 Interface_Static::SetCVal("read.step.shape.relationship","ON");
113 // Mode for reading shapes attached to Product by ShapeAspect
114 // (hybrid model representation in AP203 before 1998)
115 Interface_Static::Init("step","read.step.shape.aspect",'e',"");
116 Interface_Static::Init("step","read.step.shape.aspect",'&',"enum 0");
117 Interface_Static::Init("step","read.step.shape.aspect",'&',"eval OFF");
118 Interface_Static::Init("step","read.step.shape.aspect",'&',"eval ON");
119 Interface_Static::SetCVal("read.step.shape.aspect","ON");
121 // Mode for reading SDR and ShapeRepr if it is necessary
122 Interface_Static::Init("step","read.step.product.mode",'e',"");
123 Interface_Static::Init("step","read.step.product.mode",'&',"enum 0");
124 Interface_Static::Init("step","read.step.product.mode",'&',"eval OFF");
125 Interface_Static::Init("step","read.step.product.mode",'&',"eval ON");
126 Interface_Static::SetCVal("read.step.product.mode","ON");
128 // Order of reading ShapeDefinitionRepresentation in ProductDefinition
129 Interface_Static::Init("step","read.step.product.context",'e',"");
130 Interface_Static::Init("step","read.step.product.context",'&',"enum 1");
131 Interface_Static::Init("step","read.step.product.context",'&',"eval all"); // 1
132 Interface_Static::Init("step","read.step.product.context",'&',"eval design"); // 2
133 Interface_Static::Init("step","read.step.product.context",'&',"eval analysis");// 3
134 Interface_Static::SetCVal("read.step.product.context","all");
136 // What we try to read in ProductDefinition
137 Interface_Static::Init("step","read.step.assembly.level",'e',"");
138 Interface_Static::Init("step","read.step.assembly.level",'&',"enum 1");
139 Interface_Static::Init("step","read.step.assembly.level",'&',"eval all"); // 1
140 Interface_Static::Init("step","read.step.assembly.level",'&',"eval assembly"); // 2
141 Interface_Static::Init("step","read.step.assembly.level",'&',"eval structure");// 3
142 Interface_Static::Init("step","read.step.assembly.level",'&',"eval shape"); // 4
143 Interface_Static::SetCVal("read.step.assembly.level","all");
145 // unit: supposed to be cascade unit (target unit for reading)
146 Interface_Static::Init("step","write.step.unit", 'e',"");
147 Interface_Static::Init("step","write.step.unit",'&',"enum 1");
148 Interface_Static::Init("step","write.step.unit",'&',"eval INCH"); // 1
149 Interface_Static::Init("step","write.step.unit",'&',"eval MM"); // 2
150 Interface_Static::Init("step","write.step.unit",'&',"eval ??"); // 3
151 Interface_Static::Init("step","write.step.unit",'&',"eval FT"); // 4
152 Interface_Static::Init("step","write.step.unit",'&',"eval MI"); // 5
153 Interface_Static::Init("step","write.step.unit",'&',"eval M"); // 6
154 Interface_Static::Init("step","write.step.unit",'&',"eval KM"); // 7
155 Interface_Static::Init("step","write.step.unit",'&',"eval MIL"); // 8
156 Interface_Static::Init("step","write.step.unit",'&',"eval UM"); // 9
157 Interface_Static::Init("step","write.step.unit",'&',"eval CM"); //10
158 Interface_Static::Init("step","write.step.unit",'&',"eval UIN"); //11
159 Interface_Static::SetCVal ("write.step.unit","MM");
161 // Non-manifold topology reading: OFF by default (ssv; 26.11.2010)
162 Interface_Static::Init ("step","read.step.nonmanifold",'e',"");
163 Interface_Static::Init ("step","read.step.nonmanifold",'&',"enum 0");
164 Interface_Static::Init ("step","read.step.nonmanifold",'&',"eval Off");
165 Interface_Static::Init ("step","read.step.nonmanifold",'&',"eval On");
166 Interface_Static::SetIVal("read.step.nonmanifold",0);
168 // Non-manifold topology writing: OFF by default (ssv; 26.11.2010)
169 Interface_Static::Init ("step","write.step.nonmanifold",'e',"");
170 Interface_Static::Init ("step","write.step.nonmanifold",'&',"enum 0");
171 Interface_Static::Init ("step","write.step.nonmanifold",'&',"eval Off");
172 Interface_Static::Init ("step","write.step.nonmanifold",'&',"eval On");
173 Interface_Static::SetIVal("write.step.nonmanifold",0);
175 // I-Deas-like STEP processing: OFF by default (ssv; 22.11.2010)
176 Interface_Static::Init ("step","read.step.ideas",'e',"");
177 Interface_Static::Init ("step","read.step.ideas",'&',"enum 0");
178 Interface_Static::Init ("step","read.step.ideas",'&',"eval Off");
179 Interface_Static::Init ("step","read.step.ideas",'&',"eval On");
180 Interface_Static::SetIVal("read.step.ideas",0);
182 //Parameter to write all free vertices in one SDR (name and style of vertex are lost) (default)
183 //or each vertex in its own SDR (name and style of vertex are exported). (ika; 21.07.2014)
184 Interface_Static::Init ("step","write.step.vertex.mode",'e',"");
185 Interface_Static::Init ("step","write.step.vertex.mode",'&',"enum 0");
186 Interface_Static::Init ("step","write.step.vertex.mode",'&',"eval One Compound");
187 Interface_Static::Init ("step","write.step.vertex.mode",'&',"eval Single Vertex");
188 Interface_Static::SetIVal("write.step.vertex.mode",0);
190 // abv 15.11.00: ShapeProcessing
191 Interface_Static::Init ("XSTEP","write.step.resource.name",'t',"STEP");
192 Interface_Static::Init ("XSTEP","read.step.resource.name",'t',"STEP");
193 Interface_Static::Init ("XSTEP","write.step.sequence",'t',"ToSTEP");
194 Interface_Static::Init ("XSTEP","read.step.sequence",'t',"FromSTEP");
196 init = Standard_True;
199 Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite;
200 ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
201 theAdaptorWrite = ActWrite;
203 Handle(StepSelect_WorkLibrary) swl = new StepSelect_WorkLibrary;
204 swl->SetDumpLabel(1);
205 theAdaptorLibrary = swl;
206 theAdaptorProtocol = STEPEdit::Protocol();
207 // theAdaptorProtocol = StepAP214::Protocol();
208 theAdaptorRead = new STEPControl_ActorRead; // par ex pour Recognize
211 SetModeWriteHelp (0,"As Is");
212 SetModeWriteHelp (1,"Faceted Brep");
213 SetModeWriteHelp (2,"Shell Based");
214 SetModeWriteHelp (3,"Manifold Solid");
215 SetModeWriteHelp (4,"Wireframe");
216 TraceStatic ("read.surfacecurve.mode",5);
218 // --- SELECTIONS, SIGNATURES, COMPTEURS, EDITEURS
220 DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
222 Handle(IFSelect_Signature) sty = STEPEdit::SignType();
223 AddSessionItem (sty,"step-type");
224 Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter
225 (sty,Standard_False,Standard_True);
226 AddSessionItem (tys,"step-types");
231 Handle(IFSelect_SignAncestor)sta = new IFSelect_SignAncestor();
232 AddSessionItem (sta,"xst-derived");
233 Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
234 stdvar->SetProtocol(STEPEdit::Protocol());
235 AddSessionItem (stdvar,"step-derived");
237 Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
238 selsdr->SetInput (xmr);
239 AddSessionItem (selsdr,"step-shape-def-repr");
240 Handle(IFSelect_SelectSignature) selrrs = STEPEdit::NewSelectPlacedItem();
241 // selrrs->SetInput (xmr); deja prete avec ModelAll
242 AddSessionItem (selrrs,"step-placed-items");
243 Handle(IFSelect_SelectSignature) selsr = STEPEdit::NewSelectShapeRepr();
244 // input deja pret avec ModelAll
245 AddSessionItem (selsr,"step-shape-repr");
249 Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
250 stfaces->SetInput (xmr);
251 AddSessionItem (stfaces,"step-faces");
253 Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
254 AddSessionItem (stinst,"step-instances");
256 Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
257 stcurves->SetInput (xmr);
258 AddSessionItem (stcurves,"step-GS-curves");
260 Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
261 assembly->SetInput (xmr);
262 AddSessionItem (assembly,"step-assembly");
264 Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
265 Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
266 AddSessionItem (edhead,"step-header-edit");
267 AddSessionItem (edheadf,"step-header");
269 Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
270 Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
271 AddSessionItem (edctx,"step-context-edit");
272 AddSessionItem (edctxf,"step-context");
275 Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
276 Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
277 AddSessionItem (edsdr,"step-SDR-edit");
278 AddSessionItem (edsdrf,"step-SDR-data");
282 // ActorRead : on ajoute le cas Shape possible, a part du default
283 // ainsi, on l a tjrs sous la main
284 Handle(MoniTool_Option) optacrd = Profile()->Option("tr-read");
285 optacrd->Add ("shape",theAdaptorRead);
287 // ActorWrite : on ajoute les cas possibles (NB : shape == default)
288 // On garde a part les cas shape compound (= shape traitee globale ou en
289 // assembly), peuvent etre utiles. Tandis que les autres cas sont
290 // susceptibles d etre remplaces si on fait du Model-Editor
291 Handle(MoniTool_Option) optacwr = Profile()->Option("tr-write");
292 Handle(STEPControl_ActorWrite) ActWSh = new STEPControl_ActorWrite;
293 ActWSh->SetGroupMode(0);
294 optacwr->Add ("shape",ActWSh);
295 Handle(STEPControl_ActorWrite) ActWA1 = new STEPControl_ActorWrite;
296 ActWA1->SetGroupMode(1);
297 optacwr->Add ("compound",ActWA1);
298 optacwr->Add ("assembly",ActWA1);
299 optacwr->Add ("SRWT",ActWA1);
301 Profile()->AddConf ("Shape");
302 Profile()->AddSwitch ("Shape","tr-write","shape");
304 Profile()->AddConf ("Assembly");
305 Profile()->AddSwitch ("Assembly","tr-write","SRWT");
308 Handle(Interface_InterfaceModel) STEPControl_Controller::NewModel () const
310 return STEPEdit::NewModel();
313 Handle(Transfer_ActorOfTransientProcess) STEPControl_Controller::ActorRead
314 (const Handle(Interface_InterfaceModel)& ) const
316 return theAdaptorRead;
317 } // new Cc1ToTopoDSAct_Actor ??
319 // #### PROVISOIRE ??? ####
321 IFSelect_ReturnStatus STEPControl_Controller::TransferWriteShape
322 (const TopoDS_Shape& shape,
323 const Handle(Transfer_FinderProcess)& FP,
324 const Handle(Interface_InterfaceModel)& model,
325 const Standard_Integer modeshape) const
327 if (modeshape < 0 || modeshape > 4) return IFSelect_RetError;
328 Handle(STEPControl_ActorWrite) ActWrite =
329 Handle(STEPControl_ActorWrite)::DownCast(theAdaptorWrite);
330 // A PRESENT ON PASSE PAR LE PROFILE
331 if (!ActWrite.IsNull())
332 ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
334 return XSControl_Controller::TransferWriteShape (shape,FP,model,modeshape);
337 Standard_Boolean STEPControl_Controller::Init ()
339 static Standard_Boolean inic = Standard_False;
341 Handle(STEPControl_Controller) STEPCTL = new STEPControl_Controller;
342 STEPCTL->AutoRecord(); // avec les noms donnes a la construction
344 inic = Standard_True;
346 return Standard_True;
348 //=======================================================================
349 //function : Customise
351 //=======================================================================
353 void STEPControl_Controller::Customise(Handle(XSControl_WorkSession)& WS)
355 XSControl_Controller::Customise(WS);
356 Handle(IFSelect_SelectModelRoots) slr;
357 Handle(Standard_Transient) slr1 = WS->NamedItem("xst-model-roots");
359 slr = Handle(IFSelect_SelectModelRoots)::DownCast(slr1);
361 slr = new IFSelect_SelectModelRoots;
362 WS->AddNamedItem ("xst-model-roots",slr);
366 Handle(STEPSelections_SelectForTransfer) st1= new STEPSelections_SelectForTransfer;
367 st1->SetReader (WS->TransferReader());
368 WS->AddNamedItem ("xst-transferrable-roots",st1);
371 //DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
373 Handle(IFSelect_Signature) sty = STEPEdit::SignType();
374 WS->AddNamedItem ("step-type",sty);
376 Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter
377 (sty,Standard_False,Standard_True);
378 WS->AddNamedItem ("step-types",tys);
383 Handle(IFSelect_SignAncestor)sta = new IFSelect_SignAncestor();
384 WS->AddNamedItem ("xst-derived",sta);
385 Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
386 stdvar->SetProtocol(STEPEdit::Protocol());
387 WS->AddNamedItem ("step-derived",stdvar);
389 Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
390 selsdr->SetInput (slr);
391 WS->AddNamedItem ("step-shape-def-repr",selsdr);
392 Handle(IFSelect_SelectSignature) selrrs = STEPEdit::NewSelectPlacedItem();
393 // selrrs->SetInput (slr); deja prete avec ModelAll
394 WS->AddNamedItem ("step-placed-items",selrrs);
395 Handle(IFSelect_SelectSignature) selsr = STEPEdit::NewSelectShapeRepr();
396 // input deja pret avec ModelAll
397 WS->AddNamedItem ("step-shape-repr",selsr);
401 Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
402 stfaces->SetInput (slr);
403 WS->AddNamedItem ("step-faces",stfaces);
405 Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
406 WS->AddNamedItem ("step-instances",stinst);
408 Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
409 stcurves->SetInput (slr);
410 WS->AddNamedItem ("step-GS-curves",stcurves);
412 Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
413 assembly->SetInput (slr);
414 WS->AddNamedItem ("step-assembly",assembly);
416 Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
417 Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
418 WS->AddNamedItem ("step-header-edit",edhead);
419 WS->AddNamedItem ("step-header",edheadf);
421 Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
422 Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
423 WS->AddNamedItem ("step-context-edit",edctx);
424 WS->AddNamedItem ("step-context",edctxf);
427 Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
428 Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
429 WS->AddNamedItem ("step-SDR-edit",edsdr);
430 WS->AddNamedItem ("step-SDR-data",edsdrf);