//=================================================================================================
void GeomAlgoAPI_Box::buildWithPointAndDims()
{
- // Construct points from cordinates and dimensions to use the method with two points
+ // Construct points from cordinates and dimensions to use the method with two points
myFirstPoint =
std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(myOx - myDx, myOy - myDy, myOz - myDz));
mySecondPoint =
std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(myOx + myDx, myOy + myDy, myOz + myDz));
-
+
buildWithPoints();
}
/// \param theSecondPoint The other extremity of the diagonal
GEOMALGOAPI_EXPORT GeomAlgoAPI_Box(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
std::shared_ptr<GeomAPI_Pnt> theSecondPoint);
-
+
/// Creates a box using coordinates of a point (the center of gravity) andthe dimensions.
/// \param theOx The X coordinate of the point
/// \param theOy The Y coordinate of the point
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File: GeomAlgoAPI_Sphere.h
+// File: GeomAlgoAPI_Sphere.cpp
// Created: 16 Mar 2017
// Author: Clarisse Genrault (CEA)
#include <GeomAlgoAPI_Sphere.h>
+#include <gp_Circ.hxx>
+
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakeWire.hxx>
+
+#include <BRepPrimAPI_MakeRevol.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
//=================================================================================================
GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere(std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
const double theRadius)
{
+ isSectionSphere = false;
myCenterPoint = theCenterPoint;
myRadius = theRadius;
}
+//=================================================================================================
+GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere(const double theRMin, const double theRMax,
+ const double thePhiMin, const double thePhiMax,
+ const double theThetaMin, const double theThetaMax)
+{
+ isSectionSphere = true;
+ myRMin = theRMin;
+ myRMax = theRMax;
+ myPhiMin = thePhiMin;
+ myPhiMax = thePhiMax;
+ myThetaMin = theThetaMin;
+ myThetaMax = theThetaMax;
+}
+
//=================================================================================================
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;
+ if (isSectionSphere) {
+ if ((myRMin-myRMax) > Precision::Confusion()) {
+ myError = "Sphere builder :: RMin is larger than RMax.";
+ return false;
+ }
+ } else {
+ 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();
+
+ if (isSectionSphere) {
+ buildSectionSphere();
+ } else {
+ buildSphere();
+ }
+}
+//=================================================================================================
+void GeomAlgoAPI_Sphere::buildSphere()
+{
const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
// Construct the sphere
setDone(true);
}
+
+//=================================================================================================
+void GeomAlgoAPI_Sphere::buildSectionSphere()
+{
+ myCreatedFaces.clear();
+
+ const double aStartPhiRad = myPhiMin * M_PI / 180.;
+ BRepBuilderAPI_MakeWire aWireBuilder;
+
+ gp_Pnt anOrigin(0., 0., 0.);
+ gp_Dir aNormal(-sin(aStartPhiRad), cos(aStartPhiRad), 0.);
+
+ //The section is defined by 4 points and up to 4 wires. In the rmin = 0 case, two of the points will actually be the origin
+ double aX = myRMax*sin(myThetaMin * M_PI/180.);
+ double aZ = myRMax*cos(myThetaMin * M_PI/180.);
+ gp_Pnt aTopOuterStart(aX*cos(aStartPhiRad), aX*sin(aStartPhiRad), aZ);
+
+ aX = myRMax*sin((myThetaMin+myThetaMax) * M_PI/180.);
+ aZ = myRMax*cos((myThetaMin+myThetaMax) * M_PI/180.);
+ gp_Pnt aBaseOuterEnd(aX*cos(aStartPhiRad), aX*sin(aStartPhiRad), aZ);
+
+ aX = myRMin*sin(myThetaMin * M_PI/180.);
+ aZ = myRMin*cos(myThetaMin * M_PI/180.);
+ gp_Pnt aTopInnerStart(aX*cos(aStartPhiRad), aX*sin(aStartPhiRad), aZ);
+
+ aX = myRMin*sin((myThetaMin+myThetaMax) * M_PI/180.);
+ aZ = myRMin*cos((myThetaMin+myThetaMax) * M_PI/180.);
+ gp_Pnt aBaseInnerEnd(aX*cos(aStartPhiRad), aX*sin(aStartPhiRad), aZ);
+
+ // There will always be the rmax arc since rmax can't be zero
+ gp_Circ anOuterCircle(gp_Ax2(anOrigin, aNormal), myRMax);
+ BRepBuilderAPI_MakeEdge anArcOuterBuilder;
+ if (aTopOuterStart.IsEqual(aBaseOuterEnd, Precision::Confusion()))
+ anArcOuterBuilder = BRepBuilderAPI_MakeEdge(anOuterCircle);
+ else
+ anArcOuterBuilder = BRepBuilderAPI_MakeEdge(anOuterCircle, aTopOuterStart, aBaseOuterEnd);
+ anArcOuterBuilder.Build();
+
+ //Two cases : either we need four edges (one being an arc with curvature radius rmin) or we need three (if rmin=0).
+ // In the later case the top and bottom edges intersect at the origin
+ // Add the edges to the wire in consecutive order (very important for the face to make sense topologically)
+ if(myRMin >= Precision::Confusion()){
+ gp_Circ anInnerCircle(gp_Ax2(anOrigin, aNormal), myRMin);
+ BRepBuilderAPI_MakeEdge anArcInnerBuilder;
+ if (aTopInnerStart.IsEqual(aBaseInnerEnd, Precision::Confusion()))
+ anArcInnerBuilder = BRepBuilderAPI_MakeEdge(anInnerCircle);
+ else
+ anArcInnerBuilder = BRepBuilderAPI_MakeEdge(anInnerCircle, aTopInnerStart, aBaseInnerEnd);
+ anArcInnerBuilder.Build();
+
+ BRepBuilderAPI_MakeEdge anEdgeStartBuilder(aTopInnerStart, aTopOuterStart);
+ anEdgeStartBuilder.Build();
+ BRepBuilderAPI_MakeEdge anEdgeEndBuilder(aBaseInnerEnd, aBaseOuterEnd);
+ anEdgeEndBuilder.Build();
+
+ aWireBuilder.Add(anEdgeStartBuilder.Edge());
+ aWireBuilder.Add(anArcOuterBuilder.Edge());
+ aWireBuilder.Add(anEdgeEndBuilder.Edge());
+ aWireBuilder.Add(anArcInnerBuilder.Edge());
+ } else {
+ BRepBuilderAPI_MakeEdge anEdgeStartBuilder(anOrigin, aTopOuterStart);
+ anEdgeStartBuilder.Build();
+ BRepBuilderAPI_MakeEdge anEdgeEndBuilder(anOrigin, aBaseOuterEnd);
+ anEdgeEndBuilder.Build();
+
+ aWireBuilder.Add(anArcOuterBuilder.Edge());
+ aWireBuilder.Add(anEdgeStartBuilder.Edge());
+ aWireBuilder.Add(anEdgeEndBuilder.Edge());
+ }
+
+ // Make a face from the wire
+ aWireBuilder.Build();
+ BRepBuilderAPI_MakeFace aFaceBuilder(aWireBuilder.Wire());
+ aFaceBuilder.Build();
+
+ if (!aFaceBuilder.IsDone()){
+ myError = "Sphere builder :: section is not valid";
+ return;
+ }
+
+ // Mathematical tool objects needed by the revolution builder
+ gp_Dir aZDir(0., 0., 1.);
+ gp_Ax1 aZAxis(anOrigin, aZDir);
+
+ // Build the solid using the section face we've created and a revolution builder
+ BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aFaceBuilder.Face(), aZAxis, myPhiMax * M_PI / 180., Standard_True);
+ if(!aRevolBuilder) {
+ return;
+ myError = "Sphere builder :: section revolution did not succeed";
+ }
+ if(!aRevolBuilder->IsDone()) {
+ myError = "Sphere builder :: section revolution did not succeed";
+ return;
+ }
+
+ // Get the shape, verify it, build a GeomAPI_Shape.
+ std::shared_ptr<GeomAPI_Shape> aResultShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape()) ;
+ aResultShape->setImpl(new TopoDS_Shape(aRevolBuilder->Shape()));
+ setShape(aResultShape);
+
+ // Test on the shapes
+ if (!(aResultShape).get() || aResultShape->isNull()) {
+ myError = "Sphere builder :: resulting shape is null.";
+ return;
+ }
+
+ setImpl(aRevolBuilder);
+ setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
+
+ setDone(true);
+}
/// \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 buildSphere();
+
+ /// Builds the section of sphere.
+ GEOMALGOAPI_EXPORT void buildSectionSphere();
+
private:
- std::shared_ptr<GeomAPI_Pnt> myCenterPoint; /// Center of the sphere.
- double myRadius;
+ bool isSectionSphere; // Boolean to define if the second mode is used.
+ std::shared_ptr<GeomAPI_Pnt> myCenterPoint; /// Center of the sphere for the first mode.
+ double myRadius; /// Radius of the sphere for the first mode.
+ double myRMin, myRMax; /// Inner and outer radius for the second mode.
+ double myPhiMin, myPhiMax; /// Lower and higher phi limit for the second mode.
+ double myThetaMin, myThetaMax; /// Lower and higher theta limit for the second mode.
};
#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));
+}
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 and maximum radius
+ PRIMITIVESAPI_EXPORT
+ void setRadius(const ModelHighAPI_Double& theRMin, const ModelHighAPI_Double& theRMax);
+
+ /// Set minimum and maximum phi
+ PRIMITIVESAPI_EXPORT
+ void setPhi(const ModelHighAPI_Double& thePhiMin, const ModelHighAPI_Double& thePhiMax);
+
+ /// Set minimum 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_
if (aMethodType == CREATION_METHOD_BY_TWO_POINTS())
createBoxByTwoPoints();
-
+
if (aMethodType == CREATION_METHOD_BY_ONE_POINT_AND_DIMS())
createBoxByOnePointAndDims();
}
double aDx = real(PrimitivesPlugin_Box::HALF_DX_ID())->value();
double aDy = real(PrimitivesPlugin_Box::HALF_DY_ID())->value();
double aDz = real(PrimitivesPlugin_Box::HALF_DZ_ID())->value();
-
+
// Getting point coordinates
double x = real(PrimitivesPlugin_Box::OX_ID())->value();
double y = real(PrimitivesPlugin_Box::OY_ID())->value();
std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo;
aBoxAlgo = std::shared_ptr<GeomAlgoAPI_Box>(new GeomAlgoAPI_Box(x,y,z,aDx,aDy,aDz));
-
+
// These checks should be made to the GUI for the feature but
// the corresponding validator does not exist yet.
if (!aBoxAlgo->check()) {
* \ingroup Plugins
* \brief Feature for creation of a box primitive using various methods.
*
- * Box creates a cuboid - Parallelepiped with 6 rectangular faces. It can be built via two
+ * Box creates a cuboid - Parallelepiped with 6 rectangular faces. It can be built via three
* methods : using two points that define a diagonal, a point that define a center and 3 lengths
* that define the half-lengths on X, Y and Z-axes, or using 3 lengths that define the
* rectangular dimensions.
static const std::string MY_DZ_ID("dz");
return MY_DZ_ID;
}
-
+
/// Attribute name of the first coordinate of the center
inline static const std::string& OX_ID()
{
static const std::string MY_OZ_ID("oz");
return MY_OZ_ID;
}
-
+
/// Attribute name of the half-length on X axis
inline static const std::string& HALF_DX_ID()
{
///Perform the creation of the box using three cordinates
void createBoxByDimensions();
- ///Perform the creation of the box using a center and three half-lenths
+ ///Perform the creation of the box using a center and three half-lenths
void createBoxByOnePointAndDims();
};
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-// File: PrimitivesPlugin_Sphere.h
+// File: PrimitivesPlugin_Sphere.cpp
// Created: 15 Mar 2017
// Author: Clarisse Genrault (CEA)
#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;
// Build the sphere
aSphereAlgo->build();
- // Check if the creation of the cylinder
+ // Check if the creation of the sphere is OK
if(!aSphereAlgo->isDone()) {
setError(aSphereAlgo->getError());
return;
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 sphere
+ aSphereAlgo->build();
+
+ // Check if the creation of the sphere is OK
+ 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("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)
/**\class PrimitivesPlugin_Sphere
* \ingroup Plugins
- * \brief Feature for creation of a sphere.
+ * \brief Feature for creation of a sphere primitive using various methods.
*
- * Creates a sphere from a radius and a center point defaulting to the origin
+ * It can be built via two methods : using a radius and a center point defaulting to the origin,
+ * or radii (inner and outer) and angle limits (theta and phi).
*/
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()
{
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);
+
+ /// Perform the creation of the sphere using a point and a radius
+ void createSphereByPtRadius();
+
+ /// Perform the creation of the sphere using radii (inner and outer) and angle limits (theta and phi)
+ void createShereByDimensions();
};
.. _tui_create_sphere:
-Create / Sphere
-===============
+Create sphere
+=============
-.. literalinclude:: examples/sphere.py
+.. literalinclude:: examples/sphere1.py
:linenos:
:language: python
-:download:`Download this script <examples/sphere.py>`
-
+:download:`Download this script <examples/sphere1.py>`
--- /dev/null
+
+ .. _tui_create_part_sphere:
+
+Create part ofsphere
+====================
+
+.. literalinclude:: examples/sphere2.py
+ :linenos:
+ :language: python
+
+:download:`Download this script <examples/sphere2.py>`
-.. _box_feature:
+.. |Box_button.icon| image:: images/Box_button.png
Box
===
-.. |box.icon| image:: images/box.png
-
Box feature creates a box solid.
To create a Box in the active part:
#. select in the Main Menu *Primitives - > Box* item or
-#. click |box.icon| **Box** button in the toolbar:
+#. click |Box_button.icon| **Box** button in the toolbar:
There are 3 algorithms for creation of a Box:
+++ /dev/null
-from salome.shaper import model
-
-model.begin()
-partSet = model.moduleDocument()
-Part_1 = model.addPart(partSet)
-Part_1_doc = Part_1.document()
-Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10)
-model.do()
-model.end()
--- /dev/null
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10)
+model.do()
+model.end()
--- /dev/null
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sphere_1 = model.addSphere(Part_1_doc,5,10,180,245,0,90)
+model.do()
+model.end()
Sphere
======
-Sphere feature creates a sphere solid.
+Sphere feature creates a sphere solid or a part of a sphere solid.
To create a Sphere in the active part:
#. select in the Main Menu *Primitives - > Sphere* item or
#. click |Sphere_button.icon| **Sphere** button in the toolbar
-The following property panel appears.
+There are 2 algorithms for creation of a Sphere
-.. figure:: images/Sphere.png
+.. figure:: images/sphere_32x32.png
+ :align: left
+ :height: 24px
+
+**By a center and a radius**
+
+.. figure:: images/sphere_part_32x32.png
+ :align: left
+ :height: 24px
+
+**By radii (inner and outer) and angle limits (theta and phi)**
+
+--------------------------------------------------------------------------------
+
+By a center and a radius
+------------------------
+
+Sphere is created by a center (origin by default) and a radius.
+
+.. figure:: images/Sphere_full.png
:align: center
- Sphere property panel
-
Input fields:
- **Point** defines the center of the sphere selected in 3D OCC viewer or object browser;
- **Radius** defines the radius.
-
+
**TUI Command**:
.. py:function:: model.addSphere(Part_doc, Point, Radius)
-
+
:param part: The current part object.
:param object: Vertex.
:param real: Radius.
Result
""""""
-An example is shown below.
+A solid sphere based on the origin and a radius.
-.. figure:: images/Sphere_res.png
+.. figure:: images/Sphere1.png
:align: center
-
- Sphere created
-**See Also** a sample TUI Script of :ref:`tui_create_sphere` operation.
+**See Also** a sample TUI Script of a :ref:`tui_create_sphere` operation.
+
+By radii (inner and outer) and angle limits (theta and phi)
+-----------------------------------------------------------
+
+Part of sphere is created by radii (inner and outer) and angle limits (phi and theta).
+
+.. figure:: images/Sphere_part.png
+ :align: center
+
+Input fields:
+
+- **RMin** defines the inner radius;
+- **RMax** defines the outer radius;
+- **PhiMin** defines the lower phi limit;
+- **PhiMax** defines the higher phi limit;
+- **ThetaMin** defines the lower theta limit;
+- **ThetaMax** defines the higher theta limit.
+
+**TUI Command**:
+
+.. py:function:: model.addSphere(Part_doc, RMin, RMax, PhiMin, PhiMax, ThetaMin, ThetaMax)
+
+ :param part: The current part object.
+ :param real: Inner radius.
+ :param real: Outer radius.
+ :param real: Lower phi.
+ :param real: Hiher phi.
+ :param real: Lower theta.
+ :param real: Hiher theta.
+ :return: Result object.
+
+Result
+""""""
+
+A solid sphere based on the origin with radii (inner and outer) and angles (phi and theta).
+
+.. figure:: images/Sphere2.png
+ :align: center
+
+**See Also** a sample TUI Script of a :ref:`tui_create_part_sphere` operation.
+
+
+
<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
+ <toolbox id="CreationMethod">
+ <box id="SphereByPointRadius" title="By point and radius" icon="icons/Primitives/sphere_32x32.png">
+ <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>
+ </box>
+ <box id="SphereByDimensions" title="By dimensions" icon="icons/Primitives/sphere_part_32x32.png">
+ <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>
try :
Box_9 = shaperpy.makeBox(pnt1,pnt1)
except myExcept as ec:
- assert(ec.what() == "Box builder with points :: the distance between the two points is null.")
+ assert(ec.what() == "Box builder with two points :: the distance between the two points is null.")
try :
pnt3 = pnt(0.,50.,50.)
Box_10 = shaperpy.makeBox(pnt1,pnt3)
except myExcept as ec:
- assert(ec.what() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
+ assert(ec.what() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
try :
pnt4 = pnt(50.,0.,50.)
Box_11 = shaperpy.makeBox(pnt1,pnt4)
except myExcept as ec:
- assert(ec.what() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
+ assert(ec.what() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
try :
pnt5 = pnt(50.,50.,0.)
Box_12 = shaperpy.makeBox(pnt1,pnt5)
except myExcept as ec:
- assert(ec.what() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
+ assert(ec.what() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
try :
Box_13 = shaperpy.makeBox(None, pnt2)
except myExcept as ec:
- assert(ec.what() == "Box builder with points :: the first point is not valid.")
+ assert(ec.what() == "Box builder with two points :: the first point is not valid.")
try :
Box_14 = shaperpy.makeBox(pnt2, None)
except myExcept as ec:
- assert(ec.what() == "Box builder with points :: the second point is not valid.")
\ No newline at end of file
+ assert(ec.what() == "Box builder with two points :: the second point is not valid.")
Box_16 = model.addBox(Part_1_doc, model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"), model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_2_1/To_Face]"))
Box_17 = model.addBox(Part_1_doc, model.selection("VERTEX", "Vertex_1_1"), model.selection("VERTEX", "Vertex_2_1"))
Box_18 = model.addBox(Part_1_doc, "dx", "dy", "dz")
+Box_19 = model.addBox(Part_1_doc, 0, 0, 0, 20, 20 ,20)
model.do()
model.end()
model.testNbSubShapes(Box_18, GeomAPI_Shape.FACE, [6])
model.testHaveNamingFaces(Box_18, model, Part_1_doc)
+model.testNbResults(Box_19, 1)
+model.testNbSubResults(Box_19, [0])
+model.testNbSubShapes(Box_19, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(Box_19, GeomAPI_Shape.FACE, [6])
+model.testHaveNamingFaces(Box_19, model, Part_1_doc)
+
model.testNbResults(Box_2, 0)
assert(Box_2.feature().error() == "Box builder with dimensions :: Dx is null or negative.")
assert(Box_7.feature().error() == "Box builder with dimensions :: Dz is null or negative.")
model.testNbResults(Box_9, 0)
-assert(Box_9.feature().error() == "Box builder with points :: the distance between the two points is null.")
+assert(Box_9.feature().error() == "Box builder with two points :: the distance between the two points is null.")
model.testNbResults(Box_10, 0)
-assert(Box_10.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
+assert(Box_10.feature().error() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
model.testNbResults(Box_11, 0)
-assert(Box_11.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
+assert(Box_11.feature().error() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
model.testNbResults(Box_12, 0)
-assert(Box_12.feature().error() == "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.")
+assert(Box_12.feature().error() == "Box builder with two points :: the points belong both to one of the OXY, OYZ or OZX planes.")
model.testNbResults(Box_13, 0)
assert(Box_13.feature().error() == "Attribute \"FirstPoint\" is not initialized.")
Sphere_7 = model.addSphere(Part_1_doc, 10)
Sphere_7.setCenterPoint(Point_1)
+Sphere_8 = model.addSphere(Part_1_doc,10,40,0,180,0,180)
+Sphere_9 = model.addSphere(Part_1_doc,40,10,0,180,0,180)
+
model.do()
model.end()
model.testNbSubShapes(Sphere_7, GeomAPI_Shape.FACE, [1])
model.testHaveNamingFaces(Sphere_7, model, Part_1_doc)
+model.testNbResults(Sphere_8, 1)
+model.testNbSubResults(Sphere_8, [0])
+model.testNbSubShapes(Sphere_8, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(Sphere_8, GeomAPI_Shape.FACE, [4])
+model.testHaveNamingFaces(Sphere_8, model, Part_1_doc)
+
model.testNbResults(Sphere_2, 0)
assert(Sphere_2.feature().error() == "Sphere builder :: radius is negative or null.")
model.testNbResults(Sphere_5, 0)
assert(Sphere_5.feature().error() == "Attribute \"center_point\" is not initialized.")
+
+model.testNbResults(Sphere_9, 0)
+assert(Sphere_9.feature().error() == "Sphere builder :: RMin is larger than RMax.")