Salome HOME
RNC: EDF 1618 Modified sketcher to allow creation of arcs of circle with the destinat...
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_BuilderFace.cxx
index 724e9c77fb5c8f9c11a36e01f0a449823eff03d4..97b9250c6812f8073312b39494886016ce46ce0d 100755 (executable)
@@ -1,26 +1,29 @@
-// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-// 
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-// Lesser General Public License for more details.
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// File:       GEOMAlgo_BuilderFace.cxx
-// Created:    
-// Author:     Peter KURNEV
 
+// File:        GEOMAlgo_BuilderFace.cxx
+// Created:     
+// Author:      Peter KURNEV
+//
 #include <GEOMAlgo_BuilderFace.ixx>
 
 #include <gp_Pnt2d.hxx>
 static
   Standard_Boolean IsGrowthWire(const TopoDS_Shape& ,
 
-                               const TopTools_IndexedMapOfShape& );
+                                const TopTools_IndexedMapOfShape& );
 
 static 
   Standard_Boolean IsInside(const TopoDS_Shape& ,
-                           const TopoDS_Shape& ,
-                           IntTools_PContext& );
+                            const TopoDS_Shape& ,
+                            IntTools_PContext& );
 static
   void MakeInternalWires(const TopTools_MapOfShape& ,
-                        TopTools_ListOfShape& );
+                         TopTools_ListOfShape& );
 
 //=======================================================================
 //function : 
@@ -185,10 +188,10 @@ static
     for (; aIt.More(); aIt.Next()) {
       const TopoDS_Shape& aE=aIt.Value();
       if (!myShapesToAvoid.Contains(aE)) {
-       TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
+        TopExp::MapShapesAndAncestors(aE, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
       }
       else {
-       int a=0;
+        int a=0;
       }
     }
     aNbV=aMVE.Extent();
@@ -200,33 +203,33 @@ static
       TopTools_ListOfShape& aLE=aMVE.ChangeFromKey(aV);
       aNbE=aLE.Extent();
       if (!aNbE) {
-       continue;
+        continue;
       }
       //
       const TopoDS_Edge& aE1=TopoDS::Edge(aLE.First());
       if (aNbE==1) {
-       if (BRep_Tool::Degenerated(aE1)) {
-         continue;
-       }
-       if (aV.Orientation()==TopAbs_INTERNAL) {
-         continue;
-       }
-       bFound=Standard_True;
-       myShapesToAvoid.Add(aE1);
+        if (BRep_Tool::Degenerated(aE1)) {
+          continue;
+        }
+        if (aV.Orientation()==TopAbs_INTERNAL) {
+          continue;
+        }
+        bFound=Standard_True;
+        myShapesToAvoid.Add(aE1);
       }
       else if (aNbE==2) {
-       const TopoDS_Edge& aE2=TopoDS::Edge(aLE.Last());
-       if (aE2.IsSame(aE1)) {
-         TopoDS_Vertex aV1x, aV2x;
-         //
-         TopExp::Vertices(aE1, aV1x, aV2x);
-         if (aV1x.IsSame(aV2x)) {
-           continue;
-         }
-         bFound=Standard_True;
-         myShapesToAvoid.Add(aE1);
-         myShapesToAvoid.Add(aE2);
-       }
+        const TopoDS_Edge& aE2=TopoDS::Edge(aLE.Last());
+        if (aE2.IsSame(aE1)) {
+          TopoDS_Vertex aV1x, aV2x;
+          //
+          TopExp::Vertices(aE1, aV1x, aV2x);
+          if (aV1x.IsSame(aV2x)) {
+            continue;
+          }
+          bFound=Standard_True;
+          myShapesToAvoid.Add(aE1);
+          myShapesToAvoid.Add(aE2);
+        }
       }
     }// for (i=1; i<=aNbE; ++i) {
     //
@@ -251,6 +254,7 @@ static
   TopTools_MapIteratorOfMapOfOrientedShape aItM;
   TopTools_IndexedDataMapOfShapeListOfShape aVEMap;
   TopTools_MapOfOrientedShape aMAdded;
+  TopoDS_Iterator aItW;
   BRep_Builder aBB; 
   GEOMAlgo_WireEdgeSet aWES;
   GEOMAlgo_WESCorrector aWESCor;
