0024947: Redesign OCCT legacy type system -- final corrections
[occt.git] / src / IFSelect / IFSelect_WorkSession.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //#1 svv   10.01.00 : porting on DEC 
15 //smh#14 17.03.2000 : FRA62479 Clearing of gtool
16 #include <Standard_ErrorHandler.hxx>
17 #include <IFSelect_WorkSession.ixx>
18 #include <IFSelect_DispPerOne.hxx>
19 #include <IFSelect_DispPerCount.hxx>
20 #include <IFSelect_DispGlobal.hxx>
21 #include <IFSelect_ShareOutResult.hxx>
22 #include <Interface_Graph.hxx>
23 #include <IFGraph_SubPartsIterator.hxx>
24 #include <IFSelect_PacketList.hxx>
25 #include <Interface_ReportEntity.hxx>
26 #include <Interface_Static.hxx>
27
28 #include <IFSelect_SignValidity.hxx>
29 #include <Interface_Category.hxx>
30 #include <Interface_Check.hxx>
31 #include <Interface_CheckTool.hxx>
32 #include <Interface_CheckIterator.hxx>
33 #include <Interface_ShareTool.hxx>
34 #include <Interface_ShareFlags.hxx>
35 #include <Interface_GeneralLib.hxx>
36 #include <Interface_GeneralModule.hxx>
37 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
38 #include <Dico_IteratorOfDictionaryOfInteger.hxx>
39 #include <Interface_CopyTool.hxx>
40 #include <Interface_CopyControl.hxx>
41
42 #include <IFSelect_SelectDeduct.hxx>
43 #include <IFSelect_SelectExtract.hxx>
44 #include <IFSelect_SelectModelRoots.hxx>
45 #include <IFSelect_SelectModelEntities.hxx>
46 #include <IFSelect_SelectEntityNumber.hxx>
47 #include <IFSelect_SelectPointed.hxx>
48 #include <IFSelect_SelectControl.hxx>
49 #include <IFSelect_SelectDiff.hxx>
50 #include <IFSelect_SelectCombine.hxx>
51 #include <IFSelect_SelectUnion.hxx>
52 #include <IFSelect_SelectIntersection.hxx>
53 #include <IFSelect_SelectSignature.hxx>
54
55 #include <IFSelect_EditForm.hxx>
56 #include <IFSelect_Editor.hxx>
57 #include <IFSelect_ParamEditor.hxx>
58 #include <IFSelect_CheckCounter.hxx>
59 #include <IFSelect_TransformStandard.hxx>
60
61 #include <TColStd_MapOfInteger.hxx>
62 #include <OSD_Path.hxx>
63 #include <Interface_Macros.hxx>
64 #include <Interface_MSG.hxx>
65 #include <Message_Messenger.hxx>
66 #include <Message.hxx>
67 #include <Standard_Failure.hxx>
68 #include <IFSelect_SignatureList.hxx>
69 #include <TCollection_HAsciiString.hxx>
70 #include <IFSelect_Dispatch.hxx>
71 #include <IFSelect_Modifier.hxx>
72 #include <IFSelect_Signature.hxx>
73 #include <IFSelect_IntParam.hxx>
74
75 #define Flag_Incorrect 2
76 //  (Bit Map n0 2)
77
78
79 static Standard_Boolean errhand;  // pb : un seul a la fois, mais ca va si vite
80 static TCollection_AsciiString bufstr;
81
82
83 //  #################################################################
84
85
86 //=======================================================================
87 //function : 
88 //purpose  : 
89 //=======================================================================
90
91 IFSelect_WorkSession::IFSelect_WorkSession ()
92 {
93   theshareout  = new IFSelect_ShareOut;
94   theerrhand   = errhand = Standard_True;
95   thenames     = new Dico_DictionaryOfTransient;
96   thecopier    = new IFSelect_ModelCopier;
97   thecopier->SetShareOut (theshareout);
98   thecheckdone = Standard_False;
99   thegtool     = new Interface_GTool;
100   themodelstat = Standard_False;
101 }
102
103
104 //=======================================================================
105 //function : 
106 //purpose  : 
107 //=======================================================================
108
109 void  IFSelect_WorkSession::SetErrorHandle (const Standard_Boolean hand)
110 {
111   theerrhand = errhand = hand;
112 }
113
114
115 //=======================================================================
116 //function : 
117 //purpose  : 
118 //=======================================================================
119
120 Standard_Boolean  IFSelect_WorkSession::ErrorHandle () const 
121 {
122   return theerrhand;
123 }
124
125
126 //=======================================================================
127 //function : 
128 //purpose  : 
129 //=======================================================================
130
131 const Handle(IFSelect_ShareOut)&  IFSelect_WorkSession::ShareOut () const 
132 {
133   return theshareout;
134 }
135
136
137 //=======================================================================
138 //function : 
139 //purpose  : 
140 //=======================================================================
141
142 void IFSelect_WorkSession::SetLibrary (const Handle(IFSelect_WorkLibrary)& lib)
143 {
144   thelibrary = lib;
145 }
146
147
148 //=======================================================================
149 //function : 
150 //purpose  : 
151 //=======================================================================
152
153 Handle(IFSelect_WorkLibrary)  IFSelect_WorkSession::WorkLibrary () const
154 {
155   return thelibrary;
156 }
157
158
159 //=======================================================================
160 //function : 
161 //purpose  : 
162 //=======================================================================
163
164 void IFSelect_WorkSession::SetProtocol
165   (const Handle(Interface_Protocol)& protocol)
166
167   theprotocol = protocol;
168   Interface_Protocol::SetActive(protocol);
169   thegtool->SetProtocol (protocol);
170 }
171
172
173 //=======================================================================
174 //function : 
175 //purpose  : 
176 //=======================================================================
177
178 Handle(Interface_Protocol)  IFSelect_WorkSession::Protocol () const
179 {
180   return theprotocol;
181 }
182
183
184 //=======================================================================
185 //function : 
186 //purpose  : 
187 //=======================================================================
188
189 void IFSelect_WorkSession::SetSignType
190   (const Handle(IFSelect_Signature)& signtype)
191 {
192   thegtool->SetSignType (signtype);
193   if (signtype.IsNull()) thenames->RemoveItem ("xst-sign-type");
194   else thenames->SetItem ("xst-sign-type",signtype);
195 }
196
197
198 //=======================================================================
199 //function : 
200 //purpose  : 
201 //=======================================================================
202
203 Handle(IFSelect_Signature)  IFSelect_WorkSession::SignType () const
204 {
205   return Handle(IFSelect_Signature)::DownCast (thegtool->SignType());
206 }
207
208
209 //=======================================================================
210 //function : 
211 //purpose  : 
212 //=======================================================================
213
214 void  IFSelect_WorkSession::SetShareOut
215     (const Handle(IFSelect_ShareOut)& shareout)
216 {
217   theshareout = shareout;
218   thecopier->SetShareOut (theshareout);
219 // ... faudrait ajouter les Params, Dispatches, etc...
220 }
221
222
223 //=======================================================================
224 //function : 
225 //purpose  : 
226 //=======================================================================
227
228 Standard_Boolean  IFSelect_WorkSession::HasModel () const 
229 {
230   return (!themodel.IsNull());
231 }
232
233
234 //=======================================================================
235 //function : 
236 //purpose  : 
237 //=======================================================================
238
239 void  IFSelect_WorkSession::SetModel
240     (const Handle(Interface_InterfaceModel)& model,
241      const Standard_Boolean clearpointed)
242 {
243   if (themodel != model) {
244     theloaded.Clear();
245     //skl if (!themodel.IsNull()) themodel->Clear();
246   }
247   themodel = model;
248   if (!thegtool.IsNull()) thegtool->ClearEntities(); //smh#14 FRA62479
249 //  themodel->SetProtocol(theprotocol);
250   themodel->SetGTool (thegtool);
251   
252   thegraph.Nullify();
253   ComputeGraph();    // fait qqchose si Protocol present. Sinon, ne fait rien
254   ClearData(3);      // RAZ CheckList, a refaire
255   thecheckrun.Clear();
256   
257 //  MISE A JOUR des SelectPointed  C-A-D  on efface leur contenu
258   if (clearpointed) ClearData(4);
259   ClearData(0);
260 }
261
262
263 //=======================================================================
264 //function : 
265 //purpose  : 
266 //=======================================================================
267 Handle(Interface_InterfaceModel)  IFSelect_WorkSession::Model () const 
268 {
269   return themodel;
270 }
271
272
273 //=======================================================================
274 //function : 
275 //purpose  : 
276 //=======================================================================
277
278 void IFSelect_WorkSession::SetLoadedFile (const Standard_CString filename)
279 {
280   theloaded.Clear();
281   theloaded.AssignCat (filename);
282 }
283
284
285 //=======================================================================
286 //function : 
287 //purpose  : 
288 //=======================================================================
289
290 Standard_CString  IFSelect_WorkSession::LoadedFile () const
291 {
292   return theloaded.ToCString();
293 }
294
295
296 //=======================================================================
297 //function : 
298 //purpose  : 
299 //=======================================================================
300
301 IFSelect_ReturnStatus  IFSelect_WorkSession::ReadFile
302                                         (const Standard_CString filename)
303 {
304   if (thelibrary.IsNull()) return IFSelect_RetVoid;
305   if (theprotocol.IsNull()) return IFSelect_RetVoid;
306   Handle(Interface_InterfaceModel) model;
307   IFSelect_ReturnStatus status = IFSelect_RetVoid;
308   try {
309     OCC_CATCH_SIGNALS
310     Standard_Integer stat = thelibrary->ReadFile (filename,model,theprotocol);
311     if (stat == 0) status = IFSelect_RetDone;
312     else if (stat < 0) status = IFSelect_RetError;
313     else status = IFSelect_RetFail;
314   }
315   catch(Standard_Failure) {
316     Handle(Message_Messenger) sout = Message::DefaultMessenger();
317     sout<<"    ****    Interruption ReadFile par Exception :   ****\n";
318     sout << Standard_Failure::Caught()->GetMessageString();
319     sout<<"\n    Abandon"<<endl;
320     status = IFSelect_RetFail;
321   }
322   if (status != IFSelect_RetDone) return status;
323   if (model.IsNull()) return IFSelect_RetVoid;
324   SetModel (model);
325   SetLoadedFile (filename);
326   return status;
327 }
328
329
330 //=======================================================================
331 //function : 
332 //purpose  : 
333 //=======================================================================
334
335 Standard_Integer IFSelect_WorkSession::NbStartingEntities () const
336 {
337   if (themodel.IsNull()) return 0;
338   return themodel->NbEntities();
339 }
340
341
342 //=======================================================================
343 //function : 
344 //purpose  : 
345 //=======================================================================
346
347 Handle(Standard_Transient) IFSelect_WorkSession::StartingEntity
348   (const Standard_Integer num) const
349 {
350   Handle(Standard_Transient) res;  // Null par defaut
351   if (themodel.IsNull()) return res;
352   if (num < 1 || num > themodel->NbEntities()) return res;
353   return themodel->Value(num);
354 }
355
356
357 //=======================================================================
358 //function : 
359 //purpose  : 
360 //=======================================================================
361
362 Standard_Integer IFSelect_WorkSession::StartingNumber
363   (const Handle(Standard_Transient)& ent) const
364 {
365   if (themodel.IsNull()) return 0;
366   return themodel->Number(ent);
367 }
368
369
370 //=======================================================================
371 //function : 
372 //purpose  : 
373 //=======================================================================
374
375 Standard_Integer IFSelect_WorkSession::NumberFromLabel
376   (const Standard_CString val, const Standard_Integer afternum) const
377 {
378   Standard_Integer i, cnt = 0, num = atoi(val);
379   if (num > 0 || themodel.IsNull()) return num;    // un n0 direct : gagne !
380 //  Sinon, on considere que c est un label; a traiter en CaseNonSensitive ...
381   if (num > themodel->NbEntities())  { num = 0; return num; }
382   Standard_Boolean exact = Standard_False;
383   Standard_Integer after = (afternum >= 0 ? afternum : -afternum);
384   for (i = themodel->NextNumberForLabel (val, after, exact)  ; i != 0;
385        i = themodel->NextNumberForLabel (val, i, exact)) {
386     cnt ++;
387     if (num <= 0) num = i;
388   }
389   if (cnt == 1) return num;
390   num = -num;
391
392   return num;
393 }
394
395
396 //=======================================================================
397 //function : 
398 //purpose  : 
399 //=======================================================================
400
401 Handle(TCollection_HAsciiString)  IFSelect_WorkSession::EntityLabel
402   (const Handle(Standard_Transient)& ent) const
403 {
404   Handle(TCollection_HAsciiString) name;
405   if (themodel.IsNull() || ent.IsNull()) return name;
406   if (!themodel->Contains(ent)) return name;
407   name = themodel->StringLabel(ent);
408   return name;
409 }
410
411
412 //=======================================================================
413 //function : 
414 //purpose  : 
415 //=======================================================================
416
417 Handle(TCollection_HAsciiString)  IFSelect_WorkSession::EntityName
418   (const Handle(Standard_Transient)& ent) const
419 {
420   Handle(TCollection_HAsciiString) name;
421   if (themodel.IsNull() || ent.IsNull()) return name;
422   Interface_ShareTool sht(thegraph->Graph());
423
424   Standard_Integer CN;
425   Handle(Interface_GeneralModule) module;
426   if (!thegtool->Select (ent,module,CN)) return 0;
427   return module->Name (CN,ent,sht);
428 }
429
430
431 //=======================================================================
432 //function : 
433 //purpose  : 
434 //=======================================================================
435
436 Standard_Integer IFSelect_WorkSession::CategoryNumber
437   (const Handle(Standard_Transient)& ent) const
438 {
439   if (themodel.IsNull()) return -1;
440   Standard_Integer num = StartingNumber(ent);
441   return themodel->CategoryNumber(num);
442 }
443
444
445 //=======================================================================
446 //function : 
447 //purpose  : 
448 //=======================================================================
449
450 Standard_CString IFSelect_WorkSession::CategoryName
451   (const Handle(Standard_Transient)& ent) const
452 {
453   Standard_Integer cn = CategoryNumber (ent);
454   return Interface_Category::Name (cn);
455 }
456
457
458 //=======================================================================
459 //function : 
460 //purpose  : 
461 //=======================================================================
462
463 Standard_CString IFSelect_WorkSession::ValidityName
464   (const Handle(Standard_Transient)& ent) const
465 {
466   if (StartingNumber(ent) == 0) return "";
467   return IFSelect_SignValidity::CVal (ent,themodel);
468 }
469
470
471 //=======================================================================
472 //function : 
473 //purpose  : 
474 //=======================================================================
475
476 void IFSelect_WorkSession::ClearData (const Standard_Integer mode)
477 {
478   switch (mode) {
479     case 1 : {
480       theloaded.Clear();
481       if (!themodel.IsNull()) themodel->Clear();
482       themodel.Nullify();
483       ClearData(2);  ClearData(4);
484       thecheckrun.Clear();
485       break;
486     }
487     case 2 : {  thegraph.Nullify();  thecheckdone = Standard_False;  thecheckana.Clear();  break;  }
488     case 3 : {  thecheckdone = Standard_False;  break;  }
489     case 4 : {
490 //  MISE A JOUR des SelectPointed  C-A-D  on efface leur contenu
491 //  AINSI que des editeurs (en fait, les EditForm)
492 //  Des compteurs  C-A-D  on efface leur contenu (a reevaluer)
493       Handle(TColStd_HSequenceOfInteger) list =
494         ItemIdents(STANDARD_TYPE(IFSelect_SelectPointed));
495       Standard_Integer nb = list->Length();
496       Standard_Integer i; // svv #1 
497       for (i = 1; i <= nb; i ++) {
498         DeclareAndCast(IFSelect_SelectPointed,sp,Item(list->Value(i)));
499         if (!sp.IsNull()) sp->Clear();
500       }
501       list = ItemIdents(STANDARD_TYPE(IFSelect_SignatureList));
502       nb = list->Length();
503       for (i = 1; i <= nb; i ++) {
504         DeclareAndCast(IFSelect_SignatureList,sl,Item(list->Value(i)));
505         if (!sl.IsNull()) sl->Clear();
506         DeclareAndCast(IFSelect_SignCounter,sc,sl);
507         if (!sc.IsNull()) sc->SetSelMode(-1);
508       }
509       list = ItemIdents(STANDARD_TYPE(IFSelect_EditForm));
510       nb = list->Length();
511       Handle(Standard_Transient) nulent;
512       for (i = 1; i <= nb; i ++) {
513         DeclareAndCast(IFSelect_EditForm,edf,Item(list->Value(i)));
514         edf->ClearData ();
515       }
516       theitems.Clear();
517       break;
518     }
519     default : break;
520   }
521 }
522
523
524 //=======================================================================
525 //function : 
526 //purpose  : 
527 //=======================================================================
528
529 Standard_Boolean  IFSelect_WorkSession::ComputeGraph
530   (const Standard_Boolean enforce)
531 {
532   if (theprotocol.IsNull()) return Standard_False;
533   if (themodel.IsNull()) return Standard_False;
534   //if (themodel->NbEntities() == 0) return Standard_False;
535   if (enforce) thegraph.Nullify();
536   if (!thegraph.IsNull()) {
537     if (themodel->NbEntities() == thegraph->Graph().Size()) return Standard_True;
538     thegraph.Nullify();
539   }
540   if (themodel->NbEntities() == 0) return Standard_False;
541   //  Il faut calculer le graphe pour de bon
542   thegraph = new Interface_HGraph (themodel,themodelstat);
543   Standard_Integer nb = themodel->NbEntities();
544   if(themodelstat)
545   {
546     Standard_Integer i; // svv #1
547     for (i = 1; i <= nb; i ++) thegraph->CGraph().SetStatus(i,0);
548     Interface_BitMap& bm = thegraph->CGraph().CBitMap();
549     bm.AddFlag();
550     bm.SetFlagName (Flag_Incorrect,"Incorrect");
551   }
552   ComputeCheck();
553   thecheckdone = Standard_True;
554   if(themodelstat)
555   {
556     //  Calcul des categories, a present memorisees dans le modele
557     Interface_Category categ(thegtool);
558     Interface_ShareTool sht(thegraph);
559     Standard_Integer i =1;
560     for ( ; i <= nb; i ++) themodel->SetCategoryNumber
561       (i,categ.CatNum(themodel->Value(i),sht));
562   }
563
564   return Standard_True;
565 }
566
567
568 //=======================================================================
569 //function : 
570 //purpose  : 
571 //=======================================================================
572
573 Handle(Interface_HGraph) IFSelect_WorkSession::HGraph ()
574 {
575   ComputeGraph();
576   return thegraph;
577 }
578
579
580 //=======================================================================
581 //function : 
582 //purpose  : 
583 //=======================================================================
584
585 const Interface_Graph& IFSelect_WorkSession::Graph ()
586 {
587   ComputeGraph();
588   if (thegraph.IsNull()) Standard_DomainError::Raise
589     ("IFSelect WorkSession : Graph not available");
590   return thegraph->Graph();
591 }
592
593
594 //=======================================================================
595 //function : 
596 //purpose  : 
597 //=======================================================================
598
599 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::Shareds
600   (const Handle(Standard_Transient)& ent)
601 {
602   Handle(TColStd_HSequenceOfTransient) list;
603   if (!ComputeGraph()) return list;
604   if (StartingNumber(ent) == 0) return list;
605   return thegraph->Graph().Shareds(ent).Content();
606 }
607
608
609 //=======================================================================
610 //function : 
611 //purpose  : 
612 //=======================================================================
613
614 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::Sharings
615   (const Handle(Standard_Transient)& ent)
616 {
617   Handle(TColStd_HSequenceOfTransient) list;
618   if (!ComputeGraph()) return list;
619   if (StartingNumber(ent) == 0) return list;
620   return thegraph->Graph().Sharings(ent).Content();
621 }
622
623
624 //=======================================================================
625 //function : 
626 //purpose  : 
627 //=======================================================================
628
629 Standard_Boolean IFSelect_WorkSession::IsLoaded () const
630 {
631   if (theprotocol.IsNull()) return Standard_False;
632   if (themodel.IsNull()) return Standard_False;
633   if (themodel->NbEntities() == 0) return Standard_False;
634   if (thegraph.IsNull()) return Standard_False;
635   if (themodel->NbEntities() == thegraph->Graph().Size()) return Standard_True;
636   return Standard_False;
637 }
638
639
640 //=======================================================================
641 //function : 
642 //purpose  : 
643 //=======================================================================
644
645 Standard_Boolean IFSelect_WorkSession::ComputeCheck
646   (const Standard_Boolean enforce)
647 {
648   if (enforce) thecheckdone = Standard_False;
649   if (thecheckdone) return Standard_True;
650   if (!IsLoaded()) return Standard_False;
651
652   Interface_Graph& CG = thegraph->CGraph();
653   Interface_CheckTool cht(thegraph);
654   Interface_CheckIterator checklist = cht.VerifyCheckList();
655   themodel->FillSemanticChecks(checklist,Standard_False);
656   if(themodelstat)
657   {
658     //  Et on met a jour le Graphe (BitMap) !  Flag Incorrect (STX + SEM)
659     Interface_BitMap& BM = CG.CBitMap();
660     BM.Init (Standard_False,Flag_Incorrect);
661     Standard_Integer num, nb = CG.Size();
662     for (checklist.Start(); checklist.More(); checklist.Next()) {
663       const Handle(Interface_Check) chk = checklist.Value();
664       if (!chk->HasFailed()) continue;
665       num = checklist.Number();
666       if (num > 0 && num <= nb) BM.SetTrue (num,Flag_Incorrect);
667     }
668     for (num = 1; num <= nb; num ++)
669       if (themodel->IsErrorEntity (num)) BM.SetTrue (num,Flag_Incorrect);
670   }
671   return Standard_True;
672 }
673
674
675 //=======================================================================
676 //function : 
677 //purpose  : 
678 //=======================================================================
679
680 Interface_CheckIterator IFSelect_WorkSession::ModelCheckList
681   (const Standard_Boolean complete)
682 {
683   Interface_CheckIterator checks;
684   if (!IsLoaded()) {
685     checks.CCheck(0)->AddFail("DATA NOT AVAILABLE FOR CHECK");
686     return checks;
687   }
688   Interface_CheckTool cht(Graph());
689   checks = (complete ? cht.CompleteCheckList() : cht.AnalyseCheckList());
690   checks.SetName
691     ((char*)(complete ? "Model Complete Check List" : "Model Syntactic Check List"));
692   return checks;
693 }
694
695
696 //=======================================================================
697 //function : 
698 //purpose  : 
699 //=======================================================================
700
701 Interface_CheckIterator IFSelect_WorkSession::CheckOne
702   (const Handle(Standard_Transient)& ent,
703    const Standard_Boolean complete)
704 {
705   Interface_CheckIterator checks;
706   checks.SetModel(themodel);
707   if (!IsLoaded()) {
708     checks.CCheck(0)->AddFail("DATA NOT AVAILABLE FOR CHECK");
709     return checks;
710   }
711   Standard_Integer num = -1;
712   if (ent.IsNull() || ent == themodel) num = 0;
713   else num = themodel->Number(ent);
714
715   Handle(Interface_Check) ach = themodel->Check (num,Standard_True);
716   if (complete) ach->GetMessages (themodel->Check (num,Standard_False));
717   if (num > 0) ach->SetEntity(ent);
718   checks.Add (ach,num);
719   checks.SetName ("Data Check (One Entity)");
720   return checks;
721 }
722
723
724 //=======================================================================
725 //function : 
726 //purpose  : 
727 //=======================================================================
728
729 Interface_CheckIterator IFSelect_WorkSession::LastRunCheckList () const
730 {
731   return thecheckrun;
732 }
733
734
735 //  #####################################################################
736 //  ....                        LES VARIABLES                        ....
737
738 //=======================================================================
739 //function : 
740 //purpose  : 
741 //=======================================================================
742
743 Standard_Integer IFSelect_WorkSession::MaxIdent () const
744 {
745   return theitems.Extent();
746 }
747
748
749 //=======================================================================
750 //function : 
751 //purpose  : 
752 //=======================================================================
753
754 Handle(Standard_Transient) IFSelect_WorkSession::Item
755   (const Standard_Integer id) const
756 {
757   Handle(Standard_Transient) res;
758   if (id <= 0 || id > MaxIdent()) return res;
759   if (theitems.FindFromIndex(id).IsNull()) return res;
760   return theitems.FindKey(id);
761 }
762
763
764 //=======================================================================
765 //function : 
766 //purpose  : 
767 //=======================================================================
768
769 Standard_Integer IFSelect_WorkSession::ItemIdent
770   (const Handle(Standard_Transient)& item) const
771 {
772   if (item.IsNull()) return 0;
773   Standard_Integer id = theitems.FindIndex(item);
774   if (id == 0) return 0;
775   if (theitems.FindFromIndex(id).IsNull()) return 0;
776   return id;
777 }
778
779
780 //=======================================================================
781 //function : 
782 //purpose  : 
783 //=======================================================================
784
785 Handle(Standard_Transient) IFSelect_WorkSession::NamedItem
786   (const Standard_CString name) const
787 {
788   Handle(Standard_Transient) res;
789   if (name[0] == '\0') return res;
790   if (name[0] == '#') {    // #nnn : pas un nom mais un n0 id.
791     Standard_Integer id = atoi( &name[1] );
792     return Item(id);
793   }
794   if (!thenames->GetItem(name,res)) res.Nullify();
795   return res;
796 }
797
798
799 //=======================================================================
800 //function : 
801 //purpose  : 
802 //=======================================================================
803
804 Handle(Standard_Transient) IFSelect_WorkSession::NamedItem
805   (const Handle(TCollection_HAsciiString)& name) const
806 {
807   Handle(Standard_Transient) res;
808   if (!name.IsNull()) res = NamedItem (name->ToCString());
809   return res;
810 }
811
812
813 //=======================================================================
814 //function : 
815 //purpose  : 
816 //=======================================================================
817
818 Standard_Integer IFSelect_WorkSession::NameIdent
819   (const Standard_CString name) const
820 {
821   Handle(Standard_Transient) res;
822   if (name[0] == '\0') return 0;
823   if (name[0] == '#') {    // #nnn : pas un nom mais un n0 id.
824     Standard_Integer id = atoi( &name[1] );
825     return id;
826   }
827   if (!thenames->GetItem(name,res)) return 0;
828   return ItemIdent(res);
829 }
830
831
832 //=======================================================================
833 //function : 
834 //purpose  : 
835 //=======================================================================
836
837 Standard_Boolean IFSelect_WorkSession::HasName
838   (const Handle(Standard_Transient)& item) const
839 {
840   if (item.IsNull()) return Standard_False;
841   Standard_Integer id = theitems.FindIndex(item);
842   if (id == 0) return Standard_False;
843   Handle(Standard_Transient) att = theitems.FindFromIndex(id);
844   if (att.IsNull()) return Standard_False;
845   return att->IsKind(STANDARD_TYPE(TCollection_HAsciiString));
846 }
847
848
849 //=======================================================================
850 //function : 
851 //purpose  : 
852 //=======================================================================
853
854 Handle(TCollection_HAsciiString) IFSelect_WorkSession::Name
855   (const Handle(Standard_Transient)& item) const
856 {
857   Handle(TCollection_HAsciiString) res;
858   if (item.IsNull()) return res;
859   Standard_Integer id = theitems.FindIndex(item);
860   if (id == 0) return res;  // Null
861   Handle(Standard_Transient) att = theitems.FindFromIndex(id);
862   return GetCasted(TCollection_HAsciiString,att);
863 }
864
865
866 //=======================================================================
867 //function : 
868 //purpose  : 
869 //=======================================================================
870
871 Standard_Integer IFSelect_WorkSession::AddItem
872   (const Handle(Standard_Transient)& item,
873    const Standard_Boolean active)
874 {
875   if (item.IsNull()) return 0;
876   Standard_Integer id = theitems.FindIndex(item);
877   if (id > 0) {
878     Handle(Standard_Transient)& att = theitems.ChangeFromIndex(id);
879     if (att.IsNull()) att = item;
880   }
881   else id = theitems.Add(item,item);
882
883 //  Cas particuliers : Dispatch,Modifier
884   if (active) SetActive(item,Standard_True);
885   return id;
886 }
887
888
889 //=======================================================================
890 //function : 
891 //purpose  : 
892 //=======================================================================
893
894 Standard_Integer IFSelect_WorkSession::AddNamedItem
895   (const Standard_CString name, const Handle(Standard_Transient)& item,
896    const Standard_Boolean active)
897 {
898   if (item.IsNull()) return 0;
899   if (name[0] == '#' || name[0] == '!') return 0;
900 // #nnn : pas un nom mais un numero. !... : reserve (interdit pour un nom)
901 //   nom deja pris : on ecrase l ancienne valeur
902   if (name[0] != '\0') {
903     Standard_Boolean deja;
904     Handle(Standard_Transient)& newitem = thenames->NewItem(name,deja);
905 //    if (deja & item != newitem) return 0;
906     newitem = item;
907   }
908   Standard_Integer  id = theitems.FindIndex(item);
909   if (id > 0) {
910     Handle(Standard_Transient)& att = theitems.ChangeFromIndex(id);
911     if (att.IsNull()) att = item;
912     if (name[0] != '\0') {
913 //      if (!att->IsKind(STANDARD_TYPE(TCollection_HAsciiString))) ecrasement admis !
914         att = new TCollection_HAsciiString(name);
915     }
916   }
917   else if (name[0] != '\0')
918     id = theitems.Add(item,new TCollection_HAsciiString(name));
919   else id = theitems.Add(item,item);
920
921 //  Cas particuliers : Dispatch,Modifier
922   if (active) SetActive(item,Standard_True);
923   return id;
924 }
925
926
927 //=======================================================================
928 //function : 
929 //purpose  : 
930 //=======================================================================
931
932 Standard_Boolean IFSelect_WorkSession::SetActive
933   (const Handle(Standard_Transient)& item, const Standard_Boolean mode)
934 {
935   if (item->IsKind(STANDARD_TYPE(IFSelect_Dispatch))) {
936     DeclareAndCast(IFSelect_Dispatch,disp,item);
937     Standard_Integer num = theshareout->DispatchRank(disp);
938     if ( num > theshareout->NbDispatches()) return Standard_False;
939     if ( mode) {
940       if (num >  0) return Standard_False;
941       theshareout->AddDispatch (disp);
942       return Standard_True;
943     } else {
944       if (num <= theshareout->LastRun()) return Standard_False;
945       theshareout->RemoveDispatch(num);
946       SetFileRoot(disp,"");    // si onlynamed : nettoie aussi ShareOut
947       return Standard_True;
948     }
949   }
950
951   return Standard_False;
952 }
953
954
955 //=======================================================================
956 //function : 
957 //purpose  : 
958 //=======================================================================
959
960 Standard_Boolean IFSelect_WorkSession::RemoveNamedItem
961   (const Standard_CString name)
962 {
963   Handle(Standard_Transient) item = NamedItem(name);
964   if (item.IsNull()) return Standard_False;
965   if (!RemoveItem(item)) return Standard_False;    // qui se charge de tout
966   return Standard_True;
967 }
968
969
970 //=======================================================================
971 //function : 
972 //purpose  : 
973 //=======================================================================
974
975 Standard_Boolean IFSelect_WorkSession::RemoveName
976   (const Standard_CString name)
977 {
978   Handle(Standard_Transient) item = NamedItem(name);
979   if (item.IsNull()) return Standard_False;
980   theitems.Add(item,item);    // reste mais sans nom
981   return thenames->RemoveItem(name);
982 }
983
984
985 //=======================================================================
986 //function : 
987 //purpose  : 
988 //=======================================================================
989
990 Standard_Boolean IFSelect_WorkSession::RemoveItem
991   (const Handle(Standard_Transient)& item)
992 {
993   if (item.IsNull()) return Standard_False;
994   Standard_Integer id = theitems.FindIndex(item);
995   if (id == 0) return Standard_False;
996   Handle(Standard_Transient)& att = theitems.ChangeFromIndex(id);
997   if (att.IsNull()) return Standard_False;    // deja annulle
998
999 //  Cas particuliers : Dispatch,Modifier
1000   theshareout->RemoveItem(item);
1001
1002 //  Marquer "Removed" dans la Map (on ne peut pas la vider)
1003   if (att->IsKind(STANDARD_TYPE(TCollection_HAsciiString))) {
1004     if (!thenames->RemoveItem
1005         (GetCasted(TCollection_HAsciiString,att)->ToCString()))
1006       return Standard_False;
1007   }
1008   att.Nullify();  // cf ChangeFromIndex
1009 //  id = theitems.Add(item,att);
1010   return Standard_True;
1011 }
1012
1013
1014 //=======================================================================
1015 //function : 
1016 //purpose  : 
1017 //=======================================================================
1018
1019 void IFSelect_WorkSession::ClearItems ()
1020 {
1021   thenames->Clear();
1022   theitems.Clear();
1023   theshareout->Clear(Standard_False);
1024 }
1025
1026
1027 //=======================================================================
1028 //function : 
1029 //purpose  : 
1030 //=======================================================================
1031
1032 Handle(TCollection_HAsciiString) IFSelect_WorkSession::ItemLabel
1033   (const Standard_Integer id) const
1034 {
1035   Handle(TCollection_HAsciiString) res;
1036   Handle(Standard_Transient) var = Item(id);
1037   if (var.IsNull()) return res;
1038   DeclareAndCast(TCollection_HAsciiString,text,var);
1039   if (!text.IsNull()) {
1040     res = new TCollection_HAsciiString("Text:");
1041     res->AssignCat(text);
1042     return res;
1043   }
1044   DeclareAndCast(IFSelect_IntParam,intpar,var);
1045   if (!intpar.IsNull()) {
1046     res = new TCollection_HAsciiString(intpar->Value());
1047     res->Insert(1,"Integer:");
1048     return res;
1049   }
1050   DeclareAndCast(IFSelect_Selection,sel,var);
1051   if (!sel.IsNull()) {
1052     res = new TCollection_HAsciiString("Selection:");
1053     res->AssignCat(sel->Label().ToCString());
1054     return res;
1055   }
1056   DeclareAndCast(IFSelect_GeneralModifier,mod,var);
1057   if (!mod.IsNull()) {
1058     if (mod->IsKind(STANDARD_TYPE(IFSelect_Modifier)))
1059       res    = new TCollection_HAsciiString("ModelModifier:");
1060     else res = new TCollection_HAsciiString("FileModifier:");
1061     res->AssignCat(mod->Label().ToCString());
1062     return res;
1063   }
1064   DeclareAndCast(IFSelect_Dispatch,disp,var);
1065   if (!disp.IsNull()) {
1066     res = new TCollection_HAsciiString("Dispatch:");
1067     res->AssignCat(disp->Label().ToCString());
1068     return res;
1069   }
1070   DeclareAndCast(IFSelect_Transformer,tsf,var);
1071   if (!tsf.IsNull()) {
1072     res = new TCollection_HAsciiString("Transformer:");
1073     res->AssignCat(tsf->Label().ToCString());
1074     return res;
1075   }
1076   DeclareAndCast(IFSelect_SignatureList,slc,var);
1077   if (!slc.IsNull()) {
1078     res = new TCollection_HAsciiString("Counter:");
1079     res->AssignCat(slc->Name());
1080     return res;
1081   }
1082   DeclareAndCast(IFSelect_Signature,sig,var);
1083   if (!sig.IsNull()) {
1084     res = new TCollection_HAsciiString("Signature:");
1085     res->AssignCat(sig->Name());
1086     return res;
1087   }
1088   DeclareAndCast(IFSelect_EditForm,edf,var);
1089   if (!edf.IsNull()) {
1090     res = new TCollection_HAsciiString("EditForm:");
1091     res->AssignCat(edf->Label());
1092     return res;
1093   }
1094   DeclareAndCast(IFSelect_Editor,edt,var);
1095   if (!edt.IsNull()) {
1096     res = new TCollection_HAsciiString("Editor:");
1097     res->AssignCat(edt->Label().ToCString());
1098     return res;
1099   }
1100   res = new TCollection_HAsciiString("VariableType:");
1101   res->AssignCat(var->DynamicType()->Name());
1102   return res;
1103 }
1104
1105
1106 //=======================================================================
1107 //function : 
1108 //purpose  : 
1109 //=======================================================================
1110
1111 Handle(TColStd_HSequenceOfInteger) IFSelect_WorkSession::ItemIdents
1112   (const Handle(Standard_Type)& type) const
1113 {
1114   Handle(TColStd_HSequenceOfInteger) list =
1115     new TColStd_HSequenceOfInteger();
1116   Standard_Integer nb = theitems.Extent();
1117   for (Standard_Integer i = 1; i <= nb; i ++) {
1118     if (theitems.FindKey(i)->IsKind(type)) list->Append(i);
1119   }
1120   return list;
1121 }
1122
1123
1124 //=======================================================================
1125 //function : 
1126 //purpose  : 
1127 //=======================================================================
1128
1129 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_WorkSession::ItemNames
1130   (const Handle(Standard_Type)& type) const
1131 {
1132   Handle(TColStd_HSequenceOfHAsciiString) list =
1133     new TColStd_HSequenceOfHAsciiString();
1134   for (Dico_IteratorOfDictionaryOfTransient IT(thenames); IT.More(); IT.Next()){
1135     if (IT.Value()->IsKind(type)) list->Append
1136       (new TCollection_HAsciiString(IT.Name().ToCString()));
1137   }
1138   return list;
1139 }
1140
1141
1142 // ..  Recherche par label : recherche en liste(noms) ou iterative
1143
1144 //=======================================================================
1145 //function : 
1146 //purpose  : 
1147 //=======================================================================
1148
1149 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_WorkSession::ItemNamesForLabel
1150   (const Standard_CString label) const
1151 {
1152   Handle(TColStd_HSequenceOfHAsciiString) list =
1153     new TColStd_HSequenceOfHAsciiString();
1154   Standard_Integer i,  nb = MaxIdent();
1155   for (i = 1; i <= nb; i ++) {
1156     Handle(TCollection_HAsciiString) lab = ItemLabel(i);
1157     Handle(Standard_Transient) item = Item(i);
1158     if (lab.IsNull()) continue;
1159     if (label[0] != '\0' && lab->Search(label) <= 0) continue;
1160
1161     Handle(TCollection_HAsciiString) nom = Name(Item(i));
1162     if (nom.IsNull()) { nom = new TCollection_HAsciiString(i); nom->Insert(1,'#'); }
1163     else nom = new TCollection_HAsciiString (nom);
1164     list->Append (new TCollection_HAsciiString(lab));
1165   }
1166   return list;
1167 }
1168
1169
1170 //=======================================================================
1171 //function : 
1172 //purpose  : 
1173 //=======================================================================
1174
1175 Standard_Integer IFSelect_WorkSession::NextIdentForLabel
1176   (const Standard_CString label, const Standard_Integer id,
1177    const Standard_Integer mode) const
1178 {
1179   Standard_Integer nb = MaxIdent();
1180   for (Standard_Integer i = id+1; i <= nb; i ++) {
1181     Handle(TCollection_HAsciiString) lab = ItemLabel(i);
1182     if (lab.IsNull()) continue;
1183     switch (mode) {
1184       case 0 : if (!strcmp(lab->ToCString(),label)) return i;  break; // switch
1185       case 1 : if (lab->Search(label) == 1 ) return i;  break;
1186       case 2 : if (lab->Search(label)  > 0 ) return i;  break;
1187       default : break;  // break du switch
1188     }
1189   }
1190   return 0;  // ici : pas trouve
1191 }
1192
1193
1194 //  #################################################################
1195 //  ....                Parametres (Int et Text)                ....
1196
1197 //=======================================================================
1198 //function : 
1199 //purpose  : 
1200 //=======================================================================
1201
1202 Handle(Standard_Transient) IFSelect_WorkSession::NewParamFromStatic
1203   (const Standard_CString statname, const Standard_CString name)
1204 {
1205   Handle(Standard_Transient) param;
1206   Handle(Interface_Static) stat = Interface_Static::Static(statname);
1207   if (stat.IsNull()) return param;
1208   if (stat->Type() == Interface_ParamInteger) {
1209     Handle(IFSelect_IntParam) intpar = new IFSelect_IntParam;
1210     intpar->SetStaticName (statname);
1211     param = intpar;
1212   } else {
1213     param = stat->HStringValue();
1214   }
1215   if (param.IsNull()) return param;
1216   if ( AddNamedItem (name, param) == 0 ) param.Nullify();
1217   return param;
1218 }
1219
1220
1221 //=======================================================================
1222 //function : 
1223 //purpose  : 
1224 //=======================================================================
1225
1226 Handle(IFSelect_IntParam) IFSelect_WorkSession::IntParam
1227   (const Standard_Integer id) const
1228 {  return Handle(IFSelect_IntParam)::DownCast(Item(id));  }
1229
1230
1231 //=======================================================================
1232 //function : 
1233 //purpose  : 
1234 //=======================================================================
1235
1236 Standard_Integer IFSelect_WorkSession::IntValue
1237   (const Handle(IFSelect_IntParam)& par) const
1238 {
1239   if (!par.IsNull()) return par->Value();
1240   else return 0;
1241 }
1242
1243
1244 //=======================================================================
1245 //function : 
1246 //purpose  : 
1247 //=======================================================================
1248
1249 Handle(IFSelect_IntParam) IFSelect_WorkSession::NewIntParam
1250   (const Standard_CString name)
1251 {
1252   Handle(IFSelect_IntParam) intpar = new IFSelect_IntParam;
1253   if ( AddNamedItem (name, intpar) == 0 ) intpar.Nullify();
1254   return intpar;
1255 }
1256
1257
1258 //=======================================================================
1259 //function : 
1260 //purpose  : 
1261 //=======================================================================
1262
1263 Standard_Boolean IFSelect_WorkSession::SetIntValue
1264   (const Handle(IFSelect_IntParam)& par, const Standard_Integer val)
1265 {
1266   if (ItemIdent(par) == 0) return Standard_False;
1267   par->SetValue(val);
1268   return Standard_True;
1269 }
1270
1271
1272 //=======================================================================
1273 //function : 
1274 //purpose  : 
1275 //=======================================================================
1276
1277 Handle(TCollection_HAsciiString) IFSelect_WorkSession::TextParam
1278   (const Standard_Integer id) const
1279 {  return Handle(TCollection_HAsciiString)::DownCast(Item(id));  }
1280
1281
1282 //=======================================================================
1283 //function : 
1284 //purpose  : 
1285 //=======================================================================
1286
1287 TCollection_AsciiString IFSelect_WorkSession::TextValue
1288   (const Handle(TCollection_HAsciiString)& par) const 
1289 {
1290   if (!par.IsNull()) return TCollection_AsciiString(par->ToCString());
1291   else return TCollection_AsciiString();
1292 }
1293
1294
1295 Handle(TCollection_HAsciiString) IFSelect_WorkSession::NewTextParam
1296   (const Standard_CString name)
1297 {
1298   Handle(TCollection_HAsciiString) textpar = new TCollection_HAsciiString("");
1299   if ( AddNamedItem (name, textpar) == 0 ) textpar.Nullify();
1300   return textpar;
1301 }
1302
1303
1304 //=======================================================================
1305 //function : 
1306 //purpose  : 
1307 //=======================================================================
1308
1309 Standard_Boolean  IFSelect_WorkSession::SetTextValue
1310   (const Handle(TCollection_HAsciiString)& par, const Standard_CString val)
1311 {
1312   if (ItemIdent(par) == 0) return Standard_False;
1313   par->Clear();  par->AssignCat(val);
1314   return Standard_True;
1315 }
1316
1317 //  ########################################################################
1318 //  ....                           SIGNATURES                           ....
1319
1320 //=======================================================================
1321 //function : 
1322 //purpose  : 
1323 //=======================================================================
1324
1325 Handle(IFSelect_Signature) IFSelect_WorkSession::Signature
1326   (const Standard_Integer id) const 
1327 {  return GetCasted(IFSelect_Signature,Item(id));  }
1328
1329     Standard_CString  IFSelect_WorkSession::SignValue
1330   (const Handle(IFSelect_Signature)& sign, const Handle(Standard_Transient)& ent) const
1331 {
1332   if (sign.IsNull() || themodel.IsNull()) return "";
1333   if (StartingNumber(ent) == 0) return "";
1334   return sign->Value (ent,themodel);
1335 }
1336
1337 //  ########################################################################
1338 //  ....                        SELECTIONS & Cie                        ....
1339
1340 //=======================================================================
1341 //function : 
1342 //purpose  : 
1343 //=======================================================================
1344
1345 Handle(IFSelect_Selection) IFSelect_WorkSession::Selection
1346   (const Standard_Integer id) const 
1347 {  return GetCasted(IFSelect_Selection,Item(id));  }
1348
1349
1350 //=======================================================================
1351 //function : 
1352 //purpose  : 
1353 //=======================================================================
1354
1355 Interface_EntityIterator IFSelect_WorkSession::EvalSelection
1356   (const Handle(IFSelect_Selection)& sel) const 
1357 {
1358   Interface_EntityIterator iter;
1359   if (errhand) {
1360     errhand = Standard_False;
1361     try {
1362       OCC_CATCH_SIGNALS
1363       iter = EvalSelection(sel);    // appel normal (donc, code pas duplique)
1364     }
1365     catch (Standard_Failure) {
1366       Handle(Message_Messenger) sout = Message::DefaultMessenger();
1367       sout<<"    ****    Interruption EvalSelection par Exception :   ****\n";
1368       sout<<Standard_Failure::Caught()->GetMessageString();
1369       sout<<"\n    Abandon"<<endl;
1370     }
1371     errhand = theerrhand;
1372     return iter;
1373   }
1374
1375   if (thegraph.IsNull()) return iter;
1376  iter = sel->UniqueResult(thegraph->Graph());
1377   return iter;
1378 }
1379
1380
1381 //=======================================================================
1382 //function : 
1383 //purpose  : 
1384 //=======================================================================
1385
1386 IFSelect_SelectionIterator IFSelect_WorkSession::Sources
1387   (const Handle(IFSelect_Selection)& sel) const 
1388 {
1389   return IFSelect_SelectionIterator (sel);
1390 }
1391
1392
1393 //=======================================================================
1394 //function : 
1395 //purpose  : 
1396 //=======================================================================
1397
1398 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::SelectionResult
1399   (const Handle(IFSelect_Selection)& sel) const 
1400 {
1401   Handle(TColStd_HSequenceOfTransient)  res;
1402   if (errhand) {
1403     errhand = Standard_False;
1404     try {
1405       OCC_CATCH_SIGNALS
1406       res = SelectionResult(sel);    // appel normal (->code unique)
1407     }
1408     catch (Standard_Failure) {
1409       Handle(Message_Messenger) sout = Message::DefaultMessenger();
1410       sout<<"    ****    Interruption SelectionResult par Exception :   ****\n";
1411       sout<<Standard_Failure::Caught()->GetMessageString();
1412       sout<<"\n    Abandon"<<endl;
1413     }
1414     errhand = theerrhand;
1415     return res;
1416   }
1417
1418   if (!IsLoaded()) {
1419     cout<< " ***  Data for Evaluation not available  ***"<<endl;
1420     return new TColStd_HSequenceOfTransient();
1421   }
1422 //  if (ItemIdent(sel) == 0)
1423   if (sel.IsNull())
1424     {  cout << " Selection : "<<" Unknown"<<endl;  return res;  } //cout<<Handle
1425   return EvalSelection (sel).Content();
1426 }
1427
1428
1429 //=======================================================================
1430 //function : 
1431 //purpose  : 
1432 //=======================================================================
1433
1434 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::SelectionResultFromList
1435   (const Handle(IFSelect_Selection)& sel,
1436    const Handle(TColStd_HSequenceOfTransient)& list) const
1437 {
1438   if (list.IsNull()) return SelectionResult (sel);
1439   DeclareAndCast(IFSelect_SelectDeduct,deduct,sel);
1440   if (deduct.IsNull()) return SelectionResult (sel);
1441
1442 //   On va chercher la derniere deduction de la chaine des inputs
1443   Handle(IFSelect_Selection) ssel, newinput;
1444   ssel = sel;
1445   Standard_Integer i, nb = MaxIdent();
1446   for (i = 1; i <= nb * 2; i ++) {
1447     newinput  = deduct->Input();
1448     deduct = GetCasted(IFSelect_SelectDeduct,newinput);
1449     if (deduct.IsNull()) break;
1450     ssel   = newinput;
1451   }
1452   
1453 //  on y est (enfin, on devrait)
1454 //  ssel est la derniere selection auscultee,  deduct son downcast
1455 //  input son Input (nulle  si sel  pas une deduction)
1456   deduct = GetCasted(IFSelect_SelectDeduct,ssel);
1457
1458   deduct->Alternate()->SetList (list);
1459
1460 //   On execute puis on nettoie
1461   Handle(TColStd_HSequenceOfTransient) res = SelectionResult (sel);
1462 ////  deduct->SetInput (newinput);
1463   return res;
1464 }
1465
1466
1467 //=======================================================================
1468 //function : 
1469 //purpose  : 
1470 //=======================================================================
1471
1472 Standard_Boolean IFSelect_WorkSession::SetItemSelection
1473   (const Handle(Standard_Transient)& item,
1474    const Handle(IFSelect_Selection)& sel)
1475 {
1476   DeclareAndCast(IFSelect_Dispatch,disp,item);
1477   DeclareAndCast(IFSelect_GeneralModifier,modif,item);
1478   if (!disp.IsNull()) {
1479     if (ItemIdent(disp) == 0) return Standard_False;
1480 //  Selection Nulle : Annuler FinalSelection
1481     if (!sel.IsNull() && ItemIdent(sel) == 0) return Standard_False;
1482     disp->SetFinalSelection(sel);
1483     return Standard_True;
1484   }
1485   if (!modif.IsNull()) {
1486     if (ItemIdent(modif) == 0) return Standard_False;
1487     if (!sel.IsNull() && ItemIdent(sel) == 0) return Standard_False;
1488 //   Selection Nulle : Annuler Selection
1489     modif->SetSelection(sel);
1490     return Standard_True;
1491   }
1492   return Standard_False;
1493 }
1494
1495
1496 //=======================================================================
1497 //function : 
1498 //purpose  : 
1499 //=======================================================================
1500
1501 Standard_Boolean IFSelect_WorkSession::ResetItemSelection
1502   (const Handle(Standard_Transient)& item)
1503 {
1504   Handle(IFSelect_Selection) nulsel;
1505   return SetItemSelection (item,nulsel);
1506 }
1507
1508
1509 //=======================================================================
1510 //function : 
1511 //purpose  : 
1512 //=======================================================================
1513
1514 Handle(IFSelect_Selection) IFSelect_WorkSession::ItemSelection
1515   (const Handle(Standard_Transient)& item) const
1516 {
1517   Handle(IFSelect_Selection) sel;
1518   DeclareAndCast(IFSelect_Dispatch,disp,item);
1519   DeclareAndCast(IFSelect_GeneralModifier,modif,item);
1520   if (ItemIdent(disp)  > 0) return disp->FinalSelection();
1521   if (ItemIdent(modif) > 0) return modif->Selection();
1522   return sel;         // Nul ou inconnu -> Null
1523 }
1524
1525 //  ######################################################################
1526 //  ....                        Les COMPTEURS                         ....
1527
1528 //=======================================================================
1529 //function : 
1530 //purpose  : 
1531 //=======================================================================
1532
1533 Handle(IFSelect_SignCounter) IFSelect_WorkSession::SignCounter
1534   (const Standard_Integer id) const 
1535 {  return GetCasted(IFSelect_SignCounter,Item(id));  }
1536
1537
1538 //=======================================================================
1539 //function : 
1540 //purpose  : 
1541 //=======================================================================
1542
1543 Standard_Boolean IFSelect_WorkSession::ComputeCounter
1544   (const Handle(IFSelect_SignCounter)& counter, const Standard_Boolean forced)
1545 {
1546   if (counter.IsNull()) return Standard_False;
1547   if (!ComputeGraph())  return Standard_False;
1548   return counter->ComputeSelected (Graph(),forced);
1549 }
1550
1551
1552 //=======================================================================
1553 //function : 
1554 //purpose  : 
1555 //=======================================================================
1556
1557 Standard_Boolean IFSelect_WorkSession::ComputeCounterFromList
1558   (const Handle(IFSelect_SignCounter)& counter,
1559    const Handle(TColStd_HSequenceOfTransient)& list,
1560    const Standard_Boolean clear)
1561 {
1562   if (counter.IsNull()) return Standard_False;
1563   if (clear) counter->Clear();
1564   if (list.IsNull()) return ComputeCounter (counter,Standard_True);
1565   counter->AddList (list,themodel);
1566   return Standard_True;
1567 }
1568
1569 //  ######################################################################
1570 //  ....                        Les DISPATCHES                        ....
1571
1572 //=======================================================================
1573 //function : 
1574 //purpose  : 
1575 //=======================================================================
1576
1577 Handle(TColStd_HSequenceOfInteger) IFSelect_WorkSession::AppliedDispatches
1578   () const 
1579 {
1580   Handle(TColStd_HSequenceOfInteger) list = new TColStd_HSequenceOfInteger();
1581   Standard_Integer nb = theshareout->NbDispatches();
1582   for (Standard_Integer i = 1; i <= nb; i ++) {
1583     list->Append (ItemIdent(theshareout->Dispatch(i)));
1584   }
1585   return list;
1586 }
1587
1588
1589 //=======================================================================
1590 //function : 
1591 //purpose  : 
1592 //=======================================================================
1593
1594 void IFSelect_WorkSession::ClearShareOut (const Standard_Boolean onlydisp)
1595 {
1596   theshareout->Clear(onlydisp);
1597 }
1598
1599
1600 //=======================================================================
1601 //function : 
1602 //purpose  : 
1603 //=======================================================================
1604
1605 Handle(IFSelect_Dispatch) IFSelect_WorkSession::Dispatch
1606   (const Standard_Integer id) const 
1607 {
1608   return GetCasted(IFSelect_Dispatch,Item(id));
1609 }
1610
1611
1612 //=======================================================================
1613 //function : 
1614 //purpose  : 
1615 //=======================================================================
1616
1617 Standard_Integer IFSelect_WorkSession::DispatchRank
1618   (const Handle(IFSelect_Dispatch)& disp) const
1619 {
1620   if (ItemIdent(disp) == 0) return 0;
1621   return theshareout->DispatchRank(disp);
1622 }
1623
1624 //  ######################################################################
1625 //  ....                        Les MODIFIERS                         ....
1626
1627 //=======================================================================
1628 //function : 
1629 //purpose  : 
1630 //=======================================================================
1631
1632 Handle(IFSelect_ModelCopier) IFSelect_WorkSession::ModelCopier () const
1633 {
1634   return thecopier;
1635 }
1636
1637
1638 //=======================================================================
1639 //function : 
1640 //purpose  : 
1641 //=======================================================================
1642
1643 void IFSelect_WorkSession::SetModelCopier
1644   (const Handle(IFSelect_ModelCopier)& copier)
1645 {
1646   thecopier = copier;
1647   thecopier->SetShareOut(theshareout);
1648 }
1649
1650
1651 //=======================================================================
1652 //function : 
1653 //purpose  : 
1654 //=======================================================================
1655
1656 Standard_Integer IFSelect_WorkSession::NbFinalModifiers
1657   (const Standard_Boolean formodel) const 
1658 {
1659   return theshareout->NbModifiers(formodel);
1660 }
1661
1662
1663 //=======================================================================
1664 //function : 
1665 //purpose  : 
1666 //=======================================================================
1667
1668 Handle(TColStd_HSequenceOfInteger) IFSelect_WorkSession::FinalModifierIdents
1669                                    (const Standard_Boolean formodel) const 
1670 {
1671 //  return ItemIdents(STANDARD_TYPE(IFSelect_Modifier));
1672 //  On donne la liste dans l ordre du ModelCopier, qui fait foi
1673   Handle(TColStd_HSequenceOfInteger) list = new TColStd_HSequenceOfInteger();
1674   Standard_Integer nbm = theshareout->NbModifiers(formodel);
1675   for (Standard_Integer i = 1; i <= nbm; i ++)
1676     list->Append(ItemIdent(theshareout->GeneralModifier(formodel,i)));
1677   return list;
1678 }
1679
1680
1681 //=======================================================================
1682 //function : 
1683 //purpose  : 
1684 //=======================================================================
1685
1686 Handle(IFSelect_GeneralModifier) IFSelect_WorkSession::GeneralModifier
1687   (const Standard_Integer id) const
1688 {
1689   return GetCasted(IFSelect_GeneralModifier,Item(id));
1690 }
1691
1692
1693 //=======================================================================
1694 //function : 
1695 //purpose  : 
1696 //=======================================================================
1697
1698 Handle(IFSelect_Modifier) IFSelect_WorkSession::ModelModifier
1699   (const Standard_Integer id) const 
1700 {
1701   return GetCasted(IFSelect_Modifier,Item(id));
1702 }
1703
1704
1705 //=======================================================================
1706 //function : 
1707 //purpose  : 
1708 //=======================================================================
1709
1710 Standard_Integer IFSelect_WorkSession::ModifierRank
1711   (const Handle(IFSelect_GeneralModifier)& modif) const
1712 {
1713   if (ItemIdent(modif) == 0) return 0;
1714   return theshareout->ModifierRank(modif);
1715 }
1716
1717
1718 //=======================================================================
1719 //function : 
1720 //purpose  : 
1721 //=======================================================================
1722
1723 Standard_Boolean IFSelect_WorkSession::ChangeModifierRank
1724   (const Standard_Boolean formodel,
1725    const Standard_Integer before, const Standard_Integer after)
1726 {
1727   return theshareout->ChangeModifierRank(formodel,before,after);
1728 }
1729
1730
1731 //=======================================================================
1732 //function : 
1733 //purpose  : 
1734 //=======================================================================
1735
1736 void IFSelect_WorkSession::ClearFinalModifiers ()
1737 {
1738   Handle(TColStd_HSequenceOfInteger) list = FinalModifierIdents (Standard_True);
1739   Standard_Integer nb = list->Length();
1740   Standard_Integer i; // svv #1
1741   for (i = 1; i <= nb; i ++)
1742     RemoveItem(GeneralModifier(list->Value(i)));
1743   list = FinalModifierIdents (Standard_False);
1744   nb = list->Length();
1745   for (i = 1; i <= nb; i ++)
1746     RemoveItem(GeneralModifier(list->Value(i)));
1747 }
1748
1749
1750 //=======================================================================
1751 //function : 
1752 //purpose  : 
1753 //=======================================================================
1754
1755 Standard_Boolean IFSelect_WorkSession::SetAppliedModifier
1756   (const Handle(IFSelect_GeneralModifier)& modif,
1757    const Handle(Standard_Transient)& item)
1758 {
1759   if (ItemIdent(modif) == 0) return Standard_False;
1760
1761   if (item.IsNull()) return Standard_False;
1762   if (item == theshareout) {
1763     theshareout->AddModifier(modif,0);
1764     return Standard_True;
1765   }
1766   if (item->IsKind(STANDARD_TYPE(IFSelect_Dispatch))) {
1767     DeclareAndCast(IFSelect_Dispatch,disp,item);
1768     theshareout->AddModifier(modif,0);
1769     modif->SetDispatch(disp);
1770     return Standard_True;
1771   }
1772   if (item->IsKind(STANDARD_TYPE(IFSelect_TransformStandard))) {
1773     DeclareAndCast(IFSelect_TransformStandard,stf,item);
1774     DeclareAndCast(IFSelect_Modifier,tmod,modif);
1775     if (tmod.IsNull()) return Standard_False;
1776     stf->AddModifier (tmod);
1777     theshareout->RemoveItem(modif);
1778     return Standard_True;
1779   }
1780   return Standard_False;
1781 }
1782
1783
1784 //=======================================================================
1785 //function : 
1786 //purpose  : 
1787 //=======================================================================
1788
1789 Standard_Boolean IFSelect_WorkSession::ResetAppliedModifier
1790   (const Handle(IFSelect_GeneralModifier)& modif)
1791 {
1792   if (ItemIdent(modif) == 0) return Standard_False;
1793
1794   return theshareout->RemoveItem(modif);
1795 }
1796
1797
1798 //=======================================================================
1799 //function : 
1800 //purpose  : 
1801 //=======================================================================
1802
1803 Handle(Standard_Transient) IFSelect_WorkSession::UsesAppliedModifier
1804   (const Handle(IFSelect_GeneralModifier)& modif) const
1805 {
1806   Handle(Standard_Transient) res;
1807   if (ItemIdent(modif) == 0) return res;
1808   if (theshareout->ModifierRank(modif) == 0) return res;
1809   res = modif->Dispatch();
1810   if (res.IsNull()) res = theshareout;
1811   return res;
1812 }
1813
1814 //  #################################################################
1815 //  ....                       Transformer                       ....
1816
1817 //=======================================================================
1818 //function : 
1819 //purpose  : 
1820 //=======================================================================
1821
1822 Handle(IFSelect_Transformer) IFSelect_WorkSession::Transformer
1823   (const Standard_Integer id) const
1824 {
1825   return GetCasted(IFSelect_Transformer,Item(id));
1826 }
1827
1828
1829 //=======================================================================
1830 //function : 
1831 //purpose  : 
1832 //=======================================================================
1833
1834 Standard_Integer IFSelect_WorkSession::RunTransformer
1835   (const Handle(IFSelect_Transformer)& transf)
1836 {
1837   Standard_Integer effect = 0;
1838   if (transf.IsNull() || !IsLoaded()) return effect;
1839   Handle(Interface_InterfaceModel) newmod;    // Null au depart
1840   Interface_CheckIterator checks;
1841   checks.SetName("X-STEP WorkSession : RunTransformer");
1842   Standard_Boolean res = transf->Perform
1843     (thegraph->Graph(),theprotocol,checks,newmod);
1844
1845   if (!checks.IsEmpty(Standard_False)) {
1846     Handle(Message_Messenger) sout = Message::DefaultMessenger();
1847     sout<<"  **    RunTransformer has produced Check Messages :    **"<<endl;
1848     checks.Print (sout,themodel,Standard_False);
1849   }
1850   thecheckdone = Standard_False;
1851   thecheckrun  = checks;
1852
1853   if (newmod.IsNull()) return (res ? 1 : -1);
1854 //  MISE A JOUR des SelectPointed
1855   Handle(TColStd_HSequenceOfInteger) list =
1856     ItemIdents(STANDARD_TYPE(IFSelect_SelectPointed));
1857   Standard_Integer nb = list->Length();
1858   for (Standard_Integer i = 1; i <= nb; i ++) {
1859     DeclareAndCast(IFSelect_SelectPointed,sp,Item(list->Value(i)));
1860     sp->Update(transf);
1861   }
1862   if (newmod == themodel) {
1863     effect = (res ? 2 : -2);
1864     if (!res) return effect;
1865     Handle(Interface_Protocol) newproto = theprotocol;
1866     if (transf->ChangeProtocol(newproto))
1867       {  effect = 4;  theprotocol = newproto;  thegtool->SetProtocol(newproto);  }
1868     return (ComputeGraph(Standard_True) ? 4 : -4);
1869   } else {
1870     effect = (res ? 3 : -3);
1871     if (!res) return effect;
1872     Handle(Interface_Protocol) newproto = theprotocol;
1873     if (transf->ChangeProtocol(newproto))
1874       {  effect = 5;  theprotocol = newproto;  thegtool->SetProtocol(newproto);  }
1875     theoldel = themodel;
1876     SetModel(newmod,Standard_False);
1877   }
1878   return effect;
1879 }
1880
1881
1882 //=======================================================================
1883 //function : 
1884 //purpose  : 
1885 //=======================================================================
1886
1887 Standard_Integer IFSelect_WorkSession::RunModifier
1888   (const Handle(IFSelect_Modifier)& modif, const Standard_Boolean copy)
1889 {
1890   Handle(IFSelect_Selection) sel;  // null
1891   return RunModifierSelected (modif,sel,copy);
1892 }
1893
1894
1895 //=======================================================================
1896 //function : 
1897 //purpose  : 
1898 //=======================================================================
1899
1900 Standard_Integer IFSelect_WorkSession::RunModifierSelected
1901   (const Handle(IFSelect_Modifier)& modif,
1902    const Handle(IFSelect_Selection)& sel,  const Standard_Boolean copy)
1903 {
1904   if (ItemIdent(modif) == 0) return Standard_False;
1905   Handle(IFSelect_TransformStandard) stf = new IFSelect_TransformStandard;
1906   stf->SetCopyOption(copy);
1907   stf->SetSelection (sel);
1908   stf->AddModifier (modif);
1909   return RunTransformer (stf);
1910 }
1911
1912
1913 //=======================================================================
1914 //function : 
1915 //purpose  : 
1916 //=======================================================================
1917
1918 Handle(IFSelect_Transformer) IFSelect_WorkSession::NewTransformStandard
1919   (const Standard_Boolean copy, const Standard_CString name)
1920 {
1921   Handle(IFSelect_TransformStandard) stf = new IFSelect_TransformStandard;
1922   stf->SetCopyOption(copy);
1923   if (AddNamedItem (name, stf) == 0) stf.Nullify();
1924   return stf;
1925 }
1926
1927
1928 //    Ceci est une action directe : pourrait etre fait par un Transformer ...
1929 //=======================================================================
1930 //function : 
1931 //purpose  : 
1932 //=======================================================================
1933
1934 Standard_Boolean IFSelect_WorkSession::SetModelContent
1935   (const Handle(IFSelect_Selection)& sel, const Standard_Boolean keep)
1936 {
1937   if (sel.IsNull() || !IsLoaded()) return Standard_False;
1938   Interface_EntityIterator list = sel->UniqueResult(thegraph->Graph());
1939   if (list.NbEntities() == 0) return Standard_False;
1940
1941   Handle(Interface_InterfaceModel) newmod  = themodel->NewEmptyModel();
1942   Interface_CopyTool TC(themodel,theprotocol);
1943   Standard_Integer i, nb = themodel->NbEntities();
1944   if (keep) {
1945     for (list.Start(); list.More(); list.Next())
1946       TC.TransferEntity (list.Value());
1947   } else {
1948     Standard_Integer* flags = new Standard_Integer[nb+1];
1949     for (i = 0; i <= nb; i ++) flags[i] = 0;
1950     for (list.Start(); list.More(); list.Next()) {
1951       Standard_Integer num = themodel->Number(list.Value());
1952       if (num <= nb) flags[num] = 1;
1953     }
1954     for (i = 1; i <= nb; i ++) {
1955       if (flags[i] == 0) TC.TransferEntity (themodel->Value(i));
1956     }
1957     delete [] flags;
1958   }
1959   TC.FillModel(newmod);
1960   if (newmod->NbEntities() == 0) return Standard_False;
1961 //    Mettre a jour (ne pas oublier SelectPointed)
1962   theoldel = themodel;
1963   SetModel(newmod,Standard_False);
1964 //  MISE A JOUR des SelectPointed
1965   Handle(TColStd_HSequenceOfInteger) pts =
1966     ItemIdents(STANDARD_TYPE(IFSelect_SelectPointed));
1967   nb = pts->Length();
1968   for (i = 1; i <= nb; i ++) {
1969     DeclareAndCast(IFSelect_SelectPointed,sp,Item(pts->Value(i)));
1970     sp->Update(TC.Control());
1971   }
1972   return Standard_True;
1973 }
1974
1975
1976 //  #################################################################
1977 //  ....                        File Name                        ....
1978
1979 //=======================================================================
1980 //function : 
1981 //purpose  : 
1982 //=======================================================================
1983
1984 Handle(TCollection_HAsciiString) IFSelect_WorkSession::FilePrefix () const
1985 {
1986   return theshareout->Prefix();
1987 }
1988
1989
1990 //=======================================================================
1991 //function : 
1992 //purpose  : 
1993 //=======================================================================
1994
1995 Handle(TCollection_HAsciiString) IFSelect_WorkSession::DefaultFileRoot () const
1996 {
1997   return theshareout->DefaultRootName();
1998 }
1999
2000
2001 //=======================================================================
2002 //function : 
2003 //purpose  : 
2004 //=======================================================================
2005
2006 Handle(TCollection_HAsciiString) IFSelect_WorkSession::FileExtension () const
2007 {
2008   return theshareout->Extension();
2009 }
2010
2011
2012 //=======================================================================
2013 //function : 
2014 //purpose  : 
2015 //=======================================================================
2016
2017 Handle(TCollection_HAsciiString) IFSelect_WorkSession::FileRoot
2018   (const Handle(IFSelect_Dispatch)& disp) const
2019 {
2020   return theshareout->RootName(theshareout->DispatchRank(disp));
2021 }
2022
2023
2024 //=======================================================================
2025 //function : 
2026 //purpose  : 
2027 //=======================================================================
2028
2029 void IFSelect_WorkSession::SetFilePrefix (const Standard_CString name)
2030 {
2031   theshareout->SetPrefix (new TCollection_HAsciiString(name));
2032 }
2033
2034
2035 //=======================================================================
2036 //function : 
2037 //purpose  : 
2038 //=======================================================================
2039
2040 void IFSelect_WorkSession::SetFileExtension (const Standard_CString name)
2041 {
2042   theshareout->SetExtension (new TCollection_HAsciiString(name));
2043 }
2044
2045
2046 //=======================================================================
2047 //function : 
2048 //purpose  : 
2049 //=======================================================================
2050
2051 Standard_Boolean  IFSelect_WorkSession::SetDefaultFileRoot
2052   (const Standard_CString name)
2053 {
2054   Handle(TCollection_HAsciiString) defrt;
2055   if (name[0] != '\0') defrt = new TCollection_HAsciiString(name);
2056   return theshareout->SetDefaultRootName (defrt);
2057 }
2058
2059
2060 //=======================================================================
2061 //function : 
2062 //purpose  : 
2063 //=======================================================================
2064
2065 Standard_Boolean IFSelect_WorkSession::SetFileRoot
2066   (const Handle(IFSelect_Dispatch)& disp, const Standard_CString namefile)
2067 {
2068   Standard_Integer id = ItemIdent(disp);
2069   if (id == 0) return Standard_False;
2070   Standard_Integer nd = theshareout->DispatchRank(disp);
2071 /*  if (theonlynamed) {
2072     if      (nd == 0 && namefile[0] != 0)
2073       theshareout->AddDispatch(disp);
2074     else if (nd != 0 && namefile[0] == 0)
2075       theshareout->RemoveDispatch (nd);
2076   }  */
2077   if (nd == 0) return Standard_False;
2078 //  The order below prevented to change the root name on a given dispatch !
2079 //  if (theshareout->HasRootName(nd)) return Standard_False;
2080   Handle(TCollection_HAsciiString) filename;
2081   if (namefile[0] != '\0') filename = new TCollection_HAsciiString (namefile);
2082   return theshareout->SetRootName(nd,filename);
2083 }
2084
2085
2086 //=======================================================================
2087 //function : 
2088 //purpose  : 
2089 //=======================================================================
2090
2091 Standard_CString IFSelect_WorkSession::GiveFileRoot
2092   (const Standard_CString file) const
2093 {
2094   OSD_Path path (file);
2095   if (!path.IsValid(TCollection_AsciiString(file))) return file; // tant pis ..
2096   bufstr = path.Name();
2097   return bufstr.ToCString();
2098 }
2099
2100
2101 //=======================================================================
2102 //function : 
2103 //purpose  : 
2104 //=======================================================================
2105
2106 Standard_CString IFSelect_WorkSession::GiveFileComplete
2107   (const Standard_CString file) const
2108 {
2109 //  ajouter si besoin : Prefix; Extension
2110   bufstr.Clear(); bufstr.AssignCat (file);
2111   Standard_Integer i,j = 0,nb = bufstr.Length();
2112   Handle(TCollection_HAsciiString) ext = FileExtension ();
2113   if (!ext.IsNull()) {
2114     char val0 = '\0';  if (ext->Length() > 0) val0 = ext->Value(1);
2115     for (i = nb; i > 0; i --)  if (bufstr.Value(i) == val0) { j = 1; break; }
2116     if (j == 0) bufstr.AssignCat (ext->ToCString());
2117   }
2118   Handle(TCollection_HAsciiString) pre = FilePrefix ();
2119   if (!pre.IsNull()) {
2120     char val1 = '\0';  if (pre->Length() > 0) val1 = pre->Value(pre->Length());
2121     j = 0;
2122     for (i = nb; i > 0; i --)  if (bufstr.Value(i) == val1) { j = 1; break; }
2123     if (j == 0) bufstr.Insert (1,pre->ToCString());
2124   }
2125
2126   return bufstr.ToCString();
2127 }
2128
2129
2130 //=======================================================================
2131 //function : 
2132 //purpose  : 
2133 //=======================================================================
2134
2135 void IFSelect_WorkSession::ClearFile ()
2136 {
2137   thecopier->ClearResult();
2138   theshareout->ClearResult(Standard_True);
2139 }
2140
2141
2142 //=======================================================================
2143 //function : 
2144 //purpose  : 
2145 //=======================================================================
2146
2147 void IFSelect_WorkSession::EvaluateFile ()
2148 {
2149 ////...
2150   if (!IsLoaded()) return;
2151   Interface_CheckIterator checks;
2152   if (errhand) {
2153     errhand = Standard_False;
2154     try {
2155       OCC_CATCH_SIGNALS
2156       EvaluateFile();    // appel normal (donc, code pas duplique)
2157     }
2158     catch (Standard_Failure) {
2159       Handle(Message_Messenger) sout = Message::DefaultMessenger();
2160       sout<<"    ****    Interruption EvaluateFile par Exception :   ****\n";
2161       sout<<Standard_Failure::Caught()->GetMessageString();
2162       sout<<"\n    Abandon"<<endl;
2163       checks.CCheck(0)->AddFail ("Exception Raised -> Abandon");
2164     }
2165     errhand = theerrhand;
2166     thecheckrun = checks;
2167     return;
2168   }
2169
2170   IFSelect_ShareOutResult R(theshareout,thegraph->Graph());
2171   checks = thecopier->Copy (R,thelibrary,theprotocol);
2172   if (!checks.IsEmpty(Standard_False)) {
2173     Handle(Message_Messenger) sout = Message::DefaultMessenger();
2174     sout<<"  **    EvaluateFile has produced Check Messages :    **"<<endl;
2175     checks.Print (sout,themodel,Standard_False);
2176   } 
2177   thecopier->SetRemaining (thegraph->CGraph());
2178   thecheckrun = checks;
2179 }
2180
2181
2182 //=======================================================================
2183 //function : 
2184 //purpose  : 
2185 //=======================================================================
2186
2187 Standard_Integer IFSelect_WorkSession::NbFiles () const 
2188 {
2189   return thecopier->NbFiles();
2190 }
2191
2192
2193 //=======================================================================
2194 //function : 
2195 //purpose  : 
2196 //=======================================================================
2197
2198 Handle(Interface_InterfaceModel) IFSelect_WorkSession::FileModel
2199   (const Standard_Integer num) const 
2200 {
2201   Handle(Interface_InterfaceModel) mod;
2202   if (num > 0 && num <= NbFiles()) mod = thecopier->FileModel(num);
2203   return mod;
2204 }
2205
2206
2207 //=======================================================================
2208 //function : 
2209 //purpose  : 
2210 //=======================================================================
2211
2212 TCollection_AsciiString IFSelect_WorkSession::FileName
2213   (const Standard_Integer num) const 
2214 {
2215   TCollection_AsciiString name;
2216   if (num > 0 && num <= NbFiles()) name = thecopier->FileName(num);
2217   return name;
2218 }
2219
2220
2221 //=======================================================================
2222 //function : 
2223 //purpose  : 
2224 //=======================================================================
2225
2226 void IFSelect_WorkSession::BeginSentFiles (const Standard_Boolean record)
2227 {
2228   thecopier->BeginSentFiles(theshareout,record);
2229 }
2230
2231
2232 //=======================================================================
2233 //function : 
2234 //purpose  : 
2235 //=======================================================================
2236
2237 Handle(TColStd_HSequenceOfHAsciiString) IFSelect_WorkSession::SentFiles () const
2238 {
2239   return thecopier->SentFiles();
2240 }
2241
2242
2243 //  #########################################################################
2244 //  ....    Action de Transfert proprement dite : la grande affaire !    ....
2245
2246 //=======================================================================
2247 //function : 
2248 //purpose  : 
2249 //=======================================================================
2250
2251 Standard_Boolean IFSelect_WorkSession::SendSplit ()
2252 {
2253 ////...
2254   Interface_CheckIterator checks;
2255
2256   if (errhand) {
2257     errhand = Standard_False;
2258     try {
2259       OCC_CATCH_SIGNALS
2260       return SendSplit();   // appel normal (donc, code pas duplique)
2261     }
2262     catch (Standard_Failure) {
2263       Handle(Message_Messenger) sout = Message::DefaultMessenger();
2264       sout<<"    ****    Interruption SendSplit par Exception :   ****\n";
2265       sout<<Standard_Failure::Caught()->GetMessageString();
2266       sout<<"\n    Abandon"<<endl;
2267       checks.CCheck(0)->AddFail ("Exception Raised -> Abandon");
2268     }
2269     errhand = theerrhand;
2270     thecheckrun = checks;
2271     return Standard_False;
2272   }
2273
2274   if (thelibrary.IsNull()) {
2275     checks.CCheck(0)->AddFail("WorkLibrary undefined");
2276     thecheckrun = checks;
2277     return Standard_False;
2278   }
2279   if (!IsLoaded()) {
2280     Handle(Message_Messenger) sout = Message::DefaultMessenger();
2281     sout<< " ***  Data for SendSplit not available  ***"<<endl;
2282     checks.CCheck(0)->AddFail("Data not available");
2283     thecheckrun = checks;
2284     return Standard_False;
2285   }
2286
2287   if (NbFiles() > 0) checks = thecopier->SendCopied (thelibrary,theprotocol);
2288   else {
2289     /*
2290     IFSelect_ShareOutResult eval (ShareOut(), thegraph->Graph());
2291     checks = thecopier->Send (eval, thelibrary, theprotocol);
2292     thecopier->SetRemaining (thegraph->CGraph());
2293     */
2294 //  Decomposer
2295     if (theshareout.IsNull()) return Standard_False;
2296     Standard_Integer i, nbd = theshareout->NbDispatches();
2297     Standard_Integer nf = 0;
2298     Handle(Message_Messenger) sout = Message::DefaultMessenger();
2299     sout<<" SendSplit .. ";
2300     for (i = 1; i <= nbd; i ++) {
2301       Handle(IFSelect_Dispatch) disp = theshareout->Dispatch(i);
2302       if (disp.IsNull()) continue;
2303       IFGraph_SubPartsIterator packs(thegraph->Graph(),Standard_False);
2304       disp->Packets (thegraph->Graph(),packs);
2305       for (packs.Start(); packs.More(); packs.Next()) {
2306         Interface_EntityIterator iter = packs.Entities();
2307         if (iter.NbEntities() == 0) continue;
2308 //  Ecrire une liste d entites
2309         Handle(IFSelect_SelectPointed) sp = new IFSelect_SelectPointed;
2310         sp->SetList (iter.Content());
2311         nf ++;
2312         TCollection_AsciiString filnam (nf);
2313         filnam.Insert (1,"_");
2314         Handle(TCollection_HAsciiString) filepart;
2315         filepart = FileRoot(disp);
2316         if (!filepart.IsNull()) filnam.Insert(1,filepart->ToCString());
2317         filepart = FilePrefix();
2318         if (!filepart.IsNull()) filnam.Insert(1,filepart->ToCString());
2319         filepart = FileExtension();
2320         if (!filepart.IsNull()) filnam.AssignCat (filepart->ToCString());
2321         IFSelect_ReturnStatus stat = SendSelected (filnam.ToCString(),sp);
2322         if (stat != IFSelect_RetDone) cout<<"File "<<filnam<<" failed"<<endl;
2323       }
2324     }
2325     sout<<" .. Files Written : "<<nf<<endl;
2326   }
2327   thecheckrun = checks;
2328   return Standard_True;
2329 }
2330
2331
2332 //=======================================================================
2333 //function : 
2334 //purpose  : 
2335 //=======================================================================
2336
2337 Handle(IFSelect_PacketList) IFSelect_WorkSession::EvalSplit () const
2338 {
2339   Handle(IFSelect_PacketList) pks;
2340   if (!IsLoaded()) return pks;
2341   IFSelect_ShareOutResult sho (ShareOut(), thegraph->Graph());
2342   return sho.Packets();
2343 }
2344
2345
2346 //=======================================================================
2347 //function : 
2348 //purpose  : 
2349 //=======================================================================
2350
2351 Interface_EntityIterator IFSelect_WorkSession::SentList
2352   (const Standard_Integer newcount) const
2353 {
2354   Interface_EntityIterator iter;
2355   if (!IsLoaded()) return iter;
2356   const Interface_Graph& G = thegraph->Graph();
2357   Standard_Integer nb = G.Size();
2358   Standard_Integer i;
2359   for ( i = 1; i <= nb; i ++) {
2360     Standard_Integer stat = G.Status(i);
2361     if ( (stat > 0 && newcount < 0) || stat == newcount)
2362       iter.GetOneItem(G.Entity(i));
2363   }
2364   return iter;
2365 }
2366
2367
2368 //=======================================================================
2369 //function : 
2370 //purpose  : 
2371 //=======================================================================
2372
2373 Standard_Integer IFSelect_WorkSession::MaxSendingCount () const
2374 {
2375   Standard_Integer newcount = 0;
2376   if (!IsLoaded()) return newcount;
2377   const Interface_Graph& G = thegraph->Graph();
2378   Standard_Integer nb = G.Size();
2379   Standard_Integer  i;
2380   for (i = 1; i <= nb; i ++) {
2381     Standard_Integer stat = G.Status(i);
2382     if (stat > newcount) newcount = stat;
2383   }
2384   return newcount;
2385 }
2386
2387
2388 //=======================================================================
2389 //function : 
2390 //purpose  : 
2391 //=======================================================================
2392
2393 Standard_Boolean IFSelect_WorkSession::SetRemaining
2394   (const IFSelect_RemainMode mode)
2395 {
2396   Handle(Message_Messenger) sout = Message::DefaultMessenger();
2397   if (!IsLoaded()) return Standard_False;
2398   if (mode == IFSelect_RemainForget) {
2399     Standard_Integer nb = thegraph->Graph().Size();
2400     for (Standard_Integer i = 1; i <= nb; i ++)
2401       thegraph->CGraph().SetStatus (i,0);
2402     theoldel.Nullify();
2403     return Standard_True;
2404   } else if (mode == IFSelect_RemainCompute) {
2405     Handle(Interface_InterfaceModel) newmod;
2406     Interface_CopyTool TC(themodel,theprotocol);
2407     thecopier->CopiedRemaining (thegraph->Graph(),thelibrary,TC,newmod);
2408     if (newmod.IsNull()) {
2409       sout<<" No Remaining Data recorded"<<endl;  return Standard_False;
2410     } else if (newmod == themodel) {
2411       sout<<" Remaining causes all original data to be kept"<<endl;
2412       thecopier->SetRemaining (thegraph->CGraph());
2413       return Standard_False;
2414     } else {
2415       theoldel = themodel;
2416       SetModel(newmod,Standard_False);
2417 //  MISE A JOUR des SelectPointed
2418       Handle(TColStd_HSequenceOfInteger) list =
2419         ItemIdents(STANDARD_TYPE(IFSelect_SelectPointed));
2420       Standard_Integer nb = list->Length();
2421       for (Standard_Integer i = 1; i <= nb; i ++) {
2422         DeclareAndCast(IFSelect_SelectPointed,sp,Item(list->Value(i)));
2423         sp->Update(TC.Control());
2424       }
2425       return Standard_True;
2426     }
2427   } else if (mode == IFSelect_RemainDisplay) {
2428     Standard_Integer ne = 0;
2429     Standard_Integer nb = thegraph->Graph().Size();
2430     for (Standard_Integer i = 1; i <= nb; i ++)
2431       {  if (thegraph->Graph().Status(i) >= 0) ne ++;  }
2432     if (ne == 0) {
2433       sout<<" - All entities are remaining, none yet sent"<<endl;  return Standard_True;
2434     }
2435     Interface_EntityIterator iter = SentList(0);
2436     nb = iter.NbEntities();
2437     if (nb == 0) {
2438       sout<<" - No recorded remaining entities"<<endl;  return Standard_True;
2439     }
2440     sout <<" --  Recorded Remaining (not yet sent) Entities  --"<<endl;
2441     ListEntities(iter,2);
2442     sout << " -- Maximum Sending Count (i.e. duplication in files) "<<
2443       MaxSendingCount() << endl;
2444
2445 /*
2446     sout<< " - Now, dispatches are deactivated"<<endl;
2447     nb = theshareout->NbDispatches();
2448     for (Standard_Integer i = nb; i > theshareout->LastRun(); i --)
2449       theshareout->RemoveDispatch(i);
2450 */
2451     return Standard_True;
2452   } else if (mode == IFSelect_RemainUndo) {
2453     if (theoldel.IsNull()) return Standard_False;
2454     SetModel(theoldel);  theoldel.Nullify();
2455     return Standard_True;
2456   }
2457   else return Standard_False;
2458 }
2459
2460
2461 //=======================================================================
2462 //function : 
2463 //purpose  : 
2464 //=======================================================================
2465
2466 IFSelect_ReturnStatus IFSelect_WorkSession::SendAll
2467   (const Standard_CString filename, const Standard_Boolean computegraph)
2468 {
2469 ////...
2470   Interface_CheckIterator checks;
2471   if (!IsLoaded()) return IFSelect_RetVoid;
2472   if (thelibrary.IsNull()) {
2473     checks.CCheck(0)->AddFail("WorkLibrary undefined");
2474     thecheckrun = checks;
2475     return IFSelect_RetError;
2476   }
2477
2478   if (errhand) {
2479     errhand = Standard_False;
2480     try {
2481       OCC_CATCH_SIGNALS
2482       ComputeGraph(computegraph);
2483       checks = thecopier->SendAll(filename,thegraph->Graph(),thelibrary,theprotocol);
2484     }
2485     catch (Standard_Failure) {
2486       Handle(Message_Messenger) sout = Message::DefaultMessenger();
2487       sout<<"    ****    Interruption SendAll par Exception :   ****\n";
2488       sout<<Standard_Failure::Caught()->GetMessageString();
2489       sout<<"\n    Abandon"<<endl;
2490       errhand = theerrhand;
2491       checks.CCheck(0)->AddFail ("Exception Raised -> Abandon");
2492       thecheckrun = checks;
2493       return IFSelect_RetFail;
2494     }
2495   }
2496   else checks = thecopier->SendAll(filename,thegraph->Graph(),thelibrary,theprotocol);
2497   Handle(Interface_Check) aMainFail = checks.CCheck(0);
2498   if (!aMainFail.IsNull() && aMainFail->HasFailed ())
2499   {
2500     return IFSelect_RetStop;
2501   }
2502   if (theloaded.Length() == 0) theloaded.AssignCat(filename);
2503   thecheckrun = checks;
2504   if (checks.IsEmpty(Standard_True)) return IFSelect_RetDone;
2505   return IFSelect_RetError;
2506 }
2507
2508
2509 //=======================================================================
2510 //function : 
2511 //purpose  : 
2512 //=======================================================================
2513
2514 IFSelect_ReturnStatus IFSelect_WorkSession::SendSelected
2515   (const Standard_CString filename,
2516    const Handle(IFSelect_Selection)& sel,
2517    const Standard_Boolean computegraph)
2518 {
2519 ////...
2520   if (!IsLoaded()) return IFSelect_RetVoid;
2521   Interface_CheckIterator checks;
2522   if (thelibrary.IsNull()) {
2523     checks.CCheck(0)->AddFail("WorkLibrary undefined");
2524     thecheckrun = checks;
2525     return IFSelect_RetVoid;
2526   }
2527
2528   if (errhand) {
2529     errhand = Standard_False;
2530     try {
2531       OCC_CATCH_SIGNALS
2532       ComputeGraph(computegraph);
2533       return SendSelected (filename,sel);    // appel normal
2534     }
2535     catch (Standard_Failure) {
2536       Handle(Message_Messenger) sout = Message::DefaultMessenger();
2537       sout<<"    ****    Interruption SendSelected par Exception :   ****\n";
2538       sout<<Standard_Failure::Caught()->GetMessageString();
2539       sout<<"\n    Abandon"<<endl;
2540       checks.CCheck(0)->AddFail ("Exception Raised -> Abandon");
2541       errhand = theerrhand;
2542       thecheckrun = checks;
2543       return IFSelect_RetFail;
2544     }
2545   }
2546 //  if (ItemIdent(sel) == 0) return 3;
2547   Interface_EntityIterator iter = sel->UniqueResult(thegraph->Graph());
2548   if (iter.NbEntities() == 0) return IFSelect_RetVoid;
2549
2550   checks = thecopier->SendSelected
2551       (filename,thegraph->Graph(),thelibrary,theprotocol,iter);
2552   thecopier->SetRemaining (thegraph->CGraph());
2553   thecheckrun = checks;
2554   if (checks.IsEmpty(Standard_True)) return IFSelect_RetDone;
2555   return IFSelect_RetError;
2556 }
2557
2558
2559 //=======================================================================
2560 //function : 
2561 //purpose  : 
2562 //=======================================================================
2563
2564 IFSelect_ReturnStatus IFSelect_WorkSession::WriteFile
2565   (const Standard_CString filename)
2566 {
2567   if (WorkLibrary().IsNull()) return IFSelect_RetVoid;
2568   ComputeGraph(Standard_True);
2569   if (!IsLoaded()) return IFSelect_RetVoid;
2570   return SendAll (filename);
2571 }
2572
2573
2574 //=======================================================================
2575 //function : 
2576 //purpose  : 
2577 //=======================================================================
2578
2579 IFSelect_ReturnStatus IFSelect_WorkSession::WriteFile
2580   (const Standard_CString filename, const Handle(IFSelect_Selection)& sel)
2581 {
2582   if (WorkLibrary().IsNull() || sel.IsNull()) return IFSelect_RetVoid;
2583   ComputeGraph(Standard_True);
2584   if (!IsLoaded()) return IFSelect_RetVoid;
2585   return SendSelected (filename,sel);
2586 }
2587
2588 //  ################################################################
2589 //  ....        Actions particulieres sur les Selections        ....
2590
2591 //=======================================================================
2592 //function : 
2593 //purpose  : 
2594 //=======================================================================
2595
2596 Standard_Integer IFSelect_WorkSession::NbSources
2597   (const Handle(IFSelect_Selection)& sel) const
2598 {
2599   if (ItemIdent(sel) == 0) return 0;
2600   if (sel->IsKind(STANDARD_TYPE(IFSelect_SelectExtract)) ||
2601       sel->IsKind(STANDARD_TYPE(IFSelect_SelectDeduct))  )  return 1;
2602   if (sel->IsKind(STANDARD_TYPE(IFSelect_SelectControl)) )  return 2;
2603   if (sel->IsKind(STANDARD_TYPE(IFSelect_SelectCombine)) )  return
2604     GetCasted(IFSelect_SelectCombine,sel)->NbInputs();
2605   return 0;
2606 }
2607
2608
2609 //=======================================================================
2610 //function : 
2611 //purpose  : 
2612 //=======================================================================
2613
2614 Handle(IFSelect_Selection) IFSelect_WorkSession::Source
2615   (const Handle(IFSelect_Selection)& sel, const Standard_Integer num) const
2616 {
2617   Handle(IFSelect_Selection) sr;
2618   if (ItemIdent(sel) == 0) return sr;
2619   if      (sel->IsKind(STANDARD_TYPE(IFSelect_SelectExtract)) )  sr =
2620     GetCasted(IFSelect_SelectExtract,sel)->Input();
2621   else if (sel->IsKind(STANDARD_TYPE(IFSelect_SelectDeduct))  )  sr =
2622     GetCasted(IFSelect_SelectDeduct,sel)->Input();
2623   else if (sel->IsKind(STANDARD_TYPE(IFSelect_SelectControl)) )  {
2624     if      (num == 1) sr = GetCasted(IFSelect_SelectControl,sel)->MainInput();
2625     else if (num == 2) sr = GetCasted(IFSelect_SelectControl,sel)->SecondInput();
2626   }
2627   else if (sel->IsKind(STANDARD_TYPE(IFSelect_SelectCombine)) )  sr =
2628     GetCasted(IFSelect_SelectCombine,sel)->Input(num);
2629   return sr;
2630 }
2631
2632
2633 //=======================================================================
2634 //function : 
2635 //purpose  : 
2636 //=======================================================================
2637
2638 Standard_Boolean IFSelect_WorkSession::IsReversedSelectExtract
2639   (const Handle(IFSelect_Selection)& sel) const
2640 {
2641   if (ItemIdent(sel) == 0) return Standard_False;
2642   DeclareAndCast(IFSelect_SelectExtract,sxt,sel);
2643   if (sxt.IsNull()) return Standard_False;
2644   return (!sxt->IsDirect());
2645 }
2646
2647
2648 //=======================================================================
2649 //function : 
2650 //purpose  : 
2651 //=======================================================================
2652
2653 Standard_Boolean IFSelect_WorkSession::ToggleSelectExtract
2654   (const Handle(IFSelect_Selection)& sel)
2655 {
2656   if (ItemIdent(sel) == 0) return Standard_False;
2657   DeclareAndCast(IFSelect_SelectExtract,sxt,sel);
2658   if (sxt.IsNull()) return Standard_False;
2659   sxt->SetDirect(!sxt->IsDirect());
2660   return Standard_True;
2661 }
2662
2663
2664 //=======================================================================
2665 //function : 
2666 //purpose  : 
2667 //=======================================================================
2668
2669 Standard_Boolean IFSelect_WorkSession::SetInputSelection
2670   (const Handle(IFSelect_Selection)& sel,
2671    const Handle(IFSelect_Selection)& inp)
2672 {
2673   if (ItemIdent(sel) == 0) return Standard_False;
2674   if (!inp.IsNull() && ItemIdent(inp) == 0) return Standard_False;
2675   DeclareAndCast(IFSelect_SelectExtract,sxt,sel);
2676   if (!sxt.IsNull()) { sxt->SetInput(inp);  return Standard_True; }
2677   DeclareAndCast(IFSelect_SelectDeduct,sdt,sel);
2678   if (!sdt.IsNull()) { sdt->SetInput(inp);  return Standard_True; }
2679   return Standard_False;
2680 }
2681
2682
2683 //=======================================================================
2684 //function : 
2685 //purpose  : 
2686 //=======================================================================
2687
2688 Standard_Boolean IFSelect_WorkSession::SetControl
2689   (const Handle(IFSelect_Selection)& sel,
2690    const Handle(IFSelect_Selection)& sc,
2691    const Standard_Boolean formain)
2692 {
2693   DeclareAndCast(IFSelect_SelectControl,dsel,sel);
2694   if (ItemIdent(dsel) == 0) return Standard_False;
2695   if (ItemIdent(sc)   == 0) return Standard_False;
2696   if (formain) dsel->SetMainInput   (sc);
2697   else         dsel->SetSecondInput (sc);
2698   return Standard_True;
2699 }
2700
2701
2702 //=======================================================================
2703 //function : 
2704 //purpose  : 
2705 //=======================================================================
2706
2707 Standard_Integer IFSelect_WorkSession::CombineAdd
2708   (const Handle(IFSelect_Selection)& sel,
2709    const Handle(IFSelect_Selection)& seladd,
2710    const Standard_Integer atnum)
2711 {
2712   DeclareAndCast(IFSelect_SelectCombine,csel,sel);
2713   if (ItemIdent(csel) == 0) return 0;
2714   if (ItemIdent(seladd) == 0) return 0;
2715   csel->Add (seladd,atnum);
2716   return csel->NbInputs();
2717 }
2718
2719
2720 //=======================================================================
2721 //function : 
2722 //purpose  : 
2723 //=======================================================================
2724
2725 Standard_Boolean IFSelect_WorkSession::CombineRemove
2726   (const Handle(IFSelect_Selection)& selcomb,
2727    const Handle(IFSelect_Selection)& selrem)
2728 {
2729   DeclareAndCast(IFSelect_SelectCombine,csel,selcomb);
2730   if (ItemIdent(csel) == 0) return Standard_False;
2731   if (ItemIdent(selrem) == 0) return Standard_False;
2732   Standard_Integer nb = csel->NbInputs();
2733   for (Standard_Integer i = nb; i > 0; i --) {
2734     if (csel->Input(i) == selrem) {
2735       csel->Remove(i);
2736       return Standard_True;
2737     }
2738   }
2739   return Standard_True;
2740 }
2741
2742
2743 //=======================================================================
2744 //function : 
2745 //purpose  : 
2746 //=======================================================================
2747
2748 Handle(IFSelect_Selection) IFSelect_WorkSession::NewSelectPointed
2749   (const Handle(TColStd_HSequenceOfTransient)& list,
2750    const Standard_CString name)
2751 {
2752   Handle(IFSelect_SelectPointed) sel = new IFSelect_SelectPointed;
2753   if (!list.IsNull()) sel->AddList (list);
2754   if (AddNamedItem (name,sel) == 0) sel.Nullify();
2755   return sel;
2756 }
2757
2758
2759 //=======================================================================
2760 //function : 
2761 //purpose  : 
2762 //=======================================================================
2763
2764 Standard_Boolean IFSelect_WorkSession::SetSelectPointed
2765   (const Handle(IFSelect_Selection)& sel,
2766    const Handle(TColStd_HSequenceOfTransient)& list,
2767    const Standard_Integer mode) const
2768 {
2769   DeclareAndCast(IFSelect_SelectPointed,sp,sel);
2770   if (sp.IsNull() || list.IsNull()) return Standard_False;
2771   if (mode == 0) sp->Clear();
2772   if (mode >= 0) sp->AddList(list);
2773   else sp->RemoveList(list);
2774   return Standard_True;
2775 }
2776
2777
2778 //  ###########################################################################
2779 //  ....         Analyse d un CheckIterator par rapport a un graphe        ....
2780
2781 //=======================================================================
2782 //function : 
2783 //purpose  : 
2784 //=======================================================================
2785
2786 static void IFSelect_QueryProp (Interface_IntList& list,
2787                                 TCollection_AsciiString& ana,
2788                                 const Standard_Integer num, const int quoi)
2789 {
2790   list.SetNumber(num);
2791   Standard_Integer i, nb = list.Length();
2792   for (i = 1; i <= nb; i ++) {
2793     if (i > 1) list.SetNumber(num);  // because recursive call + depth first
2794     Standard_Integer n = list.Value(i);
2795 //    y a t il lieu de propager ?
2796 //  1 W/place  2 F/place  3 Wprop 4Wprop+W/place  5Wprop+F/place
2797 //  6 Fprop  7 Fprop+W/place  8 Fprop+F/place
2798     char val = ana.Value(n);
2799     switch (val) {
2800       case ' ' : val = (quoi ? '3' : '6');  break;
2801       case '1' : val = (quoi ? '4' : '7');  break;
2802       case '2' : val = (quoi ? '5' : '8');  break;
2803       case '3' : val = (quoi ? ' ' : '6');  break;
2804       case '4' : val = (quoi ? ' ' : '7');  break;
2805       case '5' : val = (quoi ? ' ' : '8');  break;
2806       case '6' : val = ' ';  break;
2807       case '7' : val = ' ';  break;
2808       case '8' : val = ' ';  break;
2809       default  : val = ' ';  break;
2810     }
2811     if (val == ' ') continue;
2812     ana.SetValue(n,val);
2813     IFSelect_QueryProp (list,ana,n,quoi);
2814   }
2815 }
2816
2817
2818 //=======================================================================
2819 //function : 
2820 //purpose  : 
2821 //=======================================================================
2822
2823 void IFSelect_WorkSession::QueryCheckList (const Interface_CheckIterator& chl)
2824 {
2825   if (!IsLoaded()) return;
2826   Standard_Integer i,nb = themodel->NbEntities();
2827   thecheckana = TCollection_AsciiString (nb+1,' ');
2828   for (chl.Start(); chl.More(); chl.Next()) {
2829     Standard_Integer num = chl.Number();
2830     const Handle(Interface_Check) ach = chl.Value();
2831     if (ach->HasFailed())        thecheckana.SetValue(num,'2');
2832     else if (ach->HasWarnings()) thecheckana.SetValue(num,'1');
2833   }
2834 //  analyse selon le graphe ... codes : blc = rien
2835 //  1 W/place  2 F/place  3 Wprop 4Wprop+W/place  5Wprop+F/place
2836 //  6 Fprop  7 Fprop+W/place  8 Fprop+F/place
2837   Interface_IntList list;// = thegraph->Graph().SharingNums(0);
2838 //   deux passes : d abord Warning, puis Fail
2839   for (i = 1; i <= nb; i ++) {
2840     char val = thecheckana.Value(i);
2841     int quoi = -1;
2842     if (val == '1' || val == '4' || val == '7') quoi = 0;
2843     if (quoi >= 0) IFSelect_QueryProp (list,thecheckana,i,quoi);
2844   }
2845   for (i = 1; i <= nb; i ++) {
2846     char val = thecheckana.Value(i);
2847     int quoi = -1;
2848     if (val == '2' || val == '5' || val == '8') quoi = 1;
2849     if (quoi >= 0) IFSelect_QueryProp (list,thecheckana,i,quoi);
2850   }
2851 }
2852
2853
2854 //=======================================================================
2855 //function : 
2856 //purpose  : 
2857 //=======================================================================
2858
2859 Standard_Integer IFSelect_WorkSession::QueryCheckStatus
2860   (const Handle(Standard_Transient)& ent) const
2861 {
2862   if (!IsLoaded()) return -1;
2863   Standard_Integer num = themodel->Number(ent);
2864   if (num == 0) return -1;
2865   if (thecheckana.Length() < num) return -1;
2866   Standard_Character val = thecheckana.Value (num);
2867 //  codes : blc = rien -> 0
2868 //  1 W/place -> 1   2 F/place -> 2
2869 //  3 Wprop -> 10    4 Wprop+W/place -> 11    5 Wprop+F/place -> 12
2870 //  6 Fprop -> 20    7 Fprop+W/place -> 21    8 Fprop+F/place -> 22
2871   if (val == ' ') return 0;
2872   if (val == '1') return 1;
2873   if (val == '2') return 2;
2874   if (val == '3') return 10;
2875   if (val == '4') return 11;
2876   if (val == '5') return 12;
2877   if (val == '6') return 20;
2878   if (val == '7') return 21;
2879   if (val == '8') return 22;
2880   return 0;
2881 }
2882
2883
2884 //=======================================================================
2885 //function : 
2886 //purpose  : 
2887 //=======================================================================
2888
2889 Standard_Integer IFSelect_WorkSession::QueryParent
2890   (const Handle(Standard_Transient)& entdad,
2891    const Handle(Standard_Transient)& entson) const
2892 {
2893   Standard_Integer ndad = StartingNumber(entdad);
2894   Standard_Integer nson = StartingNumber(entson);
2895   if (ndad < 1 || nson < 1) return -1;
2896   if (ndad == nson) return 0;
2897 //  on va calculer : pour chaque pere immediat, de <son>, status avec <dad> + 1
2898 //  nb : pas protege contre les boucles ...
2899   Handle(TColStd_HSequenceOfTransient) list =
2900     thegraph->Graph().Sharings(entson).Content();
2901   if (list.IsNull()) return -1;
2902   Standard_Integer i, nb = list->Length();
2903   for (i = 1; i <= nb; i ++) {
2904     if (list->Value(i) == entdad) return 1;
2905     Standard_Integer stat = QueryParent ( entdad,list->Value(i) );
2906     if (stat >= 0) return stat+1;
2907   }
2908   return -1;  // not yet implemented ...
2909 }
2910
2911 //  ###########################################################################
2912 //  ....      Dumps et Evaluations, pas faciles a passer en arguments      ....
2913
2914 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
2915 //  ....        DumpShare        ....
2916
2917 //=======================================================================
2918 //function : 
2919 //purpose  : 
2920 //=======================================================================
2921
2922 void IFSelect_WorkSession::SetParams
2923   (const TColStd_SequenceOfTransient& params,
2924    const TColStd_SequenceOfInteger&   uselist)
2925 {
2926   Standard_Integer i, nbp = params.Length(), nbu = uselist.Length();
2927   Handle(IFSelect_ParamEditor) editor = new IFSelect_ParamEditor
2928     (nbp+nbu+50,"Parameter Editor");
2929   for (i = 1; i <= nbp; i ++) {
2930     DeclareAndCast(Interface_TypedValue,val,params.Value(i));
2931     if (val.IsNull()) continue;
2932     editor->AddValue(val);
2933   }
2934   AddNamedItem("xst-params-edit",editor);
2935 //  Les EditForm
2936   Handle(IFSelect_EditForm) paramsall = editor->Form(Standard_False);
2937   AddNamedItem("xst-params-all",paramsall);
2938
2939 //  On attaque les EditForms partielles
2940   TColStd_SequenceOfInteger listgen,listload,listsend,listsplit,listread,listwrite;
2941   for (i = 1; i <= nbu; i ++) {
2942     Standard_Integer use = uselist.Value(i);
2943     switch (use) {
2944     case 1 : listgen.Append(i);   break;
2945     case 2 : listread.Append(i);  break;
2946     case 3 : listsend.Append(i);  break;
2947     case 4 : listsplit.Append(i); break;
2948     case 5 : listread.Append(i);  break;
2949     case 6 : listwrite.Append(i); break;
2950     default : break;
2951     }
2952   }
2953   Handle(IFSelect_EditForm) paramsgen  = new IFSelect_EditForm
2954     (editor,listgen ,Standard_False,Standard_True,"General Parameters");
2955   if (listgen.Length() > 0)   AddNamedItem("xst-params-general",paramsgen);
2956   Handle(IFSelect_EditForm) paramsload = new IFSelect_EditForm
2957     (editor,listload,Standard_False,Standard_True,"Loading Parameters");
2958   if (listload.Length() > 0)  AddNamedItem("xst-params-load",  paramsload);
2959   Handle(IFSelect_EditForm) paramssend = new IFSelect_EditForm
2960     (editor,listsend,Standard_False,Standard_True,"Sending Parameters");
2961   if (listsend.Length() > 0)  AddNamedItem("xst-params-send",  paramssend);
2962   Handle(IFSelect_EditForm) paramsplit = new IFSelect_EditForm
2963     (editor,listsplit,Standard_False,Standard_True,"Split Parameters");
2964   if (listsplit.Length() > 0) AddNamedItem("xst-params-split", paramsplit);
2965   Handle(IFSelect_EditForm) paramsread = new IFSelect_EditForm
2966     (editor,listread,Standard_False,Standard_True,"Read(Transfer) Parameters");
2967   if (listread.Length() > 0)  AddNamedItem("xst-params-read",  paramsread);
2968   Handle(IFSelect_EditForm) paramswrite = new IFSelect_EditForm
2969     (editor,listwrite,Standard_False,Standard_True,"Write(Transfer) Parameters");
2970   if (listwrite.Length() > 0) AddNamedItem("xst-params-write", paramswrite);
2971 }
2972
2973
2974 //=======================================================================
2975 //function : 
2976 //purpose  : 
2977 //=======================================================================
2978
2979 void IFSelect_WorkSession::TraceStatics
2980   (const Standard_Integer use, const Standard_Integer mode) const
2981 {
2982   Handle(Message_Messenger) sout = Message::DefaultMessenger();
2983   if (use > 0) {
2984     if (mode == 0)   sout<<"******************************************"<<endl;
2985     if        (use == 1) {
2986       if (mode == 0) sout<<"*****      General  Parameters       *****"<<endl;
2987     } else if (use == 2) {
2988       if (mode == 0) sout<<"*****            Load  File          *****"<<endl;
2989     } else if (use == 3) {
2990       if (mode == 0) sout<<"*****            Write File          *****"<<endl;
2991     } else if (use == 4) {
2992       if (mode == 0) sout<<"*****            Split File          *****"<<endl;
2993     } else if (use == 5) {
2994       if (mode == 0) sout<<"*****        Transfer (Read)         *****"<<endl;
2995     } else if (use == 6) {
2996       if (mode == 0) sout<<"*****        Transfer (Write)        *****"<<endl;
2997     }
2998     if (mode == 0)   sout<<"******************************************"<<endl<<endl;
2999   }
3000
3001 //    Echainements particuliers (use > 0)
3002   if (use == 5) {
3003     TraceStatics (-2,mode);
3004     if (mode == 0) sout<<endl;
3005   } else if (use == 4 || use == 6) {
3006     TraceStatics (-3,mode);
3007     if (mode == 0) sout<<endl;
3008   }
3009
3010 //    Valeurs particulieres
3011   if (use == 1 || use == -1) {  // General : trace
3012     if (mode == 0) {
3013 //      sout << "Trace Level   : "<<Message_PrinterOStream::Default()->GetTraceLevel()<<endl;
3014     }
3015   } else if (use == 4 || use == -4) {  // Split : Prefix & cie
3016     if (mode == 0) {
3017       Handle(TCollection_HAsciiString) str = theshareout->Prefix();
3018       if (!str.IsNull()) sout << "Prefix        : "<<str->ToCString()<<endl;
3019       else sout << "Prefix       not Defined" << endl;
3020       str = theshareout->DefaultRootName();
3021       if (!str.IsNull()) sout << "Default Root  : "<<str->ToCString()<<endl;
3022       else sout << "Default Root not Defined" << endl;
3023       str = theshareout->Extension();
3024       if (!str.IsNull()) sout << "Extension     : "<<str->ToCString()<<endl;
3025       else sout << "Extension    not defined" << endl;
3026     }
3027   }
3028
3029 //  LISTER  LES  STATICS
3030 //  Passer par les ParamEditor ...
3031
3032 //    Fin
3033   if (use > 0) {
3034     if (mode == 0)   sout<<"******************************************"<<endl<<endl;
3035   }
3036 }
3037
3038
3039 //=======================================================================
3040 //function : 
3041 //purpose  : 
3042 //=======================================================================
3043
3044 void IFSelect_WorkSession::DumpShare () const 
3045 {
3046   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3047   sout<<"        **********  Definition ShareOut (Complete)  **********"<<endl;
3048
3049   Handle(TCollection_HAsciiString) str = theshareout->Prefix();
3050   if (!str.IsNull()) sout << "Prefix       : " << str->ToCString() << endl;
3051   else sout << "Prefix       not Defined" << endl;
3052   str = theshareout->DefaultRootName();
3053   if (!str.IsNull()) sout << "Default Root : " << str->ToCString() << endl;
3054   else sout << "Default Root not Defined" << endl;
3055   str = theshareout->Extension();
3056   if (!str.IsNull()) sout << "Extension    : " << str->ToCString() << endl;
3057   else sout << "Extension    not defined" << endl;
3058
3059   Standard_Integer lr = theshareout->LastRun();
3060   Standard_Integer nb = theshareout->NbDispatches();
3061   sout << "Nb Dispatches : " << nb <<" (Last Run : " << lr << ") : "<<endl;
3062   for (Standard_Integer i = 1; i <= nb; i ++) {
3063     Handle(IFSelect_Dispatch) disp = theshareout->Dispatch(i);
3064     sout << "Dispatch n0 " << i;
3065     if (HasName(disp)) sout << "   Name:"<< Name(disp)->ToCString();
3066     sout << "   Label:" << disp->Label() << endl;
3067     Handle(IFSelect_Selection) sel = disp->FinalSelection();
3068     if (sel.IsNull()) sout << "   No Final Selection Defined" << endl;
3069     else if (HasName(sel)) sout << "   Final Selection : Name:"
3070       << Name(sel)->ToCString() << "  Label:" << sel->Label() << endl;
3071     else sout << "   Final Selection : " << sel->Label() << endl;
3072     if (disp->HasRootName())
3073       sout<<"   File Root Name : "<<disp->RootName()->ToCString()<<endl;
3074     else sout<<"   No specific file root name (see Default Root)"<<endl;
3075   }
3076   Standard_Integer nbm = theshareout->NbModifiers(Standard_True);
3077   if (nbm > 0) sout<<
3078     "  ***   "<<nbm<<" active Model Modifiers : see ListModifiers   ***"<<endl;
3079   Standard_Integer nbf = theshareout->NbModifiers(Standard_False);
3080   if (nbf > 0) sout<<
3081     "  ***   "<<nbf<<" active File  Modifiers : see ListModifiers   ***"<<endl;
3082   if (nbm+nbf == 0) sout<<"  ***   No active Modifiers   ***"<<endl;
3083 }
3084
3085 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3086 //  ....        ListItems        ....
3087
3088 //=======================================================================
3089 //function : 
3090 //purpose  : 
3091 //=======================================================================
3092
3093 void IFSelect_WorkSession::ListItems (const Standard_CString lab) const 
3094 {
3095   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3096   sout<< "        **********  Items in Session  **********"<<endl;
3097   Standard_Integer nb = MaxIdent();
3098   Handle(TCollection_HAsciiString) str;
3099   if (lab[0] != '\0') str = new TCollection_HAsciiString (lab);
3100   for (Standard_Integer i = 1; i <= nb; i ++) {
3101     const Handle(Standard_Transient)& var = theitems.FindKey(i);
3102     Handle(TCollection_HAsciiString) label = ItemLabel(i);
3103     if (label.IsNull()) continue;    //  -> item supprime
3104     if (!str.IsNull())  {  if (label->Location(str,1,label->Length()) == 0) continue; }
3105     sout<<"#"<<i;
3106     if (HasName(var)) sout<<"   - Named : "<<Name(var)->ToCString()<<"  - ";
3107     else sout<<" - (no name) - ";
3108     sout<<var->DynamicType()->Name()<<endl<<"    "<<label->ToCString()<<endl;
3109   }
3110 }
3111
3112 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3113 //  ....        ListModifiers
3114
3115 //=======================================================================
3116 //function : 
3117 //purpose  : 
3118 //=======================================================================
3119
3120 void IFSelect_WorkSession::ListFinalModifiers
3121   (const Standard_Boolean formodel) const 
3122 {
3123   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3124   Standard_Integer nb = theshareout->NbModifiers(formodel);
3125   sout<< "        **********  Modifiers in Session ";
3126   sout<<(formodel ? "(For Model)" : "(For File)");
3127   sout<<": "<<nb<<"  **********"<<endl;
3128   for (Standard_Integer i = 1; i <= nb; i ++) {
3129     Handle(IFSelect_GeneralModifier) modif =
3130       theshareout->GeneralModifier(formodel,i);
3131     if (!modif.IsNull()) sout<<"Modifier n0."<<i<<"     : "<<modif->Label();
3132     if (HasName(modif)) sout << "        Named as : " << Name(modif)->ToCString();
3133     sout<<endl;
3134   }
3135 }
3136
3137 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3138 //  ....        DumpSelection        ....
3139
3140 //=======================================================================
3141 //function : 
3142 //purpose  : 
3143 //=======================================================================
3144
3145 void IFSelect_WorkSession::DumpSelection
3146   (const Handle(IFSelect_Selection)& sel) const 
3147 {
3148   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3149   if (ItemIdent(sel) == 0) {
3150     sout << "Selection : "<<" Unknown"<<endl;  //sout<<Handle
3151     return;
3152   }
3153   sout << "        **********  Selection";
3154   if (HasName(sel)) sout << " , Name : " << Name(sel)->ToCString();
3155   sout <<"  **********"<<endl;
3156   sout<< "Label : " << sel->Label() << " . Input(s) : "<< endl;
3157   Standard_Integer nb = 0;
3158   IFSelect_SelectionIterator iter; sel->FillIterator(iter);
3159   for (; iter.More(); iter.Next()) {
3160     nb ++; 
3161     Handle(IFSelect_Selection) newsel = iter.Value();
3162     sout<<" -- "<<newsel->Label()<<endl;
3163   }
3164   sout << " Nb Inputs:"<<nb<<endl;
3165 }
3166
3167
3168 //              ##########################################
3169 //              #########    Fonctions complementaires
3170 //              ##########################################
3171
3172 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3173 //  ....        DumpModel        ....
3174
3175 //=======================================================================
3176 //function : 
3177 //purpose  : 
3178 //=======================================================================
3179
3180 Handle(IFSelect_Selection) IFSelect_WorkSession::GiveSelection
3181   (const Standard_CString selname) const
3182 {
3183   char nomsel[500];
3184   Standard_Integer np = -1, nf = -1, nivp = 0;
3185   for (Standard_Integer n = 0; selname[n] != '\0'; n ++) {
3186     nomsel[n] = selname[n];  nomsel[n+1] = '\0';
3187     if (selname[n] == '(') { np = n; nivp ++; }
3188     if (selname[n] == ')') { nivp --;  if (nivp <= 0) nf = n; }
3189 ////    if (selname[n] == ' ') { nb = n; break; }
3190   }
3191
3192   Handle(IFSelect_Selection) sel;
3193   if (np >= 0) nomsel[np] = 0;  if (nf >= 0) nomsel[nf] = '\0';
3194   Handle(Standard_Transient) item = NamedItem(nomsel);
3195
3196 //  Parentheses ? essayer Signature (plus tard : Selection parametree)
3197 //  NB : on compte les niveaux de parentheses (imbrications repercutees)
3198   if (np > 0 && nf > 0) {
3199     Handle(IFSelect_SelectSignature) selsign;
3200     Standard_Integer debsign = np+1;
3201
3202     DeclareAndCast(IFSelect_Signature,sign,item);
3203     DeclareAndCast(IFSelect_SignCounter,cnt,item);
3204     if (!sign.IsNull()) selsign =
3205       new IFSelect_SelectSignature (sign,&nomsel[debsign],Standard_False);
3206     else if (!cnt.IsNull()) selsign =
3207       new IFSelect_SelectSignature (cnt,&nomsel[debsign],Standard_False);
3208     else {
3209       cout<<selname<<" : neither Signature nor Counter"<<endl;
3210       return sel;
3211     }
3212
3213     selsign->SetInput (new IFSelect_SelectModelEntities);  // par defaut
3214     sel = selsign;
3215   }
3216
3217   else sel = GetCasted(IFSelect_Selection,item);
3218
3219   return sel;
3220 }
3221
3222
3223 //=======================================================================
3224 //function : 
3225 //purpose  : 
3226 //=======================================================================
3227
3228 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::GiveList
3229   (const Handle(Standard_Transient)& obj) const
3230 {
3231 //   Deja une liste
3232   DeclareAndCast(TColStd_HSequenceOfTransient,list,obj);
3233   if (!list.IsNull()) return list;
3234
3235 //   Rien du tout : retourne rien du tout
3236   if (obj.IsNull()) return list;
3237
3238 //   Une selection : son resultat (standard)
3239   DeclareAndCast(IFSelect_Selection,sel,obj);
3240   if (!sel.IsNull()) {
3241     Interface_EntityIterator iter = EvalSelection(sel);
3242     return iter.Content();
3243   }
3244
3245 //   Le modele : son contenu
3246   list = new TColStd_HSequenceOfTransient();
3247   if (obj == themodel) {
3248     Standard_Integer i, nb = themodel->NbEntities();
3249     for (i = 1; i <= nb; i ++)  list->Append (themodel->Value(i));
3250   }
3251
3252 //   Une entite du modele : cette entite
3253   else if (StartingNumber(obj) > 0) list->Append (obj);
3254
3255 //   Un Texte : son interpretation
3256   else {
3257     DeclareAndCast(TCollection_HAsciiString,str,obj);
3258     if (!str.IsNull()) return GiveList (str->ToCString());
3259   }
3260
3261 //  Si c est pas tout ca : une liste vide
3262   return list;
3263 }
3264
3265
3266 //=======================================================================
3267 //function : 
3268 //purpose  : 
3269 //=======================================================================
3270
3271 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::GiveList
3272   (const Standard_CString first, const Standard_CString second) const
3273 {
3274   Handle(TColStd_HSequenceOfTransient) list; 
3275   if (!first || first[0] == '\0') return list;
3276   if (first[0]  == ' ') return GiveList (&first[1],second);
3277   if (second && second[0] == ' ') return GiveList (first,&second[1]);
3278
3279 //   list NULLE sera interpretee comme SelectionResult (selection toute crue)
3280 //   sinon comme SelectionResultFromList
3281   if (second && second[0] != '\0') list = GiveList (second,"");
3282
3283   list = GiveListFromList (first,list);
3284   return list;
3285 }
3286
3287
3288 //=======================================================================
3289 //function : 
3290 //purpose  : 
3291 //=======================================================================
3292
3293 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::GiveListFromList
3294   (const Standard_CString selname, const Handle(Standard_Transient)& ent) const
3295 {
3296   Handle(TColStd_HSequenceOfTransient) list;
3297   Standard_Integer num;
3298
3299 //   LISTE DEFINIE D OFFICE (en ce cas, la liste d entree est ignoree)
3300   if (selname[0] == '(') {
3301 //  liste d entites donnees a la queue leu leu : (ID,ID,ID...)
3302     char entid[50];     Standard_Integer i,j = 0;
3303     TColStd_MapOfInteger numap;
3304     list = new TColStd_HSequenceOfTransient();
3305     for (i = 1; selname[i] != '\0'; i ++) {
3306       if (selname[i] == ' ') continue;
3307       if (selname[i] == ',' || selname[i] == ')') {
3308         entid[j] = '\0';
3309         if (j == 0) continue;  j = 0;
3310         num = NumberFromLabel (entid);
3311         if (num <= 0 || !numap.Add (num)) continue;
3312         Handle(Standard_Transient) anent = StartingEntity(num);
3313         if (!anent.IsNull()) list->Append (anent);
3314         if (selname[i] == ')') break;
3315         continue;
3316       }
3317       entid[j] = selname[i];  j ++;
3318     }
3319     return list;
3320   }
3321   num = NumberFromLabel (selname);
3322   if (num > 0)  return GiveList(StartingEntity(num));
3323
3324 //  Autres cas : y atil une liste d entree.
3325 //   Si OUI -> SelectionResultFromList.  Si NON -> SelectionResult
3326 //   Si une entite isolee -> on en fait une liste
3327
3328   list = GiveList(ent);  // ent NULL -> list NULL sinon intreprete
3329
3330 //    Decomposition term1 term2 ...
3331
3332   char nomsel[500];  nomsel[0] = '\0';
3333   Standard_Integer n= 0 , nb = -1;
3334   for (n = 0; selname[n] != '\0'; n ++) {
3335     nomsel[n] = selname[n];  nomsel[n+1] = '\0';
3336 //    if (selname[n] == '(') { np = n; nivp ++; }
3337 //    if (selname[n] == ')') { nivp --;  if (nivp <= 0) nf = n; }
3338     if (selname[n] == ' ') { nb = n; nomsel[n] = '\0'; break; }
3339   }
3340   if (nomsel[0] == '\0') return list;
3341
3342   Handle(IFSelect_Selection) sel = GiveSelection (nomsel);
3343   if (sel.IsNull())  {
3344     cout<<"Neither Entity Number/Label nor Selection :"<<nomsel<<endl;
3345     return list;
3346   }
3347
3348   if (nb > 0) list = GiveListFromList (&selname[nb+1],list);
3349
3350   if (list.IsNull()) list = SelectionResult (sel);
3351   else               list = SelectionResultFromList (sel,list);
3352
3353   return list;
3354 }
3355
3356
3357 //=======================================================================
3358 //function : 
3359 //purpose  : 
3360 //=======================================================================
3361
3362 Handle(TColStd_HSequenceOfTransient) IFSelect_WorkSession::GiveListCombined
3363   (const Handle(TColStd_HSequenceOfTransient)& l1,
3364    const Handle(TColStd_HSequenceOfTransient)& l2,
3365    const Standard_Integer mode) const
3366 {
3367   Handle(TColStd_HSequenceOfTransient) list;
3368   if (l1.IsNull() || l2.IsNull()) return list;
3369
3370 //  mode < 0 l1-l2  = 0 l1&l2  > 0 l1|l2 (l1+l2)
3371   TColStd_MapOfTransient numap;
3372   Standard_Integer i,n = l2->Length();
3373   for (i = n; i > 0; i --)  {
3374     Handle(Standard_Transient) ent = l2->Value(i);
3375     if (ent.IsNull()) continue;
3376     numap.Add (ent);
3377     if (mode > 0) list->Append(ent);
3378   }
3379
3380 //  ents de l1 pas deja dans l2
3381   n = l1->Length();
3382   for (i = n; i > 0; i --) {
3383     Handle(Standard_Transient) ent = l1->Value(i);
3384     if (ent.IsNull()) continue;
3385
3386     if (numap.Contains(ent)) {
3387 //    dans l1 et dans l2
3388       if (mode == 0) list->Append(ent);
3389     } else {
3390 //    dans l1 mais pas dans l2
3391       if (mode != 0) list->Append(ent);
3392     }
3393   }
3394
3395   list->Reverse();
3396   return list;
3397 }
3398
3399
3400 //=======================================================================
3401 //function : 
3402 //purpose  : 
3403 //=======================================================================
3404
3405 void IFSelect_WorkSession::DumpModel
3406   (const Standard_Integer level, const Handle(Message_Messenger)& S)
3407 {
3408   if (!IsLoaded())
3409     {  S<< " ***  Data for List not available  ***"<<endl;  return;  }
3410   S << "\n        *****************************************************************\n";
3411   if (theloaded.Length() > 0)
3412     S << "        ********  Loaded File : "<<theloaded.ToCString()<<Interface_MSG::Blanks(32-theloaded.Length())<<" ********"<<endl;
3413   else S << "        ********  No name for Loaded File"<<endl;
3414   if (level == 0) {
3415     S<<"        ********  Short Dump of Header                           ********"<<"\n";
3416   S << "        *****************************************************************\n\n";
3417     themodel->DumpHeader(S);  S<<endl;
3418   }
3419
3420   Standard_Integer nbent = themodel->NbEntities();
3421   Standard_Integer nbr = 0;
3422   Interface_ShareFlags shar(thegraph->Graph());
3423
3424   for (Standard_Integer i = 1; i <= nbent; i ++) {
3425     if (!shar.IsShared(themodel->Value(i))) nbr ++;
3426   }
3427   S << "        *****************************************************************\n";
3428   S << "        ********  Model : "<<nbent<<" Entities, of which "<<nbr<<" Root(s)"<<"\n";
3429   S << "        *****************************************************************\n"<<endl;
3430
3431   if (level <= 0) return;
3432   else if (level == 1) {
3433     S<<"        ********  Root Entities  ********      ";
3434     ListEntities (shar.RootEntities(),1);
3435   } else if (level == 2) {
3436     S<<"        ********  Complete List  ********      ";
3437     ListEntities (themodel->Entities(),1);
3438   } else if (level > 2) {
3439     IFSelect_PrintCount mode = IFSelect_ItemsByEntity;
3440     if (level == 5 || level ==  8) mode = IFSelect_CountByItem;
3441     if (level == 6 || level ==  9) mode = IFSelect_ListByItem;
3442     if (level == 7 || level == 10) mode = IFSelect_EntitiesByItem;
3443     PrintCheckList (ModelCheckList(),Standard_False, mode);
3444   } else {
3445     if (level == 3) S << "        ********  Check Model (Fails)  ********"<<endl;
3446     else            S << "        ********  Check Model (Complete)  ********"<<endl;
3447     Interface_CheckTool CT (Graph());
3448     Interface_CheckIterator C;
3449     if (theerrhand) {
3450       try {
3451         OCC_CATCH_SIGNALS
3452         if (level == 3) C = CT.CheckList();
3453         else    C = CT.CompleteCheckList();
3454       }
3455       catch (Standard_Failure) {
3456         Handle(Message_Messenger) sout = Message::DefaultMessenger();
3457         sout<<"    ****    Interruption DumpModel (Check) par Exception    ****\n";
3458         S<<"  ** **  Exception Raised during Check !  ** **\n";
3459         S<<"  -->  what could be determined is listed"<<endl;
3460       }
3461     }
3462     else if (level == 3) C = CT.CheckList();
3463     else         C = CT.CompleteCheckList();
3464
3465 //  Check List : si vide (pas demandee), naturellement passee
3466     try {
3467       OCC_CATCH_SIGNALS
3468       C.Print(S,themodel, (level == 3));
3469     }
3470     catch (Standard_Failure) {
3471       Handle(Message_Messenger) sout = Message::DefaultMessenger();
3472       sout<<"    ****    Interruption DumpModel par Exception :   ****\n";
3473       sout<<Standard_Failure::Caught()->GetMessageString();
3474       sout<<"\n    Abandon"<<endl;
3475     }
3476
3477   }
3478   S<<endl<<"There are "<<nbent<<" Entities, of which "<<nbr<<" Root(s)"<<endl;
3479 }
3480
3481 //  ....        TraceDumpModel        ....  (Model + CheckList)
3482
3483 //=======================================================================
3484 //function : 
3485 //purpose  : 
3486 //=======================================================================
3487
3488 void IFSelect_WorkSession::TraceDumpModel
3489   (const Standard_Integer mode)
3490 {
3491   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3492   DumpModel (mode,sout);
3493 //  if      (mode <= 4)  {  DumpModel (mode,sout);  return;  }
3494
3495 //  else if (mode <= 7) PrintCheckList (ModelCheckList(),Standard_False, mode-5);
3496 //  else if (mode <=10) PrintCheckList (ModelCheckList(),Standard_True , mode-8);
3497 }
3498
3499 //  ....        DumpEntity        ....
3500
3501 //=======================================================================
3502 //function : 
3503 //purpose  : 
3504 //=======================================================================
3505
3506 void IFSelect_WorkSession::DumpEntity
3507   (const Handle(Standard_Transient)& ent, const Standard_Integer level,
3508    const Handle(Message_Messenger)& S) const
3509 {
3510   if (!IsLoaded())
3511     {  S<< " ***  Data for List not available  ***"<<endl;  return;  }
3512   Standard_Integer num = themodel->Number(ent);
3513   if (num == 0) { S<<" ***  Entity to Dump not in the Model  ***"<<endl; return; }
3514   if (thelibrary.IsNull()) { S<<" ***  WorkLibrary not defined  ***"<<endl; return; }
3515   S << "        ********  Dumping Entity n0 "<<num
3516     <<" level:"<<level<<"  ********"<<endl;
3517   thelibrary->DumpEntity (themodel,theprotocol,ent,S,level);
3518 }
3519
3520 //  ....        DumpEntity        ....
3521
3522 //=======================================================================
3523 //function : 
3524 //purpose  : 
3525 //=======================================================================
3526
3527 void IFSelect_WorkSession::TraceDumpEntity
3528   (const Handle(Standard_Transient)& ent, const Standard_Integer level) const
3529 {
3530   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3531   DumpEntity (ent,level,sout);
3532 }
3533
3534 //  ....        PrintEntityStatus        ....
3535
3536 //=======================================================================
3537 //function : 
3538 //purpose  : 
3539 //=======================================================================
3540
3541 void IFSelect_WorkSession::PrintEntityStatus
3542   (const Handle(Standard_Transient)& ent, const Handle(Message_Messenger)& S)
3543 {
3544   Standard_Integer i,nb;
3545   Standard_Integer num = StartingNumber(ent);
3546   if (num == 0)  {  cout<<" --  PrintEntityStatus : unknown"<<endl;  return;  }
3547
3548   S <<"  Ent. n0/id:   ";
3549   Model()->Print(ent,S);
3550   Handle(TCollection_HAsciiString) hname = EntityName(ent);
3551   if (!hname.IsNull() && hname->Length() > 0) S<<"      Name:"<<hname->ToCString();
3552   S<<endl;
3553   Handle(IFSelect_Signature) signtype = SignType();
3554   if (signtype.IsNull()) S<<"  Type(CDL):"<<ent->DynamicType()->Name()<<endl;
3555   else S <<"  Type:"<<signtype->Value (ent,Model())<<endl;
3556   S <<"    Category : " <<CategoryName (ent)
3557     <<"    Validity : " <<ValidityName (ent) << endl;
3558   Interface_CheckIterator chl = CheckOne (ent);
3559   chl.Print (S,Model(),Standard_False,Standard_False);
3560
3561   Handle(TColStd_HSequenceOfTransient) list = Sharings(ent);
3562   if (list.IsNull()) S<<"  Root"<<endl;
3563   else {
3564     nb = list->Length();
3565     if (nb == 0) S<<"  Root";
3566     else S<<"  Super-entities:"<<nb<<" : (n0/id):";
3567     for (i = 1; i <= nb; i ++)  {  S<<" "; Model()->Print(list->Value(i),S);  }
3568     S<<endl;
3569   }
3570   list = Shareds (ent);
3571   if (list.IsNull()) S<<"  No sub-entity"<<endl;
3572   else {
3573     nb = list->Length();
3574     if (nb == 0) S<<"  No sub-entity";
3575     else S<<"  Sub-entities:"<<nb<<" , i.e. (n0/id):";
3576     for (i = 1; i <= nb; i ++)  {  S<<" "; Model()->Print(list->Value(i),S);  }
3577     S<<endl;
3578   }
3579 }
3580
3581 //  ....        PrintCheckList        ....
3582
3583 //=======================================================================
3584 //function : 
3585 //purpose  : 
3586 //=======================================================================
3587
3588 void IFSelect_WorkSession::PrintCheckList
3589   (const Interface_CheckIterator& checklist,
3590    const Standard_Boolean failsonly, const IFSelect_PrintCount mode) const
3591 {
3592 //  mode : 0  comptage   1 n0s entites   2 n0s+id ents
3593   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3594   if (mode == IFSelect_ItemsByEntity) checklist.Print (sout,themodel,failsonly);
3595   else {
3596     Interface_CheckIterator chks = checklist;
3597     Handle(IFSelect_CheckCounter) counter =
3598       new IFSelect_CheckCounter (mode>1 && mode != IFSelect_CountSummary);
3599     counter->Analyse (chks,themodel,Standard_True,failsonly);
3600     counter->PrintList  (sout,themodel,mode);
3601   }
3602 }
3603
3604 //  ....        PrintSignatureList        ....
3605
3606 //=======================================================================
3607 //function : 
3608 //purpose  : 
3609 //=======================================================================
3610
3611 void IFSelect_WorkSession::PrintSignatureList
3612   (const Handle(IFSelect_SignatureList)& signlist,
3613    const IFSelect_PrintCount mode) const
3614 {
3615   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3616   if (signlist.IsNull()) return;
3617   signlist->PrintList (sout,themodel,mode);
3618 }
3619
3620 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3621 //  ....        EvaluateSelection        ....
3622
3623 //=======================================================================
3624 //function : 
3625 //purpose  : 
3626 //=======================================================================
3627
3628 void IFSelect_WorkSession::EvaluateSelection
3629   (const Handle(IFSelect_Selection)& sel) const 
3630 {
3631   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3632   if (errhand) {
3633     errhand = Standard_False;
3634     try {
3635       OCC_CATCH_SIGNALS
3636       EvaluateSelection(sel);    // appel normal (->code unique)
3637     }
3638     catch (Standard_Failure) {
3639       sout<<"    ****    Interruption EvaluateSelection par Exception    ****  Intitule\n";
3640       sout<<Standard_Failure::Caught()->GetMessageString();
3641       sout<<"\n    Abandon"<<endl;
3642     }
3643     errhand = theerrhand;
3644     return;
3645   }
3646
3647   if (!IsLoaded())
3648     {  sout<< " ***  Data for Evaluation not available  ***"<<endl;  return;  }
3649   if (ItemIdent(sel) == 0)
3650     {  sout << " Selection : "<<" Unknown"<<endl;  return;  }  //sout<<Handle
3651   Interface_EntityIterator iter = EvalSelection (sel);
3652   ListEntities (iter,1);
3653   sout << "****  (Unique) RootResult, Selection         : "
3654     <<sel->Label()<<endl;
3655 }
3656
3657
3658 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3659 //  ....        EvaluateDispatch        ....
3660
3661 //=======================================================================
3662 //function : 
3663 //purpose  : 
3664 //=======================================================================
3665
3666 void IFSelect_WorkSession::EvaluateDispatch
3667   (const Handle(IFSelect_Dispatch)& disp, const Standard_Integer mode) const 
3668 {
3669   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3670   if (errhand) {
3671     errhand = Standard_False;
3672     try {
3673       OCC_CATCH_SIGNALS
3674       EvaluateDispatch(disp,mode);    // appel normal (->code unique)
3675     }
3676     catch (Standard_Failure) {
3677       sout<<"    ****    Interruption EvaluateDispatch par Exception    ****  Intitule\n";
3678       sout<<Standard_Failure::Caught()->GetMessageString();
3679       sout<<"\n    Abandon"<<endl;
3680     }
3681     errhand = theerrhand;
3682     return;
3683   }
3684
3685   Standard_Integer numdisp = DispatchRank(disp);
3686   if (!IsLoaded())
3687     {  sout<< " ***  Data for List not available  ***"<<endl;  return;  }
3688   if (theshareout->NbDispatches() < numdisp || numdisp <= 0)
3689     { sout<<"Dispatch : "<<" Unknown"<<endl; return; } //sout<<Handle
3690   if (disp->FinalSelection().IsNull())
3691     { sout<<"Dispatch "<<" : No Final Selection"<<endl; return; }//sout<<Handle
3692   sout<<" --- Dispatch Label : "<<disp->Label()<<endl; 
3693
3694   IFSelect_ShareOutResult eval(disp,thegraph->Graph());
3695   eval.Evaluate();
3696   Standard_Integer numpack = 0;
3697   Handle(IFSelect_PacketList) evres =
3698     eval.Packets (mode ? Standard_True : Standard_False);
3699   Standard_Integer nbpack = evres->NbPackets();
3700
3701   sout<<"Nb Packets produced : "<<nbpack<<" :"<<endl;
3702   for (numpack = 1; numpack <= nbpack; numpack ++) {
3703     sout<<"\n    ****    Packet n0 : "<<numpack<<" ****"<<endl;
3704     if (!mode) cout<<"Root Entities :"<<endl;
3705     ListEntities (evres->Entities(numpack), (mode ? 2 : -1));
3706   }
3707
3708 ////  Interface_EntityIterator iterem = disp->Remainder(thegraph->Graph());
3709   if (mode == 0) return;
3710   if (mode == 1 || mode == 3) {
3711     sout<<endl;
3712     if (evres->NbDuplicated(0,Standard_False) == 0)
3713       sout<<"    ****    All the Model is taken into account    ****"<<endl;
3714     else {
3715       sout<<"    ****    Starting Entities not taken by this Dispatch    ****"<<endl;
3716       ListEntities (evres->Duplicated(0,Standard_False),2);
3717     }
3718   }
3719   if (mode >= 2) {
3720     sout<<"    ****    Entites in more than one packet    ****";
3721     Standard_Integer max = evres->HighestDuplicationCount();
3722     if (max < 2) sout<<" :   There are none"<<endl;
3723     else {
3724       Standard_Integer newcount;
3725       sout<<endl;
3726       for (newcount = 2; newcount <= max; newcount ++) {
3727         if (evres->NbDuplicated(newcount,Standard_False) == 0) continue;
3728         sout<<"    ****   Entities put in "<<newcount<<" packets    ****"<<endl;
3729         ListEntities (evres->Duplicated(newcount,Standard_False),2);
3730       }
3731     }
3732   }
3733 }
3734
3735
3736 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3737 //  ....        EvaluateComplete        ....
3738
3739 //=======================================================================
3740 //function : 
3741 //purpose  : 
3742 //=======================================================================
3743
3744 void IFSelect_WorkSession::EvaluateComplete
3745   (const Standard_Integer mode) const 
3746 {
3747   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3748   if (errhand) {
3749     errhand = Standard_False;
3750     try {
3751       OCC_CATCH_SIGNALS
3752       EvaluateComplete(mode);    // appel normal (donc, code pas duplique)
3753     }
3754     catch (Standard_Failure) {
3755       sout<<"    ****    Interruption EvaluateComplete par Exception :   ****\n";
3756       sout<<Standard_Failure::Caught()->GetMessageString();
3757       sout<<"\n    Abandon"<<endl;
3758     }
3759     errhand = theerrhand;
3760     return;
3761   }
3762
3763   if (!IsLoaded())
3764     {  sout<< " ***  Data for List not available  ***"<<endl;  return;  }
3765   IFSelect_ShareOutResult eval(theshareout,thegraph->Graph());
3766   eval.Evaluate();
3767   sout<<"\n********    Evaluation ShareOutResult (Complete)    ********\n";
3768   sout<<"    ****    List of Packets    ****  Count : "<<eval.NbPackets()<<endl;
3769   if (mode == 0) sout << " ** (for each one : Root Entities)  **"<<endl;
3770   else sout << " ** (for each one : Evaluated Content)  **"<<endl;
3771
3772   Standard_Integer numpack = 0;
3773   Handle(IFSelect_PacketList) evres =
3774     eval.Packets (mode ? Standard_True : Standard_False);
3775   Standard_Integer nbpack = evres->NbPackets();
3776
3777   sout<<"Nb Packets produced : "<<nbpack<<" :"<<endl;
3778   for (numpack = 1; numpack <= nbpack; numpack ++) {
3779     sout<<"\n    ****    Packet n0 : "<<numpack<<" ****"<<endl;
3780     if (!mode) cout<<"Root Entities :"<<endl;
3781     ListEntities (evres->Entities(numpack), (mode ? 2: -1));
3782   }
3783   if (mode == 0) return;
3784   if (mode == 1 || mode == 3) {
3785     sout<<endl;
3786     if (evres->NbDuplicated(0,Standard_False) == 0)
3787       sout<<"    ****    All the Model is taken into account    ****"<<endl;
3788     else {
3789       sout<<"    ****    Starting Entities Forgotten    ****"<<endl;
3790       ListEntities (evres->Duplicated(0,Standard_False),2);
3791     }
3792   }
3793   if (mode >= 2) {
3794     sout<<"    ****    Entites in more than one packet    ****"<<endl;
3795     Standard_Integer max = evres->HighestDuplicationCount();
3796     if (max < 2) sout<<" :   There are none"<<endl;
3797     else {
3798       Standard_Integer newcount;
3799       sout<<endl;
3800       for (newcount = 2; newcount <= max; newcount ++) {
3801         if (evres->NbDuplicated(newcount,Standard_False) == 0) continue;
3802         sout<<"    ****   Entities put in "<<newcount<<" packets    ****"<<endl;
3803         ListEntities (evres->Duplicated(newcount,Standard_False),2);
3804       }
3805     }
3806   }
3807 }
3808
3809
3810 //  ####    ####    ####    ####    ####    ####    ####    ####    ####
3811 //  ....      Routine Interne : ListEntities
3812
3813 //=======================================================================
3814 //function : 
3815 //purpose  : 
3816 //=======================================================================
3817
3818 void IFSelect_WorkSession::ListEntities
3819   (const Interface_EntityIterator& iter, const Standard_Integer mmode) const 
3820 {
3821   Handle(Message_Messenger) sout = Message::DefaultMessenger();
3822   int titre = 0;
3823   Standard_Integer mode = (mmode < 0 ? -mmode : mmode);
3824   if (mmode >= 0) sout << " List of " << iter.NbEntities() << " Entities :"<<endl;
3825   if (!IsLoaded())
3826     {  sout<< " ***  Data for List not available  ***"<<endl;  return;  }
3827   Interface_ShareFlags tool(thegraph->Graph());
3828
3829   try {
3830     OCC_CATCH_SIGNALS
3831     int newcount = -1; int mods = 0; int cnt = 0;
3832     for (iter.Start(); iter.More(); iter.Next()) {
3833       if (!titre && mode == 1) sout
3834         << "Number/Id.           Category Validity    Type\n-----------          ----...."<<endl;
3835 //          123456789 123456789 123456  123456789 123456789 123456
3836       if (!titre && mode == 0) sout<<"  Keys : R Root   ? Unknown   * Unloaded"<<endl;
3837       if (!titre && mode == 2) sout<<"(";
3838       titre = 1;
3839       Handle(Standard_Transient) ent = iter.Value();
3840       Standard_Integer num = themodel->Number(ent);
3841       if (mode == 1) {
3842 // n0 id (root?) category validity tracetype
3843         sout<<Interface_MSG::Blanks (num,6);
3844         themodel->Print(ent,sout,0);
3845         if (!tool.IsShared(ent)) sout << " #ROOT#";
3846         else                     sout << "       ";
3847         Standard_Integer catnum = themodel->CategoryNumber(num);
3848         if (catnum > 0) sout<<"  "<<Interface_Category::Name (catnum);
3849         sout << "  (" << ValidityName (ent) << ")  ";
3850
3851         sout<<" Type:"<<themodel->TypeName (ent, Standard_False);
3852 //      Handle(Interface_GeneralModule) tracemod;
3853 //      Standard_Integer CN;
3854 //      if (thegtool->Select(ent,tracemod,CN))tracemod->TraceType(ent,CN,sout);
3855 //      else sout << "(Not in Protocol) " << ent->DynamicType();
3856         sout << endl;
3857       } else if (mode == 2) {
3858         newcount ++;
3859         if (newcount > 0) sout<<",";
3860         sout<<num;
3861       } else {
3862         newcount ++;  mods = 0; cnt ++;
3863         if      (newcount >= 10) { sout << endl<<"["<<cnt<<"]:"; newcount = 1; }
3864         if (newcount > 0)  sout << "    ";
3865         themodel->Print(ent,sout,0);
3866         if (!tool.IsShared(ent)) { if(mods == 0) sout<<"("; sout<<"R"; mods++; }
3867         if (themodel->IsUnknownEntity(num)) { sout<<(mods==0 ? '(' : ' ')<<"?"; mods ++; }
3868         if (themodel->IsRedefinedContent(num)) { sout<<(mods==0 ? '(' : ' ')<<"*"; mods ++; }
3869         if (mods) { sout<<")"; newcount ++; }
3870       }
3871     }
3872     if (mode == 0) sout<<endl;
3873     if (mode == 2) sout<<")"<<endl;
3874   }
3875   catch (Standard_Failure) {
3876     sout<<"    ****    Interruption ListEntities par Exception :   ****\n";
3877     sout<<Standard_Failure::Caught()->GetMessageString();
3878     sout<<"\n    Abandon"<<endl;
3879   }
3880 }
3881
3882 void IFSelect_WorkSession::SetModeStat( Standard_Boolean theStatMode)
3883 {
3884   themodelstat = theStatMode;
3885 }
3886
3887 Standard_Boolean IFSelect_WorkSession::GetModeStat() const
3888 {
3889   return themodelstat;
3890 }