myDy = theDy;
myDz = theDz;
myMethodType = MethodType::BOX_DIM;
+ headError = "Box builder with dimensions";
}
//=================================================================================================
myFirstPoint = theFirstPoint;
mySecondPoint = theSecondPoint;
myMethodType = MethodType::BOX_POINTS;
+ headError = "Box builder with two points";
+}
+
+//=================================================================================================
+GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theOx, const double theOy, const double theOz,
+ const double theDx, const double theDy, const double theDz)
+{
+ myOx = theOx;
+ myOy = theOy;
+ myOz = theOz;
+ myDx = theDx;
+ myDy = theDy;
+ myDz = theDz;
+ myMethodType = MethodType::BOX_POINT_DIMS;
+ headError = "Box builder with coordinates and dimensions";
}
//=================================================================================================
bool GeomAlgoAPI_Box::check()
{
- if (myMethodType == MethodType::BOX_DIM) {
+ if (myMethodType == MethodType::BOX_DIM || myMethodType == MethodType::BOX_POINT_DIMS) {
if (myDx < Precision::Confusion()) {
- myError = "Box builder with dimensions :: Dx is null or negative.";
+ myError = headError + " :: Dx is null or negative.";
return false;
} else if (myDy < Precision::Confusion()) {
- myError = "Box builder with dimensions :: Dy is null or negative.";
+ myError = headError + " :: Dy is null or negative.";
return false;
} else if (myDz < Precision::Confusion()) {
- myError = "Box builder with dimensions :: Dz is null or negative.";
+ myError = headError + " :: Dz is null or negative.";
return false;
}
} else if (myMethodType == MethodType::BOX_POINTS) {
if (!myFirstPoint.get()) {
- myError = "Box builder with points :: the first point is not valid.";
+ myError = headError + " :: the first point is not valid.";
return false;
}
if (!mySecondPoint.get()) {
- myError = "Box builder with points :: the second point is not valid.";
+ myError = headError + " :: the second point is not valid.";
return false;
}
if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) {
- myError = "Box builder with points :: the distance between the two points is null.";
+ myError = headError + " :: the distance between the two points is null.";
return false;
}
double aDiffX = myFirstPoint->x() - mySecondPoint->x();
fabs(aDiffY) < Precision::Confusion() ||
fabs(aDiffZ) < Precision::Confusion()) {
myError =
- "Box builder with points :: the points belong both to one of the OXY, OYZ or OZX planes.";
+ headError + " :: the points belong both to one of the OXY, OYZ or OZX planes.";
return false;
}
} else {
buildWithDimensions();
} else if (myMethodType == MethodType::BOX_POINTS) {
buildWithPoints();
+ } else if (myMethodType == MethodType::BOX_POINT_DIMS) {
+ buildWithPointAndDims();
} else {
myError = "Box builder :: Method not implemented.";
return;
// Test the algorithm
if (!aBoxMaker->IsDone()) {
- myError = "Box builder with dimensions :: algorithm failed.";
+ myError = headError + " :: algorithm failed.";
return;
}
// Test on the shapes
if (!aShape.get() || aShape->isNull()) {
- myError = "Box builder with dimensions :: resulting shape is null.";
+ myError = headError + " :: resulting shape is null.";
return;
}
// Test the algorithm
if(!aBoxMaker->IsDone()) {
- myError = "Box builder with two points :: algorithm failed.";
+ myError = headError + " :: algorithm failed.";
return;
}
// Tests on the shape
if (!aShape.get() || aShape->isNull()) {
- myError = "Box builder with two points :: resulting shape is null.";
+ myError = headError + " :: resulting shape is null.";
return;
}
setDone(true);
}
+//=================================================================================================
+void GeomAlgoAPI_Box::buildWithPointAndDims()
+{
+ // 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();
+}
+
//=================================================================================================
void GeomAlgoAPI_Box::prepareNamingFaces()
{
enum MethodType {
BOX_DIM, ///< Box with dimensions
BOX_POINTS, ///< Box with points
+ BOX_POINT_DIMS, ///<Box with coordinates of a point and dimensions
};
GEOMALGOAPI_EXPORT GeomAlgoAPI_Box();
/// \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
+ /// \param theOz The Z coordinate of the point
+ /// \param theDx The dimension on X
+ /// \param theDy The dimension on Y
+ /// \param theDz The dimension on Z
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Box(const double theOx, const double theOy, const double theOz,
+ const double theDx, const double theDy, const double theDz);
/// Checks if data for the box construction is OK.
GEOMALGOAPI_EXPORT bool check();
void buildWithDimensions();
/// Builds the box with two points
void buildWithPoints();
+ /// Buils the box with coordinates of a point and dimensions
+ void buildWithPointAndDims();
+ double myOx; /// X coordinate of the point to create a box.
+ double myOy; /// Y coordinate of the point to create a box.
+ double myOz; /// Z coordinate of the point to create a box.
double myDx; /// Dimension on X to create a box.
double myDy; /// Dimension on Y to create a box.
double myDz; /// Dimension Z to create a box.
std::shared_ptr<GeomAPI_Pnt> myFirstPoint; /// First point to create a box.
std::shared_ptr<GeomAPI_Pnt> mySecondPoint; /// Second point to create a box.
MethodType myMethodType; /// Type of method used.
+ std::string headError; /// Head of the error message according to the method
};
return runAlgoAndCheckShape(aBoxAlgo, aMsg);
}
+ //===============================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeBox(
+ const double theOx, const double theOy, const double theOz,
+ const double theDx, const double theDy, const double theDz) throw (GeomAlgoAPI_Exception)
+ {
+ static const std::string aMsg("Box builder with two points");
+ GeomAlgoAPI_Box aBoxAlgo(theOx, theOy, theOz, theDx, theDy, theDz);
+ return runAlgoAndCheckShape(aBoxAlgo, aMsg);
+ }
+
//===============================================================================================
std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeCylinder(
std::shared_ptr<GeomAPI_Pnt> theBasePoint, std::shared_ptr<GeomAPI_Edge> theEdge,
static std::shared_ptr<GeomAPI_Shape> makeBox(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception);
+ /// Creates a box using coordinates of a point and dimensions
+ /// \param theOx The X coordinate of the point
+ /// \param theOy The Y coordinate of the point
+ /// \param theOz The Z coordinate of the point
+ /// \param theDx The dimension on X
+ /// \param theDy The dimension on Y
+ /// \param theDz The dimension on Z
+ /// \return a shape
+ static std::shared_ptr<GeomAPI_Shape> makeBox(const double theOx, const double theOy,
+ const double theOz, const double theDx,
+ const double theDy, const double theDz)
+ throw (GeomAlgoAPI_Exception);
+
/// Creates a cylinder using a center, an axis, a radius and a height.
/// \param theBasePoint The center of the lower base of the cylinder
/// \param theEdge The axis of the cylinder
#include <GeomAlgoAPI_PointBuilder.h>
#include <memory>
-#include <iostream>
//=================================================================================================
PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiation
{
data()->addAttribute(PrimitivesPlugin_Box::CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+ // Data for the first mode
data()->addAttribute(PrimitivesPlugin_Box::DX_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(PrimitivesPlugin_Box::DY_ID(), ModelAPI_AttributeDouble::typeId());
data()->addAttribute(PrimitivesPlugin_Box::DZ_ID(), ModelAPI_AttributeDouble::typeId());
+ // Data for the second mode
data()->addAttribute(PrimitivesPlugin_Box::POINT_FIRST_ID(),
ModelAPI_AttributeSelection::typeId());
data()->addAttribute(PrimitivesPlugin_Box::POINT_SECOND_ID(),
ModelAPI_AttributeSelection::typeId());
+
+ // Data for the third mode
+ data()->addAttribute(PrimitivesPlugin_Box::OX_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::OY_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::OZ_ID(), ModelAPI_AttributeDouble::typeId());
+
+ data()->addAttribute(PrimitivesPlugin_Box::HALF_DX_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::HALF_DY_ID(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::HALF_DZ_ID(), ModelAPI_AttributeDouble::typeId());
}
//=================================================================================================
if (aMethodType == CREATION_METHOD_BY_TWO_POINTS())
createBoxByTwoPoints();
+
+ if (aMethodType == CREATION_METHOD_BY_ONE_POINT_AND_DIMS())
+ createBoxByOnePointAndDims();
}
//=================================================================================================
setResult(aResultBox, aResultIndex);
}
+//=================================================================================================
+void PrimitivesPlugin_Box::createBoxByOnePointAndDims()
+{
+ // Getting dx, dy and dz
+ 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();
+ double z = real(PrimitivesPlugin_Box::OZ_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()) {
+ setError(aBoxAlgo->getError());
+ return;
+ }
+
+ // Build the box
+ aBoxAlgo->build();
+
+ // Check if the creation of the box
+ if(!aBoxAlgo->isDone()) {
+ // The error is not displayed in a popup window. It must be in the message console.
+ setError(aBoxAlgo->getError());
+ return;
+ }
+ if(!aBoxAlgo->checkValid("Box builder with one point and dimensions")) {
+ // The error is not displayed in a popup window. It must be in the message console.
+ setError(aBoxAlgo->getError());
+ return;
+ }
+
+ int aResultIndex = 0;
+ ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
+ loadNamingDS(aBoxAlgo, aResultBox);
+ setResult(aResultBox, aResultIndex);
+}
+
//=================================================================================================
void PrimitivesPlugin_Box::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
std::shared_ptr<ModelAPI_ResultBody> theResultBox)
class GeomAPI_Shape;
class ModelAPI_ResultBody;
-/**\class PrimitivesPlugin_Box
- * \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
- * methods : using two points that define a diagonal, or using 3 lengths that define the
- * rectangular dimensions.
- */
+/// \class PrimitivesPlugin_Box
+/// \ingroup Plugins
+/// \brief Feature for creation of a box primitive using various methods.
+///
+/// Supported following methods:
+/// * two points that define a diagonal,
+/// * three lengths that define the rectangular dimensions,
+/// * one point and three lengths that define the rectangular dimensions.
class PrimitivesPlugin_Box : public ModelAPI_Feature
{
public:
return MY_CREATION_METHOD_ID;
}
+ /// Attribute name for creation method
+ inline static const std::string& CREATION_METHOD_BY_ONE_POINT_AND_DIMS()
+ {
+ static const std::string MY_CREATION_METHOD_ID("BoxByOnePointAndDims");
+ return MY_CREATION_METHOD_ID;
+ }
+
/// Attribute name of first point
inline static const std::string& POINT_FIRST_ID()
{
return MY_POINT_SECOND_ID;
}
- /// Attribute first coordinate
+ /// Attribute name of the X dimension
inline static const std::string& DX_ID()
{
static const std::string MY_DX_ID("dx");
return MY_DX_ID;
}
- /// Attribute second coordinate
+ /// Attribute name of the Y dimension
inline static const std::string& DY_ID()
{
static const std::string MY_DY_ID("dy");
return MY_DY_ID;
}
- /// Attribute third coordinate
+ /// Attribute name of the Z dimension
inline static const std::string& DZ_ID()
{
static const std::string MY_DZ_ID("dz");
return MY_DZ_ID;
}
+
+ /// Attribute name of the coordinate X for the origin
+ inline static const std::string& OX_ID()
+ {
+ static const std::string MY_OX_ID("ox");
+ return MY_OX_ID;
+ }
+
+ /// Attribute name of the coordinate Y for the origin
+ inline static const std::string& OY_ID()
+ {
+ static const std::string MY_OY_ID("oy");
+ return MY_OY_ID;
+ }
+
+ /// Attribute name of the coordinate Z for the origin
+ inline static const std::string& OZ_ID()
+ {
+ static const std::string MY_OZ_ID("oz");
+ return MY_OZ_ID;
+ }
+
+ /// Attribute name of the half length in X
+ inline static const std::string& HALF_DX_ID()
+ {
+ static const std::string MY_HALF_DX_ID("half_dx");
+ return MY_HALF_DX_ID;
+ }
+
+ /// Attribute name of the half length in Y
+ inline static const std::string& HALF_DY_ID()
+ {
+ static const std::string MY_HALF_DY_ID("half_dy");
+ return MY_HALF_DY_ID;
+ }
+
+ /// Attribute name of the half length in Z
+ inline static const std::string& HALF_DZ_ID()
+ {
+ static const std::string MY_HALF_DZ_ID("half_dz");
+ return MY_HALF_DZ_ID;
+ }
/// Returns the kind of a feature
PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind()
///Perform the creation of the box using two points defining a diagonal
void createBoxByTwoPoints();
- ///Perform the creation of the box using three cordinates
+ ///Perform the creation of the box using three dimensions
void createBoxByDimensions();
+ ///Perform the creation of the box using one point and three dimensions
+ void createBoxByOnePointAndDims();
+
};
default="10.0"
icon=""
tooltip="Dimension in X">
+ <validator id="GeomValidators_Positive" parameters="0"/>
</doublevalue>
<doublevalue
id="dy"
default="10.0"
icon=""
tooltip="Dimension in Y">
+ <validator id="GeomValidators_Positive" parameters="0"/>
</doublevalue>
<doublevalue
id="dz"
default="10.0"
icon=""
tooltip="Dimension in Z">
+ <validator id="GeomValidators_Positive" parameters="0"/>
</doublevalue>
</box>
<box id="BoxByTwoPoints" title="By two points" icon="icons/Primitives/box_2pt_32x32.png">
shape_types="vertex">
</shape_selector>
</box>
+ <box id="BoxByOnePointAndDims" title="By one point and dimensions" icon="icons/Primitives/box_pt_dxyz_32x32.png">
+ <groupbox title="Origin">
+ <doublevalue
+ id="ox"
+ label="OX"
+ step="1."
+ default="0."
+ tooltip="Enter the coordinate X for the origin">
+ </doublevalue>
+ <doublevalue
+ id="oy"
+ label="OY"
+ step="1."
+ default="0."
+ tooltip="Enter the coordinate Y for the origin">
+ </doublevalue>
+ <doublevalue
+ id="oz"
+ label="OZ"
+ step="1."
+ default="0."
+ tooltip="Enter the coordinate Z for the origin">
+ </doublevalue>
+ </groupbox>
+ <groupbox title="Half-lengths">
+ <doublevalue
+ id="half_dx"
+ label="DX"
+ step="1."
+ default="20."
+ tooltip="Enter the half length in X">
+ <validator id="GeomValidators_Positive" parameters="0"/>
+ </doublevalue>
+ <doublevalue
+ id="half_dy"
+ label="DY"
+ step="1."
+ default="20."
+ tooltip="Enter the half length in Y">
+ <validator id="GeomValidators_Positive" parameters="0"/>
+ </doublevalue>
+ <doublevalue
+ id="half_dz"
+ label="DZ"
+ step="1."
+ default="20."
+ tooltip="Enter the half length in Z">
+ <validator id="GeomValidators_Positive" parameters="0"/>
+ </doublevalue>
+ </groupbox>
+ </box>
</toolbox>
</source>
--- /dev/null
+
+ .. _tui_create_boxptdim:
+
+Create Box coordinates of a point and dimensions
+================================================
+
+.. literalinclude:: examples/box3.py
+ :linenos:
+ :language: python
+
+:download:`Download this script <examples/box3.py>`
+
#. select in the Main Menu *Primitives - > Box* item or
#. click |box.icon| **Box** button in the toolbar:
-There are 2 algorithms for creation of a Box:
+There are 3 algorithms for creation of a Box:
-.. image:: images/box_2pt_32x32.png
+.. image:: images/box_dxyz_32x32.png
:align: left
**By dimensions**
-.. image:: images/box_dxyz_32x32.png
+.. image:: images/box_2pt_32x32.png
:align: left
**By two points**
+.. image:: images/box_pt_dxyz_32x32.png
+ :align: left
+**By coordinates of a point and dimensions**
By dimensions
-------------
Created boxes
**See Also** a sample TUI Script of :ref:`tui_create_boxpnt` operation.
+
+By coordinates of a point and dimensions
+----------------------------------------
+
+Box is created by dimensions along X, Y, Z axis starting from the point of coordinates (x,y,z).
+
+.. image:: images/Box_ptAndDims.png
+ :align: center
+
+Input fields:
+
+- **OX**, **OY**, **OZ** define coordinates of the center of box.
+- **DX**, **DY**, **DZ** define dimensions (hafl length) of the box along the corresponding coordinate axes.
+
+**TUI Command**:
+
+.. py:function:: model.addBox(Part_doc, OX, OY, OZ, DX, DY, DZ)
+
+ :param part: The current part object.
+ :param real: X coordinate of the center point
+ :param real: Y coordinate of the center point
+ :param real: Z coordinate of the center point
+ :param real: Half size along X.
+ :param real: Half size along Y.
+ :param real: Half size along Z.
+ :return: Result object.
+
+Result
+""""""
+
+A solid box whose point coordinates are the center and the dimensions are half lengths on one side and the other on the axes relative to the center..
+
+.. image:: images/Box3.png
+ :align: center
+
+**See Also** a sample TUI Script of :ref:`tui_create_boxptdim` operation.
\ No newline at end of file
--- /dev/null
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Box_1 = model.addBox(Part_1_doc, 0, 0, 0, 20, 20, 20)
+model.do()
+model.end()