0029333: Boolean Operations - Prevent modification of the input shapes in case their...
[occt.git] / src / BOPDS / BOPDS_CommonBlock.cxx
CommitLineData
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 <BOPDS_CommonBlock.hxx>
17#include <BOPDS_PaveBlock.hxx>
18#include <Standard_Type.hxx>
4e57c75e 19
25e59720 20IMPLEMENT_STANDARD_RTTIEXT(BOPDS_CommonBlock,Standard_Transient)
92efcf78 21
4e57c75e 22//=======================================================================
23// function:
24// purpose:
25//=======================================================================
26 BOPDS_CommonBlock::BOPDS_CommonBlock()
27{
28}
29//=======================================================================
30// function:
31// purpose:
32//=======================================================================
33 BOPDS_CommonBlock::BOPDS_CommonBlock(const Handle(NCollection_BaseAllocator)& theAllocator)
34:
35 myPaveBlocks(theAllocator),
36 myFaces(theAllocator)
37{
38}
39//=======================================================================
40// function: AddPaveBlock
41// purpose:
42//=======================================================================
43 void BOPDS_CommonBlock::AddPaveBlock(const Handle(BOPDS_PaveBlock)& aPB)
44{
edfa30de 45 if (myPaveBlocks.IsEmpty()) {
46 myPaveBlocks.Append(aPB);
47 return;
48 }
49 //
50 // Put the pave block with the minimal index of the original edge in the first place
51 if (aPB->OriginalEdge() < myPaveBlocks.First()->OriginalEdge()) {
52 myPaveBlocks.Prepend(aPB);
53 }
54 else {
55 myPaveBlocks.Append(aPB);
56 }
4e57c75e 57}
58//=======================================================================
edfa30de 59// function: SetPaveBlocks
4e57c75e 60// purpose:
61//=======================================================================
edfa30de 62 void BOPDS_CommonBlock::SetPaveBlocks(const BOPDS_ListOfPaveBlock& aLPB)
4e57c75e 63{
edfa30de 64 myPaveBlocks.Clear();
65 BOPDS_ListIteratorOfListOfPaveBlock aIt(aLPB);
66 for (; aIt.More(); aIt.Next()) {
67 AddPaveBlock(aIt.Value());
68 }
4e57c75e 69}
70//=======================================================================
71// function: PaveBlocks
72// purpose:
73//=======================================================================
74 const BOPDS_ListOfPaveBlock& BOPDS_CommonBlock::PaveBlocks()const
75{
76 return myPaveBlocks;
77}
78//=======================================================================
79// function: AddFace
80// purpose:
81//=======================================================================
82 void BOPDS_CommonBlock::AddFace(const Standard_Integer aF)
83{
84 myFaces.Append(aF);
85}
86//=======================================================================
87// function: AddFaces
88// purpose:
89//=======================================================================
1155d05a 90 void BOPDS_CommonBlock::SetFaces(const TColStd_ListOfInteger& aLF)
4e57c75e 91{
92 myFaces=aLF;
93}
94//=======================================================================
3510db62 95// function: AppendFaces
96// purpose:
97//=======================================================================
1155d05a 98void BOPDS_CommonBlock::AppendFaces(TColStd_ListOfInteger& aLF)
3510db62 99{
100 myFaces.Append(aLF);
101}
102 //=======================================================================
4e57c75e 103// function: Faces
104// purpose:
105//=======================================================================
1155d05a 106 const TColStd_ListOfInteger& BOPDS_CommonBlock::Faces()const
4e57c75e 107{
108 return myFaces;
109}
110//=======================================================================
111// function: PaveBlock1
112// purpose:
113//=======================================================================
114 const Handle(BOPDS_PaveBlock)& BOPDS_CommonBlock::PaveBlock1()const
115{
116 return myPaveBlocks.First();
117}
118//=======================================================================
81a55a69 119// function: SetRealPaveBlock
120// purpose:
121//=======================================================================
122void BOPDS_CommonBlock::SetRealPaveBlock(const Handle(BOPDS_PaveBlock)& thePB)
123{
124 BOPDS_ListIteratorOfListOfPaveBlock it(myPaveBlocks);
125 for (; it.More(); it.Next())
126 {
127 if (it.Value() == thePB)
128 {
129 myPaveBlocks.Prepend(thePB);
130 myPaveBlocks.Remove(it);
131 break;
132 }
133 }
134}
135//=======================================================================
4e57c75e 136// function: PaveBlockOnEdge
137// purpose:
138//=======================================================================
139 Handle(BOPDS_PaveBlock)& BOPDS_CommonBlock::PaveBlockOnEdge(const Standard_Integer aIx)
140{
141 static Handle(BOPDS_PaveBlock) aPBs;
142 //
143 Standard_Integer aIOr;
144 BOPDS_ListIteratorOfListOfPaveBlock anIt;
145 //
146 anIt.Initialize(myPaveBlocks);
147 for (; anIt.More(); anIt.Next()) {
148 Handle(BOPDS_PaveBlock)& aPB=anIt.ChangeValue();
149 aIOr=aPB->OriginalEdge();
150 if (aIOr==aIx){
151 return aPB;
152 }
153 }
154 return aPBs;
155}
156//=======================================================================
157// function: IsPaveBlockOnFace
158// purpose:
159//=======================================================================
160 Standard_Boolean BOPDS_CommonBlock::IsPaveBlockOnFace(const Standard_Integer aIx)const
161{
162 Standard_Boolean bFound;
163 Standard_Integer nF;
1155d05a 164 TColStd_ListIteratorOfListOfInteger anIt;
4e57c75e 165 //
166 bFound=Standard_False;
167 anIt.Initialize(myFaces);
168 for (; anIt.More(); anIt.Next()) {
169 nF=anIt.Value();
170 if (nF==aIx){
171 return !bFound;
172 }
173 }
174 return bFound;
175}
176//=======================================================================
177// function: IsPaveBlockOnEdge
178// purpose:
179//=======================================================================
180 Standard_Boolean BOPDS_CommonBlock::IsPaveBlockOnEdge(const Standard_Integer aIx)const
181{
182 Standard_Boolean bFound;
183 Standard_Integer aIOr;
184 BOPDS_ListIteratorOfListOfPaveBlock anIt;
185 //
186 bFound=Standard_False;
187 anIt.Initialize(myPaveBlocks);
188 for (; anIt.More(); anIt.Next()) {
189 const Handle(BOPDS_PaveBlock)& aPB=anIt.Value();
190 aIOr=aPB->OriginalEdge();
191 if (aIOr==aIx){
192 return !bFound;
193 }
194 }
195 return bFound;
196}
197//=======================================================================
198//function : SetEdge
199//purpose :
200//=======================================================================
201 void BOPDS_CommonBlock::SetEdge(const Standard_Integer theEdge)
202{
203 BOPDS_ListIteratorOfListOfPaveBlock anIt;
204 //
205 anIt.Initialize(myPaveBlocks);
206 for (; anIt.More(); anIt.Next()) {
207 Handle(BOPDS_PaveBlock)& aPB=anIt.ChangeValue();
208 aPB->SetEdge(theEdge);
209 }
210}
211//=======================================================================
212//function : Edge
213//purpose :
214//=======================================================================
215 Standard_Integer BOPDS_CommonBlock::Edge()const
216{
217 const Handle(BOPDS_PaveBlock)& aPB1=myPaveBlocks.First();
218 if(!aPB1.IsNull()) {
219 return aPB1->Edge();
220 }
221 return -1;
222}
223//=======================================================================
224// function: Contains
225// purpose:
226//=======================================================================
227 Standard_Boolean BOPDS_CommonBlock::Contains(const Handle(BOPDS_PaveBlock)& aPBx)const
228{
229 Standard_Boolean bFound;
230 Standard_Integer aNb1;
231 BOPDS_ListIteratorOfListOfPaveBlock anIt;
232 //
233 bFound=Standard_False;
234 aNb1=myPaveBlocks.Extent();
235 //
236 if (!aNb1) {
237 return bFound;
238 }
239 //
240 anIt.Initialize(myPaveBlocks);
241 for (; anIt.More(); anIt.Next()) {
242 const Handle(BOPDS_PaveBlock)& aPB=anIt.Value();
243 if (aPB==aPBx) {
244 return !bFound;
245 }
246 }
247 return bFound;
248}
249//=======================================================================
250// function: Contains
251// purpose:
252//=======================================================================
253 Standard_Boolean BOPDS_CommonBlock::Contains(const Standard_Integer theF)const
254{
255 Standard_Boolean bFound;
1155d05a 256 TColStd_ListIteratorOfListOfInteger aIt;
4e57c75e 257 //
258 bFound=Standard_False;
259 aIt.Initialize(myFaces);
260 for (; aIt.More(); aIt.Next()) {
261 if (aIt.Value()==theF) {
262 return !bFound;
263 }
264 }
265 return bFound;
266}
267//=======================================================================
268// function: Dump
269// purpose:
270//=======================================================================
271 void BOPDS_CommonBlock::Dump()const
272{
273 Standard_Integer nF;
1155d05a 274 TColStd_ListIteratorOfListOfInteger aIt;
4e57c75e 275 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
276 //
277 printf(" -- CB:\n");
278 aItPB.Initialize(myPaveBlocks);
279 for (; aItPB.More(); aItPB.Next()) {
280 const Handle(BOPDS_PaveBlock)& aPB=aItPB.Value();
281 aPB->Dump();
282 printf("\n");
283 }
284 //
285 if (myFaces.Extent()) {
286 printf(" Faces:");
287 aIt.Initialize(myFaces);
288 for (; aIt.More(); aIt.Next()) {
289 nF=aIt.Value();
290 printf(" %d", nF);
291 }
292 printf("\n");
293 }
294}