From ea551d77decefb9c01f9aeb2caba39bb1613bcad Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 16 Apr 2015 17:45:16 +0300 Subject: [PATCH] Fix for issue #461 --- .../ConstructionPlugin_Axis.cpp | 19 ++++++++--- .../ConstructionPlugin_Axis.h | 1 + src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp | 32 +++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h | 5 ++- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp index e3d7eb34c..ae24aaf3c 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.cpp @@ -59,6 +59,19 @@ void ConstructionPlugin_Axis::createAxisByTwoPoints() } } +void ConstructionPlugin_Axis::createAxisByCylindricalFace() +{ + std::shared_ptr aSelection = data()->selection(CYLINDRICAL_FACE())->value(); + // update arguments due to the selection value + if (aSelection && !aSelection->isNull() && aSelection->isFace()) { + std::shared_ptr anEdge = GeomAlgoAPI_EdgeBuilder::cylinderAxis(aSelection); + + ResultConstructionPtr aConstr = document()->createConstruction(data()); + aConstr->setShape(anEdge); + setResult(aConstr); + } +} + void ConstructionPlugin_Axis::execute() { AttributeStringPtr aMethodTypeAttr = string(ConstructionPlugin_Axis::METHOD()); @@ -66,14 +79,12 @@ void ConstructionPlugin_Axis::execute() if (aMethodType == "AxisByPointsCase") { createAxisByTwoPoints(); } else if (aMethodType == "AxisByCylindricalFaceCase") { - #ifdef _DEBUG - std::cout << "ConstructionPlugin_Axis::execute: " << "AxisByCylindricalFaceCase is not supported yet." << std::endl; - #endif + createAxisByCylindricalFace(); } } bool ConstructionPlugin_Axis::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, - std::shared_ptr theDefaultPrs) + std::shared_ptr theDefaultPrs) { bool isCustomized = theDefaultPrs.get() != NULL && theDefaultPrs->customisePresentation(theResult, thePrs, theDefaultPrs); diff --git a/src/ConstructionPlugin/ConstructionPlugin_Axis.h b/src/ConstructionPlugin/ConstructionPlugin_Axis.h index df8aedcfd..1775300eb 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Axis.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Axis.h @@ -78,6 +78,7 @@ class ConstructionPlugin_Axis : public ModelAPI_Feature, public GeomAPI_ICustomP protected: void createAxisByTwoPoints(); + void createAxisByCylindricalFace(); }; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp index f1ecb2b34..0de55a60f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -32,6 +34,36 @@ std::shared_ptr GeomAlgoAPI_EdgeBuilder::line( return aRes; } +std::shared_ptr GeomAlgoAPI_EdgeBuilder::cylinderAxis( + std::shared_ptr theCylindricalFace) +{ + std::shared_ptr aResult; + const TopoDS_Shape& aShape = theCylindricalFace->impl(); + if (aShape.IsNull()) + return aResult; + TopoDS_Face aFace = TopoDS::Face(aShape); + if (aFace.IsNull()) + return aResult; + TopLoc_Location aLoc; + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace, aLoc); + if (aSurf.IsNull()) + return aResult; + Handle(Geom_CylindricalSurface) aCyl = Handle(Geom_CylindricalSurface)::DownCast(aSurf); + if (aCyl.IsNull()) + return aResult; + gp_Ax1 anAxis = aCyl->Axis(); + gp_Pnt aStart(anAxis.Location().Transformed(aLoc.Transformation())); + // edge length is 100, "-" because cylinder of extrusion has negative direction with the cylinder + gp_Pnt anEnd(anAxis.Location().XYZ() - anAxis.Direction().XYZ() * 100.); + anEnd.Transform(aLoc.Transformation()); + + BRepBuilderAPI_MakeEdge anEdgeBuilder(aStart, anEnd); + std::shared_ptr aRes(new GeomAPI_Edge); + TopoDS_Edge anEdge = anEdgeBuilder.Edge(); + aRes->setImpl(new TopoDS_Shape(anEdge)); + return aRes; +} + std::shared_ptr GeomAlgoAPI_EdgeBuilder::lineCircle( std::shared_ptr theCenter, std::shared_ptr theNormal, double theRadius) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h index ef0f82df4..0bd67621b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.h @@ -23,7 +23,10 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_EdgeBuilder public: /// Creates linear edge by two points static std::shared_ptr line(std::shared_ptr theStart, - std::shared_ptr theEnd); + std::shared_ptr theEnd); + /// Creates edge - axis of the given cylindrical face + static std::shared_ptr cylinderAxis( + std::shared_ptr theCylindricalFace); /// Creates linear edge in a form of a circle by a point and a circle radius static std::shared_ptr lineCircle(std::shared_ptr theCenter, -- 2.39.2