0022627: Change OCCT memory management defaults
[occt.git] / src / BOP / BOP_WESCorrector.cxx
CommitLineData
7fd59977 1// File: BOP_WESCorrector.cxx
2// Created: Fri Apr 13 10:47:47 2001
3// Author: Peter KURNEV
4// <pkv@irinox>
5
6
7#include <BOP_WESCorrector.ixx>
8
9#include <TopTools_IndexedMapOfOrientedShape.hxx>
10#include <TopTools_ListIteratorOfListOfShape.hxx>
11
12#include <TopoDS.hxx>
13#include <TopoDS_Shape.hxx>
14#include <TopoDS_Wire.hxx>
15#include <TopoDS_Face.hxx>
16#include <TopoDS_Edge.hxx>
17
18#include <BRep_Builder.hxx>
19#include <BRep_Tool.hxx>
20
21#include <BOP_ConnexityBlock.hxx>
22#include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
23#include <BOP_WireSplitter.hxx>
24#include <BOPTColStd_ListOfListOfShape.hxx>
25#include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
26
27static
28 void MakeWire(const TopTools_ListOfShape& aLE,
29 TopoDS_Wire& newWire);
30
31//=======================================================================
32// function: BOP_WESCorrector::BOP_WESCorrector
33// purpose:
34//=======================================================================
35 BOP_WESCorrector::BOP_WESCorrector()
36:
37 myIsDone(Standard_False),
38 myErrorStatus(1)
39{}
40//=======================================================================
41// function: SetWES
42// purpose:
43//=======================================================================
44 void BOP_WESCorrector::SetWES (const BOP_WireEdgeSet& aWES)
45{
46 BOP_WireEdgeSet* pWES=(BOP_WireEdgeSet*) &aWES;
47 myWES=pWES;
48}
49//=======================================================================
50// function: WES
51// purpose:
52//=======================================================================
53 BOP_WireEdgeSet& BOP_WESCorrector::WES ()
54{
55 return *myWES;
56}
57//=======================================================================
58// function: NewWES
59// purpose:
60//=======================================================================
61 BOP_WireEdgeSet& BOP_WESCorrector::NewWES ()
62{
63 return myNewWES;
64}
65//=======================================================================
66// function: IsDone
67// purpose:
68//=======================================================================
69 Standard_Boolean BOP_WESCorrector::IsDone () const
70{
71 return myIsDone;
72}
73//=======================================================================
74// function: ErrorStatus
75// purpose:
76//=======================================================================
77 Standard_Integer BOP_WESCorrector::ErrorStatus () const
78{
79 return myErrorStatus;
80}
81
82//=======================================================================
83// function: Do
84// purpose:
85//=======================================================================
86 void BOP_WESCorrector::Do()
87{
88 DoConnexityBlocks();
89
90 DoCorrections();
91
92 myIsDone=Standard_True;
93}
94//=======================================================================
95// function: DoConnexityBlocks
96// purpose:
97//=======================================================================
98 void BOP_WESCorrector::DoConnexityBlocks()
99{
100 Standard_Boolean EnewinM, aGoOn;
101 Standard_Integer Mextent, IsRegular, aNbNeighbours, Eindex;
102 TopTools_IndexedMapOfOrientedShape myOrientedShapeMap, aMap;
103 //
104 myWES->InitStartElements();
105 for (; myWES->MoreStartElements(); myWES->NextStartElement()) {
106 const TopoDS_Shape& anE = myWES->StartElement();
107 Mextent = myOrientedShapeMap.Extent();
108
109 Eindex = myOrientedShapeMap.Add(anE);
110
111 EnewinM = (Eindex > Mextent);
112 if (EnewinM) {
113 //
114 // make a new block starting at element Eindex
115 IsRegular=Standard_True;
116 aNbNeighbours=0;
117 Mextent = myOrientedShapeMap.Extent();
118 //
119 aMap.Clear();
120 aMap.Add(anE);
121 //
122 aGoOn = (Eindex <= Mextent);
123 while (aGoOn) {
124 const TopoDS_Shape& anEE = myOrientedShapeMap(Eindex);
125 aNbNeighbours = myWES->MaxNumberSubShape(anEE);
126
127 IsRegular = IsRegular && (aNbNeighbours == 2);
128 //
129 myWES->InitNeighbours(anEE);
130 for (; myWES->MoreNeighbours(); myWES->NextNeighbour()) {
131 const TopoDS_Shape& aNeignbE = myWES->Neighbour();
132 myOrientedShapeMap.Add(aNeignbE);
133 //
134 aMap.Add(aNeignbE);
135 }
136
137 Eindex++;
138 Mextent = myOrientedShapeMap.Extent();
139 aGoOn = (Eindex <= Mextent);
140 } // end of while aGoOn
141
142 //
143 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
144 {
145 Standard_Integer aNbE;
146
147 aNbE=aMap.Extent();
148 if (aNbE==2) {
149 const TopoDS_Edge& aEB1=TopoDS::Edge(aMap(1));
150 const TopoDS_Edge& aEB2=TopoDS::Edge(aMap(2));
151 if (aEB1.IsSame(aEB2)) {
152 if (!BRep_Tool::IsClosed(aEB1, myWES->Face())) {
153 IsRegular=Standard_False;
154 }
155 }
156 }
157 }
158 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
159 //
160 BOP_ConnexityBlock aConnexityBlock;
161 aConnexityBlock.SetShapes(aMap);
162 aConnexityBlock.SetRegularity(IsRegular);
163 myConnexityBlocks.Append(aConnexityBlock);
164 } // end of if (EnewinM)
165 } // end of for (; myWES->MoreStartElements();...
166}
167
168//=======================================================================
169// function: DoCorrections
170// purpose:
171//=======================================================================
172 void BOP_WESCorrector::DoCorrections()
173{
174 Standard_Boolean anIsRegular, anIsNothingToDo, anIsDone;
175
176 TopoDS_Wire aW;
177 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
178
179 myNewWES.Initialize(myWES->Face());
180
181 aCBIt.Initialize(myConnexityBlocks);
182 for (; aCBIt.More(); aCBIt.Next()) {
183 const BOP_ConnexityBlock& aCB=aCBIt.Value();
184 const TopTools_ListOfShape& aListOfEdges=aCB.Shapes();
185
186 anIsRegular=aCB.IsRegular();
187
188 if (anIsRegular) {
189 MakeWire(aListOfEdges, aW);
190 myNewWES.AddShape (aW);
191 continue;
192 }
193 //
194 // Treatment of non regular Connexity Block
195 const TopoDS_Face& aF=myWES->Face();
196 BOP_WireSplitter aWireSplitter;
197 aWireSplitter.SetFace(aF);
198 aWireSplitter.DoWithListOfEdges(aListOfEdges);
199
200 anIsDone=aWireSplitter.IsDone();
201 anIsNothingToDo=aWireSplitter.IsNothingToDo();
202
203 if (!anIsDone || anIsNothingToDo) {
204 MakeWire(aListOfEdges, aW);
205 myNewWES.AddShape (aW);
206 continue;
207 }
208 //
209 const BOPTColStd_ListOfListOfShape& aSSS=aWireSplitter.Shapes();
210
211 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
212 for (; aWireIt.More(); aWireIt.Next()) {
213 const TopTools_ListOfShape& aListEd=aWireIt.Value();
214 //
215 MakeWire(aListEd, aW);
216 myNewWES.AddShape (aW);
217 }
218 }
219}
220
221//=======================================================================
222// function: MakeWire
223// purpose:
224//=======================================================================
225 void MakeWire(const TopTools_ListOfShape& aLE,
226 TopoDS_Wire& newWire)
227{
228 BRep_Builder aBB;
229 aBB.MakeWire(newWire);
230
231 TopTools_ListIteratorOfListOfShape anIt(aLE);
232 for (; anIt.More(); anIt.Next()){
233 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
234 aBB.Add(newWire, aE);
235 }
236}
237/////////////////////////////////////////////////////////////////
238//
239// myErrorStatus:
240//
241// 1 - Nothing is done because only constructor has been invoked
242//
243/////////////////////////////////////////////////////////////////