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
23 // Author: Peter KURNEV
25 #include <GEOMAlgo_WESCorrector.ixx>
27 #include <Geom_Surface.hxx>
29 #include <TopLoc_Location.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Edge.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRepAdaptor_Surface.hxx>
41 #include <TopTools_IndexedMapOfOrientedShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <BOP_ConnexityBlock.hxx>
45 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
47 #include <BOPTColStd_ListOfListOfShape.hxx>
48 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
50 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
51 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
54 #include <TopTools_MapOfShape.hxx>
55 #include <TopTools_MapIteratorOfMapOfShape.hxx>
56 #include <TopoDS_Iterator.hxx>
57 #include <GEOMAlgo_WireSplitter.hxx>
58 #include <GEOMAlgo_WESScaler.hxx>
61 void MakeWire(const TopTools_ListOfShape& aLE,
62 TopoDS_Wire& newWire);
66 Standard_Boolean IsToScale(const TopoDS_Face& aF,
67 Standard_Real& aScale);
69 //=======================================================================
72 //=======================================================================
73 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
78 //=======================================================================
81 //=======================================================================
82 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
85 //=======================================================================
88 //=======================================================================
89 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
91 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
94 //=======================================================================
97 //=======================================================================
98 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
102 //=======================================================================
105 //=======================================================================
106 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
110 //=======================================================================
113 //=======================================================================
114 void GEOMAlgo_WESCorrector::Perform()
121 //=======================================================================
122 // function: DoConnexityBlocks
124 //=======================================================================
125 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
127 Standard_Boolean bRegular, bClosed;
128 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
129 TopTools_ListIteratorOfListOfShape aIt;
130 TopoDS_Iterator aItE;
132 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
133 TopTools_IndexedMapOfShape aMVS, aMVAdd;
134 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
137 const TopTools_ListOfShape& aLSE=myWES->StartElements();
138 aIt.Initialize(aLSE);
139 for (; aIt.More(); aIt.Next()) {
140 const TopoDS_Shape& aE=aIt.Value();
141 if (!aMEP.Contains(aE)) {
143 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
152 for (i=1; i<=aNbV; ++i) {
153 const TopoDS_Shape& aV=aMVE.FindKey(i);
160 if (aMVS.Contains(aV)) {
163 aMVS.Add(aV); // aMVS - globally processed vertices
165 //------------------------------------- goal: aMEC
166 aMEC.Clear(); // aMEC - edges of CB
167 aMVP.Clear(); // aMVP - vertices to process right now
168 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
174 for (j=1; j<=aNbVP; ++j) {
175 const TopoDS_Shape& aVP=aMVP(j);
176 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
178 for (; aIt.More(); aIt.Next()) {
179 const TopoDS_Shape& aE=aIt.Value();
180 if (aMEC.Contains(aE)) {
186 for (; aItE.More(); aItE.Next()) {
187 const TopoDS_Shape& aVE=aItE.Value();
188 if (!aMVS.Contains(aVE)) {
194 }//for (j=1; j<=aNbVP; ++j)
196 aNbVP=aMVAdd.Extent();
198 break; // from while(1)
202 for (j=1; j<=aNbVP; ++j) {
203 const TopoDS_Shape& aVE=aMVAdd(j);
208 //-------------------------------------
209 BOP_ConnexityBlock aCB;
210 TopTools_ListOfShape aLEC;
211 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
213 bRegular=Standard_True;
216 for (j=1; j<=aNbC; ++j) {
219 if (aMER.Contains(aER)) {
220 aER.Orientation(TopAbs_FORWARD);
222 aER.Orientation(TopAbs_REVERSED);
225 bRegular=Standard_False;
232 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aER);
233 if (!BRep_Tool::Degenerated(aEx)) {
234 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
237 }//for (j=1; j<=aNbC; ++j) {
240 Standard_Integer k, aNbVR, aNbER;
242 aNbVR=aMVER.Extent();
243 for (k=1; k<=aNbVR; ++k) {
244 const TopTools_ListOfShape& aLER=aMVER(k);
247 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
248 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
262 aCB.SetRegularity(bRegular);
263 myConnexityBlocks.Append(aCB);
265 }//for (i=1; i<=aNbV; ++i) {
268 //=======================================================================
269 // function: DoCorrections
271 //=======================================================================
272 void GEOMAlgo_WESCorrector::DoCorrections()
274 Standard_Boolean bIsRegular, bIsNothingToDo, bToScale;
275 Standard_Integer iErr;
276 Standard_Real aScale;
278 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
279 GEOMAlgo_WESScaler aWSC;
281 const TopoDS_Face& aF=myWES->Face();
283 bToScale=IsToScale(aF, aScale);
285 myNewWES.SetFace(aF);
286 aCBIt.Initialize(myConnexityBlocks);
287 for (; aCBIt.More(); aCBIt.Next()) {
288 const BOP_ConnexityBlock& aCB=aCBIt.Value();
289 const TopTools_ListOfShape& aLE=aCB.Shapes();
291 bIsRegular=aCB.IsRegular();
294 myNewWES.AddShape (aW);
298 GEOMAlgo_WireSplitter aWS;
302 TopTools_ListIteratorOfListOfShape aIt;
303 BOPTColStd_ListIteratorOfListOfListOfShape aItLLSS;
305 aWSC.SetScale(aScale);
310 iErr=aWSC.ErrorStatus();
315 const TopoDS_Face& aFS=aWSC.FaceScaled();
316 const TopTools_ListOfShape& aLES=aWSC.EdgesScaled();
322 iErr=aWS.ErrorStatus();
327 bIsNothingToDo=aWS.IsNothingToDo();
328 if (bIsNothingToDo) {
330 myNewWES.AddShape (aW);
334 const BOPTColStd_ListOfListOfShape& aLLSS=aWS.Shapes();
335 aItLLSS.Initialize(aLLSS);
336 for (; aItLLSS.More(); aItLLSS.Next()) {
337 TopTools_ListOfShape aLS;
339 const TopTools_ListOfShape& aLSS=aItLLSS.Value();
340 aIt.Initialize(aLSS);
341 for (; aIt.More(); aIt.Next()) {
342 const TopoDS_Shape& aES=aIt.Value();
348 myNewWES.AddShape (aW);
357 iErr=aWS.ErrorStatus();
361 bIsNothingToDo=aWS.IsNothingToDo();
362 if (bIsNothingToDo) {
364 myNewWES.AddShape (aW);
368 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
370 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
371 for (; aWireIt.More(); aWireIt.Next()) {
372 const TopTools_ListOfShape& aLEx=aWireIt.Value();
375 myNewWES.AddShape (aW);
381 //=======================================================================
382 // function: MakeWire
384 //=======================================================================
385 void MakeWire(const TopTools_ListOfShape& aLE,
386 TopoDS_Wire& newWire)
389 aBB.MakeWire(newWire);
391 TopTools_ListIteratorOfListOfShape anIt(aLE);
392 for (; anIt.More(); anIt.Next()){
393 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
394 aBB.Add(newWire, aE);
398 //=======================================================================
399 //function : IsToScale
401 //=======================================================================
402 Standard_Boolean IsToScale(const TopoDS_Face& aF,
403 Standard_Real& aScale)
405 Standard_Boolean bRet;
406 GeomAbs_SurfaceType aType;
407 BRepAdaptor_Surface aBAS;
413 aType=aBAS.GetType();
414 if (aType==GeomAbs_Cylinder) {
415 Standard_Real aV1, aV2, dV, dU, aTr, aC;
418 aV1=aBAS.FirstVParameter();
419 aV2=aBAS.LastVParameter();
427 //modified by NIZNHY-PKV Fri Mar 30 10:54:34 2012f
436 //modified by NIZNHY-PKV Fri Mar 30 10:54:35 2012t