From: dbv Date: Mon, 4 Jul 2016 11:07:09 +0000 (+0300) Subject: Added option to create Construction Point by projection point on plane. Fixed CPP... X-Git-Tag: V_2.5.0~242 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98d0d390dac05b7764af10c723fd33f23665c207;p=modules%2Fshaper.git Added option to create Construction Point by projection point on plane. Fixed CPP High API for Construction plane. Fixed tests. --- diff --git a/src/ConstructionAPI/ConstructionAPI_Plane.cpp b/src/ConstructionAPI/ConstructionAPI_Plane.cpp index 61a72e061..a248e71d1 100644 --- a/src/ConstructionAPI/ConstructionAPI_Plane.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Plane.cpp @@ -48,6 +48,7 @@ void ConstructionAPI_Plane::setFaceAndDistance( const ModelHighAPI_Selection & theFace, const ModelHighAPI_Double & theDistance) { + fillAttribute("PlaneByFaceAndDistance", mycreationMethod); fillAttribute(theFace, myface); fillAttribute(theDistance, mydistance); @@ -60,6 +61,7 @@ void ConstructionAPI_Plane::setGeneralEquation( const ModelHighAPI_Double & theC, const ModelHighAPI_Double & theD) { + fillAttribute("PlaneByGeneralEquation", mycreationMethod); fillAttribute(theA, myA); fillAttribute(theB, myB); fillAttribute(theC, myC); diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index c982cc2a7..738703a6e 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -40,6 +40,19 @@ ConstructionAPI_Point::ConstructionAPI_Point(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + /// If first object is vertex and second object is face then set by projection. + /// TODO: check + setByProjection(theObject1, theObject2); + } +} + //================================================================================================== ConstructionAPI_Point::~ConstructionAPI_Point() { @@ -74,6 +87,17 @@ void ConstructionAPI_Point::setByDistanceOnEdge(const ModelHighAPI_Selection& th execute(); } +//================================================================================================== +void ConstructionAPI_Point::setByProjection(const ModelHighAPI_Selection& theVertex, + const ModelHighAPI_Selection& thePlane) +{ + fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_PROJECTION(), mycreationMethod); + fillAttribute(theVertex, mypoint); + fillAttribute(thePlane, myplane); + + execute(); +} + //================================================================================================== PointPtr addPoint(const std::shared_ptr& thePart, const ModelHighAPI_Double& theX, @@ -96,3 +120,13 @@ PointPtr addPoint(const std::shared_ptr & thePart, std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); return PointPtr(new ConstructionAPI_Point(aFeature, theEdge, theDistanceValue, theDistancePercent, theReverse)); } + +//================================================================================================== +PointPtr addPoint(const std::shared_ptr & thePart, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2) +{ + // TODO(spo): check that thePart is not empty + std::shared_ptr aFeature = thePart->addFeature(ConstructionAPI_Point::ID()); + return PointPtr(new ConstructionAPI_Point(aFeature, theObject1, theObject2)); +} diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index 3e67ce80e..ab9f83837 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -20,22 +20,22 @@ class ModelHighAPI_Double; /// \class ConstructionAPI_Point /// \ingroup CPPHighAPI -/// \brief Interface for Point feature +/// \brief Interface for Point feature. class ConstructionAPI_Point: public ModelHighAPI_Interface { public: - /// Constructor without values + /// Constructor without values. CONSTRUCTIONAPI_EXPORT explicit ConstructionAPI_Point(const std::shared_ptr& theFeature); - /// Constructor with values + /// Constructor with values. CONSTRUCTIONAPI_EXPORT ConstructionAPI_Point(const std::shared_ptr& theFeature, const ModelHighAPI_Double& theX, const ModelHighAPI_Double& theY, const ModelHighAPI_Double& theZ); - /// Constructor with values + /// Constructor with values. CONSTRUCTIONAPI_EXPORT ConstructionAPI_Point(const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theEdge, @@ -43,36 +43,49 @@ public: const bool theDistancePercent = false, const bool theReverse = false); - /// Destructor + /// Constructor with values. + CONSTRUCTIONAPI_EXPORT + ConstructionAPI_Point(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2); + + /// Destructor. CONSTRUCTIONAPI_EXPORT virtual ~ConstructionAPI_Point(); - INTERFACE_8(ConstructionPlugin_Point::ID(), - creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, - x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */, - y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */, - z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */, - edge, ConstructionPlugin_Point::EDGE(), ModelAPI_AttributeSelection, /** Edge attribute */, - distanceValue, ConstructionPlugin_Point::DISTANCE_VALUE(), ModelAPI_AttributeDouble, /** Distance value attribute */, - distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */, - reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */ + INTERFACE_10(ConstructionPlugin_Point::ID(), + creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, + x, ConstructionPlugin_Point::X(), ModelAPI_AttributeDouble, /** X attribute */, + y, ConstructionPlugin_Point::Y(), ModelAPI_AttributeDouble, /** Y attribute */, + z, ConstructionPlugin_Point::Z(), ModelAPI_AttributeDouble, /** Z attribute */, + edge, ConstructionPlugin_Point::EDGE(), ModelAPI_AttributeSelection, /** Edge attribute */, + distanceValue, ConstructionPlugin_Point::DISTANCE_VALUE(), ModelAPI_AttributeDouble, /** Distance value attribute */, + distancePercent, ConstructionPlugin_Point::DISTANCE_PERCENT(), ModelAPI_AttributeBoolean, /** Distance percent attribute */, + reverse, ConstructionPlugin_Point::REVERSE(), ModelAPI_AttributeBoolean, /** Reverse attribute */, + point, ConstructionPlugin_Point::POINT(), ModelAPI_AttributeSelection, /** Point attribute */, + plane, ConstructionPlugin_Point::PLANE(), ModelAPI_AttributeSelection, /** Plane attribute */ ) - /// Set point values + /// Set point values. CONSTRUCTIONAPI_EXPORT void setByXYZ(const ModelHighAPI_Double & theX, const ModelHighAPI_Double & theY, const ModelHighAPI_Double & theZ); - /// Set edge and distance on it for point + /// Set edge and distance on it for point. CONSTRUCTIONAPI_EXPORT void setByDistanceOnEdge(const ModelHighAPI_Selection& theEdge, const ModelHighAPI_Double& theDistanceValue, const bool theDistancePercent = false, const bool theReverse = false); + + /// Set point and plane for projection. + CONSTRUCTIONAPI_EXPORT + void setByProjection(const ModelHighAPI_Selection& theVertex, + const ModelHighAPI_Selection& thePlane); }; -/// Pointer on Point object +/// Pointer on Point object. typedef std::shared_ptr PointPtr; /// \ingroup CPPHighAPI @@ -92,4 +105,11 @@ PointPtr addPoint(const std::shared_ptr & thePart, const bool theDistancePercent = false, const bool theReverse = false); +/// \ingroup CPPHighAPI +/// \brief Create Point feature +CONSTRUCTIONAPI_EXPORT +PointPtr addPoint(const std::shared_ptr & thePart, + const ModelHighAPI_Selection& theObject1, + const ModelHighAPI_Selection& theObject2); + #endif /* SRC_CONSTRUCTIONAPI_CONSTRUCTIONAPI_POINT_H_ */ diff --git a/src/ConstructionPlugin/CMakeLists.txt b/src/ConstructionPlugin/CMakeLists.txt index bdbc15f85..4b5ca9ddb 100644 --- a/src/ConstructionPlugin/CMakeLists.txt +++ b/src/ConstructionPlugin/CMakeLists.txt @@ -55,4 +55,5 @@ INCLUDE_DIRECTORIES( ADD_UNIT_TESTS(TestAxisCreation.py - TestPointName.py) + TestPointName.py + TestPoint.py) diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index c7b4f1d44..380393db7 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -13,10 +13,10 @@ #include #include -#include #include #include +#include //================================================================================================== ConstructionPlugin_Point::ConstructionPlugin_Point() @@ -43,6 +43,9 @@ void ConstructionPlugin_Point::initAttributes() data()->addAttribute(DISTANCE_VALUE(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(DISTANCE_PERCENT(), ModelAPI_AttributeBoolean::typeId()); data()->addAttribute(REVERSE(), ModelAPI_AttributeBoolean::typeId()); + + data()->addAttribute(POINT(), ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(PLANE(), ModelAPI_AttributeSelection::typeId()); } //================================================================================================== @@ -55,6 +58,8 @@ 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(); } if(aShape.get()) { @@ -76,15 +81,15 @@ bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, } //================================================================================================== -GeomShapePtr ConstructionPlugin_Point::createByXYZ() +std::shared_ptr ConstructionPlugin_Point::createByXYZ() { - return GeomAlgoAPI_PointBuilder::point(real(X())->value(), - real(Y())->value(), - real(Z())->value()); + return GeomAlgoAPI_PointBuilder::vertex(real(X())->value(), + real(Y())->value(), + real(Z())->value()); } //================================================================================================== -GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge() +std::shared_ptr ConstructionPlugin_Point::createByDistanceOnEdge() { // Get edge. AttributeSelectionPtr anEdgeSelection = selection(EDGE()); @@ -101,5 +106,27 @@ GeomShapePtr ConstructionPlugin_Point::createByDistanceOnEdge() // Get reverse flag. bool anIsReverse = boolean(REVERSE())->value(); - return GeomAlgoAPI_ShapeTools::findVertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse); + return GeomAlgoAPI_PointBuilder::vertexOnEdge(anEdge, aValue, anIsPercent, anIsReverse); +} + +//================================================================================================== +std::shared_ptr ConstructionPlugin_Point::createByProjection() +{ + // 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)); + + // Get plane. + AttributeSelectionPtr aPlaneSelection = selection(PLANE()); + GeomShapePtr aPlaneShape = aPlaneSelection->value(); + if(!aPlaneShape.get()) { + aPlaneShape = aPlaneSelection->context()->shape(); + } + std::shared_ptr aFace(new GeomAPI_Face(aPlaneShape)); + + return GeomAlgoAPI_PointBuilder::vertexByProjection(aVertex, aFace); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index 956eeeb00..65d17aef2 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -13,6 +13,8 @@ #include #include +class GeomAPI_Vertex; + /// \class ConstructionPlugin_Point /// \ingroup Plugins /// \brief Feature for creation of the new part in PartSet. @@ -50,6 +52,13 @@ public: return MY_CREATION_METHOD_ID; } + /// Attribute name for creation method. + inline static const std::string& CREATION_METHOD_BY_PROJECTION() + { + static const std::string MY_CREATION_METHOD_ID("by_projection"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name for X coordinate. inline static const std::string& X() { @@ -99,6 +108,20 @@ public: return ATTR_ID; } + /// Attribute name for point. + inline static const std::string& POINT() + { + static const std::string ATTR_ID("point"); + return ATTR_ID; + } + + /// Attribute name for plane. + inline static const std::string& PLANE() + { + static const std::string ATTR_ID("plane"); + return ATTR_ID; + } + /// Creates a new part document if needed. CONSTRUCTIONPLUGIN_EXPORT virtual void execute(); @@ -116,8 +139,9 @@ public: std::shared_ptr theDefaultPrs); private: - std::shared_ptr createByXYZ(); - std::shared_ptr createByDistanceOnEdge(); + std::shared_ptr createByXYZ(); + std::shared_ptr createByDistanceOnEdge(); + std::shared_ptr createByProjection(); }; diff --git a/src/ConstructionPlugin/Test/TestPoint.py b/src/ConstructionPlugin/Test/TestPoint.py new file mode 100644 index 000000000..272fe4d8e --- /dev/null +++ b/src/ConstructionPlugin/Test/TestPoint.py @@ -0,0 +1,49 @@ +""" +Test case for Construction Point feature. Written on High API. +""" +from ModelAPI import * +from GeomAPI import * + +import model + +# Get session +aSession = ModelAPI_Session.get() + +# Create a part +aDocument = aSession.activeDocument() +aSession.startOperation() +model.addPart(aDocument) +aDocument = aSession.activeDocument() +aSession.finishOperation() + +# Create a point by coordinates +aSession.startOperation() +aPoint = model.addPoint(aDocument, 50, 50, 50) +aSession.finishOperation() +assert (len(aPoint.result()) > 0) + +# Create a sketch with line +aSession.startOperation() +anOrigin = GeomAPI_Pnt(0, 0, 0) +aDirX = GeomAPI_Dir(1, 0, 0) +aNorm = GeomAPI_Dir(0, 0, 1) +aSketch = model.addSketch(aDocument, GeomAPI_Ax3(anOrigin, aDirX, aNorm)) +aSketchLine = aSketch.addLine(25, 25, 100, 25) +aSession.finishOperation() + +# Create a point on line +aSession.startOperation() +aPoint = model.addPoint(aDocument, aSketchLine.result()[0], 50, True, False) +aSession.finishOperation() +assert (len(aPoint.result()) > 0) + +# Create plane +aSession.startOperation() +aPlane = model.addPlane(aDocument, 1, 1, 1, 1) +aSession.finishOperation() + +# Create a point by projection +aSession.startOperation() +aPoint = model.addPoint(aDocument, aPoint.result()[0], aPlane.result()[0]) +aSession.finishOperation() +assert (len(aPoint.result()) > 0) diff --git a/src/ConstructionPlugin/icons/face.png b/src/ConstructionPlugin/icons/face.png new file mode 100644 index 000000000..6abc697c0 Binary files /dev/null and b/src/ConstructionPlugin/icons/face.png differ diff --git a/src/ConstructionPlugin/icons/point_by_projection_32x32.png b/src/ConstructionPlugin/icons/point_by_projection_32x32.png new file mode 100644 index 000000000..e5a5510ea Binary files /dev/null and b/src/ConstructionPlugin/icons/point_by_projection_32x32.png differ diff --git a/src/ConstructionPlugin/point_widget.xml b/src/ConstructionPlugin/point_widget.xml index 4557509f3..230aac45a 100644 --- a/src/ConstructionPlugin/point_widget.xml +++ b/src/ConstructionPlugin/point_widget.xml @@ -49,5 +49,23 @@ tooltip="Distance from edge end point." default="false"/> + + + + + + + diff --git a/src/GeomAPI/GeomAPI_Vertex.h b/src/GeomAPI/GeomAPI_Vertex.h index c1ec7109c..c5f0dfe27 100644 --- a/src/GeomAPI/GeomAPI_Vertex.h +++ b/src/GeomAPI/GeomAPI_Vertex.h @@ -11,32 +11,30 @@ class GeomAPI_Pnt; -/**\class GeomAPI_Vertex -* \ingroup DataModel - * \brief Interface to the vertex object - */ - -class GeomAPI_Vertex : public GeomAPI_Shape +/// \class GeomAPI_Vertex +/// \ingroup DataModel +/// \brief Interface to the vertex object. +class GeomAPI_Vertex: public GeomAPI_Shape { public: - /// Creation of empty (null) shape - GEOMAPI_EXPORT - GeomAPI_Vertex(); + /// Creation of empty (null) shape. + GEOMAPI_EXPORT + GeomAPI_Vertex(); - /// Creation of vertex by the vertex-shape - GEOMAPI_EXPORT - GeomAPI_Vertex(const std::shared_ptr& theShape); + /// Creation of vertex by the vertex-shape. + GEOMAPI_EXPORT + GeomAPI_Vertex(const std::shared_ptr& theShape); - /// Creation of vertex by 3d coordinates - GEOMAPI_EXPORT - GeomAPI_Vertex(double theX, double theY, double theZ); + /// Creation of vertex by 3d coordinates. + GEOMAPI_EXPORT + GeomAPI_Vertex(double theX, double theY, double theZ); - /// Returns the first vertex coordinates of the edge - GEOMAPI_EXPORT + /// Returns the first vertex coordinates of the edge. + GEOMAPI_EXPORT std::shared_ptr point(); - /// Returns true if the current edge is geometrically equal to the given edge - GEOMAPI_EXPORT + /// Returns true if the current edge is geometrically equal to the given edge. + GEOMAPI_EXPORT bool isEqual(const std::shared_ptr theVert) const; }; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp index dffcecce4..a76850441 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -4,18 +4,26 @@ // Created: 02 Jun 2014 // Author: Mikhail PONIKAROV -#include +#include "GeomAlgoAPI_PointBuilder.h" + +#include +#include +#include #include #include #include -#include + #include -#include -#include +#include +#include +#include +#include #include +#include +#include -std::shared_ptr GeomAlgoAPI_PointBuilder::point( - std::shared_ptr thePoint) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr thePoint) { const gp_Pnt& aPnt = thePoint->impl(); BRepBuilderAPI_MakeVertex aMaker(aPnt); @@ -25,8 +33,10 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::point( return aRes; } -std::shared_ptr GeomAlgoAPI_PointBuilder::point( - const double theX, const double theY, const double theZ) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertex(const double theX, + const double theY, + const double theZ) { const gp_Pnt aPnt(theX, theY, theZ); BRepBuilderAPI_MakeVertex aMaker(aPnt); @@ -36,7 +46,8 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::point( return aRes; } -std::shared_ptr GeomAlgoAPI_PointBuilder::point(std::shared_ptr theVertex) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::point(const std::shared_ptr theVertex) { TopoDS_Shape aShape = theVertex->impl(); if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) { @@ -47,3 +58,73 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::point(std::shared_ptr(); } + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexOnEdge(const std::shared_ptr theEdge, + const double theValue, + const bool theIsPercent, + const bool theIsReverse) +{ + if(!theEdge.get()) { + return NULL; + } + + double aValue = theValue; + if(theIsPercent) { + aValue = theEdge->length() / 100.0 * aValue; + } + + const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl()); + Standard_Real aUFirst, aULast; + Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast); + + std::shared_ptr aVertex; + if(!anEdgeCurve.IsNull() ) { + Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve; + + if(theIsReverse) { + aReOrientedCurve = anEdgeCurve->Reversed(); + aUFirst = anEdgeCurve->ReversedParameter(aULast); + } + + // Get the point by length + GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve); + GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst); + Standard_Real aParam = anAbsPnt.Parameter(); + gp_Pnt aPnt = anAdapCurve.Value(aParam); + BRepBuilderAPI_MakeVertex aMkVertex(aPnt); + const TopoDS_Vertex& aShape = aMkVertex.Vertex(); + aVertex.reset(new GeomAPI_Vertex()); + aVertex->setImpl(new TopoDS_Vertex(aShape)); + } + + return aVertex; +} + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByProjection( + const std::shared_ptr theVertex, + const std::shared_ptr thePlane) +{ + if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) { + return NULL; + } + + std::shared_ptr aGeomPnt = theVertex->point(); + gp_Pnt aPnt = aGeomPnt->impl(); + + std::shared_ptr aGeomPln = thePlane->getPlane(); + gp_Pln aPln = aGeomPln->impl(); + + gp_Dir aPntAxis = aPnt.XYZ() - aPln.Location().XYZ(); + gp_Dir aPlnNorm = aPln.Axis().Direction(); + + if(aPntAxis * aPlnNorm > 0) { + aPlnNorm.Reverse(); + } + + double aDistance = aPln.Distance(aPnt); + aPnt.Translate(gp_Vec(aPlnNorm) * aDistance); + + return std::shared_ptr(new GeomAPI_Vertex(aPnt.X(), aPnt.Y(), aPnt.Z())); +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h index cff50ee05..906a2814f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.h @@ -10,26 +10,46 @@ #include #include -class GeomAPI_Shape; +class GeomAPI_Edge; +class GeomAPI_Face; class GeomAPI_Pnt; +class GeomAPI_Shape; +class GeomAPI_Vertex; -/**\class GeomAlgoAPI_PointBuilder - * \ingroup DataAlgo - * \brief Allows to create face-shapes by different parameters - */ - +/// \class GeomAlgoAPI_PointBuilder +/// \ingroup DataAlgo +/// \brief Allows to create vertex-shapes by different parameters class GEOMALGOAPI_EXPORT GeomAlgoAPI_PointBuilder { - public: - /// Creates a shape by point - static std::shared_ptr point(std::shared_ptr thePoint); - - /// Creates a shape by point coordinates - static std::shared_ptr point( - const double theX, const double theY, const double theZ); +public: + /// Creates a vertex by point + static std::shared_ptr vertex(const std::shared_ptr thePoint); + + /// Creates a vertex by point coordinates + static std::shared_ptr vertex(const double theX, + const double theY, + const double theZ); + + /// \brief Creates vertex by edge and distance on it. + /// \param[in] theEdge edge. + /// \param[in] theValue distance value. + /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length. + /// \param[in] theIsReverse if true the distance will be measured from the edge end point. + /// \return created vertex. + static std::shared_ptr vertexOnEdge(const std::shared_ptr theEdge, + const double theValue, + const bool theIsPercent = false, + const bool theIsReverse = false); + + /// \brief Creates vertex by projection another vertex on plane. + /// \param[in] theVertex vertex to project. + /// \param[in] thePlane face for projection. Should be planar. + /// \return created vertex. + static std::shared_ptr vertexByProjection(const std::shared_ptr theVertex, + const std::shared_ptr thePlane); /// Return point by shape vertex - static std::shared_ptr point(std::shared_ptr theVertex); + static std::shared_ptr point(const std::shared_ptr theVertex); }; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 029743117..a40aff14e 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -8,9 +8,9 @@ #include "GeomAlgoAPI_SketchBuilder.h" +#include #include #include -#include #include #include @@ -21,24 +21,20 @@ #include #include #include -#include #include -#include #include #include #include #include #include #include -#include -#include #include +#include #include #include #include #include #include -#include #include #include #include @@ -667,46 +663,3 @@ bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr theE BRepExtrema_ExtCF anExt(anEdge, aFace); return anExt.IsParallel() == Standard_True; } - -//================================================================================================== -std::shared_ptr GeomAlgoAPI_ShapeTools::findVertexOnEdge(const std::shared_ptr theEdge, - const double theValue, - const bool theIsPercent, - const bool theIsReverse) -{ - std::shared_ptr aVertex; - - if(!theEdge.get()) { - return aVertex; - } - - double aValue = theValue; - if(theIsPercent) { - aValue = theEdge->length() / 100.0 * aValue; - } - - const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl()); - Standard_Real aUFirst, aULast; - Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast); - - if(!anEdgeCurve.IsNull() ) { - Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve; - - if(theIsReverse) { - aReOrientedCurve = anEdgeCurve->Reversed(); - aUFirst = anEdgeCurve->ReversedParameter(aULast); - } - - // Get the point by length - GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve); - GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst); - Standard_Real aParam = anAbsPnt.Parameter(); - gp_Pnt aPnt = anAdapCurve.Value(aParam); - BRepBuilderAPI_MakeVertex aMkVertex(aPnt); - const TopoDS_Vertex& aShape = aMkVertex.Vertex(); - aVertex.reset(new GeomAPI_Vertex()); - aVertex->setImpl(new TopoDS_Vertex(aShape)); - } - - return aVertex; -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index f1814c750..95a97f0bb 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -102,18 +102,6 @@ public: /// \return true if edge is parallel to face. GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr theEdge, const std::shared_ptr theFace); - - /// \brief Creates vertex by edge and distance on it. - /// \param[in] theEdge edge. - /// \param[in] theValue distance value. - /// \param[in] theIsPercent if true theValue will be treated as a percentage of theEdge total length. - /// \param[in] theIsReverse if true the distance will be measured from the edge end point. - /// \ return created vertex. - GEOMALGOAPI_EXPORT static std::shared_ptr findVertexOnEdge(const std::shared_ptr theEdge, - const double theValue, - const bool theIsPercent = false, - const bool theIsReverse = false); - }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 7cf3c0ddf..be3f9e568 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -119,7 +120,7 @@ void SketchPlugin_Arc::execute() std::shared_ptr aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y())); // make a visible point - std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); + std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); std::shared_ptr aConstr1 = document()->createConstruction( data(), 0); aConstr1->setShape(aCenterPointShape); @@ -242,7 +243,7 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious) } } // make a visible point - std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); + std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); aShapes.push_back(aCenterPointShape); } if (!aShapes.empty()) { diff --git a/src/SketchPlugin/SketchPlugin_Circle.cpp b/src/SketchPlugin/SketchPlugin_Circle.cpp index 9c9a78c6e..ccb1a6efe 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.cpp +++ b/src/SketchPlugin/SketchPlugin_Circle.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -122,7 +123,7 @@ AISObjectPtr SketchPlugin_Circle::getAISObject(AISObjectPtr thePrevious) if (aCircleShape && aRadius != 0) { std::list > aShapes; // make a visible point - std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); + std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); aShapes.push_back(aCenterPointShape); aShapes.push_back(aCircleShape); diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 17dbb0a3f..afa84bf13 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -42,7 +42,7 @@ void SketchPlugin_Point::execute() data()->attribute(SketchPlugin_Point::COORD_ID())); std::shared_ptr aPoint3D(aSketch->to3D(aPoint->x(), aPoint->y())); // make a visible point - std::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::point(aPoint3D); + std::shared_ptr aPointShape = GeomAlgoAPI_PointBuilder::vertex(aPoint3D); std::shared_ptr aConstr = document()->createConstruction(data()); aConstr->setShape(aPointShape); aConstr->setIsInHistory(false); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index debbfbb33..22b3257ef 100755 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -272,7 +273,7 @@ void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature, std::shared_ptr aCenter(theSketch->to3D(aPoint->x(), aPoint->y())); //std::cout<<"Execute circle "<x()<<" "<y()<<" "<z()< aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter); + std::shared_ptr aCenterPointShape = GeomAlgoAPI_PointBuilder::vertex(aCenter); std::shared_ptr aResult = theFeature->document()->createConstruction( theFeature->data(), theIndex); aResult->setShape(aCenterPointShape);