Salome HOME
untabify
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_FinderShapeOn1.cxx
index 6a8f33bb4f711469c3e48b038ea4ad0c38d20f91..5776b5b2f4b43119bf8fa6891481f3ca8bdbaf4d 100644 (file)
@@ -1,28 +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-2008  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_FinderShapeOn1.cxx
+// Created:     Fri Mar  4 10:31:06 2005
+// Author:      Peter KURNEV
+//              <pkv@irinox>
 //
-// File:       GEOMAlgo_FinderShapeOn1.cxx
-// Created:    Fri Mar  4 10:31:06 2005
-// Author:     Peter KURNEV
-//             <pkv@irinox>
-
-
 #include <GEOMAlgo_FinderShapeOn1.ixx>
 #include <math.h>
 
@@ -41,6 +42,7 @@
 #include <Poly_Triangle.hxx>
 #include <Poly_PolygonOnTriangulation.hxx>
 #include <Poly_Triangulation.hxx>
+#include <Poly_Polygon3D.hxx>
 
 #include <Geom_Curve.hxx>
 #include <Geom_Surface.hxx>
 #include <BRepLib_MakeEdge.hxx>
 
 #include <GEOMAlgo_ListIteratorOfListOfPnt.hxx>
-#include <GEOMAlgo_PassKey.hxx>
-#include <GEOMAlgo_DataMapOfPassKeyInteger.hxx>
-#include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx>
+
 #include <GEOMAlgo_SurfaceTools.hxx>
 #include <GEOMAlgo_StateCollector.hxx>
+#include <GEOMAlgo_FinderShapeOn.hxx>
 
+#include <GEOMAlgo_PassKey.hxx>
+#include <GEOMAlgo_DataMapOfPassKeyInteger.hxx>
+#include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx>
 
 //=======================================================================
 //function : GEOMAlgo_FinderShapeOn1
@@ -276,7 +280,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessVertices()
     //
     if (myShapeType==TopAbs_VERTEX){
       if (bIsConformState) {
-       myMSS.Add(aV, aSt);
+        myMSS.Add(aV, aSt);
       }
     }
     else if (bIsConformState || aSt==TopAbs_ON) {
@@ -316,11 +320,11 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
       //
       bIsConformState=myMSS.Contains(aV);
       if (!bIsConformState) {
-       break;// vertex has non-conformed state
+        break;// vertex has non-conformed state
       }
       else {
-       aSt=myMSS.FindFromKey(aV);
-       aSC.AppendState(aSt);
+        aSt=myMSS.FindFromKey(aV);
+        aSC.AppendState(aSt);
       }
     }
     //
@@ -344,7 +348,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
       //
       aType2=aGAC.GetType();
       if (aType2==GeomAbs_Line) {
-       continue;
+        continue;
       }
     }
     //
@@ -357,16 +361,16 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
     aIt.Initialize(aLP);
     for (iCnt=0; aIt.More(); aIt.Next(), ++iCnt) {
       if (myNbPntsMax) {
-       if (iCnt > myNbPntsMax) {
-         break;
-       }
+        if (iCnt > myNbPntsMax) {
+          break;
+        }
       }
       //
       const gp_Pnt& aP=aIt.Value();
       aSt = GetPointState( aP );
       bIsToBreak=aSC.AppendState(aSt);
       if (bIsToBreak) {
-       break;
+        break;
       }
     }
     //
@@ -375,7 +379,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
     if (myShapeType==TopAbs_EDGE) {
       if (bIsConformState) {
-       myMSS.Add(aE, aSt);
+        myMSS.Add(aE, aSt);
       }
     }
     else if (bIsConformState || aSt==TopAbs_ON) {
@@ -417,7 +421,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessFaces()
       aGAS.Load(aS);
       aType2=aGAS.GetType();
       if (aType2!=aType1) {
-       continue;
+        continue;
       }
     }
     //
