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 <Geom2d_Point.hxx>
17 #include <Interface_Check.hxx>
18 #include <Interface_CheckIterator.hxx>
19 #include <Interface_Graph.hxx>
20 #include <Interface_HGraph.hxx>
21 #include <Interface_InterfaceModel.hxx>
22 #include <Interface_IntVal.hxx>
23 #include <Interface_Macros.hxx>
24 #include <Message_Messenger.hxx>
25 #include <Standard_ErrorHandler.hxx>
26 #include <Standard_Failure.hxx>
27 #include <TColStd_HSequenceOfTransient.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <Transfer_Binder.hxx>
30 #include <Transfer_Finder.hxx>
31 #include <Transfer_FinderProcess.hxx>
32 #include <Transfer_ResultFromModel.hxx>
33 #include <Transfer_ResultFromTransient.hxx>
34 #include <Transfer_SimpleBinderOfTransient.hxx>
35 #include <Transfer_TransientProcess.hxx>
36 #include <TransferBRep.hxx>
37 #include <XSControl_Controller.hxx>
38 #include <XSControl_TransferReader.hxx>
39 #include <XSControl_Vars.hxx>
40 #include <XSControl_WorkSession.hxx>
42 IMPLEMENT_STANDARD_RTTIEXT(XSControl_WorkSession,IFSelect_WorkSession)
44 //=======================================================================
45 //function : XSControl_WorkSession
47 //=======================================================================
49 XSControl_WorkSession::XSControl_WorkSession ()
50 : myTransferReader(new XSControl_TransferReader),
51 myTransferWriter(new XSControl_TransferWriter),
52 myVars(new XSControl_Vars)
57 //=======================================================================
58 //function : ClearData
60 //=======================================================================
62 void XSControl_WorkSession::ClearData (const Standard_Integer mode)
64 // 1-2-3-4 : standard IFSelect
65 if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode);
67 // 5 : Transferts seuls
68 // 6 : Resultats forces seuls
69 // 7 : Management, y compris tous transferts (forces/calcules), views
71 if (mode == 5 || mode == 7) {
72 myTransferReader->Clear(-1);
73 myTransferWriter->Clear(-1);
75 if (mode == 6 && !myTransferReader.IsNull()) myTransferReader->Clear(1);
76 myTransferReader->SetGraph (HGraph());
80 //=======================================================================
81 //function : SelectNorm
83 //=======================================================================
85 Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname)
87 // Old norm and results
88 myTransferReader->Clear(-1);
89 // ???? En toute rigueur, menage a faire dans XWS : virer les items
90 // ( a la limite, pourquoi pas, refaire XWS en entier)
92 Handle(XSControl_Controller) newadapt = XSControl_Controller::Recorded (normname);
93 if (newadapt.IsNull()) return Standard_False;
94 if (newadapt == myController) return Standard_True;
95 SetController (newadapt);
100 //=======================================================================
101 //function : SetController
103 //=======================================================================
105 void XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl)
109 SetLibrary ( myController->WorkLibrary() );
110 SetProtocol ( myController->Protocol() );
113 ClearFinalModifiers();
114 ClearShareOut(Standard_False);
117 // Set worksession parameters from teh controller
118 Handle(XSControl_WorkSession) aWorkSession(this);
119 myController->Customise (aWorkSession);
121 myTransferReader->SetController (myController);
122 myTransferWriter->SetController (myController);
126 //=======================================================================
127 //function : SelectedNorm
129 //=======================================================================
131 Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const
134 Standard_CString astr = (Standard_CString ) (myController.IsNull() ? "" : myController->Name(rsc));
139 // ##########################################
140 // ############ Contexte de Transfert ######
141 // ##########################################
144 //=======================================================================
145 //function : SetAllContext
147 //=======================================================================
149 void XSControl_WorkSession::SetAllContext(const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& context)
152 myTransferReader->Context() = context;
156 //=======================================================================
157 //function : ClearContext
159 //=======================================================================
161 void XSControl_WorkSession::ClearContext ()
164 myTransferReader->Context().Clear();
168 // ##########################################
169 // ############ RESULTATS FORCES ######
170 // ##########################################
173 //=======================================================================
174 //function : PrintTransferStatus
176 //=======================================================================
178 Standard_Boolean XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num,
179 const Standard_Boolean wri,
180 const Handle(Message_Messenger)& S) const
182 const Handle(Transfer_FinderProcess) &FP = myTransferWriter->FinderProcess();
183 Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess();
185 Handle(Transfer_Binder) binder;
186 Handle(Transfer_Finder) finder;
187 Handle(Standard_Transient) ent;
191 if (FP.IsNull()) return Standard_False;
192 if (num == 0 ) return Standard_False;
194 Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots();
196 if (num > max) return Standard_False;
198 finder = FP->Mapped(ne);
199 nr = FP->RootIndex(finder);
200 } else if (num < 0) {
202 if (nr > maxr) return Standard_False;
203 finder = FP->Root(nr);
204 ne = FP->MapIndex(finder);
207 S<<"Transfer Write item n0."<<ne<<" of "<<max;
210 S<<" ** Transfer Root n0."<<ne;
213 ent = FP->FindTransient(finder);
214 S<<" -> Type "<<finder->DynamicType()->Name()<<endl;
215 FP->StartTrace (binder,finder,0,0); // pb sout/S
217 S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name();
218 const Handle(Interface_InterfaceModel) &model = Model();
220 { S<<" In output Model, Entity "; model->Print(ent,S); }
227 if (TP.IsNull()) return Standard_False;
228 Handle(Interface_InterfaceModel) model = TP->Model();
229 if (model.IsNull()) cout<<"No Model"<<endl;
230 else if (model != Model()) cout<<"Model different from the session"<<endl;
231 if (num == 0) return Standard_False;
233 Standard_Integer ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots();
235 if (num > max) return Standard_False;
237 ent = TP->Mapped(ne);
238 nr = TP->RootIndex(finder);
239 } else if (num < 0) {
241 if (nr > maxr) return Standard_False;
243 ne = TP->MapIndex(ent);
246 S<<"Transfer Read item n0."<<ne<<" of "<<max;
249 S<<" ** Transfer Root n0."<<ne;
252 if (!model.IsNull()) { S<<" In Model, Entity "; model->Print(ent,S); }
253 binder = TP->MapItem (ne);
255 TP->StartTrace (binder,ent,0,0);
259 // *** CHECK (commun READ+WRITE) ***
260 if (!binder.IsNull()) {
261 const Handle(Interface_Check) ch = binder->Check();
262 Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
264 S<<" - Warnings : "<<nbw<<" :\n";
265 for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
268 S<<" - Fails : "<<nbf<<" :\n";
269 for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
272 return Standard_True;
276 //=======================================================================
277 //function : InitTransferReader
279 //=======================================================================
281 void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
283 if (mode == 0 || mode == 5) myTransferReader->Clear(-1); // full clear
284 if (myTransferReader.IsNull()) SetTransferReader (new XSControl_TransferReader);
285 else SetTransferReader (myTransferReader);
287 // mode = 0 fait par SetTransferReader suite a Nullify
289 if (!myTransferReader.IsNull()) myTransferReader->Clear(-1);
290 else SetTransferReader (new XSControl_TransferReader);
293 Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess();
295 TP = new Transfer_TransientProcess;
296 myTransferReader->SetTransientProcess(TP);
297 TP->SetGraph (HGraph());
299 Handle(TColStd_HSequenceOfTransient) lis = myTransferReader->RecordedList();
300 Standard_Integer i, nb = lis->Length();
301 for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
304 Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess();
305 if (TP.IsNull()) return;
306 Standard_Integer i, nb = TP->NbRoots();
307 for (i = 1; i <= nb; i ++) myTransferReader->RecordResult(TP->Root(i));
309 if (mode == 4 || mode == 5) myTransferReader->BeginTransfer();
313 //=======================================================================
314 //function : SetTransferReader
316 //=======================================================================
318 void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
320 if (myTransferReader != TR) //i1 pdn 03.04.99 BUC60301
321 myTransferReader = TR;
322 if (TR.IsNull()) return;
323 TR->SetController (myController);
324 TR->SetGraph (HGraph());
325 if (!TR->TransientProcess().IsNull()) return;
326 Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
327 (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
328 TP->SetGraph (HGraph());
329 TP->SetErrorHandle(Standard_True);
330 TR->SetTransientProcess(TP);
333 //=======================================================================
334 //function : MapReader
336 //=======================================================================
338 Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader() const
340 return myTransferReader->TransientProcess();
343 //=======================================================================
344 //function : SetMapReader
346 //=======================================================================
348 Standard_Boolean XSControl_WorkSession::SetMapReader (const Handle(Transfer_TransientProcess)& TP)
350 if (TP.IsNull()) return Standard_False;
351 if (TP->Model().IsNull()) TP->SetModel (Model());
352 TP->SetGraph (HGraph());
353 if (TP->Model() != Model()) return Standard_False;
354 // TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
355 // En revanche, mieux vaut le RAZ
356 // Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
357 Handle(XSControl_TransferReader) TR = myTransferReader;
360 SetTransferReader (TR); // avec le meme mais le reinitialise
361 TR->SetTransientProcess (TP); // et prend le nouveau TP
362 return Standard_True;
366 //=======================================================================
369 //=======================================================================
371 Handle(Standard_Transient) XSControl_WorkSession::Result
372 (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
374 Standard_Integer ouca = (mode % 10);
375 Standard_Integer kica = (mode / 10);
377 Handle(Transfer_Binder) binder;
378 Handle(Transfer_ResultFromModel) resu;
380 if (ouca != 1) resu = myTransferReader->FinalResult(ent);
381 if (mode == 20) return resu;
383 if (!resu.IsNull()) binder = resu->MainResult()->Binder();
384 if (binder.IsNull() && ouca > 0)
385 binder = myTransferReader->TransientProcess()->Find(ent);
387 if (kica == 1) return binder;
388 DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
389 if (!trb.IsNull()) return trb->Result();
393 // ##########################################
394 // ############ TRANSFERT #############
395 // ##########################################
398 //=======================================================================
399 //function : TransferReadOne
401 //=======================================================================
403 Standard_Integer XSControl_WorkSession::TransferReadOne (const Handle(Standard_Transient)& ent)
405 Handle(Interface_InterfaceModel) model = Model();
406 if (ent == model) return TransferReadRoots();
408 Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
409 if (list->Length() == 1) return myTransferReader->TransferOne(list->Value(1));
410 else return myTransferReader->TransferList (list);
414 //=======================================================================
415 //function : TransferReadRoots
417 //=======================================================================
419 Standard_Integer XSControl_WorkSession::TransferReadRoots ()
421 return myTransferReader->TransferRoots(Graph());
425 // ##########################################
426 // ############ TRANSFERT WRITE
427 // ##########################################
429 //=======================================================================
430 //function : NewModel
432 //=======================================================================
434 Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
436 Handle(Interface_InterfaceModel) newmod;
437 if (myController.IsNull()) return newmod;
438 newmod = myController->NewModel();
441 if(!myTransferReader->TransientProcess().IsNull())
442 myTransferReader->TransientProcess()->Clear();
443 //clear all contains of WS
444 myTransferReader->Clear(3);
445 myTransferWriter->Clear(-1);
451 //=======================================================================
452 //function : TransferWriteShape
454 //=======================================================================
456 IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
458 IFSelect_ReturnStatus status;
459 if (myController.IsNull()) return IFSelect_RetError;
460 const Handle(Interface_InterfaceModel) &model = Model();
461 if (model.IsNull() || shape.IsNull())
463 return IFSelect_RetVoid;
466 status = myTransferWriter->TransferWriteShape (model,shape);
467 // qui s occupe de tout, try/catch inclus
469 //skl insert param compgraph for XDE writing 10.12.2003
470 if(compgraph) ComputeGraph(Standard_True);
476 //=======================================================================
477 //function : TransferWriteCheckList
479 //=======================================================================
481 Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
483 return myTransferWriter->ResultCheckList (Model());
487 //=======================================================================
488 //function : ClearBinders
490 //=======================================================================
492 void XSControl_WorkSession::ClearBinders()
494 const Handle(Transfer_FinderProcess) &FP = myTransferWriter->FinderProcess();
495 //Due to big number of chains of binders it is necessary to
496 //collect head binders of each chain in the sequence
497 TColStd_SequenceOfTransient aSeqBnd;
498 TColStd_SequenceOfTransient aSeqShapes;
499 Standard_Integer i =1;
500 for( ; i <= FP->NbMapped();i++) {
501 Handle(Transfer_Binder) bnd = FP->MapItem ( i );
504 Handle(Standard_Transient) ash (FP->Mapped(i));
505 aSeqShapes.Append(ash);
507 //removing finder process containing result of translation.
512 //removing each chain of binders
513 while(aSeqBnd.Length() >0) {
514 Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
515 Handle(Standard_Transient) ash =aSeqShapes.Value(1);
517 aSeqShapes.Remove(1);
519 while(!aBnd.IsNull()) {
520 Handle(Transfer_Binder) aBndNext = aBnd->NextResult();