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