1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: NMTAlgo_WESCorrector.cxx
22 // Author: Peter KURNEV
26 #include <GEOMAlgo_WESCorrector.ixx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Wire.hxx>
31 #include <TopoDS_Face.hxx>
32 #include <TopoDS_Edge.hxx>
34 #include <BRep_Builder.hxx>
35 #include <BRep_Tool.hxx>
37 #include <TopTools_IndexedMapOfOrientedShape.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <BOP_ConnexityBlock.hxx>
41 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
43 #include <BOPTColStd_ListOfListOfShape.hxx>
44 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
46 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
47 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <TopTools_MapOfShape.hxx>
51 #include <TopTools_MapIteratorOfMapOfShape.hxx>
52 #include <TopoDS_Iterator.hxx>
53 #include <GEOMAlgo_WireSplitter.hxx>
57 void MakeWire(const TopTools_ListOfShape& aLE,
58 TopoDS_Wire& newWire);
60 //=======================================================================
63 //=======================================================================
64 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
69 //=======================================================================
72 //=======================================================================
73 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
76 //=======================================================================
79 //=======================================================================
80 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
82 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
85 //=======================================================================
88 //=======================================================================
89 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
93 //=======================================================================
96 //=======================================================================
97 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
101 //=======================================================================
104 //=======================================================================
105 void GEOMAlgo_WESCorrector::Perform()
112 //=======================================================================
113 // function: DoConnexityBlocks
115 //=======================================================================
116 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
118 Standard_Boolean bRegular, bClosed;
119 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
120 TopTools_ListIteratorOfListOfShape aIt;
121 TopoDS_Iterator aItE;
123 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
124 TopTools_IndexedMapOfShape aMVS, aMVAdd;
125 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
128 const TopTools_ListOfShape& aLSE=myWES->StartElements();
129 aIt.Initialize(aLSE);
130 for (; aIt.More(); aIt.Next()) {
131 const TopoDS_Shape& aE=aIt.Value();
132 if (!aMEP.Contains(aE)) {
134 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
143 for (i=1; i<=aNbV; ++i) {
144 const TopoDS_Shape& aV=aMVE.FindKey(i);
151 if (aMVS.Contains(aV)) {
154 aMVS.Add(aV); // aMVS - globally processed vertices
156 //------------------------------------- goal: aMEC
157 aMEC.Clear(); // aMEC - edges of CB
158 aMVP.Clear(); // aMVP - vertices to process right now
159 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
165 for (j=1; j<=aNbVP; ++j) {
166 const TopoDS_Shape& aVP=aMVP(j);
167 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
169 for (; aIt.More(); aIt.Next()) {
170 const TopoDS_Shape& aE=aIt.Value();
171 if (aMEC.Contains(aE)) {
177 for (; aItE.More(); aItE.Next()) {
178 const TopoDS_Shape& aVE=aItE.Value();
179 if (!aMVS.Contains(aVE)) {
185 }//for (j=1; j<=aNbVP; ++j)
187 aNbVP=aMVAdd.Extent();
189 break; // from while(1)
193 for (j=1; j<=aNbVP; ++j) {
194 const TopoDS_Shape& aVE=aMVAdd(j);
199 //-------------------------------------
200 BOP_ConnexityBlock aCB;
201 TopTools_ListOfShape aLEC;
202 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
204 bRegular=Standard_True;
207 for (j=1; j<=aNbC; ++j) {
210 if (aMER.Contains(aER)) {
211 aER.Orientation(TopAbs_FORWARD);
213 aER.Orientation(TopAbs_REVERSED);
216 //modified by NIZNHY-PKV Tue Nov 28 12:02:29 2006f
217 //bClosed=BRep_Tool::IsClosed(TopoDS::Edge(aER), myWES->Face());
219 bRegular=Standard_False;
221 //modified by NIZNHY-PKV Tue Nov 28 12:02:33 2006t
228 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
230 }//for (j=1; j<=aNbC; ++j) {
233 Standard_Integer k, aNbVR, aNbER;
235 aNbVR=aMVER.Extent();
236 for (k=1; k<=aNbVR; ++k) {
237 const TopTools_ListOfShape& aLER=aMVER(k);
240 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
241 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
255 aCB.SetRegularity(bRegular);
256 myConnexityBlocks.Append(aCB);
258 }//for (i=1; i<=aNbV; ++i) {
261 //=======================================================================
262 // function: DoCorrections
264 //=======================================================================
265 void GEOMAlgo_WESCorrector::DoCorrections()
267 Standard_Boolean bIsRegular, bIsNothingToDo;
268 Standard_Integer iErr;
270 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
272 const TopoDS_Face& aF=myWES->Face();
274 myNewWES.SetFace(aF);
275 aCBIt.Initialize(myConnexityBlocks);
276 for (; aCBIt.More(); aCBIt.Next()) {
277 const BOP_ConnexityBlock& aCB=aCBIt.Value();
278 const TopTools_ListOfShape& aLE=aCB.Shapes();
280 bIsRegular=aCB.IsRegular();
284 myNewWES.AddShape (aW);
288 GEOMAlgo_WireSplitter aWS;
294 iErr=aWS.ErrorStatus();
298 bIsNothingToDo=aWS.IsNothingToDo();
299 if (bIsNothingToDo) {
301 myNewWES.AddShape (aW);
305 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
307 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
308 for (; aWireIt.More(); aWireIt.Next()) {
309 const TopTools_ListOfShape& aLEx=aWireIt.Value();
312 myNewWES.AddShape (aW);
316 //=======================================================================
317 // function: MakeWire
319 //=======================================================================
320 void MakeWire(const TopTools_ListOfShape& aLE,
321 TopoDS_Wire& newWire)
324 aBB.MakeWire(newWire);
326 TopTools_ListIteratorOfListOfShape anIt(aLE);
327 for (; anIt.More(); anIt.Next()){
328 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
329 aBB.Add(newWire, aE);