Salome HOME
Add a new mode for creating a box by a center and dimensions. (TestBox.py)
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Sphere.cpp
index 4b3b594ad59854bcdab790cb0cffc552158f42a8..20e9cbd1c93b43caa81c5c43a6e0323234c29570 100644 (file)
@@ -41,11 +41,34 @@ PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Featur
 : ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
+    fillAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD_BY_PT_RADIUS(), creationMethod());
     fillAttribute(theCenterPoint, centerPoint());
     setRadius(theRadius);
   }
 }
 
+//==================================================================================================
+PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                           const ModelHighAPI_Double& theRMin,
+                                           const ModelHighAPI_Double& theRMax,
+                                           const ModelHighAPI_Double& thePhiMin,
+                                           const ModelHighAPI_Double& thePhiMax,
+                                           const ModelHighAPI_Double& theThetaMin,
+                                           const ModelHighAPI_Double& theThetaMax)
+: ModelHighAPI_Interface(theFeature)
+{
+  if (initialize()) {
+    fillAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
+    fillAttribute(theRMin, rmin());
+    fillAttribute(theRMax, rmax());
+    fillAttribute(thePhiMin, phimin());
+    fillAttribute(thePhiMax, phimax());
+    fillAttribute(theThetaMin, thetamin());
+    fillAttribute(theThetaMax, thetamax());
+    execute();
+  }
+}
+
 //==================================================================================================
 PrimitivesAPI_Sphere::~PrimitivesAPI_Sphere()
 {
@@ -65,6 +88,33 @@ void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRadius)
   execute();
 }
 
+//==================================================================================================
+void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRMin,
+                                     const ModelHighAPI_Double& theRMax)
+{
+  fillAttribute(theRMin, rmin());
+  fillAttribute(theRMax, rmax());
+  execute();
+}
+
+//==================================================================================================
+void PrimitivesAPI_Sphere::setPhi(const ModelHighAPI_Double& thePhiMin,
+                                  const ModelHighAPI_Double& thePhiMax)
+{
+  fillAttribute(thePhiMin, phimin());
+  fillAttribute(thePhiMax, phimax());
+  execute();
+}
+
+//==================================================================================================
+void PrimitivesAPI_Sphere::setTheta(const ModelHighAPI_Double& theThetaMin,
+                                    const ModelHighAPI_Double& theThetaMax)
+{
+  fillAttribute(theThetaMin, thetamin());
+  fillAttribute(theThetaMax, thetamax());
+  execute();
+}
+
 //==================================================================================================
 void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -73,10 +123,24 @@ void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const
 
   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;
+  std::string aCreationMethod = aBase->string(PrimitivesPlugin_Sphere::CREATION_METHOD())->value();
+
+  if(aCreationMethod == PrimitivesPlugin_Sphere::CREATION_METHOD_BY_PT_RADIUS()) {
+    AttributeSelectionPtr anAttrCenterPoint =
+        aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
+    AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID());
+    theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius;
+  } else if(aCreationMethod == PrimitivesPlugin_Sphere::CREATION_METHOD_BY_DIMENSIONS()) {
+    AttributeDoublePtr anAttrRMin = aBase->real(PrimitivesPlugin_Sphere::RMIN_ID());
+    AttributeDoublePtr anAttrRMax = aBase->real(PrimitivesPlugin_Sphere::RMAX_ID());
+    AttributeDoublePtr anAttrPhiMin = aBase->real(PrimitivesPlugin_Sphere::PHIMIN_ID());
+    AttributeDoublePtr anAttrPhiMax = aBase->real(PrimitivesPlugin_Sphere::PHIMAX_ID());
+    AttributeDoublePtr anAttrThetaMin = aBase->real(PrimitivesPlugin_Sphere::THETAMIN_ID());
+    AttributeDoublePtr anAttrThetaMax = aBase->real(PrimitivesPlugin_Sphere::THETAMAX_ID());
+    theDumper << ", " << anAttrRMin << ", " << anAttrRMax;
+    theDumper << ", " << anAttrPhiMin << ", " << anAttrPhiMax;
+    theDumper << ", " << anAttrThetaMin << ", " << anAttrThetaMax;
+  }
 
   theDumper << ")" << std::endl;
 }
@@ -98,3 +162,17 @@ SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
   return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius));
 }
+
+//==================================================================================================
+SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
+                    const ModelHighAPI_Double& theRMin,
+                    const ModelHighAPI_Double& theRMax,
+                    const ModelHighAPI_Double& thePhiMin,
+                    const ModelHighAPI_Double& thePhiMax,
+                    const ModelHighAPI_Double& theThetaMin,
+                    const ModelHighAPI_Double& theThetaMax)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID());
+  return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theRMin, theRMax, thePhiMin, thePhiMax,
+                                            theThetaMin, theThetaMax));
+}