From: cg246364 Date: Fri, 18 Mar 2022 09:22:34 +0000 (+0100) Subject: Add a new mode for creating a box by a center and dimensions. (TestBox.py) X-Git-Tag: V9_9_0a2~3^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fcgt%2Fprimitives_1;p=modules%2Fshaper.git Add a new mode for creating a box by a center and dimensions. (TestBox.py) Add a new mode for creating a sphere part. (TestSphere.py) Add a new "Tube" primitive. (TestTube.py) --- diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 19ace76ed..17eec671e 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -92,6 +92,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_Defeaturing.h GeomAlgoAPI_BoundingBox.h GeomAlgoAPI_NormalToFace.h + GeomAlgoAPI_Tube.h ) SET(PROJECT_SOURCES @@ -163,6 +164,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_Defeaturing.cpp GeomAlgoAPI_BoundingBox.cpp GeomAlgoAPI_NormalToFace.cpp + GeomAlgoAPI_Tube.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index 1dcc9fa97..4ba9fd2ad 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 c6f1269f1..b64131f9b 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_Sphere.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp index f2b8db42c..7a045049f 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp @@ -23,26 +23,55 @@ #include +#include + +#include +#include +#include + +#include #include //================================================================================================= GeomAlgoAPI_Sphere::GeomAlgoAPI_Sphere(std::shared_ptr theCenterPoint, const double theRadius) { + isRootGeo = 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) +{ + isRootGeo = 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 (isRootGeo) { + 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; } @@ -51,30 +80,151 @@ bool GeomAlgoAPI_Sphere::check() void GeomAlgoAPI_Sphere::build() { myCreatedFaces.clear(); + if (isRootGeo) { + buildRootSphere(); + } else { + const gp_Pnt& aCenterPoint = myCenterPoint->impl(); + + // Construct the sphere + BRepPrimAPI_MakeSphere *aSphereMaker = new BRepPrimAPI_MakeSphere(aCenterPoint, myRadius); + + aSphereMaker->Build(); + + if (!aSphereMaker->IsDone()) { + return; + } + + TopoDS_Shape aResult = aSphereMaker->Shape(); + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + setShape(aShape); + + // Test on the shapes + if (!aShape.get() || aShape->isNull()) { + myError = "Sphere builder :: resulting shape is null."; + return; + } + + setImpl(aSphereMaker); + + setDone(true); + } +} + +//================================================================================================= +void GeomAlgoAPI_Sphere::buildRootSphere() +{ + 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); - const gp_Pnt& aCenterPoint = myCenterPoint->impl(); + 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); - // Construct the sphere - BRepPrimAPI_MakeSphere *aSphereMaker = new BRepPrimAPI_MakeSphere(aCenterPoint, myRadius); + aX = myRMin*sin(myThetaMin * M_PI/180.); + aZ = myRMin*cos(myThetaMin * M_PI/180.); + gp_Pnt aTopInnerStart(aX*cos(aStartPhiRad), aX*sin(aStartPhiRad), aZ); - aSphereMaker->Build(); + 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(); - if (!aSphereMaker->IsDone()) { + 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 = "GDML 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 = "GDML Sphere builder :: section revolution did not succeed"; + } + if(!aRevolBuilder->IsDone()) { + myError = "GDML Sphere builder :: section revolution did not succeed"; return; } - TopoDS_Shape aResult = aSphereMaker->Shape(); - std::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aResult)); - setShape(aShape); + // Get the shape, verify it, build a GeomAPI_Shape. + std::shared_ptr aResultShape = + std::shared_ptr(new GeomAPI_Shape()); + aResultShape->setImpl(new TopoDS_Shape(aRevolBuilder->Shape())); + setShape(aResultShape); // Test on the shapes - if (!aShape.get() || aShape->isNull()) { - myError = "Sphere builder :: resulting shape is null."; + if (!(aResultShape).get() || aResultShape->isNull()) { + myError = "GDML Sphere builder :: resulting shape is null."; return; } - setImpl(aSphereMaker); + setImpl(aRevolBuilder); + setBuilderType(OCCT_BRepBuilderAPI_MakeShape); setDone(true); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h index 8fb449948..1f29859bc 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.h @@ -40,6 +40,16 @@ class GeomAlgoAPI_Sphere : public GeomAlgoAPI_MakeShape /// \param theRadius The radius of the sphere GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere(std::shared_ptr theCenterPoint, const double theRadius); + /// Creates a sphere. + /// \param theRMin The inner radius of the sphere + /// \param theRMax The outer radius of the sphere + /// \param thePhiMin The lower phi limit + /// \param thePhiMax The higher phi limit + /// \param theThetaMin The lower theta limit + /// \param theThetaMax The higher theta limit + GEOMALGOAPI_EXPORT GeomAlgoAPI_Sphere(const double theRMin, const double theRMax, + const double thePhiMin, const double thePhiMax, + const double theThetaMin, const double theThetaMax); /// Checks if data for the sphere construction is OK. GEOMALGOAPI_EXPORT bool check(); @@ -47,9 +57,16 @@ class GeomAlgoAPI_Sphere : public GeomAlgoAPI_MakeShape /// Builds the sphere. GEOMALGOAPI_EXPORT void build(); + /// Builds the sphere. + GEOMALGOAPI_EXPORT void buildRootSphere(); + private: + bool isRootGeo; std::shared_ptr myCenterPoint; /// Center of the sphere. double myRadius; + double myRMin, myRMax; + double myPhiMin, myPhiMax; + double myThetaMin, myThetaMax; }; #endif // GEOMALGOAPI_SPHERE_H_ diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp new file mode 100644 index 000000000..55296f33f --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp @@ -0,0 +1,132 @@ +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include + +#include +#include +#include +#include + +#include + +#include + +#include +#include + +//================================================================================================= +GeomAlgoAPI_Tube::GeomAlgoAPI_Tube() +{ +} + +//================================================================================================= +GeomAlgoAPI_Tube::GeomAlgoAPI_Tube(const double theRMin, const double theRMax, const double theZ) +{ + myRMin = theRMin; + myRMax = theRMax; + myZ = theZ; +} + +//================================================================================================= +bool GeomAlgoAPI_Tube::check() +{ + if ((myRMax -myRMin) < Precision::Confusion()) { + myError = "Tube builder :: rmin is greater then or equal to rmax."; + return false; + } else if (myRMin < 0.) { + myError = "Tube builder :: rmin is negative."; + return false; + } else if (myZ < Precision::Confusion()) { + myError = "Tube builder :: z is negative or null."; + return false; + } + + return true; +} + +//================================================================================================= +void GeomAlgoAPI_Tube::build() +{ + buildTube(); +} + +//================================================================================================= +void GeomAlgoAPI_Tube::buildTube() +{ + myCreatedFaces.clear(); + + // Construct the inner and outer circles + gp_Pnt anOrigin(0., 0., 0.); + gp_Dir aNormal(0., 0., 1.); + gp_Circ anInnerCircle(gp_Ax2(anOrigin, aNormal), myRMin); + gp_Circ anOuterCircle(gp_Ax2(anOrigin, aNormal), myRMax); + + // Construct the inner wire + BRepBuilderAPI_MakeEdge anInnerCircleBuilder(anInnerCircle); + anInnerCircleBuilder.Build(); + BRepBuilderAPI_MakeWire anInnerWireBuilder; + anInnerWireBuilder.Add(anInnerCircleBuilder.Edge()); + anInnerWireBuilder.Build(); + TopoDS_Wire anInnerWire(anInnerWireBuilder.Wire()); + + // Construct the outer wire + BRepBuilderAPI_MakeEdge anOuterCircleBuilder(anOuterCircle); + anOuterCircleBuilder.Build(); + BRepBuilderAPI_MakeWire anOuterWireBuilder; + anOuterWireBuilder.Add(anOuterCircleBuilder.Edge()); + anOuterWireBuilder.Build(); + TopoDS_Wire anOuterWire(anOuterWireBuilder.Wire()); + + // Construct the face withe the outer wire + BRepBuilderAPI_MakeFace aFaceBuilder(anOuterWire); + aFaceBuilder.Build(); + TopoDS_Face aFace(aFaceBuilder.Face()); + + // Construct the hole face + BRepAlgo_FaceRestrictor aFaceRestrictor; + aFaceRestrictor.Init(aFace, Standard_False, Standard_True); + aFaceRestrictor.Add(anInnerWire); + aFaceRestrictor.Add(anOuterWire); + aFaceRestrictor.Perform(); + aFace = TopoDS_Face(aFaceRestrictor.Current()); + + // Construct the tube + gp_Vec aVec(aNormal); + gp_Trsf aTrsf; + aTrsf.SetTranslation(aVec * -myZ/2); + BRepBuilderAPI_Transform *aTranformBuilder = new BRepBuilderAPI_Transform(aFace, aTrsf); + if (!aTranformBuilder || !aTranformBuilder->IsDone()) { + myError = "Tube builder :: algorithm failed"; + return; + } + TopoDS_Shape aMovedBase = aTranformBuilder->Shape(); + BRepPrimAPI_MakePrism *aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aVec * myZ); + + std::shared_ptr aShape = std::shared_ptr(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aPrismBuilder->Shape())); + setShape(aShape); + + setImpl(aPrismBuilder); + setBuilderType(OCCT_BRepBuilderAPI_MakeShape); + + setDone(true); +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tube.h b/src/GeomAlgoAPI/GeomAlgoAPI_Tube.h new file mode 100644 index 000000000..73cfe4881 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tube.h @@ -0,0 +1,57 @@ +// Copyright (C) 2017-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef GEOMALGOAPI_TUBE_H_ +#define GEOMALGOAPI_TUBE_H_ + +#include + +/**\class GeomAlgoAPI_Tube + * \ingroup DataAlgo + * \brief Allows to create Tube Primitives + */ +class GeomAlgoAPI_Tube : public GeomAlgoAPI_MakeShape +{ + public: + GEOMALGOAPI_EXPORT GeomAlgoAPI_Tube(); + + /// Creates a tube. + /// \param theRMin The inside radius + /// \param theRMax The outside radius + /// \param theZ The heigth + GEOMALGOAPI_EXPORT GeomAlgoAPI_Tube(const double theRMin, + const double theRMax, + const double theZ); + + /// Checks if data for the torus construction is OK. + GEOMALGOAPI_EXPORT bool check(); + + /// Builds the torus. + GEOMALGOAPI_EXPORT void build(); + +private: + /// Builds the the tube with the inside radius, the outside radius and the height. + void buildTube(); + + double myRMin; /// inside radius to create a tube. + double myRMax; /// outside radius to create a tube. + double myZ; /// height to create a tube. +}; + +#endif // GEOMALGOAPI_TUBE_H_ diff --git a/src/PrimitivesAPI/CMakeLists.txt b/src/PrimitivesAPI/CMakeLists.txt index 507b54c45..e6df736f5 100644 --- a/src/PrimitivesAPI/CMakeLists.txt +++ b/src/PrimitivesAPI/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS PrimitivesAPI_Cylinder.h PrimitivesAPI_Sphere.h PrimitivesAPI_Torus.h + PrimitivesAPI_Tube.h ) SET(PROJECT_SOURCES @@ -34,6 +35,7 @@ SET(PROJECT_SOURCES PrimitivesAPI_Cylinder.cpp PrimitivesAPI_Sphere.cpp PrimitivesAPI_Torus.cpp + PrimitivesAPI_Tube.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/PrimitivesAPI/PrimitivesAPI.i b/src/PrimitivesAPI/PrimitivesAPI.i index 5fa74c454..3e6dc3521 100644 --- a/src/PrimitivesAPI/PrimitivesAPI.i +++ b/src/PrimitivesAPI/PrimitivesAPI.i @@ -43,6 +43,7 @@ %shared_ptr(PrimitivesAPI_Cylinder) %shared_ptr(PrimitivesAPI_Sphere) %shared_ptr(PrimitivesAPI_Torus) +%shared_ptr(PrimitivesAPI_Tube) // all supported interfaces %include "PrimitivesAPI_Box.h" @@ -50,3 +51,4 @@ %include "PrimitivesAPI_Cylinder.h" %include "PrimitivesAPI_Sphere.h" %include "PrimitivesAPI_Torus.h" +%include "PrimitivesAPI_Tube.h" diff --git a/src/PrimitivesAPI/PrimitivesAPI_Box.cpp b/src/PrimitivesAPI/PrimitivesAPI_Box.cpp index 04b73f6ee..67fbe3396 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Box.cpp +++ b/src/PrimitivesAPI/PrimitivesAPI_Box.cpp @@ -50,6 +50,29 @@ PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr& th setPoints(theFirstPoint, theSecondPoint); } +//================================================================================================== +PrimitivesAPI_Box::PrimitivesAPI_Box(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theOx, + const ModelHighAPI_Double& theOy, + const ModelHighAPI_Double& theOz, + const ModelHighAPI_Double& theHalfX, + const ModelHighAPI_Double& theHalfY, + const ModelHighAPI_Double& theHalfZ) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + { + fillAttribute(PrimitivesPlugin_Box::CREATION_METHOD_BY_ONE_POINT_AND_DIMS(), creationMethod()); + fillAttribute(theOx, ox()); + fillAttribute(theOy, oy()); + fillAttribute(theOz, oz()); + fillAttribute(theHalfX, halfdx()); + fillAttribute(theHalfY, halfdy()); + fillAttribute(theHalfZ, halfdz()); + execute(); + } +} + //================================================================================================== PrimitivesAPI_Box::~PrimitivesAPI_Box() { @@ -80,6 +103,30 @@ void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint, execute(); } +//================================================================================================== +void PrimitivesAPI_Box::setOrigin(const ModelHighAPI_Double& theOx, + const ModelHighAPI_Double& theOy, + const ModelHighAPI_Double& theOz) +{ + fillAttribute(theOx, ox()); + fillAttribute(theOy, oy()); + fillAttribute(theOz, oz()); + + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Box::setHalfLengths(const ModelHighAPI_Double& theHalfLengthX, + const ModelHighAPI_Double& theHalfLengthY, + const ModelHighAPI_Double& theHalfLengthZ) +{ + fillAttribute(theHalfLengthX, halfdx()); + fillAttribute(theHalfLengthY, halfdy()); + fillAttribute(theHalfLengthZ, halfdz()); + + execute(); +} + //================================================================================================== void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const { @@ -101,6 +148,16 @@ void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const AttributeSelectionPtr anAttrSecondPnt = aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID()); theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt; + } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_ONE_POINT_AND_DIMS()) { + AttributeDoublePtr anAttrOx = aBase->real(PrimitivesPlugin_Box::OX_ID()); + AttributeDoublePtr anAttrOy = aBase->real(PrimitivesPlugin_Box::OY_ID()); + AttributeDoublePtr anAttrOz = aBase->real(PrimitivesPlugin_Box::OZ_ID()); + AttributeDoublePtr anAttrHalfLengthX = aBase->real(PrimitivesPlugin_Box::HALF_DX_ID()); + AttributeDoublePtr anAttrHalfLengthY = aBase->real(PrimitivesPlugin_Box::HALF_DY_ID()); + AttributeDoublePtr anAttrHalfLengthZ = aBase->real(PrimitivesPlugin_Box::HALF_DZ_ID()); + theDumper << ", " << anAttrOx << ", " << anAttrOy << ", " << anAttrOz; + theDumper << ", " << anAttrHalfLengthX << ", " << anAttrHalfLengthY; + theDumper << ", " << anAttrHalfLengthZ; } theDumper << ")" << std::endl; @@ -123,4 +180,18 @@ BoxPtr addBox(const std::shared_ptr& thePart, { std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Box::ID()); return BoxPtr(new PrimitivesAPI_Box(aFeature, theFirstPoint, theSecondPoint)); -} \ No newline at end of file +} + +//================================================================================================== +BoxPtr addBox(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theOx, + const ModelHighAPI_Double& theOy, + const ModelHighAPI_Double& theOz, + const ModelHighAPI_Double& theHalfLengthX, + const ModelHighAPI_Double& theHalfLengthY, + const ModelHighAPI_Double& theHalfLengthZ) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Box::ID()); + return BoxPtr(new PrimitivesAPI_Box(aFeature, theOx, theOy, theOz, theHalfLengthX, + theHalfLengthY, theHalfLengthZ)); +} diff --git a/src/PrimitivesAPI/PrimitivesAPI_Box.h b/src/PrimitivesAPI/PrimitivesAPI_Box.h index 2fda32494..33b412bea 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Box.h +++ b/src/PrimitivesAPI/PrimitivesAPI_Box.h @@ -53,11 +53,21 @@ public: const ModelHighAPI_Selection& theFirstPoint, const ModelHighAPI_Selection& theSecondPoint); + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Box(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theOx, + const ModelHighAPI_Double& theOy, + const ModelHighAPI_Double& theOz, + const ModelHighAPI_Double& theHalfX, + const ModelHighAPI_Double& theHalfY, + const ModelHighAPI_Double& theHalfZ); + /// Destructor. PRIMITIVESAPI_EXPORT virtual ~PrimitivesAPI_Box(); - INTERFACE_6(PrimitivesPlugin_Box::ID(), + INTERFACE_12(PrimitivesPlugin_Box::ID(), creationMethod, PrimitivesPlugin_Box::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, dx, PrimitivesPlugin_Box::DX_ID(), @@ -69,7 +79,19 @@ public: firstPoint, PrimitivesPlugin_Box::POINT_FIRST_ID(), ModelAPI_AttributeSelection, /** First point */, secondPoint, PrimitivesPlugin_Box::POINT_SECOND_ID(), - ModelAPI_AttributeSelection, /** Second point */) + ModelAPI_AttributeSelection, /** Second point */, + ox, PrimitivesPlugin_Box::OX_ID(), + ModelAPI_AttributeDouble, /** X coordinate for origin*/, + oy, PrimitivesPlugin_Box::OY_ID(), + ModelAPI_AttributeDouble, /** Y coordinate for origin*/, + oz, PrimitivesPlugin_Box::OZ_ID(), + ModelAPI_AttributeDouble, /** Z coordinate for origin*/, + halfdx, PrimitivesPlugin_Box::HALF_DX_ID(), + ModelAPI_AttributeDouble, /** Half length in X*/, + halfdy, PrimitivesPlugin_Box::HALF_DY_ID(), + ModelAPI_AttributeDouble, /** Half length in Y*/, + halfdz, PrimitivesPlugin_Box::HALF_DZ_ID(), + ModelAPI_AttributeDouble, /** Half length in Z*/) /// Set dimensions PRIMITIVESAPI_EXPORT @@ -82,6 +104,18 @@ public: void setPoints(const ModelHighAPI_Selection& theFirstPoint, const ModelHighAPI_Selection& theSecondPoint); + /// Set origin point + PRIMITIVESAPI_EXPORT + void setOrigin(const ModelHighAPI_Double& theOx, + const ModelHighAPI_Double& theOy, + const ModelHighAPI_Double& theOz); + + /// Set half lengths + PRIMITIVESAPI_EXPORT + void setHalfLengths(const ModelHighAPI_Double& theHalfLengthX, + const ModelHighAPI_Double& theHalfLengthY, + const ModelHighAPI_Double& theHalfLengthZ); + /// Dump wrapped feature PRIMITIVESAPI_EXPORT virtual void dump(ModelHighAPI_Dumper& theDumper) const; @@ -105,4 +139,15 @@ BoxPtr addBox(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theFirstPoint, const ModelHighAPI_Selection& theSecondPoint); -#endif // PRIMITIVESAPI_BOX_H_ \ No newline at end of file +/// \ingroup CPPHighAPI +/// \brief Create primitive Box feature. +PRIMITIVESAPI_EXPORT +BoxPtr addBox(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theOx, + const ModelHighAPI_Double& theOy, + const ModelHighAPI_Double& theOz, + const ModelHighAPI_Double& theHalfLengthX, + const ModelHighAPI_Double& theHalfLengthY, + const ModelHighAPI_Double& theHalfLengthZ); + +#endif // PRIMITIVESAPI_BOX_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp index 4b3b594ad..20e9cbd1c 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp +++ b/src/PrimitivesAPI/PrimitivesAPI_Sphere.cpp @@ -41,11 +41,34 @@ PrimitivesAPI_Sphere::PrimitivesAPI_Sphere(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& thePhiMin, + const ModelHighAPI_Double& thePhiMax, + const ModelHighAPI_Double& theThetaMin, + const ModelHighAPI_Double& theThetaMax) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD_BY_DIMENSIONS(), creationMethod()); + fillAttribute(theRMin, rmin()); + fillAttribute(theRMax, rmax()); + fillAttribute(thePhiMin, phimin()); + fillAttribute(thePhiMax, phimax()); + fillAttribute(theThetaMin, thetamin()); + fillAttribute(theThetaMax, thetamax()); + execute(); + } +} + //================================================================================================== PrimitivesAPI_Sphere::~PrimitivesAPI_Sphere() { @@ -65,6 +88,33 @@ void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRadius) execute(); } +//================================================================================================== +void PrimitivesAPI_Sphere::setRadius(const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax) +{ + fillAttribute(theRMin, rmin()); + fillAttribute(theRMax, rmax()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Sphere::setPhi(const ModelHighAPI_Double& thePhiMin, + const ModelHighAPI_Double& thePhiMax) +{ + fillAttribute(thePhiMin, phimin()); + fillAttribute(thePhiMax, phimax()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Sphere::setTheta(const ModelHighAPI_Double& theThetaMin, + const ModelHighAPI_Double& theThetaMax) +{ + fillAttribute(theThetaMin, thetamin()); + fillAttribute(theThetaMax, thetamax()); + execute(); +} + //================================================================================================== void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const { @@ -73,10 +123,24 @@ void PrimitivesAPI_Sphere::dump(ModelHighAPI_Dumper& theDumper) const theDumper << aBase << " = model.addSphere(" << aDocName; - AttributeSelectionPtr anAttrCenterPoint = - aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID()); - AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID()); - theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius; + std::string aCreationMethod = aBase->string(PrimitivesPlugin_Sphere::CREATION_METHOD())->value(); + + if(aCreationMethod == PrimitivesPlugin_Sphere::CREATION_METHOD_BY_PT_RADIUS()) { + AttributeSelectionPtr anAttrCenterPoint = + aBase->selection(PrimitivesPlugin_Sphere::CENTER_POINT_ID()); + AttributeDoublePtr anAttrRadius = aBase->real(PrimitivesPlugin_Sphere::RADIUS_ID()); + theDumper << ", " << anAttrCenterPoint << ", " << anAttrRadius; + } else if(aCreationMethod == PrimitivesPlugin_Sphere::CREATION_METHOD_BY_DIMENSIONS()) { + AttributeDoublePtr anAttrRMin = aBase->real(PrimitivesPlugin_Sphere::RMIN_ID()); + AttributeDoublePtr anAttrRMax = aBase->real(PrimitivesPlugin_Sphere::RMAX_ID()); + AttributeDoublePtr anAttrPhiMin = aBase->real(PrimitivesPlugin_Sphere::PHIMIN_ID()); + AttributeDoublePtr anAttrPhiMax = aBase->real(PrimitivesPlugin_Sphere::PHIMAX_ID()); + AttributeDoublePtr anAttrThetaMin = aBase->real(PrimitivesPlugin_Sphere::THETAMIN_ID()); + AttributeDoublePtr anAttrThetaMax = aBase->real(PrimitivesPlugin_Sphere::THETAMAX_ID()); + theDumper << ", " << anAttrRMin << ", " << anAttrRMax; + theDumper << ", " << anAttrPhiMin << ", " << anAttrPhiMax; + theDumper << ", " << anAttrThetaMin << ", " << anAttrThetaMax; + } theDumper << ")" << std::endl; } @@ -98,3 +162,17 @@ SpherePtr addSphere(const std::shared_ptr& thePart, std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID()); return SpherePtr(new PrimitivesAPI_Sphere(aFeature, aCenterPoint, theRadius)); } + +//================================================================================================== +SpherePtr addSphere(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& thePhiMin, + const ModelHighAPI_Double& thePhiMax, + const ModelHighAPI_Double& theThetaMin, + const ModelHighAPI_Double& theThetaMax) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Sphere::ID()); + return SpherePtr(new PrimitivesAPI_Sphere(aFeature, theRMin, theRMax, thePhiMin, thePhiMax, + theThetaMin, theThetaMax)); +} diff --git a/src/PrimitivesAPI/PrimitivesAPI_Sphere.h b/src/PrimitivesAPI/PrimitivesAPI_Sphere.h index 68e0ca5df..3c4691a46 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Sphere.h +++ b/src/PrimitivesAPI/PrimitivesAPI_Sphere.h @@ -50,15 +50,39 @@ public: const ModelHighAPI_Selection& theCenterPoint, const ModelHighAPI_Double& theRadius); + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Sphere(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& thePhiMin, + const ModelHighAPI_Double& thePhiMax, + const ModelHighAPI_Double& theThetaMin, + const ModelHighAPI_Double& theThetaMax); + /// Destructor. PRIMITIVESAPI_EXPORT virtual ~PrimitivesAPI_Sphere(); - INTERFACE_2(PrimitivesPlugin_Sphere::ID(), + INTERFACE_9(PrimitivesPlugin_Sphere::ID(), + creationMethod, PrimitivesPlugin_Sphere::CREATION_METHOD(), + ModelAPI_AttributeString, /** Creation method */, centerPoint, PrimitivesPlugin_Sphere::CENTER_POINT_ID(), ModelAPI_AttributeSelection, /** Center point */, radius, PrimitivesPlugin_Sphere::RADIUS_ID(), - ModelAPI_AttributeDouble, /** Radius */) + ModelAPI_AttributeDouble, /** Radius */, + rmin, PrimitivesPlugin_Sphere::RMIN_ID(), + ModelAPI_AttributeDouble, /** The minimum radius*/, + rmax, PrimitivesPlugin_Sphere::RMAX_ID(), + ModelAPI_AttributeDouble, /** The maximum radius*/, + phimin, PrimitivesPlugin_Sphere::PHIMIN_ID(), + ModelAPI_AttributeDouble, /** The minimum phi*/, + phimax, PrimitivesPlugin_Sphere::PHIMAX_ID(), + ModelAPI_AttributeDouble, /** The maximum phi*/, + thetamin, PrimitivesPlugin_Sphere::THETAMIN_ID(), + ModelAPI_AttributeDouble, /** The minimum theta*/, + thetamax,PrimitivesPlugin_Sphere::THETAMAX_ID(), + ModelAPI_AttributeDouble, /** The maximum theta*/) /// Set center point PRIMITIVESAPI_EXPORT @@ -68,6 +92,18 @@ public: PRIMITIVESAPI_EXPORT void setRadius(const ModelHighAPI_Double& theRadius); + /// Set minimum 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; @@ -89,4 +125,15 @@ PRIMITIVESAPI_EXPORT SpherePtr addSphere(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius); +/// \ingroup CPPHighAPI +/// \brief Create primitive Sphere feature. +PRIMITIVESAPI_EXPORT +SpherePtr addSphere(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& thePhiMin, + const ModelHighAPI_Double& thePhiMax, + const ModelHighAPI_Double& theThetaMin, + const ModelHighAPI_Double& theThetaMax); + #endif // PRIMITIVESAPI_SPHERE_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_Torus.h b/src/PrimitivesAPI/PrimitivesAPI_Torus.h index b460da826..9a65372a1 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Torus.h +++ b/src/PrimitivesAPI/PrimitivesAPI_Torus.h @@ -36,7 +36,7 @@ class ModelHighAPI_Selection; /// \class PrimitivesAPI_Torus /// \ingroup CPPHighAPI -/// \brief Interface for primitive Cone feature. +/// \brief Interface for primitive Torus feature. class PrimitivesAPI_Torus: public ModelHighAPI_Interface { public: @@ -76,11 +76,11 @@ public: virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; -/// Pointer on primitive Cone object +/// Pointer on primitive Torus object typedef std::shared_ptr TorusPtr; /// \ingroup CPPHighAPI -/// \brief Create primitive Cone feature. +/// \brief Create primitive Torus feature. PRIMITIVESAPI_EXPORT TorusPtr addTorus(const std::shared_ptr& thePart, const ModelHighAPI_Selection& theBasePoint, @@ -89,7 +89,7 @@ TorusPtr addTorus(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRingRadius); /// \ingroup CPPHighAPI -/// \brief Create primitive Cone feature. +/// \brief Create primitive Torus feature. PRIMITIVESAPI_EXPORT TorusPtr addTorus(const std::shared_ptr& thePart, const ModelHighAPI_Double& theRadius, diff --git a/src/PrimitivesAPI/PrimitivesAPI_Tube.cpp b/src/PrimitivesAPI/PrimitivesAPI_Tube.cpp new file mode 100644 index 000000000..8bdd639f5 --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Tube.cpp @@ -0,0 +1,91 @@ +// Copyright (C) 2017-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "PrimitivesAPI_Tube.h" + +#include +#include + +//================================================================================================== +PrimitivesAPI_Tube::PrimitivesAPI_Tube(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +PrimitivesAPI_Tube::PrimitivesAPI_Tube(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theHeight) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(theRMin, rmin()); + fillAttribute(theRMax, rmax()); + setHeight(theHeight); + } +} + +//================================================================================================== +PrimitivesAPI_Tube::~PrimitivesAPI_Tube() +{ +} + +//================================================================================================== +void PrimitivesAPI_Tube::setRadius(const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax) +{ + fillAttribute(theRMin, rmin()); + fillAttribute(theRMax, rmax()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Tube::setHeight(const ModelHighAPI_Double& theHeight) +{ + fillAttribute(theHeight, height()); + execute(); +} + +//================================================================================================== +void PrimitivesAPI_Tube::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + theDumper << aBase << " = model.addTube(" << aDocName; + + AttributeDoublePtr anAttrRMin = aBase->real(PrimitivesPlugin_Tube::RMIN_ID()); + AttributeDoublePtr anAttrRMax = aBase->real(PrimitivesPlugin_Tube::RMAX_ID()); + AttributeDoublePtr anAttrHeight = aBase->real(PrimitivesPlugin_Tube::HEIGHT_ID()); + theDumper << ", " << anAttrRMin << ", " << anAttrRMax << ", " << anAttrHeight; + + theDumper << ")" << std::endl; +} + +//================================================================================================== +TubePtr addTube(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theHeight) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Tube::ID()); + return TubePtr(new PrimitivesAPI_Tube(aFeature, theRMin, theRMax, theHeight)); +} diff --git a/src/PrimitivesAPI/PrimitivesAPI_Tube.h b/src/PrimitivesAPI/PrimitivesAPI_Tube.h new file mode 100644 index 000000000..dd582b18f --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Tube.h @@ -0,0 +1,86 @@ +// Copyright (C) 2017-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef PRIMITIVESAPI_TUBE_H_ +#define PRIMITIVESAPI_TUBE_H_ + +#include "PrimitivesAPI.h" + +#include + +#include +#include +#include + + +/// \class PrimitivesAPI_Tube +/// \ingroup CPPHighAPI +/// \brief Interface for primitive Tube feature. +class PrimitivesAPI_Tube: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Tube(const std::shared_ptr& theFeature); + + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Tube(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theHeight); + + /// Destructor. + PRIMITIVESAPI_EXPORT + virtual ~PrimitivesAPI_Tube(); + + INTERFACE_3(PrimitivesPlugin_Tube::ID(), + rmin, PrimitivesPlugin_Tube::RMIN_ID(), + ModelAPI_AttributeDouble, /** Inner radius */, + rmax, PrimitivesPlugin_Tube::RMAX_ID(), + ModelAPI_AttributeDouble, /** Outer radius */, + height, PrimitivesPlugin_Tube::HEIGHT_ID(), + ModelAPI_AttributeDouble, /** Height */) + + /// Set radius + PRIMITIVESAPI_EXPORT + void setRadius(const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax); + + /// Set height + PRIMITIVESAPI_EXPORT + void setHeight(const ModelHighAPI_Double& theHeight); + + /// Dump wrapped feature + PRIMITIVESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on primitive Tube object +typedef std::shared_ptr TubePtr; + +/// \ingroup CPPHighAPI +/// \brief Create primitive Tube feature. +PRIMITIVESAPI_EXPORT +TubePtr addTube(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theHeight); + +#endif // PRIMITIVESAPI_TUBE_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_swig.h b/src/PrimitivesAPI/PrimitivesAPI_swig.h index 21934d3a0..7473a911b 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_swig.h +++ b/src/PrimitivesAPI/PrimitivesAPI_swig.h @@ -28,5 +28,6 @@ #include "PrimitivesAPI_Cylinder.h" #include "PrimitivesAPI_Sphere.h" #include "PrimitivesAPI_Torus.h" + #include "PrimitivesAPI_Tube.h" #endif // PRIMITIVESAPI_SWIG_H_ diff --git a/src/PrimitivesPlugin/CMakeLists.txt b/src/PrimitivesPlugin/CMakeLists.txt index 4504f17ee..9c0272d14 100644 --- a/src/PrimitivesPlugin/CMakeLists.txt +++ b/src/PrimitivesPlugin/CMakeLists.txt @@ -25,6 +25,7 @@ SET(PROJECT_HEADERS PrimitivesPlugin_Cylinder.h PrimitivesPlugin_Sphere.h PrimitivesPlugin_Torus.h + PrimitivesPlugin_Tube.h ) SET(PROJECT_SOURCES @@ -34,6 +35,7 @@ SET(PROJECT_SOURCES PrimitivesPlugin_Cylinder.cpp PrimitivesPlugin_Sphere.cpp PrimitivesPlugin_Torus.cpp + PrimitivesPlugin_Tube.cpp ) SET(XML_RESOURCES @@ -43,6 +45,7 @@ SET(XML_RESOURCES cylinder_widget.xml sphere_widget.xml torus_widget.xml + tube_widget.xml ) SET(TEXT_RESOURCES diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp index 30caf171d..feea6763d 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp @@ -40,14 +40,24 @@ 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 252cf52f3..6d2b64095 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.h @@ -31,8 +31,9 @@ class ModelAPI_ResultBody; * \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 + * 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. */ class PrimitivesPlugin_Box : public ModelAPI_Feature @@ -66,6 +67,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() { @@ -101,6 +109,48 @@ class PrimitivesPlugin_Box : public ModelAPI_Feature 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_OX_ID("ox"); + return MY_OX_ID; + } + + /// Attribute name of the second coordinate of the center + inline static const std::string& OY_ID() + { + static const std::string MY_OY_ID("oy"); + return MY_OY_ID; + } + + /// Attribute name of the third coordinate of the center + 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 on X axis + 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 on Y axis + 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 on Z axis + 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() { @@ -128,6 +178,9 @@ class PrimitivesPlugin_Box : public ModelAPI_Feature ///Perform the creation of the box using three cordinates void createBoxByDimensions(); + ///Perform the creation of the box using a center and three half-lenths + void createBoxByOnePointAndDims(); + }; diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp index 876f4dd9a..5a2481133 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Plugin.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -52,6 +53,8 @@ FeaturePtr PrimitivesPlugin_Plugin::createFeature(std::string theFeatureID) return FeaturePtr(new PrimitivesPlugin_Sphere); } else if (theFeatureID == PrimitivesPlugin_Torus::ID()) { return FeaturePtr(new PrimitivesPlugin_Torus); + } else if (theFeatureID == PrimitivesPlugin_Tube::ID()) { + return FeaturePtr(new PrimitivesPlugin_Tube); } // feature of such kind is not found return FeaturePtr(); diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp index 00ca224b0..f6da4b6cb 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp @@ -17,7 +17,7 @@ // 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) @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -43,6 +44,10 @@ PrimitivesPlugin_Sphere::PrimitivesPlugin_Sphere() //================================================================================================= void PrimitivesPlugin_Sphere::initAttributes() { + data()->addAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD(), + ModelAPI_AttributeString::typeId()); + + // data for the first mode : by a point and a radius data()->addAttribute(PrimitivesPlugin_Sphere::CENTER_POINT_ID(), ModelAPI_AttributeSelection::typeId()); @@ -60,10 +65,32 @@ void PrimitivesPlugin_Sphere::initAttributes() aCenterPoint->setValue(aPointRes, std::shared_ptr()); } } + + // data for the second mode : by dimensions + data()->addAttribute(PrimitivesPlugin_Sphere::RMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::RMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::PHIMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::PHIMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::THETAMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Sphere::THETAMAX_ID(), ModelAPI_AttributeDouble::typeId()); } //================================================================================================= void PrimitivesPlugin_Sphere::execute() +{ + AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Sphere::CREATION_METHOD()); + std::string aMethodType = aMethodTypeAttr->value(); + + if (aMethodType == CREATION_METHOD_BY_PT_RADIUS()) + createSphereByPtRadius(); + + if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) + createShereByDimensions(); +} + + +//================================================================================================= +void PrimitivesPlugin_Sphere::createSphereByPtRadius() { // Getting point. std::shared_ptr aCenterPoint; @@ -95,7 +122,7 @@ void PrimitivesPlugin_Sphere::execute() // 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; @@ -111,6 +138,48 @@ void PrimitivesPlugin_Sphere::execute() setResult(aResultBox, aResultIndex); } +//================================================================================================= +void PrimitivesPlugin_Sphere::createShereByDimensions() +{ + // Getting rmin, rmax, phimin, phimax, thetamin et thetamax + double aRMin = real(PrimitivesPlugin_Sphere::RMIN_ID())->value(); + double aRMax = real(PrimitivesPlugin_Sphere::RMAX_ID())->value(); + double aPhiMin = real(PrimitivesPlugin_Sphere::PHIMIN_ID())->value(); + double aPhiMax = real(PrimitivesPlugin_Sphere::PHIMAX_ID())->value(); + double aThetaMin = real(PrimitivesPlugin_Sphere::THETAMIN_ID())->value(); + double aThetaMax = real(PrimitivesPlugin_Sphere::THETAMAX_ID())->value(); + + std::shared_ptr aSphereAlgo = std::shared_ptr( + new GeomAlgoAPI_Sphere(aRMin, aRMax, aPhiMin, aPhiMax, aThetaMin, aThetaMax)); + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aSphereAlgo->check()) { + setError(aSphereAlgo->getError()); + return; + } + + // Build the 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 theSphereAlgo, std::shared_ptr theResultSphere) diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h index 2f00e989e..2e54765cd 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h @@ -30,9 +30,10 @@ /**\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 { @@ -44,6 +45,27 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature return MY_SPHERE_ID; } + /// Attribute name for creation method + inline static const std::string& CREATION_METHOD() + { + static const std::string MY_CREATION_METHOD_ID("CreationMethod"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method + inline static const std::string& CREATION_METHOD_BY_PT_RADIUS() + { + static const std::string MY_CREATION_METHOD_ID("SphereByPointRadius"); + return MY_CREATION_METHOD_ID; + } + + /// Attribute name for creation method + inline static const std::string& CREATION_METHOD_BY_DIMENSIONS() + { + static const std::string MY_CREATION_METHOD_ID("SphereByDimensions"); + return MY_CREATION_METHOD_ID; + } + /// Attribute name of the base point inline static const std::string& CENTER_POINT_ID() { @@ -58,6 +80,48 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature 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() { @@ -79,6 +143,13 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature void loadNamingDS(std::shared_ptr theSphereAlgo, std::shared_ptr 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(); + }; #endif // PRIMITIVESPLUGIN_SPHERE_H_ diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Tube.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Tube.cpp new file mode 100644 index 000000000..d9a90d9ff --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Tube.cpp @@ -0,0 +1,78 @@ +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include + +#include +#include + +//================================================================================================= +PrimitivesPlugin_Tube::PrimitivesPlugin_Tube() // Nothing to do during instantiation +{ +} + +//================================================================================================= +void PrimitivesPlugin_Tube::initAttributes() +{ + data()->addAttribute(PrimitivesPlugin_Tube::RMIN_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Tube::RMAX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(PrimitivesPlugin_Tube::HEIGHT_ID(), ModelAPI_AttributeDouble::typeId()); +} + +//================================================================================================= +void PrimitivesPlugin_Tube::execute() +{ + double aRMin = real(PrimitivesPlugin_Tube::RMIN_ID())->value(); + double aRMax = real(PrimitivesPlugin_Tube::RMAX_ID())->value(); + double aZ = real(PrimitivesPlugin_Tube::HEIGHT_ID())->value(); + + std::shared_ptr aTubeAlgo(new GeomAlgoAPI_Tube(aRMin,aRMax,aZ)); + + // These checks should be made to the GUI for the feature but + // the corresponding validator does not exist yet. + if (!aTubeAlgo->check()) { + setError(aTubeAlgo->getError()); + return; + } + + // Build the tube + aTubeAlgo->build(); + + int aResultIndex = 0; + ResultBodyPtr aResultTube = document()->createBody(data(), aResultIndex); + loadNamingDS(aTubeAlgo, aResultTube); + setResult(aResultTube, aResultIndex); +} + +//================================================================================================= +void PrimitivesPlugin_Tube::loadNamingDS(std::shared_ptr theTubeAlgo, + std::shared_ptr theResultTube) +{ + // Load the result + theResultTube->store(theTubeAlgo->shape()); + + // Prepare the naming + theTubeAlgo->prepareNamingFaces(); + + // Insert to faces + int num = 1; + std::map< std::string, std::shared_ptr > listOfFaces = + theTubeAlgo->getCreatedFaces(); + for (std::map< std::string, std::shared_ptr >::iterator it = listOfFaces.begin(); + it != listOfFaces.end(); + ++it) + { + theResultTube->generated((*it).second, (*it).first); + } +} diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Tube.h b/src/PrimitivesPlugin/PrimitivesPlugin_Tube.h new file mode 100644 index 000000000..c3af279e1 --- /dev/null +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Tube.h @@ -0,0 +1,88 @@ +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef PrimitivesPlugin_Tube_H_ +#define PrimitivesPlugin_Tube_H_ + +#include +#include +#include + +/**\class PrimitivesPlugin_Tube + * \ingroup Plugins + * \brief Feature for creation of a tube primitive using various methods. + * + * Tube creates a tuboid - Holed cylinder. It can be built via two methods : + * using an inner raidus, an outer radius and a heigth or radii (inner and outer) + * and angles. + */ +class PrimitivesPlugin_Tube : public ModelAPI_Feature +{ + public: + /// Tube kind + inline static const std::string& ID() + { + static const std::string MY_TUBE_ID("Tube"); + return MY_TUBE_ID; + } + + /// Attrinute name of the inner radius + inline static const std::string& RMIN_ID() + { + static const std::string MY_RMIN_ID("rmin"); + return MY_RMIN_ID; + } + + /// Attrinute name of the outer radius + inline static const std::string& RMAX_ID() + { + static const std::string MY_RMAX_ID("rmax"); + return MY_RMAX_ID; + } + + /// Attrinute name of the height + inline static const std::string& HEIGHT_ID() + { + static const std::string MY_HEIGHT_ID("height"); + return MY_HEIGHT_ID; + } + + /// Returns the kind of a feature + PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = PrimitivesPlugin_Tube::ID(); + return MY_KIND; + } + + /// Performs the algorithm and stores results it in the data structure + PRIMITIVESPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + PRIMITIVESPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation. + PrimitivesPlugin_Tube(); + + private: + /// Load naming data structure of the feature to the document + void loadNamingDS(std::shared_ptr theTubeAlgo, + std::shared_ptr theResultBox); +}; + +#endif diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_msg_fr.ts b/src/PrimitivesPlugin/PrimitivesPlugin_msg_fr.ts index 22d0de57f..a046099c6 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_msg_fr.ts +++ b/src/PrimitivesPlugin/PrimitivesPlugin_msg_fr.ts @@ -28,6 +28,10 @@ Torus Tore + + Tube + Tube + @@ -51,6 +55,10 @@ By two points Par deux points + + By one point and dimensions + Par un point et des dimensions + Box:FirstPoint @@ -121,6 +129,72 @@ Dimension en Z + + Box:ox + + OX + OX + + + Enter the coordinate X for the center + Entrez la coodonnée en X du centre + + + + Box:oy + + OY + OY + + + Enter the coordinate Y for the center + Entrez la coodonnée en Y du centre + + + + Box:oz + + OZ + OZ + + + Enter the coordinate Z for the center + Entrez la coodonnée en Z du centre + + + + Box:half_dx + + DX + DX + + + Enter the half length in X + Entrez la demi-longueur en X + + + + Box:half_dy + + DY + DY + + + Enter the half length in Y + Entrez la demi-longueur en Y + + + + Box:half_dz + + DZ + DZ + + + Enter the half length in Z + Entrez la demi-longueur en Z + + Cone @@ -313,6 +387,25 @@ Sphere Sphère + + Dimensions + Dimensions + + + Phi/theta range + Intervalles pour Phi/Theta + + + + Sphere:CreationMethod + + By point and radius + Par un centre et un rayon + + + By dimensions + Par dimensions + Sphere:center_point @@ -340,6 +433,72 @@ Rayon + + Sphere:rmin + + Enter the inner radius + Entrez le rayon interne + + + rmin + Rmin + + + + Sphere:rmax + + Enter the outer radius + Entrez le rayon externe + + + rmax + Rmax + + + + Sphere:phimin + + Enter the azimuthal starting angle + Entrez l'angle azimutal de départ + + + phimin + Phi min + + + + Sphere:phimax + + Enter the azimuthal revolution angle + Entrez l'angle azimutal de révolution + + + phimax + Phi max + + + + Sphere:thetamin + + Enter the polar starting angle + Entrez l'angle polaire de départ + + + thetamin + Theta min + + + + Sphere:thetamax + + Enter the polar revolution angle + Entrez l'angle polaire de révolution + + + thetamax + Theta max + + Torus @@ -405,4 +564,46 @@ + + Tube + + Create a Tube + + Créer un tube + + + + Tube:rmin + + Enter the inner radius + Entrez le rayon interne + + + rmin + rmin + + + + Tube:rmax + + Enter the outer radius + Entrez le rayon externe + + + rmax + rmax + + + + Tube:height + + Enter the height + Entrez la hauteur + + + height + height + + + diff --git a/src/PrimitivesPlugin/box_widget.xml b/src/PrimitivesPlugin/box_widget.xml index f968b5154..23ac51326 100644 --- a/src/PrimitivesPlugin/box_widget.xml +++ b/src/PrimitivesPlugin/box_widget.xml @@ -40,5 +40,56 @@ shape_types="vertex"> + + + + + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/doc/PrimitivesPlugin.rst b/src/PrimitivesPlugin/doc/PrimitivesPlugin.rst index 364373d00..02e0b8702 100644 --- a/src/PrimitivesPlugin/doc/PrimitivesPlugin.rst +++ b/src/PrimitivesPlugin/doc/PrimitivesPlugin.rst @@ -15,3 +15,4 @@ The Primitives plug-in contains features for creation of geometrical primitives. cylinderFeature.rst sphereFeature.rst torusFeature.rst + tubeFeature.rst 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/TUI_coneFeature.rst b/src/PrimitivesPlugin/doc/TUI_coneFeature.rst index aa95fa132..4c5b3ffdc 100644 --- a/src/PrimitivesPlugin/doc/TUI_coneFeature.rst +++ b/src/PrimitivesPlugin/doc/TUI_coneFeature.rst @@ -1,8 +1,8 @@ .. _tui_create_cone: -Create / Cone -============= +Create Cone +=========== .. literalinclude:: examples/cone.py :linenos: diff --git a/src/PrimitivesPlugin/doc/TUI_cylinderFeature.rst b/src/PrimitivesPlugin/doc/TUI_cylinderFeature.rst index dc326819c..bb9030e53 100644 --- a/src/PrimitivesPlugin/doc/TUI_cylinderFeature.rst +++ b/src/PrimitivesPlugin/doc/TUI_cylinderFeature.rst @@ -1,8 +1,8 @@ .. _tui_create_cylinder: -Create cylinder -================ +Create Cylinder +=============== .. literalinclude:: examples/cylinder1.py :linenos: diff --git a/src/PrimitivesPlugin/doc/TUI_cylinderPortion.rst b/src/PrimitivesPlugin/doc/TUI_cylinderPortion.rst index 8d2bad8fb..5014c936d 100644 --- a/src/PrimitivesPlugin/doc/TUI_cylinderPortion.rst +++ b/src/PrimitivesPlugin/doc/TUI_cylinderPortion.rst @@ -1,7 +1,7 @@ .. _tui_create_cylportion: -Create portion of cylinder +Create Portion of cylinder ========================== .. literalinclude:: examples/cylinder2.py diff --git a/src/PrimitivesPlugin/doc/TUI_sphereFeature.rst b/src/PrimitivesPlugin/doc/TUI_sphereFeature.rst index f4012bcce..45a63db54 100644 --- a/src/PrimitivesPlugin/doc/TUI_sphereFeature.rst +++ b/src/PrimitivesPlugin/doc/TUI_sphereFeature.rst @@ -1,12 +1,11 @@ .. _tui_create_sphere: -Create / Sphere -=============== +Create Sphere +============= -.. literalinclude:: examples/sphere.py +.. literalinclude:: examples/sphere1.py :linenos: :language: python -:download:`Download this script ` - +:download:`Download this script ` diff --git a/src/PrimitivesPlugin/doc/TUI_spherePart.rst b/src/PrimitivesPlugin/doc/TUI_spherePart.rst new file mode 100644 index 000000000..56b3447b4 --- /dev/null +++ b/src/PrimitivesPlugin/doc/TUI_spherePart.rst @@ -0,0 +1,11 @@ + + .. _tui_create_part_sphere: + +Create Part of sphere +===================== + +.. literalinclude:: examples/sphere2.py + :linenos: + :language: python + +:download:`Download this script ` diff --git a/src/PrimitivesPlugin/doc/TUI_torusFeature.rst b/src/PrimitivesPlugin/doc/TUI_torusFeature.rst index 5c4a63261..07a422740 100644 --- a/src/PrimitivesPlugin/doc/TUI_torusFeature.rst +++ b/src/PrimitivesPlugin/doc/TUI_torusFeature.rst @@ -1,8 +1,8 @@ .. _tui_create_torus: -Create / Torus -============== +Create Torus +============ .. literalinclude:: examples/torus.py :linenos: diff --git a/src/PrimitivesPlugin/doc/TUI_tubeFeature.rst b/src/PrimitivesPlugin/doc/TUI_tubeFeature.rst new file mode 100644 index 000000000..551c85415 --- /dev/null +++ b/src/PrimitivesPlugin/doc/TUI_tubeFeature.rst @@ -0,0 +1,12 @@ + + .. _tui_create_tube: + +Create Tube +=========== + +.. literalinclude:: examples/tube.py + :linenos: + :language: python + +:download:`Download this script ` + diff --git a/src/PrimitivesPlugin/doc/boxFeature.rst b/src/PrimitivesPlugin/doc/boxFeature.rst index 759fc9eb8..e91466c20 100644 --- a/src/PrimitivesPlugin/doc/boxFeature.rst +++ b/src/PrimitivesPlugin/doc/boxFeature.rst @@ -1,18 +1,16 @@ -.. _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 2 algorithms for creation of a Box: +There are 3 algorithms for creation of a Box: .. figure:: images/box_dxyz_32x32.png :align: left @@ -26,6 +24,12 @@ There are 2 algorithms for creation of a Box: **By two points** +.. figure:: images/box_pt_dxyz_32x32.png + :align: left + :height: 24px + +**By coordinates of a point and dimensions** + -------------------------------------------------------------------------------- By dimensions @@ -81,8 +85,6 @@ Input fields: :param object: Second vertex of diagonal. :return: Result object. -**Arguments**: Part + 2 selected points (opposite vertices of the box) - Result """""" @@ -94,3 +96,41 @@ 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). + +.. figure:: 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. + +.. figure:: images/Box3.png + :align: center + + Created boxes + +**See Also** a sample TUI Script of :ref:`tui_create_boxptdim` operation. 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/examples/sphere.py b/src/PrimitivesPlugin/doc/examples/sphere.py deleted file mode 100644 index 05320ce31..000000000 --- a/src/PrimitivesPlugin/doc/examples/sphere.py +++ /dev/null @@ -1,9 +0,0 @@ -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() diff --git a/src/PrimitivesPlugin/doc/examples/sphere1.py b/src/PrimitivesPlugin/doc/examples/sphere1.py new file mode 100644 index 000000000..05320ce31 --- /dev/null +++ b/src/PrimitivesPlugin/doc/examples/sphere1.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() +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10) +model.do() +model.end() diff --git a/src/PrimitivesPlugin/doc/examples/sphere2.py b/src/PrimitivesPlugin/doc/examples/sphere2.py new file mode 100644 index 000000000..81f469ea2 --- /dev/null +++ b/src/PrimitivesPlugin/doc/examples/sphere2.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() +Sphere_1 = model.addSphere(Part_1_doc,5,10,180,245,0,90) +model.do() +model.end() diff --git a/src/PrimitivesPlugin/doc/examples/tube.py b/src/PrimitivesPlugin/doc/examples/tube.py new file mode 100644 index 000000000..99567f94a --- /dev/null +++ b/src/PrimitivesPlugin/doc/examples/tube.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() +Torus_1 = model.addTube(Part_1_doc, 3, 5, 12) +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/doc/images/Box_ptAndDims.png b/src/PrimitivesPlugin/doc/images/Box_ptAndDims.png new file mode 100644 index 000000000..3fedaf7df Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Box_ptAndDims.png differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere.png b/src/PrimitivesPlugin/doc/images/Sphere.png deleted file mode 100644 index a507c8afe..000000000 Binary files a/src/PrimitivesPlugin/doc/images/Sphere.png and /dev/null differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere1.png b/src/PrimitivesPlugin/doc/images/Sphere1.png new file mode 100644 index 000000000..87214a713 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Sphere1.png differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere2.png b/src/PrimitivesPlugin/doc/images/Sphere2.png new file mode 100644 index 000000000..b2ad67a62 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Sphere2.png differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere_button.png b/src/PrimitivesPlugin/doc/images/Sphere_button.png index fb13d34b0..add03e29a 100644 Binary files a/src/PrimitivesPlugin/doc/images/Sphere_button.png and b/src/PrimitivesPlugin/doc/images/Sphere_button.png differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere_full.png b/src/PrimitivesPlugin/doc/images/Sphere_full.png new file mode 100644 index 000000000..4b5351b9d Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Sphere_full.png differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere_part.png b/src/PrimitivesPlugin/doc/images/Sphere_part.png new file mode 100644 index 000000000..15007d69d Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Sphere_part.png differ diff --git a/src/PrimitivesPlugin/doc/images/Sphere_res.png b/src/PrimitivesPlugin/doc/images/Sphere_res.png deleted file mode 100644 index 1ffba02ec..000000000 Binary files a/src/PrimitivesPlugin/doc/images/Sphere_res.png and /dev/null differ diff --git a/src/PrimitivesPlugin/doc/images/Tube.png b/src/PrimitivesPlugin/doc/images/Tube.png new file mode 100644 index 000000000..314d232d9 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Tube.png differ diff --git a/src/PrimitivesPlugin/doc/images/Tube_button.png b/src/PrimitivesPlugin/doc/images/Tube_button.png new file mode 100755 index 000000000..26db05d57 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Tube_button.png differ diff --git a/src/PrimitivesPlugin/doc/images/Tube_res.png b/src/PrimitivesPlugin/doc/images/Tube_res.png new file mode 100644 index 000000000..69adee651 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/Tube_res.png differ diff --git a/src/PrimitivesPlugin/doc/images/box.png b/src/PrimitivesPlugin/doc/images/box.png deleted file mode 100644 index 2b0757b05..000000000 Binary files a/src/PrimitivesPlugin/doc/images/box.png and /dev/null differ diff --git a/src/PrimitivesPlugin/doc/images/box_pt_dxyz_32x32.png b/src/PrimitivesPlugin/doc/images/box_pt_dxyz_32x32.png new file mode 100644 index 000000000..db199ea7b Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/box_pt_dxyz_32x32.png differ diff --git a/src/PrimitivesPlugin/doc/images/sphere_32x32.png b/src/PrimitivesPlugin/doc/images/sphere_32x32.png new file mode 100644 index 000000000..18dc864b2 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/sphere_32x32.png differ diff --git a/src/PrimitivesPlugin/doc/images/sphere_part_32x32.png b/src/PrimitivesPlugin/doc/images/sphere_part_32x32.png new file mode 100644 index 000000000..c74269ac0 Binary files /dev/null and b/src/PrimitivesPlugin/doc/images/sphere_part_32x32.png differ diff --git a/src/PrimitivesPlugin/doc/sphereFeature.rst b/src/PrimitivesPlugin/doc/sphereFeature.rst index 71688a999..ade524999 100644 --- a/src/PrimitivesPlugin/doc/sphereFeature.rst +++ b/src/PrimitivesPlugin/doc/sphereFeature.rst @@ -3,29 +3,46 @@ 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. @@ -34,11 +51,52 @@ Input fields: 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. + + + diff --git a/src/PrimitivesPlugin/doc/tubeFeature.rst b/src/PrimitivesPlugin/doc/tubeFeature.rst new file mode 100644 index 000000000..feb2ac468 --- /dev/null +++ b/src/PrimitivesPlugin/doc/tubeFeature.rst @@ -0,0 +1,46 @@ +.. |Tube_button.icon| image:: images/Tube_button.png + +Tube +==== + +Tube feature creates a tube solid. + +To create a Tube in the active part: + +#. select in the Main Menu *Primitives - > Tube* item or +#. click |Tube_button.icon| **Tube** button in the toolbar + +The following property panel appears. + +.. figure:: images/Tube.png + :align: center + + Tube + +Input fields: + +- **rmin** defines the inner radius of the the tube; +- **rmax** defines the outer radius of the the tube; +- **height** defines the height of the the tube; + +**TUI Command**: + +.. py:function:: model.addTube(Part_doc, rmin, rmax, height) + + :param part: The current part object. + :param real: rmin. + :param real: rmax. + :param real: height. + :return: Result object. + +Result +"""""" + +An example is shown below. + +.. figure:: images/Tube_res.png + :align: center + + Tube created + +**See Also** a sample TUI Script of :ref:`tui_create_tube` operation. 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 diff --git a/src/PrimitivesPlugin/icons/sphere.png b/src/PrimitivesPlugin/icons/sphere.png index 000d658ab..add03e29a 100644 Binary files a/src/PrimitivesPlugin/icons/sphere.png and b/src/PrimitivesPlugin/icons/sphere.png differ diff --git a/src/PrimitivesPlugin/icons/sphere_32x32.png b/src/PrimitivesPlugin/icons/sphere_32x32.png new file mode 100755 index 000000000..18dc864b2 Binary files /dev/null and b/src/PrimitivesPlugin/icons/sphere_32x32.png differ diff --git a/src/PrimitivesPlugin/icons/sphere_part_32x32.png b/src/PrimitivesPlugin/icons/sphere_part_32x32.png new file mode 100755 index 000000000..c74269ac0 Binary files /dev/null and b/src/PrimitivesPlugin/icons/sphere_part_32x32.png differ diff --git a/src/PrimitivesPlugin/icons/tube.png b/src/PrimitivesPlugin/icons/tube.png new file mode 100755 index 000000000..26db05d57 Binary files /dev/null and b/src/PrimitivesPlugin/icons/tube.png differ diff --git a/src/PrimitivesPlugin/plugin-Primitives.xml b/src/PrimitivesPlugin/plugin-Primitives.xml index f250b587e..f743fef21 100644 --- a/src/PrimitivesPlugin/plugin-Primitives.xml +++ b/src/PrimitivesPlugin/plugin-Primitives.xml @@ -30,5 +30,11 @@ + + + + + diff --git a/src/PrimitivesPlugin/sphere_widget.xml b/src/PrimitivesPlugin/sphere_widget.xml index d2f29ce1e..389d8c5bc 100644 --- a/src/PrimitivesPlugin/sphere_widget.xml +++ b/src/PrimitivesPlugin/sphere_widget.xml @@ -1,15 +1,65 @@ - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/tube_widget.xml b/src/PrimitivesPlugin/tube_widget.xml new file mode 100644 index 000000000..4fc429339 --- /dev/null +++ b/src/PrimitivesPlugin/tube_widget.xml @@ -0,0 +1,26 @@ + + + + + + + + diff --git a/src/PythonAPI/model/primitives/__init__.py b/src/PythonAPI/model/primitives/__init__.py index 6e2110eca..3c2e74901 100644 --- a/src/PythonAPI/model/primitives/__init__.py +++ b/src/PythonAPI/model/primitives/__init__.py @@ -19,4 +19,4 @@ """Package for Primitives plugin for the Parametric Geometry API of the Modeler. """ -from PrimitivesAPI import addBox, addCone, addCylinder, addSphere, addTorus +from PrimitivesAPI import addBox, addCone, addCylinder, addSphere, addTorus, addTube diff --git a/test.API/SHAPER/Primitives/TestAPI_Box.py b/test.API/SHAPER/Primitives/TestAPI_Box.py index f4711ed19..856192817 100644 --- a/test.API/SHAPER/Primitives/TestAPI_Box.py +++ b/test.API/SHAPER/Primitives/TestAPI_Box.py @@ -62,32 +62,32 @@ Box_8 = shaperpy.makeBox(pnt1,pnt2) 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.") diff --git a/test.API/SHAPER/Primitives/TestBox.py b/test.API/SHAPER/Primitives/TestBox.py index 7d228addc..c3c58a2fe 100644 --- a/test.API/SHAPER/Primitives/TestBox.py +++ b/test.API/SHAPER/Primitives/TestBox.py @@ -84,6 +84,7 @@ Box_15 = model.addBox(Part_1_doc, model.selection("VERTEX", "Sketch_1/SketchLine 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() @@ -126,6 +127,12 @@ model.testNbSubShapes(Box_18, GeomAPI_Shape.SOLID, [1]) 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.") @@ -145,16 +152,16 @@ model.testNbResults(Box_7, 0) 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.") diff --git a/test.API/SHAPER/Primitives/TestSphere.py b/test.API/SHAPER/Primitives/TestSphere.py index 33782eadb..36a820856 100644 --- a/test.API/SHAPER/Primitives/TestSphere.py +++ b/test.API/SHAPER/Primitives/TestSphere.py @@ -41,6 +41,9 @@ Sphere_6 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin 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() @@ -71,6 +74,12 @@ model.testNbSubShapes(Sphere_7, GeomAPI_Shape.SOLID, [1]) 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.") @@ -79,3 +88,6 @@ assert(Sphere_3.feature().error() == "Sphere builder :: radius is negative or nu 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.") diff --git a/test.API/SHAPER/Primitives/TestTube.py b/test.API/SHAPER/Primitives/TestTube.py new file mode 100644 index 000000000..b170cc4c0 --- /dev/null +++ b/test.API/SHAPER/Primitives/TestTube.py @@ -0,0 +1,66 @@ +# Copyright (C) 2017-2021 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +# Parameters +model.addParameter(Part_1_doc, "rmin", "10") +model.addParameter(Part_1_doc, "rmax", "12") +model.addParameter(Part_1_doc, "h", "20.5") + +# Tests +Tube_1 = model.addTube(Part_1_doc, 3, 5, 12) +Tube_2 = model.addTube(Part_1_doc, "rmin", "rmax", "h") +Tube_3 = model.addTube(Part_1_doc, 5, 3, 12) +Tube_4 = model.addTube(Part_1_doc, -2.5, 5, 12) +Tube_5 = model.addTube(Part_1_doc, 3, 5, -10) + +model.do() +model.end() + +# Checks +from GeomAPI import GeomAPI_Shape + +model.testNbResults(Tube_1, 1) +model.testNbSubResults(Tube_1, [0]) +model.testNbSubShapes(Tube_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Tube_1, GeomAPI_Shape.FACE, [4]) +model.testHaveNamingFaces(Tube_1, model, Part_1_doc) + +model.testNbResults(Tube_2, 1) +model.testNbSubResults(Tube_2, [0]) +model.testNbSubShapes(Tube_2, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Tube_2, GeomAPI_Shape.FACE, [4]) +model.testHaveNamingFaces(Tube_2, model, Part_1_doc) + +model.testNbResults(Tube_3, 0) +print(Tube_3.feature().error()) +assert(Tube_3.feature().error() == "Tube builder :: rmin is greater then or equal to rmax.") + +model.testNbResults(Tube_4, 0) +print(Tube_4.feature().error()) +assert(Tube_4.feature().error() == "Tube builder :: rmin is negative.") + +model.testNbResults(Tube_5, 0) +print(Tube_5.feature().error()) +assert(Tube_5.feature().error() == "Tube builder :: z is negative or null.") diff --git a/test.API/SHAPER/tests.set b/test.API/SHAPER/tests.set index d3bd600bd..b36fa9d9d 100644 --- a/test.API/SHAPER/tests.set +++ b/test.API/SHAPER/tests.set @@ -23,6 +23,7 @@ SET(TEST_NAMES Primitives/TestCylinder.py Primitives/TestSphere.py Primitives/TestTorus.py + Primitives/TestTube.py Primitives/TestAPI_Box.py Primitives/TestAPI_Cone.py Primitives/TestAPI_Cylinder.py