]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added "Sphere" primitive.
authorClarisse Genrault <clarisse.genrault@cea.fr>
Thu, 16 Mar 2017 15:27:33 +0000 (16:27 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Thu, 16 Mar 2017 15:27:33 +0000 (16:27 +0100)
18 files changed:
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h
src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h [new file with mode: 0644]
src/PrimitivesAPI/CMakeLists.txt
src/PrimitivesAPI/PrimitivesAPI.i
src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_Sphere.h [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_swig.h
src/PrimitivesPlugin/CMakeLists.txt
src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp
src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp [new file with mode: 0644]
src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h [new file with mode: 0644]
src/PrimitivesPlugin/icons/sphere.png [new file with mode: 0644]
src/PrimitivesPlugin/plugin-Primitives.xml
src/PrimitivesPlugin/sphere_widget.xml [new file with mode: 0644]
src/PythonAPI/model/primitives/__init__.py

index 2b5d6a2c6089ffab441f6356c7cf69fa8dc5b9ae..f3390147c6a7c5291eca17f8d7360ec27b77272b 100644 (file)
@@ -43,6 +43,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_Exception.h
     GeomAlgoAPI_Box.h
     GeomAlgoAPI_Cylinder.h
+    GeomAlgoAPI_Sphere.h
     GeomAlgoAPI_XAOExport.h
     GeomAlgoAPI_XAOImport.h
     GeomAlgoAPI_Copy.h
@@ -88,6 +89,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_Exception.cpp
     GeomAlgoAPI_Box.cpp
     GeomAlgoAPI_Cylinder.cpp
+    GeomAlgoAPI_Sphere.cpp
     GeomAlgoAPI_XAOExport.cpp
     GeomAlgoAPI_XAOImport.cpp
     GeomAlgoAPI_Copy.cpp
index 9765c645656fb2ed2fdd034530bb0f5e893a427e..55050b96ab1a6023669f03223a427a2333966f41 100644 (file)
@@ -7,12 +7,13 @@
 #include "GeomAlgoAPI_ShapeAPI.h"
 
 #include <GeomAlgoAPI_Box.h>
-#include <GeomAlgoAPI_Cylinder.h>
 #include <GeomAlgoAPI_CompoundBuilder.h>
 #include <GeomAlgoAPI_ConeSegment.h>
+#include <GeomAlgoAPI_Cylinder.h>
 #include <GeomAlgoAPI_EdgeBuilder.h>
 #include <GeomAlgoAPI_Rotation.h>
 #include <GeomAlgoAPI_Scale.h>
+#include <GeomAlgoAPI_Sphere.h>
 #include <GeomAlgoAPI_Symmetry.h>
 #include <GeomAlgoAPI_Translation.h>
 
@@ -192,6 +193,53 @@ namespace GeomAlgoAPI_ShapeAPI
     return aCylinderAlgo.shape();
   }
 
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(
+      std::shared_ptr<GeomAPI_Pnt> theCenterPoint, double theRadius) throw (GeomAlgoAPI_Exception)
+  {
+    GeomAlgoAPI_Sphere aSphereAlgo(theCenterPoint, theRadius);
+
+    if (!aSphereAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    aSphereAlgo.build();
+
+    if(!aSphereAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    if (!aSphereAlgo.checkValid("Sphere builder")) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+    return aSphereAlgo.shape();
+  }
+
+  //===============================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeSphere(double theRadius)
+      throw (GeomAlgoAPI_Exception)
+  {
+    std::shared_ptr<GeomAPI_Pnt> aCenterPoint =
+      std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(0.,0.,0.));
+
+    GeomAlgoAPI_Sphere aSphereAlgo(aCenterPoint, theRadius);
+
+    if (!aSphereAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    aSphereAlgo.build();
+
+    if(!aSphereAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+
+    if (!aSphereAlgo.checkValid("Sphere builder")) {
+      throw GeomAlgoAPI_Exception(aSphereAlgo.getError());
+    }
+    return aSphereAlgo.shape();
+  }
+
   //===============================================================================================
   std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
     std::shared_ptr<GeomAPI_Shape> theSourceShape,
index 3f137c4fe033d332c836e1fc6ae937a74042fcd6..1743e6d66002a356ed77ccf175c202a4613083ab 100644 (file)
@@ -71,6 +71,17 @@ public:
   static std::shared_ptr<GeomAPI_Shape> makeCylinder(double theRadius, double theHeight,
                      double theAngle) throw (GeomAlgoAPI_Exception);
 
+  /// Creates a sphere using a center and a radius.
+  /// \param theCenterPoint The center of the sphere
+  /// \param theRadius The radius of the sphere
+  static std::shared_ptr<GeomAPI_Shape> makeSphere(std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
+                     double theRadius) throw (GeomAlgoAPI_Exception);
+
+  /// Creates a sphere using the origin and a radius.
+  /// \param theRadius The radius of the cylinder
+  static std::shared_ptr<GeomAPI_Shape> makeSphere(double theRadius)
+                     throw (GeomAlgoAPI_Exception);
+
   /// Performs a translation from an axis and a distance.
   /// \param theSourceShape Shape to be moved
   /// \param theAxis Movement axis
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp
new file mode 100644 (file)
index 0000000..b2642c9
--- /dev/null
@@ -0,0 +1,68 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAlgoAPI_Sphere.h
+// Created:     16 Mar 2017
+// Author:      Clarisse Genrault (CEA)
+
+#include <GeomAlgoAPI_Sphere.h>
+
+#include <BRepPrimAPI_MakeSphere.hxx>
+
+//=================================================================================================
+GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere()
+{
+}
+
+//=================================================================================================
+GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere(std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
+                                       const double theRadius)
+{
+  myCenterPoint = theCenterPoint;
+  myRadius = theRadius;
+}
+
+//=================================================================================================
+bool GeomAlgoAPI_Sphere::check()
+{
+  if (!myCenterPoint) {
+    myError = "Sphere builder :: center is not valid.";
+    return false;
+  }
+  if (myRadius < Precision::Confusion()) {
+    myError = "Sphere builder :: radius is negative or null.";
+    return false;
+  }
+  return true;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_Sphere::build()
+{
+  myCreatedFaces.clear();
+
+  const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
+
+  // Construct the sphere
+  BRepPrimAPI_MakeSphere *aSphereMaker = new BRepPrimAPI_MakeSphere(aCenterPoint, myRadius);
+
+  aSphereMaker->Build();
+
+  if (!aSphereMaker->IsDone()) {
+    return;
+  }
+
+  TopoDS_Shape aResult = aSphereMaker->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 = "Sphere builder :: resulting shape is null.";
+    return;
+  }
+
+  setImpl(aSphereMaker);
+
+  setDone(true);
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h
new file mode 100644 (file)
index 0000000..f317a26
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAlgoAPI_Sphere.h
+// Created:     16 Mar 2017
+// Author:      Clarisse Genrault (CEA)
+
+#ifndef GEOMALGOAPI_SPHERE_H_
+#define GEOMALGOAPI_SPHERE_H_
+
+#include <GeomAlgoAPI_MakeShape.h>
+
+#include <GeomAPI_Pnt.h>
+
+/**\class GeomAlgoAPI_Sphere
+ * \ingroup DataAlgo
+ * \brief Allows to create Sphere Primitives
+ */
+class GeomAlgoAPI_Sphere : public GeomAlgoAPI_MakeShape
+{
+ public:
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere();
+
+  /// Creates a sphere.
+  /// \param theCenterPoint The center point of the sphere
+  /// \param theRadius The radius of the sphere
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere(std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
+                                        const double theRadius);
+
+  /// Checks if data for the sphere construction is OK.
+  GEOMALGOAPI_EXPORT bool check();
+
+  /// Builds the sphere.
+  GEOMALGOAPI_EXPORT void build();
+
+ private:
+  std::shared_ptr<GeomAPI_Pnt> myCenterPoint; /// Center of the sphere.
+  double myRadius;
+};
+
+#endif // GEOMALGOAPI_SPHERE_H_
index abd9c9f1fa0363a7b91c0aa7b3830d1ad533ce12..cbe3c9aade2871a784d144bcdac7b28f6053bbc2 100644 (file)
@@ -6,11 +6,13 @@ SET(PROJECT_HEADERS
   PrimitivesAPI.h
   PrimitivesAPI_Box.h
   PrimitivesAPI_Cylinder.h
+  PrimitivesAPI_Sphere.h
 )
 
 SET(PROJECT_SOURCES
   PrimitivesAPI_Box.cpp
   PrimitivesAPI_Cylinder.cpp
+  PrimitivesAPI_Sphere.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 3bea92c00cbcb795e1951d631e9cfb76e18db71a..d708a40cdb3fb03ba69749d71af49bae15240996 100644 (file)
@@ -21,7 +21,9 @@
 // shared pointers
 %shared_ptr(PrimitivesAPI_Box)
 %shared_ptr(PrimitivesAPI_Cylinder)
+%shared_ptr(PrimitivesAPI_Sphere)
 
 // all supported interfaces
 %include "PrimitivesAPI_Box.h"
 %include "PrimitivesAPI_Cylinder.h"
+%include "PrimitivesAPI_Sphere.h"
diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp
new file mode 100644 (file)
index 0000000..eaba588
--- /dev/null
@@ -0,0 +1,83 @@
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
+
+// File:        PrimitivesAPI_Sphere.h
+// Created:     16 Mar 2017
+// Author:      Clarisse Genrault
+
+#include "PrimitivesAPI_Sphere.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+//==================================================================================================
+PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                                      const ModelHighAPI_Selection& theCenterPoint,
+                                                      const ModelHighAPI_Double& theRadius)
+: ModelHighAPI_Interface(theFeature)
+{
+       if (initialize()) {
+         fillAttribute(theCenterPoint, centerPoint());
+         setRadius(theRadius);
+       }
+}
+
+//==================================================================================================
+PrimitivesAPI_Sphere::~PrimitivesAPI_Sphere()
+{
+}
+
+//==================================================================================================
+void PrimitivesAPI_Sphere::setCenterPoint(const ModelHighAPI_Selection& theCenterPoint)
+{
+  fillAttribute(theCenterPoint, centerPoint());
+  execute();
+}
+
+//==================================================================================================
+void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRadius)
+{
+  fillAttribute(theRadius, radius());
+  execute();
+}
+
+//==================================================================================================
+void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  theDumper << aBase << " = model.addSphere(" << aDocName;
+
+  AttributeSelectionPtr anAttrCenterPoint =
+      aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
+  AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID());
+  theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius;
+
+  theDumper << ")" << std::endl;
+}
+
+//==================================================================================================
+SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const ModelHighAPI_Selection& theCenterPoint,
+                    const ModelHighAPI_Double& theRadius)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
+  return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theCenterPoint, theRadius));
+}
+
+//==================================================================================================
+SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const ModelHighAPI_Double& theRadius)
+{
+  ModelHighAPI_Selection aCenterPoint("VERTEX", "PartSet/Origin");
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
+  return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius));
+}
diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.h b/src/PrimitivesAPI/PrimitivesAPI_Sphere.h
new file mode 100644 (file)
index 0000000..0374469
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
+
+// File:        PrimitivesAPI_Sphere.h
+// Created:     16 Mar 2017
+// Author:      Clarisse Genrault
+
+#ifndef PRIMITIVESAPI_SPHERE_H_
+#define PRIMITIVESAPI_SPHERE_H_
+
+#include "PrimitivesAPI.h"
+
+#include <PrimitivesPlugin_Sphere.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Double;
+class ModelHighAPI_Selection;
+
+/// \class PrimitivesAPI_Sphere
+/// \ingroup CPPHighAPI
+/// \brief Interface for primitive Sphere feature.
+class PrimitivesAPI_Sphere: public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values.
+  PRIMITIVESAPI_EXPORT
+  explicit PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  PRIMITIVESAPI_EXPORT
+  explicit PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                const ModelHighAPI_Selection& theCenterPoint,
+                                const ModelHighAPI_Double& theRadius);
+
+  /// Destructor.
+  PRIMITIVESAPI_EXPORT
+  virtual ~PrimitivesAPI_Sphere();
+
+  INTERFACE_2(PrimitivesPlugin_Sphere::ID(),
+             centerPoint, PrimitivesPlugin_Sphere::CENTER_POINT_ID(),
+             ModelAPI_AttributeSelection, /** Center point */,
+             radius, PrimitivesPlugin_Sphere::RADIUS_ID(),
+             ModelAPI_AttributeDouble, /** Radius */)
+
+  /// Set center point
+  PRIMITIVESAPI_EXPORT
+  void setCenterPoint(const ModelHighAPI_Selection& theCenterPoint);
+
+  /// Set radius
+  PRIMITIVESAPI_EXPORT
+  void setRadius(const ModelHighAPI_Double& theRadius);
+
+  /// Dump wrapped feature
+  PRIMITIVESAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on primitive Sphere object
+typedef std::shared_ptr<PrimitivesAPI_Sphere> SpherePtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create primitive Sphere feature.
+PRIMITIVESAPI_EXPORT
+SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const ModelHighAPI_Selection& theCenterPoint,
+                    const ModelHighAPI_Double& theRadius);
+
+/// \ingroup CPPHighAPI
+/// \brief Create primitive Sphere feature.
+PRIMITIVESAPI_EXPORT
+SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const ModelHighAPI_Double& theRadius);
+
+#endif // PRIMITIVESAPI_SPHERE_H_
index 98fc5bf038f2e06b8e44092be534341ffa97a30b..04b3e3716152911dc7afd9ecf100baa9b7b61b8a 100644 (file)
@@ -12,5 +12,6 @@
   #include "PrimitivesAPI.h"
   #include "PrimitivesAPI_Box.h"
   #include "PrimitivesAPI_Cylinder.h"
