0026937: Eliminate NO_CXX_EXCEPTION macro support
[occt.git] / src / XSControl / XSControl_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
42cf5bc1 15#include <IFSelect_DispPerCount.hxx>
16#include <IFSelect_DispPerFiles.hxx>
17#include <IFSelect_DispPerOne.hxx>
18#include <IFSelect_DispPerSignature.hxx>
19#include <IFSelect_EditForm.hxx>
20#include <IFSelect_GeneralModifier.hxx>
21#include <IFSelect_GraphCounter.hxx>
22#include <IFSelect_IntParam.hxx>
23#include <IFSelect_ParamEditor.hxx>
7fd59977 24#include <IFSelect_SelectModelEntities.hxx>
25#include <IFSelect_SelectModelRoots.hxx>
26#include <IFSelect_SelectPointed.hxx>
7fd59977 27#include <IFSelect_SelectShared.hxx>
42cf5bc1 28#include <IFSelect_SelectSharing.hxx>
c04c30b3 29#include <IFSelect_ShareOut.hxx>
42cf5bc1 30#include <IFSelect_SignAncestor.hxx>
31#include <IFSelect_Signature.hxx>
7fd59977 32#include <IFSelect_SignCategory.hxx>
42cf5bc1 33#include <IFSelect_SignCounter.hxx>
34#include <IFSelect_SignType.hxx>
7fd59977 35#include <IFSelect_SignValidity.hxx>
42cf5bc1 36#include <IFSelect_WorkLibrary.hxx>
37#include <Interface_CheckIterator.hxx>
38#include <Interface_InterfaceModel.hxx>
39#include <Interface_Macros.hxx>
40#include <Interface_Protocol.hxx>
7fd59977 41#include <Interface_Static.hxx>
42cf5bc1 42#include <Message.hxx>
43#include <Message_Messenger.hxx>
42cf5bc1 44#include <Standard_DomainError.hxx>
45#include <Standard_Transient.hxx>
46#include <Standard_Type.hxx>
47#include <TCollection_HAsciiString.hxx>
48#include <TColStd_HSequenceOfHAsciiString.hxx>
49#include <TColStd_IndexedMapOfTransient.hxx>
50#include <TopoDS_Shape.hxx>
51#include <Transfer_ActorOfFinderProcess.hxx>
52#include <Transfer_ActorOfTransientProcess.hxx>
7fd59977 53#include <Transfer_Binder.hxx>
42cf5bc1 54#include <Transfer_FinderProcess.hxx>
7fd59977 55#include <Transfer_SimpleBinderOfTransient.hxx>
56#include <Transfer_TransientMapper.hxx>
57#include <TransferBRep_ShapeMapper.hxx>
42cf5bc1 58#include <XSControl_ConnectedShapes.hxx>
59#include <XSControl_Controller.hxx>
60#include <XSControl_SelectForTransfer.hxx>
61#include <XSControl_SignTransferStatus.hxx>
62#include <XSControl_TransferReader.hxx>
63#include <XSControl_WorkSession.hxx>
7fd59977 64
92efcf78 65IMPLEMENT_STANDARD_RTTIEXT(XSControl_Controller,MMgt_TShared)
66
42cf5bc1 67// ParamEditor
68// Transferts
997e128f 69
70static NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)> listad;
7fd59977 71
7f56eba8 72//=======================================================================
73//function : XSControl_Controller
74//purpose : Constructor
75//=======================================================================
7fd59977 76
7f56eba8 77XSControl_Controller::XSControl_Controller (const Standard_CString theLongName, const Standard_CString theShortName)
78: myShortName(theShortName), myLongName(theLongName)
7fd59977 79{
7f56eba8 80 // Standard parameters
7fd59977 81 Interface_Static::Standards();
7fd59977 82 TraceStatic ("read.precision.mode" , 5);
83 TraceStatic ("read.precision.val" , 5);
84 TraceStatic ("write.precision.mode" , 6);
85 TraceStatic ("write.precision.val" , 6);
7f56eba8 86}
7fd59977 87
7f56eba8 88//=======================================================================
89//function : TraceStatic
90//purpose :
91//=======================================================================
7fd59977 92
7f56eba8 93void XSControl_Controller::TraceStatic (const Standard_CString theName, const Standard_Integer theUse)
94{
95 Handle(Interface_Static) val = Interface_Static::Static(theName);
96 if (val.IsNull()) return;
97 myParams.Append (val);
98 myParamUses.Append(theUse);
7fd59977 99}
100
7f56eba8 101//=======================================================================
102//function : SetNames
103//purpose :
104//=======================================================================
105
106void XSControl_Controller::SetNames (const Standard_CString theLongName, const Standard_CString theShortName)
7fd59977 107{
7f56eba8 108 if (theLongName && theLongName[0] != '\0') {
109 myLongName.Clear(); myLongName.AssignCat (theLongName);
7fd59977 110 }
7f56eba8 111 if (theShortName && theShortName[0] != '\0') {
112 myShortName.Clear(); myShortName.AssignCat(theShortName);
7fd59977 113 }
114}
115
7f56eba8 116//=======================================================================
117//function : Record
118//purpose :
119//=======================================================================
7fd59977 120
7f56eba8 121void XSControl_Controller::Record (const Standard_CString theName) const
7fd59977 122{
997e128f 123 if (listad.IsBound(theName)) {
124 Handle(Standard_Transient) thisadapt(this);
125 Handle(Standard_Transient) newadapt = listad.ChangeFind(theName);
7f56eba8 126 if (newadapt->IsKind(thisadapt->DynamicType()))
127 return;
128 if (!(thisadapt->IsKind(newadapt->DynamicType())) && thisadapt != newadapt)
9775fa61 129 throw Standard_DomainError("XSControl_Controller : Record");
7fd59977 130 }
997e128f 131 listad.Bind(theName, this);
7fd59977 132}
133
7f56eba8 134//=======================================================================
135//function : Recorded
136//purpose :
137//=======================================================================
7fd59977 138
997e128f 139Handle(XSControl_Controller) XSControl_Controller::Recorded(const Standard_CString theName)
7fd59977 140{
7f56eba8 141 Handle(Standard_Transient) recorded;
997e128f 142 return (listad.Find(theName, recorded)?
7f56eba8 143 Handle(XSControl_Controller)::DownCast(recorded) :
144 Handle(XSControl_Controller)());
7fd59977 145}
146
7f56eba8 147// #### DEFINITION ####
7fd59977 148
7f56eba8 149//=======================================================================
150//function : ActorRead
151//purpose :
152//=======================================================================
7fd59977 153
7f56eba8 154Handle(Transfer_ActorOfTransientProcess) XSControl_Controller::ActorRead (const Handle(Interface_InterfaceModel)&) const
7fd59977 155{
7f56eba8 156 return myAdaptorRead;
7fd59977 157}
158
7f56eba8 159//=======================================================================
160//function : ActorWrite
161//purpose :
162//=======================================================================
7fd59977 163
7f56eba8 164Handle(Transfer_ActorOfFinderProcess) XSControl_Controller::ActorWrite () const
7fd59977 165{
7f56eba8 166 return myAdaptorWrite;
7fd59977 167}
168
7fd59977 169// ###########################
170// Help du Transfer : controle de valeur + help
171
7f56eba8 172//=======================================================================
173//function : SetModeWrite
174//purpose :
175//=======================================================================
176
177void XSControl_Controller::SetModeWrite
178 (const Standard_Integer modemin, const Standard_Integer modemax, const Standard_Boolean )
7fd59977 179{
7f56eba8 180 if (modemin > modemax) { myModeWriteShapeN.Nullify(); return; }
181 myModeWriteShapeN = new Interface_HArray1OfHAsciiString (modemin,modemax);
7fd59977 182}
183
7f56eba8 184//=======================================================================
185//function : SetModeWriteHelp
186//purpose :
187//=======================================================================
188
189void XSControl_Controller::SetModeWriteHelp
190 (const Standard_Integer modetrans, const Standard_CString help, const Standard_Boolean )
7fd59977 191{
7f56eba8 192 if (myModeWriteShapeN.IsNull()) return;
193 if (modetrans < myModeWriteShapeN->Lower() ||
194 modetrans > myModeWriteShapeN->Upper()) return;
7fd59977 195 Handle(TCollection_HAsciiString) hl = new TCollection_HAsciiString (help);
7f56eba8 196 myModeWriteShapeN->SetValue (modetrans,hl);
7fd59977 197}
198
7f56eba8 199//=======================================================================
200//function : ModeWriteBounds
201//purpose :
202//=======================================================================
203
204Standard_Boolean XSControl_Controller::ModeWriteBounds
205 (Standard_Integer& modemin, Standard_Integer& modemax, const Standard_Boolean ) const
7fd59977 206{
207 modemin = modemax = 0;
7f56eba8 208 if (myModeWriteShapeN.IsNull()) return Standard_False;
209 modemin = myModeWriteShapeN->Lower();
210 modemax = myModeWriteShapeN->Upper();
7fd59977 211 return Standard_True;
212}
213
7f56eba8 214//=======================================================================
215//function : IsModeWrite
216//purpose :
217//=======================================================================
218
219Standard_Boolean XSControl_Controller::IsModeWrite
7fd59977 220 (const Standard_Integer modetrans, const Standard_Boolean ) const
221{
7f56eba8 222 if (myModeWriteShapeN.IsNull()) return Standard_True;
223 if (modetrans < myModeWriteShapeN->Lower()) return Standard_False;
224 if (modetrans > myModeWriteShapeN->Upper()) return Standard_False;
7fd59977 225 return Standard_True;
226}
227
7f56eba8 228//=======================================================================
229//function : ModeWriteHelp
230//purpose :
231//=======================================================================
232
233Standard_CString XSControl_Controller::ModeWriteHelp
7fd59977 234 (const Standard_Integer modetrans, const Standard_Boolean ) const
235{
7f56eba8 236 if (myModeWriteShapeN.IsNull()) return "";
237 if (modetrans < myModeWriteShapeN->Lower()) return "";
238 if (modetrans > myModeWriteShapeN->Upper()) return "";
239 Handle(TCollection_HAsciiString) str = myModeWriteShapeN->Value(modetrans);
7fd59977 240 if (str.IsNull()) return "";
241 return str->ToCString();
242}
243
244
245// ###########################
246// Transfer : on fait ce qu il faut par defaut (avec ActorWrite)
247// peut etre redefini ...
248
7f56eba8 249//=======================================================================
250//function : RecognizeWriteTransient
251//purpose :
252//=======================================================================
253
254Standard_Boolean XSControl_Controller::RecognizeWriteTransient
7fd59977 255 (const Handle(Standard_Transient)& obj,
256 const Standard_Integer modetrans) const
257{
7f56eba8 258 if (myAdaptorWrite.IsNull()) return Standard_False;
259 myAdaptorWrite->ModeTrans() = modetrans;
260 return myAdaptorWrite->Recognize (new Transfer_TransientMapper(obj));
7fd59977 261}
262
7f56eba8 263//=======================================================================
264//function : TransferFinder
265//purpose : internal function
266//=======================================================================
7fd59977 267
268static IFSelect_ReturnStatus TransferFinder
7f56eba8 269 (const Handle(Transfer_ActorOfFinderProcess)& theActor,
270 const Handle(Transfer_Finder)& theMapper,
271 const Handle(Transfer_FinderProcess)& theFP,
272 const Handle(Interface_InterfaceModel)& theModel,
273 const Standard_Integer theModeTrans)
7fd59977 274{
7f56eba8 275 if (theActor.IsNull()) return IFSelect_RetError;
276 if (theModel.IsNull()) return IFSelect_RetError;
277 theActor->ModeTrans() = theModeTrans;
278 theFP->SetModel (theModel);
279 theFP->SetActor (theActor);
280 theFP->Transfer (theMapper);
7fd59977 281
282 IFSelect_ReturnStatus stat = IFSelect_RetFail;
7f56eba8 283 Handle(Transfer_Binder) binder = theFP->Find (theMapper);
7fd59977 284 Handle(Transfer_SimpleBinderOfTransient) bindtr;
285 while (!binder.IsNull()) {
286 bindtr = Handle(Transfer_SimpleBinderOfTransient)::DownCast (binder);
287 if (!bindtr.IsNull()) {
288 Handle(Standard_Transient) ent = bindtr->Result();
289 if (!ent.IsNull()) {
7f56eba8 290 stat = IFSelect_RetDone;
291 theModel->AddWithRefs (ent);
7fd59977 292 }
293 }
294 binder = binder->NextResult();
295 }
296 return stat;
297}
298
7f56eba8 299//=======================================================================
300//function : TransferWriteTransient
301//purpose :
302//=======================================================================
7fd59977 303
7f56eba8 304IFSelect_ReturnStatus XSControl_Controller::TransferWriteTransient
305 (const Handle(Standard_Transient)& theObj,
306 const Handle(Transfer_FinderProcess)& theFP,
307 const Handle(Interface_InterfaceModel)& theModel,
308 const Standard_Integer theModeTrans) const
7fd59977 309{
7f56eba8 310 if (theObj.IsNull()) return IFSelect_RetVoid;
7fd59977 311 return TransferFinder
7f56eba8 312 (myAdaptorWrite,new Transfer_TransientMapper(theObj),theFP,theModel,theModeTrans);
7fd59977 313}
314
7f56eba8 315//=======================================================================
316//function : RecognizeWriteShape
317//purpose :
318//=======================================================================
319
320Standard_Boolean XSControl_Controller::RecognizeWriteShape
7fd59977 321 (const TopoDS_Shape& shape,
322 const Standard_Integer modetrans) const
323{
7f56eba8 324 if (myAdaptorWrite.IsNull()) return Standard_False;
325 myAdaptorWrite->ModeTrans() = modetrans;
326 return myAdaptorWrite->Recognize (new TransferBRep_ShapeMapper(shape));
7fd59977 327}
328
7f56eba8 329//=======================================================================
330//function : TransferWriteShape
331//purpose :
332//=======================================================================
333
334IFSelect_ReturnStatus XSControl_Controller::TransferWriteShape
7fd59977 335 (const TopoDS_Shape& shape,
336 const Handle(Transfer_FinderProcess)& FP,
337 const Handle(Interface_InterfaceModel)& model,
338 const Standard_Integer modetrans) const
339{
340 if (shape.IsNull()) return IFSelect_RetVoid;
341
342 IFSelect_ReturnStatus theReturnStat = TransferFinder
7f56eba8 343 (myAdaptorWrite,new TransferBRep_ShapeMapper(shape),FP,model,modetrans);
7fd59977 344 return theReturnStat;
345}
346
347// ###########################
7f56eba8 348// Cutomisation ! On enregistre des Items pour une WorkSession
349// (annule et remplace)
350// Ensuite, on les remet en place a la demande
7fd59977 351
7f56eba8 352//=======================================================================
353//function : AddSessionItem
354//purpose :
355//=======================================================================
7fd59977 356
7f56eba8 357void XSControl_Controller::AddSessionItem
358 (const Handle(Standard_Transient)& theItem, const Standard_CString theName, const Standard_Boolean toApply)
7fd59977 359{
7f56eba8 360 if (theItem.IsNull() || theName[0] == '\0') return;
997e128f 361 myAdaptorSession.Bind(theName,theItem);
7f56eba8 362 if (toApply && theItem->IsKind(STANDARD_TYPE(IFSelect_GeneralModifier)))
363 myAdaptorApplied.Append(theItem);
7fd59977 364}
365
7f56eba8 366//=======================================================================
367//function : SessionItem
368//purpose :
369//=======================================================================
370
371Handle(Standard_Transient) XSControl_Controller::SessionItem (const Standard_CString theName) const
7fd59977 372{
373 Handle(Standard_Transient) item;
997e128f 374 if (!myAdaptorSession.IsEmpty())
375 item = myAdaptorSession.Find(theName);
7fd59977 376 return item;
377}
378
7f56eba8 379//=======================================================================
380//function : Customise
381//purpose :
382//=======================================================================
7fd59977 383
7f56eba8 384void XSControl_Controller::Customise (Handle(XSControl_WorkSession)& WS)
7fd59977 385{
7f56eba8 386 WS->SetParams (myParams,myParamUses);
7fd59977 387
7f56eba8 388 // General
997e128f 389 if (!myAdaptorSession.IsEmpty()) {
390 NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>::Iterator iter(myAdaptorSession);
391 for (; iter.More(); iter.Next())
392 WS->AddNamedItem (iter.Key().ToCString(), iter.ChangeValue());
7fd59977 393 }
7fd59977 394
7f56eba8 395 if (WS->NamedItem("xst-model-all").IsNull()) {
7fd59977 396
7f56eba8 397 Handle(IFSelect_SelectModelEntities) sle = new IFSelect_SelectModelEntities;
398 WS->AddNamedItem ("xst-model-all",sle);
7fd59977 399
7f56eba8 400 Handle(IFSelect_SelectModelRoots) slr = new IFSelect_SelectModelRoots;
401 WS->AddNamedItem ("xst-model-roots",slr);
7fd59977 402
7f56eba8 403 if(strcasecmp(WS->SelectedNorm(),"STEP")) {
404 Handle(XSControl_SelectForTransfer) st1 = new XSControl_SelectForTransfer;
405 st1->SetInput (slr);
406 st1->SetReader (WS->TransferReader());
407 WS->AddNamedItem ("xst-transferrable-roots",st1);
7fd59977 408 }
7f56eba8 409
410 Handle(XSControl_SelectForTransfer) st2 = new XSControl_SelectForTransfer;
411 st2->SetInput (sle);
412 st2->SetReader (WS->TransferReader());
413 WS->AddNamedItem ("xst-transferrable-all",st2);
414
415 Handle(XSControl_SignTransferStatus) strs = new XSControl_SignTransferStatus;
416 strs->SetReader (WS->TransferReader());
417 WS->AddNamedItem ("xst-transfer-status",strs);
418
419 Handle(XSControl_ConnectedShapes) scs = new XSControl_ConnectedShapes;
420 scs->SetReader (WS->TransferReader());
421 WS->AddNamedItem ("xst-connected-faces",scs);
422
423 Handle(IFSelect_SignType) stp = new IFSelect_SignType (Standard_False);
424 WS->AddNamedItem ("xst-long-type",stp);
425
426 Handle(IFSelect_SignType) stc = new IFSelect_SignType (Standard_True);
427 WS->AddNamedItem ("xst-type",stc);
428
429 WS->AddNamedItem ("xst-ancestor-type",new IFSelect_SignAncestor);
430 WS->AddNamedItem ("xst-types",new IFSelect_SignCounter(stp,Standard_False,Standard_True));
431 WS->AddNamedItem ("xst-category",new IFSelect_SignCategory);
432 WS->AddNamedItem ("xst-validity",new IFSelect_SignValidity);
433
434 Handle(IFSelect_DispPerOne) dispone = new IFSelect_DispPerOne;
435 dispone->SetFinalSelection(slr);
436 WS->AddNamedItem ("xst-disp-one",dispone);
437
438 Handle(IFSelect_DispPerCount) dispcount = new IFSelect_DispPerCount;
439 Handle(IFSelect_IntParam) intcount = new IFSelect_IntParam;
440 intcount->SetValue(5);
441 dispcount->SetCount(intcount);
442 dispcount->SetFinalSelection(slr);
443 WS->AddNamedItem ("xst-disp-count",dispcount);
444
445 Handle(IFSelect_DispPerFiles) dispfiles = new IFSelect_DispPerFiles;
446 Handle(IFSelect_IntParam) intfiles = new IFSelect_IntParam;
447 intfiles->SetValue(10);
448 dispfiles->SetCount(intfiles);
449 dispfiles->SetFinalSelection(slr);
450 WS->AddNamedItem ("xst-disp-files",dispfiles);
451
452 Handle(IFSelect_DispPerSignature) dispsign = new IFSelect_DispPerSignature;
453 dispsign->SetSignCounter(new IFSelect_SignCounter(Handle(IFSelect_Signature)(stc)));
454 dispsign->SetFinalSelection(slr);
455 WS->AddNamedItem ("xst-disp-sign",dispsign);
456
457 // Not used directly but useful anyway
458 WS->AddNamedItem ("xst-pointed",new IFSelect_SelectPointed);
459 WS->AddNamedItem ("xst-sharing",new IFSelect_SelectSharing);
460 WS->AddNamedItem ("xst-shared",new IFSelect_SelectShared);
461 WS->AddNamedItem ("xst-nb-selected",new IFSelect_GraphCounter);
462
463 //szv:mySignType = stp;
464 WS->SetSignType( stp );
7fd59977 465 }
7f56eba8 466
467 // Applied Modifiers
468 Standard_Integer i, nb = myAdaptorApplied.Length();
7fd59977 469 for (i = 1; i <= nb; i ++) {
7f56eba8 470 const Handle(Standard_Transient) &anitem = myAdaptorApplied.Value(i);
7fd59977 471 Handle(TCollection_HAsciiString) name = WS->Name(anitem);
7f56eba8 472 WS->SetAppliedModifier(GetCasted(IFSelect_GeneralModifier,anitem),WS->ShareOut());
7fd59977 473 }
474
7f56eba8 475 // Editors of Parameters
476 // Here for the specific manufacturers of controllers could create the
477 // Parameters: So wait here
7fd59977 478
479 Handle(TColStd_HSequenceOfHAsciiString) listat = Interface_Static::Items();
7f56eba8 480 Handle(IFSelect_ParamEditor) paramed = IFSelect_ParamEditor::StaticEditor (listat,"All Static Parameters");
7fd59977 481 WS->AddNamedItem ("xst-static-params-edit",paramed);
482 Handle(IFSelect_EditForm) paramform = paramed->Form(Standard_False);
483 WS->AddNamedItem ("xst-static-params",paramform);
7fd59977 484}