summaryrefslogtreecommitdiff
path: root/src/IFGraph/IFGraph_SubPartsIterator.cxx
blob: 5227de918b1735558fcb94f958ce6ecb7ee1812f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include <IFGraph_SubPartsIterator.ixx> 
#include <TColStd_Array1OfInteger.hxx>
#include <Interface_InterfaceError.hxx>
#include <Standard_NoSuchObject.hxx>



// SubPartsIterator permet de regrouper les entites en plusieurs sous-parties
// A chaque sous-partie est attache un Status : la 1re a 1, la 2e a 2, etc...
// (consequence, les sous-parties sont necessairement disjointes)

    IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
  (const Interface_Graph& agraph, const Standard_Boolean whole)
      : thegraph (agraph)
{
  if (whole) thegraph.GetFromModel();
  theparts  = new TColStd_HSequenceOfInteger();
  thefirsts = new TColStd_HSequenceOfInteger();
  thepart   = 0;
  thecurr   = 0;
}

    IFGraph_SubPartsIterator::IFGraph_SubPartsIterator
  (IFGraph_SubPartsIterator& other)
      : thegraph (other.Graph())
{
  Standard_Integer nb = thegraph.Size();
  theparts = new TColStd_HSequenceOfInteger();
  thepart = 0;
  for (other.Start(); other.More(); other.Next()) {
    thepart ++;
    Standard_Integer nbent = 0;
    GetFromIter (other.Entities());
    for (Standard_Integer i = 1; i <= nb; i ++) {
      if (thegraph.Status(i) == thepart) nbent ++;
    }
    theparts->Append(nbent);  // compte vide
  }
  thepart = 0;
  thecurr = 1;
}

    void  IFGraph_SubPartsIterator::GetParts
  (IFGraph_SubPartsIterator& other)
{
  if (Model() != other.Model()) Interface_InterfaceError::Raise
    ("SubPartsIterator : GetParts");
//  On AJOUTE les Parts de other, sans perdre les siennes propres
//  (meme principe que le constructeur ci-dessus)
  Standard_Integer nb = thegraph.Size();
  thepart = theparts->Length();
  for (other.Start(); other.More(); other.Next()) {
    thepart ++;
    Standard_Integer nbent = 0;
    GetFromIter (other.Entities());
    for (Standard_Integer i = 1; i <= nb; i ++) {
      if (thegraph.Status(i) == thepart) nbent ++;
    }
    theparts->Append(nbent);  // compte vide
  }
}

    const Interface_Graph&  IFGraph_SubPartsIterator::Graph () const
      {  return thegraph;  }

//  ....            Gestion Interne (remplissage, etc...)            .... //

    Handle(Interface_InterfaceModel)  IFGraph_SubPartsIterator::Model() const 
      {  return thegraph.Model();  }

    void  IFGraph_SubPartsIterator::AddPart ()
{
  theparts->Append( Standard_Integer(0) );
  thepart = theparts->Length();
}

    Standard_Integer  IFGraph_SubPartsIterator::NbParts () const 
      {  return theparts->Length();  }

    Standard_Integer  IFGraph_SubPartsIterator::PartNum () const 
      {  return thepart;  }

    void  IFGraph_SubPartsIterator::SetLoad ()
      {  thepart = 0;  }

    void  IFGraph_SubPartsIterator::SetPartNum (const Standard_Integer num)
{
  if (num <= 0 || num > theparts->Length()) Standard_OutOfRange::Raise
    ("IFGraph_SubPartsIterator : SetPartNum");
  thepart = num;
}

    void  IFGraph_SubPartsIterator::GetFromEntity
  (const Handle(Standard_Transient)& ent, const Standard_Boolean shared)
{
  thegraph.GetFromEntity(ent,shared, thepart,thepart,Standard_False);
}

    void IFGraph_SubPartsIterator::GetFromIter (const Interface_EntityIterator& iter)
{
  thegraph.GetFromIter(iter, thepart,thepart, Standard_False);
}

    void  IFGraph_SubPartsIterator::Reset ()
{
  thegraph.Reset();
  theparts->Clear();
  thepart = 0;
  thecurr = 0;
}


