1 // Copyright (C) 2007-2011 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.hxx>
29 #include <Geom_Surface.hxx>
31 #include <TopLoc_Location.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Edge.hxx>
39 #include <BRep_Builder.hxx>
40 #include <BRep_Tool.hxx>
41 #include <BRepAdaptor_Surface.hxx>
43 #include <TopTools_IndexedMapOfOrientedShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
46 #include <BOP_ConnexityBlock.hxx>
47 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
49 #include <BOPTColStd_ListOfListOfShape.hxx>
50 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
52 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
53 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
55 #include <TopTools_IndexedMapOfShape.hxx>
56 #include <TopTools_MapOfShape.hxx>
57 #include <TopTools_MapIteratorOfMapOfShape.hxx>
58 #include <TopoDS_Iterator.hxx>
59 #include <GEOMAlgo_WireSplitter.hxx>
60 #include <GEOMAlgo_WESScaler.hxx>
63 void MakeWire(const TopTools_ListOfShape& aLE,
64 TopoDS_Wire& newWire);
68 Standard_Boolean IsToScale(const TopoDS_Face& aF,
69 Standard_Real& aScale);
71 //=======================================================================
74 //=======================================================================
75 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
80 //=======================================================================
83 //=======================================================================
84 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
87 //=======================================================================
90 //=======================================================================
91 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
93 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
96 //=======================================================================
99 //=======================================================================
100 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
104 //=======================================================================
107 //=======================================================================
108 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
112 //=======================================================================
115 //=======================================================================
116 void GEOMAlgo_WESCorrector::Perform()
123 //=======================================================================
124 // function: DoConnexityBlocks
126 //=======================================================================
127 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
129 Standard_Boolean bRegular, bClosed;
130 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
131 TopTools_ListIteratorOfListOfShape aIt;
132 TopoDS_Iterator aItE;
134 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
135 TopTools_IndexedMapOfShape aMVS, aMVAdd;
136 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
139 const TopTools_ListOfShape& aLSE=myWES->StartElements();
140 aIt.Initialize(aLSE);
141 for (; aIt.More(); aIt.Next()) {
142 const TopoDS_Shape& aE=aIt.Value();
143 if (!aMEP.Contains(aE)) {
145 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
154 for (i=1; i<=aNbV; ++i) {
155 const TopoDS_Shape& aV=aMVE.FindKey(i);
162 if (aMVS.Contains(aV)) {
165 aMVS.Add(aV); // aMVS - globally processed vertices
167 //------------------------------------- goal: aMEC
168 aMEC.Clear(); // aMEC - edges of CB
169 aMVP.Clear(); // aMVP - vertices to process right now
170 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
176 for (j=1; j<=aNbVP; ++j) {
177 const TopoDS_Shape& aVP=aMVP(j);
178 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
180 for (; aIt.More(); aIt.Next()) {
181 const TopoDS_Shape& aE=aIt.Value();
182 if (aMEC.Contains(aE)) {
188 for (; aItE.More(); aItE.Next()) {
189 const TopoDS_Shape& aVE=aItE.Value();
190 if (!aMVS.Contains(aVE)) {
196 }//for (j=1; j<=aNbVP; ++j)
198 aNbVP=aMVAdd.Extent();
200 break; // from while(1)
204 for (j=1; j<=aNbVP; ++j) {
205 const TopoDS_Shape& aVE=aMVAdd(j);
210 //-------------------------------------
211 BOP_ConnexityBlock aCB;
212 TopTools_ListOfShape aLEC;
213 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
215 bRegular=Standard_True;
218 for (j=1; j<=aNbC; ++j) {
221 if (aMER.Contains(aER)) {
222 aER.Orientation(TopAbs_FORWARD);
224 aER.Orientation(TopAbs_REVERSED);
227 bRegular=Standard_False;
234 //modified by NIZNHY-PKV Wed Oct 20 14:45:52 2010f
235 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aER);
236 if (!BRep_Tool::Degenerated(aEx)) {
237 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
240 //TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
241 //modified by NIZNHY-PKV Wed Oct 20 14:46:48 2010t
243 }//for (j=1; j<=aNbC; ++j) {
246 Standard_Integer k, aNbVR, aNbER;
248 aNbVR=aMVER.Extent();
249 for (k=1; k<=aNbVR; ++k) {
250 const TopTools_ListOfShape& aLER=aMVER(k);
253 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
254 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
268 aCB.SetRegularity(bRegular);
269 myConnexityBlocks.Append(aCB);
271 }//for (i=1; i<=aNbV; ++i) {
274 //=======================================================================
275 // function: DoCorrections
277 //=======================================================================
278 void GEOMAlgo_WESCorrector::DoCorrections()
280 Standard_Boolean bIsRegular, bIsNothingToDo, bToScale;
281 Standard_Integer iErr;
282 Standard_Real aScale;
284 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
285 GEOMAlgo_WESScaler aWSC;
287 const TopoDS_Face& aF=myWES->Face();
289 bToScale=IsToScale(aF, aScale);
291 myNewWES.SetFace(aF);
292 aCBIt.Initialize(myConnexityBlocks);
293 for (; aCBIt.More(); aCBIt.Next()) {
294 const BOP_ConnexityBlock& aCB=aCBIt.Value();
295 const TopTools_ListOfShape& aLE=aCB.Shapes();
297 bIsRegular=aCB.IsRegular();
300 myNewWES.AddShape (aW);
304 GEOMAlgo_WireSplitter aWS;
308 TopTools_ListIteratorOfListOfShape aIt;
309 BOPTColStd_ListIteratorOfListOfListOfShape aItLLSS;
311 aWSC.SetScale(aScale);
316 iErr=aWSC.ErrorStatus();
321 const TopoDS_Face& aFS=aWSC.FaceScaled();
322 const TopTools_ListOfShape& aLES=aWSC.EdgesScaled();
328 iErr=aWS.ErrorStatus();
333 bIsNothingToDo=aWS.IsNothingToDo();
334 if (bIsNothingToDo) {
336 myNewWES.AddShape (aW);
340 const BOPTColStd_ListOfListOfShape& aLLSS=aWS.Shapes();
341 aItLLSS.Initialize(aLLSS);
342 for (; aItLLSS.More(); aItLLSS.Next()) {
343 TopTools_ListOfShape aLS;
345 const TopTools_ListOfShape& aLSS=aItLLSS.Value();
346 aIt.Initialize(aLSS);
347 for (; aIt.More(); aIt.Next()) {
348 const TopoDS_Shape& aES=aIt.Value();
354 myNewWES.AddShape (aW);
363 iErr=aWS.ErrorStatus();
367 bIsNothingToDo=aWS.IsNothingToDo();
368 if (bIsNothingToDo) {
370 myNewWES.AddShape (aW);
374 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
376 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
377 for (; aWireIt.More(); aWireIt.Next()) {
378 const TopTools_ListOfShape& aLEx=aWireIt.Value();
381 myNewWES.AddShape (aW);
386 //=======================================================================
387 // function: MakeWire
389 //=======================================================================
390 void MakeWire(const TopTools_ListOfShape& aLE,
391 TopoDS_Wire& newWire)
394 aBB.MakeWire(newWire);
396 TopTools_ListIteratorOfListOfShape anIt(aLE);
397 for (; anIt.More(); anIt.Next()){
398 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
399 aBB.Add(newWire, aE);
405 //=======================================================================
406 //function : IsToScale
408 //=======================================================================
409 Standard_Boolean IsToScale(const TopoDS_Face& aF,
410 Standard_Real& aScale)
412 Standard_Boolean bRet;
413 Standard_Real aV1, aV2, dV, aTr;
414 GeomAbs_SurfaceType aType;
415 BRepAdaptor_Surface aBAS;
421 aType=aBAS.GetType();
422 if (aType==GeomAbs_Cylinder) {
424 aV1=aBAS.FirstVParameter();
425 aV2=aBAS.LastVParameter();