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