return runAlgoAndCheckShape(aSphereAlgo, aMsg);
}
+ //===============================================================================================
+ std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTorus(
std::shared_ptr<GeomAPI_Pnt> theBasePoint,
static std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> 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
/// \param theRadius The radius of the sphere
GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere(std::shared_ptr<GeomAPI_Pnt> 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();
/// Builds the sphere.
GEOMALGOAPI_EXPORT void build();
+ /// Builds the sphere.
+ GEOMALGOAPI_EXPORT void buildRootSphere();
+
private:
+ bool isRootGeo;
std::shared_ptr<GeomAPI_Pnt> myCenterPoint; /// Center of the sphere.
double myRadius;
+ double myRMin, myRMax;
+ double myPhiMin, myPhiMax;
+ double myThetaMin, myThetaMax;
};
#endif // GEOMALGOAPI_SPHERE_H_
: 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()
{
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
{
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;
}
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));
+}
\ No newline at end of file
const ModelHighAPI_Selection& theCenterPoint,
const ModelHighAPI_Double& theRadius);
+ /// Constructor with values.
+ PRIMITIVESAPI_EXPORT
+ explicit 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);
+
/// 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
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;
SpherePtr addSphere(const std::shared_ptr<ModelAPI_Document>& thePart,
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& 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_
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_Session.h>
//=================================================================================================
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());
aCenterPoint->setValue(aPointRes, std::shared_ptr<GeomAPI_Shape>());
}
}
+
+ // 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<GeomAPI_Pnt> aCenterPoint;
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<GeomAlgoAPI_Sphere> aSphereAlgo = std::shared_ptr<GeomAlgoAPI_Sphere>(
+ 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<GeomAlgoAPI_Sphere> theSphereAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultSphere)
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()
{
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()
/// Load Naming data structure of the feature to the document
void loadNamingDS(std::shared_ptr<GeomAlgoAPI_Sphere> theSphereAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultSphere);
+
+ ///
+ void createSphereByPtRadius();
+
+ ///
+ void createShereByDimensions();
};
<source>
- <shape_selector id="center_point"
+ <toolbox id="CreationMethod">
+ <box id="SphereByPointRadius" title="By point and radius" icon="">
+ <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"
+ </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
+ </doublevalue>
+ </box>
+ <box id="SphereByDimensions" title="By dimensions" icon="">
+ <groupbox title="Dimensions">
+ <doublevalue
+ id="rmin"
+ label="Rmin"
+ step="1."
+ default="0."
+ tooltip="Enter the inner radius">
+ </doublevalue>
+ <doublevalue
+ id="rmax"
+ label="Rmax"
+ step="1."
+ default="10."
+ tooltip="Enter the outer radius">
+ </doublevalue>
+ </groupbox>
+ <label title=""/>
+ <groupbox title="Phi/theta range">
+ <doublevalue
+ id="phimin"
+ label="Phi min"
+ step="1."
+ default="0."
+ tooltip="Enter the azimuthal starting angle">
+ </doublevalue>
+ <doublevalue
+ id="phimax"
+ label="Phi max"
+ step="1."
+ default="360."
+ max="360.0"
+ tooltip="Enter the azimuthal revolution angle">
+ </doublevalue>
+ <doublevalue
+ id="thetamin"
+ label="Theta min"
+ step="1."
+ default="0."
+ max="180.0"
+ tooltip="Enter the polar starting angle">
+ </doublevalue>
+ <doublevalue
+ id="thetamax"
+ label="Theta max"
+ step="1."
+ default="180."
+ max="180.0"
+ tooltip="Enter the polar revolution angle">
+ </doublevalue>
+ </groupbox>
+ </box>
+ </toolbox>
+</source>