+  #include "PrimitivesAPI_Sphere.h"
 
 #endif // PRIMITIVESAPI_SWIG_H_
index e8aa0147acde67309a3543252281d6b48914215c..8df0d67db8291933c29821c16aa4e7b920a69cf6 100644 (file)
@@ -9,18 +9,21 @@ SET(PROJECT_HEADERS
     PrimitivesPlugin_Plugin.h
     PrimitivesPlugin_Box.h
     PrimitivesPlugin_Cylinder.h
+    PrimitivesPlugin_Sphere.h
 )
 
 SET(PROJECT_SOURCES
     PrimitivesPlugin_Plugin.cpp
     PrimitivesPlugin_Box.cpp
     PrimitivesPlugin_Cylinder.cpp
+    PrimitivesPlugin_Sphere.cpp
 )
 
 SET(XML_RESOURCES
   plugin-Primitives.xml
   box_widget.xml
   cylinder_widget.xml
+  sphere_widget.xml
 )
 
 INCLUDE_DIRECTORIES(
index b3ef9cbf35386cb2001d694ad4b01b6bfc0d2455..36c77fa8a64cb7e172bbd753b71422baefb32b0c 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <PrimitivesPlugin_Box.h>
 #include <PrimitivesPlugin_Cylinder.h>
+#include <PrimitivesPlugin_Sphere.h>
+
 #include <ModelAPI_Session.h>
 
 #include <string>
@@ -29,6 +31,8 @@ FeaturePtr PrimitivesPlugin_Plugin::createFeature(std::string theFeatureID)
     return FeaturePtr(new PrimitivesPlugin_Box);
   } else if (theFeatureID == PrimitivesPlugin_Cylinder::ID()) {
     return FeaturePtr(new PrimitivesPlugin_Cylinder);
+  } else if (theFeatureID == PrimitivesPlugin_Sphere::ID()) {
+    return FeaturePtr(new PrimitivesPlugin_Sphere);
   }
   // feature of such kind is not found
   return FeaturePtr();
diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp
new file mode 100644 (file)
index 0000000..9e63047
--- /dev/null
@@ -0,0 +1,112 @@
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D
+
+// File:        PrimitivesPlugin_Sphere.h
+// Created:     15 Mar 2017
+// Author:      Clarisse Genrault (CEA)
+
+#include <PrimitivesPlugin_Sphere.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_Session.h>
+
+//=================================================================================================
+PrimitivesPlugin_Sphere::PrimitivesPlugin_Sphere()
+{
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Sphere::initAttributes()
+{
+  data()->addAttribute(PrimitivesPlugin_Sphere::CENTER_POINT_ID(),
+                       ModelAPI_AttributeSelection::typeId());
+
+  data()->addAttribute(PrimitivesPlugin_Sphere::RADIUS_ID(),
+                       ModelAPI_AttributeDouble::typeId());
+
+  // Initialize the center point of the sphere at the origin if the center point is not filled.
+  AttributeSelectionPtr aCenterPoint =
+    data()->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
+  if (!aCenterPoint->isInitialized()) {
+    ObjectPtr aPointObj = ModelAPI_Session::get()->moduleDocument()
+      ->objectByName(ModelAPI_ResultConstruction::group(), "Origin");
+    if (aPointObj.get()) {
+      ResultPtr aPointRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPointObj);
+      aCenterPoint->setValue(aPointRes, std::shared_ptr<GeomAPI_Shape>());
+    }
+  }
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Sphere::execute()
+{
+  // Getting point.
+  std::shared_ptr<GeomAPI_Pnt> aCenterPoint;
+  std::shared_ptr<ModelAPI_AttributeSelection> aPointRef =
+    selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
+  if (aPointRef.get() != NULL) {
+    GeomShapePtr aShape1 = aPointRef->value();
+    if (!aShape1.get()) {
+      aShape1 = aPointRef->context()->shape();
+    }
+    if (aShape1) {
+       aCenterPoint = GeomAlgoAPI_PointBuilder::point(aShape1);
+    }
+  }
+
+  // Getting radius
+  double aRadius = real(PrimitivesPlugin_Sphere::RADIUS_ID())->value();
+
+  std::shared_ptr<GeomAlgoAPI_Sphere> aSphereAlgo =
+    std::shared_ptr<GeomAlgoAPI_Sphere>(new GeomAlgoAPI_Sphere(aCenterPoint, aRadius));
+
+  // These checks should be made to the GUI for the feature but
+  // the corresponding validator does not exist yet.
+  if (!aSphereAlgo->check()) {
+    setError(aSphereAlgo->getError());
+    return;
+  }
+
+  // Build the sphere
+  aSphereAlgo->build();
+
+  // Check if the creation of the cylinder
+  if(!aSphereAlgo->isDone()) {
+    setError(aSphereAlgo->getError());
+    return;
+  }
+  if(!aSphereAlgo->checkValid("Sphere builder")) {
+    setError(aSphereAlgo->getError());
+    return;
+  }
+
+  int aResultIndex = 0;
+  ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
+  loadNamingDS(aSphereAlgo, aResultBox);
+  setResult(aResultBox, aResultIndex);
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Sphere::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Sphere> theSphereAlgo,
+                                           std::shared_ptr<ModelAPI_ResultBody> theResultSphere)
+{
+  // Load the result
+  theResultSphere->store(theSphereAlgo->shape());
+
+  // Prepare the naming
+  theSphereAlgo->prepareNamingFaces();
+
+  // Insert to faces
+  int num = 1;
+  std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces =
+      theSphereAlgo->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;
+    theResultSphere->generated(aFace, (*it).first, num++);
+  }
+}
diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h
new file mode 100644 (file)
index 0000000..08693f3
--- /dev/null
@@ -0,0 +1,67 @@
+// Copyright (C) 2014-201x CEA/DEN, EDF R&D
+
+// File:        PrimitivesPlugin_Sphere.h
+// Created:     15 Mar 2017
+// Author:      Clarisse Genrault (CEA)
+
+#ifndef PRIMITIVESPLUGIN_SPHERE_H_
+#define PRIMITIVESPLUGIN_SPHERE_H_
+
+#include <PrimitivesPlugin.h>
+#include <ModelAPI_Feature.h>
+#include <GeomAlgoAPI_Sphere.h>
+
+/**\class PrimitivesPlugin_Sphere
+ * \ingroup Plugins
+ * \brief Feature for creation of a sphere.
+ *
+ * Creates a sphere from a radius and a center point defaulting to the origin
+ */
+class PrimitivesPlugin_Sphere : public ModelAPI_Feature
+{
+ public:
+  /// Sphere kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_SPHERE_ID("Sphere");
+    return MY_SPHERE_ID;
+  }
+
+  /// Attribute name of the base point
+  inline static const std::string& CENTER_POINT_ID()
+  {
+    static const std::string MY_CENTER_POINT_ID("center_point");
+    return MY_CENTER_POINT_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;
+  }
+
+  /// Returns the kind of a feature
+  PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind()
+  {
+    static std::string MY_KIND = PrimitivesPlugin_Sphere::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_Sphere();
+
+ private:
+  /// Load Naming data structure of the feature to the document
+  void loadNamingDS(std::shared_ptr<GeomAlgoAPI_Sphere> theSphereAlgo,
+                    std::shared_ptr<ModelAPI_ResultBody> theResultSphere);
+
+};
+
+#endif // PRIMITIVESPLUGIN_SPHERE_H_
diff --git a/src/PrimitivesPlugin/icons/sphere.png b/src/PrimitivesPlugin/icons/sphere.png
new file mode 100644 (file)
index 0000000..000d658
Binary files /dev/null and b/src/PrimitivesPlugin/icons/sphere.png differ
index 13e22414ae0bbf3ce18b30b2a5dc29e8741ad7c7..9880e628b6a63bd5c9528fa8b746ba8014b31240 100644 (file)
         <source path="cylinder_widget.xml"/>
       </feature>
     </group>
