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