0024428: Implementation of LGPL license
[occt.git] / src / STEPControl / STEPControl_Controller.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 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
60STEPControl_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 // abv 15.11.00: ShapeProcessing
182 Interface_Static::Init ("XSTEP","write.step.resource.name",'t',"STEP");
183 Interface_Static::Init ("XSTEP","read.step.resource.name",'t',"STEP");
184 Interface_Static::Init ("XSTEP","write.step.sequence",'t',"ToSTEP");
185 Interface_Static::Init ("XSTEP","read.step.sequence",'t',"FromSTEP");
186
187 init = Standard_True;
188 }
189
190 Handle(STEPControl_ActorWrite) ActWrite = new STEPControl_ActorWrite;
191 ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
192 theAdaptorWrite = ActWrite;
193
194 Handle(StepSelect_WorkLibrary) swl = new StepSelect_WorkLibrary;
195 swl->SetDumpLabel(1);
196 theAdaptorLibrary = swl;
197 theAdaptorProtocol = STEPEdit::Protocol();
198// theAdaptorProtocol = StepAP214::Protocol();
199 theAdaptorRead = new STEPControl_ActorRead; // par ex pour Recognize
200
201 SetModeWrite (0,4);
202 SetModeWriteHelp (0,"As Is");
203 SetModeWriteHelp (1,"Faceted Brep");
204 SetModeWriteHelp (2,"Shell Based");
205 SetModeWriteHelp (3,"Manifold Solid");
206 SetModeWriteHelp (4,"Wireframe");
207 TraceStatic ("read.surfacecurve.mode",5);
208
209// --- SELECTIONS, SIGNATURES, COMPTEURS, EDITEURS
210
211 DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
212 if (!xmr.IsNull()) {
213 Handle(IFSelect_Signature) sty = STEPEdit::SignType();
214 AddSessionItem (sty,"step-type");
215 Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter
216 (sty,Standard_False,Standard_True);
217 AddSessionItem (tys,"step-types");
218 theSignType = sty;
219
220
221 //pdn S4133 18.02.99
222 Handle(IFSelect_SignAncestor)sta = new IFSelect_SignAncestor();
223 AddSessionItem (sta,"xst-derived");
224 Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
225 stdvar->SetProtocol(STEPEdit::Protocol());
226 AddSessionItem (stdvar,"step-derived");
227
228 Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
229 selsdr->SetInput (xmr);
230 AddSessionItem (selsdr,"step-shape-def-repr");
231 Handle(IFSelect_SelectSignature) selrrs = STEPEdit::NewSelectPlacedItem();
232// selrrs->SetInput (xmr); deja prete avec ModelAll
233 AddSessionItem (selrrs,"step-placed-items");
234 Handle(IFSelect_SelectSignature) selsr = STEPEdit::NewSelectShapeRepr();
235// input deja pret avec ModelAll
236 AddSessionItem (selsr,"step-shape-repr");
237 }
238
239 //pdn
240 Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
241 stfaces->SetInput (xmr);
242 AddSessionItem (stfaces,"step-faces");
243
244 Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
245 AddSessionItem (stinst,"step-instances");
246
247 Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
248 stcurves->SetInput (xmr);
249 AddSessionItem (stcurves,"step-GS-curves");
250
251 Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
252 assembly->SetInput (xmr);
253 AddSessionItem (assembly,"step-assembly");
254
255 Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
256 Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
257 AddSessionItem (edhead,"step-header-edit");
258 AddSessionItem (edheadf,"step-header");
259
260 Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
261 Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
262 AddSessionItem (edctx,"step-context-edit");
263 AddSessionItem (edctxf,"step-context");
264
265
266 Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
267 Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
268 AddSessionItem (edsdr,"step-SDR-edit");
269 AddSessionItem (edsdrf,"step-SDR-data");
270
271// #### PROFILE ####
272
273// ActorRead : on ajoute le cas Shape possible, a part du default
274// ainsi, on l a tjrs sous la main
275 Handle(IFSelect_Option) optacrd = Profile()->Option("tr-read");
276 optacrd->Add ("shape",theAdaptorRead);
277
278// ActorWrite : on ajoute les cas possibles (NB : shape == default)
279// On garde a part les cas shape compound (= shape traitee globale ou en
280// assembly), peuvent etre utiles. Tandis que les autres cas sont
281// susceptibles d etre remplaces si on fait du Model-Editor
282 Handle(IFSelect_Option) optacwr = Profile()->Option("tr-write");
283 Handle(STEPControl_ActorWrite) ActWSh = new STEPControl_ActorWrite;
284 ActWSh->SetGroupMode(0);
285 optacwr->Add ("shape",ActWSh);
286 Handle(STEPControl_ActorWrite) ActWA1 = new STEPControl_ActorWrite;
287 ActWA1->SetGroupMode(1);
288 optacwr->Add ("compound",ActWA1);
289 optacwr->Add ("assembly",ActWA1);
290 optacwr->Add ("SRWT",ActWA1);
291
292 Profile()->AddConf ("Shape");
293 Profile()->AddSwitch ("Shape","tr-write","shape");
294
295 Profile()->AddConf ("Assembly");
296 Profile()->AddSwitch ("Assembly","tr-write","SRWT");
297}
298
299Handle(Interface_InterfaceModel) STEPControl_Controller::NewModel () const
300{
301 return STEPEdit::NewModel();
302}
303
304Handle(Transfer_ActorOfTransientProcess) STEPControl_Controller::ActorRead
305 (const Handle(Interface_InterfaceModel)& ) const
306{
307 return theAdaptorRead;
308} // new Cc1ToTopoDSAct_Actor ??
309
310// #### PROVISOIRE ??? ####
311
312IFSelect_ReturnStatus STEPControl_Controller::TransferWriteShape
313 (const TopoDS_Shape& shape,
314 const Handle(Transfer_FinderProcess)& FP,
315 const Handle(Interface_InterfaceModel)& model,
316 const Standard_Integer modeshape) const
317{
318 if (modeshape < 0 || modeshape > 4) return IFSelect_RetError;
319 Handle(STEPControl_ActorWrite) ActWrite =
320 Handle(STEPControl_ActorWrite)::DownCast(theAdaptorWrite);
321// A PRESENT ON PASSE PAR LE PROFILE
322 if (!ActWrite.IsNull())
323 ActWrite->SetGroupMode (Interface_Static::IVal("write.step.assembly"));
324
325 return XSControl_Controller::TransferWriteShape (shape,FP,model,modeshape);
326}
327
328Standard_Boolean STEPControl_Controller::Init ()
329{
330 static Standard_Boolean inic = Standard_False;
331 if (!inic) {
332 Handle(STEPControl_Controller) STEPCTL = new STEPControl_Controller;
333 STEPCTL->AutoRecord(); // avec les noms donnes a la construction
334 XSAlgo::Init();
335 inic = Standard_True;
336 }
337 return Standard_True;
338}
339//=======================================================================
340//function : Customise
341//purpose :
342//=======================================================================
343
344 void STEPControl_Controller::Customise(Handle(XSControl_WorkSession)& WS)
345{
346 XSControl_Controller::Customise(WS);
347 Handle(IFSelect_SelectModelRoots) slr;
348 Handle(Standard_Transient) slr1 = WS->NamedItem("xst-model-roots");
349 if(!slr1.IsNull())
350 slr = Handle(IFSelect_SelectModelRoots)::DownCast(slr1);
351 else {
352 slr = new IFSelect_SelectModelRoots;
353 WS->AddNamedItem ("xst-model-roots",slr);
354 }
355
356
357 Handle(STEPSelections_SelectForTransfer) st1= new STEPSelections_SelectForTransfer;
358 st1->SetReader (WS->TransferReader());
359 WS->AddNamedItem ("xst-transferrable-roots",st1);
360
361
362 //DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
363 if (!slr.IsNull()) {
364 Handle(IFSelect_Signature) sty = STEPEdit::SignType();
365 WS->AddNamedItem ("step-type",sty);
366
367 Handle(IFSelect_SignCounter) tys = new IFSelect_SignCounter
368 (sty,Standard_False,Standard_True);
369 WS->AddNamedItem ("step-types",tys);
370 theSignType = sty;
371
372
373 //pdn S4133 18.02.99
374 Handle(IFSelect_SignAncestor)sta = new IFSelect_SignAncestor();
375 WS->AddNamedItem ("xst-derived",sta);
376 Handle(STEPSelections_SelectDerived) stdvar = new STEPSelections_SelectDerived();
377 stdvar->SetProtocol(STEPEdit::Protocol());
378 WS->AddNamedItem ("step-derived",stdvar);
379
380 Handle(IFSelect_SelectSignature) selsdr = STEPEdit::NewSelectSDR();
381 selsdr->SetInput (slr);
382 WS->AddNamedItem ("step-shape-def-repr",selsdr);
383 Handle(IFSelect_SelectSignature) selrrs = STEPEdit::NewSelectPlacedItem();
384// selrrs->SetInput (slr); deja prete avec ModelAll
385 WS->AddNamedItem ("step-placed-items",selrrs);
386 Handle(IFSelect_SelectSignature) selsr = STEPEdit::NewSelectShapeRepr();
387// input deja pret avec ModelAll
388 WS->AddNamedItem ("step-shape-repr",selsr);
389 }
390
391 //pdn
392 Handle(STEPSelections_SelectFaces) stfaces = new STEPSelections_SelectFaces;
393 stfaces->SetInput (slr);
394 WS->AddNamedItem ("step-faces",stfaces);
395
396 Handle(STEPSelections_SelectInstances) stinst = new STEPSelections_SelectInstances;
397 WS->AddNamedItem ("step-instances",stinst);
398
399 Handle(STEPSelections_SelectGSCurves) stcurves = new STEPSelections_SelectGSCurves;
400 stcurves->SetInput (slr);
401 WS->AddNamedItem ("step-GS-curves",stcurves);
402
403 Handle(STEPSelections_SelectAssembly) assembly = new STEPSelections_SelectAssembly;
404 assembly->SetInput (slr);
405 WS->AddNamedItem ("step-assembly",assembly);
406
407 Handle(APIHeaderSection_EditHeader) edhead = new APIHeaderSection_EditHeader;
408 Handle(IFSelect_EditForm) edheadf = new IFSelect_EditForm (edhead,Standard_False,Standard_True,"Step Header");
409 WS->AddNamedItem ("step-header-edit",edhead);
410 WS->AddNamedItem ("step-header",edheadf);
411
412 Handle(STEPEdit_EditContext) edctx = new STEPEdit_EditContext;
413 Handle(IFSelect_EditForm) edctxf = new IFSelect_EditForm (edctx,Standard_False,Standard_True,"STEP Product Definition Context");
414 WS->AddNamedItem ("step-context-edit",edctx);
415 WS->AddNamedItem ("step-context",edctxf);
416
417
418 Handle(STEPEdit_EditSDR) edsdr = new STEPEdit_EditSDR;
419 Handle(IFSelect_EditForm) edsdrf = new IFSelect_EditForm (edsdr,Standard_False,Standard_True,"STEP Product Data (SDR)");
420 WS->AddNamedItem ("step-SDR-edit",edsdr);
421 WS->AddNamedItem ("step-SDR-data",edsdrf);
422
423
424
425}