]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
2.3.3.1 Point creation by projection of another point on a line
authordbv <dbv@opencascade.com>
Wed, 27 Jun 2018 14:18:57 +0000 (17:18 +0300)
committerdbv <dbv@opencascade.com>
Wed, 27 Jun 2018 14:19:16 +0000 (17:19 +0300)
12 files changed:
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_ProjectOnEdge.py [new file with mode: 0644]
src/ConstructionPlugin/icons/point_by_projection_on_edge_32x32.png [new file with mode: 0644]
src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png [deleted file]
src/ConstructionPlugin/point_widget.xml
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp
src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h
src/ModelHighAPI/ModelHighAPI_Macro.h

index ca427fe7de5930e12a5b2c886d5afd58384d0180..350c8857e8c483e6183390f2bd0b443d35c6b47b 100644 (file)
@@ -70,7 +70,10 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr<ModelAPI_Feat
     if(aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::FACE) {
       // If first object is vertex and second object is face then set by projection.
       setByProjectionOnFace(theObject1, theObject2);
-    } /*else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
+    } else if (aType1 == GeomAPI_Shape::VERTEX && aType2 == GeomAPI_Shape::EDGE) {
+      // If first object is vertex and second object is edge then set by projection.
+      setByProjectionOnEdge(theObject1, theObject2);
+    } /* else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::EDGE) {
       // If both objects are edges then set by lines intersection.
       setByLinesIntersection(theObject1, theObject2);
     } */ else if(aType1 == GeomAPI_Shape::EDGE && aType2 == GeomAPI_Shape::FACE) {
@@ -121,6 +124,18 @@ void ConstructionAPI_Point::setByOffsetOnEdge(const ModelHighAPI_Selection& theE
   execute();
 }
 
+//==================================================================================================
+void ConstructionAPI_Point::setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
+                                                  const ModelHighAPI_Selection& theEdge)
+{
+  fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE(),
+                mycreationMethod);
+  fillAttribute(theVertex, mypoinToProjectOnEdge);
+  fillAttribute(theEdge, myedgeForPointProjection);
+
+  execute();
+}
+
 //==================================================================================================
 void ConstructionAPI_Point::setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
                                                   const ModelHighAPI_Selection& theFace)
@@ -185,6 +200,8 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const
       theDumper << ratio() << ", " << true;
     }
     theDumper << ", " << reverse()->value();
+  } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_EDGE()) {
+    theDumper << mypoinToProjectOnEdge << ", " << myedgeForPointProjection;
   } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE()) {
     theDumper << mypoinToProjectOnFace << ", " << myfaceForPointProjection;
   }
index 7e412a2f499a78ea2fd0f57fe0df931f63ae8d90..f028db1929174942ce4ccf0b157515549298c67e 100644 (file)
@@ -67,7 +67,7 @@ public:
   CONSTRUCTIONAPI_EXPORT
   virtual ~ConstructionAPI_Point();
 
-  INTERFACE_16(ConstructionPlugin_Point::ID(),
+  INTERFACE_18(ConstructionPlugin_Point::ID(),
                x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */,
                y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */,
                z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */,
@@ -96,7 +96,11 @@ public:
                poinToProjectOnFace, ConstructionPlugin_Point::POINT_TO_PROJECT_ON_FACE(),
                ModelAPI_AttributeSelection, /** Point to project on face */,
                faceForPointProjection, ConstructionPlugin_Point::FACE_FOR_POINT_PROJECTION(),
-               ModelAPI_AttributeSelection, /** Face for point projection */)
+               ModelAPI_AttributeSelection, /** Face for point projection */,
+               poinToProjectOnEdge, ConstructionPlugin_Point::POINT_TO_PROJECT_ON_EDGE(),
+               ModelAPI_AttributeSelection, /** Point to project on edge */,
+               edgeForPointProjection, ConstructionPlugin_Point::EDGE_FOR_POINT_PROJECTION(),
+               ModelAPI_AttributeSelection, /** Edge for point projection */)
 
 
   /// Set point values.
@@ -112,7 +116,12 @@ public:
                          const bool theUseRatio = false,
                          const bool theReverse = false);
 
-  /// Set point and plane for projection.
+  /// Set point and edge for projection.
+  CONSTRUCTIONAPI_EXPORT
+  void setByProjectionOnEdge(const ModelHighAPI_Selection& theVertex,
+                             const ModelHighAPI_Selection& theEdge);
+
+  /// Set point and face for projection.
   CONSTRUCTIONAPI_EXPORT
   void setByProjectionOnFace(const ModelHighAPI_Selection& theVertex,
                              const ModelHighAPI_Selection& theFace);
