Salome HOME
Win32 compliation.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_FinderShapeOn1.cxx
index 3396d93201eeeae305e28ee855ab3f24153fbb6a..3c1a98d1452a15d82868cdd20d10a3bce524bd76 100644 (file)
 // 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>
-//
+
 #include <GEOMAlgo_FinderShapeOn1.ixx>
-#include <math.h>
 
+#include <GEOMAlgo_ListIteratorOfListOfPnt.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>
+
+#include <Basics_OCCTVersion.hxx>
+
+#include <math.h>
 
 #include <Precision.hxx>
 #include <TColStd_Array1OfInteger.hxx>
 #include <BRep_Tool.hxx>
 #include <BRepLib_MakeEdge.hxx>
 
-#include <GEOMAlgo_ListIteratorOfListOfPnt.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
-//purpose  : 
+//purpose  :
 //=======================================================================
 GEOMAlgo_FinderShapeOn1::GEOMAlgo_FinderShapeOn1()
 :
@@ -95,14 +95,14 @@ GEOMAlgo_FinderShapeOn1::GEOMAlgo_FinderShapeOn1()
 }
 //=======================================================================
 //function : ~
-//purpose  : 
+//purpose  :
 //=======================================================================
 GEOMAlgo_FinderShapeOn1::~GEOMAlgo_FinderShapeOn1()
 {
 }
 //=======================================================================
 //function : SetSurface
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::SetSurface(const Handle(Geom_Surface)& aS)
 {
@@ -110,7 +110,7 @@ void GEOMAlgo_FinderShapeOn1::SetSurface(const Handle(Geom_Surface)& aS)
 }
 //=======================================================================
 //function : Surface
-//purpose  : 
+//purpose  :
 //=======================================================================
 const Handle(Geom_Surface)& GEOMAlgo_FinderShapeOn1::Surface() const
 {
@@ -118,7 +118,7 @@ const Handle(Geom_Surface)& GEOMAlgo_FinderShapeOn1::Surface() const
 }
 //=======================================================================
 //function : SetShapeType
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::SetShapeType(const TopAbs_ShapeEnum aType)
 {
@@ -126,7 +126,7 @@ void GEOMAlgo_FinderShapeOn1::SetShapeType(const TopAbs_ShapeEnum aType)
 }
 //=======================================================================
 //function : ShapeType
-//purpose  : 
+//purpose  :
 //=======================================================================
 TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn1::ShapeType()const
 {
@@ -134,7 +134,7 @@ TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn1::ShapeType()const
 }
 //=======================================================================
 //function : SetState
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::SetState(const GEOMAlgo_State aState)
 {
@@ -142,7 +142,7 @@ void GEOMAlgo_FinderShapeOn1::SetState(const GEOMAlgo_State aState)
 }
 //=======================================================================
 //function : State
-//purpose  : 
+//purpose  :
 //=======================================================================
 GEOMAlgo_State GEOMAlgo_FinderShapeOn1::State() const
 {
@@ -150,7 +150,7 @@ GEOMAlgo_State GEOMAlgo_FinderShapeOn1::State() const
 }
 //=======================================================================
 //function : SetNbPntsMin
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::SetNbPntsMin(const Standard_Integer aNb)
 {
@@ -158,7 +158,7 @@ void GEOMAlgo_FinderShapeOn1::SetNbPntsMin(const Standard_Integer aNb)
 }
 //=======================================================================
 //function : NbPntsMin
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Integer GEOMAlgo_FinderShapeOn1::NbPntsMin()const
 {
@@ -166,7 +166,7 @@ Standard_Integer GEOMAlgo_FinderShapeOn1::NbPntsMin()const
 }
 //=======================================================================
 //function : SetNbPntsMax
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::SetNbPntsMax(const Standard_Integer aNb)
 {
@@ -174,7 +174,7 @@ void GEOMAlgo_FinderShapeOn1::SetNbPntsMax(const Standard_Integer aNb)
 }
 //=======================================================================
 //function : NbPntsMax
-//purpose  : 
+//purpose  :
 //=======================================================================
 Standard_Integer GEOMAlgo_FinderShapeOn1::NbPntsMax()const
 {
@@ -182,7 +182,7 @@ Standard_Integer GEOMAlgo_FinderShapeOn1::NbPntsMax()const
 }
 //=======================================================================
 // function: MSS