@@ -426,11 +430,11 @@ void GEOMAlgo_FinderShapeOn1::ProcessFaces()
       const TopoDS_Shape& aE=aExp.Current();
       bIsConformState=myMSS.Contains(aE);
       if (!bIsConformState) {
-       break;// edge has non-conformed state
+        break;// edge has non-conformed state
       }
       else {
-       aSt=myMSS.FindFromKey(aE);
-       aSC.AppendState(aSt);
+        aSt=myMSS.FindFromKey(aE);
+        aSC.AppendState(aSt);
       }
     }
     //
@@ -447,16 +451,16 @@ void GEOMAlgo_FinderShapeOn1::ProcessFaces()
     aIt.Initialize(aLP);
     for (iCnt=0; aIt.More(); aIt.Next(), ++iCnt) {
       if (myNbPntsMax) {
-       if (iCnt > myNbPntsMax) {
-         break;
-       }
+        if (iCnt > myNbPntsMax) {
+          break;
+        }
       }
       //
       const gp_Pnt& aP=aIt.Value();
       aSt = GetPointState( aP );
       bIsToBreak=aSC.AppendState(aSt);
       if (bIsToBreak) {
-       break;
+        break;
       }
     }
     //
@@ -465,7 +469,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessFaces()
     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
     if (myShapeType==TopAbs_FACE) {
       if (bIsConformState) {
-       myMSS.Add(aF, aSt);
+        myMSS.Add(aF, aSt);
       }
     }
     else if (bIsConformState || aSt==TopAbs_ON) {
@@ -499,11 +503,11 @@ void GEOMAlgo_FinderShapeOn1::ProcessSolids()
       const TopoDS_Shape& aF=aMF(j);
       bIsConformState=myMSS.Contains(aF);
       if (!bIsConformState) {
-       break;// face has non-conformed state
+        break;// face has non-conformed state
       }
       else {
-       aSt=myMSS.FindFromKey(aF);
-       aSC.AppendState(aSt);
+        aSt=myMSS.FindFromKey(aF);
+        aSC.AppendState(aSt);
       }
     }
     //
@@ -525,12 +529,11 @@ void GEOMAlgo_FinderShapeOn1::ProcessSolids()
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
-                                         GEOMAlgo_ListOfPnt& aLP)
+                                          GEOMAlgo_ListOfPnt& aLP)
 {
   myErrorStatus=0;
   //
-  Standard_Integer j, j1, j2, k, n[4], aNbLinks, aNx, aNbMax, aNb;
-  Standard_Integer iCnt, *pIds;
+  Standard_Integer j, j1, j2, k, n[4], aNbLinks, aNx, aNb, iCnt;//, aNbMax, *pIds;
   TopLoc_Location aLoc;
   Handle(Poly_Triangulation) aTRF;
   TColStd_MapOfInteger aMBN;
@@ -542,8 +545,11 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
   //
   aTRF=BRep_Tool::Triangulation(aF, aLoc);
   if (aTRF.IsNull()) {
-    myErrorStatus=20; // no triangulation found
-    return;  
+    if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aF)) {
+      myWarningStatus=20; // no triangulation found
+      return;
+    }
+    aTRF=BRep_Tool::Triangulation(aF, aLoc);
   }
   //
   const gp_Trsf& aTrsf=aLoc.Transformation();
@@ -562,11 +568,11 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
       //
       aPK.SetIds(n[k], n[k+1]);
       if (aMPKI.IsBound(aPK)) {
-       Standard_Integer& iCntX=aMPKI.ChangeFind(aPK);
-       ++iCntX;
+        Standard_Integer& iCntX=aMPKI.ChangeFind(aPK);
+        ++iCntX;
       }
       else {
-       aMPKI.Bind(aPK, 1);
+        aMPKI.Bind(aPK, 1);
       }
     }
   }
