From dd42d90779752b89b017d5e5961d338d1120e186 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 1 Dec 2017 08:29:51 +0300 Subject: [PATCH] Issue #2318: python script failed Python API feature to process ellipsoid has been implemented. --- src/GDMLAPI/CMakeLists.txt | 2 + src/GDMLAPI/GDMLAPI.i | 3 +- src/GDMLAPI/GDMLAPI_Ellipsoid.cpp | 144 +++++++++++++++++++++++++++ src/GDMLAPI/GDMLAPI_Ellipsoid.h | 125 +++++++++++++++++++++++ src/GDMLAPI/GDMLAPI_swig.h | 1 + src/PythonAPI/model/gdml/__init__.py | 2 +- 6 files changed, 275 insertions(+), 2 deletions(-) create mode 100644 src/GDMLAPI/GDMLAPI_Ellipsoid.cpp create mode 100644 src/GDMLAPI/GDMLAPI_Ellipsoid.h diff --git a/src/GDMLAPI/CMakeLists.txt b/src/GDMLAPI/CMakeLists.txt index 205d9ddf5..6654525fa 100644 --- a/src/GDMLAPI/CMakeLists.txt +++ b/src/GDMLAPI/CMakeLists.txt @@ -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 diff --git a/src/GDMLAPI/GDMLAPI.i b/src/GDMLAPI/GDMLAPI.i index 82eb12a37..25516108d 100644 --- a/src/GDMLAPI/GDMLAPI.i +++ b/src/GDMLAPI/GDMLAPI.i @@ -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 index 000000000..385b5dea2 --- /dev/null +++ b/src/GDMLAPI/GDMLAPI_Ellipsoid.cpp @@ -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 +// + +#include "GDMLAPI_Ellipsoid.h" + +#include +#include + +GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr& theFeature) + : ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +GDMLAPI_Ellipsoid::GDMLAPI_Ellipsoid(const std::shared_ptr& 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& 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& thePart, + const ModelHighAPI_Double& theAX, + const ModelHighAPI_Double& theBY, + const ModelHighAPI_Double& theCZ) +{ + std::shared_ptr aFeature = thePart->addFeature(GDMLAPI_Ellipsoid::ID()); + return EllipsoidPtr(new GDMLAPI_Ellipsoid(aFeature, theAX, theBY, theCZ)); +} + +EllipsoidPtr addEllipsoid(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theAX, + const ModelHighAPI_Double& theBY, + const ModelHighAPI_Double& theCZ, + const ModelHighAPI_Double& theZCut1, + const ModelHighAPI_Double& theZCut2) +{ + std::shared_ptr 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 index 000000000..dcc93ff92 --- /dev/null +++ b/src/GDMLAPI/GDMLAPI_Ellipsoid.h @@ -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 +// + +#ifndef GDMLAPI_Ellipsoid_H_ +#define GDMLAPI_Ellipsoid_H_ + +#include "GDMLAPI.h" + +#include + +#include +#include + +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& theFeature); + + /// Constructor with values. + GDMLAPI_EXPORT + explicit GDMLAPI_Ellipsoid(const std::shared_ptr& 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& 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 EllipsoidPtr; + +/// \ingroup CPPHighAPI +/// \brief Create GDML Ellipsoid feature. +GDMLAPI_EXPORT +EllipsoidPtr addEllipsoid(const std::shared_ptr& 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& 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_ diff --git a/src/GDMLAPI/GDMLAPI_swig.h b/src/GDMLAPI/GDMLAPI_swig.h index 2d4d2a705..91571affd 100644 --- a/src/GDMLAPI/GDMLAPI_swig.h +++ b/src/GDMLAPI/GDMLAPI_swig.h @@ -25,6 +25,7 @@ #include "GDMLAPI.h" #include "GDMLAPI_ConeSegment.h" + #include "GDMLAPI_Ellipsoid.h" #endif // GDMLAPI_swig_H_ diff --git a/src/PythonAPI/model/gdml/__init__.py b/src/PythonAPI/model/gdml/__init__.py index 428c1be61..ffc05033b 100644 --- a/src/PythonAPI/model/gdml/__init__.py +++ b/src/PythonAPI/model/gdml/__init__.py @@ -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 -- 2.39.2