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