]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added option to create Construction Point by projection point on plane. Fixed CPP...
authordbv <dbv@opencascade.com>
Mon, 4 Jul 2016 11:07:09 +0000 (14:07 +0300)
committerdbv <dbv@opencascade.com>
Mon, 4 Jul 2016 11:07:33 +0000 (14:07 +0300)
19 files changed:
src/ConstructionAPI/ConstructionAPI_Plane.cpp
src/ConstructionAPI/ConstructionAPI_Point.cpp
src/ConstructionAPI/ConstructionAPI_Point.h
src/ConstructionPlugin/CMakeLists.txt
src/ConstructionPlugin/ConstructionPlugin_Point.cpp
src/ConstructionPlugin/ConstructionPlugin_Point.h
src/ConstructionPlugin/Test/TestPoint.py [new file with mode: 0644]
src/ConstructionPlugin/icons/face.png [new file with mode: 0644]
src/ConstructionPlugin/icons/point_by_projection_32x32.png [new file with mode: 0644]
src/ConstructionPlugin/point_widget.xml
src/GeomAPI/GeomAPI_Vertex.h
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_Circle.cpp
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp

index 61a72e06141b9c2e591b970908b11999fe970242..a248e71d1350250473907b864af272bf30112c14 100644 (file)
@@ -48,6 +48,7 @@ void ConstructionAPI_Plane::setFaceAndDistance(
     const ModelHighAPI_Selection & theFace,
     const ModelHighAPI_Double & theDistance)
 {
+  fillAttribute("PlaneByFaceAndDistance", mycreationMethod);
   fillAttribute(theFace, myface);
   fillAttribute(theDistance, mydistance);
 
@@ -60,6 +61,7 @@ void ConstructionAPI_Plane::setGeneralEquation(
     const ModelHighAPI_Double & theC,
     const ModelHighAPI_Double & theD)
 {
+  fillAttribute("PlaneByGeneralEquation", mycreationMethod);
   fillAttribute(theA, myA);
   fillAttribute(theB, myB);
   fillAttribute(theC, myC);
index c982cc2a7fb42c094efed78d4b23193bb4d43c89..738703a6e19b16270d3114aabc938606016405cd 100644 (file)
@@ -40,6 +40,19 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
   }
 }
 
+//==================================================================================================
+ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                             const ModelHighAPI_Selection& theObject1,
+                                             const ModelHighAPI_Selection& theObject2)
+: ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    /// If first object is vertex and second object is face then set by projection.
+    /// TODO: check
+    setByProjection(theObject1, theObject2);
+  }
+}
+
 //==================================================================================================
 ConstructionAPI_Point::~ConstructionAPI_Point()
 {
@@ -74,6 +87,17 @@ void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& th
   execute();
 }
 
+//==================================================================================================
+void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex,
+                                            const ModelHighAPI_Selection& thePlane)
+{
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod);
+  fillAttribute(theVertex, mypoint);
+  fillAttribute(thePlane, myplane);
+
+  execute();
+}
+
 //==================================================================================================
 PointPtr addPoint(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const ModelHighAPI_Double& theX,
@@ -96,3 +120,13 @@ PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
   return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse));
 }
+
+//==================================================================================================
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+                  const ModelHighAPI_Selection& theObject1,
+                  const ModelHighAPI_Selection& theObject2)
+{
+  // TODO(spo): check that thePart is not empty
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(ConstructionAPI_Point::ID());
+  return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2));
+}
index 3e67ce80ee76ba397b534ee1424480c2692eead0..ab9f83837c72f6469c0604e1c293f06ffe547754 100644 (file)
@@ -20,22 +20,22 @@ class ModelHighAPI_Double;
 
 /// \class ConstructionAPI_Point
 /// \ingroup CPPHighAPI
-/// \brief Interface for Point feature
+/// \brief Interface for Point feature.
 class ConstructionAPI_Point: public ModelHighAPI_Interface
 {
 public:
-  /// Constructor without values
+  /// Constructor without values.
   CONSTRUCTIONAPI_EXPORT
   explicit ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature);
 
-  /// Constructor with values
+  /// Constructor with values.
   CONSTRUCTIONAPI_EXPORT
   ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                         const ModelHighAPI_Double& theX,
                         const ModelHighAPI_Double& theY,
                         const ModelHighAPI_Double& theZ);
 
