1 // Created on: 2001-04-13
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <BOP_WESCorrector.ixx>
24 #include <TopTools_IndexedMapOfOrientedShape.hxx>
25 #include <TopTools_ListIteratorOfListOfShape.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDS_Wire.hxx>
30 #include <TopoDS_Face.hxx>
31 #include <TopoDS_Edge.hxx>
33 #include <BRep_Builder.hxx>
34 #include <BRep_Tool.hxx>
36 #include <BOP_ConnexityBlock.hxx>
37 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
38 #include <BOP_WireSplitter.hxx>
39 #include <BOPTColStd_ListOfListOfShape.hxx>
40 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
43 void MakeWire(const TopTools_ListOfShape& aLE,
44 TopoDS_Wire& newWire);
46 //=======================================================================
47 // function: BOP_WESCorrector::BOP_WESCorrector
49 //=======================================================================
50 BOP_WESCorrector::BOP_WESCorrector()
52 myIsDone(Standard_False),
55 //=======================================================================
58 //=======================================================================
59 void BOP_WESCorrector::SetWES (const BOP_WireEdgeSet& aWES)
61 BOP_WireEdgeSet* pWES=(BOP_WireEdgeSet*) &aWES;
64 //=======================================================================
67 //=======================================================================
68 BOP_WireEdgeSet& BOP_WESCorrector::WES ()
72 //=======================================================================
75 //=======================================================================
76 BOP_WireEdgeSet& BOP_WESCorrector::NewWES ()
80 //=======================================================================
83 //=======================================================================
84 Standard_Boolean BOP_WESCorrector::IsDone () const
88 //=======================================================================
89 // function: ErrorStatus
91 //=======================================================================
92 Standard_Integer BOP_WESCorrector::ErrorStatus () const
97 //=======================================================================
100 //=======================================================================
101 void BOP_WESCorrector::Do()
107 myIsDone=Standard_True;
109 //=======================================================================
110 // function: DoConnexityBlocks
112 //=======================================================================
113 void BOP_WESCorrector::DoConnexityBlocks()
115 Standard_Boolean EnewinM, aGoOn;
116 Standard_Integer Mextent, IsRegular, aNbNeighbours, Eindex;
117 TopTools_IndexedMapOfOrientedShape myOrientedShapeMap, aMap;
119 myWES->InitStartElements();
120 for (; myWES->MoreStartElements(); myWES->NextStartElement()) {
121 const TopoDS_Shape& anE = myWES->StartElement();
122 Mextent = myOrientedShapeMap.Extent();
124 Eindex = myOrientedShapeMap.Add(anE);
126 EnewinM = (Eindex > Mextent);
129 // make a new block starting at element Eindex
130 IsRegular=Standard_True;
132 Mextent = myOrientedShapeMap.Extent();
137 aGoOn = (Eindex <= Mextent);
139 const TopoDS_Shape& anEE = myOrientedShapeMap(Eindex);
140 aNbNeighbours = myWES->MaxNumberSubShape(anEE);
142 IsRegular = IsRegular && (aNbNeighbours == 2);
144 myWES->InitNeighbours(anEE);
145 for (; myWES->MoreNeighbours(); myWES->NextNeighbour()) {
146 const TopoDS_Shape& aNeignbE = myWES->Neighbour();
147 myOrientedShapeMap.Add(aNeignbE);
153 Mextent = myOrientedShapeMap.Extent();
154 aGoOn = (Eindex <= Mextent);
155 } // end of while aGoOn
158 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
160 Standard_Integer aNbE;
164 const TopoDS_Edge& aEB1=TopoDS::Edge(aMap(1));
165 const TopoDS_Edge& aEB2=TopoDS::Edge(aMap(2));
166 if (aEB1.IsSame(aEB2)) {
167 if (!BRep_Tool::IsClosed(aEB1, myWES->Face())) {
168 IsRegular=Standard_False;
173 //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
175 BOP_ConnexityBlock aConnexityBlock;
176 aConnexityBlock.SetShapes(aMap);
177 aConnexityBlock.SetRegularity(IsRegular);
178 myConnexityBlocks.Append(aConnexityBlock);
179 } // end of if (EnewinM)
180 } // end of for (; myWES->MoreStartElements();...
183 //=======================================================================
184 // function: DoCorrections
186 //=======================================================================
187 void BOP_WESCorrector::DoCorrections()
189 Standard_Boolean anIsRegular, anIsNothingToDo, anIsDone;
192 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
194 myNewWES.Initialize(myWES->Face());
196 aCBIt.Initialize(myConnexityBlocks);
197 for (; aCBIt.More(); aCBIt.Next()) {
198 const BOP_ConnexityBlock& aCB=aCBIt.Value();
199 const TopTools_ListOfShape& aListOfEdges=aCB.Shapes();
201 anIsRegular=aCB.IsRegular();
204 MakeWire(aListOfEdges, aW);
205 myNewWES.AddShape (aW);
209 // Treatment of non regular Connexity Block
210 const TopoDS_Face& aF=myWES->Face();
211 BOP_WireSplitter aWireSplitter;
212 aWireSplitter.SetFace(aF);
213 aWireSplitter.DoWithListOfEdges(aListOfEdges);
215 anIsDone=aWireSplitter.IsDone();
216 anIsNothingToDo=aWireSplitter.IsNothingToDo();
218 if (!anIsDone || anIsNothingToDo) {
219 MakeWire(aListOfEdges, aW);
220 myNewWES.AddShape (aW);
224 const BOPTColStd_ListOfListOfShape& aSSS=aWireSplitter.Shapes();
226 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
227 for (; aWireIt.More(); aWireIt.Next()) {
228 const TopTools_ListOfShape& aListEd=aWireIt.Value();
230 MakeWire(aListEd, aW);
231 myNewWES.AddShape (aW);
236 //=======================================================================
237 // function: MakeWire
239 //=======================================================================
240 void MakeWire(const TopTools_ListOfShape& aLE,
241 TopoDS_Wire& newWire)
244 aBB.MakeWire(newWire);
246 TopTools_ListIteratorOfListOfShape anIt(aLE);
247 for (; anIt.More(); anIt.Next()){
248 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
249 aBB.Add(newWire, aE);
252 /////////////////////////////////////////////////////////////////
256 // 1 - Nothing is done because only constructor has been invoked
258 /////////////////////////////////////////////////////////////////