From ccd1d538ff04366093c86220b22b53c4b7370f14 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Thu, 12 Jan 2017 12:23:24 +0100 Subject: [PATCH] Add "Cylinder" primitive. --- src/GeomAlgoAPI/CMakeLists.txt | 2 + src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp | 112 +++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h | 59 ++++++ src/PrimitivesAPI/CMakeLists.txt | 5 +- src/PrimitivesAPI/PrimitivesAPI.h | 2 +- src/PrimitivesAPI/PrimitivesAPI.i | 2 + src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp | 155 +++++++++++++++ src/PrimitivesAPI/PrimitivesAPI_Cylinder.h | 124 ++++++++++++ src/PrimitivesAPI/PrimitivesAPI_swig.h | 7 +- src/PrimitivesPlugin/CMakeLists.txt | 3 + .../PrimitivesPlugin_Cylinder.cpp | 184 ++++++++++++++++++ .../PrimitivesPlugin_Cylinder.h | 116 +++++++++++ .../PrimitivesPlugin_Plugin.cpp | 3 + src/PrimitivesPlugin/cylinder_widget.xml | 101 ++++++++++ src/PrimitivesPlugin/icons/angle.png | Bin 0 -> 499 bytes src/PrimitivesPlugin/icons/axis.png | Bin 0 -> 424 bytes src/PrimitivesPlugin/icons/cylinder.png | Bin 0 -> 542 bytes src/PrimitivesPlugin/icons/cylinder_32x32.png | Bin 0 -> 873 bytes .../icons/cylinder_portion_32x32.png | Bin 0 -> 1159 bytes src/PrimitivesPlugin/icons/dimension_v.png | Bin 0 -> 410 bytes src/PrimitivesPlugin/icons/radius.png | Bin 0 -> 609 bytes src/PrimitivesPlugin/plugin-Primitives.xml | 5 + 22 files changed, 875 insertions(+), 5 deletions(-) create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Cylinder.h create mode 100644 src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp create mode 100644 src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h create mode 100644 src/PrimitivesPlugin/cylinder_widget.xml create mode 100755 src/PrimitivesPlugin/icons/angle.png create mode 100755 src/PrimitivesPlugin/icons/axis.png create mode 100644 src/PrimitivesPlugin/icons/cylinder.png create mode 100644 src/PrimitivesPlugin/icons/cylinder_32x32.png create mode 100644 src/PrimitivesPlugin/icons/cylinder_portion_32x32.png create mode 100644 src/PrimitivesPlugin/icons/dimension_v.png create mode 100644 src/PrimitivesPlugin/icons/radius.png diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index a7b04409c..aabc35d11 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -43,6 +43,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_ShapeAPI.h GeomAlgoAPI_Exception.h GeomAlgoAPI_Box.h + GeomAlgoAPI_Cylinder.h GeomAlgoAPI_XAOExport.h GeomAlgoAPI_XAOImport.h GeomAlgoAPI_Copy.h @@ -86,6 +87,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_ShapeAPI.cpp GeomAlgoAPI_Exception.cpp GeomAlgoAPI_Box.cpp + GeomAlgoAPI_Cylinder.cpp GeomAlgoAPI_XAOExport.cpp GeomAlgoAPI_XAOImport.cpp GeomAlgoAPI_Copy.cpp diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp new file mode 100644 index 000000000..4ee724e50 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp @@ -0,0 +1,112 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Cylinder.cpp +// Created: 05 Jan 2016 +// Author: Clarisse Genrault (CEA) + +#include + +#include +#include +#include +#include + +#include + +#include + +//================================================================================================= +GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder() +{ +} + +//================================================================================================= +GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder(std::shared_ptr theAxis, + const double theRadius, + const double theHeight) +{ + withAngle = false; + //myBasePoint = theBasePoint; + myAxis = theAxis; + myRadius = theRadius; + myHeight = theHeight; +} + +//================================================================================================= +GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder(std::shared_ptr theAxis, + const double theRadius, + const double theHeight, + const double theAngle) +{ + withAngle = true; + myAxis = theAxis; + myRadius = theRadius; + myHeight = theHeight; + myAngle = theAngle; +} + +//================================================================================================= +bool GeomAlgoAPI_Cylinder::check() +{ + if (!myAxis) { + myError = "Cylinder builder :: axis is invalid."; + return false; + } + if (myRadius < Precision::Confusion()) { + myError = "Cylinder builder :: radius is negative or null."; + return false; + } + if (myHeight < Precision::Confusion()) { + myError = "Cylinder builder :: height is negative or null."; + return false; + } + if (withAngle) { + if (myAngle < Precision::Angular() * 180./M_PI) { + myError = "Cylinder builder :: angle is negative or null."; + return false; + } + if (myAngle > 360.) { + myError = "Cylinder builder :: angle greater than 360 degrees."; + return false; + } + } + return true; +} + +//================================================================================================= +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.); + } else { + aCylinderMaker = new BRepPrimAPI_MakeCylinder(anAxis, myRadius, myHeight); + } + + aCylinderMaker->Build(); + + if (!aCylinderMaker->IsDone()) { + return; + } + + TopoDS_Shape aResult = aCylinderMaker->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 = "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 new file mode 100644 index 000000000..b0f91e27c --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h @@ -0,0 +1,59 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomAlgoAPI_Cylinder.h +// Created: 05 Jan 2016 +// Author: Clarisse Genrault (CEA) + +#ifndef GEOMALGOAPI_CYLINDER_H_ +#define GEOMALGOAPI_CYLINDER_H_ + +#include + +#include +#include + +/**\class GeomAlgoAPI_Cylinder + * \ingroup DataAlgo + * \brief Allows to create Cylinder Primitives + */ +class GeomAlgoAPI_Cylinder : public GeomAlgoAPI_MakeShape +{ + public: + GEOMALGOAPI_EXPORT GeomAlgoAPI_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 + /// \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, + const double theAngle); + + /// Checks if data for the cyminder construction is OK. + GEOMALGOAPI_EXPORT bool check(); + + /// Builds the cylinder. + GEOMALGOAPI_EXPORT void build(); + + private: + bool withAngle; + std::shared_ptr myBasePoint; + std::shared_ptr myAxis; /// Axis of the cylinder. + double myRadius; /// Radius of the cylinder. + double myHeight; /// Height of the cylinder. + double myAngle; /// Covering polar angle of the cylinder; +}; + + +#endif // GEOMALGOAPI_CYLINDER_H_ diff --git a/src/PrimitivesAPI/CMakeLists.txt b/src/PrimitivesAPI/CMakeLists.txt index 5453b7ad4..d0fa87593 100644 --- a/src/PrimitivesAPI/CMakeLists.txt +++ b/src/PrimitivesAPI/CMakeLists.txt @@ -6,10 +6,12 @@ INCLUDE(UnitTest) SET(PROJECT_HEADERS PrimitivesAPI.h PrimitivesAPI_Box.h + PrimitivesAPI_Cylinder.h ) SET(PROJECT_SOURCES PrimitivesAPI_Box.cpp + PrimitivesAPI_Cylinder.cpp ) SET(PROJECT_LIBRARIES @@ -67,4 +69,5 @@ INSTALL(TARGETS PrimitivesAPI DESTINATION ${SHAPER_INSTALL_BIN}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/PrimitivesAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) # Tests -ADD_UNIT_TESTS(TestBox.py) \ No newline at end of file +ADD_UNIT_TESTS(TestBox.py + TestCylinder.py) \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI.h b/src/PrimitivesAPI/PrimitivesAPI.h index 5ef0b78fc..45d5f57ce 100644 --- a/src/PrimitivesAPI/PrimitivesAPI.h +++ b/src/PrimitivesAPI/PrimitivesAPI.h @@ -17,4 +17,4 @@ #endif #endif -#endif +#endif //PRIMITIVESAPI_H diff --git a/src/PrimitivesAPI/PrimitivesAPI.i b/src/PrimitivesAPI/PrimitivesAPI.i index a84b85a33..28b92e235 100644 --- a/src/PrimitivesAPI/PrimitivesAPI.i +++ b/src/PrimitivesAPI/PrimitivesAPI.i @@ -20,6 +20,8 @@ // shared pointers %shared_ptr(PrimitivesAPI_Box) + %shared_ptr(PrimitivesAPI_Cylinder) // all supported interfaces %include "PrimitivesAPI_Box.h" +%include "PrimitivesAPI_Cylinder.h" diff --git a/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp new file mode 100644 index 000000000..42c10aed1 --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp @@ -0,0 +1,155 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: PrimitivesAPI_Cylinder.h +// Created: 12 Jan 2017 +// Author: Clarisse Genrault (CEA) + +#include "PrimitivesAPI_Cylinder.h" + +#include +#include +#include + +//================================================================================================== +PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +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) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER(), creationMethod()); + setObjects(theBasePoint, theAxis); + 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) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION(), creationMethod()); + setObjects(theBasePoint, theAxis); + setSizes(theRadius, theHeight); + setAngle(theAngle); + } +} + +//================================================================================================== +void PrimitivesAPI_Cylinder::setObjects(const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis) +{ + fillAttribute(theBasePoint, basePoint()); + fillAttribute(theAxis, axis()); + + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Cylinder::setSizes(const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight) +{ + fillAttribute(theRadius, radius()); + fillAttribute(theHeight, height()); + + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Cylinder::setAngle(const ModelHighAPI_Double& theAngle) +{ + fillAttribute(theAngle, angle()); + + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Cylinder::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + 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()); + AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Cylinder::RADIUS_ID()); + AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Cylinder::HEIGHT_ID()); + + theDumper << ", " << anAttrBasePoint << ", " << anAttrAxis; + theDumper << ", " << anAttrRadius << ", " << anAttrHeight; + + if (aCreationMethod == PrimitivesPlugin_Cylinder::CREATION_METHOD_CYLINDER_PORTION()) { + AttributeDoublePtr anAttrAngle = aBase->real(PrimitivesPlugin_Cylinder::ANGLE_ID()); + theDumper << ", " << anAttrAngle; + } + + theDumper << ")" << std::endl; +} + +//================================================================================================== +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) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); + return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis, + theRadius, theHeight, theAngle)); +} + +//================================================================================================== +CylinderPtr addCylinder(const std::shared_ptr& thePart, + const ModelHighAPI_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); + return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis, + theRadius, theHeight)); +} + +//================================================================================================== +CylinderPtr addCylinder(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRadius, + 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"); + return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, aBasePoint, anAxis, + theRadius, theHeight, theAngle)); +} + +//================================================================================================== +CylinderPtr addCylinder(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID()); + ModelHighAPI_Selection aBasePoint("VERT", "Origin"); + ModelHighAPI_Selection anAxis("EDGE", "OZ"); + 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 new file mode 100644 index 000000000..3e16d41c8 --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h @@ -0,0 +1,124 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D --> + +// File: PrimitivesAPI_Cylinder.h +// Created: 12 Jan 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef PRIMITIVESAPI_CYLINDER_H_ +#define PRIMITIVESAPI_CYLINDER_H_ + +#include "PrimitivesAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class PrimitivesAPI_Cylinder +/// \ingroup CPPHighAPI +/// \brief Interface for primitive Cylinder feature. +class PrimitivesAPI_Cylinder: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + 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_Selection& theBasePoint, + const ModelHighAPI_Selection& theAxis, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight); + PRIMITIVESAPI_EXPORT + explicit 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); + + /// 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 + 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; +}; + +/// Pointer on primitive Box object +typedef std::shared_ptr CylinderPtr; + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cylinder 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); + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cylinder 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); +/// \ingroup CPPHighAPI +/// \brief Create primitive Cylinder feature. +PRIMITIVESAPI_EXPORT +CylinderPtr addCylinder(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight, + const ModelHighAPI_Double& theAngle); + +/// \ingroup CPPHighAPI +/// \brief Create primitive Cylinder feature. +PRIMITIVESAPI_EXPORT +CylinderPtr addCylinder(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRadius, + const ModelHighAPI_Double& theHeight); + +#endif // PRIMITIVESAPI_CYLINDER_H_ \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI_swig.h b/src/PrimitivesAPI/PrimitivesAPI_swig.h index dc7f95a4c..98fc5bf03 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_swig.h +++ b/src/PrimitivesAPI/PrimitivesAPI_swig.h @@ -4,12 +4,13 @@ // Created: 28 June 2016 // Author: Clarisse Genrault (CEA) -#ifndef PrimitivesAPI_swig_H_ -#define PrimitivesAPI_swig_H_ +#ifndef PRIMITIVESAPI_SWIG_H_ +#define PRIMITIVESAPI_SWIG_H_ #include #include "PrimitivesAPI.h" #include "PrimitivesAPI_Box.h" + #include "PrimitivesAPI_Cylinder.h" -#endif // PrimitivesAPI_swig_H_ +#endif // PRIMITIVESAPI_SWIG_H_ diff --git a/src/PrimitivesPlugin/CMakeLists.txt b/src/PrimitivesPlugin/CMakeLists.txt index 2623477a5..e8aa0147a 100644 --- a/src/PrimitivesPlugin/CMakeLists.txt +++ b/src/PrimitivesPlugin/CMakeLists.txt @@ -8,16 +8,19 @@ SET(PROJECT_HEADERS PrimitivesPlugin.h PrimitivesPlugin_Plugin.h PrimitivesPlugin_Box.h + PrimitivesPlugin_Cylinder.h ) SET(PROJECT_SOURCES PrimitivesPlugin_Plugin.cpp PrimitivesPlugin_Box.cpp + PrimitivesPlugin_Cylinder.cpp ) SET(XML_RESOURCES plugin-Primitives.xml box_widget.xml + cylinder_widget.xml ) INCLUDE_DIRECTORIES( diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp new file mode 100644 index 000000000..fd336ae8b --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp @@ -0,0 +1,184 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: PrimitivesPlugin_Cylinder.cpp +// Created: 09 Jan 2017 +// Author: Clarisse Genrault (CEA) + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +//================================================================================================= +PrimitivesPlugin_Cylinder::PrimitivesPlugin_Cylinder() +{ +} + +//================================================================================================= +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()) { + ObjectPtr aPointObj = ModelAPI_Session::get()->moduleDocument() + ->objectByName(ModelAPI_ResultConstruction::group(), "Origin"); + if (aPointObj.get()) { + ResultPtr aPointRes = std::dynamic_pointer_cast(aPointObj); + 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()) { + 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_Cylinder::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Cylinder::CREATION_METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + + if (aMethodType == CREATION_METHOD_CYLINDER()) { + createCylinder(false); + } + + if (aMethodType == CREATION_METHOD_CYLINDER_PORTION()) { + createCylinder(true); + } +} + +//================================================================================================= +void PrimitivesPlugin_Cylinder::createCylinder(bool withAngle) +{ + // Getting point. + std::shared_ptr aBasePoint; + std::shared_ptr aPointRef = + selection(PrimitivesPlugin_Cylinder::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_Cylinder::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 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 = + std::shared_ptr(new GeomAlgoAPI_Cylinder(anAxis, + aRadius, aHeight, + anAngle)); + } else { + aCylinderAlgo = + std::shared_ptr(new GeomAlgoAPI_Cylinder(anAxis, + aRadius, aHeight)); + } + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aCylinderAlgo->check()) { + setError(aCylinderAlgo->getError(), false); + return; + } + + // Build the cylinder + aCylinderAlgo->build(); + + // Check if the creation of the cylinder + if(!aCylinderAlgo->isDone()) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aCylinderAlgo->getError(), false); + return; + } + if(!aCylinderAlgo->checkValid("Cylinder builder")) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aCylinderAlgo->getError(), false); + return; + } + + int aResultIndex = 0; + ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex); + loadNamingDS(aCylinderAlgo, aResultBox); + setResult(aResultBox, aResultIndex); +} + +//================================================================================================= +void PrimitivesPlugin_Cylinder::loadNamingDS(std::shared_ptr theCylinderAlgo, + std::shared_ptr theResultCylinder) +{ + + // Load the result + theResultCylinder->store(theCylinderAlgo->shape()); + + // Prepare the naming + theCylinderAlgo->prepareNamingFaces(); + + // Insert to faces + int num = 1; + std::map< std::string, std::shared_ptr > listOfFaces = + theCylinderAlgo->getCreatedFaces(); + for (std::map< std::string, std::shared_ptr >::iterator + it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) { + std::shared_ptr aFace = (*it).second; + theResultCylinder->generated(aFace, (*it).first, num++); + } +} diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h new file mode 100644 index 000000000..1f3dce27c --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h @@ -0,0 +1,116 @@ +// Copyright (C) 2014-201x CEA/DEN, EDF R&D + +// File: PrimitivesPlugin_Cylinder.h +// Created: 09 Jan 2017 +// Author: Clarisse Genrault (CEA) + +#ifndef PRIMITIVESPLUGIN_CYLINDER_H_ +#define PRIMITIVESPLUGIN_CYLINDER_H_ + +#include +#include +#include + +class GeomAPI_Shape; +class ModelAPI_ResultBody; + +/**\class PrimitivesPlugin_Cylinder + * \ingroup Plugins + * \brief Feature for creation of a cylinder. + * + * Creates a cylinder from a radius, a height, an angle, a center point defaulting to + * the origin and an axis defaulting to OZ + */ +class PrimitivesPlugin_Cylinder : public ModelAPI_Feature +{ + public: + /// Cylinder kind + inline static const std::string& ID() + { + static const std::string MY_CYLINDER_ID("Cylinder"); + return MY_CYLINDER_ID; + } + + /// Attribute name for creation method + inline static const std::string& CREATION_METHOD() + { + 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() + { + static const std::string MY_CREATION_METHOD_ID("CylinderPortion"); + return MY_CREATION_METHOD_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 height + inline static const std::string& HEIGHT_ID() + { + static const std::string MY_HEIGHT_ID("height"); + return MY_HEIGHT_ID; + } + + /// Attribute name of the angle + inline static const std::string& ANGLE_ID() + { + static const std::string MY_ANGLE_ID("angle"); + return MY_ANGLE_ID; + } + + /// Returns the kind of a feature + PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = PrimitivesPlugin_Cylinder::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_Cylinder(); + + private: + /// Load Naming data structure of the feature to the document + void loadNamingDS(std::shared_ptr theCylinderAlgo, + std::shared_ptr theResultCylinder); + + ///Perform the creation of a cylinder + void createCylinder(bool withAngle); + +}; + +#endif // PRIMITIVESPLUGIN_CYLINDER_H_ diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp index bf3e1716c..b3ef9cbf3 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -26,6 +27,8 @@ FeaturePtr PrimitivesPlugin_Plugin::createFeature(std::string theFeatureID) { if (theFeatureID == PrimitivesPlugin_Box::ID()) { return FeaturePtr(new PrimitivesPlugin_Box); + } else if (theFeatureID == PrimitivesPlugin_Cylinder::ID()) { + return FeaturePtr(new PrimitivesPlugin_Cylinder); } // feature of such kind is not found return FeaturePtr(); diff --git a/src/PrimitivesPlugin/cylinder_widget.xml b/src/PrimitivesPlugin/cylinder_widget.xml new file mode 100644 index 000000000..a9469742e --- /dev/null +++ b/src/PrimitivesPlugin/cylinder_widget.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/angle.png b/src/PrimitivesPlugin/icons/angle.png new file mode 100755 index 0000000000000000000000000000000000000000..e401acd67fd22b2edacd3b53e3dc9c6c8a0c1469 GIT binary patch literal 499 zcmV?ss z0*&cJ^g7Vh+a{iwSL01)cH)QpAsZ+KN)@dOh9Yx<=?4(k)c@5CAc4-ltK0<7K>0_- zb8k>J0_O@BS=U;5IEdXA0?bFIG7MaPqOCDiuLY3>5uR+zJ*sQ(8Tc6>dX&jNHj6M0 zJc^}mCbjK2$<2KyxiyP1VMQkb?cu5706i z+Fe-`@UDxEjhABg_sQ*RfnB@I4E+lDO|G&oBH@1n1aqe%)$iW+(;N&%mc=$TsMin- zMb?04UjU#9=s*m>AaLyW38TPkF86>DUx0KXdIc=z>}om@J@vgrUZyQB{&gHt)}APb$D<$`;Bw z<=IGd6|@2}jR44nl_2W{>niLGG(>C0M$qk=5VZZb{NCl#O7PqW?}1Gq`l)LDrE&IZ zCCIwI1G24R)<7Qm+e;1LUqQwxxr!Vkru1|bo{U8@5A4772>YU#H)g!RL#YyJ(5as{ zhs})KAmjRZl%qI!q#(T*EP+%}DaOG=1!>POh~W^GV&~?x6$cLprrh$fs2m7p#RdkD zwBs)Ty8`11Il&a#*Ws-V43GkLfSIpfG?T#4KVjlm{*eU!7Hj~Iz#XuaRPYHVD`q^4 SbHEe;0000ugK~y-6rISxfRACf{pL5@LW@=_a5Q5YJY3L&;IMY^&q*XMF z{t3B`zCmBWFVLc$3o)T~YKpXK)!tGlp>(W8IfHY>%iR0Er$uV_8X9B2)j0=#59b`t z5mKt$ZVai{Ns#L(RiIx%1zNyoLEagk%zRmX{q4vjN5SB&#uI^Q;38+Mi^z0yasJsc zpgP{@i*ouy5NnKOV*Cczu2#8JE~5&a{SKctH(6R;!FdOO33B~k7iL=)z!_H*%<{9 literal 0 HcmV?d00001 diff --git a/src/PrimitivesPlugin/icons/cylinder_32x32.png b/src/PrimitivesPlugin/icons/cylinder_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..80a39989dbc692aca1a11a9040af18cb801e0d96 GIT binary patch literal 873 zcmV-v1D5=WP)Tk+&^ZiZTIM z=>n@)AIMW>9>9{o;*8A!EX!i)qQ&E1GA&~Q;G_$TF6b8$Uja{^J!}acv1q|U zY|H+^n@T0=>h9)I$7Ak=9{`|Ww1{Z|zDdFNlAg4+-<7uZyX56Llopp#R#u8C3=R!4 zoEXOQlHXE%z!FGJ3V@sEB+s5W^(xZUIS_sru6h!Q)WrJZ#QNjkJ+@_2yL82ib!!^l z)h@3sIC%6>gGqBE007s`pI;xW%dZdCp~8soCF9AIm+%#FU3Z#o*%d$l2q@ZX+T0jm zqC_dQ9jDNCew`|6c)5)$?J4+kNmex{A3&xUK+vfLP*pp#D~AC8zz$$rmU-D6OaRSh z4|4$k=+ptIpjq_K!7)_HqJ55jK{g|p{0RuEI)wma(L5&rzWSr83Tjq6ttk=;d7#l$ z%6Ai=K6aV{#0Lhu0T4z_{J*`oO9CrOP~Ftley7s1tVc5{Dqa`l7uX_FGSTO&-#0Kc z5V>`yt>@f@^J`R9MCI_%%SbpAK&Hoo%-**5ILHye1rQOcXI1yPj{8Y0O^uC>mG-=U zKYhaDjR|rr+H(061~-z?>!oVz{u-NP6Cyi+AW-;||$(byqDRu>YC8Ji24&!lSuZ zjJMx=7q8pH)9rg`3~s~ib~8VpN_(Q~pF;PiM`XIm}_cdmyu8}6u3TLY?aS6%(W zecMiQ_=``O3WovsF#ak^NAJ=V7WaCptg$7=LtUa zz=Lg#4Nd0&0;PdCfTO<%EuuFhx@iEI0Ms}Zn6wAi$7s%sD+MT?aOOaUfH+rTrJk8AGqSI51z^pU zjRwGATck^EoHLN7GD~;EssQwt4W?9V6>&z8I3TLJwA~KZGV^I=0F;+IZD>T(!f6W} z^Ro|OS~!-7tpY$Wm~J@{=Oio$rYo?_P7{gwRRHMdSojzj6$4>XbpqO9ypRJ}^2qR+<@`FS#q<3xPWu{y})M@AS{L7cPztPh6QOo|+C< z*h#w#7&a=ei3P@(`jNjcR!>K!Z*xLbRoc^g1D_+-gAa5yDit0OK$G_^xm%HH69SnuM;The7@CHZ_!@lwE&hHD2|9>sF Z{sq9^qr{4=f?WUr002ovPDHLkV1gGo6^;M^ literal 0 HcmV?d00001 diff --git a/src/PrimitivesPlugin/icons/dimension_v.png b/src/PrimitivesPlugin/icons/dimension_v.png new file mode 100644 index 0000000000000000000000000000000000000000..15e26af4313c0a134b25b792ee7ba0ba65eb6b17 GIT binary patch literal 410 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR44RVs|AM1d$CWzM5|7L0*ccp@Jy%n#XM9~{W56s?{{y%7h|DnXbYfs*GMPK&cDJ!% z>Cywg(pO5hZOCHi&iQ`!4C4ds;-cS9do3>g%sD^%k5_N{Xa|$V!940DBA)IM+Q$0nf??p}(*L~~d6B5+&VyH2&n9Nr)<%@^~J)=y0&bI*~FEVuD_ zp_tzhPi4}wh8(Ny4KeEs@Sz?I5U34;zXM=i0+frRW55e7>0IRH-=3-m15~9x!7TP7 z3e&5sDNFkzM0>zD>%oa+_L{_TE7q}PY3uB#qdR}Bc$Q~mU5FY@Zc3-OMcRDBqPJWe ze%B}$Fr}K+vEKMHHukl)==kq_H%L~8p%f&Sg6OOls!SHXHJS``$}WYf`~=w5lFFX_ zLwJqisZ1I;3aED;e7yDm>7A8c^VvE#k;bn v8^JBfT=!4;HD;zVp1%YC^O#ojujl*=w`Ss4LGYbO00000NkvXXu0mjfR;Ca( literal 0 HcmV?d00001 diff --git a/src/PrimitivesPlugin/plugin-Primitives.xml b/src/PrimitivesPlugin/plugin-Primitives.xml index e3ababf71..13e22414a 100644 --- a/src/PrimitivesPlugin/plugin-Primitives.xml +++ b/src/PrimitivesPlugin/plugin-Primitives.xml @@ -8,5 +8,10 @@ + + + + + -- 2.39.2