0024788: Foundation Classes - remove Dico_Dictionary
[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 <Geom2d_Point.hxx>
17#include <Interface_Check.hxx>
18#include <Interface_CheckIterator.hxx>
7fd59977 19#include <Interface_Graph.hxx>
42cf5bc1 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>
42cf5bc1 25#include <Standard_ErrorHandler.hxx>
26#include <Standard_Failure.hxx>
7fd59977 27#include <TColStd_HSequenceOfTransient.hxx>
42cf5bc1 28#include <TopoDS_Shape.hxx>
7fd59977 29#include <Transfer_Binder.hxx>
30#include <Transfer_Finder.hxx>
42cf5bc1 31#include <Transfer_FinderProcess.hxx>
32#include <Transfer_ResultFromModel.hxx>
33#include <Transfer_ResultFromTransient.hxx>
7fd59977 34#include <Transfer_SimpleBinderOfTransient.hxx>
42cf5bc1 35#include <Transfer_TransientProcess.hxx>
36#include <TransferBRep.hxx>
37#include <XSControl_Controller.hxx>
38#include <XSControl_TransferReader.hxx>
42cf5bc1 39#include <XSControl_Vars.hxx>
40#include <XSControl_WorkSession.hxx>
7fd59977 41
92efcf78 42IMPLEMENT_STANDARD_RTTIEXT(XSControl_WorkSession,IFSelect_WorkSession)
43
7fd59977 44//=======================================================================
45//function : XSControl_WorkSession
46//purpose :
47//=======================================================================
7f56eba8 48
7fd59977 49XSControl_WorkSession::XSControl_WorkSession ()
7f56eba8 50: myTransferReader(new XSControl_TransferReader),
51 myTransferWriter(new XSControl_TransferWriter),
52 myVars(new XSControl_Vars)
7fd59977 53{
7fd59977 54}
55
56
57//=======================================================================
58//function : ClearData
59//purpose :
60//=======================================================================
61
62void XSControl_WorkSession::ClearData (const Standard_Integer mode)
63{
64 // 1-2-3-4 : standard IFSelect
65 if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode);
66
67 // 5 : Transferts seuls
68 // 6 : Resultats forces seuls
69 // 7 : Management, y compris tous transferts (forces/calcules), views
70
71 if (mode == 5 || mode == 7) {
7f56eba8 72 myTransferReader->Clear(-1);
73 myTransferWriter->Clear(-1);
7fd59977 74 }
7f56eba8 75 if (mode == 6 && !myTransferReader.IsNull()) myTransferReader->Clear(1);
76 myTransferReader->SetGraph (HGraph());
7fd59977 77}
78
79
80//=======================================================================
81//function : SelectNorm
82//purpose :
83//=======================================================================
84
7f56eba8 85Standard_Boolean XSControl_WorkSession::SelectNorm(const Standard_CString normname)
7fd59977 86{
7f56eba8 87 // Old norm and results
88 myTransferReader->Clear(-1);
7fd59977 89 // ???? En toute rigueur, menage a faire dans XWS : virer les items
90 // ( a la limite, pourquoi pas, refaire XWS en entier)
91
7f56eba8 92 Handle(XSControl_Controller) newadapt = XSControl_Controller::Recorded (normname);
7fd59977 93 if (newadapt.IsNull()) return Standard_False;
7f56eba8 94 if (newadapt == myController) return Standard_True;
7fd59977 95 SetController (newadapt);
7fd59977 96 return Standard_True;
97}
98
99
100//=======================================================================
7fd59977 101//function : SetController
102//purpose :
103//=======================================================================
104
7f56eba8 105void XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl)
7fd59977 106{
7f56eba8 107 myController = ctl;
7fd59977 108
7f56eba8 109 SetLibrary ( myController->WorkLibrary() );
110 SetProtocol ( myController->Protocol() );
7fd59977 111
7f56eba8 112 ClearItems();
113 ClearFinalModifiers();
114 ClearShareOut(Standard_False);
115 ClearFile();
7fd59977 116
7f56eba8 117 // Set worksession parameters from teh controller
118 Handle(XSControl_WorkSession) aWorkSession(this);
119 myController->Customise (aWorkSession);
120
121 myTransferReader->SetController (myController);
122 myTransferWriter->SetController (myController);
7fd59977 123}
124
125
126//=======================================================================
127//function : SelectedNorm
128//purpose :
129//=======================================================================
130
131Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const
132{
133 //JR/Hp :
7f56eba8 134 Standard_CString astr = (Standard_CString ) (myController.IsNull() ? "" : myController->Name(rsc));
7fd59977 135 return astr ;
136}
7fd59977 137
138
139// ##########################################
140// ############ Contexte de Transfert ######
141// ##########################################
142
143
144//=======================================================================
7fd59977 145//function : SetAllContext
146//purpose :
147//=======================================================================
148
997e128f 149void XSControl_WorkSession::SetAllContext(const NCollection_DataMap<TCollection_AsciiString, Handle(Standard_Transient)>& context)
7fd59977 150{
7f56eba8 151 myContext = context;
152 myTransferReader->Context() = context;
7fd59977 153}
154
155
156//=======================================================================
157//function : ClearContext
158//purpose :
159//=======================================================================
160
161void XSControl_WorkSession::ClearContext ()
162{
997e128f 163 myContext.Clear();
164 myTransferReader->Context().Clear();
7fd59977 165}
166
167
168// ##########################################
169// ############ RESULTATS FORCES ######
170// ##########################################
171
172
173//=======================================================================
174//function : PrintTransferStatus
175//purpose :
176//=======================================================================
177
178Standard_Boolean XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num,
179 const Standard_Boolean wri,
180 const Handle(Message_Messenger)& S) const
181{
7f56eba8 182 const Handle(Transfer_FinderProcess) &FP = myTransferWriter->FinderProcess();
183 Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess();
7fd59977 184
185 Handle(Transfer_Binder) binder;
186 Handle(Transfer_Finder) finder;
187 Handle(Standard_Transient) ent;
188
189 // *** WRITE ***
190 if (wri) {
191 if (FP.IsNull()) return Standard_False;
192 if (num == 0 ) return Standard_False;
193
194 Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots();
195 if (num > 0) {
196 if (num > max) return Standard_False;
197 ne = num;
198 finder = FP->Mapped(ne);
199 nr = FP->RootIndex(finder);
200 } else if (num < 0) {
201 nr = -num;
202 if (nr > maxr) return Standard_False;
203 finder = FP->Root(nr);
204 ne = FP->MapIndex(finder);
205 }
206
207 S<<"Transfer Write item n0."<<ne<<" of "<<max;
208 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
209 ent = FP->FindTransient(finder);
210 S<<" -> Type "<<finder->DynamicType()->Name()<<endl;
211 FP->StartTrace (binder,finder,0,0); // pb sout/S
212 if (!ent.IsNull()) {
213 S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name();
7f56eba8 214 const Handle(Interface_InterfaceModel) &model = Model();
7fd59977 215 if (!model.IsNull())
216 { S<<" In output Model, Entity "; model->Print(ent,S); }
217 S<<endl;
218 }
219 }
220
221 // *** READ ***
222 else {
223 if (TP.IsNull()) return Standard_False;
224 Handle(Interface_InterfaceModel) model = TP->Model();
225 if (model.IsNull()) cout<<"No Model"<<endl;
226 else if (model != Model()) cout<<"Model different from the session"<<endl;
227 if (num == 0) return Standard_False;
228
229 Standard_Integer ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots();
230 if (num > 0) {
231 if (num > max) return Standard_False;
232 ne = num;
233 ent = TP->Mapped(ne);
234 nr = TP->RootIndex(finder);
235 } else if (num < 0) {
236 nr = -num;
237 if (nr > maxr) return Standard_False;
238 ent = TP->Root(nr);
239 ne = TP->MapIndex(ent);
240 }
241
242 S<<"Transfer Read item n0."<<ne<<" of "<<max;
243 if (nr > 0) S<<" ** Transfer Root n0."<<ne; S<<endl;
244 if (!model.IsNull()) { S<<" In Model, Entity "; model->Print(ent,S); }
245 binder = TP->MapItem (ne);
246 S<<endl;
247 TP->StartTrace (binder,ent,0,0);
bc650d41 248
7fd59977 249 }
250
251// *** CHECK (commun READ+WRITE) ***
252 if (!binder.IsNull()) {
253 const Handle(Interface_Check) ch = binder->Check();
254 Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
255 if (nbw > 0) {
256 S<<" - Warnings : "<<nbw<<" :\n";
257 for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
258 }
259 if (nbf > 0) {
260 S<<" - Fails : "<<nbf<<" :\n";
261 for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
262 }
263 }
264 return Standard_True;
265}
266
267
268//=======================================================================
269//function : InitTransferReader
270//purpose :
271//=======================================================================
272
273void XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
274{
7f56eba8 275 if (mode == 0 || mode == 5) myTransferReader->Clear(-1); // full clear
276 if (myTransferReader.IsNull()) SetTransferReader (new XSControl_TransferReader);
277 else SetTransferReader (myTransferReader);
7fd59977 278
279 // mode = 0 fait par SetTransferReader suite a Nullify
280 if (mode == 1) {
7f56eba8 281 if (!myTransferReader.IsNull()) myTransferReader->Clear(-1);
7fd59977 282 else SetTransferReader (new XSControl_TransferReader);
283 }
284 if (mode == 2) {
7f56eba8 285 Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess();
7fd59977 286 if (TP.IsNull()) {
287 TP = new Transfer_TransientProcess;
7f56eba8 288 myTransferReader->SetTransientProcess(TP);
7fd59977 289 TP->SetGraph (HGraph());
290 }
7f56eba8 291 Handle(TColStd_HSequenceOfTransient) lis = myTransferReader->RecordedList();
7fd59977 292 Standard_Integer i, nb = lis->Length();
293 for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
294 }
295 if (mode == 3) {
7f56eba8 296 Handle(Transfer_TransientProcess) TP = myTransferReader->TransientProcess();
7fd59977 297 if (TP.IsNull()) return;
298 Standard_Integer i, nb = TP->NbRoots();
7f56eba8 299 for (i = 1; i <= nb; i ++) myTransferReader->RecordResult(TP->Root(i));
7fd59977 300 }
7f56eba8 301 if (mode == 4 || mode == 5) myTransferReader->BeginTransfer();
7fd59977 302}
303
304
305//=======================================================================
306//function : SetTransferReader
307//purpose :
308//=======================================================================
309
310void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
311{
7f56eba8 312 if (myTransferReader != TR) //i1 pdn 03.04.99 BUC60301
313 myTransferReader = TR;
7fd59977 314 if (TR.IsNull()) return;
7f56eba8 315 TR->SetController (myController);
7fd59977 316 TR->SetGraph (HGraph());
317 if (!TR->TransientProcess().IsNull()) return;
318 Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
319 (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
320 TP->SetGraph (HGraph());
321 TP->SetErrorHandle(Standard_True);
322 TR->SetTransientProcess(TP);
323}
324
8d0b8649 325//=======================================================================
326//function : MapReader
327//purpose :
328//=======================================================================
329
330Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader() const
331{
332 return myTransferReader->TransientProcess();
333}
7fd59977 334
335//=======================================================================
7fd59977 336//function : SetMapReader
337//purpose :
338//=======================================================================
339
7f56eba8 340Standard_Boolean XSControl_WorkSession::SetMapReader (const Handle(Transfer_TransientProcess)& TP)
7fd59977 341{
7f56eba8 342 if (TP.IsNull()) return Standard_False;
7fd59977 343 if (TP->Model().IsNull()) TP->SetModel (Model());
344 TP->SetGraph (HGraph());
345 if (TP->Model() != Model()) return Standard_False;
346// TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
347// En revanche, mieux vaut le RAZ
348// Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
7f56eba8 349 Handle(XSControl_TransferReader) TR = myTransferReader;
7fd59977 350 TR->Clear(-1);
351
352 SetTransferReader (TR); // avec le meme mais le reinitialise
353 TR->SetTransientProcess (TP); // et prend le nouveau TP
354 return Standard_True;
355}
356
357
358//=======================================================================
359//function : Result
360//purpose :
361//=======================================================================
362
363Handle(Standard_Transient) XSControl_WorkSession::Result
364 (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
365{
366 Standard_Integer ouca = (mode % 10);
367 Standard_Integer kica = (mode / 10);
368
369 Handle(Transfer_Binder) binder;
370 Handle(Transfer_ResultFromModel) resu;
371
7f56eba8 372 if (ouca != 1) resu = myTransferReader->FinalResult(ent);
7fd59977 373 if (mode == 20) return resu;
374
375 if (!resu.IsNull()) binder = resu->MainResult()->Binder();
376 if (binder.IsNull() && ouca > 0)
7f56eba8 377 binder = myTransferReader->TransientProcess()->Find(ent);
7fd59977 378
379 if (kica == 1) return binder;
380 DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
381 if (!trb.IsNull()) return trb->Result();
382 return binder;
383}
384
385// ##########################################
386// ############ TRANSFERT #############
387// ##########################################
388
389
390//=======================================================================
391//function : TransferReadOne
392//purpose :
393//=======================================================================
394
7f56eba8 395Standard_Integer XSControl_WorkSession::TransferReadOne (const Handle(Standard_Transient)& ent)
7fd59977 396{
7fd59977 397 Handle(Interface_InterfaceModel) model = Model();
398 if (ent == model) return TransferReadRoots();
399
400 Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
7f56eba8 401 if (list->Length() == 1) return myTransferReader->TransferOne(list->Value(1));
402 else return myTransferReader->TransferList (list);
7fd59977 403}
404
405
406//=======================================================================
407//function : TransferReadRoots
408//purpose :
409//=======================================================================
410
7f56eba8 411Standard_Integer XSControl_WorkSession::TransferReadRoots ()
7fd59977 412{
7f56eba8 413 return myTransferReader->TransferRoots(Graph());
7fd59977 414}
415
416
417// ##########################################
418// ############ TRANSFERT WRITE
419// ##########################################
420
421//=======================================================================
422//function : NewModel
423//purpose :
424//=======================================================================
425
426Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
427{
428 Handle(Interface_InterfaceModel) newmod;
7f56eba8 429 if (myController.IsNull()) return newmod;
430 newmod = myController->NewModel();
bc650d41 431
7fd59977 432 SetModel(newmod);
7f56eba8 433 if(!myTransferReader->TransientProcess().IsNull())
434 myTransferReader->TransientProcess()->Clear();
bc650d41 435 //clear all contains of WS
7f56eba8 436 myTransferReader->Clear(3);
437 myTransferWriter->Clear(-1);
bc650d41 438
7fd59977 439 return newmod;
440}
441
442
443//=======================================================================
7fd59977 444//function : TransferWriteShape
445//purpose :
446//=======================================================================
447
7f56eba8 448IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
7fd59977 449{
450 IFSelect_ReturnStatus status;
7f56eba8 451 if (myController.IsNull()) return IFSelect_RetError;
452 const Handle(Interface_InterfaceModel) &model = Model();
7fd59977 453 if (model.IsNull()) return IFSelect_RetVoid;
454
7f56eba8 455 status = myTransferWriter->TransferWriteShape (model,shape);
7fd59977 456 // qui s occupe de tout, try/catch inclus
457
458 //skl insert param compgraph for XDE writing 10.12.2003
459 if(compgraph) ComputeGraph(Standard_True);
460
461 return status;
462}
463
464
465//=======================================================================
466//function : TransferWriteCheckList
467//purpose :
468//=======================================================================
469
470Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
471{
7f56eba8 472 return myTransferWriter->ResultCheckList (Model());
7fd59977 473}
474
475
476//=======================================================================
477//function : ClearBinders
478//purpose :
479//=======================================================================
480
481void XSControl_WorkSession::ClearBinders()
482{
7f56eba8 483 const Handle(Transfer_FinderProcess) &FP = myTransferWriter->FinderProcess();
7fd59977 484 //Due to big number of chains of binders it is necessary to
485 //collect head binders of each chain in the sequence
486 TColStd_SequenceOfTransient aSeqBnd;
487 TColStd_SequenceOfTransient aSeqShapes;
488 Standard_Integer i =1;
489 for( ; i <= FP->NbMapped();i++) {
490 Handle(Transfer_Binder) bnd = FP->MapItem ( i );
491 if(!bnd.IsNull())
492 aSeqBnd.Append(bnd);
5b111128 493 Handle(Standard_Transient) ash (FP->Mapped(i));
7fd59977 494 aSeqShapes.Append(ash);
495 }
496 //removing finder process containing result of translation.
497 FP->Clear();
498 ClearData(1);
499 ClearData(5);
500
501 //removing each chain of binders
502 while(aSeqBnd.Length() >0) {
503 Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
504 Handle(Standard_Transient) ash =aSeqShapes.Value(1);
505 aSeqBnd.Remove(1);
506 aSeqShapes.Remove(1);
507 ash.Nullify();
508 while(!aBnd.IsNull()) {
509 Handle(Transfer_Binder) aBndNext = aBnd->NextResult();
510 aBnd.Nullify();
511 aBnd = aBndNext;
512 }
513
514 }
515
516}