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