0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BOPDS / BOPDS_CommonBlock.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <BOPDS_CommonBlock.hxx>
17 #include <BOPDS_PaveBlock.hxx>
18 #include <Standard_Type.hxx>
19
20 IMPLEMENT_STANDARD_RTTIEXT(BOPDS_CommonBlock,Standard_Transient)
21
22 //=======================================================================
23 // function:  
24 // purpose: 
25 //=======================================================================
26 BOPDS_CommonBlock::BOPDS_CommonBlock()
27 :
28   myTolerance(0.0)
29 {
30 }
31 //=======================================================================
32 // function:  
33 // purpose: 
34 //=======================================================================
35   BOPDS_CommonBlock::BOPDS_CommonBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
36 :
37   myPaveBlocks(theAllocator),
38   myFaces(theAllocator),
39   myTolerance(0.0)
40 {
41 }
42 //=======================================================================
43 // function:  AddPaveBlock
44 // purpose: 
45 //=======================================================================
46   void BOPDS_CommonBlock::AddPaveBlock(const Handle(BOPDS_PaveBlock)& aPB)
47 {
48   if (myPaveBlocks.IsEmpty()) {
49     myPaveBlocks.Append(aPB);
50     return;
51   }
52   //
53   // Put the pave block with the minimal index of the original edge in the first place
54   if (aPB->OriginalEdge() < myPaveBlocks.First()->OriginalEdge()) {
55     myPaveBlocks.Prepend(aPB);
56   }
57   else {
58     myPaveBlocks.Append(aPB);
59   }
60 }
61 //=======================================================================
62 // function:  SetPaveBlocks
63 // purpose: 
64 //=======================================================================
65   void BOPDS_CommonBlock::SetPaveBlocks(const BOPDS_ListOfPaveBlock& aLPB)
66 {
67   myPaveBlocks.Clear();
68   BOPDS_ListIteratorOfListOfPaveBlock aIt(aLPB);
69   for (; aIt.More(); aIt.Next()) {
70     AddPaveBlock(aIt.Value());
71   }
72 }
73 //=======================================================================
74 // function:  PaveBlocks
75 // purpose: 
76 //=======================================================================
77   const BOPDS_ListOfPaveBlock& BOPDS_CommonBlock::PaveBlocks()const
78 {
79   return myPaveBlocks;
80 }
81 //=======================================================================
82 // function:  AddFace
83 // purpose: 
84 //=======================================================================
85   void BOPDS_CommonBlock::AddFace(const Standard_Integer aF)
86 {
87   myFaces.Append(aF);
88 }
89 //=======================================================================
90 // function:  AddFaces
91 // purpose: 
92 //=======================================================================
93   void BOPDS_CommonBlock::SetFaces(const TColStd_ListOfInteger& aLF)
94 {
95   myFaces=aLF;
96 }
97 //=======================================================================
98 // function:  AppendFaces
99 // purpose: 
100 //=======================================================================
101 void BOPDS_CommonBlock::AppendFaces(TColStd_ListOfInteger& aLF)
102 {
103   myFaces.Append(aLF);
104 }
105   //=======================================================================
106 // function:  Faces
107 // purpose: 
108 //=======================================================================
109   const TColStd_ListOfInteger& BOPDS_CommonBlock::Faces()const
110 {
111   return myFaces;
112 }
113 //=======================================================================
114 // function:  PaveBlock1
115 // purpose: 
116 //=======================================================================
117   const Handle(BOPDS_PaveBlock)& BOPDS_CommonBlock::PaveBlock1()const
118 {
119   return myPaveBlocks.First();
120 }
121 //=======================================================================
122 // function:  SetRealPaveBlock
123 // purpose: 
124 //=======================================================================
125 void BOPDS_CommonBlock::SetRealPaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
126 {
127   BOPDS_ListIteratorOfListOfPaveBlock it(myPaveBlocks);
128   for (; it.More(); it.Next())
129   {
130     if (it.Value() == thePB)
131     {
132       myPaveBlocks.Prepend(thePB);
133       myPaveBlocks.Remove(it);
134       break;
135     }
136   }
137 }
138 //=======================================================================
139 // function:  PaveBlockOnEdge
140 // purpose: 
141 //=======================================================================
142   Handle(BOPDS_PaveBlock)& BOPDS_CommonBlock::PaveBlockOnEdge(const Standard_Integer aIx)
143 {
144   static Handle(BOPDS_PaveBlock) aPBs;
145   //
146   Standard_Integer aIOr;
147   BOPDS_ListIteratorOfListOfPaveBlock anIt;
148   //
149   anIt.Initialize(myPaveBlocks);
150   for (; anIt.More(); anIt.Next()) {
151     Handle(BOPDS_PaveBlock)& aPB=anIt.ChangeValue();
152     aIOr=aPB->OriginalEdge();
153     if (aIOr==aIx){
154       return aPB;
155     }
156   }
157   return aPBs;
158 }
159 //=======================================================================
160 // function:  IsPaveBlockOnFace
161 // purpose: 
162 //=======================================================================
163   Standard_Boolean BOPDS_CommonBlock::IsPaveBlockOnFace(const Standard_Integer aIx)const
164 {
165   Standard_Boolean bFound;
166   Standard_Integer nF;
167   TColStd_ListIteratorOfListOfInteger anIt;
168   //
169   bFound=Standard_False;
170   anIt.Initialize(myFaces);
171   for (; anIt.More(); anIt.Next()) {
172     nF=anIt.Value();
173     if (nF==aIx){
174       return !bFound;
175     }
176   }
177   return bFound;
178 }
179 //=======================================================================
180 // function:  IsPaveBlockOnEdge
181 // purpose: 
182 //=======================================================================
183   Standard_Boolean BOPDS_CommonBlock::IsPaveBlockOnEdge(const Standard_Integer aIx)const
184 {
185   Standard_Boolean bFound;
186   Standard_Integer aIOr;
187   BOPDS_ListIteratorOfListOfPaveBlock anIt;
188   //
189   bFound=Standard_False;
190   anIt.Initialize(myPaveBlocks);
191   for (; anIt.More(); anIt.Next()) {
192     const Handle(BOPDS_PaveBlock)& aPB=anIt.Value();
193     aIOr=aPB->OriginalEdge();
194     if (aIOr==aIx){
195       return !bFound;
196     }
197   }
198   return bFound;
199 }
200 //=======================================================================
201 //function : SetEdge
202 //purpose  : 
203 //=======================================================================
204   void BOPDS_CommonBlock::SetEdge(const Standard_Integer theEdge)
205 {
206   BOPDS_ListIteratorOfListOfPaveBlock anIt;
207   //
208   anIt.Initialize(myPaveBlocks);
209   for (; anIt.More(); anIt.Next()) {
210     Handle(BOPDS_PaveBlock)& aPB=anIt.ChangeValue();
211     aPB->SetEdge(theEdge);
212   }
213 }
214 //=======================================================================
215 //function : Edge
216 //purpose  : 
217 //=======================================================================
218   Standard_Integer BOPDS_CommonBlock::Edge()const
219 {
220   const Handle(BOPDS_PaveBlock)& aPB1=myPaveBlocks.First();
221   if(!aPB1.IsNull()) {
222     return aPB1->Edge();
223   }
224   return -1;
225 }
226 //=======================================================================
227 // function:  Contains
228 // purpose: 
229 //=======================================================================
230   Standard_Boolean BOPDS_CommonBlock::Contains(const Handle(BOPDS_PaveBlock)& aPBx)const
231 {
232   Standard_Boolean bFound;
233   Standard_Integer aNb1;
234   BOPDS_ListIteratorOfListOfPaveBlock anIt;
235   //
236   bFound=Standard_False;
237   aNb1=myPaveBlocks.Extent();
238   //
239   if (!aNb1) {
240     return bFound;
241   }
242   //
243   anIt.Initialize(myPaveBlocks);
244   for (; anIt.More(); anIt.Next()) {
245     const Handle(BOPDS_PaveBlock)& aPB=anIt.Value();
246     if (aPB==aPBx) {
247       return !bFound;
248     }
249   }
250   return bFound;
251 }
252 //=======================================================================
253 // function:  Contains
254 // purpose: 
255 //=======================================================================
256   Standard_Boolean BOPDS_CommonBlock::Contains(const Standard_Integer theF)const
257 {
258   Standard_Boolean bFound;
259   TColStd_ListIteratorOfListOfInteger aIt;
260   //
261   bFound=Standard_False;
262   aIt.Initialize(myFaces);
263   for (; aIt.More(); aIt.Next()) {
264     if (aIt.Value()==theF) {
265       return !bFound;
266     }
267   }
268   return bFound;
269 }
270 //=======================================================================
271 // function:  Dump
272 // purpose: 
273 //=======================================================================
274   void BOPDS_CommonBlock::Dump()const
275 {
276   Standard_Integer nF;
277   TColStd_ListIteratorOfListOfInteger aIt;
278   BOPDS_ListIteratorOfListOfPaveBlock aItPB;
279   //
280   printf(" -- CB:\n");
281   aItPB.Initialize(myPaveBlocks);
282   for (; aItPB.More(); aItPB.Next()) {
283     const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
284     aPB->Dump();
285     printf("\n");
286   }
287   //
288   if (myFaces.Extent()) {
289     printf(" Faces:");
290     aIt.Initialize(myFaces);
291     for (; aIt.More(); aIt.Next()) {
292       nF=aIt.Value();
293       printf(" %d", nF);
294     }
295     printf("\n");
296   }
297 }