Salome HOME
Mantis issue 0021837: [CEA 654] Add new method to make any point inside a face.
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PointDriver.cxx
index f39665e6c58043f51cee14b6ab5c09891f2180b0..9fa9cf9c0d8aa1b2dc42e33b8fcef571a0ae5362 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  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 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 
 #include <Standard_Stream.hxx>
 
@@ -25,6 +25,7 @@
 #include <GEOMImpl_IPoint.hxx>
 #include <GEOMImpl_Types.hxx>
 #include <GEOM_Function.hxx>
+#include <GEOMAlgo_Tools3D.hxx>
 
 #include <ShapeAnalysis.hxx>
 
@@ -123,8 +124,8 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
     aPnt = gp_Pnt(aPI.GetX(), aPI.GetY(), aPI.GetZ());
   }
   else if (aType == POINT_XYZ_REF) {
-    Handle(GEOM_Function) aRefPoint = aPI.GetRef();
-    TopoDS_Shape aRefShape = aRefPoint->GetValue();
+    Handle(GEOM_Function) aRefFunc = aPI.GetRef();
+    TopoDS_Shape aRefShape = aRefFunc->GetValue();
     if (aRefShape.ShapeType() != TopAbs_VERTEX) {
       Standard_TypeMismatch::Raise
         ("Point creation aborted : referenced shape is not a vertex");
@@ -133,8 +134,8 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
     aPnt = gp_Pnt(P.X() + aPI.GetX(), P.Y() + aPI.GetY(), P.Z() + aPI.GetZ());
   }
   else if (aType == POINT_CURVE_PAR) {
-    Handle(GEOM_Function) aRefCurve = aPI.GetCurve();
-    TopoDS_Shape aRefShape = aRefCurve->GetValue();
+    Handle(GEOM_Function) aRefFunc = aPI.GetCurve();
+    TopoDS_Shape aRefShape = aRefFunc->GetValue();
     if (aRefShape.ShapeType() != TopAbs_EDGE) {
       Standard_TypeMismatch::Raise
         ("Point On Curve creation aborted : curve shape is not an edge");
@@ -145,8 +146,8 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
     aPnt = aCurve->Value(aP);
   }
   else if (aType == POINT_CURVE_COORD) {
-    Handle(GEOM_Function) aRefCurve = aPI.GetCurve();
-    TopoDS_Shape aRefShape = aRefCurve->GetValue();
+    Handle(GEOM_Function) aRefFunc = aPI.GetCurve();
+    TopoDS_Shape aRefShape = aRefFunc->GetValue();
     if (aRefShape.ShapeType() != TopAbs_EDGE) {
       Standard_TypeMismatch::Raise
         ("Point On Curve creation aborted : curve shape is not an edge");
@@ -159,12 +160,12 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
   }
   else if (aType == POINT_CURVE_LENGTH) {
     // RefCurve
-    Handle(GEOM_Function) aRefCurve = aPI.GetCurve();
-    if (aRefCurve.IsNull()) {
+    Handle(GEOM_Function) aRefFunc = aPI.GetCurve();
+    if (aRefFunc.IsNull()) {
       Standard_NullObject::Raise
         ("Point On Curve creation aborted : curve object is null");
     }
-    TopoDS_Shape aRefShape1 = aRefCurve->GetValue();
+    TopoDS_Shape aRefShape1 = aRefFunc->GetValue();
     if (aRefShape1.ShapeType() != TopAbs_EDGE) {
       Standard_TypeMismatch::Raise
         ("Point On Curve creation aborted : curve shape is not an edge");
@@ -221,8 +222,8 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
     aPnt = AdapCurve.Value(aParam);
   }
   else if (aType == POINT_SURFACE_PAR) {
-    Handle(GEOM_Function) aRefCurve = aPI.GetSurface();
-    TopoDS_Shape aRefShape = aRefCurve->GetValue();
+    Handle(GEOM_Function) aRefFunc = aPI.GetSurface();
+    TopoDS_Shape aRefShape = aRefFunc->GetValue();
     if (aRefShape.ShapeType() != TopAbs_FACE) {
       Standard_TypeMismatch::Raise
         ("Point On Surface creation aborted : surface shape is not a face");
@@ -237,8 +238,8 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
     aPnt = aSurf->Value(U,V);
   }
   else if (aType == POINT_SURFACE_COORD) {
-    Handle(GEOM_Function) aRefCurve = aPI.GetSurface();
-    TopoDS_Shape aRefShape = aRefCurve->GetValue();
+    Handle(GEOM_Function) aRefFunc = aPI.GetSurface();
+    TopoDS_Shape aRefShape = aRefFunc->GetValue();
     if (aRefShape.ShapeType() != TopAbs_FACE) {
       Standard_TypeMismatch::Raise
         ("Point On Surface creation aborted : surface shape is not a face");
@@ -249,6 +250,17 @@ Standard_Integer GEOMImpl_PointDriver::Execute(TFunction_Logbook& log) const
         ("Point On Surface creation aborted : cannot project point");
     }
   }
+  else if (aType == POINT_FACE_ANY) {
+    Handle(GEOM_Function) aRefFunc = aPI.GetSurface();
+    TopoDS_Shape aRefShape = aRefFunc->GetValue();
+    if (aRefShape.ShapeType() != TopAbs_FACE) {
+      Standard_TypeMismatch::Raise
+        ("Point On Surface creation aborted : surface shape is not a face");
+    }
+    TopoDS_Face F = TopoDS::Face(aRefShape);
+    gp_Pnt2d aP2d;
+    GEOMAlgo_Tools3D::PntInFace(F, aPnt, aP2d);
+  }
   else if (aType == POINT_LINES_INTERSECTION) {
     Handle(GEOM_Function) aRef1 = aPI.GetLine1();
     Handle(GEOM_Function) aRef2 = aPI.GetLine2();