1 // Copyright (C) 2007-2012 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
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_WESCorrector.hxx>
28 #include <Geom_Surface.hxx>
30 #include <TopLoc_Location.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Wire.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Edge.hxx>
38 #include <BRep_Builder.hxx>
39 #include <BRep_Tool.hxx>
40 #include <BRepAdaptor_Surface.hxx>
42 #include <TopTools_IndexedMapOfOrientedShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <BOP_ConnexityBlock.hxx>
46 #include <BOP_ListIteratorOfListOfConnexityBlock.hxx>
48 #include <BOPTColStd_ListOfListOfShape.hxx>
49 #include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
51 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
52 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
54 #include <TopTools_IndexedMapOfShape.hxx>
55 #include <TopTools_MapOfShape.hxx>
56 #include <TopTools_MapIteratorOfMapOfShape.hxx>
57 #include <TopoDS_Iterator.hxx>
58 #include <GEOMAlgo_WireSplitter.hxx>
59 #include <GEOMAlgo_WESScaler.hxx>
62 void MakeWire(const TopTools_ListOfShape& aLE,
63 TopoDS_Wire& newWire);
67 Standard_Boolean IsToScale(const TopoDS_Face& aF,
68 Standard_Real& aScale);
70 //=======================================================================
73 //=======================================================================
74 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
79 //=======================================================================
82 //=======================================================================
83 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
86 //=======================================================================
89 //=======================================================================
90 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
92 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
95 //=======================================================================
98 //=======================================================================
99 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
103 //=======================================================================
106 //=======================================================================
107 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
111 //=======================================================================
114 //=======================================================================
115 void GEOMAlgo_WESCorrector::Perform()
122 //=======================================================================
123 // function: DoConnexityBlocks
125 //=======================================================================
126 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
128 Standard_Boolean bRegular, bClosed;
129 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
130 TopTools_ListIteratorOfListOfShape aIt;
131 TopoDS_Iterator aItE;
133 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
134 TopTools_IndexedMapOfShape aMVS, aMVAdd;
135 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
138 const TopTools_ListOfShape& aLSE=myWES->StartElements();
139 aIt.Initialize(aLSE);
140 for (; aIt.More(); aIt.Next()) {
141 const TopoDS_Shape& aE=aIt.Value();
142 if (!aMEP.Contains(aE)) {
144 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
153 for (i=1; i<=aNbV; ++i) {
154 const TopoDS_Shape& aV=aMVE.FindKey(i);
161 if (aMVS.Contains(aV)) {
164 aMVS.Add(aV); // aMVS - globally processed vertices
166 //------------------------------------- goal: aMEC
167 aMEC.Clear(); // aMEC - edges of CB
168 aMVP.Clear(); // aMVP - vertices to process right now
169 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
175 for (j=1; j<=aNbVP; ++j) {
176 const TopoDS_Shape& aVP=aMVP(j);
177 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
179 for (; aIt.More(); aIt.Next()) {
180 const TopoDS_Shape& aE=aIt.Value();
181 if (aMEC.Contains(aE)) {
187 for (; aItE.More(); aItE.Next()) {
188 const TopoDS_Shape& aVE=aItE.Value();
189 if (!aMVS.Contains(aVE)) {
195 }//for (j=1; j<=aNbVP; ++j)
197 aNbVP=aMVAdd.Extent();
199 break; // from while(1)
203 for (j=1; j<=aNbVP; ++j) {
204 const TopoDS_Shape& aVE=aMVAdd(j);
209 //-------------------------------------
210 BOP_ConnexityBlock aCB;
211 TopTools_ListOfShape aLEC;
212 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
214 bRegular=Standard_True;
217 for (j=1; j<=aNbC; ++j) {
220 if (aMER.Contains(aER)) {
221 aER.Orientation(TopAbs_FORWARD);
223 aER.Orientation(TopAbs_REVERSED);
226 bRegular=Standard_False;
233 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aER);
234 if (!BRep_Tool::Degenerated(aEx)) {
235 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
238 }//for (j=1; j<=aNbC; ++j) {
241 Standard_Integer k, aNbVR, aNbER;
243 aNbVR=aMVER.Extent();
244 for (k=1; k<=aNbVR; ++k) {
245 const TopTools_ListOfShape& aLER=aMVER(k);
248 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
249 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
263 aCB.SetRegularity(bRegular);
264 myConnexityBlocks.Append(aCB);
266 }//for (i=1; i<=aNbV; ++i) {
269 //=======================================================================
270 // function: DoCorrections
272 //=======================================================================
273 void GEOMAlgo_WESCorrector::DoCorrections()
275 Standard_Boolean bIsRegular, bIsNothingToDo, bToScale;
276 Standard_Integer iErr;
277 Standard_Real aScale;
279 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
280 GEOMAlgo_WESScaler aWSC;
282 const TopoDS_Face& aF=myWES->Face();
284 bToScale=IsToScale(aF, aScale);
286 myNewWES.SetFace(aF);
287 aCBIt.Initialize(myConnexityBlocks);
288 for (; aCBIt.More(); aCBIt.Next()) {
289 const BOP_ConnexityBlock& aCB=aCBIt.Value();
290 const TopTools_ListOfShape& aLE=aCB.Shapes();
292 bIsRegular=aCB.IsRegular();
295 myNewWES.AddShape (aW);
299 GEOMAlgo_WireSplitter aWS;
303 TopTools_ListIteratorOfListOfShape aIt;
304 BOPTColStd_ListIteratorOfListOfListOfShape aItLLSS;
306 aWSC.SetScale(aScale);
311 iErr=aWSC.ErrorStatus();
316 const TopoDS_Face& aFS=aWSC.FaceScaled();
317 const TopTools_ListOfShape& aLES=aWSC.EdgesScaled();
323 iErr=aWS.ErrorStatus();
328 bIsNothingToDo=aWS.IsNothingToDo();
329 if (bIsNothingToDo) {
331 myNewWES.AddShape (aW);
335 const BOPTColStd_ListOfListOfShape& aLLSS=aWS.Shapes();
336 aItLLSS.Initialize(aLLSS);
337 for (; aItLLSS.More(); aItLLSS.Next()) {
338 TopTools_ListOfShape aLS;
340 const TopTools_ListOfShape& aLSS=aItLLSS.Value();
341 aIt.Initialize(aLSS);
342 for (; aIt.More(); aIt.Next()) {
343 const TopoDS_Shape& aES=aIt.Value();
349 myNewWES.AddShape (aW);
358 iErr=aWS.ErrorStatus();
362 bIsNothingToDo=aWS.IsNothingToDo();
363 if (bIsNothingToDo) {
365 myNewWES.AddShape (aW);
369 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
371 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
372 for (; aWireIt.More(); aWireIt.Next()) {
373 const TopTools_ListOfShape& aLEx=aWireIt.Value();
376 myNewWES.AddShape (aW);
382 //=======================================================================
383 // function: MakeWire
385 //=======================================================================
386 void MakeWire(const TopTools_ListOfShape& aLE,
387 TopoDS_Wire& newWire)
390 aBB.MakeWire(newWire);
392 TopTools_ListIteratorOfListOfShape anIt(aLE);
393 for (; anIt.More(); anIt.Next()){
394 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
395 aBB.Add(newWire, aE);
399 //=======================================================================
400 //function : IsToScale
402 //=======================================================================
403 Standard_Boolean IsToScale(const TopoDS_Face& aF,
404 Standard_Real& aScale)
406 Standard_Boolean bRet;
407 Standard_Real aV1, aV2, dV, aTr;
408 GeomAbs_SurfaceType aType;
409 BRepAdaptor_Surface aBAS;
415 aType=aBAS.GetType();
416 if (aType==GeomAbs_Cylinder) {
418 aV1=aBAS.FirstVParameter();
419 aV2=aBAS.LastVParameter();