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