//  ....              Resultat (Evaluation, Iterations)              .... //

    void  IFGraph_SubPartsIterator::Evaluate ()
{  }    // par defaut, ne fait rien; redefinie par les sous-classes

    Interface_GraphContent  IFGraph_SubPartsIterator::Loaded () const 
{
  Interface_EntityIterator iter;
//  Standard_Integer nb = thegraph.Size();
  return Interface_GraphContent(thegraph,0);
}

    Interface_Graph  IFGraph_SubPartsIterator::LoadedGraph () const 
{
  Interface_Graph G(Model());
  Standard_Integer nb = thegraph.Size();
  for (Standard_Integer i = 1; i <= nb; i ++) {
    if (thegraph.IsPresent(i) && thegraph.Status(i) == 0)
      G.GetFromEntity(thegraph.Entity(i),Standard_False);
  }
  return G;
}


    Standard_Boolean IFGraph_SubPartsIterator::IsLoaded
  (const Handle(Standard_Transient)& ent) const
{  return thegraph.IsPresent(thegraph.EntityNumber(ent));  }

    Standard_Boolean IFGraph_SubPartsIterator::IsInPart
  (const Handle(Standard_Transient)& ent) const
{
  Standard_Integer num = thegraph.EntityNumber(ent);
  if (!thegraph.IsPresent(num)) return Standard_False;
  return (thegraph.Status(num) != 0);
}

    Standard_Integer IFGraph_SubPartsIterator::EntityPartNum
  (const Handle(Standard_Transient)& ent) const
{
  Standard_Integer num = thegraph.EntityNumber(ent);
  if (!thegraph.IsPresent(num)) return 0;
  return thegraph.Status(num);
}


    void  IFGraph_SubPartsIterator::Start ()
{
  Evaluate();
//  On evalue les tailles des contenus des Parts
  Standard_Integer nb  = thegraph.Size();
  Standard_Integer nbp = theparts->Length();
  if (thepart > nbp) thepart = nbp;
  if (nbp == 0) {  thecurr = 1; return;  }    // L Iteration s arrete de suite

//  - On fait les comptes (via tableaux pour performances)
  TColStd_Array1OfInteger partcounts (1,nbp); partcounts.Init(0);
  TColStd_Array1OfInteger partfirsts (1,nbp); partfirsts.Init(0);
  for (Standard_Integer i = 1; i <= nb; i ++) {
    if (!thegraph.IsPresent(i)) continue;
    Standard_Integer nump = thegraph.Status(i);
    if (nump < 1 || nump > nbp) continue;
    Standard_Integer nbent = partcounts.Value(nump);
    partcounts.SetValue(nump,nbent+1);
    if (nbent == 0) partfirsts.SetValue(nump,i);
  }
//  - On les met en forme (c-a-d dans les sequences)
  theparts->Clear(); thefirsts->Clear();
  Standard_Integer lastp = 0;
  for (Standard_Integer np = 1; np <= nbp; np ++) {
    Standard_Integer nbent = partcounts.Value(np);
    if (np != 0) lastp = np;
    theparts->Append  (nbent);
    thefirsts->Append (partfirsts.Value(np));
  }
  if (lastp < nbp) theparts->Remove(lastp+1,nbp);
//  Enfin, on se prepare a iterer
  thecurr = 1;
}

    Standard_Boolean  IFGraph_SubPartsIterator::More ()
{
  if (thecurr == 0) Start();
  return (thecurr <= theparts->Length());
}

    void  IFGraph_SubPartsIterator::Next ()
{
  thecurr ++; if (thecurr > theparts->Length()) return;
  if (theparts->Value(thecurr) == 0) Next();  // sauter parties vides
}

    Standard_Boolean  IFGraph_SubPartsIterator::IsSingle () const
{
  if (thecurr < 1 || thecurr > theparts->Length()) Standard_NoSuchObject::Raise
    ("IFGraph_SubPartsIterator : IsSingle");
  return (theparts->Value(thecurr) == 1);
}

    Handle(Standard_Transient)  IFGraph_SubPartsIterator::FirstEntity
  () const 
{
  if (thecurr < 1 || thecurr > theparts->Length()) Standard_NoSuchObject::Raise
    ("IFGraph_SubPartsIterator : FirstEntity");
  Standard_Integer nument = thefirsts->Value(thecurr);
  if (nument == 0) Standard_NoSuchObject::Raise
    ("IFGraph_SubPartsIterator : FirstEntity (current part is empty)");
  return thegraph.Entity(nument);
}

    Interface_EntityIterator  IFGraph_SubPartsIterator::Entities () const 
{
  if (thecurr < 1 || thecurr > theparts->Length()) Standard_NoSuchObject::Raise
    ("IFGraph_SubPartsIterator : Entities");
  Interface_EntityIterator iter;
  Standard_Integer nb = thegraph.Size();
  Standard_Integer nument = thefirsts->Value(thecurr);
  if (nument == 0) return iter;
  if (theparts->Value(thecurr) == 1) nb = nument;   // evident : 1 seule Entite
  for (Standard_Integer i = nument; i <= nb; i ++) {
    if (thegraph.Status(i) == thecurr && thegraph.IsPresent(i))
      iter.GetOneItem(thegraph.Entity(i));
  }
  return iter;
}

//=======================================================================
//function : Delete
//purpose  : 
//=======================================================================

void IFGraph_SubPartsIterator::Delete() 
{}