From d1f0136136280f79c981e19feccfeb633039ba25 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Mon, 20 Apr 2020 11:30:11 +0200 Subject: [PATCH] Add the new mode to create a root sphere --- src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp | 13 +++ src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h | 12 +++ src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h | 17 ++++ src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp | 86 ++++++++++++++++++- src/PrimitivesAPI/PrimitivesAPI_Sphere.h | 51 ++++++++++- .../PrimitivesPlugin_Sphere.cpp | 67 +++++++++++++++ .../PrimitivesPlugin_Sphere.h | 69 +++++++++++++++ src/PrimitivesPlugin/sphere_widget.xml | 66 ++++++++++++-- 8 files changed, 370 insertions(+), 11 deletions(-) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index 6536032ce..371ed859b 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -199,6 +199,19 @@ namespace GeomAlgoAPI_ShapeAPI return runAlgoAndCheckShape(aSphereAlgo, aMsg); } + //=============================================================================================== + std::shared_ptr GeomAlgoAPI_ShapeAPI::makeSphere( + double theRMin, double theRMax, + double thePhiMin, double thePhiMax, + double theThetaMin, double theThetaMax) + throw (GeomAlgoAPI_Exception) + { + static const std::string aMsg("Sphere builder"); + GeomAlgoAPI_Sphere aSphereAlgo(theRMin, theRMax, thePhiMin, thePhiMax, + theThetaMin, theThetaMax); + return runAlgoAndCheckShape(aSphereAlgo, aMsg); + } + //=============================================================================================== std::shared_ptr GeomAlgoAPI_ShapeAPI::makeTorus( std::shared_ptr theBasePoint, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h index c34d077a3..be075b47d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h @@ -108,6 +108,18 @@ public: static std::shared_ptr makeSphere(double theRadius) throw (GeomAlgoAPI_Exception); + /// Creates a sphere using radius, phi angles and theta angles. + /// \param theRMin The inner radius of the sphere + /// \param theRMax The outer radius of the sphere + /// \param thePhiMin The lower phi limit + /// \param thePhiMax The higher phi limit + /// \param theThetaMin The lower theta limit + /// \param theThetaMax The higher theta limit + static std::shared_ptr makeSphere(double theRMin, double theRMax, + double thePhiMin, double thePhiMax, + double theThetaMin, double theThetaMax) + throw (GeomAlgoAPI_Exception); + /// Creates a torus using a base point, an axis, a radius and a ring radius. /// \param theBasePoint The center of the torus /// \param theEdge The axis of the torus diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h index fe3b3d4e5..20e129695 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h @@ -40,6 +40,16 @@ class GeomAlgoAPI_Sphere : public GeomAlgoAPI_MakeShape /// \param theRadius The radius of the sphere GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere(std::shared_ptr theCenterPoint, const double theRadius); + /// Creates a sphere. + /// \param theRMin The inner radius of the sphere + /// \param theRMax The outer radius of the sphere + /// \param thePhiMin The lower phi limit + /// \param thePhiMax The higher phi limit + /// \param theThetaMin The lower theta limit + /// \param theThetaMax The higher theta limit + GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere(const double theRMin, const double theRMax, + const double thePhiMin, const double thePhiMax, + const double theThetaMin, const double theThetaMax); /// Checks if data for the sphere construction is OK. GEOMALGOAPI_EXPORT bool check(); @@ -47,9 +57,16 @@ class GeomAlgoAPI_Sphere : public GeomAlgoAPI_MakeShape /// Builds the sphere. GEOMALGOAPI_EXPORT void build(); + /// Builds the sphere. + GEOMALGOAPI_EXPORT void buildRootSphere(); + private: + bool isRootGeo; std::shared_ptr myCenterPoint; /// Center of the sphere. double myRadius; + double myRMin, myRMax; + double myPhiMin, myPhiMax; + double myThetaMin, myThetaMax; }; #endif // GEOMALGOAPI_SPHERE_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp index 13a8b1916..0989fef02 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp +++ b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp @@ -41,11 +41,34 @@ PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr& 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& thePart, std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID()); return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius)); } + +//================================================================================================== +SpherePtr addSphere(const std::shared_ptr& 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 aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID()); + return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theRMin, theRMax, thePhiMin, thePhiMax, + theThetaMin, theThetaMax)); +} \ No newline at end of file diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.h b/src/PrimitivesAPI/PrimitivesAPI_Sphere.h index 57197dfa3..c3d007c2c 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Sphere.h +++ b/src/PrimitivesAPI/PrimitivesAPI_Sphere.h @@ -50,15 +50,39 @@ public: const ModelHighAPI_Selection& theCenterPoint, const ModelHighAPI_Double& theRadius); + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Sphere(const std::shared_ptr& 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); + /// Destructor. PRIMITIVESAPI_EXPORT virtual ~PrimitivesAPI_Sphere(); - INTERFACE_2(PrimitivesPlugin_Sphere::ID(), + INTERFACE_9(PrimitivesPlugin_Sphere::ID(), + creationMethod, PrimitivesPlugin_Sphere::CREATION_METHOD(), + ModelAPI_AttributeString, /** Creation method */, centerPoint, PrimitivesPlugin_Sphere::CENTER_POINT_ID(), ModelAPI_AttributeSelection, /** Center point */, radius, PrimitivesPlugin_Sphere::RADIUS_ID(), - ModelAPI_AttributeDouble, /** Radius */) + ModelAPI_AttributeDouble, /** Radius */, + rmin, PrimitivesPlugin_Sphere::RMIN_ID(), + ModelAPI_AttributeDouble, /** The minimum radius*/, + rmax, PrimitivesPlugin_Sphere::RMAX_ID(), + ModelAPI_AttributeDouble, /** The maximum radius*/, + phimin, PrimitivesPlugin_Sphere::PHIMIN_ID(), + ModelAPI_AttributeDouble, /** The minimum phi*/, + phimax, PrimitivesPlugin_Sphere::PHIMAX_ID(), + ModelAPI_AttributeDouble, /** The maximum phi*/, + thetamin, PrimitivesPlugin_Sphere::THETAMIN_ID(), + ModelAPI_AttributeDouble, /** The minimum theta*/, + thetamax,PrimitivesPlugin_Sphere::THETAMAX_ID(), + ModelAPI_AttributeDouble, /** The maximum theta*/) /// Set center point PRIMITIVESAPI_EXPORT @@ -68,6 +92,18 @@ public: PRIMITIVESAPI_EXPORT void setRadius(const ModelHighAPI_Double& theRadius); + /// Set minimum radius and maximum radius + PRIMITIVESAPI_EXPORT + void setRadius(const ModelHighAPI_Double& theRMin, const ModelHighAPI_Double& theRMax); + + /// Set minimum phi and maximum phi + PRIMITIVESAPI_EXPORT + void setPhi(const ModelHighAPI_Double& thePhiMin, const ModelHighAPI_Double& thePhiMax); + + /// Set minimum theta and maximum theta + PRIMITIVESAPI_EXPORT + void setTheta(const ModelHighAPI_Double& theThetaMin, const ModelHighAPI_Double& theThetaMax); + /// Dump wrapped feature PRIMITIVESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -89,4 +125,15 @@ PRIMITIVESAPI_EXPORT SpherePtr addSphere(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius); +/// \ingroup CPPHighAPI +/// \brief Create primitive Sphere feature. +PRIMITIVESAPI_EXPORT +SpherePtr addSphere(const std::shared_ptr& 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); + #endif // PRIMITIVESAPI_SPHERE_H_ diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp index c9c43d750..f80c7f3af 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,9 @@ PrimitivesPlugin_Sphere::PrimitivesPlugin_Sphere() //================================================================================================= void PrimitivesPlugin_Sphere::initAttributes() { + data()->addAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD(), ModelAPI_AttributeString::typeId()); + + // data for the first mode : by a point and a radius data()->addAttribute(PrimitivesPlugin_Sphere::CENTER_POINT_ID(), ModelAPI_AttributeSelection::typeId()); @@ -60,10 +64,31 @@ void PrimitivesPlugin_Sphere::initAttributes() aCenterPoint->setValue(aPointRes, std::shared_ptr()); } } + + // data for the second mode : by dimensions + data()->addAttribute(PrimitivesPlugin_Sphere::RMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::RMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::PHIMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::PHIMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::THETAMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::THETAMAX_ID(), ModelAPI_AttributeDouble::typeId()); } //================================================================================================= void PrimitivesPlugin_Sphere::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Sphere::CREATION_METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + + if (aMethodType == CREATION_METHOD_BY_PT_RADIUS()) + createSphereByPtRadius(); + + if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) + createShereByDimensions(); +} + +//================================================================================================= +void PrimitivesPlugin_Sphere::createSphereByPtRadius() { // Getting point. std::shared_ptr aCenterPoint; @@ -111,6 +136,48 @@ void PrimitivesPlugin_Sphere::execute() setResult(aResultBox, aResultIndex); } +//================================================================================================= +void PrimitivesPlugin_Sphere::createShereByDimensions() +{ + // Getting rmin, rmax, phimin, phimax, thetamin et thetamax + double aRMin = real(PrimitivesPlugin_Sphere::RMIN_ID())->value(); + double aRMax = real(PrimitivesPlugin_Sphere::RMAX_ID())->value(); + double aPhiMin = real(PrimitivesPlugin_Sphere::PHIMIN_ID())->value(); + double aPhiMax = real(PrimitivesPlugin_Sphere::PHIMAX_ID())->value(); + double aThetaMin = real(PrimitivesPlugin_Sphere::THETAMIN_ID())->value(); + double aThetaMax = real(PrimitivesPlugin_Sphere::THETAMAX_ID())->value(); + + std::shared_ptr aSphereAlgo = std::shared_ptr( + new GeomAlgoAPI_Sphere(aRMin, aRMax, aPhiMin, aPhiMax, aThetaMin, aThetaMax)); + + // 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 box + aSphereAlgo->build(); + + // Check if the creation of the box + if(!aSphereAlgo->isDone()) { + // The error is not displayed in a popup window. It must be in the message console. + setError(aSphereAlgo->getError()); + return; + } + if(!aSphereAlgo->checkValid("Root Sphere Builder")) { + // The error is not displayed in a popup window. It must be in the message console. + 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 theSphereAlgo, std::shared_ptr theResultSphere) diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h index 01d48dcc6..ce0e025a8 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h @@ -44,6 +44,27 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature return MY_SPHERE_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_BY_PT_RADIUS() + { + static const std::string MY_CREATION_METHOD_ID("SphereByPointRadius"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method + inline static const std::string& CREATION_METHOD_BY_DIMENSIONS() + { + static const std::string MY_CREATION_METHOD_ID("SphereByDimensions"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name of the base point inline static const std::string& CENTER_POINT_ID() { @@ -57,6 +78,48 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature static const std::string MY_RADIUS_ID("radius"); return MY_RADIUS_ID; } + + /// attribute name of the inner radius + inline static const std::string& RMIN_ID() + { + static const std::string MY_RMIN_ID("rmin"); + return MY_RMIN_ID; + } + + /// attribute name of the outer radius + inline static const std::string& RMAX_ID() + { + static const std::string MY_RMAX_ID("rmax"); + return MY_RMAX_ID; + } + + /// attribute name of the lower phi limit + inline static const std::string& PHIMIN_ID() + { + static const std::string MY_PHIMIN_ID("phimin"); + return MY_PHIMIN_ID; + } + + /// attribute name of the higher phi limit + inline static const std::string& PHIMAX_ID() + { + static const std::string MY_PHIMAX_ID("phimax"); + return MY_PHIMAX_ID; + } + + /// attribute name of the lower theta limit + inline static const std::string& THETAMIN_ID() + { + static const std::string MY_THETAMIN_ID("thetamin"); + return MY_THETAMIN_ID; + } + + /// attribute name of the higher theta limit + inline static const std::string& THETAMAX_ID() + { + static const std::string MY_THETAMAX_ID("thetamax"); + return MY_THETAMAX_ID; + } /// Returns the kind of a feature PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind() @@ -78,6 +141,12 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature /// Load Naming data structure of the feature to the document void loadNamingDS(std::shared_ptr theSphereAlgo, std::shared_ptr theResultSphere); + + /// + void createSphereByPtRadius(); + + /// + void createShereByDimensions(); }; diff --git a/src/PrimitivesPlugin/sphere_widget.xml b/src/PrimitivesPlugin/sphere_widget.xml index d2f29ce1e..ade9f70f7 100644 --- a/src/PrimitivesPlugin/sphere_widget.xml +++ b/src/PrimitivesPlugin/sphere_widget.xml @@ -1,15 +1,71 @@ - + + - - + - - \ No newline at end of file + + + + + + + + + + + + -- 2.39.2