@@ -278,6 +282,37 @@ static
     const TopoDS_Shape& aW=aIt.Value();
     myLoops.Append(aW);
   }
+  //modified by NIZNHY-PKV Tue Aug  5 15:09:29 2008f
+  // Post Treatment
+  TopTools_MapOfOrientedShape aMEP;
+  // 
+  // a. collect all edges that are in loops
+  aIt.Initialize (myLoops);
+  for (; aIt.More(); aIt.Next()) {
+    const TopoDS_Shape& aW=aIt.Value();
+    aItW.Initialize(aW);
+    for (; aItW.More(); aItW.Next()) {
+      const TopoDS_Shape& aE=aItW.Value();
+      aMEP.Add(aE);
+    }
+  }
+  // 
+  // b. collect all edges that are to avoid
+  aItM.Initialize(myShapesToAvoid);
+  for (; aItM.More(); aItM.Next()) {
+    const TopoDS_Shape& aE=aItM.Key();
+    aMEP.Add(aE);
+  }
+  //
+  // c. add all edges that are not processed to myShapesToAvoid
+  aIt.Initialize (myShapes);
+  for (; aIt.More(); aIt.Next()) {
+    const TopoDS_Shape& aE=aIt.Value();
+    if (!aMEP.Contains(aE)) {
+      myShapesToAvoid.Add(aE);
+    }
+  }
+  //modified by NIZNHY-PKV Tue Aug  5 15:09:35 2008t
   //
   // 2. Internal Wires
   myLoopsInternal.Clear();
@@ -302,24 +337,24 @@ static
     aBB.MakeWire(aW);
     aBB.Add(aW, aEE);
     //
-    TopoDS_Iterator aItW (aW);
+    aItW.Initialize(aW);
     for (; aItW.More()&&bFlag; aItW.Next()) {
       const TopoDS_Edge& aE=TopoDS::Edge(aItW.Value());
       //
       TopoDS_Iterator aItE(aE);
       for (; aItE.More()&&bFlag; aItE.Next()) {
-       const TopoDS_Vertex& aV = TopoDS::Vertex(aItE.Value());
-       const TopTools_ListOfShape& aLE=aVEMap.FindFromKey(aV);
-       aIt.Initialize(aLE);
-       for (; aIt.More()&&bFlag; aIt.Next()) { 
-         const TopoDS_Shape& aEx=aIt.Value();
-         if (aMAdded.Add(aEx)) {
-           aBB.Add(aW, aEx);
-           if(aMAdded.Extent()==aNbEA) {
-             bFlag=!bFlag;
-           }
-         }
-       }//for (; aIt.More(); aIt.Next()) { 
+        const TopoDS_Vertex& aV = TopoDS::Vertex(aItE.Value());
+        const TopTools_ListOfShape& aLE=aVEMap.FindFromKey(aV);
+        aIt.Initialize(aLE);
+        for (; aIt.More()&&bFlag; aIt.Next()) { 
+          const TopoDS_Shape& aEx=aIt.Value();
+          if (aMAdded.Add(aEx)) {
+            aBB.Add(aW, aEx);
+            if(aMAdded.Extent()==aNbEA) {
+              bFlag=!bFlag;
+            }
+          }
+        }//for (; aIt.More(); aIt.Next()) { 
       }//for (; aItE.More(); aItE.Next()) {
     }//for (; aItW.More(); aItW.Next()) {
     myLoopsInternal.Append(aW);
@@ -372,16 +407,16 @@ static
       bIsHole=GEOMAlgo_BuilderTools::IsHole(aWire, myFace);
       //XX
       if (bIsHole) {
-       aHoleWires.Append(aWire);
-       TopExp::MapShapes(aWire, TopAbs_EDGE, aMHE);
+        aHoleWires.Append(aWire);
+        TopExp::MapShapes(aWire, TopAbs_EDGE, aMHE);
       }
       else {
-       // make a growth face from a wire
-       TopoDS_Face aFace;
-       aBB.MakeFace(aFace, aS, aLoc, aTol);
-       aBB.Add (aFace, aWire);
-       //
-       aNewFaces.Append (aFace);
+        // make a growth face from a wire
+        TopoDS_Face aFace;
+        aBB.MakeFace(aFace, aS, aLoc, aTol);
+        aBB.Add (aFace, aWire);
+        //
+        aNewFaces.Append (aFace);
       }
     }
   }
