From: Clarisse Genrault Date: Fri, 13 Jan 2017 12:38:39 +0000 (+0100) Subject: Adding the "Cylinder" primitive (the following). X-Git-Tag: V_2.7.0~345 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=45ea4b0ea4a0d15133b47d8e2bc55c8a24ed402e;p=modules%2Fshaper.git Adding the "Cylinder" primitive (the following). --- diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index aabc35d11..68048d8e9 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -159,6 +159,7 @@ INSTALL(TARGETS GeomAlgoAPI DESTINATION ${SHAPER_INSTALL_BIN}) INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) ADD_UNIT_TESTS(TestAPI_Box.py + TestAPI_Cylinder.py TestAPI_GDMLConeSegment.py TestAPI_Symmetry.py TestAPI_Translation.py) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index 04c730e63..97c13ddde 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp @@ -65,7 +65,7 @@ bool GeomAlgoAPI_Box::check() if (fabs(aDiffX) < Precision::Confusion() || fabs(aDiffY) < Precision::Confusion() || fabs(aDiffZ) < Precision::Confusion()) { - myError = + myError = "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes"; return false; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp index 4ee724e50..e487b6a55 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp @@ -77,20 +77,21 @@ bool GeomAlgoAPI_Cylinder::check() void GeomAlgoAPI_Cylinder::build() { myCreatedFaces.clear(); - + const gp_Ax2& anAxis = myAxis->impl(); - + // Construct the cylinder BRepPrimAPI_MakeCylinder *aCylinderMaker; - + if (withAngle) { - aCylinderMaker = new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight, myAngle * M_PI / 180.); + aCylinderMaker = + new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight, myAngle * M_PI / 180.); } else { - aCylinderMaker = new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight); + aCylinderMaker = new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight); } - + aCylinderMaker->Build(); - + if (!aCylinderMaker->IsDone()) { return; } @@ -105,8 +106,8 @@ void GeomAlgoAPI_Cylinder::build() myError = "Cylinder builder :: resulting shape is null."; return; } - + setImpl(aCylinderMaker); - + setDone(true); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h index b0f91e27c..6bffee998 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h @@ -21,16 +21,15 @@ class GeomAlgoAPI_Cylinder : public GeomAlgoAPI_MakeShape public: GEOMALGOAPI_EXPORT GeomAlgoAPI_Cylinder(); - /// Creates a cylinder + /// Creates a cylinder. /// \param theAxis The axis of the cylinder /// \param theRadius The radius of the cylinder /// \param theHeight The height of the cylinder - /// \param theAngle The covering angle of the cylinder GEOMALGOAPI_EXPORT GeomAlgoAPI_Cylinder(std::shared_ptr theAxis, const double theRadius, const double theHeight); - /// Creates a cylinder + /// Creates a cylinder. /// \param theAxis The axis of the cylinder /// \param theRadius The radius of the cylinder /// \param theHeight The height of the cylinder @@ -47,8 +46,8 @@ class GeomAlgoAPI_Cylinder : public GeomAlgoAPI_MakeShape GEOMALGOAPI_EXPORT void build(); private: - bool withAngle; - std::shared_ptr myBasePoint; + bool withAngle; /// Boolean indicating if the type of cylinder (full or portion). + std::shared_ptr myBasePoint; /// Center of the lower base of the cylinder. std::shared_ptr myAxis; /// Axis of the cylinder. double myRadius; /// Radius of the cylinder. double myHeight; /// Height of the cylinder. diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index f738e5c41..223517a4a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -7,14 +7,17 @@ #include "GeomAlgoAPI_ShapeAPI.h" #include +#include #include #include #include #include +#include + namespace GeomAlgoAPI_ShapeAPI { - //======================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeBox( const double theDx, const double theDy, const double theDz) throw (GeomAlgoAPI_Exception) @@ -36,7 +39,7 @@ namespace GeomAlgoAPI_ShapeAPI return aBoxAlgo.shape(); } - //====================================================================================== + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeBox( std::shared_ptr theFirstPoint, std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception) @@ -58,7 +61,115 @@ namespace GeomAlgoAPI_ShapeAPI return aBoxAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + std::shared_ptr theBasePoint, std::shared_ptr theEdge, + double theRadius, double theHeight) throw (GeomAlgoAPI_Exception) + { + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight); + + if (!aCylinderAlgo.check()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + + aCylinderAlgo.build(); + + if(!aCylinderAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + if (!aCylinderAlgo.checkValid("Cylinder builder")) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + return aCylinderAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + std::shared_ptr theBasePoint, std::shared_ptr theEdge, + double theRadius, double theHeight, double theAngle) throw (GeomAlgoAPI_Exception) + { + std::shared_ptr anAxis; + anAxis = std::shared_ptr(new GeomAPI_Ax2(theBasePoint, + theEdge->line()->direction())); + + GeomAlgoAPI_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle); + + if (!aCylinderAlgo.check()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + + aCylinderAlgo.build(); + + if(!aCylinderAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + if (!aCylinderAlgo.checkValid("Cylinder portion builder")) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + return aCylinderAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + double theRadius, 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_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight); + + if (!aCylinderAlgo.check()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + + aCylinderAlgo.build(); + + if(!aCylinderAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + if (!aCylinderAlgo.checkValid("Cylinder builder")) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + return aCylinderAlgo.shape(); + } + + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeCylinder( + double theRadius, double theHeight, double theAngle) 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_Cylinder aCylinderAlgo(anAxis, theRadius, theHeight, theAngle); + + if (!aCylinderAlgo.check()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + + aCylinderAlgo.build(); + + if(!aCylinderAlgo.isDone()) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + if (!aCylinderAlgo.checkValid("Cylinder portion builder")) { + throw GeomAlgoAPI_Exception(aCylinderAlgo.getError()); + } + return aCylinderAlgo.shape(); + } + + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, std::shared_ptr theAxis, @@ -81,7 +192,7 @@ namespace GeomAlgoAPI_ShapeAPI return aTranslationAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, const double theDx, @@ -105,7 +216,7 @@ namespace GeomAlgoAPI_ShapeAPI return aTranslationAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTranslation( std::shared_ptr theSourceShape, std::shared_ptr theStartPoint, @@ -128,7 +239,7 @@ namespace GeomAlgoAPI_ShapeAPI return aTranslationAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSymmetry( std::shared_ptr theSourceShape, std::shared_ptr thePoint) throw (GeomAlgoAPI_Exception) @@ -150,7 +261,7 @@ namespace GeomAlgoAPI_ShapeAPI return aSymmetryAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSymmetry( std::shared_ptr theSourceShape, std::shared_ptr theAxis) throw (GeomAlgoAPI_Exception) @@ -172,7 +283,7 @@ namespace GeomAlgoAPI_ShapeAPI return aSymmetryAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSymmetry( std::shared_ptr theSourceShape, std::shared_ptr thePlane) throw (GeomAlgoAPI_Exception) @@ -194,7 +305,7 @@ namespace GeomAlgoAPI_ShapeAPI return aSymmetryAlgo.shape(); } - //========================================================================================================= + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeConeSegment( const double theRMin1, const double theRMax1, const double theRMin2, const double theRMax2, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h index fbed6c1cc..454f88495 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h @@ -39,10 +39,42 @@ public: static std::shared_ptr makeBox(std::shared_ptr theFirstPoint, std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception); + /// Creates a cylinder using a center, an axis, a radius and a height. + /// \param theBasePoint The center of the lower base of the cylinder + /// \param theEdge The axis of the cylinder + /// \param theRadius The radius of the cylinder + /// \param theHeight The heigth of the cylinder + static std::shared_ptr makeCylinder(std::shared_ptr theBasePoint, + std::shared_ptr theEdge, double theRadius, double theHeight) + throw (GeomAlgoAPI_Exception); + + /// Creates a portion of cylinder using a center, an axis, a radius, a height and an angle. + /// \param theBasePoint The center of the lower base of the cylinder + /// \param theEdge The axis of the cylinder + /// \param theRadius The radius of the cylinder + /// \param theHeight The heigth of the cylinder + /// \param theAngle The angle defining the portion + static std::shared_ptr makeCylinder(std::shared_ptr theBasePoint, + std::shared_ptr theEdge, double theRadius, double theHeight, + double theAngle) throw (GeomAlgoAPI_Exception); + + /// Creates a cylinder using the origin, the OZ axis, a radius and a height. + /// \param theRadius The radius of the cylinder + /// \param theHeight The heigth of the cylinder + static std::shared_ptr makeCylinder(double theRadius, double theHeight) + throw (GeomAlgoAPI_Exception); + + /// Creates a portion of cylinder using the origin, the OZ axis, a radius, a height and an angle. + /// \param theRadius The radius of the cylinder + /// \param theHeight The heigth of the cylinder + /// \param theAngle The angle defining the portion + static std::shared_ptr makeCylinder(double theRadius, double theHeight, + double theAngle) throw (GeomAlgoAPI_Exception); + /// Performs a translation from an axis and a distance. - /// \param theSourceShape Shape to be moved. - /// \param theAxis Movement axis. - /// \param theDistance Movement distance. + /// \param theSourceShape Shape to be moved + /// \param theAxis Movement axis + /// \param theDistance Movement distance /// \return a shape static std::shared_ptr makeTranslation( std::shared_ptr theSourceShape, @@ -50,10 +82,10 @@ public: const double theDistance) throw (GeomAlgoAPI_Exception); /// Performs a translation from dimensions. - /// \param theSourceShape Shape to be moved. - /// \param theDx Movement dimension on X. - /// \param theDy Movement dimension on Y. - /// \param theDz Movement dimension on Z. + /// \param theSourceShape Shape to be moved + /// \param theDx Movement dimension on X + /// \param theDy Movement dimension on Y + /// \param theDz Movement dimension on Z /// \return a shape static std::shared_ptr makeTranslation( std::shared_ptr theSourceShape, @@ -62,31 +94,37 @@ public: const double theDz) throw (GeomAlgoAPI_Exception); /// Performs a translation from two points. - /// \param theSourceShape Shape to be moved. - /// \param theStartPoint Movement start point. - /// \param theEndPoint Movement end point. + /// \param theSourceShape Shape to be moved + /// \param theStartPoint Movement start point + /// \param theEndPoint Movement end point /// \return a shape static std::shared_ptr makeTranslation( std::shared_ptr theSourceShape, std::shared_ptr theStartPoint, std::shared_ptr theEndPoint) throw (GeomAlgoAPI_Exception); - /// Performs a symmetry by a point + /// Performs a symmetry by a point. + /// \param theSourceShape Shape be symmetrized + /// \param thePoint Point of symmetry static std::shared_ptr makeSymmetry( std::shared_ptr theSourceShape, std::shared_ptr thePoint) throw (GeomAlgoAPI_Exception); - /// Performs a symmetry by an axis + /// Performs a symmetry by an axis. + /// \param theSourceShape Shape be symmetrized + /// \param theAxis Axis of symmetry static std::shared_ptr makeSymmetry( std::shared_ptr theSourceShape, std::shared_ptr theAxis) throw (GeomAlgoAPI_Exception); - /// Performs a symmetry by a plane + /// Performs a symmetry by a plane. + /// \param theSourceShape Shape be symmetrized + /// \param thePlane Plane of symmetry static std::shared_ptr makeSymmetry( std::shared_ptr theSourceShape, std::shared_ptr thePlane) throw (GeomAlgoAPI_Exception); - /// Creates a cone segment using standard GDML parameters + /// Creates a cone segment using standard GDML parameters. /// \param theRMin1 Inner radius at base of cone /// \param theRMax1 Outer radius at base of cone /// \param theRMin2 Inner radius at top of cone diff --git a/src/GeomAlgoAPI/Test/TestAPI_Cylinder.py b/src/GeomAlgoAPI/Test/TestAPI_Cylinder.py new file mode 100644 index 000000000..50a4b877d --- /dev/null +++ b/src/GeomAlgoAPI/Test/TestAPI_Cylinder.py @@ -0,0 +1,41 @@ +# Copyright (C) 2014-201x CEA/DEN, EDF R&D + +# File: TestAPI_Cylinder.py +# Created: 13 Jan 2017 +# Author: Clarisse Genrault (CEA) + +from GeomAlgoAPI import GeomAlgoAPI_ShapeAPI as shaperpy +from GeomAlgoAPI import GeomAlgoAPI_Exception as myExcept +from GeomAlgoAPI import GeomAlgoAPI_EdgeBuilder as edgeBuilder +from GeomAPI import GeomAPI_Pnt as pnt + +aPoint = pnt(10.,5.,0.) +anEdge = edgeBuilder.line(1.,0.,0.) + +# Create a cylinder +try : + cylinder1 = shaperpy.makeCylinder(5., 20.) + +except myExcept,ec: + print ec.what() + +# Create a cylinder +try : + cylinder2 = shaperpy.makeCylinder(5., 20., 100.) + +except myExcept,ec: + print ec.what() + +# Create a cylinder +try : + cylinder3 = shaperpy.makeCylinder(aPoint, anEdge, 5., 20.) + +except myExcept,ec: + print ec.what() + +# Create a cylinder +try : + cylinder4 = shaperpy.makeCylinder(aPoint, anEdge, 5., 20., 180.) + +except myExcept,ec: + print ec.what() \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI.i b/src/PrimitivesAPI/PrimitivesAPI.i index 28b92e235..3bea92c00 100644 --- a/src/PrimitivesAPI/PrimitivesAPI.i +++ b/src/PrimitivesAPI/PrimitivesAPI.i @@ -20,7 +20,7 @@ // shared pointers %shared_ptr(PrimitivesAPI_Box) - %shared_ptr(PrimitivesAPI_Cylinder) +%shared_ptr(PrimitivesAPI_Cylinder) // all supported interfaces %include "PrimitivesAPI_Box.h" diff --git a/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp index 42c10aed1..debf4b054 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp +++ b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp @@ -1,8 +1,8 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> +// Copyright (C) 2014-201x CEA/DEN, EDF R&D --> -// File: PrimitivesAPI_Cylinder.h +// File: PrimitivesAPI_Cylinder.cpp // Created: 12 Jan 2017 -// Author: Clarisse Genrault (CEA) +// Author: Clarisse Genrault #include "PrimitivesAPI_Cylinder.h" @@ -19,44 +19,40 @@ PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature, - const ModelHighAPI_Selection& theBasePoint, - const ModelHighAPI_Selection& theAxis, - const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight) + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight) : ModelHighAPI_Interface(theFeature) { if (initialize()) { - fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod()); - setObjects(theBasePoint, theAxis); + fillAttribute(theBasePoint, basePoint()); + fillAttribute(theAxis, axis()); setSizes(theRadius, theHeight); } } //================================================================================================== PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature, - const ModelHighAPI_Selection& theBasePoint, - const ModelHighAPI_Selection& theAxis, - const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight, - const ModelHighAPI_Double& theAngle) + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight, + const ModelHighAPI_Double& theAngle) : ModelHighAPI_Interface(theFeature) { if (initialize()) { - fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod()); - setObjects(theBasePoint, theAxis); + fillAttribute(theBasePoint, basePoint()); + fillAttribute(theAxis, axis()); + fillAttribute(theAngle, angle()); setSizes(theRadius, theHeight); - setAngle(theAngle); } } //================================================================================================== -void PrimitivesAPI_Cylinder::setObjects(const ModelHighAPI_Selection& theBasePoint, - const ModelHighAPI_Selection& theAxis) +PrimitivesAPI_Cylinder::~PrimitivesAPI_Cylinder() { - fillAttribute(theBasePoint, basePoint()); - fillAttribute(theAxis, axis()); - execute(); } //================================================================================================== @@ -65,15 +61,6 @@ void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius, { fillAttribute(theRadius, radius()); fillAttribute(theHeight, height()); - - execute(); -} - -//================================================================================================== -void PrimitivesAPI_Cylinder::setAngle(const ModelHighAPI_Double& theAngle) -{ - fillAttribute(theAngle, angle()); - execute(); } @@ -85,17 +72,18 @@ void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const theDumper << aBase << " = model.addCylinder(" << aDocName; - std::string aCreationMethod = aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value(); - AttributeSelectionPtr anAttrBasePoint = aBase->selection(PrimitivesPlugin_Cylinder::BASE_POINT_ID()); AttributeSelectionPtr anAttrAxis = aBase->selection(PrimitivesPlugin_Cylinder::AXIS_ID()); + theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis; + AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID()); AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID()); - - theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis; theDumper << ", " << anAttrRadius << ", " << anAttrHeight; - + + std::string aCreationMethod = + aBase->string(PrimitivesPlugin_Cylinder::CREATION_METHOD())->value(); + if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) { AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID()); theDumper << ", " << anAttrAngle; @@ -109,12 +97,11 @@ CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theBasePoint, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight, - const ModelHighAPI_Double& theAngle) + const ModelHighAPI_Double& theHeight) { std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis, - theRadius, theHeight, theAngle)); + theRadius, theHeight)); } //================================================================================================== @@ -122,34 +109,35 @@ CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theBasePoint, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight) + const ModelHighAPI_Double& theHeight, + const ModelHighAPI_Double& theAngle) { std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis, - theRadius, theHeight)); + theRadius, theHeight, theAngle)); } //================================================================================================== CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight, - const ModelHighAPI_Double& theAngle) + const ModelHighAPI_Double& theHeight) { - std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); ModelHighAPI_Selection aBasePoint("VERT", "Origin"); ModelHighAPI_Selection anAxis("EDGE", "OZ"); + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis, - theRadius, theHeight, theAngle)); + theRadius, theHeight)); } //================================================================================================== CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight) + const ModelHighAPI_Double& theHeight, + const ModelHighAPI_Double& theAngle) { - std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); ModelHighAPI_Selection aBasePoint("VERT", "Origin"); ModelHighAPI_Selection anAxis("EDGE", "OZ"); + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis, theRadius, theHeight)); } \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h index 3e16d41c8..3d473798b 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h +++ b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h @@ -1,8 +1,8 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> +// Copyright (C) 2014-201x CEA/DEN, EDF R&D --> // File: PrimitivesAPI_Cylinder.h // Created: 12 Jan 2017 -// Author: Clarisse Genrault (CEA) +// Author: Clarisse Genrault #ifndef PRIMITIVESAPI_CYLINDER_H_ #define PRIMITIVESAPI_CYLINDER_H_ @@ -17,9 +17,9 @@ class ModelHighAPI_Double; class ModelHighAPI_Selection; -/// \class PrimitivesAPI_Cylinder +/// \class PrimitivesAPI_Box /// \ingroup CPPHighAPI -/// \brief Interface for primitive Cylinder feature. +/// \brief Interface for primitive Box feature. class PrimitivesAPI_Cylinder: public ModelHighAPI_Interface { public: @@ -27,6 +27,13 @@ public: PRIMITIVESAPI_EXPORT explicit PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature); + /// Constructor with values. + /*PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theDx, + const ModelHighAPI_Double& theDy, + const ModelHighAPI_Double& theDz);*/ + /// Constructor with values. PRIMITIVESAPI_EXPORT explicit PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature, @@ -34,6 +41,8 @@ public: const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theRadius, const ModelHighAPI_Double& theHeight); + + /// Constructor with values. PRIMITIVESAPI_EXPORT explicit PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature, const ModelHighAPI_Selection& theBasePoint, @@ -42,44 +51,29 @@ public: const ModelHighAPI_Double& theHeight, const ModelHighAPI_Double& theAngle); - /// Constructor with values. - /*PRIMITIVESAPI_EXPORT - explicit PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature, - const ModelHighAPI_Selection& theFirstPoint, - const ModelHighAPI_Selection& theSecondPoint);*/ - /// Destructor. PRIMITIVESAPI_EXPORT virtual ~PrimitivesAPI_Cylinder(); INTERFACE_6(PrimitivesPlugin_Cylinder::ID(), - creationMethod, PrimitivesPlugin_Cylinder::CREATION_METHOD(), - ModelAPI_AttributeString, /** Creation method */, - basePoint, PrimitivesPlugin_Cylinder::BASE_POINT_ID(), - ModelAPI_AttributeSelection, /** Base point */, - axis, PrimitivesPlugin_Cylinder::AXIS_ID(), - ModelAPI_AttributeSelection, /** Axis */, - radius, PrimitivesPlugin_Cylinder::RADIUS_ID(), - ModelAPI_AttributeDouble, /** Radius */, - height, PrimitivesPlugin_Cylinder::HEIGHT_ID(), - ModelAPI_AttributeDouble, /** Height */, - angle, PrimitivesPlugin_Cylinder::ANGLE_ID(), - ModelAPI_AttributeDouble, /** Angle */) - - /// Set base point and axis - PRIMITIVESAPI_EXPORT - void setObjects(const ModelHighAPI_Selection& theBasePoint, - const ModelHighAPI_Selection& theAxis); - - /// Set radius and height + creationMethod, PrimitivesPlugin_Cylinder::CREATION_METHOD(), + ModelAPI_AttributeString, /** Creation method */, + basePoint, PrimitivesPlugin_Cylinder::BASE_POINT_ID(), + ModelAPI_AttributeSelection, /** Dimension in X */, + axis, PrimitivesPlugin_Cylinder::AXIS_ID(), + ModelAPI_AttributeSelection, /** Dimension in Y */, + radius, PrimitivesPlugin_Cylinder::RADIUS_ID(), + ModelAPI_AttributeDouble, /** Dimension in Z */, + height, PrimitivesPlugin_Cylinder::HEIGHT_ID(), + ModelAPI_AttributeDouble, /** First point */, + angle, PrimitivesPlugin_Cylinder::ANGLE_ID(), + ModelAPI_AttributeDouble, /** Second point */) + + /// Set dimensions PRIMITIVESAPI_EXPORT void setSizes(const ModelHighAPI_Double& theRadius, const ModelHighAPI_Double& theHeight); - /// Set angle - PRIMITIVESAPI_EXPORT - void setAngle(const ModelHighAPI_Double& theAngle); - /// Dump wrapped feature PRIMITIVESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -89,36 +83,37 @@ public: typedef std::shared_ptr CylinderPtr; /// \ingroup CPPHighAPI -/// \brief Create primitive Cylinder feature. +/// \brief Create primitive Box feature. PRIMITIVESAPI_EXPORT CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theBasePoint, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight, - const ModelHighAPI_Double& theAngle); + const ModelHighAPI_Double& theHeight); /// \ingroup CPPHighAPI -/// \brief Create primitive Cylinder feature. +/// \brief Create primitive Box feature. PRIMITIVESAPI_EXPORT CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theBasePoint, const ModelHighAPI_Selection& theAxis, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight); + const ModelHighAPI_Double& theHeight, + const ModelHighAPI_Double& theAngle); + /// \ingroup CPPHighAPI -/// \brief Create primitive Cylinder feature. +/// \brief Create primitive Box feature. PRIMITIVESAPI_EXPORT CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight, - const ModelHighAPI_Double& theAngle); + const ModelHighAPI_Double& theHeight); /// \ingroup CPPHighAPI -/// \brief Create primitive Cylinder feature. +/// \brief Create primitive Box feature. PRIMITIVESAPI_EXPORT CylinderPtr addCylinder(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius, - const ModelHighAPI_Double& theHeight); + const ModelHighAPI_Double& theHeight, + const ModelHighAPI_Double& theAngle); #endif // PRIMITIVESAPI_CYLINDER_H_ \ No newline at end of file diff --git a/src/PrimitivesAPI/Test/TestCylinder.py b/src/PrimitivesAPI/Test/TestCylinder.py new file mode 100644 index 000000000..38e6d260b --- /dev/null +++ b/src/PrimitivesAPI/Test/TestCylinder.py @@ -0,0 +1,44 @@ +""" +Test case for Primitive Cylinder feature. +Written on High API. +""" +from ModelAPI import * +from GeomAPI import * + +from salome.shaper import model + +# Get session +aSession = ModelAPI_Session.get() + +# Create a part +aDocument = aSession.activeDocument() +aSession.startOperation() +model.addPart(aDocument) +aDocument = aSession.activeDocument() +aSession.finishOperation() + +aSession.startOperation() +aBasePoint = model.addPoint(aDocument, 0, 0, 0).result() +anAxis = model.addAxis(aDocument, 10, 0, 0).result() +aSession.finishOperation() + +aSession.startOperation() +aCylinder1 = model.addCylinder(aDocument, aBasePoint, anAxis, 5., 20.) +assert (aCylinder1 is not None) +aSession.finishOperation() + +aSession.startOperation() +aCylinder2 = model.addCylinder(aDocument, aBasePoint, anAxis, 5., 20., 100.) +assert (aCylinder2 is not None) +aSession.finishOperation() + +aSession.startOperation() +aCylinder3 = model.addCylinder(aDocument, 5., 20.) +assert (aCylinder3 is not None) +aSession.finishOperation() + +aSession.startOperation() +aCylinder4 = model.addCylinder(aDocument, 5., 20., 100.) +assert (aCylinder4 is not None) +aSession.finishOperation() + diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp index fd336ae8b..63236482b 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp @@ -31,19 +31,19 @@ void PrimitivesPlugin_Cylinder::initAttributes() { data()->addAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD(), ModelAPI_AttributeString::typeId()); - + data()->addAttribute(PrimitivesPlugin_Cylinder::BASE_POINT_ID(), ModelAPI_AttributeSelection::typeId()); data()->addAttribute(PrimitivesPlugin_Cylinder::AXIS_ID(), ModelAPI_AttributeSelection::typeId()); - + data()->addAttribute(PrimitivesPlugin_Cylinder::RADIUS_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(PrimitivesPlugin_Cylinder::HEIGHT_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(PrimitivesPlugin_Cylinder::ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); - + // Initialize the base point of the cylinder at the origin if the base point is not filled. AttributeSelectionPtr aBasePoint = data()->selection(BASE_POINT_ID()); if (!aBasePoint->isInitialized()) { @@ -54,10 +54,10 @@ void PrimitivesPlugin_Cylinder::initAttributes() aBasePoint->setValue(aPointRes, std::shared_ptr()); } } - + // Initialize the axis at the OZ axis if the axis is not filled. AttributeSelectionPtr anAxis = data()->selection(AXIS_ID()); - if (!anAxis->isInitialized()) { + if (!anAxis->isInitialized()) { ObjectPtr anAxisObj = ModelAPI_Session::get()->moduleDocument() ->objectByName(ModelAPI_ResultConstruction::group(), "OZ"); if (anAxisObj.get()) { @@ -98,7 +98,7 @@ void PrimitivesPlugin_Cylinder::createCylinder(bool withAngle) aBasePoint = GeomAlgoAPI_PointBuilder::point(aShape1); } } - + // Getting axis. std::shared_ptr anAxis; std::shared_ptr anEdge; @@ -114,21 +114,21 @@ void PrimitivesPlugin_Cylinder::createCylinder(bool withAngle) anAxis = std::shared_ptr(new GeomAPI_Ax2(aBasePoint, anEdge->line()->direction())); } - + // Getting radius and height double aRadius = real(PrimitivesPlugin_Cylinder::RADIUS_ID())->value(); double aHeight = real(PrimitivesPlugin_Cylinder::HEIGHT_ID())->value(); - + std::shared_ptr aCylinderAlgo; if (withAngle) { // Getting angle double anAngle = real(PrimitivesPlugin_Cylinder::ANGLE_ID())->value(); - aCylinderAlgo = + aCylinderAlgo = std::shared_ptr(new GeomAlgoAPI_Cylinder(anAxis, aRadius, aHeight, anAngle)); } else { - aCylinderAlgo = + aCylinderAlgo = std::shared_ptr(new GeomAlgoAPI_Cylinder(anAxis, aRadius, aHeight)); } @@ -165,7 +165,6 @@ void PrimitivesPlugin_Cylinder::createCylinder(bool withAngle) void PrimitivesPlugin_Cylinder::loadNamingDS(std::shared_ptr theCylinderAlgo, std::shared_ptr theResultCylinder) { - // Load the result theResultCylinder->store(theCylinderAlgo->shape()); diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h index 1f3dce27c..250bf881b 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h @@ -37,14 +37,14 @@ class PrimitivesPlugin_Cylinder : public ModelAPI_Feature static const std::string MY_CREATION_METHOD_ID("CreationMethod"); return MY_CREATION_METHOD_ID; } - + /// Attribute name for creation method inline static const std::string& CREATION_METHOD_CYLINDER() { static const std::string MY_CREATION_METHOD_ID("Cylinder"); return MY_CREATION_METHOD_ID; } - + /// Attribute name for creation method inline static const std::string& CREATION_METHOD_CYLINDER_PORTION() { diff --git a/src/PrimitivesPlugin/icons/SVG/cylinder.svg b/src/PrimitivesPlugin/icons/SVG/cylinder.svg new file mode 100644 index 000000000..e6365bd02 --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/cylinder.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/SVG/cylinder_32x32.svg b/src/PrimitivesPlugin/icons/SVG/cylinder_32x32.svg new file mode 100644 index 000000000..58007843e --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/cylinder_32x32.svg @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/SVG/cylinder_portion_32x32.svg b/src/PrimitivesPlugin/icons/SVG/cylinder_portion_32x32.svg new file mode 100644 index 000000000..46351d570 --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/cylinder_portion_32x32.svg @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/cylinder_32x32.png b/src/PrimitivesPlugin/icons/cylinder_32x32.png index 80a39989d..6de9c1c6b 100644 Binary files a/src/PrimitivesPlugin/icons/cylinder_32x32.png and b/src/PrimitivesPlugin/icons/cylinder_32x32.png differ diff --git a/src/PrimitivesPlugin/icons/cylinder_portion_32x32.png b/src/PrimitivesPlugin/icons/cylinder_portion_32x32.png index 4f8177c43..790d6abe9 100644 Binary files a/src/PrimitivesPlugin/icons/cylinder_portion_32x32.png and b/src/PrimitivesPlugin/icons/cylinder_portion_32x32.png differ diff --git a/src/PythonAPI/model/primitives/__init__.py b/src/PythonAPI/model/primitives/__init__.py index aeb61cd51..49d9adb32 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 +from PrimitivesAPI import addBox, addCylinder