From b663f22dc23f1e64dbcdfdcea51b5fe67e6797b6 Mon Sep 17 00:00:00 2001 From: dbv Date: Thu, 14 Jul 2016 18:03:38 +0300 Subject: [PATCH] Issue #1649: Added options to create plane by rotation around axis; --- .../ConstructionPlugin_Plane.cpp | 42 ++++++++++++++++++ .../ConstructionPlugin_Plane.h | 15 +++++++ src/ConstructionPlugin/icons/angle.png | Bin 0 -> 499 bytes src/ConstructionPlugin/plane_widget.xml | 12 +++++ 4 files changed, 69 insertions(+) create mode 100644 src/ConstructionPlugin/icons/angle.png diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp index 368bc3236..ff3030055 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.cpp @@ -9,9 +9,12 @@ #include #include +#include #include +#include #include +#include #include #include #include @@ -65,6 +68,8 @@ void ConstructionPlugin_Plane::initAttributes() data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(DISTANCE(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(COINCIDENT_POINT(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(AXIS(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ANGLE(), ModelAPI_AttributeDouble::typeId()); } //================================================================================================== @@ -85,6 +90,8 @@ void ConstructionPlugin_Plane::execute() aShape = createByDistanceFromOther(); } else if(aCreationMethodOption == CREATION_METHOD_BY_COINCIDENT_TO_POINT()) { aShape = createByCoincidentPoint(); + } else if(aCreationMethodOption == CREATION_METHOD_BY_ROTATION()) { + aShape = createByRotation(); } } @@ -272,6 +279,41 @@ std::shared_ptr ConstructionPlugin_Plane::createByCoincidentPoint return makeRectangularFace(aFace, aNewPln); } +//================================================================================================== +std::shared_ptr ConstructionPlugin_Plane::createByRotation() +{ + // 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)); + + // Get axis. + AttributeSelectionPtr anAxisSelection = selection(AXIS()); + GeomShapePtr anAxisShape = anAxisSelection->value(); + if(!anAxisShape.get()) { + anAxisShape = anAxisSelection->context()->shape(); + } + std::shared_ptr anEdge(new GeomAPI_Edge(anAxisShape)); + + std::shared_ptr anAxis = std::shared_ptr(new GeomAPI_Ax1(anEdge->line()->location(), + anEdge->line()->direction())); + + // Getting angle. + double anAngle = real(ANGLE())->value(); + + GeomAlgoAPI_Rotation aRotationAlgo(aFace, anAxis, anAngle); + + std::shared_ptr aRes(new GeomAPI_Face(aRotationAlgo.shape())); + std::shared_ptr aNewPln = aRes->getPlane(); + + aRes = makeRectangularFace(aRes, aNewPln); + + return aRes; +} + //================================================================================================== GeomShapePtr faceByThreeVertices(const std::shared_ptr theV1, const std::shared_ptr theV2, diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plane.h b/src/ConstructionPlugin/ConstructionPlugin_Plane.h index d92f00811..eb2ae37c4 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plane.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Plane.h @@ -166,6 +166,20 @@ public: return ATTR_ID; } + /// Attribute name for axis. + inline static const std::string& AXIS() + { + static const std::string ATTR_ID("axis"); + return ATTR_ID; + } + + /// Attribute name for angle. + inline static const std::string& ANGLE() + { + static const std::string ATTR_ID("angle"); + return ATTR_ID; + } + /// Attribute name for a parameter for the general equation of a plane (ax+by+cz+d=0) inline static const std::string& A() { @@ -213,6 +227,7 @@ protected: std::shared_ptr createByThreePoints(); std::shared_ptr createByLineAndPoint(); std::shared_ptr createByCoincidentPoint(); + std::shared_ptr createByRotation(); /// Creates a new plane by copy of face plane with translation along the normal /// to the specified distance. std::shared_ptr createByDistanceFromOther(); diff --git a/src/ConstructionPlugin/icons/angle.png b/src/ConstructionPlugin/icons/angle.png new file mode 100644 index 0000000000000000000000000000000000000000..e401acd67fd22b2edacd3b53e3dc9c6c8a0c1469 GIT binary patch literal 499 zcmV?ss z0*&cJ^g7Vh+a{iwSL01)cH)QpAsZ+KN)@dOh9Yx<=?4(k)c@5CAc4-ltK0<7K>0_- zb8k>J0_O@BS=U;5IEdXA0?bFIG7MaPqOCDiuLY3>5uR+zJ*sQ(8Tc6>dX&jNHj6M0 zJc^}mCbjK2$<2KyxiyP1VMQkb?cu5706i z+Fe-`@UDxEjhABg_sQ*RfnB@I4E+lDO|G&oBH@1n1aqe%)$iW+(;N&%mc=$TsMin- zMb?04UjU#9=s*m>AaLyW38TPkF86>DUx0KXdIc=z>}om@J@vgrU + + + + -- 2.39.2