1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <Interface_Graph.ixx>
19 #include <Interface_GeneralModule.hxx>
20 #include <Interface_ReportEntity.hxx>
21 #include <Standard_DomainError.hxx>
22 #include <TColStd_Array1OfInteger.hxx>
23 #include <Interface_ShareTool.hxx>
24 #include <TColStd_HSequenceOfTransient.hxx>
25 #include <TColStd_ListIteratorOfListOfInteger.hxx>
26 #include <Interface_GTool.hxx>
28 // Flags : 0 = Presence, 1 = Sharing Error
29 #define Graph_Present 0
30 #define Graph_ShareError 1
33 // ###########################################################################
35 // .... CONSTRUCTEURS ....
37 // .... Construction a partir de la connaissance des Entites ....
40 Interface_Graph::Interface_Graph
41 (const Handle(Interface_InterfaceModel)& amodel,
42 const Interface_GeneralLib& /*lib*/,
43 Standard_Boolean theModeStat)
44 : themodel (amodel), thepresents ("")
51 Interface_Graph::Interface_Graph
52 (const Handle(Interface_InterfaceModel)& amodel,
53 const Handle(Interface_Protocol)& /*protocol*/,
54 Standard_Boolean theModeStat)
55 : themodel (amodel) , thepresents ("")
63 Interface_Graph::Interface_Graph
64 (const Handle(Interface_InterfaceModel)& amodel,
65 const Handle(Interface_GTool)& /*gtool*/,
66 Standard_Boolean theModeStat)
67 : themodel (amodel) , thepresents ("")
74 Interface_Graph::Interface_Graph
75 (const Handle(Interface_InterfaceModel)& amodel,
76 Standard_Boolean theModeStat)
77 : themodel (amodel) , thepresents ("")
84 // .... Construction depuis un autre Graph ....
86 Interface_Graph::Interface_Graph
87 (const Interface_Graph& agraph, const Standard_Boolean /*copied*/)
88 : themodel (agraph.Model()), thepresents ("")
90 thesharings = agraph.SharingTable();
91 Standard_Integer nb = agraph.NbStatuses();
95 thestats = new TColStd_HArray1OfInteger(1,nb);
96 for (Standard_Integer i = 1; i <= nb; i ++)
97 thestats->SetValue (i,agraph.Status(i));
98 theflags.Initialize(agraph.BitMap(),Standard_True);
101 void Interface_Graph::InitStats()
103 thestats = new TColStd_HArray1OfInteger(1,themodel->NbEntities()) ,
104 theflags.Initialize(themodel->NbEntities(),2);
105 theflags.AddFlag ("ShareError");
108 Standard_Integer Interface_Graph::NbStatuses() const
110 return (thestats.IsNull() ? 0 : thestats->Length());
113 const Handle(TColStd_HArray1OfListOfInteger)& Interface_Graph::SharingTable () const
114 { return thesharings; }
116 void Interface_Graph::Evaluate()
118 // Evaluation d un Graphe de dependances : sur chaque Entite, on prend sa
119 // liste "Shared". On en deduit les "Sharing" directement
120 Standard_Integer n = Size();
121 thesharings = new TColStd_HArray1OfListOfInteger(1,n);//TColStd_HArray1OfTransient(1,n);//Clear();
122 if(themodel->GTool().IsNull())
126 Standard_Integer i; // svv Jan11 2000 : porting on DEC
127 for (i = 1; i <= n; i ++) {
128 // ATTENTION : Si Entite non chargee donc illisible, basculer sur son
129 // "Contenu" equivalent
130 Handle(Standard_Transient) ent = themodel->Value(i);
133 // Resultat obtenu via GeneralLib
134 Interface_EntityIterator iter = GetShareds(ent);
136 // Mise en forme : liste d entiers
137 for (iter.Start(); iter.More(); iter.Next()) {
138 // num = 0 -> on sort du Model de depart, le noter "Error" et passer
139 Handle(Standard_Transient) entshare = iter.Value();
143 Standard_Integer num = EntityNumber(entshare);
147 if(!thestats.IsNull())
148 theflags.SetTrue (i,Graph_ShareError);
151 thesharings->ChangeValue(num).Append(i);
156 // .... Construction depuis un autre Graph ....
159 // ###########################################################################
161 // .... ACCES UNITAIRES AUX DONNEES DE BASE ....
163 void Interface_Graph::Reset ()
165 if(!thestats.IsNull())
168 theflags.Init (Standard_False, Graph_Present);
173 void Interface_Graph::ResetStatus ()
175 if(!thestats.IsNull())
178 theflags.Init (Standard_False, Graph_Present);
183 Standard_Integer Interface_Graph::Size () const
184 { return themodel->NbEntities(); }//thestats.Upper(); }
186 Standard_Integer Interface_Graph::EntityNumber
187 (const Handle(Standard_Transient)& ent) const
188 { return themodel->Number(ent); }
190 Standard_Boolean Interface_Graph::IsPresent
191 (const Standard_Integer num) const
193 if (num <= 0 || num > Size())
194 return Standard_False;
195 return (!thestats.IsNull() ? theflags.Value (num,Graph_Present) : Standard_False);
198 Standard_Boolean Interface_Graph::IsPresent
199 (const Handle(Standard_Transient)& ent) const
200 { return IsPresent(EntityNumber(ent)); }
202 const Handle(Standard_Transient)& Interface_Graph::Entity
203 (const Standard_Integer num) const
205 return themodel->Value(num);
209 Standard_Integer Interface_Graph::Status (const Standard_Integer num) const
211 return (!thestats.IsNull() ? thestats->Value(num) : 0);
214 void Interface_Graph::SetStatus
215 (const Standard_Integer num, const Standard_Integer stat)
217 if(!thestats.IsNull())
218 thestats->SetValue(num,stat);
221 void Interface_Graph::RemoveItem(const Standard_Integer num)
223 if(!thestats.IsNull())
225 thestats->SetValue(num,0);
226 theflags.SetFalse (num,Graph_Present);
230 void Interface_Graph::ChangeStatus
231 (const Standard_Integer oldstat, const Standard_Integer newstat)
233 if(thestats.IsNull())
235 Standard_Integer nb = thestats->Upper();
236 for (Standard_Integer i = 1; i <= nb; i ++) {
237 if (thestats->Value(i) == oldstat)
238 thestats->SetValue(i,newstat);
242 void Interface_Graph::RemoveStatus(const Standard_Integer stat)
244 if(thestats.IsNull())
246 Standard_Integer nb = thestats->Upper();
247 for (Standard_Integer i = 1; i <= nb; i ++) {
248 if (thestats->Value(i) == stat) RemoveItem(i);
252 const Interface_BitMap& Interface_Graph::BitMap () const
255 Interface_BitMap& Interface_Graph::CBitMap ()
258 // ###########################################################################
260 // .... Chargements Elementaires avec Propagation de "Share" .... //
262 const Handle(Interface_InterfaceModel)& Interface_Graph::Model() const
265 void Interface_Graph::GetFromModel ()
267 if (themodel.IsNull() || thestats.IsNull())
268 return; // no model ... (-> on n ira pas loin)
269 theflags.Init (Standard_True,Graph_Present);
273 void Interface_Graph::GetFromEntity
274 (const Handle(Standard_Transient)& ent, const Standard_Boolean shared,
275 const Standard_Integer newstat)
277 if(thestats.IsNull())
279 Standard_Integer num = EntityNumber(ent);
282 if (theflags.CTrue(num,Graph_Present)) return; // deja pris : on passe
283 thestats->SetValue(num,newstat);
285 // Attention a la redefinition !
286 Interface_EntityIterator aIter = GetShareds(ent);
288 for ( ; aIter.More() ; aIter.Next())
289 GetFromEntity(aIter.Value(),Standard_True,newstat);
292 void Interface_Graph::GetFromEntity
293 (const Handle(Standard_Transient)& ent, const Standard_Boolean shared,
294 const Standard_Integer newstat, const Standard_Integer overlapstat,
295 const Standard_Boolean cumul)
297 if(thestats.IsNull())
299 Standard_Integer num = EntityNumber(ent);
301 Standard_Boolean pasla = !theflags.CTrue (num,Graph_Present);
302 Standard_Integer stat = thestats->Value(num);
305 /// theflags.SetTrue (num, Graph_Present); // nouveau : noter avec newstat
306 thestats->SetValue(num,newstat);
308 Standard_Integer overstat = stat;
309 if (stat != newstat) { // deja pris, meme statut : passer
310 if (cumul) overstat += overlapstat; // nouveau statut : avec cumul ...
311 else overstat = overlapstat; // ... ou sans (statut force)
312 if (stat != overstat) // si repasse deja faite, passer
313 thestats->SetValue(num,overstat);
317 // Attention a la redefinition !
318 Interface_EntityIterator aIter = GetShareds(ent);
320 for ( ; aIter.More() ; aIter.Next())
321 GetFromEntity(aIter.Value(),Standard_True,newstat);
324 void Interface_Graph::GetFromIter
325 (const Interface_EntityIterator& iter, const Standard_Integer newstat)
327 if(thestats.IsNull())
329 for (iter.Start(); iter.More(); iter.Next()) {
330 Handle(Standard_Transient) ent = iter.Value();
331 Standard_Integer num = EntityNumber(ent);
334 if (theflags.CTrue(num,Graph_Present))
336 thestats->SetValue(num,newstat);
341 void Interface_Graph::GetFromIter
342 (const Interface_EntityIterator& iter,
343 const Standard_Integer newstat, const Standard_Integer overlapstat,
344 const Standard_Boolean cumul)
346 if(thestats.IsNull())
348 for (iter.Start(); iter.More(); iter.Next()) {
349 Handle(Standard_Transient) ent = iter.Value();
350 Standard_Integer num = EntityNumber(ent);
353 /*Standard_Boolean pasla = !*/theflags.Value(num,Graph_Present);
354 /*Standard_Integer stat = */thestats->Value(num);
355 GetFromEntity (ent,Standard_False,newstat,overlapstat,cumul);
360 void Interface_Graph::GetFromGraph (const Interface_Graph& agraph)
362 if (Model() != agraph.Model()) Standard_DomainError::Raise
363 ("Graph from Interface : GetFromGraph");
364 Standard_Integer nb = Size();
365 for (Standard_Integer i = 1; i <= nb; i ++) {
366 if (agraph.IsPresent(i))
367 GetFromEntity (agraph.Entity(i),Standard_False,agraph.Status(i));
371 void Interface_Graph::GetFromGraph
372 (const Interface_Graph& agraph, const Standard_Integer stat)
374 if (Model() != agraph.Model()) Standard_DomainError::Raise
375 ("Graph from Interface : GetFromGraph");
376 Standard_Integer nb = Size();
377 for (Standard_Integer i = 1; i <= nb; i ++) {
378 if (agraph.IsPresent(i) && agraph.Status(i) == stat)
379 GetFromEntity (agraph.Entity(i),Standard_False,stat);
383 // #####################################################################
385 // .... Listage des Entites Partagees ....
387 Standard_Boolean Interface_Graph::HasShareErrors
388 (const Handle(Standard_Transient)& ent) const
390 if(thestats.IsNull())
391 return Standard_False;
392 Standard_Integer num = EntityNumber(ent);
393 if (num == 0) return Standard_True;
394 return theflags.Value (num,Graph_ShareError);
397 Interface_EntityIterator Interface_Graph::Shareds
398 (const Handle(Standard_Transient)& ent) const
400 Interface_EntityIterator iter;
401 Standard_Integer num = EntityNumber(ent);
405 Handle(Standard_Transient) aCurEnt = ent;
406 if (themodel->IsRedefinedContent(num))
407 aCurEnt = themodel->ReportEntity(num)->Content();
409 //if (num == 0) Standard_DomainError::Raise ("Interface : Shareds");
410 Handle(Interface_GeneralModule) module;
412 if (themodel->GTool()->Select(aCurEnt,module,CN))
413 module->FillShared(themodel,CN,aCurEnt,iter);
417 Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetShareds(const Handle(Standard_Transient)& ent) const
419 Handle(TColStd_HSequenceOfTransient) aseq = new TColStd_HSequenceOfTransient;
420 Interface_EntityIterator iter = Shareds(ent);
421 for( ; iter.More(); iter.Next())
422 aseq->Append(iter.Value());
426 Handle(TColStd_HSequenceOfTransient) Interface_Graph::GetSharings(const Handle(Standard_Transient)& ent) const
428 Standard_Integer num = EntityNumber(ent);
431 //return Handle(TColStd_HSequenceOfTransient)::DownCast(thesharings->Value(num));
432 const TColStd_ListOfInteger& alist = thesharings->Value(num);
433 Handle(TColStd_HSequenceOfTransient) aSharings = new TColStd_HSequenceOfTransient;
434 TColStd_ListIteratorOfListOfInteger aIt(alist);
435 for( ; aIt.More() ; aIt.Next())
436 aSharings->Append(Entity(aIt.Value()));
440 Interface_EntityIterator Interface_Graph::Sharings
441 (const Handle(Standard_Transient)& ent) const
443 Interface_EntityIterator iter;
444 iter.AddList(GetSharings(ent));
449 static void AddTypedSharings
450 (const Handle(Standard_Transient)& ent, const Handle(Standard_Type)& type,
451 Interface_EntityIterator& iter, const Standard_Integer n,
452 const Interface_Graph& G)
454 if (ent.IsNull()) return;
455 if (ent->IsKind(type)) { iter.AddItem (ent); return; }
456 if (iter.NbEntities() > n) return;
458 Handle(TColStd_HSequenceOfTransient) list = G.GetSharings(ent);
462 Standard_Integer nb = list->Length();
463 for (Standard_Integer i = 1; i <= nb; i ++)
464 AddTypedSharings (list->Value(i) ,type,iter,nb,G);
467 Interface_EntityIterator Interface_Graph::TypedSharings
468 (const Handle(Standard_Transient)& ent, const Handle(Standard_Type)& type) const
470 Interface_EntityIterator iter;
471 Standard_Integer n = Size();
472 AddTypedSharings (ent,type,iter,n,*this);
477 Interface_EntityIterator Interface_Graph::RootEntities () const
479 Interface_EntityIterator iter;
480 Standard_Integer nb = thesharings->Length();
481 for (Standard_Integer i = 1; i <= nb; i ++) {
482 if(!thesharings->Value(i).IsEmpty())
484 iter.AddItem(Entity(i));
489 Handle(TCollection_HAsciiString) Interface_Graph::Name(const Handle(Standard_Transient)& ent) const
491 Handle(TCollection_HAsciiString) str;
492 if (themodel.IsNull()) return str;
493 if (themodel->Number(ent)) return str;
495 Handle(Interface_GTool) gtool = themodel->GTool();
496 if (gtool.IsNull()) return str;
498 Handle(Interface_GeneralModule) module;
500 if (!gtool->Select(ent,module,CN)) return str;
502 Interface_ShareTool sht (*this);
503 return module->Name (CN,ent,sht);
506 Standard_Boolean Interface_Graph::ModeStat() const
508 return (!thestats.IsNull());