GeomAlgoAPI_ShapeAPI.h
GeomAlgoAPI_Exception.h
GeomAlgoAPI_Box.h
+ GeomAlgoAPI_Cylinder.h
GeomAlgoAPI_XAOExport.h
GeomAlgoAPI_XAOImport.h
GeomAlgoAPI_Copy.h
GeomAlgoAPI_ShapeAPI.cpp
GeomAlgoAPI_Exception.cpp
GeomAlgoAPI_Box.cpp
+ GeomAlgoAPI_Cylinder.cpp
GeomAlgoAPI_XAOExport.cpp
GeomAlgoAPI_XAOImport.cpp
GeomAlgoAPI_Copy.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Cylinder.cpp
+// Created: 05 Jan 2016
+// Author: Clarisse Genrault (CEA)
+
+#include <GeomAlgoAPI_Cylinder.h>
+
+#include <gp_Ax2.hxx>
+#include <gp_Dir.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <BRepPrimAPI_MakeCylinder.hxx>
+
+#include <iostream>
+
+//=================================================================================================
+GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder()
+{
+}
+
+//=================================================================================================
+GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder(std::shared_ptr<GeomAPI_Ax2> theAxis,
+ const double theRadius,
+ const double theHeight)
+{
+ withAngle = false;
+ //myBasePoint = theBasePoint;
+ myAxis = theAxis;
+ myRadius = theRadius;
+ myHeight = theHeight;
+}
+
+//=================================================================================================
+GeomAlgoAPI_Cylinder::GeomAlgoAPI_Cylinder(std::shared_ptr<GeomAPI_Ax2> 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<gp_Ax2>();
+
+ // 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<GeomAPI_Shape> 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);
+}
--- /dev/null
+// 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 <GeomAlgoAPI_MakeShape.h>
+
+#include <GeomAPI_Ax2.h>
+#include <GeomAPI_Pnt.h>
+
+/**\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<GeomAPI_Ax2> 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<GeomAPI_Ax2> 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<GeomAPI_Pnt> myBasePoint;
+ std::shared_ptr<GeomAPI_Ax2> 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_
SET(PROJECT_HEADERS
PrimitivesAPI.h
PrimitivesAPI_Box.h
+ PrimitivesAPI_Cylinder.h
)
SET(PROJECT_SOURCES
PrimitivesAPI_Box.cpp
+ PrimitivesAPI_Cylinder.cpp
)
SET(PROJECT_LIBRARIES
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
#endif
#endif
-#endif
+#endif //PRIMITIVESAPI_H
// shared pointers
%shared_ptr(PrimitivesAPI_Box)
+ %shared_ptr(PrimitivesAPI_Cylinder)
// all supported interfaces
%include "PrimitivesAPI_Box.h"
+%include "PrimitivesAPI_Cylinder.h"
--- /dev/null
+// 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 <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+//==================================================================================================
+PrimitivesAPI_Cylinder::PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_Feature>& 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<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Selection& theBasePoint,
+ const ModelHighAPI_Selection& theAxis,
+ const ModelHighAPI_Double& theRadius,
+ const ModelHighAPI_Double& theHeight,
+ const ModelHighAPI_Double& theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
+ return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
+ theRadius, theHeight, theAngle));
+}
+
+//==================================================================================================
+CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Selection& theBasePoint,
+ const ModelHighAPI_Selection& theAxis,
+ const ModelHighAPI_Double& theRadius,
+ const ModelHighAPI_Double& theHeight)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Cylinder::ID());
+ return CylinderPtr(new PrimitivesAPI_Cylinder(aFeature, theBasePoint, theAxis,
+ theRadius, theHeight));
+}
+
+//==================================================================================================
+CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theRadius,
+ const ModelHighAPI_Double& theHeight,
+ const ModelHighAPI_Double& theAngle)
+{
+ std::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theRadius,
+ const ModelHighAPI_Double& theHeight)
+{
+ std::shared_ptr<ModelAPI_Feature> 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
--- /dev/null
+// 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 <PrimitivesPlugin_Cylinder.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+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<ModelAPI_Feature>& theFeature);
+
+ /// Constructor with values.
+ PRIMITIVESAPI_EXPORT
+ explicit PrimitivesAPI_Cylinder(const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_Feature>& 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<ModelAPI_Feature>& 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<PrimitivesAPI_Cylinder> CylinderPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create primitive Cylinder feature.
+PRIMITIVESAPI_EXPORT
+CylinderPtr addCylinder(const std::shared_ptr<ModelAPI_Document>& 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<ModelAPI_Document>& 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<ModelAPI_Document>& 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<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theRadius,
+ const ModelHighAPI_Double& theHeight);
+
+#endif // PRIMITIVESAPI_CYLINDER_H_
\ No newline at end of file
// 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 <ModelHighAPI_swig.h>
#include "PrimitivesAPI.h"
#include "PrimitivesAPI_Box.h"
+ #include "PrimitivesAPI_Cylinder.h"
-#endif // PrimitivesAPI_swig_H_
+#endif // PRIMITIVESAPI_SWIG_H_
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(
--- /dev/null
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D
+
+// File: PrimitivesPlugin_Cylinder.cpp
+// Created: 09 Jan 2017
+// Author: Clarisse Genrault (CEA)
+
+#include <PrimitivesPlugin_Cylinder.h>
+
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Lin.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Session.h>
+
+#include <iostream>
+
+//=================================================================================================
+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<ModelAPI_Result>(aPointObj);
+ aBasePoint->setValue(aPointRes, std::shared_ptr<GeomAPI_Shape>());
+ }
+ }
+
+ // 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<ModelAPI_Result>(anAxisObj);
+ anAxis->setValue(anAxisRes, std::shared_ptr<GeomAPI_Shape>());
+ }
+ }
+}
+
+//=================================================================================================
+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<GeomAPI_Pnt> aBasePoint;
+ std::shared_ptr<ModelAPI_AttributeSelection> 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<GeomAPI_Ax2> anAxis;
+ std::shared_ptr<GeomAPI_Edge> anEdge;
+ std::shared_ptr<ModelAPI_AttributeSelection> anEdgeRef =
+ selection(PrimitivesPlugin_Cylinder::AXIS_ID());
+ if(anEdgeRef && anEdgeRef->value() && anEdgeRef->value()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->value()));
+ } else if (anEdgeRef && !anEdgeRef->value() && anEdgeRef->context() &&
+ anEdgeRef->context()->shape() && anEdgeRef->context()->shape()->isEdge()) {
+ anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anEdgeRef->context()->shape()));
+ }
+ if(anEdge) {
+ anAxis = std::shared_ptr<GeomAPI_Ax2>(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<GeomAlgoAPI_Cylinder> aCylinderAlgo;
+ if (withAngle) {
+ // Getting angle
+ double anAngle = real(PrimitivesPlugin_Cylinder::ANGLE_ID())->value();
+ aCylinderAlgo =
+ std::shared_ptr<GeomAlgoAPI_Cylinder>(new GeomAlgoAPI_Cylinder(anAxis,
+ aRadius, aHeight,
+ anAngle));
+ } else {
+ aCylinderAlgo =
+ std::shared_ptr<GeomAlgoAPI_Cylinder>(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<GeomAlgoAPI_Cylinder> theCylinderAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> 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<GeomAPI_Shape> > listOfFaces =
+ theCylinderAlgo->getCreatedFaces();
+ for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator
+ it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) {
+ std::shared_ptr<GeomAPI_Shape> aFace = (*it).second;
+ theResultCylinder->generated(aFace, (*it).first, num++);
+ }
+}
--- /dev/null
+// 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 <PrimitivesPlugin.h>
+#include <ModelAPI_Feature.h>
+#include <GeomAlgoAPI_Cylinder.h>
+
+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<GeomAlgoAPI_Cylinder> theCylinderAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultCylinder);
+
+ ///Perform the creation of a cylinder
+ void createCylinder(bool withAngle);
+
+};
+
+#endif // PRIMITIVESPLUGIN_CYLINDER_H_
#include <PrimitivesPlugin_Plugin.h>
#include <PrimitivesPlugin_Box.h>
+#include <PrimitivesPlugin_Cylinder.h>
#include <ModelAPI_Session.h>
#include <string>
{
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();
--- /dev/null
+<!-- Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
+
+<source>
+ <toolbox id="CreationMethod">
+ <box id="Cylinder" title="Cylinder" icon="icons/Primitives/cylinder_32x32.png">
+ <shape_selector
+ id="base_point"
+ label="base_point"
+ default=""
+ shape_types="vertex"
+ icon="icons/Primitives/point.png"
+ tooltip="Select the center of the base of the cylinder">
+ <validator id="GeomValidators_ConstructionComposite"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </shape_selector>
+ <shape_selector
+ id="axis"
+ label="axis"
+ default=""
+ shape_types="edge"
+ icon="icons/Primitives/axis.png"
+ tooltip="Select the axis of the cylinder">
+ <validator id="GeomValidators_ConstructionComposite"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ </shape_selector>
+ <doublevalue
+ id="radius"
+ label="radius"
+ step="1."
+ default="5."
+ min="0."
+ icon="icons/Primitives/radius.png"
+ tooltip="Enter the radius of the cylinder">
+ <validator id="GeomValidators_Positive"/>
+ </doublevalue>
+ <doublevalue
+ id="height"
+ label="height"
+ step="1."
+ default="10."
+ min="0."
+ icon="icons/Primitives/dimension_v.png"
+ tooltip="Enter the height of the cylinder">
+ <validator id="GeomValidators_Positive"/>
+ </doublevalue>
+ </box>
+ <box id="CylinderPortion" title="Portion of cylinder" icon="icons/Primitives/cylinder_portion_32x32.png">
+ <shape_selector
+ id="base_point"
+ label="base_point"
+ default=""
+ shape_types="vertex"
+ icon="icons/Primitives/point.png"
+ tooltip="Select the center of the base of the cylinder">
+ <validator id="GeomValidators_ConstructionComposite"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </shape_selector>
+ <shape_selector
+ id="axis"
+ label="axis"
+ default=""
+ shape_types="edge"
+ icon="icons/Primitives/axis.png"
+ tooltip="Select the axis of the cylinder">
+ <validator id="GeomValidators_ConstructionComposite"/>
+ <validator id="GeomValidators_ShapeType" parameters="line"/>
+ </shape_selector>
+ <doublevalue
+ id="radius"
+ label="radius"
+ step="1."
+ default="5."
+ min="0."
+ icon="icons/Primitives/radius.png"
+ tooltip="Enter the radius of the cylinder">
+ <validator id="GeomValidators_Positive"/>
+ </doublevalue>
+ <doublevalue
+ id="height"
+ label="height"
+ step="1."
+ default="10."
+ min="0."
+ icon="icons/Primitives/dimension_v.png"
+ tooltip="Enter the height of the cylinder">
+ <validator id="GeomValidators_Positive"/>
+ </doublevalue>
+ <doublevalue
+ id="angle"
+ label="angle"
+ step="10."
+ default="45.0"
+ min="0."
+ max="360."
+ icon="icons/Primitives/angle.png"
+ tooltip="Enter the angle of the portion of the cylinder">
+ <validator id="GeomValidators_Positive"/>
+ </doublevalue>
+ </box>
+ </toolbox>
+</source>
<source path="box_widget.xml"/>
</feature>
</group>
+ <group id="Primitives">
+ <feature id="Cylinder" title="Cylinder" tooltip="Create a cylinder" icon="icons/Primitives/cylinder.png">
+ <source path="cylinder_widget.xml"/>
+ </feature>
+ </group>
</workbench>
</plugin>