0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IFGraph / IFGraph_SubPartsIterator.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
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.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
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>
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)
29 IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
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()) 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()) {
69     thepart ++;
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 ++;
74     }
75     theparts->Append(nbent);  // compte vide
76   }
77 }
78
79     const Interface_Graph&  IFGraph_SubPartsIterator::Graph () const
80       {  return thegraph;  }
81
82 //  ....            Gestion Interne (remplissage, etc...)            .... //
83
84     Handle(Interface_InterfaceModel)  IFGraph_SubPartsIterator::Model() const 
85       {  return thegraph.Model();  }
86
87     void  IFGraph_SubPartsIterator::AddPart ()
88 {
89   theparts->Append( Standard_Integer(0) );
90   thepart = theparts->Length();
91 }
92
93     Standard_Integer  IFGraph_SubPartsIterator::NbParts () const 
94       {  return theparts->Length();  }
95
96     Standard_Integer  IFGraph_SubPartsIterator::PartNum () const 
97       {  return thepart;  }
98
99     void  IFGraph_SubPartsIterator::SetLoad ()
100       {  thepart = 0;  }
101
102     void  IFGraph_SubPartsIterator::SetPartNum (const Standard_Integer num)
103 {
104   if (num <= 0 || num > theparts->Length()) throw Standard_OutOfRange("IFGraph_SubPartsIterator : SetPartNum");
105   thepart = num;
106 }
107
108     void  IFGraph_SubPartsIterator::GetFromEntity
109   (const Handle(Standard_Transient)& ent, const Standard_Boolean shared)
110 {
111   thegraph.GetFromEntity(ent,shared, thepart,thepart,Standard_False);
112 }
113
114     void IFGraph_SubPartsIterator::GetFromIter (const Interface_EntityIterator& iter)
115 {
116   thegraph.GetFromIter(iter, thepart,thepart, Standard_False);
117 }
118
119     void  IFGraph_SubPartsIterator::Reset ()
120 {
121   thegraph.Reset();
122   theparts->Clear();
123   thepart = 0;
124   thecurr = 0;
125 }
126
127
128 //  ....              Resultat (Evaluation, Iterations)              .... //
129
130     void  IFGraph_SubPartsIterator::Evaluate ()
131 {  }    // par defaut, ne fait rien; redefinie par les sous-classes
132
133     Interface_GraphContent  IFGraph_SubPartsIterator::Loaded () const 
134 {
135   Interface_EntityIterator iter;
136 //  Standard_Integer nb = thegraph.Size();
137   return Interface_GraphContent(thegraph,0);
138 }
139
140     Interface_Graph  IFGraph_SubPartsIterator::LoadedGraph () const 
141 {
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);
147   }
148   return G;
149 }
150
151
152     Standard_Boolean IFGraph_SubPartsIterator::IsLoaded
153   (const Handle(Standard_Transient)& ent) const
154 {  return thegraph.IsPresent(thegraph.EntityNumber(ent));  }
155
156     Standard_Boolean IFGraph_SubPartsIterator::IsInPart
157   (const Handle(Standard_Transient)& ent) const
158 {
159   Standard_Integer num = thegraph.EntityNumber(ent);
160   if (!thegraph.IsPresent(num)) return Standard_False;
161   return (thegraph.Status(num) != 0);
162 }
163
164     Standard_Integer IFGraph_SubPartsIterator::EntityPartNum
165   (const Handle(Standard_Transient)& ent) const
166 {
167   Standard_Integer num = thegraph.EntityNumber(ent);
168   if (!thegraph.IsPresent(num)) return 0;
169   return thegraph.Status(num);
170 }
171
172
173     void  IFGraph_SubPartsIterator::Start ()
174 {
175   Evaluate();
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
181
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);
192   }
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));
201   }
202   if (lastp < nbp) theparts->Remove(lastp+1,nbp);
203 //  Enfin, on se prepare a iterer
204   thecurr = 1;
205 }
206
207     Standard_Boolean  IFGraph_SubPartsIterator::More ()
208 {
209   if (thecurr == 0) Start();
210   return (thecurr <= theparts->Length());
211 }
212
213     void  IFGraph_SubPartsIterator::Next ()
214 {
215   thecurr ++; if (thecurr > theparts->Length()) return;
216   if (theparts->Value(thecurr) == 0) Next();  // sauter parties vides
217 }
218
219     Standard_Boolean  IFGraph_SubPartsIterator::IsSingle () const
220 {
221   if (thecurr < 1 || thecurr > theparts->Length()) throw Standard_NoSuchObject("IFGraph_SubPartsIterator : IsSingle");
222   return (theparts->Value(thecurr) == 1);
223 }
224
225     Handle(Standard_Transient)  IFGraph_SubPartsIterator::FirstEntity
226   () const 
227 {
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);
232 }
233
234     Interface_EntityIterator  IFGraph_SubPartsIterator::Entities () const 
235 {
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));
245   }
246   return iter;
247 }
248
249 //=======================================================================
250 //function : ~IFGraph_SubPartsIterator
251 //purpose  : 
252 //=======================================================================
253
254 IFGraph_SubPartsIterator::~IFGraph_SubPartsIterator() 
255 {}