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