From 0c4ac6e8bf0e1aef3238e9becfebdbff68bedd1d Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 25 Apr 2017 15:50:25 +0300 Subject: [PATCH] Add ellipse data type --- src/GeomAPI/CMakeLists.txt | 2 + src/GeomAPI/GeomAPI_Ax2.h | 3 ++ src/GeomAPI/GeomAPI_Circ.h | 3 +- src/GeomAPI/GeomAPI_Dir.h | 3 ++ src/GeomAPI/GeomAPI_Edge.cpp | 39 ++++++++++++++-- src/GeomAPI/GeomAPI_Edge.h | 16 ++++++- src/GeomAPI/GeomAPI_Ellipse.cpp | 41 +++++++++++++++++ src/GeomAPI/GeomAPI_Ellipse.h | 55 +++++++++++++++++++++++ src/GeomAPI/GeomAPI_Pnt.h | 3 ++ src/PartSet/PartSet_WidgetSketchLabel.cpp | 49 ++++++++++++++++++++ src/PartSet/PartSet_WidgetSketchLabel.h | 7 +++ 11 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 src/GeomAPI/GeomAPI_Ellipse.cpp create mode 100644 src/GeomAPI/GeomAPI_Ellipse.h diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 3332171b0..d76e17b78 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -38,6 +38,7 @@ SET(PROJECT_HEADERS GeomAPI_Trsf.h GeomAPI_Angle2d.h GeomAPI_Wire.h + GeomAPI_Ellipse.h ) SET(PROJECT_SOURCES @@ -72,6 +73,7 @@ SET(PROJECT_SOURCES GeomAPI_Trsf.cpp GeomAPI_Angle2d.cpp GeomAPI_Wire.cpp + GeomAPI_Ellipse.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAPI/GeomAPI_Ax2.h b/src/GeomAPI/GeomAPI_Ax2.h index 1ad5bcc1a..2a740d114 100644 --- a/src/GeomAPI/GeomAPI_Ax2.h +++ b/src/GeomAPI/GeomAPI_Ax2.h @@ -56,4 +56,7 @@ public: std::shared_ptr dir() const; }; +//! Pointer on the object +typedef std::shared_ptr GeomAx2Ptr; + #endif diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h index 625ca3895..686b42ede 100644 --- a/src/GeomAPI/GeomAPI_Circ.h +++ b/src/GeomAPI/GeomAPI_Circ.h @@ -23,7 +23,8 @@ class GeomAPI_Circ : public GeomAPI_Interface { public: - /** \brief Constructs a circle of radius Radius, where theAx2 locates the circle and defines its orientation in 3D space such that:\n + /** \brief Constructs a circle of radius Radius, where theAx2 locates + * the circle and defines its orientation in 3D space such that:\n * - the center of the circle is the origin of theAx2;\n * - the origin, "X Direction" and "Y Direction" of theAx2 define the plane of the circle;\n * - theAx2 is the local coordinate system of the circle.\n diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h index 9231e58f7..542f7a5f9 100644 --- a/src/GeomAPI/GeomAPI_Dir.h +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -64,5 +64,8 @@ class GeomAPI_Dir : public GeomAPI_Interface }; +//! Pointer on the object +typedef std::shared_ptr GeomDirPtr; + #endif diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index 0ce634005..925e34ec7 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include @@ -21,9 +23,11 @@ #include #include #include +#include #include #include #include +#include #include @@ -82,6 +86,16 @@ bool GeomAPI_Edge::isArc() const return false; } +bool GeomAPI_Edge::isEllipse() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); + if (aCurve->IsKind(STANDARD_TYPE(Geom_Ellipse))) + return true; + return false; +} + std::shared_ptr GeomAPI_Edge::firstPoint() { const TopoDS_Shape& aShape = const_cast(this)->impl(); @@ -102,14 +116,14 @@ std::shared_ptr GeomAPI_Edge::lastPoint() return std::shared_ptr(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z())); } -std::shared_ptr GeomAPI_Edge::circle() +std::shared_ptr GeomAPI_Edge::circle() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); double aFirst, aLast; Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); - if (aCurve) { + if (!aCurve.IsNull()) { Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve); - if (aCirc) { + if (!aCirc.IsNull()) { gp_Pnt aLoc = aCirc->Location(); std::shared_ptr aCenter(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); gp_Dir anAxis = aCirc->Axis().Direction(); @@ -120,7 +134,24 @@ std::shared_ptr GeomAPI_Edge::circle() return std::shared_ptr(); // not circle } -std::shared_ptr GeomAPI_Edge::line() +std::shared_ptr GeomAPI_Edge::ellipse() const +{ + const TopoDS_Shape& aShape = const_cast(this)->impl(); + double aFirst, aLast; + Handle(Geom_Curve) aCurve = BRep_Tool::Curve((const TopoDS_Edge&)aShape, aFirst, aLast); + if (!aCurve.IsNull()) { + Handle(Geom_Ellipse) aElips = Handle(Geom_Ellipse)::DownCast(aCurve); + if (!aElips.IsNull()) { + gp_Elips aGpElips = aElips->Elips(); + std::shared_ptr aEllipse(new GeomAPI_Ellipse()); + aEllipse->setImpl(new gp_Elips(aGpElips)); + return aEllipse; + } + } + return std::shared_ptr(); // not elipse +} + +std::shared_ptr GeomAPI_Edge::line() const { const TopoDS_Shape& aShape = const_cast(this)->impl(); double aFirst, aLast; diff --git a/src/GeomAPI/GeomAPI_Edge.h b/src/GeomAPI/GeomAPI_Edge.h index 83eaad634..05ac002f1 100644 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@ -13,6 +13,7 @@ class GeomAPI_Pln; class GeomAPI_Pnt; class GeomAPI_Circ; class GeomAPI_Lin; +class GeomAPI_Ellipse; /**\class GeomAPI_Edge * \ingroup DataModel @@ -42,6 +43,10 @@ public: GEOMAPI_EXPORT bool isArc() const; + /// Verifies that the edge is an arc of circle + GEOMAPI_EXPORT + bool isEllipse() const; + /// Returns the first vertex coordinates of the edge GEOMAPI_EXPORT std::shared_ptr firstPoint(); @@ -52,11 +57,15 @@ public: /// Returns a circle if edge is based on the circle curve GEOMAPI_EXPORT - std::shared_ptr circle(); + std::shared_ptr circle() const; + + /// Returns an ellipse if edge is based on the ellipse curve + GEOMAPI_EXPORT + std::shared_ptr ellipse() const; /// Returns a line if edge is based on the linear curve GEOMAPI_EXPORT - std::shared_ptr line(); + std::shared_ptr line() const; /// Returns true if the current edge is geometrically equal to the given edge GEOMAPI_EXPORT @@ -75,5 +84,8 @@ public: double length() const; }; +//! Pointer on attribute object +typedef std::shared_ptr GeomEdgePtr; + #endif diff --git a/src/GeomAPI/GeomAPI_Ellipse.cpp b/src/GeomAPI/GeomAPI_Ellipse.cpp new file mode 100644 index 000000000..1eae6445f --- /dev/null +++ b/src/GeomAPI/GeomAPI_Ellipse.cpp @@ -0,0 +1,41 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAPI_Ellipse.cpp +// Created: 25 April 2017 +// Author: Vitaly Smetannikov + +#include "GeomAPI_Ellipse.h" +#include "GeomAPI_Ax2.h" +#include "GeomAPI_Pnt.h" + +#include + +#define MY_ELIPS implPtr() + +GeomAPI_Ellipse::GeomAPI_Ellipse(const std::shared_ptr& theAx2, + double theMajorRadius, double theMinorRadius) +: GeomAPI_Interface(new gp_Elips(theAx2->impl(), theMajorRadius, theMinorRadius)) +{ +} + +GeomPointPtr GeomAPI_Ellipse::firstFocus() const +{ + const gp_Pnt& aFirst = MY_ELIPS->Focus1(); + return std::shared_ptr(new GeomAPI_Pnt(aFirst.X(), aFirst.Y(), aFirst.Z())); +} + +GeomPointPtr GeomAPI_Ellipse::secondFocus() const +{ + const gp_Pnt& aSecond = MY_ELIPS->Focus2(); + return std::shared_ptr(new GeomAPI_Pnt(aSecond.X(), aSecond.Y(), aSecond.Z())); +} + +double GeomAPI_Ellipse::minorRadius() const +{ + return MY_ELIPS->MinorRadius(); +} + +double GeomAPI_Ellipse::majorRadius() const +{ + return MY_ELIPS->MajorRadius(); +} diff --git a/src/GeomAPI/GeomAPI_Ellipse.h b/src/GeomAPI/GeomAPI_Ellipse.h new file mode 100644 index 000000000..a855e189b --- /dev/null +++ b/src/GeomAPI/GeomAPI_Ellipse.h @@ -0,0 +1,55 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAPI_Ellipse.h +// Created: 25 April 2017 +// Author: Vitaly Smetannikov + +#ifndef GeomAPI_Ellipse_H_ +#define GeomAPI_Ellipse_H_ + +#include +#include + +class GeomAPI_Pnt; +class GeomAPI_Ax2; + + +/**\class GeomAPI_Ellipse + * \ingroup DataModel + * \brief Ellipse in 3D + */ +class GeomAPI_Ellipse : public GeomAPI_Interface +{ +public: + + /// \brief Constructs an epty ellipse + GEOMAPI_EXPORT GeomAPI_Ellipse() : GeomAPI_Interface() {} + + /** \brief Constructs an ellipse with major and minor radiuses, + * where theAx2 locates the ellipse and defines its orientation in 3D space such that:\n + * - the center of the circle is the origin of theAx2;\n + * - the origin, "X Direction" and "Y Direction" of theAx2 define the plane of the circle;\n + * - theAx2 is the local coordinate system of the circle.\n + * Note: It is possible to create a circle where Radius is equal to 0.0. raised if Radius < 0. + */ + GEOMAPI_EXPORT GeomAPI_Ellipse(const std::shared_ptr& theAx2, + double theMajorRadius, double theMinorRadius); + + /// Returns first center of the ellipse + GEOMAPI_EXPORT std::shared_ptr firstFocus() const; + + /// Returns second center of the ellipse + GEOMAPI_EXPORT std::shared_ptr secondFocus() const; + + /// Returns minor radius of the ellipse + GEOMAPI_EXPORT double minorRadius() const; + + /// Returns major radius of the ellipse + GEOMAPI_EXPORT double majorRadius() const; + +}; + +//! Pointer on the object +typedef std::shared_ptr GeomEllipsePtr; + +#endif diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index 137b6f729..6f9ee1df7 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -77,4 +77,7 @@ class GeomAPI_Pnt : public GeomAPI_Interface void translate(const std::shared_ptr& theDir, double theDist); }; +//! Pointer on the object +typedef std::shared_ptr GeomPointPtr; + #endif diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index 473f6e5d6..b3a05a35c 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include @@ -526,6 +528,9 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate) QIntList aModes; std::shared_ptr aPlane = plane(); if (aPlane.get()) { + //QList> aEdges = findCircularEdgesInPlane(); + //foreach(std::shared_ptr aPrs, aEdges) { + //} myWorkshop->module()->activeSelectionModes(aModes); } else { @@ -605,3 +610,47 @@ void PartSet_WidgetSketchLabel::onSetPlaneView() aModule->onViewTransformed(); } } + + +//****************************************************** +QList> PartSet_WidgetSketchLabel::findCircularEdgesInPlane() +{ + QList> aResult; + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + QObjectPtrList aDispObjects = aDisplayer->displayedObjects(); + + std::shared_ptr aPlane = plane(); + foreach(ObjectPtr aObj, aDispObjects) { + ResultPtr aResObj = std::dynamic_pointer_cast(aObj); + if (aResObj.get()) { + GeomShapePtr aShape = aResObj->shape(); + if (aShape.get()) { + GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE); + for(; aExplorer.more(); aExplorer.next()) { + GeomShapePtr aEdgeShape = aExplorer.current(); + GeomAPI_Edge anEdge(aEdgeShape); + if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) && + anEdge.isInPlane(aPlane)) { + bool isContains = false; + // Check that edge is not used. + // It is possible that the same edge will be taken from different faces + foreach(std::shared_ptr aPrs, aResult) { + GeomAPI_Edge aUsedEdge(aPrs->shape()); + if (aUsedEdge.isEqual(aEdgeShape)) { + isContains = true; + break; + } + } + if (!isContains) { + std::shared_ptr + aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape)); + aResult.append(aPrs); + } + } + } + } + } + } + return aResult; +} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 7e0a1c73e..6a3aa4462 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -178,6 +178,13 @@ protected: /// \param thePlane a plane std::shared_ptr setSketchPlane(std::shared_ptr thePlane); + /** + * Returns list of presentations which have displayed shapes with circular edges + * (circles, arcs) which are in pane of of the given sketch + * \param theSketch - the sketch + */ + QList> findCircularEdgesInPlane(); + private: /// class to show/hide preview planes PartSet_PreviewPlanes* myPreviewPlanes; -- 2.39.2