index f374cc0e6c9961951dc1b8c2330dd30266572678..e9c42f29915aafe3a676bbff5ed45aeab07798dd 100644 (file)
@@ -80,6 +80,7 @@ ADD_UNIT_TESTS(TestAxisCreation.py
                TestPoint_XYZ.py
                TestPoint_LineAndPlane.py
                TestPoint_Edge.py
+               TestPoint_ProjectOnEdge.py
                TestPoint_ProjectOnFace.py
                TestPointName.py
                TestPlane.py)
index ee86684379ef1b211db52a43548f1d2fe6a3c293..60b0af1c56b534fc677a4a609792c0215c320876 100644 (file)
@@ -73,6 +73,9 @@ void ConstructionPlugin_Point::initAttributes()
   data()->addAttribute(RATIO(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId());
 
+  data()->addAttribute(POINT_TO_PROJECT_ON_EDGE(), ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(EDGE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId());
+
   data()->addAttribute(POINT_TO_PROJECT_ON_FACE(), ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(FACE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId());
 }
@@ -90,6 +93,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_ON_EDGE()) {
+    aShape = createByProjectionOnEdge();
   } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION_ON_FACE()) {
     aShape = createByProjectionOnFace();
   } /* else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) {
@@ -169,6 +174,28 @@ std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByDistanceOnEdge
   return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse);
 }
 
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjectionOnEdge()
+{
+  // Get point.
+  AttributeSelectionPtr aPointSelection = selection(POINT_TO_PROJECT_ON_EDGE());
+  GeomShapePtr aPointShape = aPointSelection->value();
+  if (!aPointShape.get()) {
+    aPointShape = aPointSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aPointShape));
+
+  // Get edge.
+  AttributeSelectionPtr anEdgeSelection = selection(EDGE_FOR_POINT_PROJECTION());
+  GeomShapePtr anEdgeShape = anEdgeSelection->value();
+  if (!anEdgeShape.get()) {
+    anEdgeShape = anEdgeSelection->context()->shape();
+  }
+  std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(anEdgeShape));
+
+  return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, anEdge);
+}
+
 //==================================================================================================
 std::shared_ptr<GeomAPI_Vertex> ConstructionPlugin_Point::createByProjectionOnFace()
 {
index a5f84a6d39db0d33217a8a8059f8d3dcf72c840a..4be62ccde80539d8e505d540bd8aea1d6b89765b 100644 (file)
@@ -68,6 +68,13 @@ public:
     return MY_CREATION_METHOD_ID;
   }
 
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD_BY_PROJECTION_ON_EDGE()
+  {
+    static const std::string MY_CREATION_METHOD_ID("by_projection_on_edge");
+    return MY_CREATION_METHOD_ID;
+  }
+
   /// Attribute name for creation method.
   inline static const std::string& CREATION_METHOD_BY_PROJECTION_ON_FACE()
   {
@@ -161,6 +168,20 @@ public:
     return ATTR_ID;
   }
 
+  /// Attribute name for point to project on edge.
+  inline static const std::string& POINT_TO_PROJECT_ON_EDGE()
+  {
+    static const std::string ATTR_ID("point_to_project_on_edge");
+    return ATTR_ID;
+  }
+
+  /// Attribute name for edge for point projection.
+  inline static const std::string& EDGE_FOR_POINT_PROJECTION()
+  {
+    static const std::string ATTR_ID("edge_for_point_projection");
+    return ATTR_ID;
+  }
+
   /// Attribute name for point to project on surface.
   inline static const std::string& POINT_TO_PROJECT_ON_FACE()
   {
@@ -245,6 +266,7 @@ public:
 private:
   std::shared_ptr<GeomAPI_Vertex> createByXYZ();
   std::shared_ptr<GeomAPI_Vertex> createByDistanceOnEdge();
+  std::shared_ptr<GeomAPI_Vertex> createByProjectionOnEdge();
   std::shared_ptr<GeomAPI_Vertex> createByProjectionOnFace();
   /*std::shared_ptr<GeomAPI_Vertex> createByLinesIntersection();*/
   std::list<std::shared_ptr<GeomAPI_Vertex> > createByLineAndPlaneIntersection();
