]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2318: python script failed
authorazv <azv@opencascade.com>
Fri, 1 Dec 2017 05:29:51 +0000 (08:29 +0300)
committerazv <azv@opencascade.com>
Fri, 1 Dec 2017 05:29:51 +0000 (08:29 +0300)
Python API feature to process ellipsoid has been implemented.

src/GDMLAPI/CMakeLists.txt
src/GDMLAPI/GDMLAPI.i
src/GDMLAPI/GDMLAPI_Ellipsoid.cpp [new file with mode: 0644]
src/GDMLAPI/GDMLAPI_Ellipsoid.h [new file with mode: 0644]
src/GDMLAPI/GDMLAPI_swig.h
src/PythonAPI/model/gdml/__init__.py

index 205d9ddf5fc2cb5800c7d9d41805b0186ab6783b..6654525fa428de3ea445f9bb6f510c47111336d9 100644 (file)
@@ -23,10 +23,12 @@ INCLUDE(Common)
 SET(PROJECT_HEADERS
   GDMLAPI.h
   GDMLAPI_ConeSegment.h
+  GDMLAPI_Ellipsoid.h
 )
 
 SET(PROJECT_SOURCES
   GDMLAPI_ConeSegment.cpp
+  GDMLAPI_Ellipsoid.cpp
 )
 
 SET(PROJECT_LIBRARIES
index 82eb12a37a5b8a8c1f8c3c7fd67181b7330987d5..25516108d34d1ddb4ce0bfb962d969306884fca2 100644 (file)
@@ -45,7 +45,8 @@
 
 // shared pointers
 %shared_ptr(GDMLAPI_ConeSegment)
+%shared_ptr(GDMLAPI_Ellipsoid)
 
 // all supported interfaces
 %include "GDMLAPI_ConeSegment.h"
-
+%include "GDMLAPI_Ellipsoid.h"
diff --git a/src/GDMLAPI/GDMLAPI_Ellipsoid.cpp b/src/GDMLAPI/GDMLAPI_Ellipsoid.cpp
new file mode 100644 (file)
index 0000000..385b5de
--- /dev/null
@@ -0,0 +1,144 @@
+// Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+//
+
+#include "GDMLAPI_Ellipsoid.h"
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+  : ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const ModelHighAPI_Double& theAX,
+                                     const ModelHighAPI_Double& theBY,
+                                     const ModelHighAPI_Double& theCZ)
+  : ModelHighAPI_Interface(theFeature)
+{
+  if (initialize()) {
+    setSizes(theAX, theBY, theCZ);
+    fillAttribute("", useZCut1());
+    fillAttribute("", useZCut1());
+  }
+}
+
+GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const ModelHighAPI_Double& theAX,
+                                     const ModelHighAPI_Double& theBY,
+                                     const ModelHighAPI_Double& theCZ,
+                                     const ModelHighAPI_Double& theZCut1,
+                                     const ModelHighAPI_Double& theZCut2)
+  : ModelHighAPI_Interface(theFeature)
+{
+  if (initialize()) {
+    setSizes(theAX, theBY, theCZ);
+    setZCut1(theZCut1);
+    setZCut2(theZCut2);
+  }
+}
+
+GDMLAPI_Ellipsoid::~GDMLAPI_Ellipsoid()
+{
+}
+
+void GDMLAPI_Ellipsoid::setSizes(const ModelHighAPI_Double& theAX,
+                                 const ModelHighAPI_Double& theBY,
+                                 const ModelHighAPI_Double& theCZ)
+{
+  fillAttribute(theAX, ax());
+  fillAttribute(theBY, by());
+  fillAttribute(theCZ, cz());
+
+  execute();
+}
+
+void GDMLAPI_Ellipsoid::setZCut1(const ModelHighAPI_Double& theZCut1)
+{
+  fillAttribute("true", useZCut1());
+  fillAttribute(theZCut1, zCut1());
+
+  execute();
+}
+
+void GDMLAPI_Ellipsoid::setZCut2(const ModelHighAPI_Double& theZCut2)
+{
+  fillAttribute("true", useZCut2());
+  fillAttribute(theZCut2, zCut2());
+
+  execute();
+}
+
+
+//==================================================================================================
+void GDMLAPI_Ellipsoid::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  AttributeDoublePtr anAttrAX = aBase->real(GDMLPlugin_Ellipsoid::AX_ID());
+  AttributeDoublePtr anAttrBY = aBase->real(GDMLPlugin_Ellipsoid::BY_ID());
+  AttributeDoublePtr anAttrCZ = aBase->real(GDMLPlugin_Ellipsoid::CZ_ID());
+
+  theDumper << aBase << " = model.addEllipsoid(" << aDocName << ", "
+            << anAttrAX << ", " << anAttrBY << ", " << anAttrCZ;
+
+  AttributeStringPtr anAttrUseZCut1 = aBase->string(GDMLPlugin_Ellipsoid::USE_ZCUT1_ID());
+  AttributeDoublePtr anAttrZCut1 = aBase->real(GDMLPlugin_Ellipsoid::ZCUT1_ID());
+  AttributeStringPtr anAttrUseZCut2 = aBase->string(GDMLPlugin_Ellipsoid::USE_ZCUT2_ID());
+  AttributeDoublePtr anAttrZCut2 = aBase->real(GDMLPlugin_Ellipsoid::ZCUT2_ID());
+
+  bool isZCut1 = !anAttrUseZCut1->value().empty();
+  bool isZCut2 = !anAttrUseZCut2->value().empty();
+  if (isZCut1 && isZCut2)
+    theDumper << ", " << anAttrZCut1 << ", " << anAttrZCut2 << ")" << std::endl;
+  else {
+    theDumper << ")" << std::endl;
+
+    if (isZCut1 && !isZCut2)
+      theDumper << theDumper.name(aBase) << ".setZCut1(" << anAttrZCut1 << ")" << std::endl;
+    else if (!isZCut1 && isZCut2)
+      theDumper << theDumper.name(aBase) << ".setZCut2(" << anAttrZCut2 << ")" << std::endl;
+  }
+}
+
+
+//==================================================================================================
+EllipsoidPtr addEllipsoid(const std::shared_ptr<ModelAPI_Document>& thePart,
+                          const ModelHighAPI_Double& theAX,
+                          const ModelHighAPI_Double& theBY,
+                          const ModelHighAPI_Double& theCZ)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID());
+  return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ));
+}
+
+EllipsoidPtr addEllipsoid(const std::shared_ptr<ModelAPI_Document>& thePart,
+                          const ModelHighAPI_Double& theAX,
+                          const ModelHighAPI_Double& theBY,
+                          const ModelHighAPI_Double& theCZ,
+                          const ModelHighAPI_Double& theZCut1,
+                          const ModelHighAPI_Double& theZCut2)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID());
+  return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ, theZCut1, theZCut2));
+}
diff --git a/src/GDMLAPI/GDMLAPI_Ellipsoid.h b/src/GDMLAPI/GDMLAPI_Ellipsoid.h
new file mode 100644 (file)
index 0000000..dcc93ff
--- /dev/null
@@ -0,0 +1,125 @@
+// Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+//
+
+#ifndef GDMLAPI_Ellipsoid_H_
+#define GDMLAPI_Ellipsoid_H_
+
+#include "GDMLAPI.h"
+
+#include <GDMLPlugin_Ellipsoid.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+class ModelHighAPI_Double;
+
+/// \class GDMLAPI_Ellipsoid
+/// \ingroup CPPHighAPI
+/// \brief Interface for primitive Ellipsoid feature.
+class GDMLAPI_Ellipsoid: public ModelHighAPI_Interface
+{
+public:
+  /// Constructor without values.
+  GDMLAPI_EXPORT
+  explicit GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  GDMLAPI_EXPORT
+  explicit GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                             const ModelHighAPI_Double& theAX,
+                             const ModelHighAPI_Double& theBY,
+                             const ModelHighAPI_Double& theCZ);
+
+  /// Constructor with values.
+  GDMLAPI_EXPORT
+  explicit GDMLAPI_Ellipsoid(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                             const ModelHighAPI_Double& theAX,
+                             const ModelHighAPI_Double& theBY,
+                             const ModelHighAPI_Double& theCZ,
+                             const ModelHighAPI_Double& theZCut1,
+                             const ModelHighAPI_Double& theZCut2);
+
+  /// Destructor.
+  GDMLAPI_EXPORT
+  virtual ~GDMLAPI_Ellipsoid();
+
+  INTERFACE_7(GDMLPlugin_Ellipsoid::ID(),
+              ax, GDMLPlugin_Ellipsoid::AX_ID(),
+                  ModelAPI_AttributeDouble,
+                  /** Ellipsoid size along X axis */,
+              by, GDMLPlugin_Ellipsoid::BY_ID(),
+                  ModelAPI_AttributeDouble,
+                  /** Ellipsoid size along Y axis */,
+              cz, GDMLPlugin_Ellipsoid::CZ_ID(),
+                  ModelAPI_AttributeDouble,
+                  /** Ellipsoid size along Z axis */,
+              useZCut1, GDMLPlugin_Ellipsoid::USE_ZCUT1_ID(),
+                  ModelAPI_AttributeString,
+                  /** First cut of the ellipsoid along Z axis */,
+              zCut1, GDMLPlugin_Ellipsoid::ZCUT1_ID(),
+                  ModelAPI_AttributeDouble,
+                  /** Position of the first cut */,
+              useZCut2, GDMLPlugin_Ellipsoid::USE_ZCUT2_ID(),
+                  ModelAPI_AttributeString,
+                  /** Second cut of the ellipsoid along Z axis */,
+              zCut2, GDMLPlugin_Ellipsoid::ZCUT2_ID(),
+                  ModelAPI_AttributeDouble,
+                  /** Position of the second cut */)
+
+  /// Set dimensions
+  GDMLAPI_EXPORT
+  void setSizes(const ModelHighAPI_Double& theAX,
+                const ModelHighAPI_Double& theBY,
+                const ModelHighAPI_Double& theCZ);
+
+  /// Set Z cut no.1
+  GDMLAPI_EXPORT
+  void setZCut1(const ModelHighAPI_Double& theZCut1);
+
+  /// Set Z cut no.2
+  GDMLAPI_EXPORT
+  void setZCut2(const ModelHighAPI_Double& theZCut2);
+
+  /// Dump wrapped feature
+  GDMLAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on primitive Ellipsoid object
+typedef std::shared_ptr<GDMLAPI_Ellipsoid> EllipsoidPtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create GDML Ellipsoid feature.
+GDMLAPI_EXPORT
+EllipsoidPtr addEllipsoid(const std::shared_ptr<ModelAPI_Document>& thePart,
+                          const ModelHighAPI_Double& theAX,
+                          const ModelHighAPI_Double& theBY,
+                          const ModelHighAPI_Double& theCZ);
+
+/// \ingroup CPPHighAPI
+/// \brief Create GDML Ellipsoid feature.
+GDMLAPI_EXPORT
+EllipsoidPtr addEllipsoid(const std::shared_ptr<ModelAPI_Document>& thePart,
+                          const ModelHighAPI_Double& theAX,
+                          const ModelHighAPI_Double& theBY,
+                          const ModelHighAPI_Double& theCZ,
+                          const ModelHighAPI_Double& theZCut1,
+                          const ModelHighAPI_Double& theZCut2);
+#endif // GDMLAPI_Ellipsoid_H_
index 2d4d2a705242fe11e767430349b6f5a6827537c2..91571affdf5a9c3391dc62dc16d5b35581cd4aa2 100644 (file)
@@ -25,6 +25,7 @@
 
   #include "GDMLAPI.h"
   #include "GDMLAPI_ConeSegment.h"
+  #include "GDMLAPI_Ellipsoid.h"
 
 #endif // GDMLAPI_swig_H_
 
index 428c1be61cfbd88b60827eb40411921325513105..ffc05033b93a12be9e36491e7cdb915bc2bb5ba2 100644 (file)
@@ -1,5 +1,5 @@
 """Package for GDML plugin for the Parametric Geometry API of the Modeler.
 """
 
-from GDMLAPI import addConeSegment
+from GDMLAPI import addConeSegment, addEllipsoid