From 3f02f2a44e42c854cb2b64c9817436e5a27788ab Mon Sep 17 00:00:00 2001 From: dbv Date: Wed, 27 Jun 2018 17:18:57 +0300 Subject: [PATCH] 2.3.3.1 Point creation by projection of another point on a line --- src/ConstructionAPI/ConstructionAPI_Point.cpp | 19 +++++- src/ConstructionAPI/ConstructionAPI_Point.h | 15 ++++- src/ConstructionPlugin/CMakeLists.txt | 1 + .../ConstructionPlugin_Point.cpp | 27 ++++++++ .../ConstructionPlugin_Point.h | 22 ++++++ .../Test/TestPoint_ProjectOnEdge.py | 50 ++++++++++++++ ... => point_by_projection_on_edge_32x32.png} | Bin src/ConstructionPlugin/point_widget.xml | 17 +++++ src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp | 37 ++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h | 8 +++ src/ModelHighAPI/ModelHighAPI_Macro.h | 63 ++++++++++++++++++ 11 files changed, 255 insertions(+), 4 deletions(-) create mode 100644 src/ConstructionPlugin/Test/TestPoint_ProjectOnEdge.py rename src/ConstructionPlugin/icons/{point_by_projection_on_line_32x32.png => point_by_projection_on_edge_32x32.png} (100%) diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index ca427fe7d..350c8857e 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -70,7 +70,10 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptrvalue(); + } 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; } diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index 7e412a2f4..f028db192 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -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); diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index f374cc0e6..e9c42f299 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -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) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index ee8668437..60b0af1c5 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -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 ConstructionPlugin_Point::createByDistanceOnEdge return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse); } +//================================================================================================== +std::shared_ptr 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 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 anEdge(new GeomAPI_Edge(anEdgeShape)); + + return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, anEdge); +} + //================================================================================================== std::shared_ptr ConstructionPlugin_Point::createByProjectionOnFace() { diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index a5f84a6d3..4be62ccde 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -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 createByXYZ(); std::shared_ptr createByDistanceOnEdge(); + std::shared_ptr createByProjectionOnEdge(); std::shared_ptr createByProjectionOnFace(); /*std::shared_ptr createByLinesIntersection();*/ std::list > createByLineAndPlaneIntersection(); diff --git a/src/ConstructionPlugin/Test/TestPoint_ProjectOnEdge.py b/src/ConstructionPlugin/Test/TestPoint_ProjectOnEdge.py new file mode 100644 index 000000000..2cc5ecf09 --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPoint_ProjectOnEdge.py @@ -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 +## + +""" +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_line_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_on_edge_32x32.png similarity index 100% rename from src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png rename to src/ConstructionPlugin/icons/point_by_projection_on_edge_32x32.png diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 5db2d6657..55e09a759 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -82,6 +82,23 @@ email : webmaster.salome@opencascade.com + + + + + + #include #include +#include #include #include #include +#include #include //================================================================================================== @@ -122,6 +124,41 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::vertexOnEdge( return aVertex; } +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByProjection( + const std::shared_ptr theVertex, + const std::shared_ptr theEdge) +{ + std::shared_ptr aVertex; + + if (!theVertex.get() || !theEdge.get()) { + return aVertex; + } + + std::shared_ptr aProjPnt = theVertex->point(); + gp_Pnt aPnt(aProjPnt->x(), aProjPnt->y(), aProjPnt->z()); + + TopoDS_Edge anEdge = TopoDS::Edge(theEdge->impl()); + 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 GeomAlgoAPI_PointBuilder::vertexByProjection( const std::shared_ptr theVertex, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h index 2d59a1263..f75ecd2ab 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h @@ -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 + vertexByProjection(const std::shared_ptr theVertex, + const std::shared_ptr 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. diff --git a/src/ModelHighAPI/ModelHighAPI_Macro.h b/src/ModelHighAPI/ModelHighAPI_Macro.h index 40417def5..a03e9e72d 100644 --- a/src/ModelHighAPI/ModelHighAPI_Macro.h +++ b/src/ModelHighAPI/ModelHighAPI_Macro.h @@ -546,6 +546,69 @@ 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, \ -- 2.30.2