0025418: Debug output to be limited to OCC development environment
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_Area2dBuilder.cxx
CommitLineData
b311480e 1// Created on: 1995-12-21
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TopOpeBRepBuild_Area2dBuilder.ixx>
18#include <TopOpeBRepBuild_Loop.hxx>
19
0797d9d3 20#ifdef OCCT_DEBUG
1d0a9d4d 21extern Standard_Boolean TopOpeBRepBuild_GettraceAREA();
7fd59977 22#endif
23
24//=======================================================================
25//function : TopOpeBRepBuild_Area2dBuilder
26//purpose :
27//=======================================================================
28
29TopOpeBRepBuild_Area2dBuilder::TopOpeBRepBuild_Area2dBuilder()
30{
31}
32
33//=======================================================================
34//function : TopOpeBRepBuild_Area2dBuilder
35//purpose :
36//=======================================================================
37
38TopOpeBRepBuild_Area2dBuilder::TopOpeBRepBuild_Area2dBuilder
39(TopOpeBRepBuild_LoopSet& LS, TopOpeBRepBuild_LoopClassifier& LC,
40 const Standard_Boolean ForceClass)
41{
42 InitAreaBuilder(LS,LC,ForceClass);
43}
44
45//=======================================================================
46//function : InitAreaBuilder
47//purpose :
48//=======================================================================
49
50void TopOpeBRepBuild_Area2dBuilder::InitAreaBuilder
51(TopOpeBRepBuild_LoopSet& LS,
52 TopOpeBRepBuild_LoopClassifier& LC,
53 const Standard_Boolean ForceClass)
54{
55 TopAbs_State state;
56 Standard_Boolean Loopinside;
57 Standard_Boolean loopoutside;
58
59 TopOpeBRepBuild_ListIteratorOfListOfListOfLoop AreaIter;
60 TopOpeBRepBuild_ListIteratorOfListOfLoop LoopIter;
61 // boundaryloops : list of boundary loops out of the areas.
62 TopOpeBRepBuild_ListOfLoop boundaryloops;
63
64 myArea.Clear(); // Clear the list of Area to be built
65
66 for (LS.InitLoop(); LS.MoreLoop(); LS.NextLoop()) {
67
68 // process a new loop : L is the new current Loop
69 const Handle(TopOpeBRepBuild_Loop)& L = LS.Loop();
70 Standard_Boolean boundaryL = L->IsShape();
71
72 // L = shape et ForceClass : on traite L comme un block
73 // L = shape et !ForceClass : on traite L comme un pur shape
74 // L = !shape : on traite L comme un block
75 Standard_Boolean traitercommeblock = (!boundaryL) || ForceClass;
76 if ( ! traitercommeblock ) {
77
78 // the loop L is a boundary loop :
79 // - try to insert it in an existing area, such as L is inside all
80 // the block loops. Only block loops of the area are compared.
81 // - if L could not be inserted, store it in list of boundary loops.
82
83 Loopinside = Standard_False;
84 for (AreaIter.Initialize(myArea); AreaIter.More(); AreaIter.Next()) {
85 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
86 if ( aArea.IsEmpty() ) continue;
87 state = CompareLoopWithListOfLoop(LC,L,aArea,TopOpeBRepBuild_BLOCK );
88 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
89 Loopinside = ( state == TopAbs_IN);
90 if ( Loopinside ) break;
91 } // end of Area scan
92
93 if ( Loopinside ) {
94 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
95 ADD_Loop_TO_LISTOFLoop(L,aArea,(void*)("IN, to current area"));
96 }
97 else if ( ! Loopinside ) {
98 ADD_Loop_TO_LISTOFLoop(L,boundaryloops,(void*)("! IN, to boundaryloops"));
99 }
100
101 } // end of boundary loop
102
103 else {
104 // the loop L is a block loop
105 // if L is IN theArea :
106 // - stop area scan, insert L in theArea.
107 // - remove from the area all the loops outside L
108 // - make a new area with them, unless they are all boundary
109 // - if they are all boundary put them back in boundaryLoops
110 // else :
111 // - create a new area with L.
112 // - insert boundary loops that are IN the new area
113 // (and remove them from 'boundaryloops')
114
115 Loopinside = Standard_False;
116 for (AreaIter.Initialize(myArea); AreaIter.More(); AreaIter.Next() ) {
117 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
118 if ( aArea.IsEmpty() ) continue;
119 state = CompareLoopWithListOfLoop(LC,L,aArea,TopOpeBRepBuild_ANYLOOP);
120 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
121 Loopinside = (state == TopAbs_IN);
122 if ( Loopinside ) break;
123 } // end of Area scan
124
125 if ( Loopinside) {
126 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
127 Standard_Boolean allShape = Standard_True;
128 TopOpeBRepBuild_ListOfLoop removedLoops;
129 LoopIter.Initialize(aArea);
130 while (LoopIter.More()) {
131 state = LC.Compare(LoopIter.Value(),L);
132 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN); // not OUT
133 loopoutside = ( state == TopAbs_OUT );
134 if ( loopoutside ) {
135 const Handle(TopOpeBRepBuild_Loop)& curL = LoopIter.Value();
136 // remove the loop from the area
137 ADD_Loop_TO_LISTOFLoop
138 (curL,removedLoops,(void*)("loopoutside = 1, area = removedLoops"));
139
140 allShape = allShape && curL->IsShape();
141 REM_Loop_FROM_LISTOFLoop
142 (LoopIter,AreaIter.Value(),(void*)("loop of cur. area, cur. area"));
143 }
144 else {
145 LoopIter.Next();
146 }
147 }
148 // insert the loop in the area
149 ADD_Loop_TO_LISTOFLoop(L,aArea,(void*)("area = current"));
150 if ( ! removedLoops.IsEmpty() ) {
151 if ( allShape ) {
152 ADD_LISTOFLoop_TO_LISTOFLoop
153 (removedLoops,boundaryloops,
154 (void*)("allShape = 1"),(void*)("removedLoops"),(void*)("boundaryloops"));
155 }
156 else {
157 // make a new area with the removed loops
158 TopOpeBRepBuild_ListOfLoop thelist;
159 myArea.Append(thelist);
160 ADD_LISTOFLoop_TO_LISTOFLoop
161 (removedLoops,myArea.Last(),
162 (void*)("allShape = 0"),(void*)("removedLoops"),(void*)("new area"));
163 }
164 }
165 } // Loopinside == True
166
167 else {
168 Standard_Integer ashapeinside,ablockinside;
169 TopOpeBRepBuild_ListOfLoop thelist1;
170 myArea.Append(thelist1);
171 TopOpeBRepBuild_ListOfLoop& newArea0 = myArea.Last();
172 ADD_Loop_TO_LISTOFLoop(L,newArea0,(void*)("new area"));
173
174 LoopIter.Initialize(boundaryloops);
175
176
177 while ( LoopIter.More() ) {
178 ashapeinside = ablockinside = Standard_False;
179 const Handle(TopOpeBRepBuild_Loop)& lb = LoopIter.Value();
180 state = LC.Compare(lb,L);
181 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
182 ashapeinside = (state == TopAbs_IN);
183 if (ashapeinside) {
184 state = LC.Compare(L,lb);
185 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
186 ablockinside = (state == TopAbs_IN);
187 }
188 if ( ashapeinside && ablockinside ) {
189 const Handle(TopOpeBRepBuild_Loop)& curL = LoopIter.Value();
190 ADD_Loop_TO_LISTOFLoop
191 (curL,newArea0,(void*)("ashapeinside && ablockinside, new area"));
192
193 REM_Loop_FROM_LISTOFLoop
194 (LoopIter,boundaryloops,(void*)("loop of boundaryloops, boundaryloops"));
195 }
196 else {
197 LoopIter.Next();
198 }
199 } // end of boundaryloops scan
200 } // Loopinside == False
201 } // end of block loop
202 } // end of LoopSet LS scan
203
204 if ( ! boundaryloops.IsEmpty() ) {
205 if ( myArea.IsEmpty() ) {
0797d9d3 206#ifdef OCCT_DEBUG
7fd59977 207 if (TopOpeBRepBuild_GettraceAREA())
208 cout<<"---"<<endl<<"--- purge"<<endl<<"---"<<endl;
209#endif
210 TopOpeBRepBuild_ListOfLoop newArea3;
211 newArea3.Append(boundaryloops);
212 myArea.Append(newArea3);
213 }
214 }
215
216 InitArea();
217}