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