summaryrefslogtreecommitdiff
path: root/src/XSControl/XSControl_WorkSession.cxx
blob: b5a34e0bbf86cbea55bcdde53a9309cb62e69991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
//:i1 pdn 03.04.99  BUC60301  

#include <XSControl_WorkSession.ixx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Interface_HGraph.hxx>
#include <Interface_Graph.hxx>

#include <IFSelect_Profile.hxx>

#include <Transfer_TransientProcess.hxx>
#include <Transfer_ResultFromModel.hxx>
#include <Transfer_ResultFromTransient.hxx>
#include <TColStd_HSequenceOfTransient.hxx>

#include <TransferBRep.hxx>
#include <Transfer_Binder.hxx>
#include <Transfer_Finder.hxx>
#include <Transfer_SimpleBinderOfTransient.hxx>

// tpent
#include <Interface_IntVal.hxx>
#include <Geom2d_Point.hxx>
#include <Dico_DictionaryOfTransient.hxx>
#include <Dico_IteratorOfDictionaryOfTransient.hxx>

#include <Interface_Macros.hxx>
#include <Interface_Check.hxx>

#include <Message_Messenger.hxx>

//=======================================================================
//function : XSControl_WorkSession
//purpose  : 
//=======================================================================

XSControl_WorkSession::XSControl_WorkSession ()
{
  theModeWriteShape = 0;
  theTransferRead  = new XSControl_TransferReader;
  theTransferWrite = new XSControl_TransferWriter;
  theVars = new XSControl_Vars;
}


//=======================================================================
//function : ClearData
//purpose  : 
//=======================================================================

void  XSControl_WorkSession::ClearData (const Standard_Integer mode)
{
  // 1-2-3-4 : standard IFSelect
  if (mode >= 1 && mode <= 4) IFSelect_WorkSession::ClearData (mode);

  // 5 : Transferts seuls
  // 6 : Resultats forces seuls
  // 7 : Management, y compris tous transferts (forces/calcules), views

  if (mode == 5 || mode == 7) {
    theTransferRead->Clear(-1);
    theTransferWrite->Clear(-1);
  }
  if (mode == 6 && !theTransferRead.IsNull()) theTransferRead->Clear(1);
  theTransferRead->SetGraph (HGraph());
}


//=======================================================================
//function : SelectNorm
//purpose  : 
//=======================================================================

Standard_Boolean  XSControl_WorkSession::SelectNorm(const Standard_CString normname,
                                                    const Standard_CString profile)
{
  //   RAZ ancienne norme  et resultats
  theTransferRead->Clear(-1);
  //  ????  En toute rigueur, menage a faire dans XWS : virer les items
  //        ( a la limite, pourquoi pas, refaire XWS en entier)

  Handle(XSControl_Controller) newadapt =
    XSControl_Controller::Recorded (normname);
  if (newadapt.IsNull()) return Standard_False;
  if (newadapt == theController) return Standard_True;
  SetController (newadapt);
  if (profile && profile[0] != '\0') newadapt->Profile()->SetCurrent(profile);

//  cout<<"##########################\n"
//      <<"##  Select Norm : "<<normname<<"\n"
//      <<"##########################"<<endl;
  return Standard_True;
}


//=======================================================================
//function : SelectProfile
//purpose  : 
//=======================================================================

Standard_Boolean  XSControl_WorkSession::SelectProfile(const Standard_CString profile)
{
  return theController->Profile()->SetCurrent(profile);
}


//=======================================================================
//function : SetController
//purpose  : 
//=======================================================================

void  XSControl_WorkSession::SetController(const Handle(XSControl_Controller)& ctl)
{
  theController = ctl;

  SetLibrary   ( theController->WorkLibrary() );
  SetProtocol  ( theController->Protocol() );
  ClearItems();  ClearFinalModifiers();
  ClearShareOut(Standard_False);  ClearFile();
  Handle(XSControl_WorkSession) aWorkSession = this;
  theController->Customise (aWorkSession);
  SetSignType  ( theController->SignType() );
  theTransferRead->SetController (theController);
  theTransferWrite->SetController (theController);

  AdaptNorm ();
}


//=======================================================================
//function : AdaptNorm
//purpose  : 
//=======================================================================

void XSControl_WorkSession::AdaptNorm ()
{
}