diff --git a/src/ConstructionPlugin/Test/TestPoint_ProjectOnEdge.py b/src/ConstructionPlugin/Test/TestPoint_ProjectOnEdge.py
new file mode 100644 (file)
index 0000000..2cc5ecf
--- /dev/null
@@ -0,0 +1,50 @@
+## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+##
+## 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, or (at your option) any later version.
+##
+## 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<mailto:webmaster.salome@opencascade.com>
+##
+
+"""
+Test case for Construction Point feature by coordinates.
+"""
+
+from salome.shaper import model
+from GeomAPI import *
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchCircle_1 = Sketch_1.addCircle(0, 0, 100)
+SketchPoint_1 = Sketch_1.addPoint(100, 100)
+model.do()
+Box_1 = model.addBox(Part_1_doc, 50, 50, 50)
+Point_2 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("EDGE", "Sketch_1/Edge-SketchCircle_1_2"))
+Point_3 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("EDGE", "Box_1_1/Front&Box_1_1/Right"))
+model.do()
+model.end()
+
+assert (len(Point_2.results()) > 0)
+rightPosition = GeomAPI_Vertex(70.7106781187, 70.7106781187, 0)
+assert(rightPosition.isEqual(Point_2.results()[0].resultSubShapePair()[0].shape()))
+
+assert (len(Point_3.results()) > 0)
+rightPosition = GeomAPI_Vertex(50, 50, 0)
+assert(rightPosition.isEqual(Point_4.results()[0].resultSubShapePair()[0].shape()))
+
+assert(model.checkPythonDump())
diff --git a/src/ConstructionPlugin/icons/point_by_projection_on_edge_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_on_edge_32x32.png
new file mode 100644 (file)
index 0000000..187864f
Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_projection_on_edge_32x32.png differ
diff --git a/src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png
deleted file mode 100644 (file)
index 187864f..0000000
Binary files a/src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png and /dev/null differ
index 5db2d6657a2fab3a7b33395f0c0f0905651ed9df..55e09a75925b8449330977f818b1d9d0a5f334c7 100644 (file)
@@ -82,6 +82,23 @@ email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com
            tooltip="Distance from edge end point."
            default="false"/>
     </box>
+    <box id="by_projection_on_edge"
+         title="By projection on edge"
+         tooltip="Point on edge by projection selected point."
+         icon="icons/Construction/point_by_projection_on_edge_32x32.png">
+      <shape_selector id="point_to_project_on_edge"
+                      label="Point"
+                      tooltip="Point for projection."
+                      icon="icons/Construction/point.png"
+                      shape_types="vertex">
+      </shape_selector>
+      <shape_selector id="edge_for_point_projection"
+                      label="edge"
+                      tooltip="Edge for projection."
+                      icon="icons/Construction/edge.png"
+                      shape_types="edge">
+      </shape_selector>
+    </box>
     <box id="by_projection_on_face"
          title="By projection on face"
          tooltip="Point on face surface by projection selected point."
index c46bfd364bb27658b4856932e950d389cd2fa042..ce7be932c4557724520697e7176ff191817a03d1 100644 (file)
 #include <Geom_Line.hxx>
 #include <GeomAdaptor_Curve.hxx>
 #include <GeomAPI_ExtremaCurveCurve.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <gp_Pln.hxx>
 #include <gp_Pnt.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
 #include <TopoDS_Vertex.hxx>
 
 //==================================================================================================
@@ -122,6 +124,41 @@ std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(
   return aVertex;
 }
 
+//==================================================================================================
+std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
+  const std::shared_ptr<GeomAPI_Vertex> theVertex,
+  const std::shared_ptr<GeomAPI_Edge> theEdge)
+{
+  std::shared_ptr<GeomAPI_Vertex> aVertex;
+
+  if (!theVertex.get() || !theEdge.get()) {
+    return aVertex;
+  }
+
+  std::shared_ptr<GeomAPI_Pnt> aProjPnt = theVertex->point();
+  gp_Pnt aPnt(aProjPnt->x(), aProjPnt->y(), aProjPnt->z());
+
+  TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
+  double aFirstOnCurve, aLastOnCurve;
+  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, aFirstOnCurve, aLastOnCurve);
+
+  if (aCurve.IsNull()) {
+    return aVertex;
+  }
+
+  GeomAPI_ProjectPointOnCurve aProjection(aPnt, aCurve);
+
+  if (aProjection.NbPoints() == 0) {
+    return aVertex;
+  }
+
+  gp_Pnt aNearestPoint = aProjection.NearestPoint();
+
+  aVertex.reset(new GeomAPI_Vertex(aNearestPoint.X(), aNearestPoint.Y(), aNearestPoint.Z()));
+
+  return aVertex;
+}
+
 //==================================================================================================
 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
     const std::shared_ptr<GeomAPI_Vertex> theVertex,
index 2d59a12636d183c2cc62c8154ea929e0734a53c9..f75ecd2ab5c2d8eb3568be8827c51d7f8cd5305e 100644 (file)
@@ -56,6 +56,14 @@ public:
                                                       const bool theIsPercent = false,
                                                       const bool theIsReverse = false);
 