-  /// Constructor with values
+  /// Constructor with values.
   CONSTRUCTIONAPI_EXPORT
   ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                         const ModelHighAPI_Selection& theEdge,
@@ -43,36 +43,49 @@ public:
                         const bool theDistancePercent = false,
                         const bool theReverse = false);
 
-  /// Destructor
+  /// Constructor with values.
+  CONSTRUCTIONAPI_EXPORT
+  ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                        const ModelHighAPI_Selection& theObject1,
+                        const ModelHighAPI_Selection& theObject2);
+
+  /// Destructor.
   CONSTRUCTIONAPI_EXPORT
   virtual ~ConstructionAPI_Point();
 
-  INTERFACE_8(ConstructionPlugin_Point::ID(),
-              creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
-              x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
-              y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
-              z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
-              edge, ConstructionPlugin_Point::EDGE(), ModelAPI_AttributeSelection, /** Edge attribute */,
-              distanceValue, ConstructionPlugin_Point::DISTANCE_VALUE(), ModelAPI_AttributeDouble, /** Distance value attribute */,
-              distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */,
-              reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */
+  INTERFACE_10(ConstructionPlugin_Point::ID(),
+               creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */,
+               x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
+               y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
+               z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
+               edge, ConstructionPlugin_Point::EDGE(), ModelAPI_AttributeSelection, /** Edge attribute */,
+               distanceValue, ConstructionPlugin_Point::DISTANCE_VALUE(), ModelAPI_AttributeDouble, /** Distance value attribute */,
+               distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */,
+               reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */,
+               point, ConstructionPlugin_Point::POINT(), ModelAPI_AttributeSelection, /** Point attribute */,
+               plane, ConstructionPlugin_Point::PLANE(), ModelAPI_AttributeSelection, /** Plane attribute */
   )
 
-  /// Set point values
+  /// Set point values.
   CONSTRUCTIONAPI_EXPORT
   void setByXYZ(const ModelHighAPI_Double & theX,
                 const ModelHighAPI_Double & theY,
                 const ModelHighAPI_Double & theZ);
 
-  /// Set edge and distance on it for point
+  /// Set edge and distance on it for point.
   CONSTRUCTIONAPI_EXPORT
   void setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge,
                            const ModelHighAPI_Double& theDistanceValue,
                            const bool theDistancePercent = false,
                            const bool theReverse = false);
+
+  /// Set point and plane for projection.
+  CONSTRUCTIONAPI_EXPORT
+  void setByProjection(const ModelHighAPI_Selection& theVertex,
+                       const ModelHighAPI_Selection& thePlane);
 };
 
-/// Pointer on Point object
+/// Pointer on Point object.
 typedef std::shared_ptr<ConstructionAPI_Point> PointPtr;
 
 /// \ingroup CPPHighAPI
@@ -92,4 +105,11 @@ PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
                   const bool theDistancePercent = false,
                   const bool theReverse = false);
 
+/// \ingroup CPPHighAPI
+/// \brief Create Point feature
+CONSTRUCTIONAPI_EXPORT
+PointPtr addPoint(const std::shared_ptr<ModelAPI_Document> & thePart,
+                  const ModelHighAPI_Selection& theObject1,
+                  const ModelHighAPI_Selection& theObject2);
+
 #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */ 
index bdbc15f8536a4626df324adcb418ed465caf446e..4b5ca9ddb246badcdc13b74002b795ba2b7755e2 100644 (file)
@@ -55,4 +55,5 @@ INCLUDE_DIRECTORIES(
 
 
 ADD_UNIT_TESTS(TestAxisCreation.py
-               TestPointName.py)
+               TestPointName.py
+               TestPoint.py)
index c7b4f1d444a44ef351e0d2f928115d78605bfea0..380393db703ea60e5feb37ac5c474aacea46f967 100644 (file)
 #include <ModelAPI_ResultConstruction.h>
 
 #include <GeomAlgoAPI_PointBuilder.h>
-#include <GeomAlgoAPI_ShapeTools.h>
 
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Vertex.h>
 
 //==================================================================================================
 ConstructionPlugin_Point::ConstructionPlugin_Point()
@@ -43,6 +43,9 @@ void ConstructionPlugin_Point::initAttributes()
   data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId());
   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
+
+  data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId());
 }
 
 //==================================================================================================
