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