From: cg246364 Date: Wed, 21 Jul 2021 09:39:12 +0000 (+0200) Subject: Add a new primitive to create a tube with radii and height. X-Git-Tag: OPERA_v0.5-s990~1^2^2~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=868c6fd2baddaddc9e5d9a75c22491c561c01137;p=modules%2Fshaper.git Add a new primitive to create a tube with radii and height. --- diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 0c549a45b..4073754d5 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -91,6 +91,7 @@ SET(PROJECT_HEADERS GeomAlgoAPI_Chamfer.h GeomAlgoAPI_Defeaturing.h GeomAlgoAPI_BoundingBox.h + GeomAlgoAPI_Tube.h ) SET(PROJECT_SOURCES @@ -161,6 +162,7 @@ SET(PROJECT_SOURCES GeomAlgoAPI_Chamfer.cpp GeomAlgoAPI_Defeaturing.cpp GeomAlgoAPI_BoundingBox.cpp + GeomAlgoAPI_Tube.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp index 73ca13050..8a9a292ca 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Sphere.cpp @@ -80,7 +80,7 @@ bool GeomAlgoAPI_Sphere::check() void GeomAlgoAPI_Sphere::build() { myCreatedFaces.clear(); - + if (isSectionSphere) { buildSectionSphere(); } else { @@ -129,7 +129,8 @@ void GeomAlgoAPI_Sphere::buildSectionSphere() 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 + // 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); @@ -155,9 +156,11 @@ void GeomAlgoAPI_Sphere::buildSectionSphere() 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) + // 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; @@ -202,7 +205,9 @@ void GeomAlgoAPI_Sphere::buildSectionSphere() 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); + BRepPrimAPI_MakeRevol* aRevolBuilder = new BRepPrimAPI_MakeRevol(aFaceBuilder.Face(), aZAxis, + myPhiMax * M_PI / 180., + Standard_True); if(!aRevolBuilder) { return; myError = "Sphere builder :: section revolution did not succeed"; @@ -213,7 +218,8 @@ void GeomAlgoAPI_Sphere::buildSectionSphere() } // Get the shape, verify it, build a GeomAPI_Shape. - std::shared_ptr aResultShape = std::shared_ptr(new GeomAPI_Shape()) ; + std::shared_ptr aResultShape = + std::shared_ptr(new GeomAPI_Shape()); aResultShape->setImpl(new TopoDS_Shape(aRevolBuilder->Shape())); setShape(aResultShape); 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_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_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 26ed6511d..f6da4b6cb 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.cpp @@ -44,7 +44,8 @@ PrimitivesPlugin_Sphere::PrimitivesPlugin_Sphere() //================================================================================================= void PrimitivesPlugin_Sphere::initAttributes() { - data()->addAttribute(PrimitivesPlugin_Sphere::CREATION_METHOD(), ModelAPI_AttributeString::typeId()); + 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(), diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h index 348c1287c..2e54765cd 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Sphere.h @@ -79,42 +79,42 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature static const std::string MY_RADIUS_ID("radius"); return MY_RADIUS_ID; } - + /// attribute name of the inner radius inline static const std::string& RMIN_ID() { static const std::string MY_RMIN_ID("rmin"); return MY_RMIN_ID; } - + /// attribute name of the outer radius inline static const std::string& RMAX_ID() { static const std::string MY_RMAX_ID("rmax"); return MY_RMAX_ID; } - + /// attribute name of the lower phi limit inline static const std::string& PHIMIN_ID() { static const std::string MY_PHIMIN_ID("phimin"); return MY_PHIMIN_ID; } - + /// attribute name of the higher phi limit inline static const std::string& PHIMAX_ID() { static const std::string MY_PHIMAX_ID("phimax"); return MY_PHIMAX_ID; } - + /// attribute name of the lower theta limit inline static const std::string& THETAMIN_ID() { static const std::string MY_THETAMIN_ID("thetamin"); return MY_THETAMIN_ID; } - + /// attribute name of the higher theta limit inline static const std::string& THETAMAX_ID() { @@ -142,11 +142,12 @@ class PrimitivesPlugin_Sphere : public ModelAPI_Feature /// Load Naming data structure of the feature to the document 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) + + /// Perform the creation of the sphere using radii (inner and outer) and angle limits + /// (theta and phi) void createShereByDimensions(); }; 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 bcd5ba91a..23ac51326 100644 --- a/src/PrimitivesPlugin/box_widget.xml +++ b/src/PrimitivesPlugin/box_widget.xml @@ -47,21 +47,21 @@ label="OX" step="1." default="0." - tooltip="Enter the coordinate X for the origin"> + tooltip="Enter the coordinate X for the center"> + tooltip="Enter the coordinate Y for the center"> + tooltip="Enter the coordinate Z for the center"> 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_tubeFeature.rst b/src/PrimitivesPlugin/doc/TUI_tubeFeature.rst new file mode 100644 index 000000000..7b871a1e2 --- /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/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/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/Sphere_button.png b/src/PrimitivesPlugin/doc/images/Sphere_button.png index 000d658ab..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_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..3e274917c 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/sphere_32x32.png b/src/PrimitivesPlugin/doc/images/sphere_32x32.png index 484c384e8..18dc864b2 100644 Binary files a/src/PrimitivesPlugin/doc/images/sphere_32x32.png 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 index ce9c5856b..c74269ac0 100644 Binary files a/src/PrimitivesPlugin/doc/images/sphere_part_32x32.png and b/src/PrimitivesPlugin/doc/images/sphere_part_32x32.png differ 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/sphere.png b/src/PrimitivesPlugin/icons/sphere.png old mode 100644 new mode 100755 index 000d658ab..add03e29a 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 old mode 100644 new mode 100755 index 484c384e8..18dc864b2 Binary files a/src/PrimitivesPlugin/icons/sphere_32x32.png 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 old mode 100644 new mode 100755 index ce9c5856b..c74269ac0 Binary files a/src/PrimitivesPlugin/icons/sphere_part_32x32.png 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..3e274917c 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/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/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