@@ -55,6 +58,8 @@ void ConstructionPlugin_Point::execute()
     aShape = createByXYZ();
   } else if(aCreationMethod == CREATION_METHOD_BY_DISTANCE_ON_EDGE()) {
     aShape = createByDistanceOnEdge();
+  } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION()) {
+    aShape = createByProjection();
   }
 
   if(aShape.get()) {
@@ -76,15 +81,15 @@ bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult,
 }
 
 //==================================================================================================
-GeomShapePtr ConstructionPlugin_Point::createByXYZ()
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByXYZ()
 {
-  return GeomAlgoAPI_PointBuilder::point(real(X())->value(),
-                                         real(Y())->value(),
-                                         real(Z())->value());
+  return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(),
+                                          real(Y())->value(),
+                                          real(Z())->value());
 }
 
 //==================================================================================================
-GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge()
 {
   // Get edge.
   AttributeSelectionPtr anEdgeSelection = selection(EDGE());
@@ -101,5 +106,27 @@ GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge()
   // Get reverse flag.
   bool anIsReverse = boolean(REVERSE())->value();
 
-  return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
+  return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjection()
+{
+  // Get point.
+  AttributeSelectionPtr aPointSelection = selection(POINT());
+  GeomShapePtr aPointShape = aPointSelection->value();
+  if(!aPointShape.get()) {
+    aPointShape = aPointSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+
+  // Get plane.
+  AttributeSelectionPtr aPlaneSelection = selection(PLANE());
+  GeomShapePtr aPlaneShape = aPlaneSelection->value();
+  if(!aPlaneShape.get()) {
+    aPlaneShape = aPlaneSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aPlaneShape));
+
+  return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace);
 }
index 956eeeb0069ae108010c8acf3374dcdec5ba3f7c..65d17aef2e878f03880a095a7e797257ef718b07 100644 (file)
@@ -13,6 +13,8 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 
+class GeomAPI_Vertex;
+
 /// \class ConstructionPlugin_Point
 /// \ingroup Plugins
 /// \brief Feature for creation of the new part in PartSet.
@@ -50,6 +52,13 @@ public:
     return MY_CREATION_METHOD_ID;
   }
 
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_PROJECTION()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_projection");
+    return MY_CREATION_METHOD_ID;
+  }
+
   /// Attribute name for X coordinate.
   inline static const std::string& X()
   {
@@ -99,6 +108,20 @@ public:
     return ATTR_ID;
   }
 
+  /// Attribute name for point.
+  inline static const std::string& POINT()
+  {
+    static const std::string ATTR_ID("point");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for plane.
+  inline static const std::string& PLANE()
+  {
+    static const std::string ATTR_ID("plane");
+    return ATTR_ID;
+  }
+
   /// Creates a new part document if needed.
   CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
 
@@ -116,8 +139,9 @@ public:
                                      std::shared_ptr<GeomAPI_ICustomPrs> theDefaultPrs);
 
 private:
-  std::shared_ptr<GeomAPI_Shape> createByXYZ();
-  std::shared_ptr<GeomAPI_Shape> createByDistanceOnEdge();
+  std::shared_ptr<GeomAPI_Vertex> createByXYZ();
+  std::shared_ptr<GeomAPI_Vertex> createByDistanceOnEdge();
+  std::shared_ptr<GeomAPI_Vertex> createByProjection();
 
 };
 
