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