0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / XSControl / XSControl_WorkSession.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//:i1 pdn 03.04.99 BUC60301
15
42cf5bc1 16#include <Dico_DictionaryOfTransient.hxx>
17#include <Dico_IteratorOfDictionaryOfTransient.hxx>
18#include <Geom2d_Point.hxx>
19#include <Interface_Check.hxx>
20#include <Interface_CheckIterator.hxx>
7fd59977 21#include <Interface_Graph.hxx>
42cf5bc1 22#include <Interface_HGraph.hxx>
23#include <Interface_InterfaceModel.hxx>
24#include <Interface_IntVal.hxx>
25#include <Interface_Macros.hxx>
26#include <Message_Messenger.hxx>
c04c30b3 27#include <MoniTool_Profile.hxx>
42cf5bc1 28#include <Standard_ErrorHandler.hxx>
29#include <Standard_Failure.hxx>
30#include <Standard_Transient.hxx>
31#include <Standard_Type.hxx>
7fd59977 32#include <TColStd_HSequenceOfTransient.hxx>
42cf5bc1 33#include <TopoDS_Shape.hxx>
7fd59977 34#include <Transfer_Binder.hxx>
35#include <Transfer_Finder.hxx>
42cf5bc1 36#include <Transfer_FinderProcess.hxx>
37#include <Transfer_ResultFromModel.hxx>
38#include <Transfer_ResultFromTransient.hxx>
7fd59977 39#include <Transfer_SimpleBinderOfTransient.hxx>
42cf5bc1 40#include <Transfer_TransientProcess.hxx>
41#include <TransferBRep.hxx>
42#include <XSControl_Controller.hxx>
43#include <XSControl_TransferReader.hxx>
44#include <XSControl_TransferWriter.hxx>
45#include <XSControl_Vars.hxx>
46#include <XSControl_WorkSession.hxx>
7fd59977 47
92efcf78 48IMPLEMENT_STANDARD_RTTIEXT(XSControl_WorkSession,IFSelect_WorkSession)
49
7fd59977 50// tpent
7fd59977 51//=======================================================================
52//function : XSControl_WorkSession
53//purpose :
54//=======================================================================
7fd59977 55XSControl_WorkSession::XSControl_WorkSession ()
56{
57 theModeWriteShape = 0;
58 theTransferRead = new XSControl_TransferReader;
59 theTransferWrite = new XSControl_TransferWriter;
60 theVars = new XSControl_Vars;
61}
62
63
64//=======================================================================
65//function : ClearData
66//purpose :
67//=======================================================================
68
69void XSControl_WorkSession::ClearData (const Standard_Integer mode)
70{
71 // 1-2-3-4 : standard IFSelect
72 if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode);
73
74 // 5 : Transferts seuls
75 // 6 : Resultats forces seuls
76 // 7 : Management, y compris tous transferts (forces/calcules), views
77
78 if (mode == 5 || mode == 7) {
79 theTransferRead->Clear(-1);
80 theTransferWrite->Clear(-1);
81 }
82 if (mode == 6 && !theTransferRead.IsNull()) theTransferRead->Clear(1);
83 theTransferRead->SetGraph (HGraph());
84}
85
86
87//=======================================================================
88//function : SelectNorm
89//purpose :
90//=======================================================================
91
92Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname,
93 const Standard_CString profile)
94{
95 // RAZ ancienne norme et resultats
96 theTransferRead->Clear(-1);
97 // ???? En toute rigueur, menage a faire dans XWS : virer les items
98 // ( a la limite, pourquoi pas, refaire XWS en entier)
99
100 Handle(XSControl_Controller) newadapt =
101 XSControl_Controller::Recorded (normname);
102 if (newadapt.IsNull()) return Standard_False;
103 if (newadapt == theController) return Standard_True;
104 SetController (newadapt);
105 if (profile && profile[0] != '\0') newadapt->Profile()->SetCurrent(profile);
106
107// cout<<"##########################\n"
108// <<"## Select Norm : "<<normname<<"\n"
109// <<"##########################"<<endl;
110 return Standard_True;
111}
112
113
114//=======================================================================
115//function : SelectProfile
116//purpose :
117//=======================================================================
118
119Standard_Boolean XSControl_WorkSession::SelectProfile(const Standard_CString profile)
120{
121 return theController->Profile()->SetCurrent(profile);
122}
123
124
125//=======================================================================
126//function : SetController
127//purpose :
128//=======================================================================
129
130void XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl)
131{
132 theController = ctl;
133
134 SetLibrary ( theController->WorkLibrary() );
135 SetProtocol ( theController->Protocol() );
136 ClearItems(); ClearFinalModifiers();
137 ClearShareOut(Standard_False); ClearFile();
138 Handle(XSControl_WorkSession) aWorkSession = this;
139 theController->Customise (aWorkSession);
140 SetSignType ( theController->SignType() );
141 theTransferRead->SetController (theController);
142 theTransferWrite->SetController (theController);
143
144 AdaptNorm ();
145}
146
147
148//=======================================================================
149//function : AdaptNorm
150//purpose :
151//=======================================================================
152
153void XSControl_WorkSession::AdaptNorm ()
154{
155}
156
157
158//=======================================================================
159//function : SelectedNorm
160//purpose :
161//=======================================================================
162
163Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const
164{
165 //JR/Hp :
166 Standard_CString astr = (Standard_CString ) (theController.IsNull() ? "" : theController->Name(rsc));
167 return astr ;
168}
169// { return (theController.IsNull() ? "" : theController->Name(rsc)); }
170
171
172//=======================================================================
173//function : NormAdaptor
174//purpose :
175//=======================================================================
176
177Handle(XSControl_Controller) XSControl_WorkSession::NormAdaptor () const
178{
179 return theController;
180}
181
182
183// ##########################################
184// ############ Contexte de Transfert ######
185// ##########################################
186
187
188//=======================================================================
189//function : Context
190//purpose :
191//=======================================================================
192
193Handle(Dico_DictionaryOfTransient) XSControl_WorkSession::Context () const
194{
195 return theContext;
196}
197
198
199//=======================================================================
200//function : SetAllContext
201//purpose :
202//=======================================================================
203
204void XSControl_WorkSession::SetAllContext(const Handle(Dico_DictionaryOfTransient)& context)
205{
206 theContext = context;
207 theTransferRead->Context() = context;
208}
209
210
211//=======================================================================
212//function : ClearContext
213//purpose :
214//=======================================================================
215
216void XSControl_WorkSession::ClearContext ()
217{
218 Handle(Dico_DictionaryOfTransient) nulctx;
219 SetAllContext(nulctx);
220}
221
222
223// ##########################################
224// ############ RESULTATS FORCES ######
225// ##########################################
226
227
228//=======================================================================
229//function : PrintTransferStatus
230//purpose :
231//=======================================================================
232
233Standard_Boolean XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num,
234 const Standard_Boolean wri,
235 const Handle(Message_Messenger)& S) const
236{
237 Handle(Transfer_FinderProcess) FP = MapWriter();
238 Handle(Transfer_TransientProcess) TP = MapReader();
239
240 Handle(Transfer_Binder) binder;
241 Handle(Transfer_Finder) finder;
242 Handle(Standard_Transient) ent;
243
244 // *** WRITE ***
245 if (wri) {
246 if (FP.IsNull()) return Standard_False;
247 if (num == 0 ) return Standard_False;
248
249 Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots();
250 if (num > 0) {
251 if (num > max) return Standard_False;
252 ne = num;
253 finder = FP->Mapped(ne);
254 nr = FP->RootIndex(finder);
255 } else if (num < 0) {
256 nr = -num;
257 if (nr > maxr) return Standard_False;
258 finder = FP->Root(nr);
259 ne = FP->MapIndex(finder);
260 }
261
262 S<<"Transfer Write item n0."<<ne<<" of "<<max;
263 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
264 ent = FP->FindTransient(finder);
265 S<<" -> Type "<<finder->DynamicType()->Name()<<endl;
266 FP->StartTrace (binder,finder,0,0); // pb sout/S
267 if (!ent.IsNull()) {
268 S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name();
269 Handle(Interface_InterfaceModel) model = Model();
270 if (!model.IsNull())
271 { S<<" In output Model, Entity "; model->Print(ent,S); }
272 S<<endl;
273 }
274 }
275
276 // *** READ ***
277 else {
278 if (TP.IsNull()) return Standard_False;
279 Handle(Interface_InterfaceModel) model = TP->Model();
280 if (model.IsNull()) cout<<"No Model"<<endl;
281 else if (model != Model()) cout<<"Model different from the session"<<endl;
282 if (num == 0) return Standard_False;
283
284 Standard_Integer ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots();
285 if (num > 0) {
286 if (num > max) return Standard_False;
287 ne = num;
288 ent = TP->Mapped(ne);
289 nr = TP->RootIndex(finder);
290 } else if (num < 0) {
291 nr = -num;
292 if (nr > maxr) return Standard_False;
293 ent = TP->Root(nr);
294 ne = TP->MapIndex(ent);
295 }
296
297 S<<"Transfer Read item n0."<<ne<<" of "<<max;
298 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
299 if (!model.IsNull()) { S<<" In Model, Entity "; model->Print(ent,S); }
300 binder = TP->MapItem (ne);
301 S<<endl;
302 TP->StartTrace (binder,ent,0,0);
bc650d41 303
7fd59977 304 }
305
306// *** CHECK (commun READ+WRITE) ***
307 if (!binder.IsNull()) {
308 const Handle(Interface_Check) ch = binder->Check();
309 Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
310 if (nbw > 0) {
311 S<<" - Warnings : "<<nbw<<" :\n";
312 for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
313 }
314 if (nbf > 0) {
315 S<<" - Fails : "<<nbf<<" :\n";
316 for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
317 }
318 }
319 return Standard_True;
320}
321
322
323//=======================================================================
324//function : InitTransferReader
325//purpose :
326//=======================================================================
327
328void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
329{
330 if (mode == 0 || mode == 5) theTransferRead->Clear(-1); // full clear
331 if (theTransferRead.IsNull()) SetTransferReader (new XSControl_TransferReader);
332 else SetTransferReader (theTransferRead);
333
334 // mode = 0 fait par SetTransferReader suite a Nullify
335 if (mode == 1) {
336 if (!theTransferRead.IsNull()) theTransferRead->Clear(-1);
337 else SetTransferReader (new XSControl_TransferReader);
338 }
339 if (mode == 2) {
340 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
341 if (TP.IsNull()) {
342 TP = new Transfer_TransientProcess;
343 theTransferRead->SetTransientProcess(TP);
344 TP->SetGraph (HGraph());
345 }
346 Handle(TColStd_HSequenceOfTransient) lis = theTransferRead->RecordedList();
347 Standard_Integer i, nb = lis->Length();
348 for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
349 }
350 if (mode == 3) {
351 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
352 if (TP.IsNull()) return;
353 Standard_Integer i, nb = TP->NbRoots();
354 for (i = 1; i <= nb; i ++) theTransferRead->RecordResult(TP->Root(i));
355 }
356 if (mode == 4 || mode == 5) theTransferRead->BeginTransfer();
357}
358
359
360//=======================================================================
361//function : SetTransferReader
362//purpose :
363//=======================================================================
364
365void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
366{
367 if (theTransferRead != TR) //i1 pdn 03.04.99 BUC60301
368 theTransferRead = TR;
369 if (TR.IsNull()) return;
370 TR->SetController (theController);
371 TR->SetGraph (HGraph());
372 if (!TR->TransientProcess().IsNull()) return;
373 Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
374 (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
375 TP->SetGraph (HGraph());
376 TP->SetErrorHandle(Standard_True);
377 TR->SetTransientProcess(TP);
378}
379
380
381//=======================================================================
382//function : TransferReader
383//purpose :
384//=======================================================================
385
386Handle(XSControl_TransferReader) XSControl_WorkSession::TransferReader () const
387{
388 return theTransferRead;
389}
390
391
392//=======================================================================
393//function : MapReader
394//purpose :
395//=======================================================================
396
397Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader () const
398{
399 return theTransferRead->TransientProcess();
400}
401
402
403//=======================================================================
404//function : SetMapReader
405//purpose :
406//=======================================================================
407
408Standard_Boolean XSControl_WorkSession::SetMapReader
409 (const Handle(Transfer_TransientProcess)& TP)
410{
411 if ( TP.IsNull()) return Standard_False;
412 if (TP->Model().IsNull()) TP->SetModel (Model());
413 TP->SetGraph (HGraph());
414 if (TP->Model() != Model()) return Standard_False;
415// TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
416// En revanche, mieux vaut le RAZ
417// Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
418 Handle(XSControl_TransferReader) TR = theTransferRead;
419 TR->Clear(-1);
420
421 SetTransferReader (TR); // avec le meme mais le reinitialise
422 TR->SetTransientProcess (TP); // et prend le nouveau TP
423 return Standard_True;
424}
425
426
427//=======================================================================
428//function : Result
429//purpose :
430//=======================================================================
431
432Handle(Standard_Transient) XSControl_WorkSession::Result
433 (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
434{
435 Standard_Integer ouca = (mode % 10);
436 Standard_Integer kica = (mode / 10);
437
438 Handle(Transfer_Binder) binder;
439 Handle(Transfer_ResultFromModel) resu;
440
441 if (ouca != 1) resu = theTransferRead->FinalResult(ent);
442 if (mode == 20) return resu;
443
444 if (!resu.IsNull()) binder = resu->MainResult()->Binder();
445 if (binder.IsNull() && ouca > 0)
446 binder = theTransferRead->TransientProcess()->Find(ent);
447
448 if (kica == 1) return binder;
449 DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
450 if (!trb.IsNull()) return trb->Result();
451 return binder;
452}
453
454// ##########################################
455// ############ TRANSFERT #############
456// ##########################################
457
458
459//=======================================================================
460//function : TransferReadOne
461//purpose :
462//=======================================================================
463
464Standard_Integer XSControl_WorkSession::TransferReadOne
465 (const Handle(Standard_Transient)& ent)
466{
7fd59977 467 Handle(Interface_InterfaceModel) model = Model();
468 if (ent == model) return TransferReadRoots();
469
470 Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
471 if (list->Length() == 1) return theTransferRead->TransferOne(list->Value(1));
472 else return theTransferRead->TransferList (list);
473}
474
475
476//=======================================================================
477//function : TransferReadRoots
478//purpose :
479//=======================================================================
480
481Standard_Integer XSControl_WorkSession::TransferReadRoots ()
482{
483 return theTransferRead->TransferRoots(Graph());
484}
485
486
487// ##########################################
488// ############ TRANSFERT WRITE
489// ##########################################
490
491//=======================================================================
492//function : NewModel
493//purpose :
494//=======================================================================
495
496Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
497{
498 Handle(Interface_InterfaceModel) newmod;
499 if (theController.IsNull()) return newmod;
500 newmod = theController->NewModel();
bc650d41 501
7fd59977 502 SetModel(newmod);
bc650d41
G
503 if(!MapReader().IsNull())
504 MapReader()->Clear();
505 //clear all contains of WS
506 theTransferRead->Clear(3);
7fd59977 507 theTransferWrite->Clear(-1);
bc650d41 508
7fd59977 509 return newmod;
510}
511
512
513//=======================================================================
514//function : TransferWriter
515//purpose :
516//=======================================================================
517
518Handle(XSControl_TransferWriter) XSControl_WorkSession::TransferWriter () const
519{
520 return theTransferWrite;
521}
522
523
524//=======================================================================
525//function : MapWriter
526//purpose :
527//=======================================================================
528
529Handle(Transfer_FinderProcess) XSControl_WorkSession::MapWriter () const
530{
531 return theTransferWrite->FinderProcess();
532}
533
534
535//=======================================================================
536//function : SetMapWriter
537//purpose :
538//=======================================================================
539
540Standard_Boolean XSControl_WorkSession::SetMapWriter
541 (const Handle(Transfer_FinderProcess)& FP)
542{
543 if ( FP.IsNull()) return Standard_False;
544 theTransferWrite->SetFinderProcess (FP);
545 return Standard_True;
546}
547
548
549//=======================================================================
550//function : SetModeWriteShape
551//purpose :
552//=======================================================================
553
554void XSControl_WorkSession::SetModeWriteShape(const Standard_Integer mode)
555{
556 theTransferWrite->SetTransferMode(mode);
557}
558
559
560//=======================================================================
561//function : ModeWriteShape
562//purpose :
563//=======================================================================
564
565Standard_Integer XSControl_WorkSession::ModeWriteShape () const
566{
567 return theTransferWrite->TransferMode();
568}
569
570
571//=======================================================================
572//function : TransferWriteShape
573//purpose :
574//=======================================================================
575
576IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape
577 (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
578{
579 IFSelect_ReturnStatus status;
580 if (theController.IsNull()) return IFSelect_RetError;
581 Handle(Interface_InterfaceModel) model = Model();
582 if (model.IsNull()) return IFSelect_RetVoid;
583
584 status = theTransferWrite->TransferWriteShape (model,shape);
585 // qui s occupe de tout, try/catch inclus
586
587 //skl insert param compgraph for XDE writing 10.12.2003
588 if(compgraph) ComputeGraph(Standard_True);
589
590 return status;
591}
592
593
594//=======================================================================
595//function : TransferWriteCheckList
596//purpose :
597//=======================================================================
598
599Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
600{
601 return theTransferWrite->ResultCheckList (Model());
602}
603
604
605//=======================================================================
606//function : Vars
607//purpose :
608//=======================================================================
609
610Handle(XSControl_Vars) XSControl_WorkSession::Vars () const
611{
612 return theVars;
613}
614
615
616//=======================================================================
617//function : SetVars
618//purpose :
619//=======================================================================
620
621void XSControl_WorkSession::SetVars (const Handle(XSControl_Vars)& newvars)
622{
623 theVars = newvars;
624}
625
626
627//=======================================================================
628//function : ClearBinders
629//purpose :
630//=======================================================================
631
632void XSControl_WorkSession::ClearBinders()
633{
634 Handle(Transfer_FinderProcess) FP = theTransferWrite->FinderProcess();
635 //Due to big number of chains of binders it is necessary to
636 //collect head binders of each chain in the sequence
637 TColStd_SequenceOfTransient aSeqBnd;
638 TColStd_SequenceOfTransient aSeqShapes;
639 Standard_Integer i =1;
640 for( ; i <= FP->NbMapped();i++) {
641 Handle(Transfer_Binder) bnd = FP->MapItem ( i );
642 if(!bnd.IsNull())
643 aSeqBnd.Append(bnd);
5b111128 644 Handle(Standard_Transient) ash (FP->Mapped(i));
7fd59977 645 aSeqShapes.Append(ash);
646 }
647 //removing finder process containing result of translation.
648 FP->Clear();
649 ClearData(1);
650 ClearData(5);
651
652 //removing each chain of binders
653 while(aSeqBnd.Length() >0) {
654 Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
655 Handle(Standard_Transient) ash =aSeqShapes.Value(1);
656 aSeqBnd.Remove(1);
657 aSeqShapes.Remove(1);
658 ash.Nullify();
659 while(!aBnd.IsNull()) {
660 Handle(Transfer_Binder) aBndNext = aBnd->NextResult();
661 aBnd.Nullify();
662 aBnd = aBndNext;
663 }
664
665 }
666
667}
668
669
670//=======================================================================
671//function : Destroy
672//purpose :
673//=======================================================================
674
675void XSControl_WorkSession::Destroy()
676{
677 ClearBinders();
678}
679
680