diff --git a/src/ConstructionPlugin/Test/TestPoint.py b/src/ConstructionPlugin/Test/TestPoint.py
new file mode 100644 (file)
index 0000000..272fe4d
--- /dev/null
@@ -0,0 +1,49 @@
+"""
+Test case for Construction Point feature. Written on High API.
+"""
+from ModelAPI import *
+from GeomAPI import *
+
+import model
+
+# Get session
+aSession = ModelAPI_Session.get()
+
+# Create a part
+aDocument = aSession.activeDocument()
+aSession.startOperation()
+model.addPart(aDocument)
+aDocument = aSession.activeDocument()
+aSession.finishOperation()
+
+# Create a point by coordinates
+aSession.startOperation()
+aPoint = model.addPoint(aDocument, 50, 50, 50)
+aSession.finishOperation()
+assert (len(aPoint.result()) > 0)
+
+# Create a sketch with line
+aSession.startOperation()
+anOrigin = GeomAPI_Pnt(0, 0, 0)
+aDirX = GeomAPI_Dir(1, 0, 0)
+aNorm = GeomAPI_Dir(0, 0, 1)
+aSketch = model.addSketch(aDocument, GeomAPI_Ax3(anOrigin, aDirX, aNorm))
+aSketchLine = aSketch.addLine(25, 25, 100, 25)
+aSession.finishOperation()
+
+# Create a point on line
+aSession.startOperation()
+aPoint = model.addPoint(aDocument, aSketchLine.result()[0], 50, True, False)
+aSession.finishOperation()
+assert (len(aPoint.result()) > 0)
+
+# Create plane
+aSession.startOperation()
+aPlane = model.addPlane(aDocument, 1, 1, 1, 1)
+aSession.finishOperation()
+
+# Create a point by projection
+aSession.startOperation()
+aPoint = model.addPoint(aDocument, aPoint.result()[0], aPlane.result()[0])
+aSession.finishOperation()
+assert (len(aPoint.result()) > 0)
diff --git a/src/ConstructionPlugin/icons/face.png b/src/ConstructionPlugin/icons/face.png
new file mode 100644 (file)
index 0000000..6abc697
Binary files /dev/null and b/src/ConstructionPlugin/icons/face.png differ
diff --git a/src/ConstructionPlugin/icons/point_by_projection_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_32x32.png
new file mode 100644 (file)
index 0000000..e5a5510
Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_projection_32x32.png differ
index 4557509f39f119ebdd77c3dd2699fc6f846a5eda..230aac45a3f728b9f939617709f0080a9287dab7 100644 (file)
            tooltip="Distance from edge end point."
            default="false"/>
     </box>
+    <box id="by_projection"
+         title="By projection"
+         tooltip="Point on face surface by projection selected point."
+         icon="icons/Construction/point_by_projection_32x32.png">
+      <shape_selector id="point"
+                      label="Point"
+                      tooltip="Point for projection."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+      </shape_selector>
+      <shape_selector id="plane"
+                      label="Plane"
+                      tooltip="Plane for projection."
+                      icon="icons/Construction/face.png"
+                      shape_types="face">
+        <validator id="GeomValidators_Face" parameters="plane"/>
+      </shape_selector>
+    </box>
   </toolbox>
 </source>
index c1ec7109c3d669158ffad59dd374360ddc6f1d32..c5f0dfe27144e2ff9054a7287aeefc43f26adb41 100644 (file)
 
 class GeomAPI_Pnt;
 
-/**\class GeomAPI_Vertex
-* \ingroup DataModel
- * \brief Interface to the vertex object
- */
-
-class GeomAPI_Vertex : public GeomAPI_Shape
+/// \class GeomAPI_Vertex
+/// \ingroup DataModel
+/// \brief Interface to the vertex object.
+class GeomAPI_Vertex: public GeomAPI_Shape
 {
 public:
-   /// Creation of empty (null) shape
-  GEOMAPI_EXPORT 
-   GeomAPI_Vertex();
+  /// Creation of empty (null) shape.
+  GEOMAPI_EXPORT
+  GeomAPI_Vertex();
 
-   /// Creation of vertex by the vertex-shape
-  GEOMAPI_EXPORT 
-   GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape);
+   /// Creation of vertex by the vertex-shape.
+  GEOMAPI_EXPORT
+  GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape);
 
-   /// Creation of vertex by 3d coordinates
-  GEOMAPI_EXPORT 
-   GeomAPI_Vertex(double theX, double theY, double theZ);
+   /// Creation of vertex by 3d coordinates.
+  GEOMAPI_EXPORT
+  GeomAPI_Vertex(double theX, double theY, double theZ);
 
-  /// Returns the first vertex coordinates of the edge 
-  GEOMAPI_EXPORT 
+  /// Returns the first vertex coordinates of the edge.
+  GEOMAPI_EXPORT
   std::shared_ptr<GeomAPI_Pnt> point();
 
-  /// Returns true if the current edge is geometrically equal to the given edge
-  GEOMAPI_EXPORT 
+  /// Returns true if the current edge is geometrically equal to the given edge.
+  GEOMAPI_EXPORT
   bool isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const;
 };
 
index dffcecce403d8ab1f74c70d577937e0e0a9edccf..a76850441fe1e14021b5613d75f9b57d5b76bd9d 100644 (file)
@@ -4,18 +4,26 @@
 // Created:     02 Jun 2014
 // Author:      Mikhail PONIKAROV
 
