4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
4e57c75e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
4e57c75e |
14 | |
42cf5bc1 |
15 | |
16 | #include <Bnd_Box.hxx> |
4e57c75e |
17 | #include <BOPDS_ListOfPave.hxx> |
42cf5bc1 |
18 | #include <BOPDS_Pave.hxx> |
19 | #include <BOPDS_PaveBlock.hxx> |
7a76337e |
20 | #include <BOPDS_VectorOfPave.hxx> |
4e57c75e |
21 | #include <NCollection_BaseAllocator.hxx> |
42cf5bc1 |
22 | #include <Standard.hxx> |
23 | #include <Standard_Type.hxx> |
4e57c75e |
24 | |
7a76337e |
25 | #include <algorithm> |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(BOPDS_PaveBlock,MMgt_TShared) |
27 | |
57c28b61 |
28 | #ifdef _MSC_VER |
4e57c75e |
29 | #pragma warning ( disable : 4291 ) |
30 | #endif |
31 | |
4e57c75e |
32 | //======================================================================= |
33 | //function : |
34 | //purpose : |
35 | //======================================================================= |
36 | BOPDS_PaveBlock::BOPDS_PaveBlock() |
37 | : |
38 | myAllocator(NCollection_BaseAllocator::CommonBaseAllocator()), |
39 | myExtPaves(myAllocator) |
40 | { |
41 | myEdge=-1; |
42 | myOriginalEdge=-1; |
43 | myTS1=-99.; |
44 | myTS2=myTS1; |
45 | } |
46 | //======================================================================= |
47 | //function : |
48 | //purpose : |
49 | //======================================================================= |
50 | BOPDS_PaveBlock::BOPDS_PaveBlock(const Handle(NCollection_BaseAllocator)& theAllocator) |
51 | : |
52 | myAllocator(theAllocator), |
53 | myExtPaves(theAllocator), |
54 | myMFence(100, theAllocator) |
55 | { |
56 | myEdge=-1; |
57 | myOriginalEdge=-1; |
58 | myTS1=-99.; |
59 | myTS2=myTS1; |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : SetEdge |
64 | //purpose : |
65 | //======================================================================= |
66 | void BOPDS_PaveBlock::SetEdge(const Standard_Integer theEdge) |
67 | { |
68 | myEdge=theEdge; |
69 | } |
70 | //======================================================================= |
71 | //function : Edge |
72 | //purpose : |
73 | //======================================================================= |
74 | Standard_Integer BOPDS_PaveBlock::Edge()const |
75 | { |
76 | return myEdge; |
77 | } |
78 | //======================================================================= |
79 | //function : HasEdge |
80 | //purpose : |
81 | //======================================================================= |
82 | Standard_Boolean BOPDS_PaveBlock::HasEdge()const |
83 | { |
84 | return (myEdge>=0); |
85 | } |
86 | //======================================================================= |
87 | //function : HasEdge |
88 | //purpose : |
89 | //======================================================================= |
90 | Standard_Boolean BOPDS_PaveBlock::HasEdge(Standard_Integer& theEdge)const |
91 | { |
92 | theEdge=myEdge; |
93 | return (myEdge>=0); |
94 | } |
95 | |
96 | //======================================================================= |
97 | //function : SetOriginalEdge |
98 | //purpose : |
99 | //======================================================================= |
100 | void BOPDS_PaveBlock::SetOriginalEdge(const Standard_Integer theEdge) |
101 | { |
102 | myOriginalEdge=theEdge; |
103 | } |
104 | //======================================================================= |
105 | //function : OriginalEdge |
106 | //purpose : |
107 | //======================================================================= |
108 | Standard_Integer BOPDS_PaveBlock::OriginalEdge()const |
109 | { |
110 | return myOriginalEdge; |
111 | } |
112 | //======================================================================= |
113 | //function : IsSplitEdge |
114 | //purpose : |
115 | //======================================================================= |
116 | Standard_Boolean BOPDS_PaveBlock::IsSplitEdge()const |
117 | { |
118 | return (myEdge!=myOriginalEdge); |
119 | } |
120 | //======================================================================= |
121 | //function : SetPave1 |
122 | //purpose : |
123 | //======================================================================= |
124 | void BOPDS_PaveBlock::SetPave1(const BOPDS_Pave& thePave) |
125 | { |
126 | myPave1=thePave; |
127 | } |
128 | //======================================================================= |
129 | //function : Pave1 |
130 | //purpose : |
131 | //======================================================================= |
132 | const BOPDS_Pave& BOPDS_PaveBlock::Pave1()const |
133 | { |
134 | return myPave1; |
135 | } |
136 | //======================================================================= |
137 | //function : SetPave2 |
138 | //purpose : |
139 | //======================================================================= |
140 | void BOPDS_PaveBlock::SetPave2(const BOPDS_Pave& thePave) |
141 | { |
142 | myPave2=thePave; |
143 | } |
144 | //======================================================================= |
145 | //function : Pave2 |
146 | //purpose : |
147 | //======================================================================= |
148 | const BOPDS_Pave& BOPDS_PaveBlock::Pave2()const |
149 | { |
150 | return myPave2; |
151 | } |
152 | //======================================================================= |
153 | //function : Range |
154 | //purpose : |
155 | //======================================================================= |
156 | void BOPDS_PaveBlock::Range(Standard_Real& theT1, |
157 | Standard_Real& theT2)const |
158 | { |
159 | theT1=myPave1.Parameter(); |
160 | theT2=myPave2.Parameter(); |
161 | } |
162 | //======================================================================= |
163 | //function : Indices |
164 | //purpose : |
165 | //======================================================================= |
166 | void BOPDS_PaveBlock::Indices(Standard_Integer& theIndex1, |
167 | Standard_Integer& theIndex2)const |
168 | { |
169 | theIndex1=myPave1.Index(); |
170 | theIndex2=myPave2.Index(); |
171 | } |
172 | //======================================================================= |
173 | //function : HasSameBounds |
174 | //purpose : |
175 | //======================================================================= |
176 | Standard_Boolean BOPDS_PaveBlock::HasSameBounds(const Handle(BOPDS_PaveBlock)& theOther)const |
177 | { |
178 | Standard_Boolean bFlag1, bFlag2; |
179 | Standard_Integer n11, n12, n21, n22; |
180 | // |
181 | Indices(n11, n12); |
182 | theOther->Indices(n21, n22); |
183 | // |
184 | bFlag1=(n11==n21) && (n12==n22); |
185 | bFlag2=(n11==n22) && (n12==n21); |
186 | // |
187 | return (bFlag1 || bFlag2); |
188 | } |
189 | |
190 | |
191 | // |
192 | // Extras |
193 | // |
194 | //======================================================================= |
195 | //function : AppendExtPave |
196 | //purpose : |
197 | //======================================================================= |
198 | void BOPDS_PaveBlock::AppendExtPave(const BOPDS_Pave& thePave) |
199 | { |
200 | if (myMFence.Add(thePave.Index())) { |
201 | myExtPaves.Append(thePave); |
202 | } |
203 | } |
204 | //======================================================================= |
205 | //function : AppendExtPave1 |
206 | //purpose : |
207 | //======================================================================= |
208 | void BOPDS_PaveBlock::AppendExtPave1(const BOPDS_Pave& thePave) |
209 | { |
210 | myExtPaves.Append(thePave); |
211 | } |
212 | //======================================================================= |
213 | //function : ExtPaves |
214 | //purpose : |
215 | //======================================================================= |
216 | const BOPDS_ListOfPave& BOPDS_PaveBlock::ExtPaves()const |
217 | { |
218 | return myExtPaves; |
219 | } |
220 | //======================================================================= |
221 | //function : ChangeExtPaves |
222 | //purpose : |
223 | //======================================================================= |
224 | BOPDS_ListOfPave& BOPDS_PaveBlock::ChangeExtPaves() |
225 | { |
226 | return myExtPaves; |
227 | } |
228 | //======================================================================= |
229 | //function : IsToUpdate |
230 | //purpose : |
231 | //======================================================================= |
232 | Standard_Boolean BOPDS_PaveBlock::IsToUpdate()const |
233 | { |
234 | return !myExtPaves.IsEmpty(); |
235 | } |
236 | //======================================================================= |
237 | //function : ContainsParameter |
238 | //purpose : |
239 | //======================================================================= |
240 | Standard_Boolean BOPDS_PaveBlock::ContainsParameter(const Standard_Real theT, |
787c4320 |
241 | const Standard_Real theTol, |
242 | Standard_Integer& theInd) const |
4e57c75e |
243 | { |
244 | Standard_Boolean bRet; |
4e57c75e |
245 | BOPDS_ListIteratorOfListOfPave aIt; |
246 | // |
787c4320 |
247 | bRet = Standard_False; |
4e57c75e |
248 | aIt.Initialize(myExtPaves); |
249 | for (; aIt.More(); aIt.Next()) { |
787c4320 |
250 | const BOPDS_Pave& aPave = aIt.Value(); |
251 | bRet = (Abs(aPave.Parameter() - theT) < theTol); |
252 | if (bRet) { |
253 | theInd = aPave.Index(); |
4e57c75e |
254 | break; |
255 | } |
256 | } |
257 | return bRet; |
258 | } |
259 | //======================================================================= |
260 | //function : Update |
261 | //purpose : |
262 | //======================================================================= |
263 | void BOPDS_PaveBlock::Update(BOPDS_ListOfPaveBlock& theLPB, |
264 | const Standard_Boolean theFlag) |
265 | { |
266 | Standard_Integer i, aNb; |
4e57c75e |
267 | BOPDS_Pave aPave1, aPave2; |
268 | Handle(BOPDS_PaveBlock) aPB; |
269 | BOPDS_ListIteratorOfListOfPave aIt; |
270 | // |
271 | aNb=myExtPaves.Extent(); |
272 | if (theFlag) { |
273 | aNb=aNb+2; |
274 | } |
275 | // |
7a76337e |
276 | if (aNb <= 1) { |
277 | myExtPaves.Clear(); |
278 | myMFence.Clear(); |
279 | return; |
4e57c75e |
280 | } |
281 | // |
7a76337e |
282 | BOPDS_VectorOfPave pPaves(1, aNb); |
283 | // |
284 | i=1; |
4e57c75e |
285 | if (theFlag) { |
7a76337e |
286 | pPaves(i) = myPave1; |
4e57c75e |
287 | ++i; |
7a76337e |
288 | pPaves(i) = myPave2; |
4e57c75e |
289 | ++i; |
290 | } |
291 | // |
292 | aIt.Initialize(myExtPaves); |
293 | for (; aIt.More(); aIt.Next()) { |
294 | const BOPDS_Pave& aPave=aIt.Value(); |
7a76337e |
295 | pPaves(i) = aPave; |
4e57c75e |
296 | ++i; |
297 | } |
298 | myExtPaves.Clear(); |
299 | myMFence.Clear(); |
300 | // |
7a76337e |
301 | std::sort(pPaves.begin(), pPaves.end()); |
4e57c75e |
302 | // |
7a76337e |
303 | for (i = 1; i <= aNb; ++i) { |
304 | const BOPDS_Pave& aPave = pPaves(i); |
305 | if (i == 1) { |
306 | aPave1 = aPave; |
4e57c75e |
307 | continue; |
308 | } |
309 | // |
7a76337e |
310 | aPave2 = aPave; |
311 | aPB = new BOPDS_PaveBlock; |
4e57c75e |
312 | aPB->SetOriginalEdge(myOriginalEdge); |
313 | aPB->SetPave1(aPave1); |
314 | aPB->SetPave2(aPave2); |
315 | // |
316 | theLPB.Append(aPB); |
317 | // |
7a76337e |
318 | aPave1 = aPave2; |
4e57c75e |
319 | } |
4e57c75e |
320 | } |
4e57c75e |
321 | // ShrunkData |
322 | //======================================================================= |
323 | //function : HasShrunkData |
324 | //purpose : |
325 | //======================================================================= |
326 | Standard_Boolean BOPDS_PaveBlock::HasShrunkData()const |
327 | { |
328 | return (!myShrunkBox.IsVoid()); |
329 | } |
330 | //======================================================================= |
331 | //function : SetShrunkData |
332 | //purpose : |
333 | //======================================================================= |
334 | void BOPDS_PaveBlock::SetShrunkData(const Standard_Real theT1, |
335 | const Standard_Real theT2, |
336 | const Bnd_Box& theBox) |
337 | { |
338 | myTS1=theT1; |
339 | myTS2=theT2; |
340 | myShrunkBox=theBox; |
341 | } |
342 | //======================================================================= |
343 | //function : ShrunkData |
344 | //purpose : |
345 | //======================================================================= |
346 | void BOPDS_PaveBlock::ShrunkData(Standard_Real& theT1, |
347 | Standard_Real& theT2, |
348 | Bnd_Box& theBox)const |
349 | { |
350 | theT1=myTS1; |
351 | theT2=myTS2; |
352 | theBox=myShrunkBox; |
353 | } |
354 | //======================================================================= |
355 | //function : Dump |
356 | //purpose : |
357 | //======================================================================= |
358 | void BOPDS_PaveBlock::Dump()const |
359 | { |
360 | printf(" PB:{ E:%d orE:%d", myEdge, myOriginalEdge); |
361 | printf(" Pave1:"); |
362 | myPave1.Dump(); |
363 | printf(" Pave2:"); |
364 | myPave2.Dump(); |
365 | printf(" }"); |
366 | } |