]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add "Cylinder" primitive.
authorClarisse Genrault <clarisse.genrault@cea.fr>
Thu, 12 Jan 2017 11:23:24 +0000 (12:23 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Thu, 12 Jan 2017 11:23:24 +0000 (12:23 +0100)
22 files changed:
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h [new file with mode: 0644]
src/PrimitivesAPI/CMakeLists.txt
src/PrimitivesAPI/PrimitivesAPI.h
src/PrimitivesAPI/PrimitivesAPI.i
src/PrimitivesAPI/PrimitivesAPI_Cylinder.cpp [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_Cylinder.h [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_swig.h
src/PrimitivesPlugin/CMakeLists.txt
src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.cpp [new file with mode: 0644]
src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h [new file with mode: 0644]
src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp
src/PrimitivesPlugin/cylinder_widget.xml [new file with mode: 0644]
src/PrimitivesPlugin/icons/angle.png [new file with mode: 0755]
src/PrimitivesPlugin/icons/axis.png [new file with mode: 0755]
src/PrimitivesPlugin/icons/cylinder.png [new file with mode: 0644]
src/PrimitivesPlugin/icons/cylinder_32x32.png [new file with mode: 0644]
src/PrimitivesPlugin/icons/cylinder_portion_32x32.png [new file with mode: 0644]
src/PrimitivesPlugin/icons/dimension_v.png [new file with mode: 0644]
src/PrimitivesPlugin/icons/radius.png [new file with mode: 0644]
src/PrimitivesPlugin/plugin-Primitives.xml

index a7b04409ca5cf0a85266da861cbd8fe660ddbcd4..aabc35d119c4f045f25bc666fe4fc718a1e70842 100644 (file)
@@ -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 (file)
index 0000000..4ee724e
--- /dev/null
@@ -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 <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);
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h b/src/GeomAlgoAPI/GeomAlgoAPI_Cylinder.h
new file mode 100644 (file)
index 0000000..b0f91e2
--- /dev/null
@@ -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 <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_
index 5453b7ad449d5fd3a125888503bf3d51e388a9e7..d0fa875935caaa4ea44297e45e07f6d6cd92ebfd 100644 (file)
@@ -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
index 5ef0b78fc91cf489c4439b5f9141035cf5f45ea7..45d5f57ce552884535aa976f93f4c4d8f33f760d 100644 (file)
@@ -17,4 +17,4 @@
 #endif
 #endif
 
-#endif
+#endif //PRIMITIVESAPI_H
index a84b85a3390a8d6005a07e09fcd81dfbfc0c1dda..28b92e23556247fe7041ec08eacacc94152dab5a 100644 (file)
@@ -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 (file)
index 0000000..42c10ae
--- /dev/null
@@ -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 <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
diff --git a/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h b/src/PrimitivesAPI/PrimitivesAPI_Cylinder.h
new file mode 100644 (file)
index 0000000..3e16d41
--- /dev/null
@@ -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 <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
index dc7f95a4c9a2e2a24f1e2eb8eb255cfb8fa4bbb6..98fc5bf038f2e06b8e44092be534341ffa97a30b 100644 (file)
@@ -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 <ModelHighAPI_swig.h>
 
   #include "PrimitivesAPI.h"
   #include "PrimitivesAPI_Box.h"
+  #include "PrimitivesAPI_Cylinder.h"
 
-#endif // PrimitivesAPI_swig_H_
+#endif // PRIMITIVESAPI_SWIG_H_
index 2623477a50d91b975caf65a92367371d35d640dd..e8aa0147acde67309a3543252281d6b48914215c 100644 (file)
@@ -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 (file)
index 0000000..fd336ae
--- /dev/null
@@ -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 <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++);
+  }
+}
diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h b/src/PrimitivesPlugin/PrimitivesPlugin_Cylinder.h
new file mode 100644 (file)
index 0000000..1f3dce2
--- /dev/null
@@ -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 <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_
index bf3e1716c034b8933e2c194c13d556d16debc16e..b3ef9cbf35386cb2001d694ad4b01b6bfc0d2455 100644 (file)
@@ -7,6 +7,7 @@
 #include <PrimitivesPlugin_Plugin.h>
 
 #include <PrimitivesPlugin_Box.h>
+#include <PrimitivesPlugin_Cylinder.h>
 #include <ModelAPI_Session.h>
 
 #include <string>
@@ -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 (file)
index 0000000..a946974
--- /dev/null
@@ -0,0 +1,101 @@
+<!-- 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>
diff --git a/src/PrimitivesPlugin/icons/angle.png b/src/PrimitivesPlugin/icons/angle.png
new file mode 100755 (executable)
index 0000000..e401acd
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 (executable)
index 0000000..015d270
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 (file)
index 0000000..200b9d1
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 (file)
index 0000000..80a3998
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 (file)
index 0000000..4f8177c
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 (file)
index 0000000..15e26af
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 (file)
index 0000000..7ff3b4d
Binary files /dev/null and b/src/PrimitivesPlugin/icons/radius.png differ
index e3ababf71245c1bc6db147a792aebc567e61f5ab..13e22414ae0bbf3ce18b30b2a5dc29e8741ad7c7 100644 (file)
@@ -8,5 +8,10 @@
         <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>