1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 //:i1 pdn 03.04.99 BUC60301
16 #include <XSControl_WorkSession.ixx>
17 #include <Standard_ErrorHandler.hxx>
18 #include <Standard_Failure.hxx>
19 #include <Interface_HGraph.hxx>
20 #include <Interface_Graph.hxx>
22 #include <IFSelect_Profile.hxx>
24 #include <Transfer_TransientProcess.hxx>
25 #include <Transfer_ResultFromModel.hxx>
26 #include <Transfer_ResultFromTransient.hxx>
27 #include <TColStd_HSequenceOfTransient.hxx>
29 #include <TransferBRep.hxx>
30 #include <Transfer_Binder.hxx>
31 #include <Transfer_Finder.hxx>
32 #include <Transfer_SimpleBinderOfTransient.hxx>
35 #include <Interface_IntVal.hxx>
36 #include <Geom2d_Point.hxx>
37 #include <Dico_DictionaryOfTransient.hxx>
38 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
40 #include <Interface_Macros.hxx>
41 #include <Interface_Check.hxx>
43 #include <Message_Messenger.hxx>
45 //=======================================================================
46 //function : XSControl_WorkSession
48 //=======================================================================
50 XSControl_WorkSession::XSControl_WorkSession ()
52 theModeWriteShape = 0;
53 theTransferRead = new XSControl_TransferReader;
54 theTransferWrite = new XSControl_TransferWriter;
55 theVars = new XSControl_Vars;
59 //=======================================================================
60 //function : ClearData
62 //=======================================================================
64 void XSControl_WorkSession::ClearData (const Standard_Integer mode)
66 // 1-2-3-4 : standard IFSelect
67 if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode);
69 // 5 : Transferts seuls
70 // 6 : Resultats forces seuls
71 // 7 : Management, y compris tous transferts (forces/calcules), views
73 if (mode == 5 || mode == 7) {
74 theTransferRead->Clear(-1);
75 theTransferWrite->Clear(-1);
77 if (mode == 6 && !theTransferRead.IsNull()) theTransferRead->Clear(1);
78 theTransferRead->SetGraph (HGraph());
82 //=======================================================================
83 //function : SelectNorm
85 //=======================================================================
87 Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname,
88 const Standard_CString profile)
90 // RAZ ancienne norme et resultats
91 theTransferRead->Clear(-1);
92 // ???? En toute rigueur, menage a faire dans XWS : virer les items
93 // ( a la limite, pourquoi pas, refaire XWS en entier)
95 Handle(XSControl_Controller) newadapt =
96 XSControl_Controller::Recorded (normname);
97 if (newadapt.IsNull()) return Standard_False;
98 if (newadapt == theController) return Standard_True;
99 SetController (newadapt);
100 if (profile && profile[0] != '\0') newadapt->Profile()->SetCurrent(profile);
102 // cout<<"##########################\n"
103 // <<"## Select Norm : "<<normname<<"\n"
104 // <<"##########################"<<endl;
105 return Standard_True;
109 //=======================================================================
110 //function : SelectProfile
112 //=======================================================================
114 Standard_Boolean XSControl_WorkSession::SelectProfile(const Standard_CString profile)
116 return theController->Profile()->SetCurrent(profile);
120 //=======================================================================
121 //function : SetController
123 //=======================================================================
125 void XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl)
129 SetLibrary ( theController->WorkLibrary() );
130 SetProtocol ( theController->Protocol() );
131 ClearItems(); ClearFinalModifiers();
132 ClearShareOut(Standard_False); ClearFile();
133 Handle(XSControl_WorkSession) aWorkSession = this;
134 theController->Customise (aWorkSession);
135 SetSignType ( theController->SignType() );
136 theTransferRead->SetController (theController);
137 theTransferWrite->SetController (theController);
143 //=======================================================================
144 //function : AdaptNorm
146 //=======================================================================
148 void XSControl_WorkSession::AdaptNorm ()
153 //=======================================================================
154 //function : SelectedNorm
156 //=======================================================================
158 Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const
161 Standard_CString astr = (Standard_CString ) (theController.IsNull() ? "" : theController->Name(rsc));
164 // { return (theController.IsNull() ? "" : theController->Name(rsc)); }
167 //=======================================================================
168 //function : NormAdaptor
170 //=======================================================================
172 Handle(XSControl_Controller) XSControl_WorkSession::NormAdaptor () const
174 return theController;
178 // ##########################################
179 // ############ Contexte de Transfert ######
180 // ##########################################
183 //=======================================================================
186 //=======================================================================
188 Handle(Dico_DictionaryOfTransient) XSControl_WorkSession::Context () const
194 //=======================================================================
195 //function : SetAllContext
197 //=======================================================================
199 void XSControl_WorkSession::SetAllContext(const Handle(Dico_DictionaryOfTransient)& context)
201 theContext = context;
202 theTransferRead->Context() = context;
206 //=======================================================================
207 //function : ClearContext
209 //=======================================================================
211 void XSControl_WorkSession::ClearContext ()
213 Handle(Dico_DictionaryOfTransient) nulctx;
214 SetAllContext(nulctx);
218 // ##########################################
219 // ############ RESULTATS FORCES ######
220 // ##########################################
223 //=======================================================================
224 //function : PrintTransferStatus
226 //=======================================================================
228 Standard_Boolean XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num,
229 const Standard_Boolean wri,
230 const Handle(Message_Messenger)& S) const
232 Handle(Transfer_FinderProcess) FP = MapWriter();
233 Handle(Transfer_TransientProcess) TP = MapReader();
235 Handle(Transfer_Binder) binder;
236 Handle(Transfer_Finder) finder;
237 Handle(Standard_Transient) ent;
241 if (FP.IsNull()) return Standard_False;
242 if (num == 0 ) return Standard_False;
244 Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots();
246 if (num > max) return Standard_False;
248 finder = FP->Mapped(ne);
249 nr = FP->RootIndex(finder);
250 } else if (num < 0) {
252 if (nr > maxr) return Standard_False;
253 finder = FP->Root(nr);
254 ne = FP->MapIndex(finder);
257 S<<"Transfer Write item n0."<<ne<<" of "<<max;
258 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
259 ent = FP->FindTransient(finder);
260 S<<" -> Type "<<finder->DynamicType()->Name()<<endl;
261 FP->StartTrace (binder,finder,0,0); // pb sout/S
263 S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name();
264 Handle(Interface_InterfaceModel) model = Model();
266 { S<<" In output Model, Entity "; model->Print(ent,S); }
273 if (TP.IsNull()) return Standard_False;
274 Handle(Interface_InterfaceModel) model = TP->Model();
275 if (model.IsNull()) cout<<"No Model"<<endl;
276 else if (model != Model()) cout<<"Model different from the session"<<endl;
277 if (num == 0) return Standard_False;
279 Standard_Integer ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots();
281 if (num > max) return Standard_False;
283 ent = TP->Mapped(ne);
284 nr = TP->RootIndex(finder);
285 } else if (num < 0) {
287 if (nr > maxr) return Standard_False;
289 ne = TP->MapIndex(ent);
292 S<<"Transfer Read item n0."<<ne<<" of "<<max;
293 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
294 if (!model.IsNull()) { S<<" In Model, Entity "; model->Print(ent,S); }
295 binder = TP->MapItem (ne);
297 TP->StartTrace (binder,ent,0,0);
301 // *** CHECK (commun READ+WRITE) ***
302 if (!binder.IsNull()) {
303 const Handle(Interface_Check) ch = binder->Check();
304 Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
306 S<<" - Warnings : "<<nbw<<" :\n";
307 for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
310 S<<" - Fails : "<<nbf<<" :\n";
311 for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
314 return Standard_True;
318 //=======================================================================
319 //function : InitTransferReader
321 //=======================================================================
323 void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
325 if (mode == 0 || mode == 5) theTransferRead->Clear(-1); // full clear
326 if (theTransferRead.IsNull()) SetTransferReader (new XSControl_TransferReader);
327 else SetTransferReader (theTransferRead);
329 // mode = 0 fait par SetTransferReader suite a Nullify
331 if (!theTransferRead.IsNull()) theTransferRead->Clear(-1);
332 else SetTransferReader (new XSControl_TransferReader);
335 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
337 TP = new Transfer_TransientProcess;
338 theTransferRead->SetTransientProcess(TP);
339 TP->SetGraph (HGraph());
341 Handle(TColStd_HSequenceOfTransient) lis = theTransferRead->RecordedList();
342 Standard_Integer i, nb = lis->Length();
343 for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
346 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
347 if (TP.IsNull()) return;
348 Standard_Integer i, nb = TP->NbRoots();
349 for (i = 1; i <= nb; i ++) theTransferRead->RecordResult(TP->Root(i));
351 if (mode == 4 || mode == 5) theTransferRead->BeginTransfer();
355 //=======================================================================
356 //function : SetTransferReader
358 //=======================================================================
360 void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
362 if (theTransferRead != TR) //i1 pdn 03.04.99 BUC60301
363 theTransferRead = TR;
364 if (TR.IsNull()) return;
365 TR->SetController (theController);
366 TR->SetGraph (HGraph());
367 if (!TR->TransientProcess().IsNull()) return;
368 Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
369 (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
370 TP->SetGraph (HGraph());
371 TP->SetErrorHandle(Standard_True);
372 TR->SetTransientProcess(TP);
376 //=======================================================================
377 //function : TransferReader
379 //=======================================================================
381 Handle(XSControl_TransferReader) XSControl_WorkSession::TransferReader () const
383 return theTransferRead;
387 //=======================================================================
388 //function : MapReader
390 //=======================================================================
392 Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader () const
394 return theTransferRead->TransientProcess();
398 //=======================================================================
399 //function : SetMapReader
401 //=======================================================================
403 Standard_Boolean XSControl_WorkSession::SetMapReader
404 (const Handle(Transfer_TransientProcess)& TP)
406 if ( TP.IsNull()) return Standard_False;
407 if (TP->Model().IsNull()) TP->SetModel (Model());
408 TP->SetGraph (HGraph());
409 if (TP->Model() != Model()) return Standard_False;
410 // TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
411 // En revanche, mieux vaut le RAZ
412 // Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
413 Handle(XSControl_TransferReader) TR = theTransferRead;
416 SetTransferReader (TR); // avec le meme mais le reinitialise
417 TR->SetTransientProcess (TP); // et prend le nouveau TP
418 return Standard_True;
422 //=======================================================================
425 //=======================================================================
427 Handle(Standard_Transient) XSControl_WorkSession::Result
428 (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
430 Standard_Integer ouca = (mode % 10);
431 Standard_Integer kica = (mode / 10);
433 Handle(Transfer_Binder) binder;
434 Handle(Transfer_ResultFromModel) resu;
436 if (ouca != 1) resu = theTransferRead->FinalResult(ent);
437 if (mode == 20) return resu;
439 if (!resu.IsNull()) binder = resu->MainResult()->Binder();
440 if (binder.IsNull() && ouca > 0)
441 binder = theTransferRead->TransientProcess()->Find(ent);
443 if (kica == 1) return binder;
444 DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
445 if (!trb.IsNull()) return trb->Result();
449 // ##########################################
450 // ############ TRANSFERT #############
451 // ##########################################
454 //=======================================================================
455 //function : TransferReadOne
457 //=======================================================================
459 Standard_Integer XSControl_WorkSession::TransferReadOne
460 (const Handle(Standard_Transient)& ent)
462 Handle(Interface_InterfaceModel) model = Model();
463 if (ent == model) return TransferReadRoots();
465 Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
466 if (list->Length() == 1) return theTransferRead->TransferOne(list->Value(1));
467 else return theTransferRead->TransferList (list);
471 //=======================================================================
472 //function : TransferReadRoots
474 //=======================================================================
476 Standard_Integer XSControl_WorkSession::TransferReadRoots ()
478 return theTransferRead->TransferRoots(Graph());
482 // ##########################################
483 // ############ TRANSFERT WRITE
484 // ##########################################
486 //=======================================================================
487 //function : NewModel
489 //=======================================================================
491 Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
493 Handle(Interface_InterfaceModel) newmod;
494 if (theController.IsNull()) return newmod;
495 newmod = theController->NewModel();
498 if(!MapReader().IsNull())
499 MapReader()->Clear();
500 //clear all contains of WS
501 theTransferRead->Clear(3);
502 theTransferWrite->Clear(-1);
508 //=======================================================================
509 //function : TransferWriter
511 //=======================================================================
513 Handle(XSControl_TransferWriter) XSControl_WorkSession::TransferWriter () const
515 return theTransferWrite;
519 //=======================================================================
520 //function : MapWriter
522 //=======================================================================
524 Handle(Transfer_FinderProcess) XSControl_WorkSession::MapWriter () const
526 return theTransferWrite->FinderProcess();
530 //=======================================================================
531 //function : SetMapWriter
533 //=======================================================================
535 Standard_Boolean XSControl_WorkSession::SetMapWriter
536 (const Handle(Transfer_FinderProcess)& FP)
538 if ( FP.IsNull()) return Standard_False;
539 theTransferWrite->SetFinderProcess (FP);
540 return Standard_True;
544 //=======================================================================
545 //function : SetModeWriteShape
547 //=======================================================================
549 void XSControl_WorkSession::SetModeWriteShape(const Standard_Integer mode)
551 theTransferWrite->SetTransferMode(mode);
555 //=======================================================================
556 //function : ModeWriteShape
558 //=======================================================================
560 Standard_Integer XSControl_WorkSession::ModeWriteShape () const
562 return theTransferWrite->TransferMode();
566 //=======================================================================
567 //function : TransferWriteShape
569 //=======================================================================
571 IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape
572 (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
574 IFSelect_ReturnStatus status;
575 if (theController.IsNull()) return IFSelect_RetError;
576 Handle(Interface_InterfaceModel) model = Model();
577 if (model.IsNull()) return IFSelect_RetVoid;
579 status = theTransferWrite->TransferWriteShape (model,shape);
580 // qui s occupe de tout, try/catch inclus
582 //skl insert param compgraph for XDE writing 10.12.2003
583 if(compgraph) ComputeGraph(Standard_True);
589 //=======================================================================
590 //function : TransferWriteCheckList
592 //=======================================================================
594 Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
596 return theTransferWrite->ResultCheckList (Model());
600 //=======================================================================
603 //=======================================================================
605 Handle(XSControl_Vars) XSControl_WorkSession::Vars () const
611 //=======================================================================
614 //=======================================================================
616 void XSControl_WorkSession::SetVars (const Handle(XSControl_Vars)& newvars)
622 //=======================================================================
623 //function : ClearBinders
625 //=======================================================================
627 void XSControl_WorkSession::ClearBinders()
629 Handle(Transfer_FinderProcess) FP = theTransferWrite->FinderProcess();
630 //Due to big number of chains of binders it is necessary to
631 //collect head binders of each chain in the sequence
632 TColStd_SequenceOfTransient aSeqBnd;
633 TColStd_SequenceOfTransient aSeqShapes;
634 Standard_Integer i =1;
635 for( ; i <= FP->NbMapped();i++) {
636 Handle(Transfer_Binder) bnd = FP->MapItem ( i );
639 Handle(Standard_Transient) ash = FP->Mapped(i);
640 aSeqShapes.Append(ash);
642 //removing finder process containing result of translation.
647 //removing each chain of binders
648 while(aSeqBnd.Length() >0) {
649 Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
650 Handle(Standard_Transient) ash =aSeqShapes.Value(1);
652 aSeqShapes.Remove(1);
654 while(!aBnd.IsNull()) {
655 Handle(Transfer_Binder) aBndNext = aBnd->NextResult();
665 //=======================================================================
668 //=======================================================================
670 void XSControl_WorkSession::Destroy()