+    <group id="Primitives">
+      <feature id="Sphere" title="Sphere" tooltip="Create a sphere" icon="icons/Primitives/sphere.png">
+        <source path="sphere_widget.xml"/>
+      </feature>
+    </group>
   </workbench>
 </plugin>
diff --git a/src/PrimitivesPlugin/sphere_widget.xml b/src/PrimitivesPlugin/sphere_widget.xml
new file mode 100644 (file)
index 0000000..664f41a
--- /dev/null
@@ -0,0 +1,17 @@
+<!-- Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
+
+<source>
+  <shape_selector id="center_point"
+                  label="Center point"
+                  icon="icons/Primitives/point.png"
+                  tooltip="Select a center point"
+                  shape_types="vertex">
+  </shape_selector>
+  <doublevalue id="radius"
+               label="Radius"
+               icon="icons/Primitives/radius.png"
+               tooltip="Enter a radius"
+               step="1."
+               default="10.">
+  </doublevalue>
+</source>
\ No newline at end of file
index 49d9adb32d9ef049dae12a859c730bd050130bff..6f0b8e061282152776bf681cf487a37feed05c4f 100644 (file)
@@ -1,4 +1,4 @@
 """Package for Primitives plugin for the Parametric Geometry API of the Modeler.
 """
 
-from PrimitivesAPI import addBox, addCylinder
+from PrimitivesAPI import addBox, addCylinder, addSphere