1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 //:i1 pdn 03.04.99 BUC60301
20 #include <XSControl_WorkSession.ixx>
21 #include <Standard_ErrorHandler.hxx>
22 #include <Standard_Failure.hxx>
23 #include <Interface_HGraph.hxx>
24 #include <Interface_Graph.hxx>
26 #include <IFSelect_Profile.hxx>
28 #include <Transfer_TransientProcess.hxx>
29 #include <Transfer_ResultFromModel.hxx>
30 #include <Transfer_ResultFromTransient.hxx>
31 #include <TColStd_HSequenceOfTransient.hxx>
33 #include <TransferBRep.hxx>
34 #include <Transfer_Binder.hxx>
35 #include <Transfer_Finder.hxx>
36 #include <Transfer_SimpleBinderOfTransient.hxx>
39 #include <Interface_IntVal.hxx>
40 #include <Geom2d_Point.hxx>
41 #include <Dico_DictionaryOfTransient.hxx>
42 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
44 #include <Interface_Macros.hxx>
45 #include <Interface_Check.hxx>
47 #include <Message_Messenger.hxx>
49 //=======================================================================
50 //function : XSControl_WorkSession
52 //=======================================================================
54 XSControl_WorkSession::XSControl_WorkSession ()
56 theModeWriteShape = 0;
57 theTransferRead = new XSControl_TransferReader;
58 theTransferWrite = new XSControl_TransferWriter;
59 theVars = new XSControl_Vars;
63 //=======================================================================
64 //function : ClearData
66 //=======================================================================
68 void XSControl_WorkSession::ClearData (const Standard_Integer mode)
70 // 1-2-3-4 : standard IFSelect
71 if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode);
73 // 5 : Transferts seuls
74 // 6 : Resultats forces seuls
75 // 7 : Management, y compris tous transferts (forces/calcules), views
77 if (mode == 5 || mode == 7) {
78 theTransferRead->Clear(-1);
79 theTransferWrite->Clear(-1);
81 if (mode == 6 && !theTransferRead.IsNull()) theTransferRead->Clear(1);
82 theTransferRead->SetGraph (HGraph());
86 //=======================================================================
87 //function : SelectNorm
89 //=======================================================================
91 Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname,
92 const Standard_CString profile)
94 // RAZ ancienne norme et resultats
95 theTransferRead->Clear(-1);
96 // ???? En toute rigueur, menage a faire dans XWS : virer les items
97 // ( a la limite, pourquoi pas, refaire XWS en entier)
99 Handle(XSControl_Controller) newadapt =
100 XSControl_Controller::Recorded (normname);
101 if (newadapt.IsNull()) return Standard_False;
102 if (newadapt == theController) return Standard_True;
103 SetController (newadapt);
104 if (profile && profile[0] != '\0') newadapt->Profile()->SetCurrent(profile);
106 // cout<<"##########################\n"
107 // <<"## Select Norm : "<<normname<<"\n"
108 // <<"##########################"<<endl;
109 return Standard_True;
113 //=======================================================================
114 //function : SelectProfile
116 //=======================================================================
118 Standard_Boolean XSControl_WorkSession::SelectProfile(const Standard_CString profile)
120 return theController->Profile()->SetCurrent(profile);
124 //=======================================================================
125 //function : SetController
127 //=======================================================================
129 void XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl)
133 SetLibrary ( theController->WorkLibrary() );
134 SetProtocol ( theController->Protocol() );
135 ClearItems(); ClearFinalModifiers();
136 ClearShareOut(Standard_False); ClearFile();
137 Handle(XSControl_WorkSession) aWorkSession = this;
138 theController->Customise (aWorkSession);
139 SetSignType ( theController->SignType() );
140 theTransferRead->SetController (theController);
141 theTransferWrite->SetController (theController);
147 //=======================================================================
148 //function : AdaptNorm
150 //=======================================================================
152 void XSControl_WorkSession::AdaptNorm ()
157 //=======================================================================
158 //function : SelectedNorm
160 //=======================================================================
162 Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const
165 Standard_CString astr = (Standard_CString ) (theController.IsNull() ? "" : theController->Name(rsc));
168 // { return (theController.IsNull() ? "" : theController->Name(rsc)); }
171 //=======================================================================
172 //function : NormAdaptor
174 //=======================================================================
176 Handle(XSControl_Controller) XSControl_WorkSession::NormAdaptor () const
178 return theController;
182 // ##########################################
183 // ############ Contexte de Transfert ######
184 // ##########################################
187 //=======================================================================
190 //=======================================================================
192 Handle(Dico_DictionaryOfTransient) XSControl_WorkSession::Context () const
198 //=======================================================================
199 //function : SetAllContext
201 //=======================================================================
203 void XSControl_WorkSession::SetAllContext(const Handle(Dico_DictionaryOfTransient)& context)
205 theContext = context;
206 theTransferRead->Context() = context;
210 //=======================================================================
211 //function : ClearContext
213 //=======================================================================
215 void XSControl_WorkSession::ClearContext ()
217 Handle(Dico_DictionaryOfTransient) nulctx;
218 SetAllContext(nulctx);
222 // ##########################################
223 // ############ RESULTATS FORCES ######
224 // ##########################################
227 //=======================================================================
228 //function : PrintTransferStatus
230 //=======================================================================
232 Standard_Boolean XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num,
233 const Standard_Boolean wri,
234 const Handle(Message_Messenger)& S) const
236 Handle(Transfer_FinderProcess) FP = MapWriter();
237 Handle(Transfer_TransientProcess) TP = MapReader();
239 Handle(Transfer_Binder) binder;
240 Handle(Transfer_Finder) finder;
241 Handle(Standard_Transient) ent;
245 if (FP.IsNull()) return Standard_False;
246 if (num == 0 ) return Standard_False;
248 Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots();
250 if (num > max) return Standard_False;
252 finder = FP->Mapped(ne);
253 nr = FP->RootIndex(finder);
254 } else if (num < 0) {
256 if (nr > maxr) return Standard_False;
257 finder = FP->Root(nr);
258 ne = FP->MapIndex(finder);
261 S<<"Transfer Write item n0."<<ne<<" of "<<max;
262 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
263 ent = FP->FindTransient(finder);
264 S<<" -> Type "<<finder->DynamicType()->Name()<<endl;
265 FP->StartTrace (binder,finder,0,0); // pb sout/S
267 S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name();
268 Handle(Interface_InterfaceModel) model = Model();
270 { S<<" In output Model, Entity "; model->Print(ent,S); }
277 if (TP.IsNull()) return Standard_False;
278 Handle(Interface_InterfaceModel) model = TP->Model();
279 if (model.IsNull()) cout<<"No Model"<<endl;
280 else if (model != Model()) cout<<"Model different from the session"<<endl;
281 if (num == 0) return Standard_False;
283 Standard_Integer ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots();
285 if (num > max) return Standard_False;
287 ent = TP->Mapped(ne);
288 nr = TP->RootIndex(finder);
289 } else if (num < 0) {
291 if (nr > maxr) return Standard_False;
293 ne = TP->MapIndex(ent);
296 S<<"Transfer Read item n0."<<ne<<" of "<<max;
297 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
298 if (!model.IsNull()) { S<<" In Model, Entity "; model->Print(ent,S); }
299 binder = TP->MapItem (ne);
301 TP->StartTrace (binder,ent,0,0);
305 // *** CHECK (commun READ+WRITE) ***
306 if (!binder.IsNull()) {
307 const Handle(Interface_Check) ch = binder->Check();
308 Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
310 S<<" - Warnings : "<<nbw<<" :\n";
311 for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
314 S<<" - Fails : "<<nbf<<" :\n";
315 for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
318 return Standard_True;
322 //=======================================================================
323 //function : InitTransferReader
325 //=======================================================================
327 void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
329 if (mode == 0 || mode == 5) theTransferRead->Clear(-1); // full clear
330 if (theTransferRead.IsNull()) SetTransferReader (new XSControl_TransferReader);
331 else SetTransferReader (theTransferRead);
333 // mode = 0 fait par SetTransferReader suite a Nullify
335 if (!theTransferRead.IsNull()) theTransferRead->Clear(-1);
336 else SetTransferReader (new XSControl_TransferReader);
339 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
341 TP = new Transfer_TransientProcess;
342 theTransferRead->SetTransientProcess(TP);
343 TP->SetGraph (HGraph());
345 Handle(TColStd_HSequenceOfTransient) lis = theTransferRead->RecordedList();
346 Standard_Integer i, nb = lis->Length();
347 for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
350 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
351 if (TP.IsNull()) return;
352 Standard_Integer i, nb = TP->NbRoots();
353 for (i = 1; i <= nb; i ++) theTransferRead->RecordResult(TP->Root(i));
355 if (mode == 4 || mode == 5) theTransferRead->BeginTransfer();
359 //=======================================================================
360 //function : SetTransferReader
362 //=======================================================================
364 void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
366 if (theTransferRead != TR) //i1 pdn 03.04.99 BUC60301
367 theTransferRead = TR;
368 if (TR.IsNull()) return;
369 TR->SetController (theController);
370 TR->SetGraph (HGraph());
371 if (!TR->TransientProcess().IsNull()) return;
372 Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
373 (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
374 TP->SetGraph (HGraph());
375 TP->SetErrorHandle(Standard_True);
376 TR->SetTransientProcess(TP);
380 //=======================================================================
381 //function : TransferReader
383 //=======================================================================
385 Handle(XSControl_TransferReader) XSControl_WorkSession::TransferReader () const
387 return theTransferRead;
391 //=======================================================================
392 //function : MapReader
394 //=======================================================================
396 Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader () const
398 return theTransferRead->TransientProcess();
402 //=======================================================================
403 //function : SetMapReader
405 //=======================================================================
407 Standard_Boolean XSControl_WorkSession::SetMapReader
408 (const Handle(Transfer_TransientProcess)& TP)
410 if ( TP.IsNull()) return Standard_False;
411 if (TP->Model().IsNull()) TP->SetModel (Model());
412 TP->SetGraph (HGraph());
413 if (TP->Model() != Model()) return Standard_False;
414 // TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
415 // En revanche, mieux vaut le RAZ
416 // Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
417 Handle(XSControl_TransferReader) TR = theTransferRead;
420 SetTransferReader (TR); // avec le meme mais le reinitialise
421 TR->SetTransientProcess (TP); // et prend le nouveau TP
422 return Standard_True;
426 //=======================================================================
429 //=======================================================================
431 Handle(Standard_Transient) XSControl_WorkSession::Result
432 (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
434 Standard_Integer ouca = (mode % 10);
435 Standard_Integer kica = (mode / 10);
437 Handle(Transfer_Binder) binder;
438 Handle(Transfer_ResultFromModel) resu;
440 if (ouca != 1) resu = theTransferRead->FinalResult(ent);
441 if (mode == 20) return resu;
443 if (!resu.IsNull()) binder = resu->MainResult()->Binder();
444 if (binder.IsNull() && ouca > 0)
445 binder = theTransferRead->TransientProcess()->Find(ent);
447 if (kica == 1) return binder;
448 DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
449 if (!trb.IsNull()) return trb->Result();
453 // ##########################################
454 // ############ TRANSFERT #############
455 // ##########################################
458 //=======================================================================
459 //function : TransferReadOne
461 //=======================================================================
463 Standard_Integer XSControl_WorkSession::TransferReadOne
464 (const Handle(Standard_Transient)& ent)
466 Handle(Interface_InterfaceModel) model = Model();
467 if (ent == model) return TransferReadRoots();
469 Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
470 if (list->Length() == 1) return theTransferRead->TransferOne(list->Value(1));
471 else return theTransferRead->TransferList (list);
475 //=======================================================================
476 //function : TransferReadRoots
478 //=======================================================================
480 Standard_Integer XSControl_WorkSession::TransferReadRoots ()
482 return theTransferRead->TransferRoots(Graph());
486 // ##########################################
487 // ############ TRANSFERT WRITE
488 // ##########################################
490 //=======================================================================
491 //function : NewModel
493 //=======================================================================
495 Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
497 Handle(Interface_InterfaceModel) newmod;
498 if (theController.IsNull()) return newmod;
499 newmod = theController->NewModel();
502 if(!MapReader().IsNull())
503 MapReader()->Clear();
504 //clear all contains of WS
505 theTransferRead->Clear(3);
506 theTransferWrite->Clear(-1);
512 //=======================================================================
513 //function : TransferWriter
515 //=======================================================================
517 Handle(XSControl_TransferWriter) XSControl_WorkSession::TransferWriter () const
519 return theTransferWrite;
523 //=======================================================================
524 //function : MapWriter
526 //=======================================================================
528 Handle(Transfer_FinderProcess) XSControl_WorkSession::MapWriter () const
530 return theTransferWrite->FinderProcess();
534 //=======================================================================
535 //function : SetMapWriter
537 //=======================================================================
539 Standard_Boolean XSControl_WorkSession::SetMapWriter
540 (const Handle(Transfer_FinderProcess)& FP)
542 if ( FP.IsNull()) return Standard_False;
543 theTransferWrite->SetFinderProcess (FP);
544 return Standard_True;
548 //=======================================================================
549 //function : SetModeWriteShape
551 //=======================================================================
553 void XSControl_WorkSession::SetModeWriteShape(const Standard_Integer mode)
555 theTransferWrite->SetTransferMode(mode);
559 //=======================================================================
560 //function : ModeWriteShape
562 //=======================================================================
564 Standard_Integer XSControl_WorkSession::ModeWriteShape () const
566 return theTransferWrite->TransferMode();
570 //=======================================================================
571 //function : TransferWriteShape
573 //=======================================================================
575 IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape
576 (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
578 IFSelect_ReturnStatus status;
579 if (theController.IsNull()) return IFSelect_RetError;
580 Handle(Interface_InterfaceModel) model = Model();
581 if (model.IsNull()) return IFSelect_RetVoid;
583 status = theTransferWrite->TransferWriteShape (model,shape);
584 // qui s occupe de tout, try/catch inclus
586 //skl insert param compgraph for XDE writing 10.12.2003
587 if(compgraph) ComputeGraph(Standard_True);
593 //=======================================================================
594 //function : TransferWriteCheckList
596 //=======================================================================
598 Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
600 return theTransferWrite->ResultCheckList (Model());
604 //=======================================================================
607 //=======================================================================
609 Handle(XSControl_Vars) XSControl_WorkSession::Vars () const
615 //=======================================================================
618 //=======================================================================
620 void XSControl_WorkSession::SetVars (const Handle(XSControl_Vars)& newvars)
626 //=======================================================================
627 //function : ClearBinders
629 //=======================================================================
631 void XSControl_WorkSession::ClearBinders()
633 Handle(Transfer_FinderProcess) FP = theTransferWrite->FinderProcess();
634 //Due to big number of chains of binders it is necessary to
635 //collect head binders of each chain in the sequence
636 TColStd_SequenceOfTransient aSeqBnd;
637 TColStd_SequenceOfTransient aSeqShapes;
638 Standard_Integer i =1;
639 for( ; i <= FP->NbMapped();i++) {
640 Handle(Transfer_Binder) bnd = FP->MapItem ( i );
643 Handle(Standard_Transient) ash = FP->Mapped(i);
644 aSeqShapes.Append(ash);
646 //removing finder process containing result of translation.
651 //removing each chain of binders
652 while(aSeqBnd.Length() >0) {
653 Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
654 Handle(Standard_Transient) ash =aSeqShapes.Value(1);
656 aSeqShapes.Remove(1);
658 while(!aBnd.IsNull()) {
659 Handle(Transfer_Binder) aBndNext = aBnd->NextResult();
669 //=======================================================================
672 //=======================================================================
674 void XSControl_WorkSession::Destroy()