]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add Python API for tube
authorcg246364 <clarisse.genrault@cea.fr>
Mon, 9 Nov 2020 07:29:12 +0000 (08:29 +0100)
committercg246364 <clarisse.genrault@cea.fr>
Mon, 9 Nov 2020 07:29:12 +0000 (08:29 +0100)
src/GeomAlgoAPI/GeomAlgoAPI_Tube.cpp
src/PrimitivesAPI/CMakeLists.txt
src/PrimitivesAPI/PrimitivesAPI.i
src/PrimitivesAPI/PrimitivesAPI_Tube.cpp [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_Tube.h [new file with mode: 0644]
src/PrimitivesAPI/PrimitivesAPI_swig.h
src/PythonAPI/model/primitives/__init__.py

index 770c479df06e69df4272e10b8357e8cd46ae298a..0673066031fed2abed516e12b133404d34c00bbf 100644 (file)
@@ -23,6 +23,7 @@
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepBuilderAPI_MakeFace.hxx>
 #include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
 #include <BRepPrimAPI_MakePrism.hxx>
 #include <BRepPrimAPI_MakeRevol.hxx>
 
@@ -153,7 +154,17 @@ std::shared_ptr<GeomAPI_Shape> 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<GeomAlgoAPI_MakeShape>(
+//       new GeomAlgoAPI_MakeShape(aTransformBuilder)));
+  TopoDS_Shape aMovedBase = aTransformBuilder->Shape();
+  BRepPrimAPI_MakePrism* aPrismBuilder = new BRepPrimAPI_MakePrism(aMovedBase, aVec * myZ);
   
   setImpl(aPrismBuilder);
   setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
index 53b860925a27b6edc3a127c957e0a979de51f606..02db57262a8a50e514aef5988c1a63cc09baee40 100644 (file)
@@ -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
index f910ffefba1665ccc3fab425d164ccd1b9b58dd7..42541907b410a1255b9c81975b35e5aa70935dcd 100644 (file)
@@ -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 (file)
index 0000000..8d9c044
--- /dev/null
@@ -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 <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+PrimitivesAPI_Tube::PrimitivesAPI_Tube(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+}
+
+//==================================================================================================
+PrimitivesAPI_Tube::PrimitivesAPI_Tube(const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_Feature>& 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<ModelAPI_Document>& thePart,
+                const ModelHighAPI_Double& theRMin,
+                const ModelHighAPI_Double& theRMax,
+                const ModelHighAPI_Double& theZ)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PrimitivesAPI_Tube::ID());
+  return TubePtr(new PrimitivesAPI_Tube(aFeature, theRMin, theRMax, theZ));
+}
+
+//==================================================================================================
+TubePtr addTube(const std::shared_ptr<ModelAPI_Document>& thePart,
+                const ModelHighAPI_Double& theRMin,
+                const ModelHighAPI_Double& theRMax,
+                const ModelHighAPI_Double& theZ,
+                const ModelHighAPI_Double& theStartPhi,
+                const ModelHighAPI_Double& theDeltaPhi)
+{
+  std::shared_ptr<ModelAPI_Feature> 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 (file)
index 0000000..1e7c37d
--- /dev/null
@@ -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 <PrimitivesPlugin_Tube.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+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<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  PRIMITIVESAPI_EXPORT
+  explicit PrimitivesAPI_Tube(const std::shared_ptr<ModelAPI_Feature>& 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<ModelAPI_Feature>& 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<PrimitivesAPI_Tube> TubePtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create primitive Box feature.
+PRIMITIVESAPI_EXPORT
+TubePtr addTube(const std::shared_ptr<ModelAPI_Document>& 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<ModelAPI_Document>& 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_
index a1b7996e3009f056e0c278a4e0ee3ba5c262eb99..45cfd55caee5fa4bba88efc5b85265ff57b9b141 100644 (file)
@@ -28,5 +28,6 @@
   #include "PrimitivesAPI_Cylinder.h"
   #include "PrimitivesAPI_Sphere.h"
   #include "PrimitivesAPI_Torus.h"
+  #include "PrimitivesAPI_Tube.h"
 
 #endif // PRIMITIVESAPI_SWIG_H_
index 830633b7aaff825cd779d0ab5634740976cbdaef..6d7039605692070186043f76f3a5bffaa0db1548 100644 (file)
@@ -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