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