1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: NMTAlgo_WESCorrector.cxx
25 // Author: Peter KURNEV
28 #include <GEOMAlgo_WESCorrector.ixx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Wire.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Edge.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRep_Tool.hxx>
39 #include <TopTools_IndexedMapOfOrientedShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 #include <BOP_ConnexityBlock.hxx>
43 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
45 #include <BOPTColStd_ListOfListOfShape.hxx>
46 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
48 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
49 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
51 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <TopTools_MapOfShape.hxx>
53 #include <TopTools_MapIteratorOfMapOfShape.hxx>
54 #include <TopoDS_Iterator.hxx>
55 #include <GEOMAlgo_WireSplitter.hxx>
59 void MakeWire(const TopTools_ListOfShape& aLE,
60 TopoDS_Wire& newWire);
62 //=======================================================================
65 //=======================================================================
66 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
71 //=======================================================================
74 //=======================================================================
75 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
78 //=======================================================================
81 //=======================================================================
82 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
84 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
87 //=======================================================================
90 //=======================================================================
91 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
95 //=======================================================================
98 //=======================================================================
99 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
103 //=======================================================================
106 //=======================================================================
107 void GEOMAlgo_WESCorrector::Perform()
114 //=======================================================================
115 // function: DoConnexityBlocks
117 //=======================================================================
118 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
120 Standard_Boolean bRegular, bClosed;
121 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
122 TopTools_ListIteratorOfListOfShape aIt;
123 TopoDS_Iterator aItE;
125 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
126 TopTools_IndexedMapOfShape aMVS, aMVAdd;
127 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
130 const TopTools_ListOfShape& aLSE=myWES->StartElements();
131 aIt.Initialize(aLSE);
132 for (; aIt.More(); aIt.Next()) {
133 const TopoDS_Shape& aE=aIt.Value();
134 if (!aMEP.Contains(aE)) {
136 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
145 for (i=1; i<=aNbV; ++i) {
146 const TopoDS_Shape& aV=aMVE.FindKey(i);
153 if (aMVS.Contains(aV)) {
156 aMVS.Add(aV); // aMVS - globally processed vertices
158 //------------------------------------- goal: aMEC
159 aMEC.Clear(); // aMEC - edges of CB
160 aMVP.Clear(); // aMVP - vertices to process right now
161 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
167 for (j=1; j<=aNbVP; ++j) {
168 const TopoDS_Shape& aVP=aMVP(j);
169 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
171 for (; aIt.More(); aIt.Next()) {
172 const TopoDS_Shape& aE=aIt.Value();
173 if (aMEC.Contains(aE)) {
179 for (; aItE.More(); aItE.Next()) {
180 const TopoDS_Shape& aVE=aItE.Value();
181 if (!aMVS.Contains(aVE)) {
187 }//for (j=1; j<=aNbVP; ++j)
189 aNbVP=aMVAdd.Extent();
191 break; // from while(1)
195 for (j=1; j<=aNbVP; ++j) {
196 const TopoDS_Shape& aVE=aMVAdd(j);
201 //-------------------------------------
202 BOP_ConnexityBlock aCB;
203 TopTools_ListOfShape aLEC;
204 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
206 bRegular=Standard_True;
209 for (j=1; j<=aNbC; ++j) {
212 if (aMER.Contains(aER)) {
213 aER.Orientation(TopAbs_FORWARD);
215 aER.Orientation(TopAbs_REVERSED);
218 //modified by NIZNHY-PKV Tue Nov 28 12:02:29 2006f
219 //bClosed=BRep_Tool::IsClosed(TopoDS::Edge(aER), myWES->Face());
221 bRegular=Standard_False;
223 //modified by NIZNHY-PKV Tue Nov 28 12:02:33 2006t
230 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
232 }//for (j=1; j<=aNbC; ++j) {
235 Standard_Integer k, aNbVR, aNbER;
237 aNbVR=aMVER.Extent();
238 for (k=1; k<=aNbVR; ++k) {
239 const TopTools_ListOfShape& aLER=aMVER(k);
242 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
243 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
257 aCB.SetRegularity(bRegular);
258 myConnexityBlocks.Append(aCB);
260 }//for (i=1; i<=aNbV; ++i) {
263 //=======================================================================
264 // function: DoCorrections
266 //=======================================================================
267 void GEOMAlgo_WESCorrector::DoCorrections()
269 Standard_Boolean bIsRegular, bIsNothingToDo;
270 Standard_Integer iErr;
272 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
274 const TopoDS_Face& aF=myWES->Face();
276 myNewWES.SetFace(aF);
277 aCBIt.Initialize(myConnexityBlocks);
278 for (; aCBIt.More(); aCBIt.Next()) {
279 const BOP_ConnexityBlock& aCB=aCBIt.Value();
280 const TopTools_ListOfShape& aLE=aCB.Shapes();
282 bIsRegular=aCB.IsRegular();
286 myNewWES.AddShape (aW);
290 GEOMAlgo_WireSplitter aWS;
296 iErr=aWS.ErrorStatus();
300 bIsNothingToDo=aWS.IsNothingToDo();
301 if (bIsNothingToDo) {
303 myNewWES.AddShape (aW);
307 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
309 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
310 for (; aWireIt.More(); aWireIt.Next()) {
311 const TopTools_ListOfShape& aLEx=aWireIt.Value();
314 myNewWES.AddShape (aW);
318 //=======================================================================
319 // function: MakeWire
321 //=======================================================================
322 void MakeWire(const TopTools_ListOfShape& aLE,
323 TopoDS_Wire& newWire)
326 aBB.MakeWire(newWire);
328 TopTools_ListIteratorOfListOfShape anIt(aLE);
329 for (; anIt.More(); anIt.Next()){
330 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
331 aBB.Add(newWire, aE);