0024023: Revamp the OCCT Handle -- general
[occt.git] / src / IGESControl / IGESControl_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//
d5f74e42 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
973c2be1 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//#58 rln 28.12.98 changing default values for Global Section
15//sln 14.01.2002 OCC51 : verifying whether entry model of method ActorRead is IGESDatat_IGESModel
16
17#include <IGESControl_Controller.ixx>
18#include <IGESSelect_WorkLibrary.hxx>
19#include <IGESToBRep_Actor.hxx>
20#include <IGESData_IGESModel.hxx>
c04c30b3 21#include <IGESData_Protocol.hxx>
7fd59977 22#include <IGESSolid.hxx>
23#include <IGESAppli.hxx>
24
25#include <Interface_Static.hxx>
26#include <IGESSelect_AutoCorrect.hxx>
27#include <IGESSelect_ComputeStatus.hxx>
28#include <IGESSelect_UpdateFileName.hxx>
29#include <IGESSelect_SetGlobalParameter.hxx>
30#include <IGESSelect_FloatFormat.hxx>
31#include <IGESSelect_SelectBypassGroup.hxx>
32#include <IGESSelect_SelectBypassSubfigure.hxx>
33#include <IGESSelect_SelectBasicGeom.hxx>
34#include <IGESSelect_SelectFaces.hxx>
35#include <IGESSelect_SelectPCurves.hxx>
36#include <IGESSelect_SelectVisibleStatus.hxx>
37#include <IGESSelect_SelectSubordinate.hxx>
38#include <IFSelect_SelectType.hxx>
39#include <IGESBasic_SubfigureDef.hxx>
40#include <IGESSelect_IGESTypeForm.hxx>
41#include <IGESSelect_SignStatus.hxx>
42#include <IGESSelect_SignLevelNumber.hxx>
43#include <IGESSelect_SignColor.hxx>
44#include <IGESSelect_IGESName.hxx>
45#include <IFSelect_SignType.hxx>
46#include <IFSelect_SignMultiple.hxx>
47#include <IGESSelect_CounterOfLevelNumber.hxx>
48#include <IFSelect_SignCounter.hxx>
49#include <IGESSelect_EditHeader.hxx>
50#include <IGESSelect_EditDirPart.hxx>
51#include <IFSelect_EditForm.hxx>
52#include <IGESSelect_RemoveCurves.hxx>
53#include <IGESSelect_SetLabel.hxx>
54
55#include <TCollection_HAsciiString.hxx>
56
57#include <IGESControl_ActorWrite.hxx>
58#include <IGESControl_AlgoContainer.hxx>
59
60#include <XSAlgo.hxx>
61#include <Interface_Macros.hxx>
62#include <IGESToBRep.hxx>
63#include <IFSelect_SelectModelEntities.hxx>
64#include <IFSelect_SelectModelEntities.hxx>
65#include <IFSelect_SelectModelRoots.hxx>
66#include <XSControl_SelectForTransfer.hxx>
67
68//szv#4:S4163:12Mar99 never referenced
69//static const Standard_CString thelong = "IGES";
70//static const Standard_CString theshort = "iges";
71
72//=======================================================================
73//function : IGESControl_Controller
74//purpose :
75//=======================================================================
76
77IGESControl_Controller::IGESControl_Controller (const Standard_Boolean mod)
78//JR/Hp
79 : XSControl_Controller ((Standard_CString ) (mod ? "FNES" : "IGES") , (Standard_CString ) (mod ? "fnes" : "iges") ) ,
80// : XSControl_Controller ( (mod ? "FNES" : "iges") , (mod ? "fnes" : "iges") ) ,
81 themode (mod)
82{
83 static Standard_Boolean init = Standard_False;
84 if (!init) {
85 IGESSolid::Init();
86 IGESAppli::Init();
87 init = Standard_True;
88 }
89 AddSessionItem (new IGESSelect_RemoveCurves(Standard_True) ,"iges-remove-pcurves");
90 AddSessionItem (new IGESSelect_RemoveCurves(Standard_False),"iges-remove-curves-3d");
91 AddSessionItem (new IGESSelect_SetLabel (0,Standard_True) ,"iges-clear-label");
92 AddSessionItem (new IGESSelect_SetLabel (1,Standard_False),"iges-set-label-dnum");
93
94 AddSessionItem (new IGESSelect_AutoCorrect,"iges-auto-correct","send");
95 AddSessionItem (new IGESSelect_ComputeStatus,"iges-compute-status","send");
96 Handle(IGESSelect_FloatFormat) flf = new IGESSelect_FloatFormat;
97 flf->SetDefault (12);
98 AddSessionItem (flf,"iges-float-digits-12","send");
99
100// -- Sender Product Identification -- (pas un statique ...)
101 Handle(IGESSelect_SetGlobalParameter) set3 = new IGESSelect_SetGlobalParameter(3);
102//#58 rln Handle(TCollection_HAsciiString) pa3 = new TCollection_HAsciiString("MDTV X-STEP");
103 Handle(TCollection_HAsciiString) pa3 =
104 Interface_Static::Static("write.iges.header.product")->HStringValue();
105 set3->SetValue(pa3);
106 AddSessionItem (pa3, "iges-header-val-sender");
107 AddSessionItem (set3,"iges-header-set-sender","send");
108
109 AddSessionItem (new IGESSelect_UpdateFileName,"iges-update-file-name","send");
110
111// -- Receiver -- Acces par Static, ajustable
112 Handle(IGESSelect_SetGlobalParameter) set12 = new IGESSelect_SetGlobalParameter(12);
113// Handle(TCollection_HAsciiString) pa12 = new TCollection_HAsciiString("Unknown");
114 Handle(TCollection_HAsciiString) pa12 =
115 Interface_Static::Static("write.iges.header.receiver")->HStringValue();
116 set12->SetValue(pa12);
117 AddSessionItem (pa12, "iges-header-val-receiver");
118 AddSessionItem (set12,"iges-header-set-receiver","send");
119
120// -- Auteur -- acces par Static (demarre par whoami), ajustable
121 Handle(IGESSelect_SetGlobalParameter) set21 = new IGESSelect_SetGlobalParameter(21);
122// Handle(TCollection_HAsciiString) pa21 = new TCollection_HAsciiString("Unknown");
123 Handle(TCollection_HAsciiString) pa21 =
124 Interface_Static::Static("write.iges.header.author")->HStringValue();
125 set21->SetValue(pa21);
126 AddSessionItem (pa21, "iges-header-val-author");
127 AddSessionItem (set21,"iges-header-set-author","send");
128
129// -- Compagnie (de l auteur) -- acces par Static, ajustable
130 Handle(IGESSelect_SetGlobalParameter) set22 = new IGESSelect_SetGlobalParameter(22);
131// Handle(TCollection_HAsciiString) pa22 = new TCollection_HAsciiString("MATRA-DATAVISION");
132 Handle(TCollection_HAsciiString) pa22 =
133 Interface_Static::Static("write.iges.header.company")->HStringValue();
134 set22->SetValue(pa22);
135 AddSessionItem (pa22, "iges-header-val-company");
136 AddSessionItem (set22,"iges-header-set-company","send");
137 // -- STATICS
138
139 TraceStatic ("read.iges.bspline.approxd1.mode",5);
140 TraceStatic ("read.iges.bspline.continuity",5);
141
142 TraceStatic ("write.iges.header.receiver",2);
143 TraceStatic ("write.iges.header.author",2);
144 TraceStatic ("write.iges.header.company",2);
145 TraceStatic ("write.iges.unit",6);
146 TraceStatic ("write.iges.brep.mode",6);
147
148 theAdaptorLibrary = new IGESSelect_WorkLibrary(themode);
149 theAdaptorProtocol = IGESSelect_WorkLibrary::DefineProtocol();
150
151 Handle(IGESToBRep_Actor) anactiges = new IGESToBRep_Actor;
152 anactiges->SetContinuity(0);
153 theAdaptorRead = anactiges;
154
155 theAdaptorWrite = new IGESControl_ActorWrite;
156 SetModeWrite (0,1);
157 SetModeWriteHelp (0,"Faces");
158 SetModeWriteHelp (1,"BRep");
159}
160void IGESControl_Controller::Customise(Handle(XSControl_WorkSession)& WS)
161{
162 XSControl_Controller::Customise(WS);
163
164
165// --- SELECTIONS, SIGNATURES, COMPTEURS, EDITEURS
166// -- BypassGroup / xst-model-roots
167
168
169 //DeclareAndCast(IFSelect_Selection,xma,SessionItem("xst-model-all"));
170 Handle(IFSelect_SelectModelEntities) xma;
171 Handle(Standard_Transient) xma1 = WS->NamedItem("xst-model-all");
172 if(xma1.IsNull()) xma = new IFSelect_SelectModelEntities;
173 else {
174 xma =Handle(IFSelect_SelectModelEntities)::DownCast(xma1);
175 WS->AddNamedItem ("xst-model-all",xma);
176 }
177
178 //DeclareAndCast(IFSelect_Selection,xmr,SessionItem("xst-model-roots"));
179 Handle(IFSelect_SelectModelRoots) xmr;
180 Handle(Standard_Transient) xmr1 = WS->NamedItem("xst-model-roots");
181 if(!xmr1.IsNull())
182 xmr = Handle(IFSelect_SelectModelRoots)::DownCast(xmr1);
183 else {
184 xmr = new IFSelect_SelectModelRoots;
185 WS->AddNamedItem ("xst-model-roots",xmr);
186 }
187// DeclareAndCast(IFSelect_Selection,xtr,SessionItem("xst-transferrable-roots"));
188 Handle(XSControl_SelectForTransfer) xtr;
189 Handle(Standard_Transient) xtr1 = WS->NamedItem("xst-transferrable-roots");
190 if(!xtr1.IsNull())
191 xtr = Handle(XSControl_SelectForTransfer)::DownCast(xtr1);
192 //st1->SetInput (slr);
193 else {
194 xtr= new XSControl_SelectForTransfer;
195 xtr->SetReader (WS->TransferReader());
196 WS->AddNamedItem ("xst-transferrable-roots",xtr);
197 }
198 if (!xmr.IsNull()) {
199 Handle(IGESSelect_SelectVisibleStatus) visa = new IGESSelect_SelectVisibleStatus;
200 visa->SetInput(xmr);
201 WS->AddNamedItem ("iges-visible-roots",visa);
202 Handle(IGESSelect_SelectVisibleStatus) vist = new IGESSelect_SelectVisibleStatus;
203 vist->SetInput(xtr);
204 WS->AddNamedItem ("iges-visible-transf-roots",vist);
205 Handle(IGESSelect_SelectVisibleStatus) blka = new IGESSelect_SelectVisibleStatus;
206 blka->SetDirect (Standard_False);
207 blka->SetInput(xmr);
208 WS->AddNamedItem ("iges-blanked-roots",blka);
209 Handle(IGESSelect_SelectVisibleStatus) blkt = new IGESSelect_SelectVisibleStatus;
210 blkt->SetDirect (Standard_False);
211 blkt->SetInput(xtr);
212 WS->AddNamedItem ("iges-blanked-transf-roots",blkt);
213 Handle(IGESSelect_SelectSubordinate) indp = new IGESSelect_SelectSubordinate (0);
214 indp->SetInput (xma);
215 WS->AddNamedItem ("iges-status-independant",indp);
216
217 Handle(IGESSelect_SelectBypassGroup) sb = new IGESSelect_SelectBypassGroup;
218 sb->SetInput(xmr);
219 WS->AddNamedItem ("iges-bypass-group",sb);
220 Handle(IGESSelect_SelectBypassSubfigure) sfi = new IGESSelect_SelectBypassSubfigure;
221 sfi->SetInput(xmr);
222 WS->AddNamedItem ("iges-bypass-subfigure",sfi);
223 Handle(IGESSelect_SelectBypassGroup) sfb = new IGESSelect_SelectBypassGroup;
224 sfb->SetInput(sfi);
225 WS->AddNamedItem ("iges-bypass-group-subfigure",sfb);
226 Handle(IGESSelect_SelectBasicGeom) sc3d = new IGESSelect_SelectBasicGeom(1);
227 sc3d->SetInput(sfi);
228 WS->AddNamedItem ("iges-curves-3d",sc3d);
229 Handle(IGESSelect_SelectBasicGeom) sb3d = new IGESSelect_SelectBasicGeom(2);
230 sb3d->SetInput(sfi);
231 WS->AddNamedItem ("iges-basic-curves-3d",sb3d);
232 Handle(IGESSelect_SelectBasicGeom) sbg = new IGESSelect_SelectBasicGeom(0);
233 sbg->SetInput(sfi);
234 WS->AddNamedItem ("iges-basic-geom",sbg);
235 Handle(IGESSelect_SelectBasicGeom) srf = new IGESSelect_SelectBasicGeom(-1);
236 srf->SetInput(sfi);
237 WS->AddNamedItem ("iges-surfaces",srf);
238 Handle(IGESSelect_SelectFaces) sfa = new IGESSelect_SelectFaces;
239 sfa->SetInput(sfi);
240 WS->AddNamedItem ("iges-faces",sfa );
241 Handle(IGESSelect_SelectPCurves) spc = new IGESSelect_SelectPCurves(Standard_True);
242 spc->SetInput(sfa);
243 WS->AddNamedItem ("iges-pcurves",spc);
244
245 Handle(IFSelect_SelectType) snosub = new IFSelect_SelectType
246 (STANDARD_TYPE(IGESBasic_SubfigureDef));
247 snosub->SetDirect(Standard_False);
248 snosub->SetInput(xmr);
249 WS->AddNamedItem ("iges-no-indep-subfigure-def",snosub);
250
251 Handle(IGESSelect_IGESTypeForm) itf = new IGESSelect_IGESTypeForm(Standard_True);
252 WS->AddNamedItem ("iges-type",itf);
253
254 Handle(IGESSelect_SignStatus) sigst = new IGESSelect_SignStatus;
255 Handle(IFSelect_SignMultiple) typsta = new IFSelect_SignMultiple
256 ("IGES Type Form Status");
257 typsta->Add (itf,15);
258 typsta->Add (sigst);
259 WS->AddNamedItem ("iges-type-status",typsta);
260
261 Handle(IFSelect_SignMultiple) typnam = new IFSelect_SignMultiple
262 ("IGES Type Form TypeName");
263 typnam->Add (itf,4);
264 typnam->Add (new IFSelect_SignType(Standard_True));
265 WS->AddNamedItem ("iges-type-name",typnam);
266
267 Handle(IFSelect_SignCounter) itfs = new IFSelect_SignCounter
268 (itf,Standard_False,Standard_True);
269 WS->AddNamedItem ("iges-types",itfs);
270 Handle(IGESSelect_CounterOfLevelNumber) levs =
271 new IGESSelect_CounterOfLevelNumber;
272 WS->AddNamedItem ("iges-levels",levs);
273
274 Handle(IGESSelect_SignLevelNumber) slev = new IGESSelect_SignLevelNumber(Standard_False);
275 WS->AddNamedItem ("iges-level-number",slev);
276 Handle(IGESSelect_IGESName) igna = new IGESSelect_IGESName;
277 WS->AddNamedItem ("iges-name",igna);
278
279 Handle(IGESSelect_SignColor) scol1 = new IGESSelect_SignColor (1);
280 WS->AddNamedItem ("iges-color-number",scol1);
281 Handle(IGESSelect_SignColor) scol2 = new IGESSelect_SignColor (2);
282 WS->AddNamedItem ("iges-color-name",scol2);
283 Handle(IGESSelect_SignColor) scol3 = new IGESSelect_SignColor (3);
284 WS->AddNamedItem ("iges-color-rgb",scol3);
285 Handle(IGESSelect_SignColor) scol4 = new IGESSelect_SignColor (4);
286 WS->AddNamedItem ("iges-color-red",scol4);
287 Handle(IGESSelect_SignColor) scol5 = new IGESSelect_SignColor (5);
288 WS->AddNamedItem ("iges-color-green",scol5);
289 Handle(IGESSelect_SignColor) scol6 = new IGESSelect_SignColor (6);
290 WS->AddNamedItem ("iges-color-blue",scol6);
291
292 Handle(IGESSelect_EditHeader) edhead = new IGESSelect_EditHeader;
293 WS->AddNamedItem ("iges-header-edit",edhead);
294 Handle(IFSelect_EditForm) edheadf = edhead->Form(Standard_False);
295 WS->AddNamedItem ("iges-header",edheadf);
296
297 Handle(IGESSelect_EditDirPart) eddirp = new IGESSelect_EditDirPart;
298 WS->AddNamedItem ("iges-dir-part-edit",eddirp);
299 Handle(IFSelect_EditForm) eddirpf = eddirp->Form(Standard_False);
300 WS->AddNamedItem ("iges-dir-part",eddirpf);
301
302 theSignType = typnam;
303 }
304
305
306}
307
308
309//=======================================================================
310//function : NewModel
311//purpose :
312//=======================================================================
313
314 Handle(Interface_InterfaceModel) IGESControl_Controller::NewModel () const
315{
316// On prend un modele qu on prepare avec les statiques enregistres
317 DeclareAndCast(IGESData_IGESModel,igm,Interface_InterfaceModel::Template("iges"));
318 IGESData_GlobalSection GS = igm->GlobalSection();
319
320 GS.SetReceiveName (Interface_Static::Static("write.iges.header.receiver")->HStringValue());
321 GS.SetUnitFlag (Interface_Static::IVal("write.iges.unit"));
322 GS.SetUnitName (new TCollection_HAsciiString(Interface_Static::CVal("write.iges.unit")));
323 GS.SetAuthorName (Interface_Static::Static("write.iges.header.author")->HStringValue());
324 GS.SetCompanyName (Interface_Static::Static("write.iges.header.company")->HStringValue());
325 igm->SetGlobalSection (GS);
326 return igm;
327}
328
329//=======================================================================
330//function : ActorRead
331//purpose :
332//=======================================================================
333
334 Handle(Transfer_ActorOfTransientProcess) IGESControl_Controller::ActorRead
335 (const Handle(Interface_InterfaceModel)& model) const
336{
337 DeclareAndCast(IGESToBRep_Actor,anactiges,theAdaptorRead);
338 if (anactiges.IsNull()) return theAdaptorRead;
339 //sln 14.01.2002 OCC51 : verifying whether entry model is IGESDatat_IGESModel,
340 // if this condition is false new model is created
341 Handle(Interface_InterfaceModel) aModel;
342 if(model->IsKind(STANDARD_TYPE(IGESData_IGESModel)))
343 aModel = model;
344 else
345 aModel = NewModel();
346 anactiges->SetModel(GetCasted(IGESData_IGESModel,aModel));
347 anactiges->SetContinuity(Interface_Static::IVal("read.iges.bspline.continuity"));
348 return anactiges;
349}
350
351// #### TRANSFERT (ECRITURE SHAPE) ####
352// modetrans : 0 <5.1 (groupe de faces), 1 BREP-5.1
353
354//=======================================================================
355//function : TransferWriteShape
356//purpose :
357//=======================================================================
358
359 IFSelect_ReturnStatus IGESControl_Controller::TransferWriteShape (const TopoDS_Shape& shape,
360 const Handle(Transfer_FinderProcess)& FP,
361 const Handle(Interface_InterfaceModel)& model,
362 const Standard_Integer modetrans) const
363{
364 return XSControl_Controller::TransferWriteShape (shape,FP,model,modetrans);
365}
366
367//=======================================================================
368//function : Init
369//purpose :
370//=======================================================================
371
372 Standard_Boolean IGESControl_Controller::Init ()
373{
374 static Standard_Boolean inic = Standard_False;
375 if (!inic) {
376 Handle(IGESControl_Controller) ADIGES = new IGESControl_Controller(Standard_False);
377 ADIGES->AutoRecord();
378 XSAlgo::Init();
379 IGESToBRep::Init();
380 IGESToBRep::SetAlgoContainer (new IGESControl_AlgoContainer());
381 inic = Standard_True;
382 }
383 return Standard_True;
384}