1 // Copyright (C) 2007-2010 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>
55 #include <GEOMAlgo_WESScaler.hxx>
59 void MakeWire(const TopTools_ListOfShape& aLE,
60 TopoDS_Wire& newWire);
62 //modified by NIZNHY-PKV Thu Jun 10 11:26:55 2010f
64 Standard_Boolean IsToScale(const TopoDS_Face& aF,
65 Standard_Real& aScale);
66 //modified by NIZNHY-PKV Thu Jun 10 11:27:02 2010t
67 //=======================================================================
70 //=======================================================================
71 GEOMAlgo_WESCorrector::GEOMAlgo_WESCorrector()
76 //=======================================================================
79 //=======================================================================
80 GEOMAlgo_WESCorrector::~GEOMAlgo_WESCorrector()
83 //=======================================================================
86 //=======================================================================
87 void GEOMAlgo_WESCorrector::SetWES (const GEOMAlgo_WireEdgeSet& aWES)
89 GEOMAlgo_WireEdgeSet* pWES=(GEOMAlgo_WireEdgeSet*) &aWES;
92 //=======================================================================
95 //=======================================================================
96 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::WES ()
100 //=======================================================================
103 //=======================================================================
104 GEOMAlgo_WireEdgeSet& GEOMAlgo_WESCorrector::NewWES ()
108 //=======================================================================
111 //=======================================================================
112 void GEOMAlgo_WESCorrector::Perform()
119 //=======================================================================
120 // function: DoConnexityBlocks
122 //=======================================================================
123 void GEOMAlgo_WESCorrector::DoConnexityBlocks()
125 Standard_Boolean bRegular, bClosed;
126 Standard_Integer i, aNbV, j, aNbC, aNbVP, aNbVS;
127 TopTools_ListIteratorOfListOfShape aIt;
128 TopoDS_Iterator aItE;
130 TopTools_IndexedMapOfShape aMER, aMEP, aMEC, aMVP;
131 TopTools_IndexedMapOfShape aMVS, aMVAdd;
132 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
135 const TopTools_ListOfShape& aLSE=myWES->StartElements();
136 aIt.Initialize(aLSE);
137 for (; aIt.More(); aIt.Next()) {
138 const TopoDS_Shape& aE=aIt.Value();
139 if (!aMEP.Contains(aE)) {
141 TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
150 for (i=1; i<=aNbV; ++i) {
151 const TopoDS_Shape& aV=aMVE.FindKey(i);
158 if (aMVS.Contains(aV)) {
161 aMVS.Add(aV); // aMVS - globally processed vertices
163 //------------------------------------- goal: aMEC
164 aMEC.Clear(); // aMEC - edges of CB
165 aMVP.Clear(); // aMVP - vertices to process right now
166 aMVAdd.Clear(); // aMVAdd vertices to process on next step of while(1)
172 for (j=1; j<=aNbVP; ++j) {
173 const TopoDS_Shape& aVP=aMVP(j);
174 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aVP);
176 for (; aIt.More(); aIt.Next()) {
177 const TopoDS_Shape& aE=aIt.Value();
178 if (aMEC.Contains(aE)) {
184 for (; aItE.More(); aItE.Next()) {
185 const TopoDS_Shape& aVE=aItE.Value();
186 if (!aMVS.Contains(aVE)) {
192 }//for (j=1; j<=aNbVP; ++j)
194 aNbVP=aMVAdd.Extent();
196 break; // from while(1)
200 for (j=1; j<=aNbVP; ++j) {
201 const TopoDS_Shape& aVE=aMVAdd(j);
206 //-------------------------------------
207 BOP_ConnexityBlock aCB;
208 TopTools_ListOfShape aLEC;
209 TopTools_IndexedDataMapOfShapeListOfShape aMVER;
211 bRegular=Standard_True;
214 for (j=1; j<=aNbC; ++j) {
217 if (aMER.Contains(aER)) {
218 aER.Orientation(TopAbs_FORWARD);
220 aER.Orientation(TopAbs_REVERSED);
223 bRegular=Standard_False;
230 TopExp::MapShapesAndAncestors(aER, TopAbs_VERTEX, TopAbs_EDGE, aMVER);
232 }//for (j=1; j<=aNbC; ++j) {
235 Standard_Integer k, aNbVR, aNbER;
237 aNbVR=aMVER.Extent();
238 for (k=1; k<=aNbVR; ++k) {
239 const TopTools_ListOfShape& aLER=aMVER(k);
242 const TopoDS_Edge& aEx=TopoDS::Edge(aER);
243 bClosed=BRep_Tool::IsClosed(aEx, myWES->Face());
257 aCB.SetRegularity(bRegular);
258 myConnexityBlocks.Append(aCB);
260 }//for (i=1; i<=aNbV; ++i) {
263 //=======================================================================
264 // function: DoCorrections
266 //=======================================================================
267 void GEOMAlgo_WESCorrector::DoCorrections()
269 Standard_Boolean bIsRegular, bIsNothingToDo, bToScale;
270 Standard_Integer iErr;
271 Standard_Real aScale;
273 BOP_ListIteratorOfListOfConnexityBlock aCBIt;
274 GEOMAlgo_WESScaler aWSC;
276 const TopoDS_Face& aF=myWES->Face();
277 //modified by NIZNHY-PKV Thu Jun 10 11:27:45 2010f
278 bToScale=IsToScale(aF, aScale);
279 //modified by NIZNHY-PKV Thu Jun 10 11:27:49 2010t
281 myNewWES.SetFace(aF);
282 aCBIt.Initialize(myConnexityBlocks);
283 for (; aCBIt.More(); aCBIt.Next()) {
284 const BOP_ConnexityBlock& aCB=aCBIt.Value();
285 const TopTools_ListOfShape& aLE=aCB.Shapes();
287 bIsRegular=aCB.IsRegular();
290 myNewWES.AddShape (aW);
294 GEOMAlgo_WireSplitter aWS;
296 //modified by NIZNHY-PKV Thu Jun 10 10:40:43 2010f
299 TopTools_ListIteratorOfListOfShape aIt;
300 BOPTColStd_ListIteratorOfListOfListOfShape aItLLSS;
302 aWSC.SetScale(aScale);
307 iErr=aWSC.ErrorStatus();
312 const TopoDS_Face& aFS=aWSC.FaceScaled();
313 const TopTools_ListOfShape& aLES=aWSC.EdgesScaled();
319 iErr=aWS.ErrorStatus();
324 bIsNothingToDo=aWS.IsNothingToDo();
325 if (bIsNothingToDo) {
327 myNewWES.AddShape (aW);
331 const BOPTColStd_ListOfListOfShape& aLLSS=aWS.Shapes();
332 aItLLSS.Initialize(aLLSS);
333 for (; aItLLSS.More(); aItLLSS.Next()) {
334 TopTools_ListOfShape aLS;
336 const TopTools_ListOfShape& aLSS=aItLLSS.Value();
337 aIt.Initialize(aLSS);
338 for (; aIt.More(); aIt.Next()) {
339 const TopoDS_Shape& aES=aIt.Value();
345 myNewWES.AddShape (aW);
348 //modified by NIZNHY-PKV Thu Jun 10 10:40:48 2010t
355 iErr=aWS.ErrorStatus();
359 bIsNothingToDo=aWS.IsNothingToDo();
360 if (bIsNothingToDo) {
362 myNewWES.AddShape (aW);
366 const BOPTColStd_ListOfListOfShape& aSSS=aWS.Shapes();
368 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
369 for (; aWireIt.More(); aWireIt.Next()) {
370 const TopTools_ListOfShape& aLEx=aWireIt.Value();
373 myNewWES.AddShape (aW);
378 //=======================================================================
379 // function: MakeWire
381 //=======================================================================
382 void MakeWire(const TopTools_ListOfShape& aLE,
383 TopoDS_Wire& newWire)
386 aBB.MakeWire(newWire);
388 TopTools_ListIteratorOfListOfShape anIt(aLE);
389 for (; anIt.More(); anIt.Next()){
390 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
391 aBB.Add(newWire, aE);
395 //modified by NIZNHY-PKV Thu Jun 10 11:14:09 2010f
397 #include <Geom_Surface.hxx>
398 #include <TopLoc_Location.hxx>
399 #include <BRepAdaptor_Surface.hxx>
401 //=======================================================================
402 //function : IsToScale
404 //=======================================================================
405 Standard_Boolean IsToScale(const TopoDS_Face& aF,
406 Standard_Real& aScale)
408 Standard_Boolean bRet;
409 Standard_Real aV1, aV2, dV, aTr;
410 GeomAbs_SurfaceType aType;
411 BRepAdaptor_Surface aBAS;
417 aType=aBAS.GetType();
418 if (aType==GeomAbs_Cylinder) {
420 aV1=aBAS.FirstVParameter();
421 aV2=aBAS.LastVParameter();
430 //modified by NIZNHY-PKV Thu Jun 10 11:14:12 2010t