0027349: XtControl_Reader is not thread-safe
[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     init = Standard_True;
195   }
196
197   Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite;
198   ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
199   myAdaptorWrite = ActWrite;
200
201   Handle(StepSelect_WorkLibrary) swl = new StepSelect_WorkLibrary;
202   swl->SetDumpLabel(1);
203   myAdaptorLibrary  = swl;
204   myAdaptorProtocol = STEPEdit::Protocol();
205   myAdaptorRead     = new STEPControl_ActorRead;  // par ex pour Recognize
206
207   SetModeWrite (0,4);
208   SetModeWriteHelp (0,"As Is");
209   SetModeWriteHelp (1,"Faceted Brep");
210   SetModeWriteHelp (2,"Shell Based");
211   SetModeWriteHelp (3,"Manifold Solid");
212   SetModeWriteHelp (4,"Wireframe");
213   TraceStatic ("read.surfacecurve.mode",5);
214
215   //   ---  SELECTIONS, SIGNATURES, COMPTEURS, EDITEURS
216
217   DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
218   if (!xmr.IsNull()) {
219     Handle(IFSelect_Signature) sty = STEPEdit::SignType();
220     AddSessionItem (sty,"step-type");
221     Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter(sty,Standard_False,Standard_True);
222     AddSessionItem (tys,"step-types");
223
224     //szv:mySignType = sty;
225     
226     //pdn S4133 18.02.99
227     AddSessionItem (new IFSelect_SignAncestor(),"xst-derived");
228
229     Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
230     stdvar->SetProtocol(STEPEdit::Protocol());
231     AddSessionItem (stdvar,"step-derived");
232     
233     Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
234     selsdr->SetInput (xmr);
235     AddSessionItem (selsdr,"step-shape-def-repr");
236
237     AddSessionItem (STEPEdit::NewSelectPlacedItem(),"step-placed-items");
238     // input deja pret avec ModelAll
239     AddSessionItem (STEPEdit::NewSelectShapeRepr(),"step-shape-repr");
240   }
241   
242   //pdn
243   Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
244   stfaces->SetInput (xmr);
245   AddSessionItem (stfaces,"step-faces");
246   
247   Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
248   AddSessionItem (stinst,"step-instances");
249   
250   Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
251   stcurves->SetInput (xmr);
252   AddSessionItem (stcurves,"step-GS-curves");
253   
254   Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
255   assembly->SetInput (xmr);
256   AddSessionItem (assembly,"step-assembly");
257   
258   Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
259   Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
260   AddSessionItem (edhead,"step-header-edit");
261   AddSessionItem (edheadf,"step-header");
262
263   Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
264   Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
265   AddSessionItem (edctx,"step-context-edit");
266   AddSessionItem (edctxf,"step-context");
267
268
269   Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
270   Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
271   AddSessionItem (edsdr,"step-SDR-edit");
272   AddSessionItem (edsdrf,"step-SDR-data");
273 }
274
275 Handle(Interface_InterfaceModel)  STEPControl_Controller::NewModel () const
276 {
277   return STEPEdit::NewModel();
278 }
279
280 //  ####    PROVISOIRE ???   ####
281
282 IFSelect_ReturnStatus  STEPControl_Controller::TransferWriteShape
283   (const TopoDS_Shape& shape,
284    const Handle(Transfer_FinderProcess)& FP,
285    const Handle(Interface_InterfaceModel)& model,
286    const Standard_Integer modeshape) const
287 {
288   if (modeshape < 0 || modeshape > 4) return IFSelect_RetError;
289   Handle(STEPControl_ActorWrite) ActWrite =
290     Handle(STEPControl_ActorWrite)::DownCast(myAdaptorWrite);
291 //    A PRESENT ON PASSE PAR LE PROFILE
292   if (!ActWrite.IsNull()) 
293     ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
294
295   return XSControl_Controller::TransferWriteShape (shape,FP,model,modeshape);
296 }
297
298 Standard_Boolean STEPControl_Controller::Init ()
299 {
300   static Standard_Boolean inic = Standard_False;
301   if (!inic) {
302     Handle(STEPControl_Controller) STEPCTL = new STEPControl_Controller;
303     STEPCTL->AutoRecord();  // avec les noms donnes a la construction
304     XSAlgo::Init();                                                                                                        
305     inic = Standard_True;
306   }
307   return Standard_True;
308 }
309 //=======================================================================
310 //function : Customise
311 //purpose  : 
312 //=======================================================================
313
314 void STEPControl_Controller::Customise(Handle(XSControl_WorkSession)& WS) 
315 {
316   XSControl_Controller::Customise(WS);
317
318   Handle(IFSelect_SelectModelRoots) slr;
319   Handle(Standard_Transient) slr1 = WS->NamedItem("xst-model-roots");
320   if(!slr1.IsNull())
321     slr = Handle(IFSelect_SelectModelRoots)::DownCast(slr1);
322   else  {
323     slr = new IFSelect_SelectModelRoots;
324     WS->AddNamedItem ("xst-model-roots",slr);
325   }
326
327   Handle(STEPSelections_SelectForTransfer) st1= new STEPSelections_SelectForTransfer;
328   st1->SetReader (WS->TransferReader());
329   WS->AddNamedItem ("xst-transferrable-roots",st1);
330
331   if (!slr.IsNull()) {
332     Handle(IFSelect_Signature) sty = STEPEdit::SignType();
333     WS->AddNamedItem ("step-type",sty);
334     
335     Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter(sty,Standard_False,Standard_True);
336     WS->AddNamedItem ("step-types",tys);
337
338         //szv:mySignType = sty;
339     WS->SetSignType( sty );
340     
341     //pdn S4133 18.02.99
342     WS->AddNamedItem ("xst-derived",new IFSelect_SignAncestor());
343     Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
344     stdvar->SetProtocol(STEPEdit::Protocol());
345     WS->AddNamedItem ("step-derived",stdvar);
346     
347     Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
348     selsdr->SetInput (slr);
349     WS->AddNamedItem ("step-shape-def-repr",selsdr);
350     Handle(IFSelect_SelectSignature) selrrs = STEPEdit::NewSelectPlacedItem();
351     WS->AddNamedItem ("step-placed-items",selrrs);
352     Handle(IFSelect_SelectSignature) selsr = STEPEdit::NewSelectShapeRepr();
353     // input deja pret avec ModelAll
354     WS->AddNamedItem ("step-shape-repr",selsr);
355   }
356   
357   //pdn
358   Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
359   stfaces->SetInput (slr);
360   WS->AddNamedItem ("step-faces",stfaces);
361   
362   Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
363   WS->AddNamedItem ("step-instances",stinst);
364   
365   Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
366   stcurves->SetInput (slr);
367   WS->AddNamedItem ("step-GS-curves",stcurves);
368   
369   Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
370   assembly->SetInput (slr);
371   WS->AddNamedItem ("step-assembly",assembly);
372   
373   Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
374   Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
375   WS->AddNamedItem ("step-header-edit",edhead);
376   WS->AddNamedItem ("step-header",edheadf);
377
378   Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
379   Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
380   WS->AddNamedItem ("step-context-edit",edctx);
381   WS->AddNamedItem ("step-context",edctxf);
382
383
384   Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
385   Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
386   WS->AddNamedItem ("step-SDR-edit",edsdr);
387   WS->AddNamedItem ("step-SDR-data",edsdrf);
388
389   
390   
391 }