From 1191f5ca0d2b19c0559f6209c606fecedecc4a6f Mon Sep 17 00:00:00 2001 From: cg246364 Date: Mon, 9 Nov 2020 08:29:12 +0100 Subject: [PATCH] Add Python API for tube --- src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp | 13 ++- src/PrimitivesAPI/CMakeLists.txt | 2 + src/PrimitivesAPI/PrimitivesAPI.i | 2 + src/PrimitivesAPI/PrimitivesAPI_Tube.cpp | 123 +++++++++++++++++++++ src/PrimitivesAPI/PrimitivesAPI_Tube.h | 103 +++++++++++++++++ src/PrimitivesAPI/PrimitivesAPI_swig.h | 1 + src/PythonAPI/model/primitives/__init__.py | 2 +- 7 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Tube.cpp create mode 100644 src/PrimitivesAPI/PrimitivesAPI_Tube.h diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp index 770c479df..067306603 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -153,7 +154,17 @@ std::shared_ptr GeomAlgoAPI_Tube::buildSimpleTube() // Construct the tube gp_Vec aVec(aNormal); - BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aFace, aVec * myZ); + gp_Trsf aTrsf; + aTrsf.SetTranslation(aVec * -myZ/2); + BRepBuilderAPI_Transform* aTransformBuilder = + new BRepBuilderAPI_Transform(aFace, aTrsf); + if (!aTransformBuilder || !aTransformBuilder->IsDone()) { + return; + } +// this->appendAlgo(std::shared_ptr( +// new GeomAlgoAPI_MakeShape(aTransformBuilder))); + TopoDS_Shape aMovedBase = aTransformBuilder->Shape(); + BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aVec * myZ); setImpl(aPrismBuilder); setBuilderType(OCCT_BRepBuilderAPI_MakeShape); diff --git a/src/PrimitivesAPI/CMakeLists.txt b/src/PrimitivesAPI/CMakeLists.txt index 53b860925..02db57262 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 f910ffefb..42541907b 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_Tube.cpp b/src/PrimitivesAPI/PrimitivesAPI_Tube.cpp new file mode 100644 index 000000000..8d9c044fc --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Tube.cpp @@ -0,0 +1,123 @@ +// Copyright (C) 2014-2019 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) +{ +} + +//================================================================================================== +PrimitivesAPI_Tube::PrimitivesAPI_Tube(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(PrimitivesPlugin_Tube::METHODE_SIMPLE_TUBE_ID(), creationMethod()); + fillAttribute(theRMin, rmin()); + fillAttribute(theRMax, rmax()); + fillAttribute(theZ, z()); + + execute(); + } +} + +//================================================================================================== +PrimitivesAPI_Tube::PrimitivesAPI_Tube(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ, + const ModelHighAPI_Double& theStartPhi, + const ModelHighAPI_Double& theDeltaPhi) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) { + fillAttribute(PrimitivesPlugin_Tube::METHODE_SEGMENT_TUBE_ID(), creationMethod()); + fillAttribute(theRMin, rmin()); + fillAttribute(theRMax, rmax()); + fillAttribute(theZ, z()); + fillAttribute(theStartPhi, startphi()); + fillAttribute(theDeltaPhi, deltaphi()); + + execute(); + } +} + +//================================================================================================== +PrimitivesAPI_Tube::~PrimitivesAPI_Tube() +{ +} + +//================================================================================================== +void PrimitivesAPI_Tube::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + theDumper << aBase << " = model.addTube(" << aDocName; + + std::string aCreationMethod = aBase->string(PrimitivesPlugin_Tube::CREATION_METHOD())->value(); + + if(aCreationMethod == PrimitivesPlugin_Tube::METHODE_SIMPLE_TUBE_ID()) { + AttributeDoublePtr anAttrRMin = aBase->real(PrimitivesPlugin_Tube::RMIN_ID()); + AttributeDoublePtr anAttrRMax = aBase->real(PrimitivesPlugin_Tube::RMAX_ID()); + AttributeDoublePtr anAttrZ = aBase->real(PrimitivesPlugin_Tube::Z_ID()); + theDumper << ", " << anAttrRMin << ", " << anAttrRMax << ", " << anAttrZ; + } else if (aCreationMethod == PrimitivesPlugin_Tube::METHODE_SEGMENT_TUBE_ID()) { + AttributeDoublePtr anAttrRMin = aBase->real(PrimitivesPlugin_Tube::RMIN_ID()); + AttributeDoublePtr anAttrRMax = aBase->real(PrimitivesPlugin_Tube::RMAX_ID()); + AttributeDoublePtr anAttrZ = aBase->real(PrimitivesPlugin_Tube::Z_ID()); + AttributeDoublePtr anAttrStartPhi = aBase->real(PrimitivesPlugin_Tube::START_PHI_ID()); + AttributeDoublePtr anAttrDeltaPhi = aBase->real(PrimitivesPlugin_Tube::DELTA_PHI_ID()); + theDumper << ", " << anAttrRMin << ", " << anAttrRMax << ", " << anAttrZ; + theDumper << ", " << anAttrStartPhi << ", " << anAttrDeltaPhi; + } + + theDumper << ")" << std::endl; +} + +//================================================================================================== +TubePtr addTube(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Tube::ID()); + return TubePtr(new PrimitivesAPI_Tube(aFeature, theRMin, theRMax, theZ)); +} + +//================================================================================================== +TubePtr addTube(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ, + const ModelHighAPI_Double& theStartPhi, + const ModelHighAPI_Double& theDeltaPhi) +{ + std::shared_ptr aFeature = thePart->addFeature(PrimitivesAPI_Tube::ID()); + return TubePtr(new PrimitivesAPI_Tube(aFeature, theRMin, theRMax, theZ, + theStartPhi, theDeltaPhi)); +} diff --git a/src/PrimitivesAPI/PrimitivesAPI_Tube.h b/src/PrimitivesAPI/PrimitivesAPI_Tube.h new file mode 100644 index 000000000..1e7c37d0c --- /dev/null +++ b/src/PrimitivesAPI/PrimitivesAPI_Tube.h @@ -0,0 +1,103 @@ +// Copyright (C) 2014-2019 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 + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \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& theZ); + + /// Constructor with values. + PRIMITIVESAPI_EXPORT + explicit PrimitivesAPI_Tube(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ, + const ModelHighAPI_Double& theStartPhi, + const ModelHighAPI_Double& theDeltaPhi); + + /// Destructor. + PRIMITIVESAPI_EXPORT + virtual ~PrimitivesAPI_Tube(); + + INTERFACE_6(PrimitivesPlugin_Tube::ID(), + creationMethod, PrimitivesPlugin_Tube::CREATION_METHOD(), + ModelAPI_AttributeString, /** Creation method */, + rmin, PrimitivesPlugin_Tube::RMIN_ID(), + ModelAPI_AttributeDouble, /** ???? */, + rmax, PrimitivesPlugin_Tube::RMAX_ID(), + ModelAPI_AttributeDouble, /** ???? */, + z, PrimitivesPlugin_Tube::Z_ID(), + ModelAPI_AttributeDouble, /** ???? */, + startphi, PrimitivesPlugin_Tube::START_PHI_ID(), + ModelAPI_AttributeDouble, /** ???? */, + deltaphi, PrimitivesPlugin_Tube::DELTA_PHI_ID(), + ModelAPI_AttributeDouble, /** ???? */) + + /// 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 Box feature. +PRIMITIVESAPI_EXPORT +TubePtr addTube(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ); + +/// \ingroup CPPHighAPI +/// \brief Create primitive Box feature. +PRIMITIVESAPI_EXPORT +TubePtr addTube(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theRMin, + const ModelHighAPI_Double& theRMax, + const ModelHighAPI_Double& theZ, + const ModelHighAPI_Double& theStartPhi, + const ModelHighAPI_Double& theDeltaPhi); + +#endif // PRIMITIVESAPI_TUBE_H_ diff --git a/src/PrimitivesAPI/PrimitivesAPI_swig.h b/src/PrimitivesAPI/PrimitivesAPI_swig.h index a1b7996e3..45cfd55ca 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/PythonAPI/model/primitives/__init__.py b/src/PythonAPI/model/primitives/__init__.py index 830633b7a..6d7039605 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 -- 2.39.2