From c1e8de73f772aef0a65200b94ee731fbf4cca507 Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 15 Jul 2016 18:01:29 +0300 Subject: [PATCH] Issue #1650: Added option to create axis by plane and point. --- .../ConstructionPlugin_Axis.cpp | 42 ++++++++++++++++++- .../ConstructionPlugin_Axis.h | 22 ++++++++++ src/ConstructionPlugin/axis_widget.xml | 15 +++++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index 876b79897..1dad21a93 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -71,6 +72,10 @@ void ConstructionPlugin_Axis::initAttributes() /// Attributes for axis by line. data()->addAttribute(LINE(), ModelAPI_AttributeSelection::typeId()); + + /// Attributes for axis by plane and point. + data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId()); } void ConstructionPlugin_Axis::createAxisByTwoPoints() @@ -181,6 +186,40 @@ void ConstructionPlugin_Axis::createAxisByLine() setResult(aConstr); } +void ConstructionPlugin_Axis::createAxisByPlaneAndPoint() +{ + // Get face. + AttributeSelectionPtr aFaceSelection = selection(PLANE()); + GeomShapePtr aFaceShape = aFaceSelection->value(); + if(!aFaceShape.get()) { + aFaceShape = aFaceSelection->context()->shape(); + } + std::shared_ptr aFace(new GeomAPI_Face(aFaceShape)); + std::shared_ptr aPln = aFace->getPlane(); + + // Get point. + AttributeSelectionPtr aPointSelection = selection(POINT()); + GeomShapePtr aPointShape = aPointSelection->value(); + if(!aPointShape.get()) { + aPointShape = aPointSelection->context()->shape(); + } + std::shared_ptr aVertex(new GeomAPI_Vertex(aPointShape)); + std::shared_ptr aPnt = aVertex->point(); + + std::shared_ptr aProjPnt = aPln->project(aPnt); + + if(aProjPnt->isEqual(aPnt)) { + aPnt->translate(aPln->direction(), 10); + } + + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::line(aProjPnt, aPnt); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setInfinite(true); + aConstr->setShape(anEdge); + setResult(aConstr); +} + void ConstructionPlugin_Axis::execute() { AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); @@ -195,7 +234,8 @@ void ConstructionPlugin_Axis::execute() createAxisByDimensions(); } else if(aMethodType == CREATION_METHOD_BY_LINE()) { createAxisByLine(); - + } else if(aMethodType == CREATION_METHOD_BY_PLANE_AND_POINT()) { + createAxisByPlaneAndPoint(); } } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index c0116e81c..0a1eb5de8 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -49,6 +49,13 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP return METHOD_ATTR; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_PLANE_AND_POINT() + { + static const std::string METHOD_ATTR("by_plane_and_point"); + return METHOD_ATTR; + } + /// attribute name for first point inline static const std::string& POINT_FIRST() { @@ -114,6 +121,20 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP return ATTR_ID; } + /// Attribute name for plane. + inline static const std::string& PLANE() + { + static const std::string ATTR_ID("plane"); + return ATTR_ID; + } + + /// Attribute name for point. + inline static const std::string& POINT() + { + static const std::string ATTR_ID("point"); + return ATTR_ID; + } + /// Returns a minimal length for axis inline static const double MINIMAL_LENGTH() { return 1.e-5; } @@ -143,6 +164,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP /// Creates a new axis by point and direction void createAxisByPointAndDirection(); void createAxisByLine(); + void createAxisByPlaneAndPoint(); }; diff --git a/src/ConstructionPlugin/axis_widget.xml b/src/ConstructionPlugin/axis_widget.xml index 243d0c794..e2e6ac47d 100644 --- a/src/ConstructionPlugin/axis_widget.xml +++ b/src/ConstructionPlugin/axis_widget.xml @@ -46,6 +46,21 @@ + + + + + + + -- 2.39.2