0022802: The memory allocated with an excess is not released
[occt.git] / src / XSControl / XSControl_WorkSession.cxx
... / ...
CommitLineData
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);
285/*skl
286 if (!binder.IsNull()) {
287 // infos complementaires : cas et attributs
288 Standard_Integer icas, nbcas = binder->NbCases();
289 if (nbcas > 0) S<<"Recorded Cases : "<<nbcas<<" :";
290 for (icas = 1; icas <= nbcas; icas ++) S<<" "<<binder->CaseName(icas);
291 if (nbcas > 0) S<<endl;
292 Standard_Integer nbatr = 0;
293 Handle(Dico_DictionaryOfTransient) atrs = binder->AttrList();
294 Dico_IteratorOfDictionaryOfTransient iatr (atrs);
295 for (; iatr.More(); iatr.Next()) {
296 Handle(Standard_Transient) atr = iatr.Value();
297 if (atr.IsNull()) continue;
298 if (nbatr == 0) S<<"-- List of Attributes"<<endl;
299 nbatr ++;
300 S<<iatr.Name()<<" : ";
301 DeclareAndCast(Interface_IntVal,intatr,atr);
302 if (!intatr.IsNull()) S<<"Integer="<<intatr->Value();
303 DeclareAndCast(Geom2d_Point,realtr,atr);
304 if (!realtr.IsNull()) S<<"Real="<<realtr->X();
305 if (intatr.IsNull() && realtr.IsNull()) S<<"Type:"<<atr->DynamicType()->Name();
306 S<<endl;
307 }
308 if (nbatr > 0) S<<"-- Total of Attributes : "<<nbatr<<endl;
309 }
310skl*/
311 }
312
313// *** CHECK (commun READ+WRITE) ***
314 if (!binder.IsNull()) {
315 const Handle(Interface_Check) ch = binder->Check();
316 Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
317 if (nbw > 0) {
318 S<<" - Warnings : "<<nbw<<" :\n";
319 for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
320 }
321 if (nbf > 0) {
322 S<<" - Fails : "<<nbf<<" :\n";
323 for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
324 }
325 }
326 return Standard_True;
327}
328
329
330//=======================================================================
331//function : InitTransferReader
332//purpose :
333//=======================================================================
334
335void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
336{
337 if (mode == 0 || mode == 5) theTransferRead->Clear(-1); // full clear
338 if (theTransferRead.IsNull()) SetTransferReader (new XSControl_TransferReader);
339 else SetTransferReader (theTransferRead);
340
341 // mode = 0 fait par SetTransferReader suite a Nullify
342 if (mode == 1) {
343 if (!theTransferRead.IsNull()) theTransferRead->Clear(-1);
344 else SetTransferReader (new XSControl_TransferReader);
345 }
346 if (mode == 2) {
347 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
348 if (TP.IsNull()) {
349 TP = new Transfer_TransientProcess;
350 theTransferRead->SetTransientProcess(TP);
351 TP->SetGraph (HGraph());
352 }
353 Handle(TColStd_HSequenceOfTransient) lis = theTransferRead->RecordedList();
354 Standard_Integer i, nb = lis->Length();
355 for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
356 }
357 if (mode == 3) {
358 Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
359 if (TP.IsNull()) return;
360 Standard_Integer i, nb = TP->NbRoots();
361 for (i = 1; i <= nb; i ++) theTransferRead->RecordResult(TP->Root(i));
362 }
363 if (mode == 4 || mode == 5) theTransferRead->BeginTransfer();
364}
365
366
367//=======================================================================
368//function : SetTransferReader
369//purpose :
370//=======================================================================
371
372void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
373{
374 if (theTransferRead != TR) //i1 pdn 03.04.99 BUC60301
375 theTransferRead = TR;
376 if (TR.IsNull()) return;
377 TR->SetController (theController);
378 TR->SetGraph (HGraph());
379 if (!TR->TransientProcess().IsNull()) return;
380 Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
381 (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
382 TP->SetGraph (HGraph());
383 TP->SetErrorHandle(Standard_True);
384 TR->SetTransientProcess(TP);
385}
386
387
388//=======================================================================
389//function : TransferReader
390//purpose :
391//=======================================================================
392
393Handle(XSControl_TransferReader) XSControl_WorkSession::TransferReader () const
394{
395 return theTransferRead;
396}
397
398
399//=======================================================================
400//function : MapReader
401//purpose :
402//=======================================================================
403
404Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader () const
405{
406 return theTransferRead->TransientProcess();
407}
408
409
410//=======================================================================
411//function : SetMapReader
412//purpose :
413//=======================================================================
414
415Standard_Boolean XSControl_WorkSession::SetMapReader
416 (const Handle(Transfer_TransientProcess)& TP)
417{
418 if ( TP.IsNull()) return Standard_False;
419 if (TP->Model().IsNull()) TP->SetModel (Model());
420 TP->SetGraph (HGraph());
421 if (TP->Model() != Model()) return Standard_False;
422// TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
423// En revanche, mieux vaut le RAZ
424// Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
425 Handle(XSControl_TransferReader) TR = theTransferRead;
426 TR->Clear(-1);
427
428 SetTransferReader (TR); // avec le meme mais le reinitialise
429 TR->SetTransientProcess (TP); // et prend le nouveau TP
430 return Standard_True;
431}
432
433
434//=======================================================================
435//function : Result
436//purpose :
437//=======================================================================
438
439Handle(Standard_Transient) XSControl_WorkSession::Result
440 (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
441{
442 Standard_Integer ouca = (mode % 10);
443 Standard_Integer kica = (mode / 10);
444
445 Handle(Transfer_Binder) binder;
446 Handle(Transfer_ResultFromModel) resu;
447
448 if (ouca != 1) resu = theTransferRead->FinalResult(ent);
449 if (mode == 20) return resu;
450
451 if (!resu.IsNull()) binder = resu->MainResult()->Binder();
452 if (binder.IsNull() && ouca > 0)
453 binder = theTransferRead->TransientProcess()->Find(ent);
454
455 if (kica == 1) return binder;
456 DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
457 if (!trb.IsNull()) return trb->Result();
458 return binder;
459}
460
461// ##########################################
462// ############ TRANSFERT #############
463// ##########################################
464
465
466//=======================================================================
467//function : TransferReadOne
468//purpose :
469//=======================================================================
470
471Standard_Integer XSControl_WorkSession::TransferReadOne
472 (const Handle(Standard_Transient)& ent)
473{
474 //Standard_OStream& sout = Interface_TraceFile::Def();
475 //Standard_Integer level = Interface_TraceFile::DefLevel();
476 Handle(Interface_InterfaceModel) model = Model();
477 if (ent == model) return TransferReadRoots();
478
479 Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
480 if (list->Length() == 1) return theTransferRead->TransferOne(list->Value(1));
481 else return theTransferRead->TransferList (list);
482}
483
484
485//=======================================================================
486//function : TransferReadRoots
487//purpose :
488//=======================================================================
489
490Standard_Integer XSControl_WorkSession::TransferReadRoots ()
491{
492 return theTransferRead->TransferRoots(Graph());
493}
494
495
496// ##########################################
497// ############ TRANSFERT WRITE
498// ##########################################
499
500//=======================================================================
501//function : NewModel
502//purpose :
503//=======================================================================
504
505Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
506{
507 Handle(Interface_InterfaceModel) newmod;
508 if (theController.IsNull()) return newmod;
509 newmod = theController->NewModel();
510 SetModel(newmod);
511 theTransferWrite->Clear(-1);
512 return newmod;
513}
514
515
516//=======================================================================
517//function : TransferWriter
518//purpose :
519//=======================================================================
520
521Handle(XSControl_TransferWriter) XSControl_WorkSession::TransferWriter () const
522{
523 return theTransferWrite;
524}
525
526
527//=======================================================================
528//function : MapWriter
529//purpose :
530//=======================================================================
531
532Handle(Transfer_FinderProcess) XSControl_WorkSession::MapWriter () const
533{
534 return theTransferWrite->FinderProcess();
535}
536
537
538//=======================================================================
539//function : SetMapWriter
540//purpose :
541//=======================================================================
542
543Standard_Boolean XSControl_WorkSession::SetMapWriter
544 (const Handle(Transfer_FinderProcess)& FP)
545{
546 if ( FP.IsNull()) return Standard_False;
547 theTransferWrite->SetFinderProcess (FP);
548 return Standard_True;
549}
550
551
552//=======================================================================
553//function : SetModeWriteShape
554//purpose :
555//=======================================================================
556
557void XSControl_WorkSession::SetModeWriteShape(const Standard_Integer mode)
558{
559 theTransferWrite->SetTransferMode(mode);
560}
561
562
563//=======================================================================
564//function : ModeWriteShape
565//purpose :
566//=======================================================================
567
568Standard_Integer XSControl_WorkSession::ModeWriteShape () const
569{
570 return theTransferWrite->TransferMode();
571}
572
573
574//=======================================================================
575//function : TransferWriteShape
576//purpose :
577//=======================================================================
578
579IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape
580 (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
581{
582 IFSelect_ReturnStatus status;
583 if (theController.IsNull()) return IFSelect_RetError;
584 Handle(Interface_InterfaceModel) model = Model();
585 if (model.IsNull()) return IFSelect_RetVoid;
586
587 status = theTransferWrite->TransferWriteShape (model,shape);
588 // qui s occupe de tout, try/catch inclus
589
590 //skl insert param compgraph for XDE writing 10.12.2003
591 if(compgraph) ComputeGraph(Standard_True);
592
593 return status;
594}
595
596
597//=======================================================================
598//function : TransferWriteCheckList
599//purpose :
600//=======================================================================
601
602Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
603{
604 return theTransferWrite->ResultCheckList (Model());
605}
606
607
608//=======================================================================
609//function : Vars
610//purpose :
611//=======================================================================
612
613Handle(XSControl_Vars) XSControl_WorkSession::Vars () const
614{
615 return theVars;
616}
617
618
619//=======================================================================
620//function : SetVars
621//purpose :
622//=======================================================================
623
624void XSControl_WorkSession::SetVars (const Handle(XSControl_Vars)& newvars)
625{
626 theVars = newvars;
627}
628
629
630//=======================================================================
631//function : ClearBinders
632//purpose :
633//=======================================================================
634
635void XSControl_WorkSession::ClearBinders()
636{
637 Handle(Transfer_FinderProcess) FP = theTransferWrite->FinderProcess();
638 //Due to big number of chains of binders it is necessary to
639 //collect head binders of each chain in the sequence
640 TColStd_SequenceOfTransient aSeqBnd;
641 TColStd_SequenceOfTransient aSeqShapes;
642 Standard_Integer i =1;
643 for( ; i <= FP->NbMapped();i++) {
644 Handle(Transfer_Binder) bnd = FP->MapItem ( i );
645 if(!bnd.IsNull())
646 aSeqBnd.Append(bnd);
647 Handle(Standard_Transient) ash = FP->Mapped(i);
648 aSeqShapes.Append(ash);
649 }
650 //removing finder process containing result of translation.
651 FP->Clear();
652 ClearData(1);
653 ClearData(5);
654
655 //removing each chain of binders
656 while(aSeqBnd.Length() >0) {
657 Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
658 Handle(Standard_Transient) ash =aSeqShapes.Value(1);
659 aSeqBnd.Remove(1);
660 aSeqShapes.Remove(1);
661 ash.Nullify();
662 while(!aBnd.IsNull()) {
663 Handle(Transfer_Binder) aBndNext = aBnd->NextResult();
664 aBnd.Nullify();
665 aBnd = aBndNext;
666 }
667
668 }
669
670}
671
672
673//=======================================================================
674//function : Destroy
675//purpose :
676//=======================================================================
677
678void XSControl_WorkSession::Destroy()
679{
680 ClearBinders();
681}
682
683