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