-// purpose: 
+// purpose:
 //=======================================================================
 const GEOMAlgo_IndexedDataMapOfShapeState& GEOMAlgo_FinderShapeOn1::MSS() const
 {
@@ -190,7 +190,7 @@ const GEOMAlgo_IndexedDataMapOfShapeState& GEOMAlgo_FinderShapeOn1::MSS() const
 }
 //=======================================================================
 // function: Shapes
-// purpose: 
+// purpose:
 //=======================================================================
 const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn1::Shapes() const
 {
@@ -211,7 +211,7 @@ const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn1::Shapes() const
 }
 //=======================================================================
 //function : Perform
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::Perform()
 {
@@ -225,6 +225,11 @@ void GEOMAlgo_FinderShapeOn1::Perform()
     return;
   }
   //
+#if OCC_VERSION_LARGE > 0x06050200
+  // Initialize the context
+  GEOMAlgo_ShapeAlgo::Perform();
+#endif
+  //
   // 1
   ProcessVertices();
   if(myErrorStatus) {
@@ -253,12 +258,12 @@ void GEOMAlgo_FinderShapeOn1::Perform()
   }
   //
   // 4
-  ProcessSolids(); 
+  ProcessSolids();
   //
 }
 //=======================================================================
 //function : ProcessVertices
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::ProcessVertices()
 {
@@ -291,7 +296,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessVertices()
 }
 //=======================================================================
 //function : ProcessEdges
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::ProcessEdges()
 {
@@ -334,13 +339,13 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
     }
     //
     if (BRep_Tool::Degenerated(aE)) {
-      myMSS.Add(aE, aSt); 
+      myMSS.Add(aE, aSt);
       continue;
     }
     //
     if (myState==GEOMAlgo_ST_ON && aType1==GeomAbs_Sphere) {
       Standard_Real aT1, aT2;
-      Handle(Geom_Curve) aC; 
+      Handle(Geom_Curve) aC;
       GeomAdaptor_Curve aGAC;
       GeomAbs_CurveType aType2;
       //
@@ -355,7 +360,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
     //
     InnerPoints(aE, aLP);
     if (myErrorStatus) {
-      return;  
+      return;
     }
     //
     bIsConformState=Standard_True;
@@ -375,7 +380,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
       }
     }
     //
-    aSt=aSC.State();    
+    aSt=aSC.State();
     //
     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
     if (myShapeType==TopAbs_EDGE) {
@@ -386,11 +391,11 @@ void GEOMAlgo_FinderShapeOn1::ProcessEdges()
     else if (bIsConformState || aSt==TopAbs_ON) {
       myMSS.Add(aE, aSt);
     }
-  } //  for (i=1; i<=aNb; ++i) next edge 
+  } //  for (i=1; i<=aNb; ++i) next edge
 }
 //=======================================================================
 //function : ProcessFaces
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::ProcessFaces()
 {
@@ -465,7 +470,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessFaces()
       }
     }
     //
-    aSt=aSC.State();    
+    aSt=aSC.State();
     //
     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
     if (myShapeType==TopAbs_FACE) {
@@ -476,11 +481,11 @@ void GEOMAlgo_FinderShapeOn1::ProcessFaces()
     else if (bIsConformState || aSt==TopAbs_ON) {
       myMSS.Add(aF, aSt);
     }
-  }//  for (i=1; i<=aNb; ++i) next face 
+  }//  for (i=1; i<=aNb; ++i) next face
 }
 //=======================================================================
 //function : ProcessSolids
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::ProcessSolids()
 {
@@ -516,7 +521,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessSolids()
       continue; // face has non-conformed state,skip solid
     }
     //
-    aSt=aSC.State();    
+    aSt=aSC.State();
     //
     bIsConformState=GEOMAlgo_SurfaceTools::IsConformState(aSt, myState);
     if (bIsConformState) {
@@ -527,7 +532,7 @@ void GEOMAlgo_FinderShapeOn1::ProcessSolids()
 //
 //=======================================================================
 //function : InnerPoints
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
                                           GEOMAlgo_ListOfPnt& aLP)
@@ -585,24 +590,15 @@ 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=(Standard_Integer)aPK.Id(1);
       aMBN.Add(aNx);
       aNx=(Standard_Integer)aPK.Id(2);
       aMBN.Add(aNx);
