1 // File: TopOpeBRepBuild_Area1dBuilder.cxx
2 // Created: Thu Dec 21 17:07:40 1995
3 // Author: Jean Yves LEBEY
5 // Copyright: Matra Datavision 1995
7 #include <TopOpeBRepBuild_Area1dBuilder.ixx>
9 #include <TopOpeBRepBuild_Pave.hxx>
10 #include <TopOpeBRepBuild_LoopEnum.hxx>
11 #include <Standard_DomainError.hxx>
12 #include <TopAbs_ShapeEnum.hxx>
13 #include <TopAbs_Orientation.hxx>
17 Standard_IMPORT Standard_Boolean TopOpeBRepBuild_GettraceAREA();
18 Standard_IMPORT Standard_Boolean TopOpeBRepDS_GettraceSTRANGE();
21 //=======================================================================
24 //=======================================================================
26 void TopOpeBRepBuild_Area1dBuilder::DumpList(const TopOpeBRepBuild_ListOfLoop& LOL)
29 Standard_Integer iLOL;
30 TopOpeBRepBuild_ListIteratorOfListOfLoop itLOL;
31 for (iLOL = 0, itLOL.Initialize(LOL); itLOL.More(); iLOL++, itLOL.Next()) {
33 else cout<<"DUMP_AREA : ";
34 const Handle(TopOpeBRepBuild_Loop)& L = itLOL.Value();
40 //=======================================================================
41 //function : TopOpeBRepBuild_Area1dBuilder
43 //=======================================================================
45 TopOpeBRepBuild_Area1dBuilder::TopOpeBRepBuild_Area1dBuilder()
49 //=======================================================================
50 //function : TopOpeBRepBuild_Area1dBuilder
52 //=======================================================================
54 TopOpeBRepBuild_Area1dBuilder::TopOpeBRepBuild_Area1dBuilder
55 (TopOpeBRepBuild_PaveSet& LS,
56 TopOpeBRepBuild_PaveClassifier& LC,
57 const Standard_Boolean ForceClass)
59 InitAreaBuilder(LS,LC,ForceClass);
62 //=======================================================================
63 //function : InitAreaBuilder
65 //=======================================================================
67 void TopOpeBRepBuild_Area1dBuilder::InitAreaBuilder
68 (TopOpeBRepBuild_LoopSet& LS,
69 TopOpeBRepBuild_LoopClassifier& LC,
70 const Standard_Boolean ForceClass)
73 Standard_Boolean Loopinside;
74 Standard_Boolean loopoutside;
76 TopOpeBRepBuild_ListIteratorOfListOfListOfLoop AreaIter;
77 TopOpeBRepBuild_ListIteratorOfListOfLoop LoopIter;
78 // boundaryloops : list of boundary loops out of the areas.
79 TopOpeBRepBuild_ListOfLoop boundaryloops;
81 myArea.Clear(); // Clear the list of Area to be built
83 for (LS.InitLoop(); LS.MoreLoop(); LS.NextLoop()) {
85 // process a new loop : L is the new current Loop
86 const Handle(TopOpeBRepBuild_Loop)& L = LS.Loop();
87 Standard_Boolean boundaryL = L->IsShape();
90 if (TopOpeBRepBuild_GettraceAREA()) {
91 cout<<"++++ new loop : "; L->Dump();
92 if (boundaryL) cout<<" is bound"; else cout<<" is not bound";
98 // L = shape et ForceClass : on traite L comme un block
99 // L = shape et !ForceClass : on traite L comme un pur shape
100 // L = !shape : on traite L comme un block
101 Standard_Boolean traitercommeblock = !boundaryL || ForceClass;
102 if ( ! traitercommeblock ) {
104 // the loop L is a boundary loop :
105 // - try to insert it in an existing area, such as L is inside all
106 // the block loops. Only block loops of the area are compared.
107 // - if L could not be inserted, store it in list of boundary loops.
109 Loopinside = Standard_False;
110 for (AreaIter.Initialize(myArea); AreaIter.More(); AreaIter.Next()) {
111 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
112 if ( aArea.IsEmpty() ) continue;
113 state = CompareLoopWithListOfLoop(LC,L,aArea,TopOpeBRepBuild_BLOCK);
114 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
115 Loopinside = ( state == TopAbs_IN);
116 if ( Loopinside ) break;
117 } // end of Area scan
120 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
121 ADD_Loop_TO_LISTOFLoop(L,aArea,(void*)("IN, to current area"));
123 else if ( ! Loopinside ) {
124 ADD_Loop_TO_LISTOFLoop(L,boundaryloops,(void*)("! IN, to boundaryloops"));
127 } // end of boundary loop
130 // the loop L is a block loop
131 // if L is IN theArea :
132 // - stop area scan, insert L in theArea.
133 // - remove from the area all the loops outside L
134 // - make a new area with them, unless they are all boundary
135 // - if they are all boundary put them back in boundaryLoops
137 // - create a new area with L.
138 // - insert boundary loops that are IN the new area
139 // (and remove them from 'boundaryloops')
141 Loopinside = Standard_False;
142 for (AreaIter.Initialize(myArea); AreaIter.More(); AreaIter.Next() ) {
143 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
144 if ( aArea.IsEmpty() ) continue;
145 state = CompareLoopWithListOfLoop(LC,L,aArea,TopOpeBRepBuild_ANYLOOP);
146 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
147 Loopinside = (state == TopAbs_IN);
148 if ( Loopinside ) break;
149 } // end of Area scan
152 TopOpeBRepBuild_ListOfLoop& aArea = AreaIter.Value();
153 Standard_Boolean allShape = Standard_True;
154 TopOpeBRepBuild_ListOfLoop removedLoops;
155 LoopIter.Initialize(aArea);
156 while (LoopIter.More()) {
157 state = LC.Compare(LoopIter.Value(),L);
158 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN); // not OUT
159 loopoutside = ( state == TopAbs_OUT );
161 const Handle(TopOpeBRepBuild_Loop)& curL = LoopIter.Value();
162 // remove the loop from the area
163 ADD_Loop_TO_LISTOFLoop
164 (curL,removedLoops,(void*)("loopoutside = 1, area = removedLoops"));
166 allShape = allShape && curL->IsShape();
167 REM_Loop_FROM_LISTOFLoop
168 (LoopIter,AreaIter.Value(),(void*)("loop of cur. area, cur. area"));
174 // insert the loop in the area
175 ADD_Loop_TO_LISTOFLoop(L,aArea,(void*)("area = current"));
176 if ( ! removedLoops.IsEmpty() ) {
178 ADD_LISTOFLoop_TO_LISTOFLoop
179 (removedLoops,boundaryloops,
180 (void*)("allShape = 1"),(void*)("removedLoops"),(void*)("boundaryloops"));
183 // make a new area with the removed loops
184 TopOpeBRepBuild_ListOfLoop thelist;
185 myArea.Append(thelist);
186 ADD_LISTOFLoop_TO_LISTOFLoop
187 (removedLoops,myArea.Last(),
188 (void*)("allShape = 0"),(void*)("removedLoops"),(void*)("new area"));
191 } // Loopinside == True
194 Standard_Integer ashapeinside,ablockinside;
195 TopOpeBRepBuild_ListOfLoop thelist1;
196 myArea.Append(thelist1);
197 TopOpeBRepBuild_ListOfLoop& newArea0 = myArea.Last();
198 ADD_Loop_TO_LISTOFLoop(L,newArea0,(void*)("new area"));
200 LoopIter.Initialize(boundaryloops);
201 while ( LoopIter.More() ) {
202 ashapeinside = ablockinside = Standard_False;
203 state = LC.Compare(LoopIter.Value(),L);
204 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
205 ashapeinside = (state == TopAbs_IN);
207 state = LC.Compare(L,LoopIter.Value());
208 if (state == TopAbs_UNKNOWN) Atomize(state,TopAbs_IN);
209 ablockinside = (state == TopAbs_IN);
211 if ( ashapeinside && ablockinside ) {
212 const Handle(TopOpeBRepBuild_Loop)& curL = LoopIter.Value();
213 ADD_Loop_TO_LISTOFLoop
214 (curL,newArea0,(void*)("ashapeinside && ablockinside, new area"));
216 REM_Loop_FROM_LISTOFLoop
217 (LoopIter,boundaryloops,(void*)("loop of boundaryloops, boundaryloops"));
222 } // end of boundaryloops scan
223 } // Loopinside == False
224 } // end of block loop
225 } // end of LoopSet LS scan
228 if (TopOpeBRepBuild_GettraceAREA()) {
229 if ( ! myArea.IsEmpty() ) {
230 cout<<"------- Areas -------"<<endl;
231 for (AreaIter.Initialize(myArea);AreaIter.More();AreaIter.Next())
232 DumpList(AreaIter.Value());
233 cout<<"---------------------"<<endl;
241 //=======================================================================
242 //function : ADD_Loop_TO_LISTOFLoop
244 //=======================================================================
246 void TopOpeBRepBuild_Area1dBuilder::ADD_Loop_TO_LISTOFLoop
247 (const Handle(TopOpeBRepBuild_Loop)& L,
248 TopOpeBRepBuild_ListOfLoop& LOL,
249 const Standard_Address ss) const
258 if (TopOpeBRepBuild_GettraceAREA()) {
259 cout<<"--------------------- add area loop to area : ";
260 L->Dump(); cout<<endl;
261 if (s != NULL) cout<<s<<endl;
263 cout<<"---------------------"<<endl;
268 //=======================================================================
269 //function : REM_Loop_FROM_LISTOFLoop
271 //=======================================================================
273 void TopOpeBRepBuild_Area1dBuilder::REM_Loop_FROM_LISTOFLoop
274 (TopOpeBRepBuild_ListIteratorOfListOfLoop& ITA,
275 TopOpeBRepBuild_ListOfLoop& A,
276 const Standard_Address ss) const
283 if (TopOpeBRepBuild_GettraceAREA()) {
285 cout<<"--------------------- remove area loop from area : ";
286 ITA.Value()->Dump(); cout<<endl;
287 if (s != NULL) cout<<s<<endl;
295 if (TopOpeBRepBuild_GettraceAREA()) {
297 cout<<"---------------------"<<endl;
302 //=======================================================================
303 //function : ADD_LISTOFLoop_TO_LISTOFLoop
305 //=======================================================================
307 void TopOpeBRepBuild_Area1dBuilder::ADD_LISTOFLoop_TO_LISTOFLoop
308 (TopOpeBRepBuild_ListOfLoop& A1,
309 TopOpeBRepBuild_ListOfLoop& A2,
310 const Standard_Address ss,
311 const Standard_Address ss1,
312 const Standard_Address ss2) const
316 char* s1 = (char*)ss1;
317 char* s2 = (char*)ss2;
319 if (TopOpeBRepBuild_GettraceAREA()) {
320 cout<<"--------------------- add area 1 to area 2 : ";
321 if (s != NULL) cout<<s; cout<<endl;
322 cout<<"1 : "; if (s1 != NULL) cout<<s1; cout<<endl;
330 if (TopOpeBRepBuild_GettraceAREA()) {
331 cout<<"2 : "; if (s2 != NULL) cout<<s2; cout<<endl;
333 cout<<"---------------------"<<endl;