Salome HOME
Merge branch 'V9_11_BR'
[modules/shaper.git] / src / PrimitivesAPI / PrimitivesAPI_Sphere.cpp
index ab6c68954562eac8a92d7483c85ad459c6291076..7143444de124decda845e21f1ec08c9e324eae4f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2017-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -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_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;
+  } else { // CREATION_METHOD_BY_PT_RADIUS by default to support versions with undefined method
+    AttributeSelectionPtr anAttrCenterPoint =
+        aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID());
+    AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID());
+    theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius;
+  }
 
   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));
+}