From: dbv Date: Fri, 15 Jul 2016 15:01:29 +0000 (+0300) Subject: Issue #1650: Added option to create axis by plane and point. X-Git-Tag: V_2.5.0~187 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c1e8de73f772aef0a65200b94ee731fbf4cca507;p=modules%2Fshaper.git Issue #1650: Added option to create axis by plane and point. --- 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 @@ + + + + + + +