From: Clarisse Genrault Date: Wed, 15 Apr 2020 13:08:25 +0000 (+0200) Subject: Add a new mode for the box X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7687c08a185003291853ffc445f069a10a2ac43f;p=modules%2Fshaper.git Add a new mode for the box --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index 8105c7bf2..450a54cec 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp @@ -34,6 +34,7 @@ GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theDx, const double theDy, const d myDy = theDy; myDz = theDz; myMethodType = MethodType::BOX_DIM; + headError = "Box builder with dimensions"; } //================================================================================================= @@ -43,33 +44,48 @@ GeomAlgoAPI_Box::GeomAlgoAPI_Box(std::shared_ptr theFirstPoint, 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(); @@ -79,7 +95,7 @@ bool GeomAlgoAPI_Box::check() 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 { @@ -96,6 +112,8 @@ void GeomAlgoAPI_Box::build() buildWithDimensions(); } else if (myMethodType == MethodType::BOX_POINTS) { buildWithPoints(); + } else if (myMethodType == MethodType::BOX_POINT_DIMS) { + buildWithPointAndDims(); } else { myError = "Box builder :: Method not implemented."; return; @@ -113,7 +131,7 @@ void GeomAlgoAPI_Box::buildWithDimensions() // Test the algorithm if (!aBoxMaker->IsDone()) { - myError = "Box builder with dimensions :: algorithm failed."; + myError = headError + " :: algorithm failed."; return; } @@ -124,7 +142,7 @@ void GeomAlgoAPI_Box::buildWithDimensions() // 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; } @@ -147,7 +165,7 @@ void GeomAlgoAPI_Box::buildWithPoints() // Test the algorithm if(!aBoxMaker->IsDone()) { - myError = "Box builder with two points :: algorithm failed."; + myError = headError + " :: algorithm failed."; return; } @@ -159,7 +177,7 @@ void GeomAlgoAPI_Box::buildWithPoints() // 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; } @@ -168,6 +186,18 @@ void GeomAlgoAPI_Box::buildWithPoints() setDone(true); } +//================================================================================================= +void GeomAlgoAPI_Box::buildWithPointAndDims() +{ + // Construct points from cordinates and dimensions to use the method with two points + myFirstPoint = + std::shared_ptr(new GeomAPI_Pnt(myOx - myDx, myOy - myDy, myOz - myDz)); + mySecondPoint = + std::shared_ptr(new GeomAPI_Pnt(myOx + myDx, myOy + myDy, myOz + myDz)); + + buildWithPoints(); +} + //================================================================================================= void GeomAlgoAPI_Box::prepareNamingFaces() { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.h b/src/GeomAlgoAPI/GeomAlgoAPI_Box.h index 69236954f..8dfce4e55 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.h @@ -34,6 +34,7 @@ class GeomAlgoAPI_Box : public GeomAlgoAPI_MakeShape enum MethodType { BOX_DIM, ///< Box with dimensions BOX_POINTS, ///< Box with points + BOX_POINT_DIMS, /// theFirstPoint, std::shared_ptr 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(); @@ -64,13 +75,19 @@ class GeomAlgoAPI_Box : public GeomAlgoAPI_MakeShape 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 myFirstPoint; /// First point to create a box. std::shared_ptr 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 }; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index 55567c40a..6536032ce 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -85,6 +85,16 @@ namespace GeomAlgoAPI_ShapeAPI return runAlgoAndCheckShape(aBoxAlgo, aMsg); } + //=============================================================================================== + std::shared_ptr 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 GeomAlgoAPI_ShapeAPI::makeCylinder( std::shared_ptr theBasePoint, std::shared_ptr theEdge, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h index fe1f86f2b..c34d077a3 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h @@ -52,6 +52,19 @@ public: static std::shared_ptr makeBox(std::shared_ptr theFirstPoint, std::shared_ptr 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 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 diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp index 8fce2cc9b..196872dc2 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp @@ -28,7 +28,6 @@ #include #include -#include //================================================================================================= PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiation @@ -40,14 +39,25 @@ void PrimitivesPlugin_Box::initAttributes() { 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()); } //================================================================================================= @@ -61,6 +71,9 @@ void PrimitivesPlugin_Box::execute() if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) createBoxByTwoPoints(); + + if (aMethodType == CREATION_METHOD_BY_ONE_POINT_AND_DIMS()) + createBoxByOnePointAndDims(); } //================================================================================================= @@ -148,6 +161,50 @@ void PrimitivesPlugin_Box::createBoxByTwoPoints() 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 aBoxAlgo; + aBoxAlgo = std::shared_ptr(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 theBoxAlgo, std::shared_ptr theResultBox) diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.h b/src/PrimitivesPlugin/PrimitivesPlugin_Box.h index e9ab91cf5..8a56f8363 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.h @@ -27,14 +27,14 @@ 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: @@ -66,6 +66,13 @@ class PrimitivesPlugin_Box : public ModelAPI_Feature 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() { @@ -80,26 +87,68 @@ class PrimitivesPlugin_Box : public ModelAPI_Feature 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() @@ -125,9 +174,12 @@ class PrimitivesPlugin_Box : public ModelAPI_Feature ///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(); + }; diff --git a/src/PrimitivesPlugin/box_widget.xml b/src/PrimitivesPlugin/box_widget.xml index f968b5154..53eb9c0f2 100644 --- a/src/PrimitivesPlugin/box_widget.xml +++ b/src/PrimitivesPlugin/box_widget.xml @@ -8,6 +8,7 @@ default="10.0" icon="" tooltip="Dimension in X"> + + + @@ -40,5 +43,56 @@ shape_types="vertex"> + + + + + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/doc/TUI_boxByPtDims.rst b/src/PrimitivesPlugin/doc/TUI_boxByPtDims.rst new file mode 100644 index 000000000..2b5aa3142 --- /dev/null +++ b/src/PrimitivesPlugin/doc/TUI_boxByPtDims.rst @@ -0,0 +1,12 @@ + + .. _tui_create_boxptdim: + +Create Box coordinates of a point and dimensions +================================================ + +.. literalinclude:: examples/box3.py + :linenos: + :language: python + +:download:`Download this script ` + diff --git a/src/PrimitivesPlugin/doc/boxFeature.rst b/src/PrimitivesPlugin/doc/boxFeature.rst index a0809eba8..be10b6443 100644 --- a/src/PrimitivesPlugin/doc/boxFeature.rst +++ b/src/PrimitivesPlugin/doc/boxFeature.rst @@ -11,16 +11,19 @@ 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: -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 ------------- @@ -88,3 +91,39 @@ A solid box based on two points and with edges parallel to the coordinate axes. 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 diff --git a/src/PrimitivesPlugin/doc/examples/box3.py b/src/PrimitivesPlugin/doc/examples/box3.py new file mode 100644 index 000000000..493143920 --- /dev/null +++ b/src/PrimitivesPlugin/doc/examples/box3.py @@ -0,0 +1,9 @@ +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() diff --git a/src/PrimitivesPlugin/doc/images/Box3.png b/src/PrimitivesPlugin/doc/images/Box3.png new file mode 100644 index 000000000..a1b5e5fce Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Box3.png differ diff --git a/src/PrimitivesPlugin/doc/images/Box_2points.png b/src/PrimitivesPlugin/doc/images/Box_2points.png index 77bec595d..fa73200da 100644 Binary files a/src/PrimitivesPlugin/doc/images/Box_2points.png and b/src/PrimitivesPlugin/doc/images/Box_2points.png differ diff --git a/src/PrimitivesPlugin/doc/images/Box_dimensions.png b/src/PrimitivesPlugin/doc/images/Box_dimensions.png index 8fee3ead8..40ef70117 100644 Binary files a/src/PrimitivesPlugin/doc/images/Box_dimensions.png and b/src/PrimitivesPlugin/doc/images/Box_dimensions.png differ diff --git a/src/PrimitivesPlugin/icons/box_pt_dxyz_32x32.png b/src/PrimitivesPlugin/icons/box_pt_dxyz_32x32.png new file mode 100644 index 000000000..db199ea7b Binary files /dev/null and b/src/PrimitivesPlugin/icons/box_pt_dxyz_32x32.png differ