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