-#include <GeomAlgoAPI_PointBuilder.h>
+#include "GeomAlgoAPI_PointBuilder.h"
+
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Pln.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Vertex.h>
-#include <BRepBuilderAPI_MakeVertex.hxx>
+
 #include <BRep_Tool.hxx>
-#include <TopoDS_Vertex.hxx>
-#include <TopoDS.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <gp_Pln.hxx>
 #include <gp_Pnt.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
 
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
-    std::shared_ptr<GeomAPI_Pnt> thePoint)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint)
 {
   const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
   BRepBuilderAPI_MakeVertex aMaker(aPnt);
@@ -25,8 +33,10 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
   return aRes;
 }
 
-std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
-    const double theX, const double theY, const double theZ)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const double theX,
+                                                                 const double theY,
+                                                                 const double theZ)
 {
   const gp_Pnt aPnt(theX, theY, theZ);
   BRepBuilderAPI_MakeVertex aMaker(aPnt);
@@ -36,7 +46,8 @@ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_PointBuilder::point(
   return aRes;
 }
 
-std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(std::shared_ptr<GeomAPI_Shape> theVertex)
+//==================================================================================================
+std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(const std::shared_ptr<GeomAPI_Shape> theVertex)
 {
   TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
   if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
@@ -47,3 +58,73 @@ std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(std::shared_ptr<Geo
   }
   return std::shared_ptr<GeomAPI_Pnt>();
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
+                                                                       const double theValue,
+                                                                       const bool theIsPercent,
+                                                                       const bool theIsReverse)
+{
+  if(!theEdge.get()) {
+    return NULL;
+  }
+
+  double aValue = theValue;
+  if(theIsPercent) {
+    aValue = theEdge->length() / 100.0 * aValue;
+  }
+
+  const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+  Standard_Real aUFirst, aULast;
+  Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
+
+  std::shared_ptr<GeomAPI_Vertex> aVertex;
+  if(!anEdgeCurve.IsNull() ) {
+    Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
+
+    if(theIsReverse) {
+      aReOrientedCurve = anEdgeCurve->Reversed();
+      aUFirst = anEdgeCurve->ReversedParameter(aULast);
+    }
+
+    // Get the point by length
+    GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
+    GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
+    Standard_Real aParam = anAbsPnt.Parameter();
+    gp_Pnt aPnt = anAdapCurve.Value(aParam);
+    BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
+    const TopoDS_Vertex& aShape = aMkVertex.Vertex();
+    aVertex.reset(new GeomAPI_Vertex());
+    aVertex->setImpl(new TopoDS_Vertex(aShape));
+  }
+
+  return aVertex;
+}
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
+    const std::shared_ptr<GeomAPI_Vertex> theVertex,
+    const std::shared_ptr<GeomAPI_Face> thePlane)
+{
+  if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) {
+    return NULL;
+  }
+
+  std::shared_ptr<GeomAPI_Pnt> aGeomPnt = theVertex->point();
+  gp_Pnt aPnt = aGeomPnt->impl<gp_Pnt>();
+
+  std::shared_ptr<GeomAPI_Pln> aGeomPln = thePlane->getPlane();
+  gp_Pln aPln = aGeomPln->impl<gp_Pln>();
+
+  gp_Dir aPntAxis = aPnt.XYZ() - aPln.Location().XYZ();
+  gp_Dir aPlnNorm = aPln.Axis().Direction();
+
+  if(aPntAxis * aPlnNorm > 0) {
+    aPlnNorm.Reverse();
+  }
+
+  double aDistance = aPln.Distance(aPnt);
+  aPnt.Translate(gp_Vec(aPlnNorm) * aDistance);
+
+  return std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aPnt.X(), aPnt.Y(), aPnt.Z()));
+}
index cff50ee0561cdb35becd322c685e9b99f907e5f7..906a2814febbc8effdf2e1f35109b3d6d0ccf5d2 100644 (file)
 #include <GeomAlgoAPI.h>
 #include <memory>
 
-class GeomAPI_Shape;
+class GeomAPI_Edge;
+class GeomAPI_Face;
 class GeomAPI_Pnt;
+class GeomAPI_Shape;
+class GeomAPI_Vertex;
 