//=======================================================================
//function : SelectedNorm
//purpose  : 
//=======================================================================

Standard_CString XSControl_WorkSession::SelectedNorm(const Standard_Boolean rsc) const
{
  //JR/Hp :
  Standard_CString astr = (Standard_CString ) (theController.IsNull() ? "" : theController->Name(rsc));
  return astr ;
}
//      {  return (theController.IsNull() ? "" : theController->Name(rsc));  }


//=======================================================================
//function : NormAdaptor
//purpose  : 
//=======================================================================

Handle(XSControl_Controller) XSControl_WorkSession::NormAdaptor () const
{
  return theController;
}


//              ##########################################
//              ############  Contexte de Transfert ######
//              ##########################################


//=======================================================================
//function : Context
//purpose  : 
//=======================================================================

Handle(Dico_DictionaryOfTransient) XSControl_WorkSession::Context () const
{
  return theContext;
}


//=======================================================================
//function : SetAllContext
//purpose  : 
//=======================================================================

void XSControl_WorkSession::SetAllContext(const Handle(Dico_DictionaryOfTransient)& context)
{
  theContext = context;
  theTransferRead->Context() = context;
}


//=======================================================================
//function : ClearContext
//purpose  : 
//=======================================================================

void XSControl_WorkSession::ClearContext ()
{
  Handle(Dico_DictionaryOfTransient) nulctx;
  SetAllContext(nulctx);
}


//              ##########################################
//              ############    RESULTATS FORCES    ######
//              ##########################################


//=======================================================================
//function : PrintTransferStatus
//purpose  : 
//=======================================================================

Standard_Boolean  XSControl_WorkSession::PrintTransferStatus(const Standard_Integer num,
                                                             const Standard_Boolean wri,
                                                             const Handle(Message_Messenger)& S) const
{
  Handle(Transfer_FinderProcess)    FP = MapWriter();
  Handle(Transfer_TransientProcess) TP = MapReader();

  Handle(Transfer_Binder) binder;
  Handle(Transfer_Finder) finder;
  Handle(Standard_Transient) ent;

  //   ***   WRITE  ***
  if (wri) {
    if (FP.IsNull()) return Standard_False;
    if (num == 0 ) return Standard_False;

    Standard_Integer ne=0, nr=0, max = FP->NbMapped() ,maxr = FP->NbRoots();
    if (num > 0) {
      if (num > max) return Standard_False;
      ne = num;
      finder = FP->Mapped(ne);
      nr = FP->RootIndex(finder);
    } else if (num < 0) {
      nr = -num;
      if (nr > maxr) return Standard_False;
      finder = FP->Root(nr);
      ne  = FP->MapIndex(finder);
    }

    S<<"Transfer Write item n0."<<ne<<" of "<<max;
    if (nr > 0) S<<"  ** Transfer Root n0."<<ne;  S<<endl;
    ent = FP->FindTransient(finder);
    S<<" -> Type "<<finder->DynamicType()->Name()<<endl;
    FP->StartTrace (binder,finder,0,0);  // pb sout/S
    if (!ent.IsNull()) {
      S<<" ** Resultat Transient, type "<<ent->DynamicType()->Name();
      Handle(Interface_InterfaceModel) model = Model();
      if (!model.IsNull())
	{  S<<" In output Model, Entity ";  model->Print(ent,S);  }
      S<<endl;
    }
  }

  //    ***   READ   ***
  else {
    if (TP.IsNull()) return Standard_False;
    Handle(Interface_InterfaceModel) model = TP->Model();
    if (model.IsNull()) cout<<"No Model"<<endl;
    else if (model != Model()) cout<<"Model different from the session"<<endl;
    if (num == 0) return Standard_False;

    Standard_Integer  ne=0, nr=0, max = TP->NbMapped() ,maxr = TP->NbRoots();
    if (num > 0) {
      if (num > max) return Standard_False;
      ne = num;
      ent = TP->Mapped(ne);
      nr = TP->RootIndex(finder);
    } else if (num < 0) {
      nr = -num;
      if (nr > maxr) return Standard_False;
      ent = TP->Root(nr);
      ne  = TP->MapIndex(ent);
    }

    S<<"Transfer Read item n0."<<ne<<" of "<<max;
    if (nr > 0) S<<"  ** Transfer Root n0."<<ne;  S<<endl;
    if (!model.IsNull())  {  S<<" In Model, Entity ";  model->Print(ent,S); }
    binder = TP->MapItem (ne);
    S<<endl;
    TP->StartTrace (binder,ent,0,0);
/*skl
    if (!binder.IsNull()) {
      // infos complementaires : cas et attributs
      Standard_Integer icas, nbcas = binder->NbCases();
      if (nbcas > 0) S<<"Recorded Cases : "<<nbcas<<" :";
      for (icas = 1; icas <= nbcas; icas ++) S<<"  "<<binder->CaseName(icas);
      if (nbcas > 0) S<<endl;
      Standard_Integer nbatr = 0;
      Handle(Dico_DictionaryOfTransient) atrs = binder->AttrList();
      Dico_IteratorOfDictionaryOfTransient iatr (atrs);
      for (; iatr.More(); iatr.Next()) {
	Handle(Standard_Transient) atr = iatr.Value();
	if (atr.IsNull()) continue;
	if (nbatr == 0) S<<"-- List of Attributes"<<endl;
	nbatr ++;
	S<<iatr.Name()<<" : ";
	DeclareAndCast(Interface_IntVal,intatr,atr);
	if (!intatr.IsNull()) S<<"Integer="<<intatr->Value();
	DeclareAndCast(Geom2d_Point,realtr,atr);
	if (!realtr.IsNull()) S<<"Real="<<realtr->X();
	if (intatr.IsNull() && realtr.IsNull()) S<<"Type:"<<atr->DynamicType()->Name();
	S<<endl;
      }
      if (nbatr > 0) S<<"-- Total of Attributes : "<<nbatr<<endl;
    }
skl*/
  }

//   ***   CHECK (commun READ+WRITE)   ***
  if (!binder.IsNull()) {
    const Handle(Interface_Check) ch = binder->Check();
    Standard_Integer i,nbw = ch->NbWarnings(), nbf = ch->NbFails();
    if (nbw > 0) {
      S<<" - Warnings : "<<nbw<<" :\n";
      for (i = 1; i <= nbw; i ++) S<<ch->CWarning(i)<<endl;
    }
    if (nbf > 0) {
      S<<" - Fails : "<<nbf<<" :\n";
      for (i = 1; i <= nbf; i ++) S<<ch->CFail(i)<<endl;
    }
  }
  return Standard_True;
}


