0025748: Parallel version of progress indicator
[occt.git] / src / STEPControl / STEPControl_Controller.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //:j4 gka 16.03.99 S4134
15 //    gka 05.04.99 S4136: parameters definitions changed
16
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 <RWHeaderSection.hxx>
29 #include <RWStepAP214.hxx>
30 #include <Standard_Type.hxx>
31 #include <Standard_Version.hxx>
32 #include <STEPControl_ActorRead.hxx>
33 #include <STEPControl_ActorWrite.hxx>
34 #include <STEPControl_Controller.hxx>
35 #include <StepData_FileProtocol.hxx>
36 #include <StepData_StepModel.hxx>
37 #include <STEPEdit.hxx>
38 #include <STEPEdit_EditContext.hxx>
39 #include <STEPEdit_EditSDR.hxx>
40 #include <StepSelect_StepType.hxx>
41 #include <StepSelect_WorkLibrary.hxx>
42 #include <STEPSelections_SelectAssembly.hxx>
43 #include <STEPSelections_SelectDerived.hxx>
44 #include <STEPSelections_SelectFaces.hxx>
45 #include <STEPSelections_SelectForTransfer.hxx>
46 #include <STEPSelections_SelectGSCurves.hxx>
47 #include <STEPSelections_SelectInstances.hxx>
48 #include <TCollection_HAsciiString.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <Transfer_ActorOfTransientProcess.hxx>
51 #include <Transfer_FinderProcess.hxx>
52 #include <XSAlgo.hxx>
53 #include <XSControl_WorkSession.hxx>
54
55 IMPLEMENT_STANDARD_RTTIEXT(STEPControl_Controller,XSControl_Controller)
56
57 //  Pour NewModel et Write : definition de produit (temporaire ...)
58 STEPControl_Controller::STEPControl_Controller ()
59 : XSControl_Controller ("STEP", "step")
60 {
61   static Standard_Boolean init = Standard_False;
62   if (!init) {
63     RWHeaderSection::Init();  RWStepAP214::Init();
64
65     Interface_Static::Init ("step","write.step.product.name",'t',"Open CASCADE STEP translator " OCC_VERSION_STRING);
66     Interface_Static::Init ("step","write.step.assembly",'e',"");
67     Interface_Static::Init ("step","write.step.assembly",'&',"enum 0");
68     Interface_Static::Init ("step","write.step.assembly",'&',"eval Off");
69     Interface_Static::Init ("step","write.step.assembly",'&',"eval On");
70     Interface_Static::Init ("step","write.step.assembly",'&',"eval Auto");
71     Interface_Static::SetCVal("write.step.assembly","Auto"); 
72
73     Interface_Static::Init("step","step.angleunit.mode", 'e',"");
74     Interface_Static::Init("step","step.angleunit.mode", '&',"enum 0");
75     Interface_Static::Init("step","step.angleunit.mode", '&',"eval File");
76     Interface_Static::Init("step","step.angleunit.mode", '&',"eval Rad");
77     Interface_Static::Init("step","step.angleunit.mode", '&',"eval Deg");
78     Interface_Static::SetCVal("step.angleunit.mode","File"); 
79
80     Interface_Static::Init("step","write.step.schema", 'e',"");  
81     Interface_Static::Init("step","write.step.schema",'&',"enum 1");
82     Interface_Static::Init("step","write.step.schema",'&',"eval AP214CD");
83     Interface_Static::Init("step","write.step.schema",'&',"eval AP214DIS");
84     Interface_Static::Init("step","write.step.schema",'&',"eval AP203");
85     Interface_Static::Init("step","write.step.schema",'&',"eval AP214IS");
86     Interface_Static::Init("step","write.step.schema",'&',"eval AP242DIS");
87     Interface_Static::SetCVal("write.step.schema","AP214IS"); 
88
89     // Type of Product Definition for reading
90     // Note: the numbers should be consistent with function FindShapeReprType()
91     // in STEPControl_ActorRead.cxx
92     Interface_Static::Init("step","read.step.shape.repr",'e',"");
93     Interface_Static::Init("step","read.step.shape.repr",'&',"enum 1");
94     Interface_Static::Init("step","read.step.shape.repr",'&',"eval All");   // 1
95     Interface_Static::Init("step","read.step.shape.repr",'&',"eval ABSR");  // 2
96     Interface_Static::Init("step","read.step.shape.repr",'&',"eval MSSR");  // 3
97     Interface_Static::Init("step","read.step.shape.repr",'&',"eval GBSSR"); // 4
98     Interface_Static::Init("step","read.step.shape.repr",'&',"eval FBSR");  // 5
99     Interface_Static::Init("step","read.step.shape.repr",'&',"eval EBWSR"); // 6
100     Interface_Static::Init("step","read.step.shape.repr",'&',"eval GBWSR"); // 7
101     Interface_Static::SetCVal("read.step.shape.repr","All");
102
103     // Mode for reading shapes attached to main SDR by SRR
104     // (hybrid model representation in AP203 since 1998)
105     Interface_Static::Init("step","read.step.shape.relationship",'e',"");
106     Interface_Static::Init("step","read.step.shape.relationship",'&',"enum 0");
107     Interface_Static::Init("step","read.step.shape.relationship",'&',"eval OFF");
108     Interface_Static::Init("step","read.step.shape.relationship",'&',"eval ON");
109     Interface_Static::SetCVal("read.step.shape.relationship","ON");
110
111     // Mode for reading shapes attached to Product by ShapeAspect 
112     // (hybrid model representation in AP203 before 1998)
113     Interface_Static::Init("step","read.step.shape.aspect",'e',"");
114     Interface_Static::Init("step","read.step.shape.aspect",'&',"enum 0");
115     Interface_Static::Init("step","read.step.shape.aspect",'&',"eval OFF");
116     Interface_Static::Init("step","read.step.shape.aspect",'&',"eval ON");
117     Interface_Static::SetCVal("read.step.shape.aspect","ON");
118
119     // Mode for reading SDR and ShapeRepr if it is necessary
120     Interface_Static::Init("step","read.step.product.mode",'e',"");
121     Interface_Static::Init("step","read.step.product.mode",'&',"enum 0");
122     Interface_Static::Init("step","read.step.product.mode",'&',"eval OFF");
123     Interface_Static::Init("step","read.step.product.mode",'&',"eval ON");
124     Interface_Static::SetCVal("read.step.product.mode","ON");
125
126     // Order of reading ShapeDefinitionRepresentation in ProductDefinition
127     Interface_Static::Init("step","read.step.product.context",'e',"");
128     Interface_Static::Init("step","read.step.product.context",'&',"enum 1");
129     Interface_Static::Init("step","read.step.product.context",'&',"eval all");     // 1
130     Interface_Static::Init("step","read.step.product.context",'&',"eval design");  // 2
131     Interface_Static::Init("step","read.step.product.context",'&',"eval analysis");// 3
132     Interface_Static::SetCVal("read.step.product.context","all");
133
134     // What we try to read in ProductDefinition
135     Interface_Static::Init("step","read.step.assembly.level",'e',"");
136     Interface_Static::Init("step","read.step.assembly.level",'&',"enum 1");
137     Interface_Static::Init("step","read.step.assembly.level",'&',"eval all");      // 1
138     Interface_Static::Init("step","read.step.assembly.level",'&',"eval assembly"); // 2
139     Interface_Static::Init("step","read.step.assembly.level",'&',"eval structure");// 3
140     Interface_Static::Init("step","read.step.assembly.level",'&',"eval shape");    // 4
141     Interface_Static::SetCVal("read.step.assembly.level","all");
142
143     // unit: supposed to be cascade unit (target unit for reading)
144     Interface_Static::Init("step","write.step.unit", 'e',"");
145     Interface_Static::Init("step","write.step.unit",'&',"enum 1");
146     Interface_Static::Init("step","write.step.unit",'&',"eval INCH");  // 1
147     Interface_Static::Init("step","write.step.unit",'&',"eval MM");    // 2
148     Interface_Static::Init("step","write.step.unit",'&',"eval ??");    // 3
149     Interface_Static::Init("step","write.step.unit",'&',"eval FT");    // 4
150     Interface_Static::Init("step","write.step.unit",'&',"eval MI");    // 5
151     Interface_Static::Init("step","write.step.unit",'&',"eval M");     // 6
152     Interface_Static::Init("step","write.step.unit",'&',"eval KM");    // 7
153     Interface_Static::Init("step","write.step.unit",'&',"eval MIL");   // 8
154     Interface_Static::Init("step","write.step.unit",'&',"eval UM");    // 9
155     Interface_Static::Init("step","write.step.unit",'&',"eval CM");    //10
156     Interface_Static::Init("step","write.step.unit",'&',"eval UIN");   //11
157     Interface_Static::SetCVal ("write.step.unit","MM");
158
159     // Non-manifold topology reading: OFF by default (ssv; 26.11.2010)
160     Interface_Static::Init ("step","read.step.nonmanifold",'e',"");
161     Interface_Static::Init ("step","read.step.nonmanifold",'&',"enum 0");
162     Interface_Static::Init ("step","read.step.nonmanifold",'&',"eval Off");
163     Interface_Static::Init ("step","read.step.nonmanifold",'&',"eval On");
164     Interface_Static::SetIVal("read.step.nonmanifold",0); 
165
166     // Non-manifold topology writing: OFF by default (ssv; 26.11.2010)
167     Interface_Static::Init ("step","write.step.nonmanifold",'e',"");
168     Interface_Static::Init ("step","write.step.nonmanifold",'&',"enum 0");
169     Interface_Static::Init ("step","write.step.nonmanifold",'&',"eval Off");
170     Interface_Static::Init ("step","write.step.nonmanifold",'&',"eval On");
171     Interface_Static::SetIVal("write.step.nonmanifold",0); 
172
173     // I-Deas-like STEP processing: OFF by default (ssv; 22.11.2010)
174     Interface_Static::Init ("step","read.step.ideas",'e',"");
175     Interface_Static::Init ("step","read.step.ideas",'&',"enum 0");
176     Interface_Static::Init ("step","read.step.ideas",'&',"eval Off");
177     Interface_Static::Init ("step","read.step.ideas",'&',"eval On");
178     Interface_Static::SetIVal("read.step.ideas",0); 
179
180     //Parameter to write all free vertices in one SDR (name and style of vertex are lost) (default) 
181     //or each vertex in its own SDR (name and style of vertex are exported). (ika; 21.07.2014) 
182     Interface_Static::Init ("step","write.step.vertex.mode",'e',"");
183     Interface_Static::Init ("step","write.step.vertex.mode",'&',"enum 0");
184     Interface_Static::Init ("step","write.step.vertex.mode",'&',"eval One Compound");
185     Interface_Static::Init ("step","write.step.vertex.mode",'&',"eval Single Vertex");
186     Interface_Static::SetIVal("write.step.vertex.mode",0);
187   
188     // abv 15.11.00: ShapeProcessing
189     Interface_Static::Init ("XSTEP","write.step.resource.name",'t',"STEP");
190     Interface_Static::Init ("XSTEP","read.step.resource.name",'t',"STEP");
191     Interface_Static::Init ("XSTEP","write.step.sequence",'t',"ToSTEP");
192     Interface_Static::Init ("XSTEP","read.step.sequence",'t',"FromSTEP");
193
194     // ika 28.07.16: Paremeter to read all top level solids and shells,
195     // should be used only in case of invalid shape_representation without links to shapes.
196     Interface_Static::Init("step", "read.step.all.shapes", 'e', "");
197     Interface_Static::Init("step", "read.step.all.shapes", '&', "enum 0");
198     Interface_Static::Init("step", "read.step.all.shapes", '&', "eval Off");
199     Interface_Static::Init("step", "read.step.all.shapes", '&', "eval On");
200     Interface_Static::SetIVal("read.step.all.shapes", 0);
201
202      // Mode for reading constructive geometry representation relationship to read
203     //StepRepr_ConstructiveGeometryRepresentation method implemented only for StepGeom_MakeAxis2Placement3d
204     //for axis placements representing axis for suplemented geometry. Axis placements are translated to planar faces with CS 
205     //equal to translated axis placements
206     Interface_Static::Init("step","read.step.constructivegeom.relationship",'e',"");
207     Interface_Static::Init("step","read.step.constructivegeom.relationship",'&',"enum 0");
208     Interface_Static::Init("step","read.step.constructivegeom.relationship",'&',"eval OFF");
209     Interface_Static::Init("step","read.step.constructivegeom.relationship",'&',"eval ON");
210     Interface_Static::SetCVal("read.step.constructivegeom.relationship","OFF");
211
212     init = Standard_True;
213   }
214
215   Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite;
216   ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
217   myAdaptorWrite = ActWrite;
218
219   Handle(StepSelect_WorkLibrary) swl = new StepSelect_WorkLibrary;
220   swl->SetDumpLabel(1);
221   myAdaptorLibrary  = swl;
222   myAdaptorProtocol = STEPEdit::Protocol();
223   myAdaptorRead     = new STEPControl_ActorRead;  // par ex pour Recognize
224
225   SetModeWrite (0,4);
226   SetModeWriteHelp (0,"As Is");
227   SetModeWriteHelp (1,"Faceted Brep");
228   SetModeWriteHelp (2,"Shell Based");
229   SetModeWriteHelp (3,"Manifold Solid");
230   SetModeWriteHelp (4,"Wireframe");
231   TraceStatic ("read.surfacecurve.mode",5);
232
233   //   ---  SELECTIONS, SIGNATURES, COMPTEURS, EDITEURS
234
235   DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
236   if (!xmr.IsNull()) {
237     Handle(IFSelect_Signature) sty = STEPEdit::SignType();
238     AddSessionItem (sty,"step-type");
239     Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter(sty,Standard_False,Standard_True);
240     AddSessionItem (tys,"step-types");
241
242     //szv:mySignType = sty;
243     
244     //pdn S4133 18.02.99
245     AddSessionItem (new IFSelect_SignAncestor(),"xst-derived");
246
247     Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
248     stdvar->SetProtocol(STEPEdit::Protocol());
249     AddSessionItem (stdvar,"step-derived");
250     
251     Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
252     selsdr->SetInput (xmr);
253     AddSessionItem (selsdr,"step-shape-def-repr");
254
255     AddSessionItem (STEPEdit::NewSelectPlacedItem(),"step-placed-items");
256     // input deja pret avec ModelAll
257     AddSessionItem (STEPEdit::NewSelectShapeRepr(),"step-shape-repr");
258   }
259   
260   //pdn
261   Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
262   stfaces->SetInput (xmr);
263   AddSessionItem (stfaces,"step-faces");
264   
265   Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
266   AddSessionItem (stinst,"step-instances");
267   
268   Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
269   stcurves->SetInput (xmr);
270   AddSessionItem (stcurves,"step-GS-curves");
271   
272   Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
273   assembly->SetInput (xmr);
274   AddSessionItem (assembly,"step-assembly");
275   
276   Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
277   Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
278   AddSessionItem (edhead,"step-header-edit");
279   AddSessionItem (edheadf,"step-header");
280
281   Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
282   Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
283   AddSessionItem (edctx,"step-context-edit");
284   AddSessionItem (edctxf,"step-context");
285
286
287   Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
288   Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
289   AddSessionItem (edsdr,"step-SDR-edit");
290   AddSessionItem (edsdrf,"step-SDR-data");
291 }
292
293 Handle(Interface_InterfaceModel)  STEPControl_Controller::NewModel () const
294 {
295   return STEPEdit::NewModel();
296 }
297
298 //  ####    PROVISOIRE ???   ####
299
300 IFSelect_ReturnStatus  STEPControl_Controller::TransferWriteShape
301   (const TopoDS_Shape& shape,
302    const Handle(Transfer_FinderProcess)& FP,
303    const Handle(Interface_InterfaceModel)& model,
304    const Standard_Integer modeshape,
305    const Message_ProgressRange& theProgress) const
306 {
307   if (modeshape < 0 || modeshape > 4) return IFSelect_RetError;
308   Handle(STEPControl_ActorWrite) ActWrite =
309     Handle(STEPControl_ActorWrite)::DownCast(myAdaptorWrite);
310 //    A PRESENT ON PASSE PAR LE PROFILE
311   if (!ActWrite.IsNull()) 
312     ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
313
314   return XSControl_Controller::TransferWriteShape(shape, FP, model, modeshape, theProgress);
315 }
316
317 Standard_Boolean STEPControl_Controller::Init ()
318 {
319   static Standard_Boolean inic = Standard_False;
320   if (!inic) {
321     Handle(STEPControl_Controller) STEPCTL = new STEPControl_Controller;
322     STEPCTL->AutoRecord();  // avec les noms donnes a la construction
323     XSAlgo::Init();                                                                                                        
324     inic = Standard_True;
325   }
326   return Standard_True;
327 }
328 //=======================================================================
329 //function : Customise
330 //purpose  : 
331 //=======================================================================
332
333 void STEPControl_Controller::Customise(Handle(XSControl_WorkSession)& WS) 
334 {
335   XSControl_Controller::Customise(WS);
336
337   Handle(IFSelect_SelectModelRoots) slr;
338   Handle(Standard_Transient) slr1 = WS->NamedItem("xst-model-roots");
339   if(!slr1.IsNull())
340     slr = Handle(IFSelect_SelectModelRoots)::DownCast(slr1);
341   else  {
342     slr = new IFSelect_SelectModelRoots;
343     WS->AddNamedItem ("xst-model-roots",slr);
344   }
345
346   Handle(STEPSelections_SelectForTransfer) st1= new STEPSelections_SelectForTransfer;
347   st1->SetReader (WS->TransferReader());
348   WS->AddNamedItem ("xst-transferrable-roots",st1);
349
350   if (!slr.IsNull()) {
351     Handle(IFSelect_Signature) sty = STEPEdit::SignType();
352     WS->AddNamedItem ("step-type",sty);
353     
354     Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter(sty,Standard_False,Standard_True);
355     WS->AddNamedItem ("step-types",tys);
356
357         //szv:mySignType = sty;
358     WS->SetSignType( sty );
359     
360     //pdn S4133 18.02.99
361     WS->AddNamedItem ("xst-derived",new IFSelect_SignAncestor());
362     Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
363     stdvar->SetProtocol(STEPEdit::Protocol());
364     WS->AddNamedItem ("step-derived",stdvar);
365     
366     Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
367     selsdr->SetInput (slr);
368     WS->AddNamedItem ("step-shape-def-repr",selsdr);
369     Handle(IFSelect_SelectSignature) selrrs = STEPEdit::NewSelectPlacedItem();
370     WS->AddNamedItem ("step-placed-items",selrrs);
371     Handle(IFSelect_SelectSignature) selsr = STEPEdit::NewSelectShapeRepr();
372     // input deja pret avec ModelAll
373     WS->AddNamedItem ("step-shape-repr",selsr);
374   }
375   
376   //pdn
377   Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
378   stfaces->SetInput (slr);
379   WS->AddNamedItem ("step-faces",stfaces);
380   
381   Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
382   WS->AddNamedItem ("step-instances",stinst);
383   
384   Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
385   stcurves->SetInput (slr);
386   WS->AddNamedItem ("step-GS-curves",stcurves);
387   
388   Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
389   assembly->SetInput (slr);
390   WS->AddNamedItem ("step-assembly",assembly);
391   
392   Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
393   Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
394   WS->AddNamedItem ("step-header-edit",edhead);
395   WS->AddNamedItem ("step-header",edheadf);
396
397   Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
398   Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
399   WS->AddNamedItem ("step-context-edit",edctx);
400   WS->AddNamedItem ("step-context",edctxf);
401
402
403   Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
404   Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
405   WS->AddNamedItem ("step-SDR-edit",edsdr);
406   WS->AddNamedItem ("step-SDR-data",edsdrf);
407
408   
409   
410 }