From: Clarisse Genrault Date: Thu, 12 Jan 2017 11:23:24 +0000 (+0100) Subject: Add "Cylinder" primitive. X-Git-Tag: V_2.7.0~348 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ccd1d538ff04366093c86220b22b53c4b7370f14;p=modules%2Fshaper.git Add "Cylinder" primitive. --- 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 000000000..e401acd67 Binary files /dev/null and b/src/PrimitivesPlugin/icons/angle.png differ diff --git a/src/PrimitivesPlugin/icons/axis.png b/src/PrimitivesPlugin/icons/axis.png new file mode 100755 index 000000000..015d270bf Binary files /dev/null and b/src/PrimitivesPlugin/icons/axis.png differ diff --git a/src/PrimitivesPlugin/icons/cylinder.png b/src/PrimitivesPlugin/icons/cylinder.png new file mode 100644 index 000000000..200b9d133 Binary files /dev/null and b/src/PrimitivesPlugin/icons/cylinder.png differ diff --git a/src/PrimitivesPlugin/icons/cylinder_32x32.png b/src/PrimitivesPlugin/icons/cylinder_32x32.png new file mode 100644 index 000000000..80a39989d Binary files /dev/null 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 new file mode 100644 index 000000000..4f8177c43 Binary files /dev/null and b/src/PrimitivesPlugin/icons/cylinder_portion_32x32.png differ diff --git a/src/PrimitivesPlugin/icons/dimension_v.png b/src/PrimitivesPlugin/icons/dimension_v.png new file mode 100644 index 000000000..15e26af43 Binary files /dev/null and b/src/PrimitivesPlugin/icons/dimension_v.png differ diff --git a/src/PrimitivesPlugin/icons/radius.png b/src/PrimitivesPlugin/icons/radius.png new file mode 100644 index 000000000..7ff3b4d2b Binary files /dev/null and b/src/PrimitivesPlugin/icons/radius.png differ 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 @@ + + + + +