e367b6cd67b200ab4b71dbf7480a8a2ad62130c3
[occt.git] / src / Transfer / Transfer_TransferProcess.gxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 // DCE 21.01.99 S3767 Display original messages only 
15 //       if the level is greater than 2
16
17 //#include <Transfer_TransferProcess.ixx>
18 //  Class generique
19
20 //  TheStart est suppose Handle(Standard_Transient) ou (Transfer_Finder)
21 //  Il doit offrir : "==" , .IsNull() , ->DynamicType()
22
23 #include <Standard_ErrorHandler.hxx>
24 #include <Standard_Failure.hxx>
25
26 #include <Message_Messenger.hxx>
27 #include <Message_Msg.hxx>
28 #include <Message.hxx>
29
30 #include <Transfer_VoidBinder.hxx>
31 #include <Transfer_SimpleBinderOfTransient.hxx>
32 #include <Transfer_MultipleBinder.hxx>
33 #include <Transfer_StatusResult.hxx>
34 #include <Transfer_TransferFailure.hxx>
35 #include <Transfer_TransferDeadLoop.hxx>
36
37 #include <TCollection_HAsciiString.hxx>
38 #include <Dico_DictionaryOfTransient.hxx>
39 #include <Dico_IteratorOfDictionaryOfTransient.hxx>
40 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
41 #include <TColStd_Array1OfInteger.hxx>
42 #include <TColStd_HArray1OfInteger.hxx>
43
44
45 //#define TRANSLOG   // debug
46
47 static Handle(Standard_Transient)  nultrans;   // pour retour const&(Null) ...
48 static Handle(Transfer_Binder)     nulbinder;
49
50
51 //=======================================================================
52 //function : Transfer_TransferProcess
53 //purpose  : 
54 //=======================================================================
55
56 Transfer_TransferProcess::Transfer_TransferProcess (const Standard_Integer nb)
57       : themap (nb)
58 {
59   theerrh  = Standard_True;
60   therootm = Standard_False;
61   thelevel = 0;     therootl  = 0;
62   themessenger = Message::DefaultMessenger();
63   thetrace = 0;
64 //  theroots = new TColStd_HSequenceOfInteger ();
65   theindex = 0;
66 }
67
68
69 //=======================================================================
70 //function : Transfer_TransferProcess
71 //purpose  : 
72 //=======================================================================
73
74 Transfer_TransferProcess::Transfer_TransferProcess(const Handle(Message_Messenger)& messenger,
75                                                    const Standard_Integer nb)
76      : themap (nb)
77 {
78   theerrh  = Standard_True;
79   therootm = Standard_False;
80   thelevel = 0;     therootl  = 0;
81   SetMessenger (messenger);
82   thetrace = 1;
83 //  theroots = new TColStd_HSequenceOfInteger ();
84   theindex = 0;
85 }
86
87     void Transfer_TransferProcess::Clear ()
88 {
89   thelevel = 0;     therootl  = 0;
90   theroots.Clear();
91   themap.Clear();
92   theindex = 0;  thelastobj.Nullify();  thelastbnd.Nullify();
93 }
94
95     void Transfer_TransferProcess::Clean ()
96 {
97   Standard_Integer i, nb = NbMapped();
98   Standard_Integer j,unb = 0;
99   for (i = 1; i <= nb; i ++) {
100     if (themap(i).IsNull()) unb ++;
101   }
102   if (unb == 0) return;
103
104 //   Refaire la map -> decalages
105   TColStd_Array1OfInteger unbs (1,nb);  unbs.Init(0);
106   Transfer_TransferMap newmap (nb*2);
107   for (i = 1; i <= nb; i ++) {
108     TheStart ent = Mapped(i);
109     Handle(Transfer_Binder) bnd = MapItem(i);
110     if (bnd.IsNull()) continue;
111     j = newmap.Add (ent,bnd);
112     unbs.SetValue (i,j);
113   }
114   themap.Assign (newmap);
115
116   // Update   La liste des racines
117   TColStd_IndexedMapOfInteger aNewRoots;
118   for( i=1; i<= theroots.Extent(); i++ ) {
119     j = theroots.FindKey(i);
120     Standard_Integer k = unbs.Value(j);
121     if ( k ) aNewRoots.Add ( k );
122   }
123   theroots.Clear();
124   theroots = aNewRoots;
125
126 //    Le reste : nettoyage
127   thelastobj.Nullify();
128   thelastbnd.Nullify();
129   theindex = 0;
130 }
131
132
133 //=======================================================================
134 //function : Resize
135 //purpose  : 
136 //=======================================================================
137
138 void Transfer_TransferProcess::Resize (const Standard_Integer nb)
139 {
140   if (nb > themap.NbBuckets()) themap.ReSize(nb);
141 }
142
143
144 //=======================================================================
145 //function : SetActor
146 //purpose  : 
147 //=======================================================================
148
149 void  Transfer_TransferProcess::SetActor(const Handle(Transfer_Actor)& actor)
150 {
151   if (theactor == actor)         return;
152   if (theactor.IsNull())         theactor = actor;
153   else if (actor.IsNull())       theactor = actor;  // declenche RAZ
154   else if (theactor->IsLast()) { actor->SetNext(theactor);  theactor = actor; }
155   else                           theactor->SetNext(actor);
156 }
157
158
159 //=======================================================================
160 //function : Actor
161 //purpose  : 
162 //=======================================================================
163
164 Handle(Transfer_Actor)  Transfer_TransferProcess::Actor () const 
165 {
166   return theactor;
167 }
168
169
170 //  ########################################################################
171 //  ....                             MAPPING                            ....
172
173 //  ##    ##    ##       Actions Generales sur Binders       ##    ##    ##
174 //  ##    ##    ##               Consultations               ##    ##    ##
175
176
177 //        ##    ##    Find    ##    ##
178
179 //=======================================================================
180 //function : Find
181 //purpose  : 
182 //=======================================================================
183
184 Handle(Transfer_Binder) Transfer_TransferProcess::Find (const TheStart& start) const
185 //                                                       const Standard_Integer categ) const
186 {
187   if (thelastobj == start) {
188     //if (theindex > 0) return thelastbnd->Search(categ); //skl
189     if (theindex > 0) return thelastbnd; //skl
190   }
191   Standard_Integer index = themap.FindIndex (start);
192   if (index > 0) {
193     const Handle(Transfer_Binder)& binder = themap.FindFromIndex(index);
194     //if (binder.IsNull()) //skl
195     return binder;
196     //return binder->Search(categ); //skl
197   }
198   return nulbinder;
199 }
200
201 //        ##    ##    IsBound    ##    ##
202
203 //=======================================================================
204 //function : IsBound
205 //purpose  : 
206 //=======================================================================
207
208 Standard_Boolean  Transfer_TransferProcess::IsBound(const TheStart& start) const
209 //                                                  const Standard_Integer categ) const
210 {
211   Handle(Transfer_Binder) binder = Find(start); //,categ); skl
212   if (binder.IsNull()) return Standard_False;
213   return binder->HasResult();
214 }
215
216 //        ##    ##    IsAlreadyUsed    ##    ##
217
218 //=======================================================================
219 //function : IsAlreadyUsed
220 //purpose  : 
221 //=======================================================================
222
223 Standard_Boolean Transfer_TransferProcess::IsAlreadyUsed(const TheStart& start) const
224 //                                                       const Standard_Integer categ) const
225 {
226   Handle(Transfer_Binder) binder = Find(start); //,categ); skl
227   if (binder.IsNull()) {
228     StartTrace (binder,start,thelevel,4);
229     Transfer_TransferFailure::Raise
230       ("TransferProcess : IsAlreadyUsed, transfer not done cannot be used...");
231   }
232   return (binder->Status() == Transfer_StatusUsed);
233 }
234
235
236 //        ##    ##    FindAndMask (private)    ##    ##
237
238 //=======================================================================
239 //function : FindAndMask
240 //purpose  : 
241 //=======================================================================
242
243 Handle(Transfer_Binder) Transfer_TransferProcess::FindAndMask(const TheStart& start)
244 //                                                            const Standard_Integer categ)
245 {
246   if (thelastobj == start) {
247     if (theindex > 0) return thelastbnd; //skl ->Search(categ);
248   }
249   thelastobj = start;
250   theindex   = themap.FindIndex (start);
251   if (theindex > 0) thelastbnd = themap.FindFromIndex(theindex);
252   else thelastbnd.Nullify();
253   //if (thelastbnd.IsNull()) skl
254   return thelastbnd;
255   //return thelastbnd->Search(categ); //skl
256 }
257
258
259 //  ##    ##    ##               Modifications               ##    ##    ##
260
261
262 //=======================================================================
263 //function : Bind
264 //purpose  : 
265 //=======================================================================
266
267 void Transfer_TransferProcess::Bind (const TheStart& start,
268                                      const Handle(Transfer_Binder)& binder)
269 //                                    const Standard_Integer categ)
270 {
271   if (binder.IsNull()) return;
272   Handle(Transfer_Binder) former = FindAndMask(start);//,categ);skl
273   if (!former.IsNull()) {
274 //  On admet VoidBinder : alors on reprend son Check
275     if (former->DynamicType() == STANDARD_TYPE(Transfer_VoidBinder)) {
276       binder->Merge(former);
277       //binder->SetCategory(categ); //skl
278       themap(theindex) = binder;                          // Substitution
279     }
280     else if (former->Status() == Transfer_StatusUsed) {
281       StartTrace (former,start,thelevel,4);
282       Transfer_TransferFailure::Raise
283         ("TransferProcess : Bind, already Bound");
284     }
285     else {
286       if (thetrace > 2) StartTrace (former,start,thelevel,5);
287       binder->CCheck()->GetMessages (former->Check());
288     }
289   }
290   //binder->SetCategory(categ); //skl
291   if (theindex == 0 || thelastbnd.IsNull()) {
292     if (theindex == 0) theindex = themap.Add(start,binder);  // Nouveau
293     else themap(theindex) = binder;                          // idem en fait
294     thelastbnd = binder;
295   }
296   else { //skl
297     //binder->AddResult(thelastbnd);
298     thelastbnd  = binder;
299     themap(theindex) = binder;
300   }
301 /*skl else if (thelastbnd->Category() == categ) {   // Substitue cette categorie
302     binder->Next(Standard_False)->SetNext(thelastbnd->Next(Standard_True),Standard_True);
303     thelastbnd  = binder;
304     themap(theindex) = binder;
305   } else {
306     thelastbnd->AddNext (binder,categ,Standard_True);
307   } */
308 }
309
310
311 //=======================================================================
312 //function : Rebind
313 //purpose  : 
314 //=======================================================================
315
316 void  Transfer_TransferProcess::Rebind (const TheStart& start,
317                                         const Handle(Transfer_Binder)& binder)
318 //                                      const Standard_Integer categ)
319 {
320   Bind(start,binder); //,categ);skl
321   // entre les deux, les differences allaient s amenuisant
322   //  au debut, on criait si pas encore Bound (idiot)
323   //  ne restait plus comme difference que le test StatusUsed sur Rebind,
324   //    tandis que Bind refusait des lors qu il y avait un resultat
325   //  -> a present, Bind s aligne sur Rebind
326 }
327
328
329 //=======================================================================
330 //function : Unbind
331 //purpose  : 
332 //=======================================================================
333
334 Standard_Boolean Transfer_TransferProcess::Unbind(const TheStart& start)
335 //                                                 const Standard_Integer categ)
336 {
337   Handle(Transfer_Binder) former = FindAndMask(start);//,categ);skl
338   if (theindex == 0) return Standard_False;
339   if (former.IsNull()) return Standard_False;
340   if (former->DynamicType() == STANDARD_TYPE(Transfer_VoidBinder)) return Standard_True;
341   //const Interface_Check& ach = thelastbnd->Check();
342   //Handle(Transfer_Binder) newbinder = thelastbnd->RemoveNext(categ);skl
343   //if (newbinder != thelastbnd)skl
344     themap(theindex) = thelastbnd;// = newbinder;skl
345   if(theroots.Contains(theindex)) {
346     TColStd_IndexedMapOfInteger aNewRoots;
347     for(Standard_Integer i = 1; i <= theroots.Extent(); i++)
348       if(theindex!= theroots.FindKey(i))
349         aNewRoots.Add(theroots.FindKey(i));
350     
351     theroots.Clear();
352     theroots = aNewRoots;
353   }
354
355   thelastobj.Nullify();
356   thelastbnd.Nullify();
357   theindex = 0;
358   return Standard_True;
359 }
360
361
362 //=======================================================================
363 //function : FindElseBind
364 //purpose  : 
365 //=======================================================================
366
367 Handle(Transfer_Binder) Transfer_TransferProcess::FindElseBind(const TheStart& start)
368 //                                                             const Standard_Integer categ)
369 {
370   Handle(Transfer_Binder) binder = FindAndMask (start);//,categ);skl
371   if (!binder.IsNull()) return binder;
372   binder = new Transfer_VoidBinder;
373   Bind(start,binder);//,categ);skl
374   return binder;
375 }
376
377
378 //  ##    ##    ##              Messages associes              ##    ##    ##
379
380 //=======================================================================
381 //function : SetMessenger
382 //purpose  : 
383 //=======================================================================
384
385 void Transfer_TransferProcess::SetMessenger (const Handle(Message_Messenger)& messenger)
386 {
387   if ( messenger.IsNull() )
388     themessenger = Message::DefaultMessenger();
389   else   
390     themessenger = messenger;
391 }
392
393 //=======================================================================
394 //function : Messenger
395 //purpose  : 
396 //=======================================================================
397
398 Handle(Message_Messenger) Transfer_TransferProcess::Messenger () const
399 {
400   return themessenger;
401 }
402
403 //=======================================================================
404 //function : SetTraceLevel
405 //purpose  : 
406 //=======================================================================
407
408 void Transfer_TransferProcess::SetTraceLevel (const Standard_Integer tracelev)
409 {
410   thetrace = tracelev;
411 }
412
413 //=======================================================================
414 //function : TraceLevel
415 //purpose  : 
416 //=======================================================================
417
418 Standard_Integer Transfer_TransferProcess::TraceLevel () const
419 {
420   return thetrace;
421 }
422
423 //=======================================================================
424 //function : SendFail
425 //purpose  : 
426 //=======================================================================
427
428 void  Transfer_TransferProcess::SendFail(const TheStart& start,
429                                          const Message_Msg& amsg)
430 {
431   AddFail(start,amsg);
432 }
433
434
435 //=======================================================================
436 //function : SendWarning
437 //purpose  : 
438 //=======================================================================
439
440 void  Transfer_TransferProcess::SendWarning(const TheStart& start,
441                                             const Message_Msg& amsg)
442 {
443   AddWarning(start,amsg);
444 }
445
446
447 //=======================================================================
448 //function : SendMsg
449 //purpose  : 
450 //=======================================================================
451
452 void  Transfer_TransferProcess::SendMsg(const TheStart& start,
453                                         const Message_Msg& amsg)
454 {
455   Handle(Transfer_Binder) binder = FindAndMask(start);
456   if (binder.IsNull()) {
457     binder = new Transfer_VoidBinder;
458     Bind (start,binder);
459   }
460   // Alimente la trace : Regle causant (user messages)
461   if (thetrace > 0) {
462     StartTrace (binder,start,thelevel,6);
463     themessenger << amsg.Value();
464     if (amsg.IsEdited()&&thetrace>2)
465       themessenger << " [from: " << amsg.Original() << "]";
466     themessenger << endl;
467   }
468 }
469
470
471 //=======================================================================
472 //function : AddFail
473 //purpose  : 
474 //=======================================================================
475
476 void Transfer_TransferProcess::AddFail(const TheStart& start,
477                                        const Standard_CString mess,
478                                        const Standard_CString orig)
479 {
480   Handle(Transfer_Binder) binder = FindAndMask(start);
481   if (binder.IsNull()) {
482     binder = new Transfer_VoidBinder;
483     Bind (start,binder);
484   }
485   binder->AddFail (mess,orig);
486   if (thetrace > 0) {
487     StartTrace (binder,start,thelevel,1);
488     themessenger << "    --> Fail : " << mess;
489     if (orig[0] != '\0'&&thetrace>2) themessenger << " [from: " << orig << "]";
490     themessenger << endl;
491   }
492 }
493
494
495 //=======================================================================
496 //function : AddError
497 //purpose  : 
498 //=======================================================================
499
500 void Transfer_TransferProcess::AddError(const TheStart& start,
501                                         const Standard_CString mess,
502                                         const Standard_CString orig)
503 {
504   AddFail (start,mess,orig);
505 }
506
507
508 //=======================================================================
509 //function : AddFail
510 //purpose  : 
511 //=======================================================================
512
513 void Transfer_TransferProcess::AddFail(const TheStart& start,
514                                        const Message_Msg& amsg)
515 {
516   if (amsg.IsEdited()) AddFail (start,TCollection_AsciiString(amsg.Value()).ToCString(),
517                                 TCollection_AsciiString(amsg.Original()).ToCString());
518   else AddFail (start,TCollection_AsciiString(amsg.Value()).ToCString());
519 }
520
521
522 //=======================================================================
523 //function : AddWarning
524 //purpose  : 
525 //=======================================================================
526
527 void Transfer_TransferProcess::AddWarning(const TheStart& start,
528                                           const Standard_CString mess,
529                                           const Standard_CString orig)
530 {
531   Handle(Transfer_Binder) binder = FindAndMask(start);
532   if (binder.IsNull()) {
533     binder = new Transfer_VoidBinder;
534     Bind (start,binder);
535   }
536   binder->AddWarning(mess,orig);
537   if (thetrace > 1) {
538     StartTrace (binder,start,thelevel,2);
539     themessenger << "    --> Warning : " << mess;
540     if (orig[0] != '\0'&&thetrace>2) themessenger << " [from: " << orig << "]";
541     themessenger << endl;
542   }
543 }
544
545
546 //=======================================================================
547 //function : AddWarning
548 //purpose  : 
549 //=======================================================================
550
551 void Transfer_TransferProcess::AddWarning(const TheStart& start,
552                                           const Message_Msg& amsg)
553 {
554   if (amsg.IsEdited()) AddWarning (start,TCollection_AsciiString(amsg.Value()).ToCString(),
555                                    TCollection_AsciiString(amsg.Original()).ToCString());
556   else AddWarning (start,TCollection_AsciiString(amsg.Value()).ToCString());
557 }
558
559
560 //=======================================================================
561 //function : Mend
562 //purpose  : 
563 //=======================================================================
564
565 void  Transfer_TransferProcess::Mend(const TheStart& start,
566                                      const Standard_CString pref)
567 {
568   Handle(Transfer_Binder) binder = FindAndMask(start);
569   if (binder.IsNull()) return;  // rien a faire ...
570   Handle(Interface_Check) ach =  binder->CCheck();
571   ach->Mend (pref);
572 }
573
574
575 //=======================================================================
576 //function : Check
577 //purpose  : 
578 //=======================================================================
579
580 Handle(Interface_Check) Transfer_TransferProcess::Check(const TheStart& start) const
581 {
582   const Handle(Transfer_Binder)& binder = Find(start);
583   if (binder.IsNull()) {
584     Handle(Interface_Check) check;
585     return check;
586   }
587   return binder->Check();
588 }
589
590 /*skl
591 void Transfer_TransferProcess::AddCaseName(const TheStart& start,
592                                            const Standard_CString casename)
593 {
594   AddCaseValue (start, new TCollection_HAsciiString (casename));
595 }
596
597
598 void Transfer_TransferProcess::AddCaseValue(const TheStart& start,
599                                             const Handle(Standard_Transient)& caseval)
600 {
601   Handle(Transfer_Binder) binder = FindAndMask(start);
602   if (binder.IsNull()) {
603     binder = new Transfer_VoidBinder;
604     Bind (start,binder);
605   }
606   binder->AddCaseValue (caseval);
607 }
608
609
610 Handle(TColStd_HSequenceOfTransient) Transfer_TransferProcess::CaseList
611        (const TheStart& start) const
612 {
613   Handle(TColStd_HSequenceOfTransient) list;
614   const Handle(Transfer_Binder)& binder = Find(start);
615   if (binder.IsNull()) return list;
616   return binder->CaseList();
617 }
618
619 Standard_Integer Transfer_TransferProcess::NextItemWithAttribute
620   (const Standard_CString name, const Standard_Integer num0) const
621 {
622   Standard_Integer num, nb = NbMapped();
623   for (num = num0+1; num <= nb; num ++) {
624     Handle(Transfer_Binder) bnd = MapItem (num);
625     if (bnd.IsNull()) continue;
626     if (!bnd->Attribute(name).IsNull()) return num;
627   }
628   return 0;
629 }
630
631
632 Interface_ParamType Transfer_TransferProcess::AttributeType
633   (const Standard_CString name) const
634 {
635   Interface_ParamType aty, res = Interface_ParamVoid;
636   Standard_Integer num, nb = NbMapped();
637   for (num = 1; num <= nb; num ++) {
638     Handle(Transfer_Binder) bnd = MapItem (num);
639     if (bnd.IsNull()) continue;
640     aty = bnd->AttributeType(name);
641     if (aty == Interface_ParamVoid) continue;
642     if (res == Interface_ParamVoid) res = aty;
643     else if (res != aty) return Interface_ParamMisc;
644   }
645   return res;
646 }
647
648 Handle(Dico_DictionaryOfInteger) Transfer_TransferProcess::Attributes
649   (const Standard_CString rootname) const
650 {
651   Handle(Dico_DictionaryOfInteger) list = new Dico_DictionaryOfInteger;
652   Standard_Integer num, nb = NbMapped();
653   for (num = 1; num <= nb; num ++) {
654     Handle(Transfer_Binder) bnd = MapItem (num);
655     if (bnd.IsNull()) continue;
656     Handle(Dico_DictionaryOfTransient) atr = bnd->AttrList();
657     if (atr.IsNull()) continue;
658     Dico_IteratorOfDictionaryOfTransient iatr(atr,rootname);
659     for (; iatr.More(); iatr.Next()) {
660       TCollection_AsciiString name = iatr.Name();
661       Standard_Boolean deja;
662       Standard_Integer& nbval = list->NewItem (name.ToCString(),deja);
663       if (!deja) nbval = 0;
664       nbval ++;
665     }
666
667   }
668   return list;
669 }
670 skl*/
671
672
673 //  ##    ##    ##        Actions sur Types Privilegies        ##    ##    ##
674 //  ##    ##    ##          (Transient)                        ##    ##    ##
675
676 // Bind associe un objet a un objet resultat; or la Map associe un Objet a un
677 // Binder (qui designe son resultat)
678 //  *Transient  travaillent avec un SimpleBinderOfTransient
679 // si  deja la, on considere son resultat
680 // sinon, on cree un Binder du bon type
681
682
683 //=======================================================================
684 //function : BindTransient
685 //purpose  : 
686 //=======================================================================
687
688 void Transfer_TransferProcess::BindTransient(const TheStart& start,
689                                              const Handle(Standard_Transient)& res)
690 //                                           const Standard_Integer categ)
691 {
692   if (res.IsNull()) return;
693   Handle(Transfer_Binder) former = Find(start);//,categ);skl
694   Handle(Transfer_SimpleBinderOfTransient) binder =
695     Handle(Transfer_SimpleBinderOfTransient)::DownCast(former);
696 //      Binding sur place ?
697   if (!binder.IsNull()) {
698     if (binder->Status() == Transfer_StatusVoid) { binder->SetResult(res); return; }
699   }
700 //      Sinon, refaire
701   binder = new Transfer_SimpleBinderOfTransient;
702   binder->SetResult (res);
703   if (former.IsNull()) Bind(start,binder);//,categ);skl
704   else Rebind(start,binder);//,categ);skl
705 }
706
707
708 //=======================================================================
709 //function : FindTransient
710 //purpose  : 
711 //=======================================================================
712
713 const Handle(Standard_Transient)& Transfer_TransferProcess::FindTransient
714        (const TheStart& start) const
715 {
716   Handle(Transfer_SimpleBinderOfTransient) binder =
717     Handle(Transfer_SimpleBinderOfTransient)::DownCast(Find(start));
718   if (binder.IsNull()) return nultrans;
719   if (!binder->HasResult()) return nultrans;
720   return binder->Result();
721 }
722
723
724 //  Binding Multiple : D abord le declarer par BindMultiple (si pas deja fait)
725 //  Puis ajouter les termes par AddMultiple
726
727 //=======================================================================
728 //function : BindMultiple
729 //purpose  : 
730 //=======================================================================
731
732 void Transfer_TransferProcess::BindMultiple(const TheStart& start)
733 //                                          const Standard_Integer categ)
734 {
735   Handle(Transfer_Binder) binder = FindAndMask (start);//,categ);skl
736   if (!binder.IsNull()) {
737     if (!binder->IsKind(STANDARD_TYPE(Transfer_MultipleBinder))) {
738       StartTrace (thelastbnd,start,thelevel,4);
739       Transfer_TransferFailure::Raise ("TransferProcess : BindMultiple");
740     }
741   }
742   else Bind(start,new Transfer_MultipleBinder);//,categ);skl
743 }
744
745
746 //=======================================================================
747 //function : AddMultiple
748 //purpose  : 
749 //=======================================================================
750
751 void Transfer_TransferProcess::AddMultiple(const TheStart& start,
752                                            const Handle(Standard_Transient)& res)
753 //                                         const Standard_Integer categ)
754 {
755   Handle(Transfer_Binder) binder = FindAndMask(start);//,categ);skl
756   Handle(Transfer_MultipleBinder) multr =
757     Handle(Transfer_MultipleBinder)::DownCast(binder);
758   if (multr.IsNull()) {
759     StartTrace (binder,start,thelevel,4);
760     if (binder.IsNull()) Transfer_TransferFailure::Raise
761       ("TransferProcess : AddMultiple, nothing bound");
762     else                 Transfer_TransferFailure::Raise
763       ("TransferProcess : AddMultiple, Binder not a MultipleBinder");
764   }
765   multr->AddResult(res);
766 }
767
768
769 //=======================================================================
770 //function : FindTypedTransient
771 //purpose  : 
772 //=======================================================================
773
774 Standard_Boolean Transfer_TransferProcess::FindTypedTransient
775   (const TheStart& start, const Handle(Standard_Type)& atype,
776    Handle(Standard_Transient)& val) const
777 {
778   return GetTypedTransient (Find(start),atype,val);
779 }
780
781
782 //=======================================================================
783 //function : GetTypedTransient
784 //purpose  : 
785 //=======================================================================
786
787 Standard_Boolean  Transfer_TransferProcess::GetTypedTransient
788   (const Handle(Transfer_Binder)& binder, const Handle(Standard_Type)& atype,
789    Handle(Standard_Transient)& val) const
790 {
791   return Transfer_SimpleBinderOfTransient::GetTypedResult(binder,atype,val);
792 }
793
794
795 //  ##    ##    ##    ##    ##    Acces Atomique    ##    ##    ##    ##    ##
796 //    (ne gere pas le scope mais donne acces aux categories)
797
798 //=======================================================================
799 //function : NbMapped
800 //purpose  : 
801 //=======================================================================
802
803 Standard_Integer  Transfer_TransferProcess::NbMapped () const
804 {
805   return themap.Extent();
806 }
807
808
809 //=======================================================================
810 //function : Mapped
811 //purpose  : 
812 //=======================================================================
813
814 const TheStart& Transfer_TransferProcess::Mapped(const Standard_Integer num) const
815 {
816   return themap.FindKey(num);
817 }
818
819
820 //=======================================================================
821 //function : MapIndex
822 //purpose  : 
823 //=======================================================================
824
825 Standard_Integer Transfer_TransferProcess::MapIndex(const TheStart& start) const
826 {
827   return themap.FindIndex(start);
828 }
829
830
831 //=======================================================================
832 //function : MapItem
833 //purpose  : 
834 //=======================================================================
835
836 Handle(Transfer_Binder) Transfer_TransferProcess::MapItem(const Standard_Integer num) const
837 //                                                        const Standard_Integer categ) const
838 {
839   Handle(Transfer_Binder) binder = themap.FindFromIndex(num);
840   //sklif (binder.IsNull())
841   return binder;
842   //sklreturn binder->Search (categ);
843 }
844
845
846 //  ########################################################################
847 //  ....                         ROOT MANAGEMENT                        ....
848
849 //=======================================================================
850 //function : SetRoot
851 //purpose  : 
852 //=======================================================================
853
854 void Transfer_TransferProcess::SetRoot (const TheStart& start)
855 {
856   Standard_Integer index = MapIndex(start);
857   if (index == 0) {
858     //StartTrace (thelastbnd,start,thelevel,4);
859     //Transfer_TransferFailure::Raise("TransferProcess : SetRoot");
860     return;
861   }
862
863   theroots.Add(index);
864   if (thetrace > 2) StartTrace (MapItem(index),start,thelevel,3);
865 }
866
867
868 //=======================================================================
869 //function : SetRootManagement
870 //purpose  : 
871 //=======================================================================
872
873 void  Transfer_TransferProcess::SetRootManagement(const Standard_Boolean stat)
874 {
875   therootm = stat;
876 }
877
878
879 //=======================================================================
880 //function : NbRoots
881 //purpose  : 
882 //=======================================================================
883
884 Standard_Integer  Transfer_TransferProcess::NbRoots () const
885 {
886   return theroots.Extent();
887 }
888
889
890 //=======================================================================
891 //function : Root
892 //purpose  : 
893 //=======================================================================
894
895 const TheStart&  Transfer_TransferProcess::Root(const Standard_Integer num) const
896 {
897   Standard_Integer ind = 0;
898   if (num > 0 && num <= theroots.Extent()) ind = theroots.FindKey(num);
899   return themap.FindKey (ind);
900 }
901
902
903 //=======================================================================
904 //function : RootItem
905 //purpose  : 
906 //=======================================================================
907
908 Handle(Transfer_Binder) Transfer_TransferProcess::RootItem(const Standard_Integer num) const
909 //                                                         const Standard_Integer categ) const
910 {
911   Standard_Integer ind = 0;
912   if (num > 0 && num <= theroots.Extent()) ind = theroots.FindKey(num);
913   return themap.FindFromIndex(ind);//->Search(categ);skl
914 }
915
916
917 //=======================================================================
918 //function : RootIndex
919 //purpose  : 
920 //=======================================================================
921
922 Standard_Integer  Transfer_TransferProcess::RootIndex(const TheStart& start) const
923 {
924   Standard_Integer index = MapIndex(start);
925   if (index == 0) return 0;
926   return theroots.FindIndex(index);
927 }
928
929
930 //=======================================================================
931 //function : NestingLevel
932 //purpose  : 
933 //=======================================================================
934
935 Standard_Integer  Transfer_TransferProcess::NestingLevel () const
936 {
937   return thelevel;
938 }
939
940
941 //=======================================================================
942 //function : ResetNestingLevel
943 //purpose  : 
944 //=======================================================================
945
946 void Transfer_TransferProcess::ResetNestingLevel ()
947 {
948   thelevel = 0;
949 }
950
951
952 //  ########################################################################
953 //  ....                        SCOPE MANAGEMENT                        ....
954
955
956 //======================================================================
957 //Purpose : gka TRJ9 for writing SDR for solid
958 //          Check if binder has already been bound to the result binder.
959 //======================================================================
960
961 // static Standard_Boolean Contains(const Handle(Transfer_Binder)& resbinder, 
962 //                               const Handle(Transfer_Binder)& addbinder)
963 // {
964 //   Handle(Transfer_Binder) tmpbind = resbinder;
965 //   for ( ; ! tmpbind.IsNull(); tmpbind = tmpbind->NextResult() )
966 //     if ( tmpbind == addbinder ) return Standard_True;
967 //   return Standard_False;
968 // }
969
970 //  ########################################################################
971 //  ....                    AUTOMATISMES DE TRANSFERT                   ....
972
973 //  ##    ##    ##    ##    ##  Fonctions de Base  ##    ##    ##    ##    ##
974
975
976 //=======================================================================
977 //function : Recognize
978 //purpose  : 
979 //=======================================================================
980
981 Standard_Boolean  Transfer_TransferProcess::Recognize(const TheStart& start) const
982 {
983   Handle(Transfer_Actor) actor = theactor;
984   //   On balaie les Next jusqu a avoir un Resultat
985   while (!actor.IsNull()) {
986     if (actor->Recognize (start)) return Standard_True;
987     actor = actor->Next();
988   }
989   return Standard_False;
990 }
991
992
993 //=======================================================================
994 //function : Transferring
995 //purpose  : 
996 //=======================================================================
997
998 Handle(Transfer_Binder) Transfer_TransferProcess::Transferring(const TheStart& start)
999 {
1000   //   Map deja alimentee ?
1001   Handle(Transfer_Binder) former = FindAndMask(start);
1002
1003   //  ....    Transfert deja effectue avec Resultat ?    ....
1004
1005   //  On considere que cette nouvelle demande de Transfert correspond donc a une
1006   //  utilisation en plus : noter "AlreadyUsed", donc resultat non modifiable
1007   if (!former.IsNull()) {
1008     if (former->HasResult()) {
1009       former->SetAlreadyUsed();
1010       return former;
1011     }
1012   //}
1013
1014     //  ....    Etat Initial : peut-etre deja fait ... ou infaisable !
1015
1016   //if (!former.IsNull()) {
1017     Transfer_StatusExec statex = former->StatusExec();
1018     switch (statex) {
1019       case Transfer_StatusInitial :               // Transfert prepare a faire
1020         break;
1021       case Transfer_StatusDone :                  // Transfert deja fait
1022 //#ifdef TRANSLOG
1023         themessenger << " .. and Transfer done" << endl;
1024 //#endif
1025 //      if (former->HasResult()) former->SetAlreadyUsed();
1026         return former;
1027       case Transfer_StatusRun :                   // ca y est, on boucle
1028         former->SetStatusExec(Transfer_StatusLoop);
1029         return former;
1030       case Transfer_StatusError :                 // pas propre, ca ...
1031         if (thetrace) {
1032           themessenger << "                  *** Transfer in Error Status  :" << endl;
1033           StartTrace (former, start, thelevel,0);
1034 //        (*themessenger->Out()) << flush;
1035         }
1036         else StartTrace (former, start,thelevel,4);
1037         Transfer_TransferFailure::Raise
1038           ("TransferProcess : Transfer in Error Status");
1039       case Transfer_StatusLoop :                  // la boucle est bouclee ...
1040         if (thetrace) {
1041           themessenger << "                  *** Transfer  Head of Dead Loop  :" << endl;
1042           StartTrace (former, start, thelevel,0);
1043 //        (*themessenger->Out()) << flush;
1044         }
1045         else StartTrace (former, start,thelevel,4);
1046         Transfer_TransferDeadLoop::Raise
1047           ("TransferProcess : Transfer at Head of a Dead Loop");
1048     }
1049 #ifdef TRANSLOG
1050     cout << "Transfer,level "<<thelevel<<Message_Flush;
1051 #endif
1052   //}
1053
1054   //  ....    OK, on peut lancer l Execution
1055   //if (!former.IsNull()) 
1056     former->SetStatusExec(Transfer_StatusRun);
1057   }
1058 #ifdef TRANSLOG
1059   cout << " GO .." << endl;
1060 #endif
1061
1062   Handle(Transfer_Binder) binder;
1063   Standard_Boolean newbind = Standard_False;
1064   if (theerrh) {
1065     //   Transfert sous protection pour les exceptions (pour notification en fait)
1066     Standard_Integer oldlev = thelevel;
1067     try {
1068       OCC_CATCH_SIGNALS
1069       binder = TransferProduct(start);
1070     }
1071
1072     //    ...  Exceptions a Rattraper : elles ne se ressemblent pas toutes ... !
1073     catch (Transfer_TransferDeadLoop) {
1074       if (binder.IsNull()) {
1075         themessenger << "                  *** Dead Loop with no Result" << endl;
1076         if (thetrace) StartTrace (binder, start, thelevel-1,0);
1077         binder = new Transfer_VoidBinder;
1078         Bind (start,binder);  newbind = Standard_True;
1079       } else if (binder->StatusExec() == Transfer_StatusLoop) {
1080         if (thetrace) {
1081           themessenger << "                  *** Dead Loop : Finding head of Loop :" << endl;
1082           StartTrace (binder, start, thelevel-1,0);
1083         }
1084         else StartTrace (binder, start,thelevel-1,4);
1085         Transfer_TransferFailure::Raise("TransferProcess : Head of Dead Loop");
1086 // Autrement dit, on change d exception (on est sorti de la boucle)
1087       } else {
1088         if (thetrace) {
1089           themessenger << "                  *** Dead Loop : Actor in Loop :" << endl;
1090           StartTrace (binder, start, thelevel-1,0);
1091         }
1092       }
1093       binder->AddFail("Transfer in dead Loop");
1094       thelevel = oldlev;
1095     }
1096     catch (Standard_Failure) {
1097       if (binder.IsNull()) {
1098         themessenger << "                  *** Exception Raised with no Result" << endl;
1099         binder = new Transfer_VoidBinder;
1100         Bind (start,binder);  newbind = Standard_True;
1101       }
1102       binder->AddFail("Transfer stopped by exception raising");
1103       if (thetrace) {
1104         themessenger << "    *** Raised : " << Standard_Failure::Caught()->GetMessageString() << endl;
1105         StartTrace (binder, start, thelevel-1,4);
1106       }
1107       thelevel = oldlev;
1108     }
1109   }
1110
1111 //   Transfert non protege (ainsi, dbx a la main en cas de plantage par Raise)
1112   else  binder = TransferProduct(start);
1113
1114 //  ....                Conclusion : Noter dans la Map                ....
1115
1116   if (!newbind && !binder.IsNull()) {
1117     if (former.IsNull()) {
1118 //    Peut-etre <theactor> a fait lui meme Bind ... verifier sinon le faire
1119       if (!IsBound(start)) Bind(start,binder);     // resultat = categorie 0
1120       else {                                       // gka TRJ9 for writing SDR for solid
1121 //      Handle(Transfer_Binder) tmpbind = Find(start);
1122 //      if(!Contains(binder,tmpbind))
1123 //         binder->AddResult(tmpbind);
1124         Rebind(start,binder); // test_pattern.sat
1125       }
1126     }
1127     else Rebind(start,binder);
1128 //  (du coup, <thelastbnd> vaut <binder>)
1129 #ifdef TRANSLOG
1130     cout << " ... OK" << endl;
1131 #endif
1132   }
1133   else {
1134     //= by ABV: 5 Oct 97: nothing generated, but former can be in run state - drop it
1135     //= ASK: may be set it to StatusInitial ?
1136     if ( ! former.IsNull() ) former->SetStatusExec ( Transfer_StatusDone ); //+
1137     return nulbinder;    // Binder Null ... que faire d autre ?
1138   }
1139
1140 //  ....                Gerer les Racines (si prevu)                ....
1141
1142   if (therootl >= thelevel) {
1143     therootl = 0;
1144     if (therootm && binder->Status() != Transfer_StatusVoid) {
1145       SetRoot (start);
1146     }
1147   }
1148   return thelastbnd;
1149 }
1150
1151 //  ##    ##        TransferProduct : Action proprement dite        ##    ##
1152
1153     Handle(Transfer_Binder) Transfer_TransferProcess::TransferProduct
1154   (const TheStart& start)
1155 {
1156   thelevel ++;             // si decremente et == 0, transfert racine
1157   Handle(Transfer_Binder) binder;
1158   Handle(Transfer_Actor) actor = theactor;
1159
1160 //   On balaie les Next jusqu a avoir un Resultat
1161   while (!actor.IsNull()) {
1162     if (actor->Recognize (start)) binder = actor->Transferring(start,this);
1163     else binder.Nullify();
1164     if (!binder.IsNull()) break;
1165     actor = actor->Next();
1166   }
1167   if (binder.IsNull()) {
1168 //    if (thetrace) {
1169 //      themessenger << "Transfer has produced no Result" <<endl;
1170 //      StartTrace (binder, start, thelevel-1,0); sout << flush;
1171 //    }
1172     if (thelevel > 0) thelevel --;
1173     return binder;
1174   }
1175 //      Gestion du niveau racine (.. a regarder de pres ..)
1176   if (therootl == 0 && binder->StatusExec() == Transfer_StatusDone)
1177     therootl = thelevel - 1;
1178
1179   if (thelevel > 0) thelevel --;
1180   return binder;
1181 }
1182
1183
1184 //=======================================================================
1185 //function : Transfer
1186 //purpose  : 
1187 //=======================================================================
1188
1189 Standard_Boolean  Transfer_TransferProcess::Transfer(const TheStart& start)
1190 {
1191   Handle(Transfer_Binder) binder = Transferring(start);
1192   return (!binder.IsNull());
1193 }
1194
1195
1196 //  #########################################################################
1197 //  ....                      Error Handling + Trace                     ....
1198
1199 //  trace : 1 pour Fail et Exception , 2 pour Root et Warning
1200
1201
1202 //=======================================================================
1203 //function : SetErrorHandle
1204 //purpose  : 
1205 //=======================================================================
1206
1207 void Transfer_TransferProcess::SetErrorHandle(const Standard_Boolean err)
1208 {
1209   theerrh = err;
1210 }    // traite par Transferring
1211
1212
1213 //=======================================================================
1214 //function : ErrorHandle
1215 //purpose  : 
1216 //=======================================================================
1217
1218 Standard_Boolean  Transfer_TransferProcess::ErrorHandle() const
1219 {
1220   return theerrh;
1221 }
1222
1223 //=======================================================================
1224 //function : StartTrace
1225 //purpose  : 
1226 //=======================================================================
1227
1228 void Transfer_TransferProcess::StartTrace(const Handle(Transfer_Binder)& binder,
1229                                           const TheStart& start,
1230                                           const Standard_Integer level,
1231                                           const Standard_Integer mode) const 
1232 {
1233   // ###  Fail (Roots:50)  --  Start start->DynamicType()
1234   // ###  Fail (Roots:50)  --  Start id:#label.. Type:start->DynamicType()
1235   if (thetrace > 3) {  // Internal to be switch when searching bug (trace >= 4)
1236     if (mode == 1) themessenger << "  ###  Fail";
1237     if (mode == 2) themessenger << "  ###  Warning";
1238     if (mode == 3) themessenger << "  ###  New Root n0 " << theroots.Extent();
1239     if (mode == 4) themessenger << "  ###  Exception";
1240     if (mode == 5) themessenger << "  ###  Substitution";
1241     if (mode == 6) themessenger << "  ###  Information";
1242     if (level > 1)
1243       themessenger << " (nested)";  // " at nesting Level:"<<level;
1244     if (mode >= 0 && mode != 3)
1245       themessenger << " at " << theroots.Extent() << " Roots";
1246   }
1247   if (!start.IsNull()) PrintTrace (start,themessenger);
1248 ////  sout << endl;
1249
1250   if (!binder.IsNull()) {   // old: if IsNull sout <<endl<< "  ---  Not Bound";
1251     Handle(Transfer_Binder) bnd = binder;
1252     Standard_Boolean hasres = Standard_False;
1253     while (!bnd.IsNull()) {
1254       if (bnd->Status() != Transfer_StatusVoid) {
1255 // ---  Result Type: binder->ResultType()  ---  Binder : binder->DynamicType();
1256         if (!hasres)
1257           themessenger << "\n  ---  Result Type : ";
1258         else 
1259           themessenger << " , ";
1260         themessenger << bnd->ResultTypeName();
1261 //  CKY 9-JAN-1999:  waiting for XSTEP Kernel message (not IGES_2075)
1262 /*        Message_Msg Msg2075("IGES_2075");
1263           Msg2075.AddString(bnd->ResultTypeName());
1264           Msg2075.TraceEver();  */
1265         hasres = Standard_True;
1266       }
1267       bnd = bnd->NextResult();
1268     }
1269     if (!hasres && mode > 2) {
1270       themessenger << "\n  ---  No Result recorded";
1271 //  CKY 9-JAN-1999 : waiting for XSTEP Kernel message
1272 //     (not IGES_2075, no reference to specifically TopoDS_Shape)
1273 /*       Message_Msg Msg2075("IGES_2075");
1274          Msg2075.AddString("No TopoDS_Shape");
1275          Msg2075.TraceEver();  */
1276     }
1277 //old    if (isused) sout << "  --    (Already Used in another Transfer)";
1278   }
1279   themessenger << endl;
1280 }
1281
1282
1283 //=======================================================================
1284 //function : PrintTrace
1285 //purpose  : 
1286 //=======================================================================
1287
1288 void  Transfer_TransferProcess::PrintTrace(const TheStart& start,
1289                                            const Handle(Message_Messenger)& S) const
1290 {
1291   if (!start.IsNull())   S <<" Type:" << start->DynamicType()->Name();
1292 }
1293
1294
1295 //=======================================================================
1296 //function : IsLooping
1297 //purpose  : 
1298 //=======================================================================
1299
1300 Standard_Boolean  Transfer_TransferProcess::IsLooping
1301   (const Standard_Integer alevel) const 
1302       {  return alevel > NbMapped();  }
1303
1304
1305
1306 //  #########################################################################
1307 //  ....                            RESULTATS                            ....
1308
1309
1310 //  ##    ##        RootResult : Les Racines        ##    ##
1311
1312
1313 //=======================================================================
1314 //function : RootResult
1315 //purpose  : 
1316 //=======================================================================
1317
1318 Transfer_Iterator Transfer_TransferProcess::RootResult(const Standard_Boolean withstart) const
1319 {
1320   Transfer_Iterator iter(withstart);
1321   Standard_Integer max = theroots.Extent();
1322   for (Standard_Integer j = 1; j <= max; j ++) {
1323     Standard_Integer i = theroots.FindKey(j);
1324     Handle(Transfer_Binder) binder = MapItem(i);
1325     if (binder.IsNull()) continue;
1326     if (withstart) iter.Add (binder,Mapped(i));
1327     else iter.Add (binder);
1328   }
1329   return iter;
1330 }
1331
1332
1333 //  ##    ##        CompleteResult : Tous les Resultats        ##    ##
1334
1335 //=======================================================================
1336 //function : CompleteResult
1337 //purpose  : 
1338 //=======================================================================
1339
1340 Transfer_Iterator Transfer_TransferProcess::CompleteResult
1341   (const Standard_Boolean withstart) const
1342 {
1343   Transfer_Iterator iter(withstart);
1344   Standard_Integer max = NbMapped();
1345   for (Standard_Integer i = 1; i <= max; i ++) {
1346     Handle(Transfer_Binder) binder = MapItem(i);
1347     if (binder.IsNull()) continue;
1348     if (withstart) iter.Add (binder,Mapped(i));
1349     else iter.Add (binder);
1350   }
1351   return iter;
1352 }
1353
1354
1355 //  ##    ##        AbnormalResult : Transferts a probleme        ##    ##
1356 //=======================================================================
1357 //function : AbnormalResult
1358 //purpose  : 
1359 //=======================================================================
1360
1361 Transfer_Iterator Transfer_TransferProcess::AbnormalResult() const
1362 {
1363   Transfer_Iterator iter(Standard_True);
1364   Standard_Integer max = NbMapped();
1365   for (Standard_Integer i = 1; i <= max; i ++) {
1366     Handle(Transfer_Binder) binder = MapItem(i);
1367     if (binder.IsNull()) continue;
1368     Transfer_StatusExec statex = binder->StatusExec();
1369     if (statex != Transfer_StatusInitial && statex != Transfer_StatusDone)
1370       iter.Add (binder,Mapped(i));  // on note les cas "pas normaux"
1371   }
1372   return iter;
1373 }
1374
1375
1376 //  ##    ##    ##         CheckList : les messages         ##    ##    ##
1377 //=======================================================================
1378 //function : CheckList
1379 //purpose  : 
1380 //=======================================================================
1381
1382 Interface_CheckIterator  Transfer_TransferProcess::CheckList
1383   (const Standard_Boolean erronly) const
1384 {
1385   Interface_CheckIterator list;
1386   Standard_Integer num, max = NbMapped();
1387   for (Standard_Integer i = 1; i <= max; i ++) {
1388     Handle(Transfer_Binder) binder = MapItem(i);
1389     if (binder.IsNull()) continue;
1390     Transfer_StatusExec statex = binder->StatusExec();
1391     Handle(Interface_Check) check = binder->Check();
1392     if (statex != Transfer_StatusInitial && statex != Transfer_StatusDone &&
1393         !check->HasFailed())
1394       check->AddFail("Transfer in Abnormal Status (!= Initial or Done)");
1395     if (!check->HasFailed() && (erronly || check->NbWarnings() == 0)) continue;
1396     const TheStart& ent = Mapped(i);
1397     num = CheckNum(ent);
1398     if (num == 0) num = i;
1399     check->SetEntity(ent);
1400     list.Add(check,num);
1401   }
1402   return list;
1403 }
1404
1405
1406 //  #########################################################################
1407 //  ....                       RESULTATS PAR ENTITE                      ....
1408
1409 //=======================================================================
1410 //function : ResultOne
1411 //purpose  : 
1412 //=======================================================================
1413
1414 Transfer_Iterator Transfer_TransferProcess::ResultOne(const TheStart& start,
1415                                                       const Standard_Integer level,
1416                                                       const Standard_Boolean withstart) const
1417 {
1418   Transfer_Iterator iter(withstart);
1419   Standard_Integer max = NbMapped();
1420   Standard_Integer ind = MapIndex (start);
1421   if (ind == 0) return iter;
1422   Standard_Integer i1 = (level == 0 ? ind : 1);
1423   Standard_Integer i2 = (level == 0 ? ind : max);
1424   Handle(TColStd_HArray1OfInteger) map = new TColStd_HArray1OfInteger (i1,i2,0);
1425   //MarkScoped (ind,level,map);
1426
1427   for (Standard_Integer i = i1; i <= i2; i ++) {
1428     ind = map->Value(i);
1429     if (ind == 0) continue;
1430     Handle(Transfer_Binder) binder = MapItem(i);
1431     if (binder.IsNull()) continue;
1432     if (withstart) iter.Add (binder,Mapped(ind));
1433     else iter.Add (binder);
1434   }
1435   return iter;
1436 }
1437
1438
1439 //=======================================================================
1440 //function : CheckListOne
1441 //purpose  : 
1442 //=======================================================================
1443
1444 Interface_CheckIterator  Transfer_TransferProcess::CheckListOne
1445   (const TheStart& start,const Standard_Integer level,
1446    const Standard_Boolean erronly) const
1447 {
1448   Interface_CheckIterator list;
1449   Standard_Integer max = NbMapped();
1450   Standard_Integer num, ind = MapIndex (start);
1451   if (ind == 0) return list;
1452   Standard_Integer i1 = (level == 0 ? ind : 1);
1453   Standard_Integer i2 = (level == 0 ? ind : max);
1454   Handle(TColStd_HArray1OfInteger) map = new TColStd_HArray1OfInteger (i1,i2,0);
1455   //MarkScoped (ind,level,map);
1456
1457   for (Standard_Integer i = i1; i <= i2; i ++) {
1458     ind = map->Value(i);
1459     if (ind == 0) continue;
1460     Handle(Transfer_Binder) binder = MapItem(ind);
1461     if (binder.IsNull()) continue;
1462     Transfer_StatusExec statex = binder->StatusExec();
1463     Handle(Interface_Check) check = binder->Check();
1464     if (statex != Transfer_StatusInitial && statex != Transfer_StatusDone &&
1465         !check->HasFailed())
1466       check->AddFail("Transfer in Abnormal Status (!= Initial or Done)");
1467     if (!check->HasFailed() && (erronly || check->NbWarnings() == 0)) continue;
1468     const TheStart& ent = Mapped(ind);
1469     num = CheckNum(ent);  if (num == 0) num = ind;
1470     check->SetEntity(ent);
1471     list.Add(check,num);
1472   }
1473   return list;
1474 }
1475
1476
1477 //=======================================================================
1478 //function : IsCheckListEmpty
1479 //purpose  : 
1480 //=======================================================================
1481
1482 Standard_Boolean  Transfer_TransferProcess::IsCheckListEmpty
1483   (const TheStart& start, const Standard_Integer level,
1484    const Standard_Boolean erronly) const
1485 {
1486   Standard_Integer max = NbMapped();
1487   Standard_Integer ind = MapIndex (start);
1488   if (ind == 0) return Standard_False;
1489   Standard_Integer i1 = (level == 0 ? ind : 1);
1490   Standard_Integer i2 = (level == 0 ? ind : max);
1491   Handle(TColStd_HArray1OfInteger) map = new TColStd_HArray1OfInteger (i1,i2,0);
1492 //  MarkScoped (ind,level,map);
1493
1494   for (Standard_Integer i = i1; i <= i2; i ++) {
1495     ind = map->Value(i);
1496     if (ind == 0) continue;
1497     Handle(Transfer_Binder) binder = MapItem(ind);
1498     if (binder.IsNull()) continue;
1499
1500     Transfer_StatusExec statex = binder->StatusExec();
1501     Handle(Interface_Check) check = binder->Check();
1502     if (statex != Transfer_StatusInitial && statex != Transfer_StatusDone)
1503       return Standard_False;
1504     if (check->HasFailed() || (!erronly && check->NbWarnings() > 0)) return Standard_False;
1505   }
1506   return Standard_True;
1507 }
1508
1509
1510 //=======================================================================
1511 //function : RemoveResult
1512 //purpose  : 
1513 //=======================================================================
1514
1515 void  Transfer_TransferProcess::RemoveResult(const TheStart& start,
1516                                              const Standard_Integer level,
1517                                              const Standard_Boolean /*compute*/)
1518 {
1519   //if (compute) ComputeScopes();
1520   Standard_Integer max = NbMapped();
1521   Standard_Integer ind = MapIndex (start);
1522   if (ind == 0) return;
1523   Standard_Integer i1 = (level == 0 ? ind : 1);
1524   Standard_Integer i2 = (level == 0 ? ind : max);
1525   Handle(TColStd_HArray1OfInteger) map = new TColStd_HArray1OfInteger (i1,i2,0);
1526 //  MarkScoped (ind,level,map);
1527
1528   Standard_Integer i; // svv Jan11 2000 : porting on DEC
1529   for (i = i1; i <= i2; i ++) {
1530     ind = map->Value(i);
1531     if (ind == 0) continue;
1532     Handle(Transfer_Binder) binder = MapItem(ind);
1533     if (binder.IsNull()) continue;
1534 //    Standard_Boolean cayest = binder->SetNbUserScopes (-1);
1535 //    if (cayest) themap(ind) = nulbinder;    // RAZ !
1536   }
1537
1538 //pdn commented  for (i = NbRoots(); i > 0; i --)
1539 //    if (theroots.Value(i) == ind) theroots.Remove(i);
1540 }
1541
1542
1543 Standard_Integer  Transfer_TransferProcess::CheckNum(const TheStart& ) const
1544 {
1545   return 0;
1546 }
1547
1548
1549 //=======================================================================
1550 //function : SetProgress
1551 //purpose  : Sets Progress indicator
1552 //=======================================================================
1553
1554 void Transfer_TransferProcess::SetProgress(const Handle(Message_ProgressIndicator)& theProgress)
1555 {
1556   myProgress = theProgress;
1557 }
1558
1559 //=======================================================================
1560 //function : GetProgress
1561 //purpose  : Returns Progress indicator
1562 //=======================================================================
1563
1564 Handle(Message_ProgressIndicator) Transfer_TransferProcess::GetProgress() const
1565 {
1566   return myProgress;
1567 }