Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Interface / Interface_Graph.cxx
1 #include <Interface_Graph.ixx> 
2 #include <Interface_GeneralModule.hxx>
3 #include <Interface_ReportEntity.hxx>
4 #include <Standard_DomainError.hxx>
5 #include <TColStd_Array1OfInteger.hxx>
6 #include <Interface_ShareTool.hxx>
7
8
9
10 // Flags : 0 = Presence, 1 = Sharing Error
11 #define Graph_Present 0
12 #define Graph_ShareError 1
13
14
15 //  ###########################################################################
16
17 //  ....                           CONSTRUCTEURS                           ....
18
19 //  ....       Construction a partir de la connaissance des Entites        ....
20
21
22     Interface_Graph::Interface_Graph
23   (const Handle(Interface_InterfaceModel)& amodel,
24    const Interface_GeneralLib& lib)
25    : themodel   (amodel), thepresents ("") , thestats (0,amodel->NbEntities()) , 
26      theflags   (amodel->NbEntities(),2) ,  
27      theshareds (amodel->NbEntities()) , /*thesharnews(amodel->NbEntities()) , */
28      thesharings (amodel->NbEntities())
29 {
30   Handle(Interface_GTool) gtool;  // null
31   theflags.AddFlag ("ShareError");  // -> flag n0 1
32   Evaluate(lib,gtool);
33 }
34
35     Interface_Graph::Interface_Graph
36   (const Handle(Interface_InterfaceModel)& amodel,
37    const Handle(Interface_Protocol)& protocol)
38    : themodel   (amodel) , thepresents ("") ,
39      thestats (0,amodel->NbEntities()) ,      theflags   (amodel->NbEntities(),2) ,  
40      theshareds (amodel->NbEntities()) ,      /*thesharnews(amodel->NbEntities()) ,*/
41      thesharings (amodel->NbEntities())
42 {
43   Handle(Interface_GTool) gtool;  // null
44   theflags.AddFlag ("ShareError");  // -> flag n0 1
45   Evaluate(Interface_GeneralLib(protocol),gtool);
46 }
47
48     Interface_Graph::Interface_Graph
49   (const Handle(Interface_InterfaceModel)& amodel,
50    const Handle(Interface_GTool)& gtool)
51    : themodel   (amodel) , thepresents ("") , 
52      thestats (0,amodel->NbEntities()) ,  theflags   (amodel->NbEntities(),2) ,  
53      theshareds (amodel->NbEntities()) , /*thesharnews(amodel->NbEntities()) , */
54      thesharings (amodel->NbEntities()) 
55 {
56   theflags.AddFlag ("ShareError");  // -> flag n0 1
57   Evaluate(gtool->Lib(),gtool);
58 }
59
60     Interface_Graph::Interface_Graph
61   (const Handle(Interface_InterfaceModel)& amodel)
62    : themodel   (amodel) , thepresents ("") , 
63      thestats (0,amodel->NbEntities()) , theflags   (amodel->NbEntities(),2) ,  
64      theshareds (amodel->NbEntities()) , 
65      /*thesharnews(amodel->NbEntities()) ,*/ thesharings (amodel->NbEntities())
66 {
67   theflags.AddFlag ("ShareError");  // -> flag n0 1
68   Handle(Interface_GTool) gtool = amodel->GTool();
69   if (gtool.IsNull()) return;
70   gtool->Reservate(amodel->NbEntities());
71   Evaluate (gtool->Lib(),gtool);
72 }
73
74     void Interface_Graph::Evaluate
75   (const Interface_GeneralLib& lib, const Handle(Interface_GTool)& gtool)
76 {
77 //  Evaluation d un Graphe de dependances : sur chaque Entite, on prend sa
78 //  liste "Shared". On en deduit les "Sharing"  directement
79
80   Standard_Boolean patool = gtool.IsNull();
81   Standard_Integer n = Size(), total = 0;
82   theshareds.Clear();
83   thesharings.Clear();
84   TColStd_Array1OfInteger counts (0,n); counts.Init(0);
85   TColStd_Array1OfInteger lasts  (0,n); lasts.Init(0);
86   Standard_Integer i; // svv Jan11 2000 : porting on DEC
87   for (i = 1; i <= n; i ++) {
88     theshareds.SetNumber (i);
89
90 //    ATTENTION : Si Entite non chargee donc illisible, basculer sur son
91 //    "Contenu" equivalent
92     Handle(Standard_Transient) ent = themodel->Value(i);
93     if (themodel->IsRedefinedContent(i)) ent = themodel->ReportEntity(i)->Content();
94
95 //    Resultat obtenu via GeneralLib
96     Interface_EntityIterator iter;
97     Handle(Interface_GeneralModule) module;
98     Standard_Integer CN;
99
100     if (patool) {
101       if (lib.Select(ent,module,CN))  module->FillShared(themodel,CN,ent,iter);
102     } else {
103       if (gtool->Select(ent,module,CN))  module->FillShared(themodel,CN,ent,iter);
104     }
105
106     theshareds.Reservate (iter.NbEntities());
107 //    Mise en forme : liste d entiers
108     for (iter.Start(); iter.More(); iter.Next()) {
109 //    num = 0 -> on sort du Model de depart, le noter "Error" et passer
110       Standard_Integer num = EntityNumber(iter.Value());
111       if (num == 0)  theflags.SetTrue (i,Graph_ShareError);
112       else {
113 //  controle d unicite de couple (pere-fils)
114         if (lasts(num) == i) continue;
115         total ++;
116         lasts.ChangeValue(num) = i;
117         theshareds.Add (num);
118         counts.ChangeValue(num) ++;
119 //  References inverses : plus tard
120       }
121     }
122   }
123
124 //  Les references inverses : preallocation (pour compte > 1 seulement)
125
126   thesharings.SetNumber(0);  thesharings.Reservate (total);
127   for (i = 1; i <= n; i ++) {
128     if (counts(i) < 2) continue;
129     thesharings.SetNumber(i);
130     thesharings.Reservate (-counts(i));
131   }
132 //  Enregistrement par inversion
133   for (i = 1; i <= n; i ++) {
134     theshareds.SetNumber (i);
135     Standard_Integer j,num, nb = theshareds.Length();
136     for (j = 1; j <= nb; j ++) {
137       num = theshareds.Value(j);
138       thesharings.SetNumber(-num);
139       thesharings.Add(-i);
140     }
141   }
142
143 }
144
145     void Interface_Graph::EvalSharings ()
146 {
147   thesharings.Clear();
148   Standard_Integer n = thesharings.NbEntities();
149
150 // Difference avec Evaluate : SharedNums prend les Redefinis si necessaire
151
152   for (Standard_Integer i = 1; i <= n; i ++) {
153     Standard_Integer nb, num;
154     if (thesharnews.IsRedefined(i)) {
155       thesharnews.SetNumber(i);
156       nb = thesharnews.Length();
157       for (Standard_Integer j = 1; j <= nb; j ++) {
158         num = thesharnews.Value (j);
159         thesharings.SetNumber (num);
160         thesharings.Reservate (thesharings.Length()+1);
161         thesharings.Add (i);
162       }
163     } else {
164       theshareds.SetNumber(i);
165       nb = theshareds.Length();
166       for (Standard_Integer j = 1; j <= nb; j ++) {
167         num = theshareds.Value (j);
168         thesharings.SetNumber (num);
169         thesharings.Reservate (thesharings.Length()+1);
170         thesharings.Add (i);
171       }
172     }
173   }
174 }
175
176
177 //  ....                Construction depuis un autre Graph                ....
178
179     Interface_Graph::Interface_Graph
180   (const Interface_Graph& agraph, const Standard_Boolean /*copied*/)
181     : themodel   (agraph.Model()), thepresents ("") , 
182       thestats (0,agraph.Size()) , 
183       theflags   (agraph.BitMap(),Standard_True) , 
184       theshareds  (agraph.BasicSharedTable(),Standard_True) ,
185       thesharnews (agraph.RedefinedSharedTable(),Standard_True) ,
186       thesharings (agraph.SharingTable(),Standard_True)
187 {
188   Standard_Integer nb = Size();
189   for (Standard_Integer i = 1; i <= nb; i ++)
190     thestats.SetValue (i,agraph.Status(i));
191 }
192
193     Interface_IntList  Interface_Graph::BasicSharedTable () const
194       {  return theshareds;  }
195
196     Interface_IntList  Interface_Graph::RedefinedSharedTable () const
197       {  return thesharnews;  }
198
199     Interface_IntList  Interface_Graph::SharingTable () const
200       {  return thesharings;  }
201
202
203 //  ###########################################################################
204
205 //  ....                ACCES UNITAIRES AUX DONNEES DE BASE                ....
206
207     void  Interface_Graph::Reset ()
208 {
209   thestats.Init(0);
210   theflags.Init (Standard_False, Graph_Present);
211   thesharnews.Clear();
212   EvalSharings();
213 }
214
215     void  Interface_Graph::ResetStatus ()
216       {    thestats.Init(0);  theflags.Init (Standard_False, Graph_Present);  }
217
218
219     Standard_Integer  Interface_Graph::Size () const 
220       {  return thestats.Upper();  }
221
222     Standard_Integer  Interface_Graph::EntityNumber
223   (const Handle(Standard_Transient)& ent) const 
224      {  return themodel->Number(ent);  }
225
226     Standard_Boolean  Interface_Graph::IsPresent
227   (const Standard_Integer num) const 
228 {
229   if (num <= 0 || num > Size()) return Standard_False;
230   return theflags.Value (num,Graph_Present);
231 }
232
233     Standard_Boolean  Interface_Graph::IsPresent
234   (const Handle(Standard_Transient)& ent) const 
235       {  return IsPresent(EntityNumber(ent));  }
236
237     const Handle(Standard_Transient)&  Interface_Graph::Entity
238   (const Standard_Integer num) const 
239       {  return themodel->Value(num);  }
240
241
242     Standard_Integer  Interface_Graph::Status (const Standard_Integer num) const
243       {  return thestats.Value(num);  }
244
245     Standard_Integer&  Interface_Graph::CStatus (const Standard_Integer num)
246       {  return thestats.ChangeValue(num);  }
247
248     void  Interface_Graph::SetStatus
249   (const Standard_Integer num, const Standard_Integer stat)
250       {  thestats.SetValue(num,stat);  }
251
252     void  Interface_Graph::RemoveItem(const Standard_Integer num)
253 {
254   thestats.SetValue(num,0);  theflags.SetFalse (num,Graph_Present);
255 }
256
257     void  Interface_Graph::ChangeStatus
258   (const Standard_Integer oldstat, const Standard_Integer newstat)
259 {
260   Standard_Integer nb = thestats.Upper();
261   for (Standard_Integer i = 1; i <= nb; i ++) {
262     if (thestats.Value(i) == oldstat) thestats.SetValue(i,newstat);
263   }
264 }
265
266     void  Interface_Graph::RemoveStatus(const Standard_Integer stat)
267 {
268   Standard_Integer nb = thestats.Upper();
269   for (Standard_Integer i = 1; i <= nb; i ++) {
270     if (thestats.Value(i) == stat) RemoveItem(i);
271   }
272 }
273
274     const Interface_BitMap&  Interface_Graph::BitMap () const
275       {  return theflags;  }
276
277     Interface_BitMap&  Interface_Graph::CBitMap ()
278       {  return theflags;  }
279
280
281 //  ###########################################################################
282
283 //  ....      Chargements Elementaires avec Propagation de "Share"      .... //
284
285     const Handle(Interface_InterfaceModel)&  Interface_Graph::Model() const 
286       {  return themodel;  }
287
288     void  Interface_Graph::GetFromModel ()
289 {
290   if (themodel.IsNull()) return;    // no model ... (-> on n ira pas loin)
291   theflags.Init (Standard_True,Graph_Present);
292   thestats.Init (0);
293 }
294
295     void  Interface_Graph::GetFromEntity
296   (const Handle(Standard_Transient)& ent, const Standard_Boolean shared,
297    const Standard_Integer newstat)
298 {
299   Standard_Integer num = EntityNumber(ent);
300   if (num == 0) return;
301   if (theflags.CTrue(num,Graph_Present)) return;  // deja pris : on passe
302   thestats.SetValue(num,newstat);
303   if (!shared) return;
304 //  Attention a la redefinition !
305   Interface_IntList list = thesharnews;
306   if (!list.IsRedefined(num)) list = theshareds;
307   list.SetNumber (num);
308
309   Standard_Integer nb = list.Length();
310   for (Standard_Integer i = 1; i <= nb; i ++)    GetFromEntity
311     (themodel->Value (list.Value(i)),Standard_True,newstat);
312 }
313
314     void  Interface_Graph::GetFromEntity
315   (const Handle(Standard_Transient)& ent, const Standard_Boolean shared,
316    const Standard_Integer newstat, const Standard_Integer overlapstat,
317    const Standard_Boolean cumul)
318 {
319   Standard_Integer num   = EntityNumber(ent);
320   if (num == 0) return;
321   Standard_Boolean pasla = !theflags.CTrue (num,Graph_Present);
322   Standard_Integer stat  = thestats.Value(num); 
323
324   if (pasla) {
325 ///    theflags.SetTrue (num, Graph_Present);   // nouveau : noter avec newstat
326     thestats.SetValue(num,newstat);
327   } else {
328     Standard_Integer overstat = stat;
329     if (stat != newstat) {                   // deja pris, meme statut : passer
330       if (cumul) overstat += overlapstat;    // nouveau statut : avec cumul ...
331       else       overstat  = overlapstat;    // ... ou sans (statut force)
332       if (stat != overstat)                  // si repasse deja faite, passer
333         thestats.SetValue(num,overstat);
334     }
335   }
336   if (!shared) return;
337 //  Attention a la redefinition !
338   Interface_IntList list = thesharnews;
339   if (!list.IsRedefined(num)) list = theshareds;
340   list.SetNumber (num);
341   Standard_Integer nb = list.Length();
342   for (Standard_Integer i = 1; i <= nb; i ++)    GetFromEntity
343     (themodel->Value (list.Value(i)),Standard_True,newstat);
344 }
345
346
347
348     void  Interface_Graph::GetFromIter
349   (const Interface_EntityIterator& iter, const Standard_Integer newstat)
350 {
351   for (iter.Start(); iter.More(); iter.Next()) {
352     Handle(Standard_Transient) ent = iter.Value();
353     Standard_Integer num = EntityNumber(ent);
354     if (num == 0) continue;
355     if (theflags.CTrue(num,Graph_Present)) continue;
356     thestats.SetValue(num,newstat);
357   }
358 }
359
360
361     void  Interface_Graph::GetFromIter
362   (const Interface_EntityIterator& iter,
363    const Standard_Integer newstat, const Standard_Integer overlapstat,
364    const Standard_Boolean cumul)
365 {
366   for (iter.Start(); iter.More(); iter.Next()) {
367     Handle(Standard_Transient) ent = iter.Value();
368     Standard_Integer num   = EntityNumber(ent);
369     if (num == 0) continue;
370     /*Standard_Boolean pasla = !*/theflags.Value(num,Graph_Present);
371     /*Standard_Integer stat  = */thestats.Value(num); 
372     GetFromEntity (ent,Standard_False,newstat,overlapstat,cumul);
373   }
374 }
375
376
377     void Interface_Graph::GetFromGraph (const Interface_Graph& agraph)
378 {
379   if (Model() != agraph.Model()) Standard_DomainError::Raise
380     ("Graph from Interface : GetFromGraph");
381   Standard_Integer nb = Size();
382   for (Standard_Integer i = 1; i <= nb; i ++) {
383     if (agraph.IsPresent(i))
384       GetFromEntity (agraph.Entity(i),Standard_False,agraph.Status(i));
385   }
386 }
387
388     void Interface_Graph::GetFromGraph
389   (const Interface_Graph& agraph, const Standard_Integer stat)
390 {
391   if (Model() != agraph.Model()) Standard_DomainError::Raise
392     ("Graph from Interface : GetFromGraph");
393   Standard_Integer nb = Size();
394   for (Standard_Integer i = 1; i <= nb; i ++) {
395     if (agraph.IsPresent(i) && agraph.Status(i) == stat)
396       GetFromEntity (agraph.Entity(i),Standard_False,stat);
397   }
398 }
399
400 //  #####################################################################
401
402 //  ....                Listage des Entites Partagees                ....
403
404     Standard_Boolean Interface_Graph::HasShareErrors
405   (const Handle(Standard_Transient)& ent) const
406 {
407   Standard_Integer num   = EntityNumber(ent);
408   if (num == 0) return Standard_True;
409   return theflags.Value (num,Graph_ShareError);
410 }
411
412 //  A chaque entite, on peut attacher une Liste de numeros d entites partagees
413 //  Si elle est nulle, BasicShareds convient, sinon on prend RedefinedShareds
414
415     Standard_Boolean Interface_Graph::HasRedefinedShareds
416   (const Handle(Standard_Transient)& ent) const
417 {
418   Standard_Integer num   = EntityNumber(ent);
419   if (num == 0) return Standard_False;
420   return thesharnews.IsRedefined (num);
421 }
422
423     Interface_EntityIterator Interface_Graph::Shareds
424   (const Handle(Standard_Transient)& ent) const
425 {
426   Standard_Integer num   = EntityNumber(ent);
427   if (num == 0)  Standard_DomainError::Raise ("Interface : Shareds");
428
429   Interface_EntityIterator iter;
430   Interface_IntList list = thesharnews;
431   if (!list.IsRedefined(num)) list = theshareds;
432   list.SetNumber (num);
433   Standard_Integer nb = list.Length();
434   for (Standard_Integer i = 1; i <= nb; i ++)
435     iter.GetOneItem (themodel->Value (list.Value(i) ));
436   return iter;
437 }
438
439     Interface_IntList  Interface_Graph::SharedNums
440   (const Standard_Integer num) const
441 {
442   Interface_IntList list = thesharnews;
443   if (!list.IsRedefined(num)) list = theshareds;
444   list.SetNumber (num);
445   return list;
446 }
447
448     Interface_EntityIterator Interface_Graph::Sharings
449   (const Handle(Standard_Transient)& ent) const
450 {
451   Standard_Integer num   = EntityNumber(ent);
452   if (num == 0) Standard_DomainError::Raise ("Interface : Sharings");
453
454   Interface_EntityIterator iter;
455   Interface_IntList list = thesharings;  list.SetNumber (num);
456   Standard_Integer nb = list.Length();
457   for (Standard_Integer i = 1; i <= nb; i ++)
458     iter.GetOneItem (themodel->Value(list.Value(i)));
459   return iter;
460 }
461
462     Interface_IntList Interface_Graph::SharingNums
463   (const Standard_Integer num) const
464 {
465   Interface_IntList list = thesharings;
466   if (num > 0) list.SetNumber (num);
467   return list;
468 }
469
470
471 static void AddTypedSharings
472   (const Handle(Standard_Transient)& ent, const Handle(Standard_Type)& type,
473    Interface_EntityIterator& iter, const Standard_Integer n,
474    const Interface_Graph& G)
475 {
476   if (ent.IsNull()) return;
477   if (ent->IsKind(type))  {  iter.AddItem (ent);  return;  }
478   if (iter.NbEntities() > n) return;
479
480   Interface_IntList list = G.SharingNums(G.EntityNumber(ent));
481   Standard_Integer nb = list.Length();
482   for (Standard_Integer i = 1; i <= nb; i ++)
483     AddTypedSharings (G.Entity(list.Value(i)) ,type,iter,nb,G);
484 }
485
486     Interface_EntityIterator Interface_Graph::TypedSharings
487   (const Handle(Standard_Transient)& ent, const Handle(Standard_Type)& type) const
488 {
489   Interface_EntityIterator iter;
490   Standard_Integer n = Size();
491   AddTypedSharings (ent,type,iter,n,*this);
492   return iter;
493 }
494   
495
496     Interface_EntityIterator Interface_Graph::RootEntities () const
497 {
498   Interface_EntityIterator iter;
499   Standard_Integer nb = Size();
500   Interface_IntList list (thesharings);
501   for (Standard_Integer i = 1; i <= nb; i ++) {
502     list.SetNumber (i);
503     if (list.Length() == 0) iter.GetOneItem (themodel->Value(i));
504   }
505   return iter;
506 }
507
508
509 //  ######################################################################
510
511 //  ....                Redefinition des listes Shared-Sharing        ....
512
513     void Interface_Graph::SetShare
514   (const Handle(Standard_Transient)& ent)
515 {
516   Standard_Integer num = EntityNumber(ent);
517   if (num == 0) return;
518   SetShare (ent,SharedNums(num));
519 }
520
521     void Interface_Graph::SetShare
522   (const Handle(Standard_Transient)& ent,
523    const Interface_EntityIterator& list)
524 {
525   if(!thesharnews.NbEntities())
526     thesharnews.Initialize(themodel->NbEntities());
527   Standard_Integer num   = EntityNumber(ent);
528   if (num == 0) return;
529   thesharnews.SetNumber (num);
530   thesharnews.SetRedefined (Standard_True);
531   thesharnews.Reservate (list.NbEntities());
532
533   for (list.Start(); list.More(); list.Next()) {
534     Standard_Integer nsh = EntityNumber(list.Value());
535     if (nsh != 0) thesharnews.Add (nsh);
536   }
537 }
538
539     void Interface_Graph::SetShare
540   (const Handle(Standard_Transient)& ent, const Interface_IntList& list)
541 {
542   Standard_Integer num   = EntityNumber(ent);
543   if (num == 0) return;
544   if(!thesharnews.NbEntities())
545     thesharnews.Initialize(themodel->NbEntities());
546   Standard_Integer i, n = list.Length();
547   thesharnews.SetNumber (num);
548   thesharnews.SetRedefined (Standard_True);
549   thesharnews.Reservate (n);
550   for (i = 1; i <= n; i ++) {
551     Standard_Integer nsh = list.Value(i);
552     if (nsh != 0) thesharnews.Add (nsh);
553   }
554 }
555
556     void Interface_Graph::SetNoShare
557   (const Handle(Standard_Transient)& ent)
558 {
559   Standard_Integer num   = EntityNumber(ent);
560   if (num == 0) return;
561   if(!thesharnews.NbEntities()) return;
562    
563   thesharnews.SetNumber (num);
564   thesharnews.SetRedefined (Standard_False);
565 }
566
567     void Interface_Graph::SetNoShare (const Interface_EntityIterator& list)
568 {
569   for (list.Start(); list.More(); list.Next()) SetNoShare(list.Value());
570 }
571
572     void Interface_Graph::AddShared
573   (const Handle(Standard_Transient)& ent,
574    const Handle(Standard_Transient)& shared)
575 {
576   //Standard_Integer i, nb; svv Feb21 2000 : porting on SIL
577   Standard_Integer num   = EntityNumber(ent);
578   Standard_Integer nsh   = EntityNumber(shared);
579   
580   if (!thesharnews.IsRedefined(num) || num == 0 || nsh == 0) Standard_DomainError::Raise
581     ("Interface Graph : AddShared, cannot be applied");
582   if(!thesharnews.NbEntities()) 
583     thesharnews.Initialize(themodel->NbEntities());
584 //   Liste Shared(ent)
585   thesharnews.SetNumber (num);
586   thesharnews.Reservate (thesharnews.Length()+1);
587   thesharnews.Add (nsh);
588
589 //  Liste Sharing(shared)
590   thesharings.SetNumber (nsh);
591   thesharings.Reservate (thesharings.Length()+1);
592   thesharings.Add (num);
593 }
594
595
596     void Interface_Graph::RemoveShared
597   (const Handle(Standard_Transient)& ent,
598    const Handle(Standard_Transient)& shared)
599 {
600   Standard_Integer num   = EntityNumber(ent);
601   Standard_Integer nsh   = EntityNumber(shared);
602   if (!thesharnews.IsRedefined(num) || num == 0 || nsh == 0) Standard_DomainError::Raise
603     ("Interface Graph : RemoveShared, cannot be applied");
604
605 //  Liste Shared (ent)
606   if(!thesharnews.NbEntities()) 
607     thesharnews.Initialize(themodel->NbEntities());
608   
609   thesharnews.SetNumber (num);
610   Standard_Integer i,nbsh = thesharnews.Length();
611   for (i = nbsh; i > 0; i --)
612     if (thesharnews.Value(i) == nsh) thesharnews.Remove(i);
613
614 //  Liste Sharing (shared)
615   thesharings.SetNumber (nsh);
616   nbsh = thesharings.Length();
617   for (i = nbsh; i > 0; i --)
618     if (thesharings.Value(i) == num) thesharings.Remove(i);
619 }
620
621
622     void Interface_Graph::ResetShare
623   (const Handle(Standard_Transient)& ent)
624 {
625   Standard_Integer num   = EntityNumber(ent);
626   if (num == 0) return;
627
628   Interface_IntList snew(thesharnews);
629   
630   if (!thesharnews.NbEntities() || !snew.IsRedefined(num)) return;
631   snew.SetNumber (num);
632   Interface_IntList sold(theshareds);
633   sold.SetNumber (num);
634
635 //  Attention aux Sharings ... Il va falloir ajouter, supprimer ... laisser !
636 //  Tableau // Entites : 0 hors jeu  1 reapparait  2 disparait  3 reste 
637
638   Standard_Integer n = Size();
639   TColStd_Array1OfInteger oldnew(1,n); oldnew.Init(0);
640   Standard_Integer ns = sold.Length();
641   Standard_Integer i; // svv Jan11 2000 : porting on DEC
642   for (i = 1; i <= ns; i ++)
643     oldnew.SetValue(sold.Value(i),1);    // pourra passer en 3 plus tard ...
644   ns = snew.Length();
645   for (i = 1; i <= ns; i ++) {
646     Standard_Integer oldstat = oldnew.Value(snew.Value(i));
647     oldnew.SetValue(snew.Value(i),oldstat+2);  // 0 -> 2, 1 -> 3
648   }
649
650 //  Muni de ces donnees, on pourra modifier les listes Sharings impliquees
651   for (i = 1; i <= n; i ++) {
652     Standard_Integer oldstat = oldnew.Value(snew.Value(i));
653     if (oldstat == 0 || oldstat == 2) continue;
654     thesharings.SetNumber(i);
655     if (oldstat == 1) {
656       thesharings.Reservate (thesharings.Length()+1);
657       thesharings.Add (num);
658     } else if (oldstat == 3) {
659       Standard_Integer j,nbsh = thesharings.Length();
660       for (j = nbsh; j > 0; j --)
661         if (thesharings.Value(j) == num) thesharings.Remove(j);
662     }
663   }
664
665 //  Shared : beaucoup plus simple, ANNULER Redefined
666   thesharnews.SetRedefined (Standard_False);
667 }
668
669     void Interface_Graph::ResetAllShare ()
670 {
671   thesharnews.Clear();
672   EvalSharings();
673 }
674
675
676     Handle(TCollection_HAsciiString)  Interface_Graph::Name
677   (const Handle(Standard_Transient)& ent) const
678 {
679   Handle(TCollection_HAsciiString) str;
680   if (themodel.IsNull()) return str;
681   if (themodel->Number(ent)) return str;
682
683   Handle(Interface_GTool) gtool = themodel->GTool();
684   if (gtool.IsNull()) return str;
685
686   Handle(Interface_GeneralModule) module;
687   Standard_Integer CN;
688   if (!gtool->Select(ent,module,CN)) return str;
689
690   Interface_ShareTool sht (*this);
691   return module->Name (CN,ent,sht);
692 }