-/**\class GeomAlgoAPI_PointBuilder
- * \ingroup DataAlgo
- * \brief Allows to create face-shapes by different parameters
- */
-
+/// \class GeomAlgoAPI_PointBuilder
+/// \ingroup DataAlgo
+/// \brief Allows to create vertex-shapes by different parameters
 class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder
 {
- public:
-  /// Creates a shape by point
-  static std::shared_ptr<GeomAPI_Shape> point(std::shared_ptr<GeomAPI_Pnt> thePoint);
-
-  /// Creates a shape by point coordinates
-  static std::shared_ptr<GeomAPI_Shape> point(
-    const double theX, const double theY, const double theZ);
+public:
+  /// Creates a vertex by point
+  static std::shared_ptr<GeomAPI_Vertex> vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint);
+
+  /// Creates a vertex by point coordinates
+  static std::shared_ptr<GeomAPI_Vertex> vertex(const double theX,
+                                                const double theY,
+                                                const double theZ);
+
+  /// \brief Creates vertex by edge and distance on it.
+  /// \param[in] theEdge edge.
+  /// \param[in] theValue distance value.
+  /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length.
+  /// \param[in] theIsReverse if true the distance will be measured from the edge end point.
+  /// \return created vertex.
+  static std::shared_ptr<GeomAPI_Vertex> vertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
+                                                      const double theValue,
+                                                      const bool theIsPercent = false,
+                                                      const bool theIsReverse = false);
+
+  /// \brief Creates vertex by projection another vertex on plane.
+  /// \param[in] theVertex vertex to project.
+  /// \param[in] thePlane face for projection. Should be planar.
+  /// \return created vertex.
+  static std::shared_ptr<GeomAPI_Vertex> vertexByProjection(const std::shared_ptr<GeomAPI_Vertex> theVertex,
+                                                            const std::shared_ptr<GeomAPI_Face> thePlane);
 
   /// Return point by shape vertex
-  static std::shared_ptr<GeomAPI_Pnt> point(std::shared_ptr<GeomAPI_Shape> theVertex);
+  static std::shared_ptr<GeomAPI_Pnt> point(const std::shared_ptr<GeomAPI_Shape> theVertex);
 };
 
 #endif
index 029743117c77fbd33550558955e1d989b3782406..a40aff14e34b60c4ceae641285ee1753fab8c3cd 100644 (file)
@@ -8,9 +8,9 @@
 
 #include "GeomAlgoAPI_SketchBuilder.h"
 
+#include <GeomAPI_Edge.h>
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_Face.h>
-#include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_Pnt.h>
 
 #include <BRepAlgo_FaceRestrictor.hxx>
 #include <BRepBndLib.hxx>
 #include <BRepBuilderAPI_FindPlane.hxx>
-#include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
-#include <BRepBuilderAPI_MakeVertex.hxx>
 #include <BRepCheck_Analyzer.hxx>
 #include <BRepExtrema_DistShapeShape.hxx>
 #include <BRepExtrema_ExtCF.hxx>
 #include <BRepGProp.hxx>
 #include <BRepTools.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
-#include <GCPnts_AbscissaPoint.hxx>
-#include <Geom_Curve.hxx>
 #include <Geom2d_Curve.hxx>
+#include <Handle_Geom2d_Curve.hxx>
 #include <BRepLib_CheckCurveOnSurface.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom_Plane.hxx>
 #include <GeomLib_IsPlanarSurface.hxx>
 #include <GeomLib_Tool.hxx>
-#include <GeomProjLib.hxx>
 #include <gp_Pln.hxx>
 #include <GProp_GProps.hxx>
 #include <IntAna_IntConicQuad.hxx>
@@ -667,46 +663,3 @@ bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr<GeomAPI_Edge> theE
   BRepExtrema_ExtCF anExt(anEdge, aFace);
   return anExt.IsParallel() == Standard_True;
 }
