From 6cb54607705e4880cb22a8dd99cf211492d1d087 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Wed, 22 Mar 2017 08:22:03 +0100 Subject: [PATCH] Add "Torus" primitive and "Cone" primitive. --- src/GeomAlgoAPI/CMakeLists.txt | 4 + src/GeomAlgoAPI/GeomAlgoAPI_Cone.cpp | 86 ++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Cone.h | 46 ++++++ src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp | 2 - src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp | 134 +++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h | 34 +++- src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp | 78 +++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Torus.h | 43 +++++ src/PrimitivesAPI/CMakeLists.txt | 4 + src/PrimitivesAPI/PrimitivesAPI.i | 4 + src/PrimitivesAPI/PrimitivesAPI_Cone.cpp | 105 ++++++++++++ src/PrimitivesAPI/PrimitivesAPI_Cone.h | 90 +++++++++++ src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp | 12 +- src/PrimitivesAPI/PrimitivesAPI_Torus.cpp | 91 +++++++++++ src/PrimitivesAPI/PrimitivesAPI_Torus.h | 81 ++++++++++ src/PrimitivesAPI/PrimitivesAPI_swig.h | 2 + src/PrimitivesPlugin/CMakeLists.txt | 6 + .../PrimitivesPlugin_Cone.cpp | 153 ++++++++++++++++++ src/PrimitivesPlugin/PrimitivesPlugin_Cone.h | 88 ++++++++++ .../PrimitivesPlugin_Plugin.cpp | 6 + .../PrimitivesPlugin_Torus.cpp | 149 +++++++++++++++++ src/PrimitivesPlugin/PrimitivesPlugin_Torus.h | 81 ++++++++++ src/PrimitivesPlugin/cone_widget.xml | 46 ++++++ src/PrimitivesPlugin/icons/SVG/cone.svg | 123 ++++++++++++++ src/PrimitivesPlugin/icons/SVG/torus.svg | 142 ++++++++++++++++ src/PrimitivesPlugin/icons/cone.png | Bin 0 -> 677 bytes src/PrimitivesPlugin/icons/torus.png | Bin 0 -> 845 bytes src/PrimitivesPlugin/plugin-Primitives.xml | 10 ++ src/PrimitivesPlugin/torus_widget.xml | 38 +++++ src/PythonAPI/model/primitives/__init__.py | 2 +- 30 files changed, 1650 insertions(+), 10 deletions(-) create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Cone.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Cone.h create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Torus.h create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Cone.cpp create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Cone.h create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Torus.cpp create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Torus.h create mode 100644 src/PrimitivesPlugin/PrimitivesPlugin_Cone.cpp create mode 100644 src/PrimitivesPlugin/PrimitivesPlugin_Cone.h create mode 100644 src/PrimitivesPlugin/PrimitivesPlugin_Torus.cpp create mode 100644 src/PrimitivesPlugin/PrimitivesPlugin_Torus.h create mode 100644 src/PrimitivesPlugin/cone_widget.xml create mode 100644 src/PrimitivesPlugin/icons/SVG/cone.svg create mode 100644 src/PrimitivesPlugin/icons/SVG/torus.svg create mode 100644 src/PrimitivesPlugin/icons/cone.png create mode 100644 src/PrimitivesPlugin/icons/torus.png create mode 100644 src/PrimitivesPlugin/torus_widget.xml diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index f3390147c..0ad49ca0f 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -42,8 +42,10 @@ SET(PROJECT_HEADERS GeomAlgoAPI_ShapeAPI.h GeomAlgoAPI_Exception.h GeomAlgoAPI_Box.h + GeomAlgoAPI_Cone.h GeomAlgoAPI_Cylinder.h GeomAlgoAPI_Sphere.h + GeomAlgoAPI_Torus.h GeomAlgoAPI_XAOExport.h GeomAlgoAPI_XAOImport.h GeomAlgoAPI_Copy.h @@ -88,8 +90,10 @@ SET(PROJECT_SOURCES GeomAlgoAPI_ShapeAPI.cpp GeomAlgoAPI_Exception.cpp GeomAlgoAPI_Box.cpp + GeomAlgoAPI_Cone.cpp GeomAlgoAPI_Cylinder.cpp GeomAlgoAPI_Sphere.cpp + GeomAlgoAPI_Torus.cpp GeomAlgoAPI_XAOExport.cpp GeomAlgoAPI_XAOImport.cpp GeomAlgoAPI_Copy.cpp diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cone.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Cone.cpp new file mode 100644 index 000000000..5d9be8c86 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cone.cpp @@ -0,0 +1,86 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Cone.cpp +// Created: 20 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include + +#include + +//================================================================================================= +GeomAlgoAPI_Cone::GeomAlgoAPI_Cone() +{ +} + +//================================================================================================= +GeomAlgoAPI_Cone::GeomAlgoAPI_Cone(std::shared_ptr theAxis, + const double theBaseRadius, + const double theTopRadius, + const double theHeight) +{ + myAxis = theAxis; + myBaseRadius = theBaseRadius; + myTopRadius = theTopRadius; + myHeight = theHeight; +} + +//================================================================================================= +bool GeomAlgoAPI_Cone::check() +{ + if (!myAxis) { + myError = "Cone builder :: axis is not valid."; + return false; + } else if (myBaseRadius < Precision::Confusion() && myTopRadius < Precision::Confusion()) { + myError = "Cone builder :: base radius and top radius are negative or null."; + return false; + } else if (myBaseRadius < 0.) { + myError = "Cone builder :: base radius is negative."; + return false; + } else if (myTopRadius < 0.) { + myError = "Cone builder :: top radius is negative."; + return false; + } else if (fabs(myBaseRadius-myTopRadius) < Precision::Confusion()) { + myError = "Cone builder :: base radius and top radius are too close."; + return false; + } else if (myHeight < Precision::Confusion()) { + myError = "Cone builder :: height is negative or null."; + return false; + } + return true; +} + +//================================================================================================= +void GeomAlgoAPI_Cone::build() +{ + myCreatedFaces.clear(); + + const gp_Ax2& anAxis = myAxis->impl(); + + // Construct the torus + BRepPrimAPI_MakeCone *aConeMaker = + new BRepPrimAPI_MakeCone(anAxis, myBaseRadius, myTopRadius, myHeight); + + aConeMaker->Build(); + + if (!aConeMaker->IsDone()) { + return; + } + + TopoDS_Shape aResult = aConeMaker->Shape(); + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + setShape(aShape); + + // Test on the shapes + if (!aShape.get() || aShape->isNull()) { + myError = "Torus builder :: resulting shape is null."; + return; + } + + setImpl(aConeMaker); + + setDone(true); +} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cone.h b/src/GeomAlgoAPI/GeomAlgoAPI_Cone.h new file mode 100644 index 000000000..327ef6bbc --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cone.h @@ -0,0 +1,46 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Cone.h +// Created: 20 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef GEOMALGOAPI_CONE_H_ +#define GEOMALGOAPI_CONE_H_ + +#include + +#include + +/**\class GeomAlgoAPI_Cone + * \ingroup DataAlgo + * \brief Allows to create Cone Primitives + */ +class GeomAlgoAPI_Cone : public GeomAlgoAPI_MakeShape +{ + public: + GEOMALGOAPI_EXPORT GeomAlgoAPI_Cone(); + + /// Creates a cone. + /// \param theAxis The axis of the cone + /// \param theBaseRadius The base radius of the cone + /// \param theTopRadius The top radius of the cone + /// \param theHeight The height of the cone + GEOMALGOAPI_EXPORT GeomAlgoAPI_Cone(std::shared_ptr theAxis, + const double theBaseRadius, + const double theTopRadius, + const double theHeight); + + /// Checks if data for the cone construction is OK. + GEOMALGOAPI_EXPORT bool check(); + + /// Builds the cone. + GEOMALGOAPI_EXPORT void build(); + + private: + std::shared_ptr myAxis; /// Axis of the cone. + double myBaseRadius; /// Base radius of the cone. + double myTopRadius; /// Top radius of the cone. + double myHeight; /// Height of the cone. +}; + +#endif // GEOMALGOAPI_CONE_H_ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp index a7512d382..a3d64ae63 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp @@ -13,8 +13,6 @@ #include -#include - //================================================================================================= GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder() { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index e02a28cc5..5fdeaee50 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -240,6 +242,138 @@ namespace GeomAlgoAPI_ShapeAPI return aSphereAlgo.shape(); } + //=============================================================================================== + std::shared_ptr makeTorus(std::shared_ptr theBasePoint, + std::shared_ptr theEdge, + double theRadius, double theRingRadius) + throw (GeomAlgoAPI_Exception) + { + // Check if the base point is OK + if (!theBasePoint) { + throw GeomAlgoAPI_Exception("Torus builder :: the base point is not valid."); + } + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Torus builder :: the axis is not valid."); + } + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius); + + if (!aTorusAlgo.check()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + aTorusAlgo.build(); + + if(!aTorusAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + if (!aTorusAlgo.checkValid("Torus builder")) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + return aTorusAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr makeTorus(double theRadius, double theRingRadius) + throw (GeomAlgoAPI_Exception) + { + std::shared_ptr aBasePoint = + std::shared_ptr(new GeomAPI_Pnt(0.,0.,0.)); + std::shared_ptr aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.); + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, + aEdge->line()->direction())); + + GeomAlgoAPI_Torus aTorusAlgo(anAxis, theRadius, theRingRadius); + + if (!aTorusAlgo.check()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + aTorusAlgo.build(); + + if(!aTorusAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + + if (!aTorusAlgo.checkValid("Torus builder")) { + throw GeomAlgoAPI_Exception(aTorusAlgo.getError()); + } + return aTorusAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr makeCone(std::shared_ptr theBasePoint, + std::shared_ptr theEdge, + double theBaseRadius, double theTopRadius, + double theHeight) throw (GeomAlgoAPI_Exception) + { + // Check if the base point is OK + if (!theBasePoint) { + throw GeomAlgoAPI_Exception("Cone builder :: the base point is not valid."); + } + // Check if the edge is OK + if (!theEdge) { + throw GeomAlgoAPI_Exception("Cone builder :: the axis is not valid."); + } + + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight); + + if (!aConeAlgo.check()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + aConeAlgo.build(); + + if(!aConeAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + if (!aConeAlgo.checkValid("Cone builder")) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + return aConeAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr makeCone(double theBaseRadius, double theTopRadius, + double theHeight) throw (GeomAlgoAPI_Exception) + { + std::shared_ptr aBasePoint = + std::shared_ptr(new GeomAPI_Pnt(0.,0.,0.)); + std::shared_ptr aEdge = GeomAlgoAPI_EdgeBuilder::line(0., 0., 1.); + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, + aEdge->line()->direction())); + + GeomAlgoAPI_Cone aConeAlgo(anAxis, theBaseRadius, theTopRadius, theHeight); + + if (!aConeAlgo.check()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + aConeAlgo.build(); + + if(!aConeAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + + if (!aConeAlgo.checkValid("Cone builder")) { + throw GeomAlgoAPI_Exception(aConeAlgo.getError()); + } + return aConeAlgo.shape(); + } + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h index 1743e6d66..d7bd12034 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h @@ -78,10 +78,42 @@ public: double theRadius) throw (GeomAlgoAPI_Exception); /// Creates a sphere using the origin and a radius. - /// \param theRadius The radius of the cylinder + /// \param theRadius The radius of the sphere static std::shared_ptr makeSphere(double theRadius) throw (GeomAlgoAPI_Exception); + /// Creates a torus using a base point, an axis, a radius and a ring radius. + /// \param theBasePoint The center of the torus + /// \param theEdge The axis of the torus + /// \param theRadius The radius of the torus + /// \param theRingRadius The ring radius of the torus + static std::shared_ptr makeTorus(std::shared_ptr theBasePoint, + std::shared_ptr theEdge, double theRadius, double theRingRadius) + throw (GeomAlgoAPI_Exception); + + /// Creates a torus using a radius and a ring radius. + /// \param theRadius The radius of the torus + /// \param theRingRadius The ring radius of the torus + static std::shared_ptr makeTorus(double theRadius, double theRingRadius) + throw (GeomAlgoAPI_Exception); + + /// Creates a cone using a base point, an axis, a base radius, a top radius and a height. + /// \param theBasePoint The center of the lower base of the cone + /// \param theEdge The axis of the cone + /// \param theBaseRadius The base radius of the cone + /// \param theTopRadius The top radius of the cone + /// \param theHeight The height of the cone + static std::shared_ptr makeCone(std::shared_ptr theBasePoint, + std::shared_ptr theEdge, double theBaseRadius, + double theTopRadius, double theHeight) throw (GeomAlgoAPI_Exception); + + /// Creates a cone using a base radius, a top radius and a height. + /// \param theBaseRadius The base radius of the cone + /// \param theTopRadius The top radius of the cone + /// \param theHeight The height of the cone + static std::shared_ptr makeCone(double theBaseRadius, double theTopRadius, + double theHeight) throw (GeomAlgoAPI_Exception); + /// Performs a translation from an axis and a distance. /// \param theSourceShape Shape to be moved /// \param theAxis Movement axis diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp new file mode 100644 index 000000000..3bc0653d8 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Torus.cpp @@ -0,0 +1,78 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Torus.cpp +// Created: 20 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include + +#include + +//================================================================================================= +GeomAlgoAPI_Torus::GeomAlgoAPI_Torus() +{ +} + +//================================================================================================= +GeomAlgoAPI_Torus::GeomAlgoAPI_Torus(std::shared_ptr theAxis, + const double theRadius, + const double theRingRadius) +{ + myAxis = theAxis; + myRadius = theRadius; + myRingRadius = theRingRadius; +} + +//================================================================================================= +bool GeomAlgoAPI_Torus::check() +{ + if (!myAxis) { + myError = "Torus builder :: axis is not valid."; + return false; + } else if (myRadius < Precision::Confusion()) { + myError = "Torus builder :: radius is negative or null."; + return false; + } else if (myRingRadius < Precision::Confusion()) { + myError = "Torus builder :: ring radius is negative or null."; + return false; + } else if (myRadius < myRingRadius) { + myError = "Torus builder :: ring radius is greater than the radius."; + return false; + } + return true; +} + +//================================================================================================= +void GeomAlgoAPI_Torus::build() +{ + myCreatedFaces.clear(); + + const gp_Ax2& anAxis = myAxis->impl(); + + // Construct the torus + BRepPrimAPI_MakeTorus *aTorusMaker = + new BRepPrimAPI_MakeTorus(anAxis, myRadius, myRingRadius); + + aTorusMaker->Build(); + + if (!aTorusMaker->IsDone()) { + return; + } + + TopoDS_Shape aResult = aTorusMaker->Shape(); + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + setShape(aShape); + + // Test on the shapes + if (!aShape.get() || aShape->isNull()) { + myError = "Torus builder :: resulting shape is null."; + return; + } + + setImpl(aTorusMaker); + + setDone(true); +} \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Torus.h b/src/GeomAlgoAPI/GeomAlgoAPI_Torus.h new file mode 100644 index 000000000..10f66f53e --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Torus.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Torus.h +// Created: 20 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef GEOMALGOAPI_TORUS_H_ +#define GEOMALGOAPI_TORUS_H_ + +#include + +#include + +/**\class GeomAlgoAPI_Torus + * \ingroup DataAlgo + * \brief Allows to create Torus Primitives + */ +class GeomAlgoAPI_Torus : public GeomAlgoAPI_MakeShape +{ + public: + GEOMALGOAPI_EXPORT GeomAlgoAPI_Torus(); + + /// Creates a torus. + /// \param theAxis The axis of the torus + /// \param theRadius The radius of the torus + /// \param theRingRadius The ring radius of the torus + GEOMALGOAPI_EXPORT GeomAlgoAPI_Torus(std::shared_ptr theAxis, + const double theRadius, + const double theRingRadius); + + /// Checks if data for the torus construction is OK. + GEOMALGOAPI_EXPORT bool check(); + + /// Builds the torus. + GEOMALGOAPI_EXPORT void build(); + + private: + std::shared_ptr myAxis; /// Axis of the torus. + double myRadius; /// Radius of the torus. + double myRingRadius; /// Ring radius of the torus. +}; + +#endif // GEOMALGOAPI_TORUS_H_ \ No newline at end of file diff --git a/src/PrimitivesAPI/CMakeLists.txt b/src/PrimitivesAPI/CMakeLists.txt index cbe3c9aad..83a1426f3 100644 --- a/src/PrimitivesAPI/CMakeLists.txt +++ b/src/PrimitivesAPI/CMakeLists.txt @@ -5,14 +5,18 @@ INCLUDE(Common) SET(PROJECT_HEADERS PrimitivesAPI.h PrimitivesAPI_Box.h + PrimitivesAPI_Cone.h PrimitivesAPI_Cylinder.h PrimitivesAPI_Sphere.h + PrimitivesAPI_Torus.h ) SET(PROJECT_SOURCES PrimitivesAPI_Box.cpp + PrimitivesAPI_Cone.cpp PrimitivesAPI_Cylinder.cpp PrimitivesAPI_Sphere.cpp + PrimitivesAPI_Torus.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/PrimitivesAPI/PrimitivesAPI.i b/src/PrimitivesAPI/PrimitivesAPI.i index d708a40cd..1651b0788 100644 --- a/src/PrimitivesAPI/PrimitivesAPI.i +++ b/src/PrimitivesAPI/PrimitivesAPI.i @@ -20,10 +20,14 @@ // shared pointers %shared_ptr(PrimitivesAPI_Box) +%shared_ptr(PrimitivesAPI_Cone) %shared_ptr(PrimitivesAPI_Cylinder) %shared_ptr(PrimitivesAPI_Sphere) +%shared_ptr(PrimitivesAPI_Torus) // all supported interfaces %include "PrimitivesAPI_Box.h" +%include "PrimitivesAPI_Cone.h" %include "PrimitivesAPI_Cylinder.h" %include "PrimitivesAPI_Sphere.h" +%include "PrimitivesAPI_Torus.h" diff --git a/src/PrimitivesAPI/PrimitivesAPI_Cone.cpp b/src/PrimitivesAPI/PrimitivesAPI_Cone.cpp new file mode 100644 index 000000000..da564cc8b --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Cone.cpp @@ -0,0 +1,105 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D --> + +// File: PrimitivesAPI_Cone.cpp +// Created: 20 Mar 2017 +// Author: Clarisse Genrault + +#include "PrimitivesAPI_Cone.h" + +#include +#include +#include + +//================================================================================================== +PrimitivesAPI_Cone::PrimitivesAPI_Cone(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +PrimitivesAPI_Cone::PrimitivesAPI_Cone(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius, + const ModelHighAPI_Double& theHeight) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(theBasePoint, basePoint()); + fillAttribute(theAxis, axis()); + fillAttribute(theBaseRadius, baseRadius()); + fillAttribute(theTopRadius, topRadius()); + setHeight(theHeight); + } +} + +//================================================================================================== +PrimitivesAPI_Cone::~PrimitivesAPI_Cone() +{ +} + +//================================================================================================== +void PrimitivesAPI_Cone::setRadius(const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius) +{ + fillAttribute(theBaseRadius, baseRadius()); + fillAttribute(theTopRadius, topRadius()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Cone::setHeight(const ModelHighAPI_Double& theHeight) +{ + fillAttribute(theHeight, height()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Cone::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + theDumper << aBase << " = model.addCone(" << aDocName; + + AttributeSelectionPtr anAttrBasePoint = + aBase->selection(PrimitivesPlugin_Cone::BASE_POINT_ID()); + AttributeSelectionPtr anAttrAxis = + aBase->selection(PrimitivesPlugin_Cone::AXIS_ID()); + theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis; + + AttributeDoublePtr anAttrBaseRadius = aBase->real(PrimitivesPlugin_Cone::BASE_RADIUS_ID()); + AttributeDoublePtr anAttrTopRadius = aBase->real(PrimitivesPlugin_Cone::TOP_RADIUS_ID()); + AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cone::HEIGHT_ID()); + theDumper << ", " << anAttrBaseRadius << ", " << anAttrTopRadius << ", " << anAttrHeight; + + theDumper << ")" << std::endl; +} + +//================================================================================================== +ConePtr addCone(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius, + const ModelHighAPI_Double& theHeight) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cone::ID()); + return ConePtr(new PrimitivesAPI_Cone(aFeature, theBasePoint, theAxis, theBaseRadius, + theTopRadius, theHeight)); +} + +//================================================================================================== +ConePtr addCone(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius, + const ModelHighAPI_Double& theHeight) +{ + ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin"); + ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ"); + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cone::ID()); + return ConePtr(new PrimitivesAPI_Cone(aFeature, aBasePoint, anAxis, theBaseRadius, + theTopRadius, theHeight)); +} \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI_Cone.h b/src/PrimitivesAPI/PrimitivesAPI_Cone.h new file mode 100644 index 000000000..a83f78ae6 --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Cone.h @@ -0,0 +1,90 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D --> + +// File: PrimitivesAPI_Cone.h +// Created: 20 Mar 2017 +// Author: Clarisse Genrault + +#ifndef PRIMITIVESAPI_CONE_H_ +#define PRIMITIVESAPI_CONE_H_ + +#include "PrimitivesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class PrimitivesAPI_Cone +/// \ingroup CPPHighAPI +/// \brief Interface for primitive Cone feature. +class PrimitivesAPI_Cone: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Cone(const std::shared_ptr& theFeature); + + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Cone(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius, + const ModelHighAPI_Double& theHeight); + + /// Destructor. + PRIMITIVESAPI_EXPORT + virtual ~PrimitivesAPI_Cone(); + + INTERFACE_5(PrimitivesPlugin_Cone::ID(), + basePoint, PrimitivesPlugin_Cone::BASE_POINT_ID(), + ModelAPI_AttributeSelection, /** Base point */, + axis, PrimitivesPlugin_Cone::AXIS_ID(), + ModelAPI_AttributeSelection, /** Axis */, + baseRadius, PrimitivesPlugin_Cone::BASE_RADIUS_ID(), + ModelAPI_AttributeDouble, /** Base radius */, + topRadius, PrimitivesPlugin_Cone::TOP_RADIUS_ID(), + ModelAPI_AttributeDouble, /** Top radius */, + height, PrimitivesPlugin_Cone::HEIGHT_ID(), + ModelAPI_AttributeDouble, /** Height */) + + /// Set radius + PRIMITIVESAPI_EXPORT + void setRadius(const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius); + + /// Set height + PRIMITIVESAPI_EXPORT + void setHeight(const ModelHighAPI_Double& theHeight); + + /// Dump wrapped feature + PRIMITIVESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on primitive Cone object +typedef std::shared_ptr ConePtr; + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cone feature. +PRIMITIVESAPI_EXPORT +ConePtr addCone(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius, + const ModelHighAPI_Double& theHeight); + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cone feature. +PRIMITIVESAPI_EXPORT +ConePtr addCone(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theBaseRadius, + const ModelHighAPI_Double& theTopRadius, + const ModelHighAPI_Double& theHeight); + +#endif // PRIMITIVESAPI_CONE_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp index eaba588f7..dc8b6aba6 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp +++ b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp @@ -19,14 +19,14 @@ PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr& theFeature, - const ModelHighAPI_Selection& theCenterPoint, - const ModelHighAPI_Double& theRadius) + const ModelHighAPI_Selection& theCenterPoint, + const ModelHighAPI_Double& theRadius) : ModelHighAPI_Interface(theFeature) { - if (initialize()) { - fillAttribute(theCenterPoint, centerPoint()); - setRadius(theRadius); - } + if (initialize()) { + fillAttribute(theCenterPoint, centerPoint()); + setRadius(theRadius); + } } //================================================================================================== diff --git a/src/PrimitivesAPI/PrimitivesAPI_Torus.cpp b/src/PrimitivesAPI/PrimitivesAPI_Torus.cpp new file mode 100644 index 000000000..825c2b9ae --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Torus.cpp @@ -0,0 +1,91 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D --> + +// File: PrimitivesAPI_Torus.cpp +// Created: 20 Mar 2017 +// Author: Clarisse Genrault + +#include "PrimitivesAPI_Torus.h" + +#include +#include +#include + +//================================================================================================== +PrimitivesAPI_Torus::PrimitivesAPI_Torus(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +PrimitivesAPI_Torus::PrimitivesAPI_Torus(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(theBasePoint, basePoint()); + fillAttribute(theAxis, axis()); + setRadius(theRadius, theRingRadius); + } +} + +//================================================================================================== +PrimitivesAPI_Torus::~PrimitivesAPI_Torus() +{ +} + +//================================================================================================== +void PrimitivesAPI_Torus::setRadius(const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius) +{ + fillAttribute(theRadius, radius()); + fillAttribute(theRingRadius, ringRadius()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Torus::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + theDumper << aBase << " = model.addTorus(" << aDocName; + + AttributeSelectionPtr anAttrBasePoint = + aBase->selection(PrimitivesPlugin_Torus::BASE_POINT_ID()); + AttributeSelectionPtr anAttrAxis = + aBase->selection(PrimitivesPlugin_Torus::AXIS_ID()); + theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis; + + AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Torus::RADIUS_ID()); + AttributeDoublePtr anAttrRingRadius = aBase->real(PrimitivesPlugin_Torus::RING_RADIUS_ID()); + theDumper << ", " << anAttrRadius << ", " << anAttrRingRadius; + + theDumper << ")" << std::endl; +} + +//================================================================================================== +TorusPtr addTorus(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID()); + return TorusPtr(new PrimitivesAPI_Torus(aFeature, theBasePoint, theAxis, + theRadius, theRingRadius)); +} + +//================================================================================================== +TorusPtr addTorus(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius) +{ + ModelHighAPI_Selection aBasePoint("VERTEX", "PartSet/Origin"); + ModelHighAPI_Selection anAxis("EDGE", "PartSet/OZ"); + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Torus::ID()); + return TorusPtr(new PrimitivesAPI_Torus(aFeature, aBasePoint, anAxis, theRadius, theRingRadius)); +} \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI_Torus.h b/src/PrimitivesAPI/PrimitivesAPI_Torus.h new file mode 100644 index 000000000..32c7d101f --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Torus.h @@ -0,0 +1,81 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D --> + +// File: PrimitivesAPI_Torus.h +// Created: 20 Mar 2017 +// Author: Clarisse Genrault + +#ifndef PRIMITIVESAPI_TORUS_H_ +#define PRIMITIVESAPI_TORUS_H_ + +#include "PrimitivesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class PrimitivesAPI_Torus +/// \ingroup CPPHighAPI +/// \brief Interface for primitive Cone feature. +class PrimitivesAPI_Torus: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Torus(const std::shared_ptr& theFeature); + + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Torus(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius); + + /// Destructor. + PRIMITIVESAPI_EXPORT + virtual ~PrimitivesAPI_Torus(); + + INTERFACE_4(PrimitivesPlugin_Torus::ID(), + basePoint, PrimitivesPlugin_Torus::BASE_POINT_ID(), + ModelAPI_AttributeSelection, /** Base point */, + axis, PrimitivesPlugin_Torus::AXIS_ID(), + ModelAPI_AttributeSelection, /** Axis */, + radius, PrimitivesPlugin_Torus::RADIUS_ID(), + ModelAPI_AttributeDouble, /** Radius */, + ringRadius, PrimitivesPlugin_Torus::RING_RADIUS_ID(), + ModelAPI_AttributeDouble, /** Ring radius */) + + /// Set radius + PRIMITIVESAPI_EXPORT + void setRadius(const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius); + + /// Dump wrapped feature + PRIMITIVESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on primitive Cone object +typedef std::shared_ptr TorusPtr; + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cone feature. +PRIMITIVESAPI_EXPORT +TorusPtr addTorus(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius); + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cone feature. +PRIMITIVESAPI_EXPORT +TorusPtr addTorus(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theRingRadius); + +#endif // PRIMITIVESAPI_TORUS_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_swig.h b/src/PrimitivesAPI/PrimitivesAPI_swig.h index 04b3e3716..698317f03 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_swig.h +++ b/src/PrimitivesAPI/PrimitivesAPI_swig.h @@ -11,7 +11,9 @@ #include "PrimitivesAPI.h" #include "PrimitivesAPI_Box.h" + #include "PrimitivesAPI_Cone.h" #include "PrimitivesAPI_Cylinder.h" #include "PrimitivesAPI_Sphere.h" + #include "PrimitivesAPI_Torus.h" #endif // PRIMITIVESAPI_SWIG_H_ diff --git a/src/PrimitivesPlugin/CMakeLists.txt b/src/PrimitivesPlugin/CMakeLists.txt index 8df0d67db..cfbf18609 100644 --- a/src/PrimitivesPlugin/CMakeLists.txt +++ b/src/PrimitivesPlugin/CMakeLists.txt @@ -8,22 +8,28 @@ SET(PROJECT_HEADERS PrimitivesPlugin.h PrimitivesPlugin_Plugin.h PrimitivesPlugin_Box.h + PrimitivesPlugin_Cone.h PrimitivesPlugin_Cylinder.h PrimitivesPlugin_Sphere.h + PrimitivesPlugin_Torus.h ) SET(PROJECT_SOURCES PrimitivesPlugin_Plugin.cpp PrimitivesPlugin_Box.cpp + PrimitivesPlugin_Cone.cpp PrimitivesPlugin_Cylinder.cpp PrimitivesPlugin_Sphere.cpp + PrimitivesPlugin_Torus.cpp ) SET(XML_RESOURCES plugin-Primitives.xml box_widget.xml + cone_widget.xml cylinder_widget.xml sphere_widget.xml + torus_widget.xml ) INCLUDE_DIRECTORIES( diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cone.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Cone.cpp new file mode 100644 index 000000000..fba4eb498 --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Cone.cpp @@ -0,0 +1,153 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: PrimitivesPlugin_Cone.cpp +// Created: 17 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +//================================================================================================= +PrimitivesPlugin_Cone::PrimitivesPlugin_Cone() +{ +} + +//================================================================================================= +void PrimitivesPlugin_Cone::initAttributes() +{ + data()->addAttribute(PrimitivesPlugin_Cone::BASE_POINT_ID(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(PrimitivesPlugin_Cone::AXIS_ID(), + ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(PrimitivesPlugin_Cone::BASE_RADIUS_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Cone::TOP_RADIUS_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Cone::HEIGHT_ID(), + ModelAPI_AttributeDouble::typeId()); + + // Initialize the base point of the cone at the origin if the base point is not filled. + AttributeSelectionPtr aCenterPoint = + data()->selection(PrimitivesPlugin_Cone::BASE_POINT_ID()); + if (!aCenterPoint->isInitialized()) { + ObjectPtr aPointObj = ModelAPI_Session::get()->moduleDocument() + ->objectByName(ModelAPI_ResultConstruction::group(), "Origin"); + if (aPointObj.get()) { + ResultPtr aPointRes = std::dynamic_pointer_cast(aPointObj); + aCenterPoint->setValue(aPointRes, std::shared_ptr()); + } + } + + // Initialize the axis at the OZ axis if the axis is not filled. + AttributeSelectionPtr anAxis = data()->selection(PrimitivesPlugin_Cone::AXIS_ID()); + if (!anAxis->isInitialized()) { + ObjectPtr anAxisObj = ModelAPI_Session::get()->moduleDocument() + ->objectByName(ModelAPI_ResultConstruction::group(), "OZ"); + if (anAxisObj.get()) { + ResultPtr anAxisRes = std::dynamic_pointer_cast(anAxisObj); + anAxis->setValue(anAxisRes, std::shared_ptr()); + } + } +} + +//================================================================================================= +void PrimitivesPlugin_Cone::execute() +{ + // Getting base point. + std::shared_ptr aBasePoint; + std::shared_ptr aPointRef = + selection(PrimitivesPlugin_Cone::BASE_POINT_ID()); + if (aPointRef.get() != NULL) { + GeomShapePtr aShape1 = aPointRef->value(); + if (!aShape1.get()) { + aShape1 = aPointRef->context()->shape(); + } + if (aShape1) { + aBasePoint = GeomAlgoAPI_PointBuilder::point(aShape1); + } + } + + // Getting axis. + std::shared_ptr anAxis; + std::shared_ptr anEdge; + std::shared_ptr anEdgeRef = + selection(PrimitivesPlugin_Cone::AXIS_ID()); + if(anEdgeRef && anEdgeRef->value() && anEdgeRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anEdgeRef->value())); + } else if (anEdgeRef && !anEdgeRef->value() && anEdgeRef->context() && + anEdgeRef->context()->shape() && anEdgeRef->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anEdgeRef->context()->shape())); + } + if(anEdge) { + anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, + anEdge->line()->direction())); + } + + // Getting base radius, top radius and height + double aBaseRadius = real(PrimitivesPlugin_Cone::BASE_RADIUS_ID())->value(); + double aTopRadius = real(PrimitivesPlugin_Cone::TOP_RADIUS_ID())->value(); + double aHeight = real(PrimitivesPlugin_Cone::HEIGHT_ID())->value(); + + std::shared_ptr aConeAlgo = + std::shared_ptr(new GeomAlgoAPI_Cone(anAxis, + aBaseRadius, + aTopRadius, + aHeight)); + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aConeAlgo->check()) { + setError(aConeAlgo->getError()); + return; + } + + // Build the sphere + aConeAlgo->build(); + + // Check if the creation of the cylinder + if(!aConeAlgo->isDone()) { + setError(aConeAlgo->getError()); + return; + } + if(!aConeAlgo->checkValid("Cone builder")) { + setError(aConeAlgo->getError()); + return; + } + + int aResultIndex = 0; + ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); + loadNamingDS(aConeAlgo, aResultBox); + setResult(aResultBox, aResultIndex); +} + +//================================================================================================= +void PrimitivesPlugin_Cone::loadNamingDS(std::shared_ptr theConeAlgo, + std::shared_ptr theResultCone) +{ + // Load the result + theResultCone->store(theConeAlgo->shape()); + + // Prepare the naming + theConeAlgo->prepareNamingFaces(); + + // Insert to faces + int num = 1; + std::map< std::string, std::shared_ptr > listOfFaces = + theConeAlgo->getCreatedFaces(); + for (std::map< std::string, std::shared_ptr >::iterator + it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) { + std::shared_ptr aFace = (*it).second; + theResultCone->generated(aFace, (*it).first, num++); + } +} \ No newline at end of file diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cone.h b/src/PrimitivesPlugin/PrimitivesPlugin_Cone.h new file mode 100644 index 000000000..9cbc0b1af --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Cone.h @@ -0,0 +1,88 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: PrimitivesPlugin_Cone.h +// Created: 17 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef PRIMITIVESPLUGIN_CONE_H_ +#define PRIMITIVESPLUGIN_CONE_H_ + +#include +#include +#include + +/**\class PrimitivesPlugin_Cone + * \ingroup Plugins + * \brief Feature for creation of a cone. + * + * Creates a cone from a + */ +class PrimitivesPlugin_Cone : public ModelAPI_Feature +{ + public: + /// Cone kind + inline static const std::string& ID() + { + static const std::string MY_CONE_ID("Cone"); + return MY_CONE_ID; + } + + /// Attribute name of the base point + inline static const std::string& BASE_POINT_ID() + { + static const std::string MY_BASE_POINT_ID("base_point"); + return MY_BASE_POINT_ID; + } + + /// Attribute name of the axis + inline static const std::string& AXIS_ID() + { + static const std::string MY_AXIS_ID("axis"); + return MY_AXIS_ID; + } + + /// Attribute name of the base radius + inline static const std::string& BASE_RADIUS_ID() + { + static const std::string MY_BASE_RADIUS_ID("base_radius"); + return MY_BASE_RADIUS_ID; + } + + /// Attribute name of the radius + inline static const std::string& TOP_RADIUS_ID() + { + static const std::string MY_TOP_RADIUS_ID("top_radius"); + return MY_TOP_RADIUS_ID; + } + + /// Attribute name of the radius + inline static const std::string& HEIGHT_ID() + { + static const std::string MY_HEIGHT_ID("height"); + return MY_HEIGHT_ID; + } + + /// Returns the kind of a feature + PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = PrimitivesPlugin_Cone::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed + PRIMITIVESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + PRIMITIVESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + PrimitivesPlugin_Cone(); + + private: + /// Load Naming data structure of the feature to the document + void loadNamingDS(std::shared_ptr theConeAlgo, + std::shared_ptr theResultCone); + +}; + +#endif // PRIMITIVESPLUGIN_CONE_H_ diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp index 36c77fa8a..8db8d5d16 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp @@ -7,8 +7,10 @@ #include #include +#include #include #include +#include #include @@ -29,10 +31,14 @@ FeaturePtr PrimitivesPlugin_Plugin::createFeature(std::string theFeatureID) { if (theFeatureID == PrimitivesPlugin_Box::ID()) { return FeaturePtr(new PrimitivesPlugin_Box); + } else if (theFeatureID == PrimitivesPlugin_Cone::ID()) { + return FeaturePtr(new PrimitivesPlugin_Cone); } else if (theFeatureID == PrimitivesPlugin_Cylinder::ID()) { return FeaturePtr(new PrimitivesPlugin_Cylinder); } else if (theFeatureID == PrimitivesPlugin_Sphere::ID()) { return FeaturePtr(new PrimitivesPlugin_Sphere); + } else if (theFeatureID == PrimitivesPlugin_Torus::ID()) { + return FeaturePtr(new PrimitivesPlugin_Torus); } // feature of such kind is not found return FeaturePtr(); diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Torus.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Torus.cpp new file mode 100644 index 000000000..817714a95 --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Torus.cpp @@ -0,0 +1,149 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: PrimitivesPlugin_Torus.cpp +// Created: 17 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +//================================================================================================= +PrimitivesPlugin_Torus::PrimitivesPlugin_Torus() +{ +} + +//================================================================================================= +void PrimitivesPlugin_Torus::initAttributes() +{ + data()->addAttribute(PrimitivesPlugin_Torus::BASE_POINT_ID(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(PrimitivesPlugin_Torus::AXIS_ID(), + ModelAPI_AttributeSelection::typeId()); + + data()->addAttribute(PrimitivesPlugin_Torus::RADIUS_ID(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Torus::RING_RADIUS_ID(), + ModelAPI_AttributeDouble::typeId()); + + // Initialize the base point of the torus at the origin if the base point is not filled. + AttributeSelectionPtr aCenterPoint = + data()->selection(PrimitivesPlugin_Torus::BASE_POINT_ID()); + if (!aCenterPoint->isInitialized()) { + ObjectPtr aPointObj = ModelAPI_Session::get()->moduleDocument() + ->objectByName(ModelAPI_ResultConstruction::group(), "Origin"); + if (aPointObj.get()) { + ResultPtr aPointRes = std::dynamic_pointer_cast(aPointObj); + aCenterPoint->setValue(aPointRes, std::shared_ptr()); + } + } + + // Initialize the axis at the OZ axis if the axis is not filled. + AttributeSelectionPtr anAxis = data()->selection(PrimitivesPlugin_Torus::AXIS_ID()); + if (!anAxis->isInitialized()) { + ObjectPtr anAxisObj = ModelAPI_Session::get()->moduleDocument() + ->objectByName(ModelAPI_ResultConstruction::group(), "OZ"); + if (anAxisObj.get()) { + ResultPtr anAxisRes = std::dynamic_pointer_cast(anAxisObj); + anAxis->setValue(anAxisRes, std::shared_ptr()); + } + } +} + +//================================================================================================= +void PrimitivesPlugin_Torus::execute() +{ + // Getting base point. + std::shared_ptr aBasePoint; + std::shared_ptr aPointRef = + selection(PrimitivesPlugin_Torus::BASE_POINT_ID()); + if (aPointRef.get() != NULL) { + GeomShapePtr aShape1 = aPointRef->value(); + if (!aShape1.get()) { + aShape1 = aPointRef->context()->shape(); + } + if (aShape1) { + aBasePoint = GeomAlgoAPI_PointBuilder::point(aShape1); + } + } + + // Getting axis. + std::shared_ptr anAxis; + std::shared_ptr anEdge; + std::shared_ptr anEdgeRef = + selection(PrimitivesPlugin_Torus::AXIS_ID()); + if(anEdgeRef && anEdgeRef->value() && anEdgeRef->value()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anEdgeRef->value())); + } else if (anEdgeRef && !anEdgeRef->value() && anEdgeRef->context() && + anEdgeRef->context()->shape() && anEdgeRef->context()->shape()->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(anEdgeRef->context()->shape())); + } + if(anEdge) { + anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, + anEdge->line()->direction())); + } + + // Getting radius and ring radius + double aRadius = real(PrimitivesPlugin_Torus::RADIUS_ID())->value(); + double aRingRadius = real(PrimitivesPlugin_Torus::RING_RADIUS_ID())->value(); + + std::shared_ptr aTorusAlgo = + std::shared_ptr(new GeomAlgoAPI_Torus(anAxis, + aRadius, + aRingRadius)); + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aTorusAlgo->check()) { + setError(aTorusAlgo->getError()); + return; + } + + // Build the sphere + aTorusAlgo->build(); + + // Check if the creation of the cylinder + if(!aTorusAlgo->isDone()) { + setError(aTorusAlgo->getError()); + return; + } + if(!aTorusAlgo->checkValid("Torus builder")) { + setError(aTorusAlgo->getError()); + return; + } + + int aResultIndex = 0; + ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); + loadNamingDS(aTorusAlgo, aResultBox); + setResult(aResultBox, aResultIndex); +} + +//================================================================================================= +void PrimitivesPlugin_Torus::loadNamingDS(std::shared_ptr theTorusAlgo, + std::shared_ptr theResultTorus) +{ + // Load the result + theResultTorus->store(theTorusAlgo->shape()); + + // Prepare the naming + theTorusAlgo->prepareNamingFaces(); + + // Insert to faces + int num = 1; + std::map< std::string, std::shared_ptr > listOfFaces = + theTorusAlgo->getCreatedFaces(); + for (std::map< std::string, std::shared_ptr >::iterator + it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) { + std::shared_ptr aFace = (*it).second; + theResultTorus->generated(aFace, (*it).first, num++); + } +} \ No newline at end of file diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Torus.h b/src/PrimitivesPlugin/PrimitivesPlugin_Torus.h new file mode 100644 index 000000000..69ea8bf85 --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Torus.h @@ -0,0 +1,81 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: PrimitivesPlugin_Torus.h +// Created: 17 Mar 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef PRIMITIVESPLUGIN_TORUS_H_ +#define PRIMITIVESPLUGIN_TORUS_H_ + +#include +#include +#include + +/**\class PrimitivesPlugin_Torus + * \ingroup Plugins + * \brief Feature for creation of a torus. + * + * Creates a torus from a + */ +class PrimitivesPlugin_Torus : public ModelAPI_Feature +{ + public: + /// Torus kind + inline static const std::string& ID() + { + static const std::string MY_TORUS_ID("Torus"); + return MY_TORUS_ID; + } + + /// Attribute name of the base point + inline static const std::string& BASE_POINT_ID() + { + static const std::string MY_BASE_POINT_ID("base_point"); + return MY_BASE_POINT_ID; + } + + /// Attribute name of the axis + inline static const std::string& AXIS_ID() + { + static const std::string MY_AXIS_ID("axis"); + return MY_AXIS_ID; + } + + /// Attribute name of the radius + inline static const std::string& RADIUS_ID() + { + static const std::string MY_RADIUS_ID("radius"); + return MY_RADIUS_ID; + } + + /// Attribute name of the section radius + inline static const std::string& RING_RADIUS_ID() + { + static const std::string MY_RING_RADIUS_ID("ring_radius"); + return MY_RING_RADIUS_ID; + } + + /// Returns the kind of a feature + PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = PrimitivesPlugin_Torus::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed + PRIMITIVESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + PRIMITIVESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + PrimitivesPlugin_Torus(); + + private: + /// Load Naming data structure of the feature to the document + void loadNamingDS(std::shared_ptr theTorusAlgo, + std::shared_ptr theResultTorus); + +}; + +#endif // PRIMITIVESPLUGIN_TORUS_H_ diff --git a/src/PrimitivesPlugin/cone_widget.xml b/src/PrimitivesPlugin/cone_widget.xml new file mode 100644 index 000000000..4f1acd5e4 --- /dev/null +++ b/src/PrimitivesPlugin/cone_widget.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/PrimitivesPlugin/icons/SVG/cone.svg b/src/PrimitivesPlugin/icons/SVG/cone.svg new file mode 100644 index 000000000..bcf82d663 --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/cone.svg @@ -0,0 +1,123 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/SVG/torus.svg b/src/PrimitivesPlugin/icons/SVG/torus.svg new file mode 100644 index 000000000..1f4e4365c --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/torus.svg @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/cone.png b/src/PrimitivesPlugin/icons/cone.png new file mode 100644 index 0000000000000000000000000000000000000000..4c89e6282d491970a00f20c648b62420652a2741 GIT binary patch literal 677 zcmV;W0$TlvP)~DCe_B+a$3}AL$>pr!7zCeY?Jm2TxA=Hs4r#i{9@1e)-P8kMci_1&nTxWMyUW^pYUTZyo&hTWQ|4Jf!@-zTo zVruf*=(Djl02j<&GCy?Y@?LQE(dBR=aw?2J%)qmO4nMe$PfJT{&UL$cZtjs@ zH$jz4DgY%FOO(x>GO?rv!1Yxroo_e-Cq5`kGL8p=&1S%fP;ZkYir|D>bpft(c|U+? zUnFV>Ad49w2xN_f&lmtwow>Ys55U6M5D`(bFJ3hl*OZPWszgM@je%W&L#o=$fvW+Z zAF?R6Gy=5Atu4MI$G|~1Jn`%Mw*jn7mjT$5vBb|t#WkfiJ?*+pQ?~&E_`Oz1Lcs60 z{SVL`4BBK#0yu_i0OH{7J)vG+Z+T`3Bv?X$Zh&y02H*fK%*@Wv?*~QNs5^5$lC-;GBa9ZuEXn7tGcz%Fv49&mI4uy6g9Kv*PTfe{~D9Uqj9~E=)tzH0ZKucC&1XA<Zg zvkNFHa_-)|=bZPv&v}G((9qEBn%erZK~X_h@HJ>tcboV8h$b+jDdAtJiu99zGfrAZ3gmiuU*ZA=L*vic&7Z z0{*Vn6N!WSKlQFRmlf!Z{!pqfbkifk3%u-frt>%}iogEDUD=#CxtLtIbmeF7(9?fK z1nPFw>6y>FlKJj@@3F%{&+zkMeLNJdk_97C4sr&Nqcx4gh0}S-CVxD=)LbfGTD=owAZrb23YW=Kzz_(HKBQd0?xrxEO@J z9$v@PVg{(MEDPZCZP@}aHaW4dqJQStSX;Lls?JoMV?G>C71r#0g3$Ts$v^paEM{t|suFIuI}Z`biC@Lz$(~;>JMY~4 z-36otPE6doKD_E&cBH)xkslQbEz6=hP{}sGA5~>yD#}P?G&jUKK~Il|dPDC-1K8Ho zRv~JAEyyWg?MB8$wMVkf^J90eOs-AOinf|_!%EQ8T8|Lh0%A3XSBX)X7E Xo6{%ZL>rm400000NkvXXu0mjfSVD;Z literal 0 HcmV?d00001 diff --git a/src/PrimitivesPlugin/plugin-Primitives.xml b/src/PrimitivesPlugin/plugin-Primitives.xml index 9880e628b..4c087288e 100644 --- a/src/PrimitivesPlugin/plugin-Primitives.xml +++ b/src/PrimitivesPlugin/plugin-Primitives.xml @@ -18,5 +18,15 @@ + + + + + + + + + + diff --git a/src/PrimitivesPlugin/torus_widget.xml b/src/PrimitivesPlugin/torus_widget.xml new file mode 100644 index 000000000..44d0ce688 --- /dev/null +++ b/src/PrimitivesPlugin/torus_widget.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/PythonAPI/model/primitives/__init__.py b/src/PythonAPI/model/primitives/__init__.py index 6f0b8e061..a707b9cfe 100644 --- a/src/PythonAPI/model/primitives/__init__.py +++ b/src/PythonAPI/model/primitives/__init__.py @@ -1,4 +1,4 @@ """Package for Primitives plugin for the Parametric Geometry API of the Modeler. """ -from PrimitivesAPI import addBox, addCylinder, addSphere +from PrimitivesAPI import addBox, addCone, addCylinder, addSphere, addTorus -- 2.39.2