-      //qt
     }
   }
   //
-  // inner nodes=all_nodes - boundary_nodes 
+  // inner nodes=all_nodes - boundary_nodes
   j1=aNodes.Lower();
   j2=aNodes.Upper();
   for (j=j1; j<=j2; ++j) {
@@ -614,7 +610,7 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
   //
   aNb=aLP.Extent();
   //
-  if (!aNb && myNbPntsMin) { 
+  if (!aNb && myNbPntsMin) {
     // try to fill it yourself
     Standard_Boolean bIsDone;
     Standard_Integer aN1, aN2;
@@ -635,17 +631,10 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
           // 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);
           //
@@ -674,74 +663,34 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Face& aF,
           break;
         }// if (iCnt>1)
       }// for (; aIt.More(); aIt.Next())
-    }// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) 
-  }// if (!aNb && myNbPntsMin) { 
+    }// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder)
+  }// if (!aNb && myNbPntsMin) {
 }
+//modified by NIZNHY-PKV Thu Jan 26 09:56:20 2012f
 //=======================================================================
 //function : InnerPoints
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
                                           GEOMAlgo_ListOfPnt& aLP)
 {
-  myErrorStatus=0;
+  Standard_Integer aNbPntsMin;
   //
-  Standard_Integer j, aNbNodes, aIndex, aNb;
-  Handle(Poly_PolygonOnTriangulation) aPTE;
-  Handle(Poly_Triangulation) aTRE;
-  TopLoc_Location aLoc;
-  gp_Pnt aP;
+  myErrorStatus=0;
+  aNbPntsMin=21;
   //
   aLP.Clear();
-  BRep_Tool::PolygonOnTriangulation(aE, aPTE, aTRE, aLoc);
-  if (aTRE.IsNull() || aPTE.IsNull()) {
-    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);
-    }
-  }
-  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();
-  if (!aNb && myNbPntsMin) { 
-    // try to fill it yourself
-    InnerPoints(aE, myNbPntsMin, aLP);
-    aNb=aLP.Extent();
-  }
+  InnerPoints(aE, aNbPntsMin, aLP);
 }
+//modified by NIZNHY-PKV Thu Jan 26 09:56:32 2012t
 //=======================================================================
 //function : InnerPoints
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
                                           const Standard_Integer aNbPntsMin,
                                           GEOMAlgo_ListOfPnt& aLP)
 {
-  // try to fill it yourself
   Standard_Boolean bInf1, bInf2;
   Standard_Integer j, aNbT;
   Standard_Real dT, aT, aT1, aT2;
@@ -759,6 +708,8 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
     return;
   }
   //
+  //modified by NIZNHY-PKV Thu Jan 26 09:51:20 2012f
+  /*
   aNbT=myNbPntsMin+1;
   dT=(aT2-aT1)/aNbT;
   for (j=1; j<=aNbPntsMin; ++j) {
@@ -766,11 +717,20 @@ void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
     aC3D->D0(aT, aP);
     aLP.Append(aP);
   }
+  */
+  aNbT=aNbPntsMin+1;
+  dT=(aT2-aT1)/aNbT;
+  for (j=1; j<aNbT; ++j) {
+    aT=aT1+j*dT;
+    aC3D->D0(aT, aP);
+    aLP.Append(aP);
+  }
+  //modified by NIZNHY-PKV Thu Jan 26 09:51:24 2012t
 }
 
 //=======================================================================
 //function : CheckData
-//purpose  : 
+//purpose  :
 //=======================================================================
 void GEOMAlgo_FinderShapeOn1::CheckData()
 {
@@ -790,11 +750,11 @@ void GEOMAlgo_FinderShapeOn1::CheckData()
         myShapeType==TopAbs_EDGE ||
         myShapeType==TopAbs_FACE ||
         myShapeType==TopAbs_SOLID)) {
-    myErrorStatus=12; // unallowed sub-shape type
+    myErrorStatus=12; // unallowed subshape type
     return;
   }
   //