-
-//==================================================================================================
-std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_ShapeTools::findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
-                                                                         const double theValue,
-                                                                         const bool theIsPercent,
-                                                                         const bool theIsReverse)
-{
-  std::shared_ptr<GeomAPI_Vertex> aVertex;
-
-  if(!theEdge.get()) {
-    return aVertex;
-  }
-
-  double aValue = theValue;
-  if(theIsPercent) {
-    aValue = theEdge->length() / 100.0 * aValue;
-  }
-
-  const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
-  Standard_Real aUFirst, aULast;
-  Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
-
-  if(!anEdgeCurve.IsNull() ) {
-    Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
-
-    if(theIsReverse) {
-      aReOrientedCurve = anEdgeCurve->Reversed();
-      aUFirst = anEdgeCurve->ReversedParameter(aULast);
-    }
-
-    // Get the point by length
-    GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
-    GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
-    Standard_Real aParam = anAbsPnt.Parameter();
-    gp_Pnt aPnt = anAdapCurve.Value(aParam);
-    BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
-    const TopoDS_Vertex& aShape = aMkVertex.Vertex();
-    aVertex.reset(new GeomAPI_Vertex());
-    aVertex->setImpl(new TopoDS_Vertex(aShape));
-  }
-
-  return aVertex;
-}
index f1814c750d873fe10bdcf840c312b4d29d2c4108..95a97f0bbaef960234118ff5a60af6565a3a5a08 100644 (file)
@@ -102,18 +102,6 @@ public:
   /// \return true if edge is parallel to face.
   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
                                             const std::shared_ptr<GeomAPI_Face> theFace);
-
-  /// \brief Creates vertex by edge and distance on it.
-  /// \param[in] theEdge edge.
-  /// \param[in] theValue distance value.
-  /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length.
-  /// \param[in] theIsReverse if true the distance will be measured from the edge end point.
-  /// \ return created vertex.
-  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Vertex> findVertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
-                                                                             const double theValue,
-                                                                             const bool theIsPercent = false,
-                                                                             const bool theIsReverse = false);
-
 };
 
 #endif
index 7cf3c0ddfe73a25f6270a535bd99a3b36504a457..be3f9e56862aa325020ff6555f2c14fa222178bc 100644 (file)
@@ -29,6 +29,7 @@
 #include <GeomAPI_Lin2d.h>
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Vertex.h>
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
@@ -119,7 +120,7 @@ void SketchPlugin_Arc::execute()
 
     std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
     // make a visible point
-    std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+    std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
     std::shared_ptr<ModelAPI_ResultConstruction> aConstr1 = document()->createConstruction(
         data(), 0);
     aConstr1->setShape(aCenterPointShape);
@@ -242,7 +243,7 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
           }
         }
         // make a visible point
-        std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+        std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
         aShapes.push_back(aCenterPointShape);
       }
       if (!aShapes.empty()) {
index 9c9a78c6e10ca1b916c2a1c9cc7cfbc3583a9703..ccb1a6efe0ba58991c853535229a022c4d67b408 100644 (file)
@@ -17,6 +17,7 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Circ.h>
 #include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Vertex.h>
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
@@ -122,7 +123,7 @@ AISObjectPtr SketchPlugin_Circle::getAISObject(AISObjectPtr thePrevious)
         if (aCircleShape && aRadius != 0) {
           std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
           // make a visible point
-          std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+          std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
           aShapes.push_back(aCenterPointShape);
           aShapes.push_back(aCircleShape);
 
index 17dbb0a3fe63e4ac097c687e09664a554938b684..afa84bf135efa5993c0762f1e1e3662640abf25c 100644 (file)
@@ -42,7 +42,7 @@ void SketchPlugin_Point::execute()
             data()->attribute(SketchPlugin_Point::COORD_ID()));
     std::shared_ptr<GeomAPI_Pnt> aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y()));
     // make a visible point
-    std::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D);
+    std::shared_ptr<GeomAPI_Shape> aPointShape = GeomAlgoAPI_PointBuilder::vertex(aPoint3D);
     std::shared_ptr<ModelAPI_ResultConstruction> aConstr = document()->createConstruction(data());
     aConstr->setShape(aPointShape);
     aConstr->setIsInHistory(false);
index debbfbb336b6bb47607c08e4212cf0a1661a95b7..22b3257ef7e9ca73b3db750d1555158bacd2efd0 100755 (executable)
@@ -11,6 +11,7 @@
 
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_Vertex.h>
 
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAlgoAPI_PointBuilder.h>
@@ -272,7 +273,7 @@ void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature,
   std::shared_ptr<GeomAPI_Pnt> aCenter(theSketch->to3D(aPoint->x(), aPoint->y()));
   //std::cout<<"Execute circle "<<aCenter->x()<<" "<<aCenter->y()<<" "<<aCenter->z()<<std::endl;
   // make a visible point
-  std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+  std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter);
   std::shared_ptr<ModelAPI_ResultConstruction> aResult = theFeature->document()->createConstruction(
                      theFeature->data(), theIndex);
   aResult->setShape(aCenterPointShape);