@@ -578,12 +584,20 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
     iCnt=aIt.Value();
     if (iCnt==1) {
       const GEOMAlgo_PassKey& aPK=aIt.Key();
+      //qf
+      /*
       aNbMax=aPK.NbMax();
       pIds=(Standard_Integer*)aPK.Key();
       for (k=1; k<3; ++k) {
-       aNx=*(pIds+aNbMax-k);
-       aMBN.Add(aNx);
+        aNx=*(pIds+aNbMax-k);
+        aMBN.Add(aNx);
       }
+      */
+      aNx=(Standard_Integer)aPK.Id(1);
+      aMBN.Add(aNx);
+      aNx=(Standard_Integer)aPK.Id(2);
+      aMBN.Add(aNx);
+      //qt
     }
   }
   //
@@ -615,42 +629,49 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
       aNbLinks=aMPKI.Extent();
       aIt.Initialize(aMPKI);
       for (; aIt.More(); aIt.Next()) {
-       iCnt=aIt.Value();
-       if (iCnt>1) {
-         // take the first having occured inner link
-         // and discretize it
-         const GEOMAlgo_PassKey& aPK=aIt.Key();
-         aNbMax=aPK.NbMax();
-         pIds=(Standard_Integer*)aPK.Key();
-         aN1=*(pIds+aNbMax-1);
-         aN2=*(pIds+aNbMax-2);
-         aP1=aNodes(aN1).Transformed(aTrsf);
-         aP2=aNodes(aN2).Transformed(aTrsf);
-         //
-         if (aType==GeomAbs_Cylinder) {
-           Standard_Real aTolSM;
-           gp_Cylinder aCyl;
-           //
-           aTolSM=1.523e-6;//~1.-cos(0.1 deg)
-           aCyl=aGAS.Cylinder();
-           if (!GEOMAlgo_SurfaceTools::IsCoaxial(aP1, aP2, aCyl, aTolSM)) {
-             continue;
-           }
-         }
-         //
-         BRepLib_MakeEdge aBME(aP1, aP2);
-         bIsDone=aBME.IsDone();
-         if (!bIsDone) {
-           myErrorStatus=30; //can not obtain the line fron the link
-           return;
-         }
-         //
-         const TopoDS_Shape& aSx=aBME.Shape();
-         const TopoDS_Edge& aE=TopoDS::Edge(aSx);
-         //
-         InnerPoints(aE, myNbPntsMin, aLP);
-         break;
-       }// if (iCnt>1)
+        iCnt=aIt.Value();
+        if (iCnt>1) {
+          // take the first having occured inner link
+          // and discretize it
+          const GEOMAlgo_PassKey& aPK=aIt.Key();
+          //qf
+          /*
+          aNbMax=aPK.NbMax();
+          pIds=(Standard_Integer*)aPK.Key();
+          aN1=*(pIds+aNbMax-1);
+          aN2=*(pIds+aNbMax-2);
+          */
+          //
+          aN1=(Standard_Integer)aPK.Id(1);
+          aN2=(Standard_Integer)aPK.Id(2);
+          //qt
+          aP1=aNodes(aN1).Transformed(aTrsf);
+          aP2=aNodes(aN2).Transformed(aTrsf);
+          //
+          if (aType==GeomAbs_Cylinder) {
+            Standard_Real aTolSM;
+            gp_Cylinder aCyl;
+            //
+            aTolSM=1.523e-6;//~1.-cos(0.1 deg)
+            aCyl=aGAS.Cylinder();
+            if (!GEOMAlgo_SurfaceTools::IsCoaxial(aP1, aP2, aCyl, aTolSM)) {
+              continue;
+            }
+          }
+          //
+          BRepLib_MakeEdge aBME(aP1, aP2);
+          bIsDone=aBME.IsDone();
+          if (!bIsDone) {
+            myErrorStatus=30; //can not obtain the line fron the link
+            return;
+          }
+          //
+          const TopoDS_Shape& aSx=aBME.Shape();
+          const TopoDS_Edge& aE=TopoDS::Edge(aSx);
+          //
+          InnerPoints(aE, myNbPntsMin, aLP);
+          break;
+        }// if (iCnt>1)
       }// for (; aIt.More(); aIt.Next())
     }// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) 
   }// if (!aNb && myNbPntsMin) { 
