1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <IFGraph_SubPartsIterator.hxx>
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_Graph.hxx>
18 #include <Interface_GraphContent.hxx>
19 #include <Interface_InterfaceError.hxx>
20 #include <Interface_InterfaceModel.hxx>
21 #include <Standard_NoSuchObject.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <Standard_Transient.hxx>
24 #include <TColStd_Array1OfInteger.hxx>
26 // SubPartsIterator permet de regrouper les entites en plusieurs sous-parties
27 // A chaque sous-partie est attache un Status : la 1re a 1, la 2e a 2, etc...
28 // (consequence, les sous-parties sont necessairement disjointes)
29 IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
30 (const Interface_Graph& agraph, const Standard_Boolean whole)
33 if (whole) thegraph.GetFromModel();
34 theparts = new TColStd_HSequenceOfInteger();
35 thefirsts = new TColStd_HSequenceOfInteger();
40 IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
41 (IFGraph_SubPartsIterator& other)
42 : thegraph (other.Graph())
44 Standard_Integer nb = thegraph.Size();
45 theparts = new TColStd_HSequenceOfInteger();
47 for (other.Start(); other.More(); other.Next()) {
49 Standard_Integer nbent = 0;
50 GetFromIter (other.Entities());
51 for (Standard_Integer i = 1; i <= nb; i ++) {
52 if (thegraph.Status(i) == thepart) nbent ++;
54 theparts->Append(nbent); // compte vide
60 void IFGraph_SubPartsIterator::GetParts
61 (IFGraph_SubPartsIterator& other)
63 if (Model() != other.Model()) throw Interface_InterfaceError("SubPartsIterator : GetParts");
64 // On AJOUTE les Parts de other, sans perdre les siennes propres
65 // (meme principe que le constructeur ci-dessus)
66 Standard_Integer nb = thegraph.Size();
67 thepart = theparts->Length();
68 for (other.Start(); other.More(); other.Next()) {
70 Standard_Integer nbent = 0;
71 GetFromIter (other.Entities());
72 for (Standard_Integer i = 1; i <= nb; i ++) {
73 if (thegraph.Status(i) == thepart) nbent ++;
75 theparts->Append(nbent); // compte vide
79 const Interface_Graph& IFGraph_SubPartsIterator::Graph () const
82 // .... Gestion Interne (remplissage, etc...) .... //
84 Handle(Interface_InterfaceModel) IFGraph_SubPartsIterator::Model() const
85 { return thegraph.Model(); }
87 void IFGraph_SubPartsIterator::AddPart ()
89 theparts->Append( Standard_Integer(0) );
90 thepart = theparts->Length();
93 Standard_Integer IFGraph_SubPartsIterator::NbParts () const
94 { return theparts->Length(); }
96 Standard_Integer IFGraph_SubPartsIterator::PartNum () const
99 void IFGraph_SubPartsIterator::SetLoad ()
102 void IFGraph_SubPartsIterator::SetPartNum (const Standard_Integer num)
104 if (num <= 0 || num > theparts->Length()) throw Standard_OutOfRange("IFGraph_SubPartsIterator : SetPartNum");
108 void IFGraph_SubPartsIterator::GetFromEntity
109 (const Handle(Standard_Transient)& ent, const Standard_Boolean shared)
111 thegraph.GetFromEntity(ent,shared, thepart,thepart,Standard_False);
114 void IFGraph_SubPartsIterator::GetFromIter (const Interface_EntityIterator& iter)
116 thegraph.GetFromIter(iter, thepart,thepart, Standard_False);
119 void IFGraph_SubPartsIterator::Reset ()
128 // .... Resultat (Evaluation, Iterations) .... //
130 void IFGraph_SubPartsIterator::Evaluate ()
131 { } // par defaut, ne fait rien; redefinie par les sous-classes
133 Interface_GraphContent IFGraph_SubPartsIterator::Loaded () const
135 Interface_EntityIterator iter;
136 // Standard_Integer nb = thegraph.Size();
137 return Interface_GraphContent(thegraph,0);
140 Interface_Graph IFGraph_SubPartsIterator::LoadedGraph () const
142 Interface_Graph G(Model());
143 Standard_Integer nb = thegraph.Size();
144 for (Standard_Integer i = 1; i <= nb; i ++) {
145 if (thegraph.IsPresent(i) && thegraph.Status(i) == 0)
146 G.GetFromEntity(thegraph.Entity(i),Standard_False);
152 Standard_Boolean IFGraph_SubPartsIterator::IsLoaded
153 (const Handle(Standard_Transient)& ent) const
154 { return thegraph.IsPresent(thegraph.EntityNumber(ent)); }
156 Standard_Boolean IFGraph_SubPartsIterator::IsInPart
157 (const Handle(Standard_Transient)& ent) const
159 Standard_Integer num = thegraph.EntityNumber(ent);
160 if (!thegraph.IsPresent(num)) return Standard_False;
161 return (thegraph.Status(num) != 0);
164 Standard_Integer IFGraph_SubPartsIterator::EntityPartNum
165 (const Handle(Standard_Transient)& ent) const
167 Standard_Integer num = thegraph.EntityNumber(ent);
168 if (!thegraph.IsPresent(num)) return 0;
169 return thegraph.Status(num);
173 void IFGraph_SubPartsIterator::Start ()
176 // On evalue les tailles des contenus des Parts
177 Standard_Integer nb = thegraph.Size();
178 Standard_Integer nbp = theparts->Length();
179 if (thepart > nbp) thepart = nbp;
180 if (nbp == 0) { thecurr = 1; return; } // L Iteration s arrete de suite
182 // - On fait les comptes (via tableaux pour performances)
183 TColStd_Array1OfInteger partcounts (1,nbp); partcounts.Init(0);
184 TColStd_Array1OfInteger partfirsts (1,nbp); partfirsts.Init(0);
185 for (Standard_Integer i = 1; i <= nb; i ++) {
186 if (!thegraph.IsPresent(i)) continue;
187 Standard_Integer nump = thegraph.Status(i);
188 if (nump < 1 || nump > nbp) continue;
189 Standard_Integer nbent = partcounts.Value(nump);
190 partcounts.SetValue(nump,nbent+1);
191 if (nbent == 0) partfirsts.SetValue(nump,i);
193 // - On les met en forme (c-a-d dans les sequences)
194 theparts->Clear(); thefirsts->Clear();
195 Standard_Integer lastp = 0;
196 for (Standard_Integer np = 1; np <= nbp; np ++) {
197 Standard_Integer nbent = partcounts.Value(np);
198 if (np != 0) lastp = np;
199 theparts->Append (nbent);
200 thefirsts->Append (partfirsts.Value(np));
202 if (lastp < nbp) theparts->Remove(lastp+1,nbp);
203 // Enfin, on se prepare a iterer
207 Standard_Boolean IFGraph_SubPartsIterator::More ()
209 if (thecurr == 0) Start();
210 return (thecurr <= theparts->Length());
213 void IFGraph_SubPartsIterator::Next ()
215 thecurr ++; if (thecurr > theparts->Length()) return;
216 if (theparts->Value(thecurr) == 0) Next(); // sauter parties vides
219 Standard_Boolean IFGraph_SubPartsIterator::IsSingle () const
221 if (thecurr < 1 || thecurr > theparts->Length()) throw Standard_NoSuchObject("IFGraph_SubPartsIterator : IsSingle");
222 return (theparts->Value(thecurr) == 1);
225 Handle(Standard_Transient) IFGraph_SubPartsIterator::FirstEntity
228 if (thecurr < 1 || thecurr > theparts->Length()) throw Standard_NoSuchObject("IFGraph_SubPartsIterator : FirstEntity");
229 Standard_Integer nument = thefirsts->Value(thecurr);
230 if (nument == 0) throw Standard_NoSuchObject("IFGraph_SubPartsIterator : FirstEntity (current part is empty)");
231 return thegraph.Entity(nument);
234 Interface_EntityIterator IFGraph_SubPartsIterator::Entities () const
236 if (thecurr < 1 || thecurr > theparts->Length()) throw Standard_NoSuchObject("IFGraph_SubPartsIterator : Entities");
237 Interface_EntityIterator iter;
238 Standard_Integer nb = thegraph.Size();
239 Standard_Integer nument = thefirsts->Value(thecurr);
240 if (nument == 0) return iter;
241 if (theparts->Value(thecurr) == 1) nb = nument; // evident : 1 seule Entite
242 for (Standard_Integer i = nument; i <= nb; i ++) {
243 if (thegraph.Status(i) == thecurr && thegraph.IsPresent(i))
244 iter.GetOneItem(thegraph.Entity(i));
249 //=======================================================================
250 //function : ~IFGraph_SubPartsIterator
252 //=======================================================================
254 IFGraph_SubPartsIterator::~IFGraph_SubPartsIterator()