1 // Copyright (C) 2007-2008 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
22 // File: NMTAlgo_WESCorrector.cxx
24 // Author: Peter KURNEV
27 #include <GEOMAlgo_WESCorrector.ixx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS_Edge.hxx>
35 #include <BRep_Builder.hxx>
36 #include <BRep_Tool.hxx>
38 #include <TopTools_IndexedMapOfOrientedShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
41 #include <BOP_ConnexityBlock.hxx>
42 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
44 #include <BOPTColStd_ListOfListOfShape.hxx>
45 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
47 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
48 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_MapOfShape.hxx>
52 #include <TopTools_MapIteratorOfMapOfShape.hxx>
53 #include <TopoDS_Iterator.hxx>
54 #include <GEOMAlgo_WireSplitter.hxx>
58 void MakeWire(const TopTools_ListOfShape& aLE,
59 TopoDS_Wire& newWire);
61 //=======================================================================
64 //=======================================================================
65 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
70 //=======================================================================
73 //=======================================================================
74 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
77 //=======================================================================
80 //=======================================================================
81 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
83 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
86 //=======================================================================
89 //=======================================================================
90 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
94 //=======================================================================
97 //=======================================================================
98 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
102 //=======================================================================
105 //=======================================================================
106 void GEOMAlgo_WESCorrector::Perform()
113 //=======================================================================
114 // function: DoConnexityBlocks
116 //=======================================================================
117 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
119 Standard_Boolean bRegular, bClosed;
120 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
121 TopTools_ListIteratorOfListOfShape aIt;
122 TopoDS_Iterator aItE;
124 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
125 TopTools_IndexedMapOfShape aMVS, aMVAdd;
126 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
129 const TopTools_ListOfShape& aLSE=myWES->StartElements();
130 aIt.Initialize(aLSE);
131 for (; aIt.More(); aIt.Next()) {
132 const TopoDS_Shape& aE=aIt.Value();
133 if (!aMEP.Contains(aE)) {
135 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
144 for (i=1; i<=aNbV; ++i) {
145 const TopoDS_Shape& aV=aMVE.FindKey(i);
152 if (aMVS.Contains(aV)) {
155 aMVS.Add(aV); // aMVS - globally processed vertices
157 //------------------------------------- goal: aMEC
158 aMEC.Clear(); // aMEC - edges of CB
159 aMVP.Clear(); // aMVP - vertices to process right now
160 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
166 for (j=1; j<=aNbVP; ++j) {
167 const TopoDS_Shape& aVP=aMVP(j);
168 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
170 for (; aIt.More(); aIt.Next()) {
171 const TopoDS_Shape& aE=aIt.Value();
172 if (aMEC.Contains(aE)) {
178 for (; aItE.More(); aItE.Next()) {
179 const TopoDS_Shape& aVE=aItE.Value();
180 if (!aMVS.Contains(aVE)) {
186 }//for (j=1; j<=aNbVP; ++j)
188 aNbVP=aMVAdd.Extent();
190 break; // from while(1)
194 for (j=1; j<=aNbVP; ++j) {
195 const TopoDS_Shape& aVE=aMVAdd(j);
200 //-------------------------------------
201 BOP_ConnexityBlock aCB;
202 TopTools_ListOfShape aLEC;
203 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
205 bRegular=Standard_True;
208 for (j=1; j<=aNbC; ++j) {
211 if (aMER.Contains(aER)) {
212 aER.Orientation(TopAbs_FORWARD);
214 aER.Orientation(TopAbs_REVERSED);
217 //modified by NIZNHY-PKV Tue Nov 28 12:02:29 2006f
218 //bClosed=BRep_Tool::IsClosed(TopoDS::Edge(aER), myWES->Face());
220 bRegular=Standard_False;
222 //modified by NIZNHY-PKV Tue Nov 28 12:02:33 2006t
229 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
231 }//for (j=1; j<=aNbC; ++j) {
234 Standard_Integer k, aNbVR, aNbER;
236 aNbVR=aMVER.Extent();
237 for (k=1; k<=aNbVR; ++k) {
238 const TopTools_ListOfShape& aLER=aMVER(k);
241 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
242 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
256 aCB.SetRegularity(bRegular);
257 myConnexityBlocks.Append(aCB);
259 }//for (i=1; i<=aNbV; ++i) {
262 //=======================================================================
263 // function: DoCorrections
265 //=======================================================================
266 void GEOMAlgo_WESCorrector::DoCorrections()
268 Standard_Boolean bIsRegular, bIsNothingToDo;
269 Standard_Integer iErr;
271 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
273 const TopoDS_Face& aF=myWES->Face();
275 myNewWES.SetFace(aF);
276 aCBIt.Initialize(myConnexityBlocks);
277 for (; aCBIt.More(); aCBIt.Next()) {
278 const BOP_ConnexityBlock& aCB=aCBIt.Value();
279 const TopTools_ListOfShape& aLE=aCB.Shapes();
281 bIsRegular=aCB.IsRegular();
285 myNewWES.AddShape (aW);
289 GEOMAlgo_WireSplitter aWS;
295 iErr=aWS.ErrorStatus();
299 bIsNothingToDo=aWS.IsNothingToDo();
300 if (bIsNothingToDo) {
302 myNewWES.AddShape (aW);
306 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
308 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
309 for (; aWireIt.More(); aWireIt.Next()) {
310 const TopTools_ListOfShape& aLEx=aWireIt.Value();
313 myNewWES.AddShape (aW);
317 //=======================================================================
318 // function: MakeWire
320 //=======================================================================
321 void MakeWire(const TopTools_ListOfShape& aLE,
322 TopoDS_Wire& newWire)
325 aBB.MakeWire(newWire);
327 TopTools_ListIteratorOfListOfShape anIt(aLE);
328 for (; anIt.More(); anIt.Next()){
329 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
330 aBB.Add(newWire, aE);