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
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.
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.
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.
21 //modified by NIZNHY-PKV Tue Apr 3 15:50:23 2001
23 #include <BOP_Area2dBuilder.ixx>
25 #include <BOP_Loop.hxx>
26 #include <BOP_ListIteratorOfListOfLoop.hxx>
28 //=======================================================================
29 //function : BOP_Area2dBuilder::BOP_Area2dBuilder
31 //=======================================================================
32 BOP_Area2dBuilder::BOP_Area2dBuilder()
36 //=======================================================================
37 //function : BOP_Area2dBuilder::BOP_Area2dBuilder
39 //=======================================================================
40 BOP_Area2dBuilder::BOP_Area2dBuilder(BOP_LoopSet& LS,
41 BOP_LoopClassifier& LC,
42 const Standard_Boolean ForceClass)
44 InitAreaBuilder(LS,LC,ForceClass);
47 //=======================================================================
48 //function : InitAreaBuilder
50 //=======================================================================
51 void BOP_Area2dBuilder::InitAreaBuilder(BOP_LoopSet& LS,
52 BOP_LoopClassifier& LC,
53 const Standard_Boolean ForceClass)
56 Standard_Boolean Loopinside;
57 Standard_Boolean loopoutside;
59 BOP_ListIteratorOfListOfListOfLoop AreaIter;
60 BOP_ListIteratorOfListOfLoop LoopIter;
61 // boundaryloops : list of boundary loops out of the areas.
62 BOP_ListOfLoop boundaryloops;
64 myArea.Clear(); // Clear the list of Area to be built
66 for (LS.InitLoop(); LS.MoreLoop(); LS.NextLoop()) {
68 // process a new loop : L is the new current Loop
69 const Handle(BOP_Loop)& L = LS.Loop();
70 Standard_Boolean boundaryL = L->IsShape();
72 //const TopoDS_Shape& aSL=L->Shape();
74 // L = shape et ForceClass : on traite L comme un block
75 // L = shape et !ForceClass : on traite L comme un pur shape
76 // L = !shape : on traite L comme un block
77 Standard_Boolean traitercommeblock = (!boundaryL) || ForceClass;
78 if ( !traitercommeblock ) {
79 // the loop L is a boundary loop :
80 // - try to insert it in an existing area, such as L is inside all
81 // the block loops. Only block loops of the area are compared.
82 // - if L could not be inserted, store it in list of boundary loops.
83 Loopinside = Standard_False;
84 AreaIter.Initialize(myArea);
85 for (; AreaIter.More(); AreaIter.Next()) {
86 BOP_ListOfLoop& aArea = AreaIter.Value();
87 if ( aArea.IsEmpty() ) {
90 state = CompareLoopWithListOfLoop(LC,L,aArea,BOP_BLOCK );
91 if (state == TopAbs_UNKNOWN){
92 Atomize(state,TopAbs_IN);
94 Loopinside = ( state == TopAbs_IN);
101 BOP_ListOfLoop& aArea = AreaIter.Value();
102 ADD_Loop_TO_LISTOFLoop(L, aArea);
104 else if ( ! Loopinside ) {
105 ADD_Loop_TO_LISTOFLoop(L, boundaryloops);
107 } // end of boundary loop
110 // the loop L is a block loop
111 // if L is IN theArea :
112 // - stop area scan, insert L in theArea.
113 // - remove from the area all the loops outside L
114 // - make a new area with them, unless they are all boundary
115 // - if they are all boundary put them back in boundaryLoops
117 // - create a new area with L.
118 // - insert boundary loops that are IN the new area
119 // (and remove them from 'boundaryloops')
121 Standard_Integer aNbAreas, aNbLoops;
122 Loopinside = Standard_False;
124 aNbAreas=myArea.Extent();
126 AreaIter.Initialize(myArea);
127 for (; AreaIter.More(); AreaIter.Next()) {
128 BOP_ListOfLoop& aArea = AreaIter.Value();
129 aNbLoops=aArea.Extent();
134 state = CompareLoopWithListOfLoop(LC, L, aArea, BOP_ANYLOOP);
136 if (state == TopAbs_UNKNOWN){
137 Atomize(state,TopAbs_IN);
140 Loopinside = (state==TopAbs_IN);
144 } // end of Area scan
148 BOP_ListOfLoop& aArea = AreaIter.Value();
149 Standard_Boolean allShape = Standard_True;
150 BOP_ListOfLoop removedLoops;
151 LoopIter.Initialize(aArea);
152 while (LoopIter.More()) {
153 const Handle(BOP_Loop)& curL = LoopIter.Value();
154 state = LC.Compare(curL, L);
155 if (state == TopAbs_UNKNOWN) {
156 Atomize(state,TopAbs_IN); // not OUT
159 loopoutside = ( state == TopAbs_OUT );
162 // remove the loop from the area
163 ADD_Loop_TO_LISTOFLoop(curL, removedLoops);
165 allShape = allShape && curL->IsShape();
166 REM_Loop_FROM_LISTOFLoop(LoopIter, aArea);
171 }// while (LoopIter.More()) {
173 // insert the loop in the area
174 ADD_Loop_TO_LISTOFLoop(L, aArea);
175 if ( ! removedLoops.IsEmpty() ) {
177 ADD_LISTOFLoop_TO_LISTOFLoop (removedLoops,boundaryloops);
180 // make a new area with the removed loops
181 BOP_ListOfLoop thelistofloop;
182 myArea.Append(thelistofloop);
183 ADD_LISTOFLoop_TO_LISTOFLoop(removedLoops, myArea.Last());
186 } // Loopinside == True
189 Standard_Integer ashapeinside,ablockinside;
190 BOP_ListOfLoop thelistofloop1;
191 myArea.Append(thelistofloop1);
192 BOP_ListOfLoop& newArea0 = myArea.Last();
193 ADD_Loop_TO_LISTOFLoop(L, newArea0);
195 LoopIter.Initialize(boundaryloops);
196 while ( LoopIter.More() ) {
197 ashapeinside = ablockinside = Standard_False;
198 const Handle(BOP_Loop)& lb = LoopIter.Value();
199 state = LC.Compare(lb,L);
200 if (state == TopAbs_UNKNOWN){
201 Atomize(state,TopAbs_IN);
203 ashapeinside = (state == TopAbs_IN);
205 state = LC.Compare(L,lb);
206 if (state == TopAbs_UNKNOWN){
207 Atomize(state,TopAbs_IN);
209 ablockinside = (state == TopAbs_IN);
211 if ( ashapeinside && ablockinside ) {
212 const Handle(BOP_Loop)& curL = LoopIter.Value();
213 ADD_Loop_TO_LISTOFLoop(curL, newArea0);
215 REM_Loop_FROM_LISTOFLoop(LoopIter,boundaryloops);
220 } // end of boundaryloops scan
221 } // Loopinside == False
222 } // end of block loop
223 } // end of LoopSet LS scan
225 if ( ! boundaryloops.IsEmpty() ) {
226 if ( myArea.IsEmpty() ) {
227 BOP_ListOfLoop newArea3;
228 newArea3.Append(boundaryloops);
229 myArea.Append(newArea3);