Integration of OCCT 6.5.0 from SVN
[occt.git] / src / IFGraph / IFGraph_SubPartsIterator.cxx
CommitLineData
7fd59977 1#include <IFGraph_SubPartsIterator.ixx>
2#include <TColStd_Array1OfInteger.hxx>
3#include <Interface_InterfaceError.hxx>
4#include <Standard_NoSuchObject.hxx>
5
6
7
8// SubPartsIterator permet de regrouper les entites en plusieurs sous-parties
9// A chaque sous-partie est attache un Status : la 1re a 1, la 2e a 2, etc...
10// (consequence, les sous-parties sont necessairement disjointes)
11
12 IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
13 (const Interface_Graph& agraph, const Standard_Boolean whole)
14 : thegraph (agraph)
15{
16 if (whole) thegraph.GetFromModel();
17 theparts = new TColStd_HSequenceOfInteger();
18 thefirsts = new TColStd_HSequenceOfInteger();
19 thepart = 0;
20 thecurr = 0;
21}
22
23 IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
24 (IFGraph_SubPartsIterator& other)
25 : thegraph (other.Graph())
26{
27 Standard_Integer nb = thegraph.Size();
28 theparts = new TColStd_HSequenceOfInteger();
29 thepart = 0;
30 for (other.Start(); other.More(); other.Next()) {
31 thepart ++;
32 Standard_Integer nbent = 0;
33 GetFromIter (other.Entities());
34 for (Standard_Integer i = 1; i <= nb; i ++) {
35 if (thegraph.Status(i) == thepart) nbent ++;
36 }
37 theparts->Append(nbent); // compte vide
38 }
39 thepart = 0;
40 thecurr = 1;
41}
42
43 void IFGraph_SubPartsIterator::GetParts
44 (IFGraph_SubPartsIterator& other)
45{
46 if (Model() != other.Model()) Interface_InterfaceError::Raise
47 ("SubPartsIterator : GetParts");
48// On AJOUTE les Parts de other, sans perdre les siennes propres
49// (meme principe que le constructeur ci-dessus)
50 Standard_Integer nb = thegraph.Size();
51 thepart = theparts->Length();
52 for (other.Start(); other.More(); other.Next()) {
53 thepart ++;
54 Standard_Integer nbent = 0;
55 GetFromIter (other.Entities());
56 for (Standard_Integer i = 1; i <= nb; i ++) {
57 if (thegraph.Status(i) == thepart) nbent ++;
58 }
59 theparts->Append(nbent); // compte vide
60 }
61}
62
63 const Interface_Graph& IFGraph_SubPartsIterator::Graph () const
64 { return thegraph; }
65
66// .... Gestion Interne (remplissage, etc...) .... //
67
68 Handle(Interface_InterfaceModel) IFGraph_SubPartsIterator::Model() const
69 { return thegraph.Model(); }
70
71 void IFGraph_SubPartsIterator::AddPart ()
72{
73 theparts->Append( Standard_Integer(0) );
74 thepart = theparts->Length();
75}
76
77 Standard_Integer IFGraph_SubPartsIterator::NbParts () const
78 { return theparts->Length(); }
79
80 Standard_Integer IFGraph_SubPartsIterator::PartNum () const
81 { return thepart; }
82
83 void IFGraph_SubPartsIterator::SetLoad ()
84 { thepart = 0; }
85
86 void IFGraph_SubPartsIterator::SetPartNum (const Standard_Integer num)
87{
88 if (num <= 0 || num > theparts->Length()) Standard_OutOfRange::Raise
89 ("IFGraph_SubPartsIterator : SetPartNum");
90 thepart = num;
91}
92
93 void IFGraph_SubPartsIterator::GetFromEntity
94 (const Handle(Standard_Transient)& ent, const Standard_Boolean shared)
95{
96 thegraph.GetFromEntity(ent,shared, thepart,thepart,Standard_False);
97}
98
99 void IFGraph_SubPartsIterator::GetFromIter (const Interface_EntityIterator& iter)
100{
101 thegraph.GetFromIter(iter, thepart,thepart, Standard_False);
102}
103
104 void IFGraph_SubPartsIterator::Reset ()
105{
106 thegraph.Reset();
107 theparts->Clear();
108 thepart = 0;
109 thecurr = 0;
110}
111
112
113// .... Resultat (Evaluation, Iterations) .... //
114
115 void IFGraph_SubPartsIterator::Evaluate ()
116{ } // par defaut, ne fait rien; redefinie par les sous-classes
117
118 Interface_GraphContent IFGraph_SubPartsIterator::Loaded () const
119{
120 Interface_EntityIterator iter;
121// Standard_Integer nb = thegraph.Size();
122 return Interface_GraphContent(thegraph,0);
123}
124
125 Interface_Graph IFGraph_SubPartsIterator::LoadedGraph () const
126{
127 Interface_Graph G(Model());
128 Standard_Integer nb = thegraph.Size();
129 for (Standard_Integer i = 1; i <= nb; i ++) {
130 if (thegraph.IsPresent(i) && thegraph.Status(i) == 0)
131 G.GetFromEntity(thegraph.Entity(i),Standard_False);
132 }
133 return G;
134}
135
136
137 Standard_Boolean IFGraph_SubPartsIterator::IsLoaded
138 (const Handle(Standard_Transient)& ent) const
139{ return thegraph.IsPresent(thegraph.EntityNumber(ent)); }
140
141 Standard_Boolean IFGraph_SubPartsIterator::IsInPart
142 (const Handle(Standard_Transient)& ent) const
143{
144 Standard_Integer num = thegraph.EntityNumber(ent);
145 if (!thegraph.IsPresent(num)) return Standard_False;
146 return (thegraph.Status(num) != 0);
147}
148
149 Standard_Integer IFGraph_SubPartsIterator::EntityPartNum
150 (const Handle(Standard_Transient)& ent) const
151{
152 Standard_Integer num = thegraph.EntityNumber(ent);
153 if (!thegraph.IsPresent(num)) return 0;
154 return thegraph.Status(num);
155}
156
157
158 void IFGraph_SubPartsIterator::Start ()
159{
160 Evaluate();
161// On evalue les tailles des contenus des Parts
162 Standard_Integer nb = thegraph.Size();
163 Standard_Integer nbp = theparts->Length();
164 if (thepart > nbp) thepart = nbp;
165 if (nbp == 0) { thecurr = 1; return; } // L Iteration s arrete de suite
166
167// - On fait les comptes (via tableaux pour performances)
168 TColStd_Array1OfInteger partcounts (1,nbp); partcounts.Init(0);
169 TColStd_Array1OfInteger partfirsts (1,nbp); partfirsts.Init(0);
170 for (Standard_Integer i = 1; i <= nb; i ++) {
171 if (!thegraph.IsPresent(i)) continue;
172 Standard_Integer nump = thegraph.Status(i);
173 if (nump < 1 || nump > nbp) continue;
174 Standard_Integer nbent = partcounts.Value(nump);
175 partcounts.SetValue(nump,nbent+1);
176 if (nbent == 0) partfirsts.SetValue(nump,i);
177 }
178// - On les met en forme (c-a-d dans les sequences)
179 theparts->Clear(); thefirsts->Clear();
180 Standard_Integer lastp = 0;
181 for (Standard_Integer np = 1; np <= nbp; np ++) {
182 Standard_Integer nbent = partcounts.Value(np);
183 if (np != 0) lastp = np;
184 theparts->Append (nbent);
185 thefirsts->Append (partfirsts.Value(np));
186 }
187 if (lastp < nbp) theparts->Remove(lastp+1,nbp);
188// Enfin, on se prepare a iterer
189 thecurr = 1;
190}
191
192 Standard_Boolean IFGraph_SubPartsIterator::More ()
193{
194 if (thecurr == 0) Start();
195 return (thecurr <= theparts->Length());
196}
197
198 void IFGraph_SubPartsIterator::Next ()
199{
200 thecurr ++; if (thecurr > theparts->Length()) return;
201 if (theparts->Value(thecurr) == 0) Next(); // sauter parties vides
202}
203
204 Standard_Boolean IFGraph_SubPartsIterator::IsSingle () const
205{
206 if (thecurr < 1 || thecurr > theparts->Length()) Standard_NoSuchObject::Raise
207 ("IFGraph_SubPartsIterator : IsSingle");
208 return (theparts->Value(thecurr) == 1);
209}
210
211 Handle(Standard_Transient) IFGraph_SubPartsIterator::FirstEntity
212 () const
213{
214 if (thecurr < 1 || thecurr > theparts->Length()) Standard_NoSuchObject::Raise
215 ("IFGraph_SubPartsIterator : FirstEntity");
216 Standard_Integer nument = thefirsts->Value(thecurr);
217 if (nument == 0) Standard_NoSuchObject::Raise
218 ("IFGraph_SubPartsIterator : FirstEntity (current part is empty)");
219 return thegraph.Entity(nument);
220}
221
222 Interface_EntityIterator IFGraph_SubPartsIterator::Entities () const
223{
224 if (thecurr < 1 || thecurr > theparts->Length()) Standard_NoSuchObject::Raise
225 ("IFGraph_SubPartsIterator : Entities");
226 Interface_EntityIterator iter;
227 Standard_Integer nb = thegraph.Size();
228 Standard_Integer nument = thefirsts->Value(thecurr);
229 if (nument == 0) return iter;
230 if (theparts->Value(thecurr) == 1) nb = nument; // evident : 1 seule Entite
231 for (Standard_Integer i = nument; i <= nb; i ++) {
232 if (thegraph.Status(i) == thecurr && thegraph.IsPresent(i))
233 iter.GetOneItem(thegraph.Entity(i));
234 }
235 return iter;
236}
237
238//=======================================================================
239//function : Delete
240//purpose :
241//=======================================================================
242
243void IFGraph_SubPartsIterator::Delete()
244{}