@@ -660,7 +681,7 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
-                                         GEOMAlgo_ListOfPnt& aLP)
+                                          GEOMAlgo_ListOfPnt& aLP)
 {
   myErrorStatus=0;
   //
@@ -673,19 +694,35 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
   aLP.Clear();
   BRep_Tool::PolygonOnTriangulation(aE, aPTE, aTRE, aLoc);
   if (aTRE.IsNull() || aPTE.IsNull()) {
-    myErrorStatus=20; // no triangulation found
-    return;  
+    Handle(Poly_Polygon3D) aPE = BRep_Tool::Polygon3D(aE, aLoc);
+    if (aPE.IsNull()) {
+      if (!GEOMAlgo_FinderShapeOn::BuildTriangulation(aE)) {
+        myErrorStatus=20; // no triangulation found
+        return;
+      }
+      aPE = BRep_Tool::Polygon3D(aE, aLoc);
+    }
+    const gp_Trsf& aTrsf=aLoc.Transformation();
+    const TColgp_Array1OfPnt& aNodes=aPE->Nodes();
+    //
+    aNbNodes=aPE->NbNodes();
+    Standard_Integer low = aNodes.Lower(), up = aNodes.Upper();
+    for (j=low+1; j<up; ++j) {
+      aP=aNodes(j).Transformed(aTrsf);
+      aLP.Append(aP);
+    }
   }
-  //
-  const gp_Trsf& aTrsf=aLoc.Transformation();
-  const TColgp_Array1OfPnt& aNodes=aTRE->Nodes();
-  //
-  aNbNodes=aPTE->NbNodes();
-  const TColStd_Array1OfInteger& aInds=aPTE->Nodes();
-  for (j=2; j<aNbNodes; ++j) {
-    aIndex=aInds(j);
-    aP=aNodes(aIndex).Transformed(aTrsf);
-    aLP.Append(aP);
+  else {
+    const gp_Trsf& aTrsf=aLoc.Transformation();
+    const TColgp_Array1OfPnt& aNodes=aTRE->Nodes();
+    //
+    aNbNodes=aPTE->NbNodes();
+    const TColStd_Array1OfInteger& aInds=aPTE->Nodes();
+    for (j=2; j<aNbNodes; ++j) {
+      aIndex=aInds(j);
+      aP=aNodes(aIndex).Transformed(aTrsf);
+      aLP.Append(aP);
+    }
   }
   //
   aNb=aLP.Extent();
@@ -693,7 +730,6 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
     // try to fill it yourself
     InnerPoints(aE, myNbPntsMin, aLP);
     aNb=aLP.Extent();
-    
   }
 }
 //=======================================================================
@@ -701,8 +737,8 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
 //purpose  : 
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
-                                         const Standard_Integer aNbPntsMin,
-                                         GEOMAlgo_ListOfPnt& aLP)
+                                          const Standard_Integer aNbPntsMin,
+                                          GEOMAlgo_ListOfPnt& aLP)
 {
   // try to fill it yourself
   Standard_Boolean bInf1, bInf2;
@@ -750,9 +786,9 @@ void GEOMAlgo_FinderShapeOn1::CheckData()
   }
   //
   if (!(myShapeType==TopAbs_VERTEX ||
-       myShapeType==TopAbs_EDGE ||
-       myShapeType==TopAbs_FACE ||
-       myShapeType==TopAbs_SOLID)) {
+        myShapeType==TopAbs_EDGE ||
+        myShapeType==TopAbs_FACE ||
+        myShapeType==TopAbs_SOLID)) {
     myErrorStatus=12; // unallowed subshape type
     return;
   }
@@ -768,8 +804,8 @@ void GEOMAlgo_FinderShapeOn1::CheckData()
   myGAS.Load(mySurface);
   aType=myGAS.GetType();
   if (!(aType==GeomAbs_Plane || 
-       aType==GeomAbs_Cylinder ||
-       aType==GeomAbs_Sphere)) {
+        aType==GeomAbs_Cylinder ||
+        aType==GeomAbs_Sphere)) {
     myErrorStatus=14; // unallowed surface type
   }
 }