//=======================================================================
//function : InitTransferReader
//purpose  : 
//=======================================================================

void  XSControl_WorkSession::InitTransferReader(const Standard_Integer mode)
{
  if (mode == 0 || mode == 5)  theTransferRead->Clear(-1);  // full clear
  if (theTransferRead.IsNull()) SetTransferReader (new XSControl_TransferReader);
  else SetTransferReader (theTransferRead);

  // mode = 0 fait par SetTransferReader suite a Nullify
  if (mode == 1) {
    if (!theTransferRead.IsNull()) theTransferRead->Clear(-1);
    else SetTransferReader (new XSControl_TransferReader);
  }
  if (mode == 2) {
    Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
    if (TP.IsNull()) {
      TP = new Transfer_TransientProcess;
      theTransferRead->SetTransientProcess(TP);
      TP->SetGraph (HGraph());
    }
    Handle(TColStd_HSequenceOfTransient) lis = theTransferRead->RecordedList();
    Standard_Integer i, nb = lis->Length();
    for (i = 1; i <= nb; i ++) TP->SetRoot(lis->Value(i));
  }
  if (mode == 3) {
    Handle(Transfer_TransientProcess) TP = theTransferRead->TransientProcess();
    if (TP.IsNull()) return;
    Standard_Integer i, nb = TP->NbRoots();
    for (i = 1; i <= nb; i ++) theTransferRead->RecordResult(TP->Root(i));
  }
  if (mode == 4 || mode == 5) theTransferRead->BeginTransfer();
}


//=======================================================================
//function : SetTransferReader
//purpose  : 
//=======================================================================