+  /// \brief Creates vertex by projection another vertex on edge.
+  /// \param[in] theVertex vertex to project.
+  /// \param[in] theEdge edge for projection.
+  /// \return created vertex.
+  static std::shared_ptr<GeomAPI_Vertex>
+    vertexByProjection(const std::shared_ptr<GeomAPI_Vertex> theVertex,
+    const std::shared_ptr<GeomAPI_Edge> theEdge);
+
   /// \brief Creates vertex by projection another vertex on plane.
   /// \param[in] theVertex vertex to project.
   /// \param[in] theFace face for projection. Should be planar.
index 40417def5f1d61fea68cc3ca00c4f8d6ee10f91e..a03e9e72d85e5a0cf6fcce36deeeaf79e7e6a29a 100644 (file)
     END_INIT() \
   public:
 
+//--------------------------------------------------------------------------------------
+#define INTERFACE_18(KIND, \
+                     N_0, AN_0, T_0, C_0, \
+                     N_1, AN_1, T_1, C_1, \
+                     N_2, AN_2, T_2, C_2, \
+                     N_3, AN_3, T_3, C_3, \
+                     N_4, AN_4, T_4, C_4, \
+                     N_5, AN_5, T_5, C_5, \
+                     N_6, AN_6, T_6, C_6, \
+                     N_7, AN_7, T_7, C_7, \
+                     N_8, AN_8, T_8, C_8, \
+                     N_9, AN_9, T_9, C_9, \
+                     N_10, AN_10, T_10, C_10, \
+                     N_11, AN_11, T_11, C_11, \
+                     N_12, AN_12, T_12, C_12, \
+                     N_13, AN_13, T_13, C_13, \
+                     N_14, AN_14, T_14, C_14, \
+                     N_15, AN_15, T_15, C_15, \
+                     N_16, AN_16, T_16, C_16, \
+                     N_17, AN_17, T_17, C_17) \
+  public: \
+    INTERFACE_COMMON(KIND) \
+    DEFINE_ATTRIBUTE(N_0, T_0, C_0) \
+    DEFINE_ATTRIBUTE(N_1, T_1, C_1) \
+    DEFINE_ATTRIBUTE(N_2, T_2, C_2) \
+    DEFINE_ATTRIBUTE(N_3, T_3, C_3) \
+    DEFINE_ATTRIBUTE(N_4, T_4, C_4) \
+    DEFINE_ATTRIBUTE(N_5, T_5, C_5) \
+    DEFINE_ATTRIBUTE(N_6, T_6, C_6) \
+    DEFINE_ATTRIBUTE(N_7, T_7, C_7) \
+    DEFINE_ATTRIBUTE(N_8, T_8, C_8) \
+    DEFINE_ATTRIBUTE(N_9, T_9, C_9) \
+    DEFINE_ATTRIBUTE(N_10, T_10, C_10) \
+    DEFINE_ATTRIBUTE(N_11, T_11, C_11) \
+    DEFINE_ATTRIBUTE(N_12, T_12, C_12) \
+    DEFINE_ATTRIBUTE(N_13, T_13, C_13) \
+    DEFINE_ATTRIBUTE(N_14, T_14, C_14) \
+    DEFINE_ATTRIBUTE(N_15, T_15, C_15) \
+    DEFINE_ATTRIBUTE(N_16, T_16, C_16) \
+    DEFINE_ATTRIBUTE(N_17, T_17, C_17) \
+  protected: \
+    START_INIT() \
+      SET_ATTRIBUTE(N_0, T_0, AN_0) \
+      SET_ATTRIBUTE(N_1, T_1, AN_1) \
+      SET_ATTRIBUTE(N_2, T_2, AN_2) \
+      SET_ATTRIBUTE(N_3, T_3, AN_3) \
+      SET_ATTRIBUTE(N_4, T_4, AN_4) \
+      SET_ATTRIBUTE(N_5, T_5, AN_5) \
+      SET_ATTRIBUTE(N_6, T_6, AN_6) \
+      SET_ATTRIBUTE(N_7, T_7, AN_7) \
+      SET_ATTRIBUTE(N_8, T_8, AN_8) \
+      SET_ATTRIBUTE(N_9, T_9, AN_9) \
+      SET_ATTRIBUTE(N_10, T_10, AN_10) \
+      SET_ATTRIBUTE(N_11, T_11, AN_11) \
+      SET_ATTRIBUTE(N_12, T_12, AN_12) \
+      SET_ATTRIBUTE(N_13, T_13, AN_13) \
+      SET_ATTRIBUTE(N_14, T_14, AN_14) \
+      SET_ATTRIBUTE(N_15, T_15, AN_15) \
+      SET_ATTRIBUTE(N_16, T_16, AN_16) \
+      SET_ATTRIBUTE(N_17, T_17, AN_17) \
+    END_INIT() \
+  public:
+
 //--------------------------------------------------------------------------------------
 #define INTERFACE_20(KIND, \
                      N_0, AN_0, T_0, C_0, \