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