-  if (myState==GEOMAlgo_ST_UNKNOWN || 
+  if (myState==GEOMAlgo_ST_UNKNOWN ||
       myState==GEOMAlgo_ST_INOUT) {
     myErrorStatus=13; // unallowed state type
     return;
@@ -804,7 +764,7 @@ void GEOMAlgo_FinderShapeOn1::CheckData()
   //
   myGAS.Load(mySurface);
   aType=myGAS.GetType();
-  if (!(aType==GeomAbs_Plane || 
+  if (!(aType==GeomAbs_Plane ||
         aType==GeomAbs_Cylinder ||
         aType==GeomAbs_Sphere)) {
     myErrorStatus=14; // unallowed surface type
@@ -813,10 +773,10 @@ void GEOMAlgo_FinderShapeOn1::CheckData()
 
 //=======================================================================
 //function : GetPointState
-//purpose  : 
+//purpose  :
 //=======================================================================
 
-TopAbs_State GEOMAlgo_FinderShapeOn1::GetPointState(const gp_Pnt& aP) 
+TopAbs_State GEOMAlgo_FinderShapeOn1::GetPointState(const gp_Pnt& aP)
 {
   TopAbs_State aSt;
   GEOMAlgo_SurfaceTools::GetState(aP, myGAS, myTolerance, aSt);
@@ -829,63 +789,70 @@ TopAbs_State GEOMAlgo_FinderShapeOn1::GetPointState(const gp_Pnt& aP)
 //
 // 10 -mySurface=NULL
 // 11 -myShape=NULL
-// 12 -unallowed type of sub-shapes 
-// 13 -unallowed state  
+// 12 -unallowed type of subshapes
+// 13 -unallowed state
 // 14 -unallowed surface type
 // 15 -unallowed surface type
 // 20- no triangulation found
 // 30- can not obtain the line from the link
 
-
+//modified by NIZNHY-PKV Thu Jan 26 10:01:14 2012f
 /*
-// Chronometer
-#include <OSD_Chronometer.hxx>
-#include <Standard_Static.hxx>
-
-Standard_STATIC(OSD_Chronometer, x_S_Chrono);
-static void x_StartChrono();
-static void x_StopChrono(); 
-static Standard_Boolean x_IsToShow(); 
-//
 //=======================================================================
-//function : x_StartChrono
-//purpose  : 
+//function : InnerPoints
+//purpose  :
 //=======================================================================
-void x_StartChrono() 
+void GEOMAlgo_FinderShapeOn1::InnerPoints(const TopoDS_Edge& aE,
+                                          GEOMAlgo_ListOfPnt& aLP)
 {
-  if (x_IsToShow()){
-    x_S_Chrono().Reset();
-    x_S_Chrono().Start();
+  myErrorStatus=0;
+  //
+  Standard_Integer j, aNbNodes, aIndex, aNb;
+  Handle(Poly_PolygonOnTriangulation) aPTE;
+  Handle(Poly_Triangulation) aTRE;
+  TopLoc_Location aLoc;
+  gp_Pnt aP;
+  //
+  aLP.Clear();
+  BRep_Tool::PolygonOnTriangulation(aE, aPTE, aTRE, aLoc);
+  if (aTRE.IsNull() || aPTE.IsNull()) {
+    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);
+    }
   }
-}
-//=======================================================================
-//function : x_StopChrono
-//purpose  : 
-//=======================================================================
-void x_StopChrono() 
-{ 
-  if (x_IsToShow()){
-    Standard_Real Chrono;
-    x_S_Chrono().Stop();
-    x_S_Chrono().Show(Chrono);
-    printf(" Tps: %lf\n", Chrono);
-    //cout << "Tps: " << Chrono << endl;
+  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);
+    }
   }
-}
-//=======================================================================
-//function : x_IsToShow
-//purpose  : 
-//=======================================================================
-Standard_Boolean x_IsToShow() 
-{ 
-  Standard_Boolean bFlag=Standard_False;
   //
-  char *xr=getenv ("STDCHRONO");
-  if (xr!=NULL){
-    if (!strcmp (xr, "yes")) {
-      bFlag=!bFlag;
-    }
+  aNb=aLP.Extent();
+  if (!aNb && myNbPntsMin) {
+    // try to fill it yourself
+    InnerPoints(aE, myNbPntsMin, aLP);
+    aNb=aLP.Extent();
   }
-  return bFlag;
 }
 */
+//modified by NIZNHY-PKV Thu Jan 26 10:01:17 2012t