From ea6a38a23418dfbc8eed24f70e52ef3ca8e9f4c4 Mon Sep 17 00:00:00 2001 From: dbv Date: Tue, 26 Jun 2018 21:34:29 +0300 Subject: [PATCH] 2.3.3.2 Point creation by projection of another point on a plane --- src/ConstructionAPI/ConstructionAPI_Point.cpp | 32 +++++----- src/ConstructionAPI/ConstructionAPI_Point.h | 15 +++-- src/ConstructionPlugin/CMakeLists.txt | 1 + .../ConstructionPlugin_Point.cpp | 23 +++---- .../ConstructionPlugin_Point.h | 24 ++++---- .../Test/TestPoint_ProjectOnFace.py | 49 +++++++++++++++ ... => point_by_projection_on_face_32x32.png} | Bin .../point_by_projection_on_line_32x32.png | Bin 0 -> 812 bytes src/ConstructionPlugin/point_widget.xml | 16 ++--- src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp | 6 +- src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h | 4 +- src/ModelHighAPI/ModelHighAPI_Macro.h | 57 ++++++++++++++++++ 12 files changed, 171 insertions(+), 56 deletions(-) create mode 100644 src/ConstructionPlugin/Test/TestPoint_ProjectOnFace.py rename src/ConstructionPlugin/icons/{point_by_projection_32x32.png => point_by_projection_on_face_32x32.png} (100%) create mode 100644 src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 8d045791f..ca427fe7d 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -67,14 +67,13 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptrvalue().empty()) { // call method with defined offset theDumper << ", " << offset() << ", " << reverseOffset(); } - theDumper << ")" << std::endl; - } - else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) { + } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_DISTANCE_ON_EDGE()) { theDumper << edge() << ", "; if (offsetType()->value() == ConstructionPlugin_Point::OFFSET_TYPE_BY_DISTANCE()) { theDumper << distance() << ", " << false; @@ -186,8 +184,12 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const else { theDumper << ratio() << ", " << true; } - theDumper << ", " << reverse()->value() << ")" << std::endl; + theDumper << ", " << reverse()->value(); + } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION_ON_FACE()) { + theDumper << mypoinToProjectOnFace << ", " << myfaceForPointProjection; } + + theDumper << ")" << std::endl; } //================================================================================================== diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index 087ea95e8..7e412a2f4 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -67,7 +67,7 @@ public: CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Point(); - INTERFACE_14(ConstructionPlugin_Point::ID(), + INTERFACE_16(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 */, @@ -92,7 +92,11 @@ public: ratio, ConstructionPlugin_Point::RATIO(), ModelAPI_AttributeDouble, /** Ratio */, reverse, ConstructionPlugin_Point::REVERSE(), - ModelAPI_AttributeBoolean, /** Reverse */) + ModelAPI_AttributeBoolean, /** Reverse */, + 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 */) /// Set point values. @@ -108,17 +112,18 @@ public: const bool theUseRatio = false, const bool theReverse = false); - /* /// Set point and plane for projection. CONSTRUCTIONAPI_EXPORT - void setByProjection(const ModelHighAPI_Selection& theVertex, - const ModelHighAPI_Selection& theFace); + void setByProjectionOnFace(const ModelHighAPI_Selection& theVertex, + const ModelHighAPI_Selection& theFace); + /* /// Set lines for intersections. CONSTRUCTIONAPI_EXPORT void setByLinesIntersection(const ModelHighAPI_Selection& theEdge1, const ModelHighAPI_Selection& theEdge2); */ + /// Set line and plane for intersections. CONSTRUCTIONAPI_EXPORT void setByLineAndPlaneIntersection(const ModelHighAPI_Selection& theEdge, diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index 11cfdcedc..f374cc0e6 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -80,5 +80,6 @@ ADD_UNIT_TESTS(TestAxisCreation.py TestPoint_XYZ.py TestPoint_LineAndPlane.py TestPoint_Edge.py + TestPoint_ProjectOnFace.py TestPointName.py TestPlane.py) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 2081f4ed1..ee8668437 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -56,9 +56,6 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); /* - data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(FIRST_LINE(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(SECOND_LINE(), ModelAPI_AttributeSelection::typeId()); */ @@ -75,6 +72,9 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(RATIO(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(POINT_TO_PROJECT_ON_FACE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(FACE_FOR_POINT_PROJECTION(), ModelAPI_AttributeSelection::typeId()); } //================================================================================================== @@ -90,11 +90,11 @@ 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(); - } else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) { + } else if(aCreationMethod == CREATION_METHOD_BY_PROJECTION_ON_FACE()) { + aShape = createByProjectionOnFace(); + } /* else if(aCreationMethod == CREATION_METHOD_BY_LINES_INTERSECTION()) { aShape = createByLinesIntersection(); - }*/ else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { + } */ else if(aCreationMethod == CREATION_METHOD_BY_LINE_AND_PLANE_INTERSECTION()) { // this may produce several points std::list > aPoints = createByLineAndPlaneIntersection(); if (!aPoints.empty()) { // if no points found produce the standard error later @@ -168,12 +168,12 @@ std::shared_ptr ConstructionPlugin_Point::createByDistanceOnEdge return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse); } -/* + //================================================================================================== -std::shared_ptr ConstructionPlugin_Point::createByProjection() +std::shared_ptr ConstructionPlugin_Point::createByProjectionOnFace() { // Get point. - AttributeSelectionPtr aPointSelection = selection(POINT()); + AttributeSelectionPtr aPointSelection = selection(POINT_TO_PROJECT_ON_FACE()); GeomShapePtr aPointShape = aPointSelection->value(); if(!aPointShape.get()) { aPointShape = aPointSelection->context()->shape(); @@ -181,7 +181,7 @@ std::shared_ptr ConstructionPlugin_Point::createByProjection() std::shared_ptr aVertex(new GeomAPI_Vertex(aPointShape)); // Get plane. - AttributeSelectionPtr aPlaneSelection = selection(PLANE()); + AttributeSelectionPtr aPlaneSelection = selection(FACE_FOR_POINT_PROJECTION()); GeomShapePtr aPlaneShape = aPlaneSelection->value(); if(!aPlaneShape.get()) { aPlaneShape = aPlaneSelection->context()->shape(); @@ -191,6 +191,7 @@ std::shared_ptr ConstructionPlugin_Point::createByProjection() return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace); } +/* //================================================================================================== std::shared_ptr ConstructionPlugin_Point::createByLinesIntersection() { diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index 7537970a8..a5f84a6d3 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -68,14 +68,14 @@ public: return MY_CREATION_METHOD_ID; } - /* /// Attribute name for creation method. - inline static const std::string& CREATION_METHOD_BY_PROJECTION() + inline static const std::string& CREATION_METHOD_BY_PROJECTION_ON_FACE() { - static const std::string MY_CREATION_METHOD_ID("by_projection"); + static const std::string MY_CREATION_METHOD_ID("by_projection_on_face"); return MY_CREATION_METHOD_ID; } + /* /// Attribute name for creation method. inline static const std::string& CREATION_METHOD_BY_LINES_INTERSECTION() { @@ -161,21 +161,21 @@ public: return ATTR_ID; } - /* - /// Attribute name for point. - inline static const std::string& POINT() + /// Attribute name for point to project on surface. + inline static const std::string& POINT_TO_PROJECT_ON_FACE() { - static const std::string ATTR_ID("point"); + static const std::string ATTR_ID("point_to_project_on_face"); return ATTR_ID; } - /// Attribute name for plane. - inline static const std::string& PLANE() + /// Attribute name for face for point projection. + inline static const std::string& FACE_FOR_POINT_PROJECTION() { - static const std::string ATTR_ID("plane"); + static const std::string ATTR_ID("face_for_point_projection"); return ATTR_ID; } + /* /// Attribute name for selected first line. inline static const std::string& FIRST_LINE() { @@ -245,8 +245,8 @@ public: private: std::shared_ptr createByXYZ(); std::shared_ptr createByDistanceOnEdge(); - /*std::shared_ptr createByProjection(); - std::shared_ptr createByLinesIntersection();*/ + std::shared_ptr createByProjectionOnFace(); + /*std::shared_ptr createByLinesIntersection();*/ std::list > createByLineAndPlaneIntersection(); }; diff --git a/src/ConstructionPlugin/Test/TestPoint_ProjectOnFace.py b/src/ConstructionPlugin/Test/TestPoint_ProjectOnFace.py new file mode 100644 index 000000000..1b5218ea7 --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPoint_ProjectOnFace.py @@ -0,0 +1,49 @@ +## 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 projection point on face. +""" + +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("XOZ")) +SketchPoint_1 = Sketch_1.addPoint(50, 50) +model.do() +Box_1 = model.addBox(Part_1_doc, 10, 100, 100) +Point_2 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("FACE", "Box_1_1/Front")) +Point_3 = model.addPoint(Part_1_doc, model.selection("VERTEX", "Sketch_1/Vertex-SketchPoint_1"), model.selection("FACE", "PartSet/XOY")) +model.do() +model.end() + +assert (len(Point_2.results()) > 0) +rightPosition = GeomAPI_Vertex(10, 0, 50) +assert(rightPosition.isEqual(Point_2.results()[0].resultSubShapePair()[0].shape())) + +assert (len(Point_3.results()) > 0) +rightPosition = GeomAPI_Vertex(50, 0, 0) +assert(rightPosition.isEqual(Point_3.results()[0].resultSubShapePair()[0].shape())) + +assert(model.checkPythonDump()) diff --git a/src/ConstructionPlugin/icons/point_by_projection_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_on_face_32x32.png similarity index 100% rename from src/ConstructionPlugin/icons/point_by_projection_32x32.png rename to src/ConstructionPlugin/icons/point_by_projection_on_face_32x32.png diff --git a/src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_on_line_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..187864f0411f2076b66840f22c2b5400a604fc47 GIT binary patch literal 812 zcmV+{1JnG8P)N2bZe?^J zG%heMF*(%MvSa`N0;x$vK~z{ry_Y>~(?A%8L+QYPNQ+uK{0s~X6=LjyR3t0Dz)+~q zQp3!Q7=V=}TNWfF7A7P_`4bI4Vq#!pU;~K-b|jGaD-r{sQq23FeC3jU&LxoelOEUi z-gozY=h`{Dl4aS@*a(!~M)IbZ>q8WMFsh4-yI}q{RQiJv5K^uWQ5*ymFpUB-6!3-Z zK?*?r3Gf-L@tm5NI0*ZXH+QoDPAK(D;DfO*POF&Y33wyrSkONQ-UFIH13TUR zuH<3Z8=aiVC;ce(6ZG{pCtZzU@D%{vYfiQZgHRNZe_UX$ zuVQbw=8o|pibcTWR;{trgvk|x_B-&~m@EA4xWs3;a_}50 zrg4VzSJZexSW;JN&>+TpIqF4l0tifZN=LNjrO=$c1 zZ<%Q<&AVfKh++|cSFShk$Xx(ugL;zkkwjsa@RXdF#`QxKC1A|QjVoV=Sv!c+2Uzhv zv^zl~T}AtdG|q=8_5zd3o96jGPIzOwdH;eax)hm@3Q;65n{>?i`)*z$M~x`v=G;uI z`GS-;3bqJknv|63wsx0000 -