0024157: Parallelization of assembly part of BO
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Area1dBuilder.cxx
CommitLineData
b311480e 1// Created on: 1995-12-21
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <TopOpeBRepBuild_Area1dBuilder.ixx>
23
24#include <TopOpeBRepBuild_Pave.hxx>
25#include <TopOpeBRepBuild_LoopEnum.hxx>
26#include <Standard_DomainError.hxx>
27#include <TopAbs_ShapeEnum.hxx>
28#include <TopAbs_Orientation.hxx>
29#include <TopAbs.hxx>
30
31#ifdef DEB
1d0a9d4d 32extern Standard_Boolean TopOpeBRepBuild_GettraceAREA();
33extern Standard_Boolean TopOpeBRepDS_GettraceSTRANGE();
7fd59977 34#endif
35
36//=======================================================================
37//function : DumpList
38//purpose :
39//=======================================================================
40
498ce76b 41#ifdef DEB
7fd59977 42void TopOpeBRepBuild_Area1dBuilder::DumpList(const TopOpeBRepBuild_ListOfLoop& LOL)
43{
7fd59977 44 Standard_Integer iLOL;
45 TopOpeBRepBuild_ListIteratorOfListOfLoop itLOL;
46 for (iLOL = 0, itLOL.Initialize(LOL); itLOL.More(); iLOL++, itLOL.Next()) {
47 if (iLOL) cout<<" ";
48 else cout<<"DUMP_AREA : ";
49 const Handle(TopOpeBRepBuild_Loop)& L = itLOL.Value();
50 L->Dump();cout<<endl;
51 }
498ce76b 52#else
53void TopOpeBRepBuild_Area1dBuilder::DumpList(const TopOpeBRepBuild_ListOfLoop&)
54{
7fd59977 55#endif
56}
57
58//=======================================================================
59//function : TopOpeBRepBuild_Area1dBuilder
60//purpose :
61//=======================================================================
62
63TopOpeBRepBuild_Area1dBuilder::TopOpeBRepBuild_Area1dBuilder()
64{
65}
66
67//=======================================================================
68//function : TopOpeBRepBuild_Area1dBuilder
69//purpose :
70//=======================================================================
71
72TopOpeBRepBuild_Area1dBuilder::TopOpeBRepBuild_Area1dBuilder
73(TopOpeBRepBuild_PaveSet& LS,
74 TopOpeBRepBuild_PaveClassifier& LC,
75 const Standard_Boolean ForceClass)
76{
77 InitAreaBuilder(LS,LC,ForceClass);
78}
79
80//=======================================================================
81//function : InitAreaBuilder
82//purpose :
83//=======================================================================
84
85void TopOpeBRepBuild_Area1dBuilder::InitAreaBuilder
86(TopOpeBRepBuild_LoopSet& LS,
87 TopOpeBRepBuild_LoopClassifier& LC,
88 const Standard_Boolean ForceClass)
89{
90 TopAbs_State state;
91 Standard_Boolean Loopinside;
92 Standard_Boolean loopoutside;
93
94 TopOpeBRepBuild_ListIteratorOfListOfListOfLoop AreaIter;
95 TopOpeBRepBuild_ListIteratorOfListOfLoop LoopIter;
96 // boundaryloops : list of boundary loops out of the areas.
97 TopOpeBRepBuild_ListOfLoop boundaryloops;
98
99 myArea.Clear(); // Clear the list of Area to be built
100
101 for (LS.InitLoop(); LS.MoreLoop(); LS.NextLoop()) {
102
103 // process a new loop : L is the new current Loop
104 const Handle(TopOpeBRepBuild_Loop)& L = LS.Loop();
105 Standard_Boolean boundaryL = L->IsShape();
106
107#ifdef DEB
108 if (TopOpeBRepBuild_GettraceAREA()) {
109 cout<<"++++ new loop : "; L->Dump();
110 if (boundaryL) cout<<" is bound"; else cout<<" is not bound";
111 cout<<endl;
112 }
113#endif
114
115
116 // L = shape et ForceClass : on traite L comme un block
117 // L = shape et !ForceClass : on traite L comme un pur shape
118 // L = !shape : on traite L comme un block
119 Standard_Boolean traitercommeblock = !boundaryL || ForceClass;
120 if ( ! traitercommeblock ) {
121
122 // the loop L is a boundary loop :
123 // - try to insert it in an existing area, such as L is inside all
124 // the block loops. Only block loops of the area are compared.
125 // - if L could not be inserted, store it in list of boundary loops.
126
127 Loopinside = Standard_False;
128 for (AreaIter.Initialize(myArea); AreaIter.More(); AreaIter.Next()) {
129 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
130 if ( aArea.IsEmpty() ) continue;
131 state = CompareLoopWithListOfLoop(LC,L,aArea,TopOpeBRepBuild_BLOCK);
132 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
133 Loopinside = ( state == TopAbs_IN);
134 if ( Loopinside ) break;
135 } // end of Area scan
136
137 if ( Loopinside ) {
138 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
139 ADD_Loop_TO_LISTOFLoop(L,aArea,(void*)("IN, to current area"));
140 }
141 else if ( ! Loopinside ) {
142 ADD_Loop_TO_LISTOFLoop(L,boundaryloops,(void*)("! IN, to boundaryloops"));
143 }
144
145 } // end of boundary loop
146
147 else {
148 // the loop L is a block loop
149 // if L is IN theArea :
150 // - stop area scan, insert L in theArea.
151 // - remove from the area all the loops outside L
152 // - make a new area with them, unless they are all boundary
153 // - if they are all boundary put them back in boundaryLoops
154 // else :
155 // - create a new area with L.
156 // - insert boundary loops that are IN the new area
157 // (and remove them from 'boundaryloops')
158
159 Loopinside = Standard_False;
160 for (AreaIter.Initialize(myArea); AreaIter.More(); AreaIter.Next() ) {
161 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
162 if ( aArea.IsEmpty() ) continue;
163 state = CompareLoopWithListOfLoop(LC,L,aArea,TopOpeBRepBuild_ANYLOOP);
164 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
165 Loopinside = (state == TopAbs_IN);
166 if ( Loopinside ) break;
167 } // end of Area scan
168
169 if ( Loopinside) {
170 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
171 Standard_Boolean allShape = Standard_True;
172 TopOpeBRepBuild_ListOfLoop removedLoops;
173 LoopIter.Initialize(aArea);
174 while (LoopIter.More()) {
175 state = LC.Compare(LoopIter.Value(),L);
176 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN); // not OUT
177 loopoutside = ( state == TopAbs_OUT );
178 if ( loopoutside ) {
179 const Handle(TopOpeBRepBuild_Loop)& curL = LoopIter.Value();
180 // remove the loop from the area
181 ADD_Loop_TO_LISTOFLoop
182 (curL,removedLoops,(void*)("loopoutside = 1, area = removedLoops"));
183
184 allShape = allShape && curL->IsShape();
185 REM_Loop_FROM_LISTOFLoop
186 (LoopIter,AreaIter.Value(),(void*)("loop of cur. area, cur. area"));
187 }
188 else {
189 LoopIter.Next();
190 }
191 }
192 // insert the loop in the area
193 ADD_Loop_TO_LISTOFLoop(L,aArea,(void*)("area = current"));
194 if ( ! removedLoops.IsEmpty() ) {
195 if ( allShape ) {
196 ADD_LISTOFLoop_TO_LISTOFLoop
197 (removedLoops,boundaryloops,
198 (void*)("allShape = 1"),(void*)("removedLoops"),(void*)("boundaryloops"));
199 }
200 else {
201 // make a new area with the removed loops
202 TopOpeBRepBuild_ListOfLoop thelist;
203 myArea.Append(thelist);
204 ADD_LISTOFLoop_TO_LISTOFLoop
205 (removedLoops,myArea.Last(),
206 (void*)("allShape = 0"),(void*)("removedLoops"),(void*)("new area"));
207 }
208 }
209 } // Loopinside == True
210
211 else {
212 Standard_Integer ashapeinside,ablockinside;
213 TopOpeBRepBuild_ListOfLoop thelist1;
214 myArea.Append(thelist1);
215 TopOpeBRepBuild_ListOfLoop& newArea0 = myArea.Last();
216 ADD_Loop_TO_LISTOFLoop(L,newArea0,(void*)("new area"));
217
218 LoopIter.Initialize(boundaryloops);
219 while ( LoopIter.More() ) {
220 ashapeinside = ablockinside = Standard_False;
221 state = LC.Compare(LoopIter.Value(),L);
222 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
223 ashapeinside = (state == TopAbs_IN);
224 if (ashapeinside) {
225 state = LC.Compare(L,LoopIter.Value());
226 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
227 ablockinside = (state == TopAbs_IN);
228 }
229 if ( ashapeinside && ablockinside ) {
230 const Handle(TopOpeBRepBuild_Loop)& curL = LoopIter.Value();
231 ADD_Loop_TO_LISTOFLoop
232 (curL,newArea0,(void*)("ashapeinside && ablockinside, new area"));
233
234 REM_Loop_FROM_LISTOFLoop
235 (LoopIter,boundaryloops,(void*)("loop of boundaryloops, boundaryloops"));
236 }
237 else {
238 LoopIter.Next();
239 }
240 } // end of boundaryloops scan
241 } // Loopinside == False
242 } // end of block loop
243 } // end of LoopSet LS scan
244
245#ifdef DEB
246 if (TopOpeBRepBuild_GettraceAREA()) {
247 if ( ! myArea.IsEmpty() ) {
248 cout<<"------- Areas -------"<<endl;
249 for (AreaIter.Initialize(myArea);AreaIter.More();AreaIter.Next())
250 DumpList(AreaIter.Value());
251 cout<<"---------------------"<<endl;
252 }
253 }
254#endif
255
256 InitArea();
257}
258
259//=======================================================================
260//function : ADD_Loop_TO_LISTOFLoop
261//purpose :
262//=======================================================================
263
264void TopOpeBRepBuild_Area1dBuilder::ADD_Loop_TO_LISTOFLoop
265(const Handle(TopOpeBRepBuild_Loop)& L,
266 TopOpeBRepBuild_ListOfLoop& LOL,
498ce76b 267 const Standard_Address
7fd59977 268#ifdef DEB
498ce76b 269 ss
7fd59977 270#endif
498ce76b 271 ) const
272{
7fd59977 273 LOL.Append(L);
274
275#ifdef DEB
276 if (TopOpeBRepBuild_GettraceAREA()) {
277 cout<<"--------------------- add area loop to area : ";
278 L->Dump(); cout<<endl;
498ce76b 279 if (ss != NULL) cout<<(char*)ss<<endl;
7fd59977 280 DumpList(LOL);
281 cout<<"---------------------"<<endl;
282 }
283#endif
284 }
285
286//=======================================================================
287//function : REM_Loop_FROM_LISTOFLoop
288//purpose :
289//=======================================================================
290
291void TopOpeBRepBuild_Area1dBuilder::REM_Loop_FROM_LISTOFLoop
292(TopOpeBRepBuild_ListIteratorOfListOfLoop& ITA,
293 TopOpeBRepBuild_ListOfLoop& A,
498ce76b 294#ifdef DEB
7fd59977 295 const Standard_Address ss) const
296{
7fd59977 297 char* s = (char*)ss;
498ce76b 298#else
299const Standard_Address) const
300{
7fd59977 301#endif
302
303#ifdef DEB
304 if (TopOpeBRepBuild_GettraceAREA()) {
305 if (ITA.More()) {
306 cout<<"--------------------- remove area loop from area : ";
307 ITA.Value()->Dump(); cout<<endl;
308 if (s != NULL) cout<<s<<endl;
309 }
310 }
311#endif
312
313 A.Remove(ITA);
314
315#ifdef DEB
316 if (TopOpeBRepBuild_GettraceAREA()) {
317 DumpList(A);
318 cout<<"---------------------"<<endl;
319 }
320#endif
321}
322
323//=======================================================================
324//function : ADD_LISTOFLoop_TO_LISTOFLoop
325//purpose :
326//=======================================================================
327
328void TopOpeBRepBuild_Area1dBuilder::ADD_LISTOFLoop_TO_LISTOFLoop
329(TopOpeBRepBuild_ListOfLoop& A1,
330 TopOpeBRepBuild_ListOfLoop& A2,
498ce76b 331 #ifdef DEB
7fd59977 332 const Standard_Address ss,
333 const Standard_Address ss1,
334 const Standard_Address ss2) const
498ce76b 335#else
336 const Standard_Address,
337 const Standard_Address,
338 const Standard_Address) const
339#endif
7fd59977 340{
341#ifdef DEB
342 char* s = (char*)ss;
343 char* s1 = (char*)ss1;
344 char* s2 = (char*)ss2;
345
346 if (TopOpeBRepBuild_GettraceAREA()) {
347 cout<<"--------------------- add area 1 to area 2 : ";
348 if (s != NULL) cout<<s; cout<<endl;
349 cout<<"1 : "; if (s1 != NULL) cout<<s1; cout<<endl;
350 DumpList(A1);
351 }
352#endif
353
354 A2.Append(A1);
355
356#ifdef DEB
357 if (TopOpeBRepBuild_GettraceAREA()) {
358 cout<<"2 : "; if (s2 != NULL) cout<<s2; cout<<endl;
359 DumpList(A2);
360 cout<<"---------------------"<<endl;
361 }
362#endif
363}
364
365
366
367
368
369
370
371
372