void XSControl_WorkSession::SetTransferReader(const Handle(XSControl_TransferReader)& TR)
{
  if (theTransferRead != TR) //i1 pdn 03.04.99 BUC60301
    theTransferRead = TR;
  if (TR.IsNull()) return;
  TR->SetController (theController);
  TR->SetGraph (HGraph());
  if (!TR->TransientProcess().IsNull()) return;
  Handle(Transfer_TransientProcess) TP = new Transfer_TransientProcess
    (Model().IsNull() ? 100 : Model()->NbEntities() + 100);
  TP->SetGraph (HGraph());
  TP->SetErrorHandle(Standard_True);
  TR->SetTransientProcess(TP);
}


//=======================================================================
//function : TransferReader
//purpose  : 
//=======================================================================

Handle(XSControl_TransferReader) XSControl_WorkSession::TransferReader () const
{
  return theTransferRead;
}


//=======================================================================
//function : MapReader
//purpose  : 
//=======================================================================

Handle(Transfer_TransientProcess) XSControl_WorkSession::MapReader () const
{
  return theTransferRead->TransientProcess();
}


//=======================================================================
//function : SetMapReader
//purpose  : 
//=======================================================================

Standard_Boolean  XSControl_WorkSession::SetMapReader
  (const Handle(Transfer_TransientProcess)& TP)
{
  if ( TP.IsNull())  return Standard_False;
  if (TP->Model().IsNull()) TP->SetModel (Model());
  TP->SetGraph (HGraph());
  if (TP->Model() != Model()) return Standard_False;
//  TR ne doit pas bouger, c est un "crochet" pour signatures, selections ...
//  En revanche, mieux vaut le RAZ
//  Handle(XSControl_TransferReader) TR = new XSControl_TransferReader;
  Handle(XSControl_TransferReader) TR = theTransferRead;
  TR->Clear(-1);

  SetTransferReader (TR);        // avec le meme mais le reinitialise
  TR->SetTransientProcess (TP);  // et prend le nouveau TP
  return Standard_True;
}


//=======================================================================
//function : Result
//purpose  : 
//=======================================================================

Handle(Standard_Transient)  XSControl_WorkSession::Result
  (const Handle(Standard_Transient)& ent, const Standard_Integer mode) const
{
  Standard_Integer ouca = (mode % 10);
  Standard_Integer kica = (mode / 10);

  Handle(Transfer_Binder) binder;
  Handle(Transfer_ResultFromModel) resu;

  if (ouca !=  1) resu = theTransferRead->FinalResult(ent);
  if (mode == 20) return resu;

  if (!resu.IsNull()) binder = resu->MainResult()->Binder();
  if (binder.IsNull() && ouca > 0)
    binder = theTransferRead->TransientProcess()->Find(ent);

  if (kica == 1) return binder;
  DeclareAndCast(Transfer_SimpleBinderOfTransient,trb,binder);
  if (!trb.IsNull()) return trb->Result();
  return binder;
}

//              ##########################################
//              ############    TRANSFERT    #############
//              ##########################################


//=======================================================================
//function : TransferReadOne
//purpose  : 
//=======================================================================

Standard_Integer  XSControl_WorkSession::TransferReadOne
  (const Handle(Standard_Transient)& ent)
{
  //Standard_OStream& sout = Interface_TraceFile::Def();
  //Standard_Integer level = Interface_TraceFile::DefLevel();
  Handle(Interface_InterfaceModel) model = Model();
  if (ent == model) return TransferReadRoots();

  Handle(TColStd_HSequenceOfTransient) list = GiveList(ent);
  if (list->Length() == 1) return theTransferRead->TransferOne(list->Value(1));
  else return theTransferRead->TransferList (list);
}


//=======================================================================
//function : TransferReadRoots
//purpose  : 
//=======================================================================

Standard_Integer  XSControl_WorkSession::TransferReadRoots ()
{
  return theTransferRead->TransferRoots(Graph());
}


//              ##########################################
//              ############    TRANSFERT  WRITE
//              ##########################################

//=======================================================================
//function : NewModel
//purpose  : 
//=======================================================================

Handle(Interface_InterfaceModel) XSControl_WorkSession::NewModel ()
{
  Handle(Interface_InterfaceModel) newmod;
  if (theController.IsNull()) return newmod;
  newmod = theController->NewModel();
  SetModel(newmod);
  theTransferWrite->Clear(-1);
  return newmod;
}


//=======================================================================
//function : TransferWriter
//purpose  : 
//=======================================================================