@@ -415,13 +450,13 @@ static
     if (aInOutMap.IsBound(aHole)){
       const TopoDS_Shape& aF=aInOutMap(aHole);
       if (aMSH.IsBound(aF)) {
-       TopTools_ListOfShape& aLH=aMSH.ChangeFind(aF);
-       aLH.Append(aHole);
+        TopTools_ListOfShape& aLH=aMSH.ChangeFind(aF);
+        aLH.Append(aHole);
       }
       else {
-       TopTools_ListOfShape aLH;
-       aLH.Append(aHole);
-       aMSH.Bind(aF, aLH);
+        TopTools_ListOfShape aLH;
+        aLH.Append(aHole);
+        aMSH.Bind(aF, aLH);
       }
     }
   }// for (; aIt2.More(); aIt2.Next())
@@ -497,7 +532,7 @@ static
     for (; aItME.More(); aItME.Next()) {
       const TopoDS_Edge& aE=TopoDS::Edge(aItME.Key());
       if (IsInside(aE, aF, myContext)) {
-       aMEP.Add(aE);
+        aMEP.Add(aE);
       }
     }
     //
@@ -530,7 +565,7 @@ static
 //purpose  : 
 //=======================================================================
 void MakeInternalWires(const TopTools_MapOfShape& theME,
-                      TopTools_ListOfShape& theWires)
+                       TopTools_ListOfShape& theWires)
 {
   TopTools_MapIteratorOfMapOfShape aItM;
   TopTools_MapOfShape aAddedMap;
@@ -564,15 +599,15 @@ void MakeInternalWires(const TopTools_MapOfShape& theME,
       TopExp_Explorer aExp(aE, TopAbs_VERTEX);
       for (; aExp.More(); aExp.Next()) {
         const TopoDS_Shape& aV =aExp.Current();
-       const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aV);
-       aItE.Initialize(aLE);
-       for (; aItE.More(); aItE.Next()) { 
-         TopoDS_Shape aEL=aItE.Value();
-         if (aAddedMap.Add(aEL)){
-           aEL.Orientation(TopAbs_INTERNAL);
-           aBB.Add(aW, aEL);
-         }
-       }
+        const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aV);
+        aItE.Initialize(aLE);
+        for (; aItE.More(); aItE.Next()) { 
+          TopoDS_Shape aEL=aItE.Value();
+          if (aAddedMap.Add(aEL)){
+            aEL.Orientation(TopAbs_INTERNAL);
+            aBB.Add(aW, aEL);
+          }
+        }
       }
     }
     theWires.Append(aW);
@@ -583,8 +618,8 @@ void MakeInternalWires(const TopTools_MapOfShape& theME,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsInside(const TopoDS_Shape& theHole,
-                         const TopoDS_Shape& theF2,
-                         IntTools_PContext& theContext)
+                          const TopoDS_Shape& theF2,
+                          IntTools_PContext& theContext)
 {
   Standard_Boolean bRet;
   Standard_Real aT, aU, aV;
@@ -624,7 +659,7 @@ Standard_Boolean IsInside(const TopoDS_Shape& theHole,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsGrowthWire(const TopoDS_Shape& theWire,
-                             const TopTools_IndexedMapOfShape& theMHE)
+                              const TopTools_IndexedMapOfShape& theMHE)
 {
   Standard_Boolean bRet;
   TopoDS_Iterator aIt;
@@ -635,7 +670,7 @@ Standard_Boolean IsGrowthWire(const TopoDS_Shape& theWire,
     for(; aIt.More(); aIt.Next()) {
       const TopoDS_Shape& aE=aIt.Value();
       if (theMHE.Contains(aE)) {
-       return !bRet;
+        return !bRet;
       }
     }
   }
@@ -654,8 +689,8 @@ Standard_Boolean IsGrowthWire(const TopoDS_Shape& theWire,
 //purpose  : 
 //=======================================================================
 Standard_Boolean IsInside(const TopoDS_Shape& theHole,
-                         const TopoDS_Shape& theF2,
-                         IntTools_PContext& theContext)
+                          const TopoDS_Shape& theF2,
+                          IntTools_PContext& theContext)
 {
   Standard_Real aT, aU, aV;
   TopExp_Explorer aExp;