0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / HLRTopoBRep / HLRTopoBRep_Data.cxx
1 // Created on: 1994-10-24
2 // Created by: Christophe MARION
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <HLRTopoBRep_Data.hxx>
19 #include <HLRTopoBRep_ListOfVData.hxx>
20 #include <HLRTopoBRep_VData.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Face.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopoDS_Vertex.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27
28 //=======================================================================
29 //function : HLRTopoBRep_Data
30 //purpose  : 
31 //=======================================================================
32 HLRTopoBRep_Data::HLRTopoBRep_Data ()
33 {
34   Clear();
35 }
36
37 //=======================================================================
38 //function : Clear
39 //purpose  : 
40 //=======================================================================
41
42 void HLRTopoBRep_Data::Clear ()
43 {
44   myOldS.Clear();
45   mySplE.Clear();
46   myData.Clear();
47   myOutV.Clear();
48   myIntV.Clear();
49   myEdgesVertices.Clear();
50 }
51
52 //=======================================================================
53 //function : Clean
54 //purpose  : 
55 //=======================================================================
56
57 void HLRTopoBRep_Data::Clean ()
58 {
59 }
60
61 //=======================================================================
62 //function : EdgeHasSplE
63 //purpose  : 
64 //=======================================================================
65
66 Standard_Boolean 
67 HLRTopoBRep_Data::EdgeHasSplE (const TopoDS_Edge& E) const 
68 {
69   if (!mySplE.IsBound(E)) return Standard_False;
70   return !mySplE(E).IsEmpty();
71 }
72
73 //=======================================================================
74 //function : FaceHasIntL
75 //purpose  : 
76 //=======================================================================
77
78 Standard_Boolean 
79 HLRTopoBRep_Data::FaceHasIntL (const TopoDS_Face& F) const 
80 {
81   if (!myData.IsBound(F)) return Standard_False;
82   return !myData(F).FaceIntL().IsEmpty();
83 }
84
85 //=======================================================================
86 //function : FaceHasOutL
87 //purpose  : 
88 //=======================================================================
89
90 Standard_Boolean 
91 HLRTopoBRep_Data::FaceHasOutL (const TopoDS_Face& F) const 
92 {
93   if (!myData.IsBound(F)) return Standard_False;
94   return !myData(F).FaceOutL().IsEmpty();
95 }
96
97 //=======================================================================
98 //function : FaceHasIsoL
99 //purpose  : 
100 //=======================================================================
101
102 Standard_Boolean 
103 HLRTopoBRep_Data::FaceHasIsoL (const TopoDS_Face& F) const 
104 {
105   if (!myData.IsBound(F)) return Standard_False;
106   return !myData(F).FaceIsoL().IsEmpty();
107 }
108
109 //=======================================================================
110 //function : IsSplEEdgeEdge
111 //purpose  : 
112 //=======================================================================
113
114 Standard_Boolean 
115 HLRTopoBRep_Data::IsSplEEdgeEdge (const TopoDS_Edge& E1,
116                                   const TopoDS_Edge& E2) const 
117 {
118   Standard_Boolean found = Standard_False;
119   if (EdgeHasSplE(E1)) {
120     
121     TopTools_ListIteratorOfListOfShape itS;
122     for (itS.Initialize(EdgeSplE(E1));
123          itS.More() && !found;
124          itS.Next())
125       found= itS.Value().IsSame(E2);
126   }
127   else
128     found = E1.IsSame(E2);
129   return found;
130 }
131
132 //=======================================================================
133 //function : IsIntLFaceEdge
134 //purpose  : 
135 //=======================================================================
136
137 Standard_Boolean 
138 HLRTopoBRep_Data::IsIntLFaceEdge (const TopoDS_Face& F,
139                                   const TopoDS_Edge& E) const 
140 {
141   Standard_Boolean found = Standard_False;
142   if (FaceHasIntL(F)) {
143
144     TopTools_ListIteratorOfListOfShape itE;
145     for(itE.Initialize(FaceIntL(F));
146         itE.More() && !found;
147         itE.Next()) {
148       found = IsSplEEdgeEdge(TopoDS::Edge(itE.Value()),E);
149     }
150   }
151   return found;
152 }
153
154 //=======================================================================
155 //function : IsOutLFaceEdge
156 //purpose  : 
157 //=======================================================================
158
159 Standard_Boolean 
160 HLRTopoBRep_Data::IsOutLFaceEdge (const TopoDS_Face& F,
161                                   const TopoDS_Edge& E) const 
162 {
163   Standard_Boolean found = Standard_False;
164   if (FaceHasOutL(F)) {
165
166     TopTools_ListIteratorOfListOfShape itE;
167     for(itE.Initialize(FaceOutL(F));
168         itE.More() && !found;
169         itE.Next()) {
170       found = IsSplEEdgeEdge(TopoDS::Edge(itE.Value()),E);
171     }
172   }
173   return found;
174 }
175
176 //=======================================================================
177 //function : IsIsoLFaceEdge
178 //purpose  : 
179 //=======================================================================
180
181 Standard_Boolean 
182 HLRTopoBRep_Data::IsIsoLFaceEdge (const TopoDS_Face& F,
183                                   const TopoDS_Edge& E) const 
184 {
185   Standard_Boolean found = Standard_False;
186   if (FaceHasIsoL(F)) {
187
188     TopTools_ListIteratorOfListOfShape itE;
189     for(itE.Initialize(FaceIsoL(F));
190         itE.More() && !found;
191         itE.Next()) {
192       found = IsSplEEdgeEdge(TopoDS::Edge(itE.Value()),E);
193     }
194   }
195   return found;
196 }
197
198 //=======================================================================
199 //function : NewSOldS
200 //purpose  : 
201 //=======================================================================
202
203 TopoDS_Shape HLRTopoBRep_Data::NewSOldS (const TopoDS_Shape& NewS) const 
204 {
205   if (myOldS.IsBound(NewS)) return myOldS(NewS);
206   else                      return NewS;
207 }
208
209 //=======================================================================
210 //function : AddOldS
211 //purpose  : 
212 //=======================================================================
213
214 void HLRTopoBRep_Data::AddOldS (const TopoDS_Shape& NewS,
215                                 const TopoDS_Shape& OldS)
216 {
217   if (!myOldS.IsBound(NewS))
218     myOldS.Bind(NewS,OldS);
219 }
220
221 //=======================================================================
222 //function : AddSplE
223 //purpose  : 
224 //=======================================================================
225
226 TopTools_ListOfShape & HLRTopoBRep_Data::AddSplE (const TopoDS_Edge& E)
227 {
228   if (!mySplE.IsBound(E)) {
229     TopTools_ListOfShape empty;
230     mySplE.Bind(E,empty);
231   }
232   return mySplE(E);
233 }
234
235 //=======================================================================
236 //function : AddIntL
237 //purpose  : 
238 //=======================================================================
239
240 TopTools_ListOfShape & HLRTopoBRep_Data::AddIntL (const TopoDS_Face& F)
241 {
242   if (!myData.IsBound(F)) {
243     HLRTopoBRep_FaceData theData;
244     myData.Bind(F, theData);
245   }
246   return myData(F).AddIntL();
247 }
248
249 //=======================================================================
250 //function : AddOutL
251 //purpose  : 
252 //=======================================================================
253
254 TopTools_ListOfShape & HLRTopoBRep_Data::AddOutL (const TopoDS_Face& F)
255 {
256   if (!myData.IsBound(F)) {
257     HLRTopoBRep_FaceData theData;
258     myData.Bind(F, theData);
259   }
260   return myData(F).AddOutL();
261 }
262
263 //=======================================================================
264 //function : AddIsoL
265 //purpose  : 
266 //=======================================================================
267
268 TopTools_ListOfShape & HLRTopoBRep_Data::AddIsoL (const TopoDS_Face& F)
269 {
270   if (!myData.IsBound(F)) {
271     HLRTopoBRep_FaceData theData;
272     myData.Bind(F, theData);
273   }
274   return myData(F).AddIsoL();
275 }
276
277 //=======================================================================
278 //function : InitEdge
279 //purpose  : 
280 //=======================================================================
281
282 void HLRTopoBRep_Data::InitEdge ()
283 {
284   myEIterator.Initialize(myEdgesVertices);
285
286   while (myEIterator.More() && myEIterator.Value().IsEmpty())
287     myEIterator.Next();
288 }
289
290 //=======================================================================
291 //function : NextEdge
292 //purpose  : 
293 //=======================================================================
294
295 void HLRTopoBRep_Data::NextEdge ()
296 {
297   myEIterator.Next();
298
299   while (myEIterator.More() && myEIterator.Value().IsEmpty())
300     myEIterator.Next();
301 }
302
303 //=======================================================================
304 //function : InitVertex
305 //purpose  : 
306 //=======================================================================
307
308 void HLRTopoBRep_Data::InitVertex (const TopoDS_Edge& E)
309 {
310   if (!myEdgesVertices.IsBound(E)) {
311     HLRTopoBRep_ListOfVData empty;
312     myEdgesVertices.Bind(E,empty);
313   }
314   HLRTopoBRep_ListOfVData& L = myEdgesVertices(E);
315   myVList = &L;
316   myVIterator.Initialize(L);
317 }
318
319 //=======================================================================
320 //function : Vertex
321 //purpose  : 
322 //=======================================================================
323
324 const TopoDS_Vertex & HLRTopoBRep_Data::Vertex () const 
325 {
326   return TopoDS::Vertex(myVIterator.Value().Vertex());
327 }
328
329 //=======================================================================
330 //function : Parameter
331 //purpose  : 
332 //=======================================================================
333
334 Standard_Real HLRTopoBRep_Data::Parameter() const 
335 {
336   return myVIterator.Value().Parameter();
337 }
338
339 //=======================================================================
340 //function : InsertBefore
341 //purpose  : 
342 //=======================================================================
343
344 void HLRTopoBRep_Data::InsertBefore (const TopoDS_Vertex& V,
345                                      const Standard_Real P)
346 {
347   HLRTopoBRep_VData VD(P,V);
348   myVList->InsertBefore(VD,myVIterator);
349 }
350
351 //=======================================================================
352 //function : Append
353 //purpose  : 
354 //=======================================================================
355
356 void HLRTopoBRep_Data::Append (const TopoDS_Vertex& V, 
357                                const Standard_Real P)
358 {
359   HLRTopoBRep_VData VD(P,V);
360   myVList->Append(VD);
361 }
362