Handle(XSControl_TransferWriter) XSControl_WorkSession::TransferWriter () const
{
  return theTransferWrite;
}


//=======================================================================
//function : MapWriter
//purpose  : 
//=======================================================================

Handle(Transfer_FinderProcess) XSControl_WorkSession::MapWriter () const
{
  return theTransferWrite->FinderProcess();
}


//=======================================================================
//function : SetMapWriter
//purpose  : 
//=======================================================================

Standard_Boolean XSControl_WorkSession::SetMapWriter
  (const Handle(Transfer_FinderProcess)& FP)
{
  if ( FP.IsNull())  return Standard_False;
  theTransferWrite->SetFinderProcess (FP);
  return Standard_True;
}


//=======================================================================
//function : SetModeWriteShape
//purpose  : 
//=======================================================================

void XSControl_WorkSession::SetModeWriteShape(const Standard_Integer mode)
{
  theTransferWrite->SetTransferMode(mode);
}


//=======================================================================
//function : ModeWriteShape
//purpose  : 
//=======================================================================

Standard_Integer XSControl_WorkSession::ModeWriteShape () const
{
  return theTransferWrite->TransferMode();
}


//=======================================================================
//function : TransferWriteShape
//purpose  : 
//=======================================================================

IFSelect_ReturnStatus XSControl_WorkSession::TransferWriteShape
  (const TopoDS_Shape& shape, const Standard_Boolean compgraph)
{
  IFSelect_ReturnStatus  status;
  if (theController.IsNull()) return IFSelect_RetError;
  Handle(Interface_InterfaceModel) model = Model();
  if (model.IsNull()) return IFSelect_RetVoid;

  status = theTransferWrite->TransferWriteShape (model,shape);
  //  qui s occupe de tout, try/catch inclus

  //skl insert param compgraph for XDE writing 10.12.2003
  if(compgraph) ComputeGraph(Standard_True);

  return status;
}


//=======================================================================
//function : TransferWriteCheckList
//purpose  : 
//=======================================================================

Interface_CheckIterator XSControl_WorkSession::TransferWriteCheckList () const
{
  return theTransferWrite->ResultCheckList (Model());
}


//=======================================================================
//function : Vars
//purpose  : 
//=======================================================================

Handle(XSControl_Vars) XSControl_WorkSession::Vars () const
{
  return theVars;
}


//=======================================================================
//function : SetVars
//purpose  : 
//=======================================================================

void XSControl_WorkSession::SetVars (const Handle(XSControl_Vars)& newvars)
{
  theVars = newvars;
}


//=======================================================================
//function : ClearBinders
//purpose  : 
//=======================================================================

void XSControl_WorkSession::ClearBinders()
{
  Handle(Transfer_FinderProcess) FP = theTransferWrite->FinderProcess();
  //Due to big number of chains of binders it is necessary to 
  //collect head binders of each chain in the sequence
  TColStd_SequenceOfTransient aSeqBnd;
  TColStd_SequenceOfTransient aSeqShapes;
  Standard_Integer i =1;
  for( ; i <= FP->NbMapped();i++) {
    Handle(Transfer_Binder) bnd = FP->MapItem ( i );
    if(!bnd.IsNull())
      aSeqBnd.Append(bnd);
    Handle(Standard_Transient) ash = FP->Mapped(i);
    aSeqShapes.Append(ash);
  }
  //removing finder process containing result of translation.
  FP->Clear();
  ClearData(1);
  ClearData(5);
  
  //removing each chain of binders
  while(aSeqBnd.Length() >0) {
    Handle(Transfer_Binder) aBnd = Handle(Transfer_Binder)::DownCast(aSeqBnd.Value(1));
    Handle(Standard_Transient) ash =aSeqShapes.Value(1);
    aSeqBnd.Remove(1);
    aSeqShapes.Remove(1);
    ash.Nullify();
    while(!aBnd.IsNull()) {
      Handle(Transfer_Binder) aBndNext = aBnd->NextResult();
      aBnd.Nullify();
      aBnd = aBndNext;
    }
    
  }

}


//=======================================================================
//function : Destroy
//purpose  : 
//=======================================================================

void XSControl_WorkSession::Destroy()
{
  ClearBinders();
}