0023024: Update headers of OCCT files
[occt.git] / src / BOPTools / BOPTools_IteratorOfCoupleOfShape.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18
19#include <BOPTools_IteratorOfCoupleOfShape.ixx>
20
21#include <BooleanOperations_ShapesDataStructure.hxx>
22#include <BOPTools_RoughShapeIntersector.hxx>
23#include <BOPTools_CoupleOfInteger.hxx>
24
25// ================================================================================================
26// function: Constructor
27// ================================================================================================
b311480e 28BOPTools_IteratorOfCoupleOfShape::BOPTools_IteratorOfCoupleOfShape()
7fd59977 29:
30 myCurrentIndex1(-1),
31 myCurrentIndex2(-1),
32 myType1(TopAbs_SHAPE),
33 myType2(TopAbs_SHAPE),
34 myFirstLowerIndex(1),
35 myFirstUpperIndex(0),
36 mySecondLowerIndex(1),
37 mySecondUpperIndex(0)
38{
39 myPDS = NULL;
40}
41
42// ================================================================================================
43// function: Constructor
44// ================================================================================================
45 BOPTools_IteratorOfCoupleOfShape::BOPTools_IteratorOfCoupleOfShape(const BooleanOperations_PShapesDataStructure& PDS,
46 const TopAbs_ShapeEnum Type1,
47 const TopAbs_ShapeEnum Type2)
48 :
49 myCurrentIndex1(-1),
50 myCurrentIndex2(-1),
51 myType1(TopAbs_SHAPE),
52 myType2(TopAbs_SHAPE)
53{
54 SetDataStructure(PDS);
55
56 Initialize(Type1, Type2);
57}
58
59// ================================================================================================
60// function: virtual destructor
61// ================================================================================================
62void BOPTools_IteratorOfCoupleOfShape::Destroy()
63{
64}
65
66// ================================================================================================
67// function: SetDataStructure
68// ================================================================================================
69 void BOPTools_IteratorOfCoupleOfShape::SetDataStructure(const BooleanOperations_PShapesDataStructure& PDS)
70{
71 if(PDS==NULL) {
72 Standard_NoSuchObject::Raise("BOPTools_IteratorOfCoupleOfShape::SetDataStructure: PDS==NULL");
73 }
74
75 myListOfCouple.Clear();
76
77 myPDS = PDS;
78
79 BOPTools_RoughShapeIntersector aRoughIntersector(myPDS);
80 aRoughIntersector.Perform();
81 if(aRoughIntersector.IsDone()) {
82 myTableOfStatus = aRoughIntersector.TableOfStatus();
83 } else {
84 Handle(BOPTools_HArray2OfIntersectionStatus) anemptyhandle;
85 myTableOfStatus = anemptyhandle;
86 }
87}
88
89
90// ================================================================================================
91// function: Initialize
92// ================================================================================================
93 void BOPTools_IteratorOfCoupleOfShape::Initialize(const TopAbs_ShapeEnum Type1,
94 const TopAbs_ShapeEnum Type2)
95{
96
97 if(myPDS==NULL) {
98 Standard_NoSuchObject::Raise("BOPTools_IteratorOfCoupleOfShape::Initialize: myPDS==NULL");
99 }
100 myType1 = Type1;
101 myType2 = Type2;
102 myCurrentIndex1 = -1;
103 myCurrentIndex2 = -1;
104 //
105 myFirstLowerIndex=1;
106 myFirstUpperIndex=myPDS->NumberOfShapesOfTheObject();
107 mySecondLowerIndex=myFirstUpperIndex+1;
108 mySecondUpperIndex=myFirstUpperIndex+myPDS->NumberOfShapesOfTheTool();
109
110 NextP();
111
112 Standard_Integer n1, n2;
113
114 myListOfCouple.Clear();
115 for (; MoreP(); NextP()) {
116 CurrentP(n1, n2);
117 BOPTools_CoupleOfInteger aCouple(n1, n2);
118 myListOfCouple.Append(aCouple);
119 }
120 myIterator.Initialize(myListOfCouple);
121}
122
123//=======================================================================
124// function: More
125// purpose:
126//=======================================================================
127 Standard_Boolean BOPTools_IteratorOfCoupleOfShape::More()const
128{
129 return myIterator.More();
130}
131//=======================================================================
132// function: Next
133// purpose:
134//=======================================================================
135 void BOPTools_IteratorOfCoupleOfShape::Next()
136{
137 myIterator.Next();
138}
139//=======================================================================
140// function: Current
141// purpose:
142//=======================================================================
143 void BOPTools_IteratorOfCoupleOfShape::Current(Standard_Integer& Index1,
144 Standard_Integer& Index2,
145 Standard_Boolean& WithSubShape) const
146{
147 WithSubShape = Standard_False;
148
149 const BOPTools_CoupleOfInteger& aCouple=myIterator.Value();
150 aCouple.Couple(Index1, Index2);
151
152 BOPTools_IntersectionStatus aStatus = myTableOfStatus->Value(Index1, Index2);
153
154 if(aStatus == BOPTools_BOUNDINGBOXOFSUBSHAPESINTERSECTED) {
155 WithSubShape = Standard_True;
156 }
157}
158
159//=======================================================================
160// function: ListOfCouple
161// purpose:
162//=======================================================================
163 const BOPTools_ListOfCoupleOfInteger& BOPTools_IteratorOfCoupleOfShape::ListOfCouple() const
164{
165 return myListOfCouple;
166}
167
168// ================================================================================================
169// function: NextP
170// ================================================================================================
171 void BOPTools_IteratorOfCoupleOfShape::NextP()
172{
173 if(myPDS==NULL) {
174 myCurrentIndex1 = -1;
175 myCurrentIndex2 = -1;
176 return;
177 }
178
179 Standard_Boolean couplefound, IsValidTableOfStatus = Standard_False;
180 Standard_Integer stopedindex1, stopedindex2, starti, i, startj, j;
181 TopAbs_ShapeEnum aTypei, aTypej;
182
183 stopedindex1 = myCurrentIndex1;
184 stopedindex2 = myCurrentIndex2;
185
186 if(!myTableOfStatus.IsNull()) {
187 IsValidTableOfStatus = Standard_True;
188 }
189
190 myCurrentIndex1 = -1;
191 myCurrentIndex2 = -1;
192
193 couplefound = Standard_False;
194 starti = stopedindex1;
195 if(starti < 0){
196 starti = myFirstLowerIndex;
197 }
198 for(i = starti; !couplefound && i<=myFirstUpperIndex; i++) {
199 startj = mySecondLowerIndex;
200 if(i==stopedindex1 && (stopedindex2 >= 0)) {
201 startj = stopedindex2 + 1;
202 }
203 for(j = startj; !couplefound && j<=mySecondUpperIndex; j++) {
204 aTypei=myPDS->GetShapeType(i);
205 aTypej=myPDS->GetShapeType(j);
206
207 if(((aTypei == myType1) && (aTypej == myType2)) ||
208 ((aTypei == myType2) && (aTypej == myType1))) {
209 myCurrentIndex1 = i;
210 myCurrentIndex2 = j;
211 //
212 couplefound = Standard_True;
213 if(IsValidTableOfStatus) {
214 BOPTools_IntersectionStatus aStatus = myTableOfStatus->Value(i, j);
215 if(aStatus==BOPTools_INTERSECTED || aStatus==BOPTools_NONINTERSECTED) {
216 myCurrentIndex1 = -1;
217 myCurrentIndex2 = -1;
218 couplefound = Standard_False;
219 }
220 }
221 }
222 }
223 }
224 //}
225}
226
227// ================================================================================================
228// function: More
229// ================================================================================================
230 Standard_Boolean BOPTools_IteratorOfCoupleOfShape::MoreP() const
231{
232 if((myCurrentIndex1 < 0) || (myCurrentIndex2 < 0))
233 return Standard_False;
234 return Standard_True;
235}
236
237// ================================================================================================
238// function: Current
239// ================================================================================================
240 void BOPTools_IteratorOfCoupleOfShape::CurrentP(Standard_Integer& Index1,
241 Standard_Integer& Index2) const
242{
243 if((myCurrentIndex1 < 0) || (myCurrentIndex2 < 0)) {
244 Standard_NoSuchObject::Raise("BOPTools_IteratorOfCoupleOfShape::Current");
245 }
246 Index1 = myCurrentIndex1;
247 Index2 = myCurrentIndex2;
248}
249
250
251// ================================================================================================
252// function: SetIntersectionStatus
253// ================================================================================================
254 void BOPTools_IteratorOfCoupleOfShape::SetIntersectionStatus(const Standard_Integer Index1,
255 const Standard_Integer Index2,
256 const BOPTools_IntersectionStatus theStatus)
257{
258 if((Index1 >= myTableOfStatus->LowerRow()) &&
259 (Index1 <= myTableOfStatus->UpperRow()) &&
260 (Index2 >= myTableOfStatus->LowerCol()) &&
261 (Index2 <= myTableOfStatus->UpperCol())) {
262 myTableOfStatus->ChangeValue(Index1, Index2) = theStatus;
263 }
264}
265
266// ================================================================================================
267// function: GetTableOfIntersectionStatus
268// ================================================================================================
269 const Handle(BOPTools_HArray2OfIntersectionStatus)&
270 BOPTools_IteratorOfCoupleOfShape::GetTableOfIntersectionStatus() const
271{
272 return myTableOfStatus;
273}
274
275// ================================================================================================
276// function: DumpTableOfIntersectionStatus
277// ================================================================================================
278 void BOPTools_IteratorOfCoupleOfShape::DumpTableOfIntersectionStatus() const
279{
280 cout << "*BOPTools_IteratorOfCoupleOfShape::DumpTableOfIntersectionStatus.BEGIN*" << endl;
281 cout << "myTableOfStatus.LowerRow="<< myTableOfStatus->LowerRow() << endl;
282 cout << "myTableOfStatus.UpperRow="<< myTableOfStatus->UpperRow() << endl;
283 cout << "myTableOfStatus.LowerCol()="<< myTableOfStatus->LowerCol() << endl;
284 cout << "myTableOfStatus.UpperCol()="<< myTableOfStatus->UpperCol() << endl;
285 for(Standard_Integer k=myTableOfStatus->LowerCol(); k<=myTableOfStatus->UpperCol(); k++) {
286 cout << k << " ";
287 }
288 cout << endl;
289 for(Standard_Integer i=myTableOfStatus->LowerRow(); i<=myTableOfStatus->UpperRow(); i++) {
290 for(Standard_Integer j=myTableOfStatus->LowerCol(); j<=myTableOfStatus->UpperCol(); j++) {
291 cout << myTableOfStatus->Value(i, j) << " ";
292 }
293 cout << endl;
294 }
295 cout << "*BOPTools_IteratorOfCoupleOfShape::DumpTableOfIntersectionStatus.END*" << endl;
296}