From 3add42a668add45c02ec50b512ebb20fdc3ab5f5 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Wed, 5 Jul 2017 16:25:54 +0200 Subject: [PATCH] Add the feature "GDML Ellipsoid". --- src/GDMLPlugin/CMakeLists.txt | 3 + src/GDMLPlugin/GDMLPlugin_ConeSegment.cpp | 1 - src/GDMLPlugin/GDMLPlugin_Ellipsoid.cpp | 120 ++++++++++++ src/GDMLPlugin/GDMLPlugin_Ellipsoid.h | 110 +++++++++++ src/GDMLPlugin/GDMLPlugin_Plugin.cpp | 4 + src/GDMLPlugin/ellipsoid_widget.xml | 60 ++++++ src/GDMLPlugin/icons/ellipsoid.png | Bin 0 -> 699 bytes src/GDMLPlugin/icons/gui_ellipsoid.png | Bin 0 -> 25248 bytes src/GDMLPlugin/plugin-GDML.xml | 5 +- src/GeomAlgoAPI/CMakeLists.txt | 2 + src/GeomAlgoAPI/GeomAlgoAPI_Ellipsoid.cpp | 220 ++++++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Ellipsoid.h | 62 ++++++ 12 files changed, 585 insertions(+), 2 deletions(-) create mode 100644 src/GDMLPlugin/GDMLPlugin_Ellipsoid.cpp create mode 100644 src/GDMLPlugin/GDMLPlugin_Ellipsoid.h create mode 100644 src/GDMLPlugin/ellipsoid_widget.xml create mode 100644 src/GDMLPlugin/icons/ellipsoid.png create mode 100644 src/GDMLPlugin/icons/gui_ellipsoid.png create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Ellipsoid.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_Ellipsoid.h diff --git a/src/GDMLPlugin/CMakeLists.txt b/src/GDMLPlugin/CMakeLists.txt index 3723e2220..ce4ae6a26 100644 --- a/src/GDMLPlugin/CMakeLists.txt +++ b/src/GDMLPlugin/CMakeLists.txt @@ -27,16 +27,19 @@ SET(PROJECT_HEADERS GDMLPlugin.h GDMLPlugin_Plugin.h GDMLPlugin_ConeSegment.h + GDMLPlugin_Ellipsoid.h ) SET(PROJECT_SOURCES GDMLPlugin_Plugin.cpp GDMLPlugin_ConeSegment.cpp + GDMLPlugin_Ellipsoid.cpp ) SET(XML_RESOURCES plugin-GDML.xml conesegment_widget.xml + ellipsoid_widget.xml ) INCLUDE_DIRECTORIES( diff --git a/src/GDMLPlugin/GDMLPlugin_ConeSegment.cpp b/src/GDMLPlugin/GDMLPlugin_ConeSegment.cpp index fc371beda..2429edd78 100644 --- a/src/GDMLPlugin/GDMLPlugin_ConeSegment.cpp +++ b/src/GDMLPlugin/GDMLPlugin_ConeSegment.cpp @@ -23,7 +23,6 @@ #include #include #include -#include //================================================================================================= GDMLPlugin_ConeSegment::GDMLPlugin_ConeSegment() // Nothing to do during instantiation diff --git a/src/GDMLPlugin/GDMLPlugin_Ellipsoid.cpp b/src/GDMLPlugin/GDMLPlugin_Ellipsoid.cpp new file mode 100644 index 000000000..db962dcfe --- /dev/null +++ b/src/GDMLPlugin/GDMLPlugin_Ellipsoid.cpp @@ -0,0 +1,120 @@ +// 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 + +#include +#include +#include +#include + +//================================================================================================= +GDMLPlugin_Ellipsoid::GDMLPlugin_Ellipsoid() // Nothing to do during instantiation +{ +} + +//================================================================================================= +void GDMLPlugin_Ellipsoid::initAttributes() +{ + data()->addAttribute(GDMLPlugin_Ellipsoid::AX_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(GDMLPlugin_Ellipsoid::BY_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(GDMLPlugin_Ellipsoid::CZ_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(GDMLPlugin_Ellipsoid::USE_ZCUT1_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(GDMLPlugin_Ellipsoid::ZCUT1_ID(), ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(GDMLPlugin_Ellipsoid::USE_ZCUT2_ID(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(GDMLPlugin_Ellipsoid::ZCUT2_ID(), ModelAPI_AttributeDouble::typeId()); +} + +//================================================================================================= +void GDMLPlugin_Ellipsoid::execute() +{ + std::shared_ptr anEllipsoidAlgo; + + double aAx = real(AX_ID())->value(); + double aBy = real(BY_ID())->value(); + double aCz = real(CZ_ID())->value(); + + std::string useZCut1 = string(USE_ZCUT1_ID())->value(); + std::string useZCut2 = string(USE_ZCUT2_ID())->value(); + + double aZCut1 = 0.; + if (useZCut1.empty()) { + aZCut1 = aCz /2.; + } else { + aZCut1 = real(ZCUT1_ID())->value(); + } + double aZCut2 = 0.; + if (useZCut2.empty()) { + aZCut2 = aCz /2.; + } else { + aZCut2 = real(ZCUT2_ID())->value(); + } + + anEllipsoidAlgo = std::shared_ptr( + new GeomAlgoAPI_Ellipsoid(aAx, aBy, aCz, aZCut1, aZCut2)); + + // Check with that the arguments for anEllipsoidAlgo are correct + if (!anEllipsoidAlgo->check()){ + setError(anEllipsoidAlgo->getError(), false); + return; + } + + anEllipsoidAlgo->build(); + + // Check if the creation of the ellipsoid is correct + if (!anEllipsoidAlgo->isDone()) { + setError(anEllipsoidAlgo->getError(), false); + return; + } + + // Check if the created ellipsoid is valid + if (!anEllipsoidAlgo->checkValid("Ellipsoid builder")) { + setError(anEllipsoidAlgo->getError(), false); + return; + } + + int aResultIndex = 0; + ResultBodyPtr aResultEllipsoid = document()->createBody(data(), aResultIndex); + loadNamingDS(anEllipsoidAlgo, aResultEllipsoid); + setResult(aResultEllipsoid, aResultIndex); + +} + +//================================================================================================= +void GDMLPlugin_Ellipsoid::loadNamingDS(std::shared_ptr theEllipsoidAlgo, + std::shared_ptr theResultEllipsoid) +{ + // Load the result + theResultEllipsoid->store(theEllipsoidAlgo->shape()); + + // Prepare the naming + theEllipsoidAlgo->prepareNamingFaces(); + + // Insert to faces + int num = 1; + std::map< std::string, std::shared_ptr > listOfFaces = + theEllipsoidAlgo->getCreatedFaces(); + for (std::map< std::string, std::shared_ptr >::iterator + it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) { + std::shared_ptr aFace = (*it).second; + theResultEllipsoid->generated(aFace, (*it).first, num++); + } +} + diff --git a/src/GDMLPlugin/GDMLPlugin_Ellipsoid.h b/src/GDMLPlugin/GDMLPlugin_Ellipsoid.h new file mode 100644 index 000000000..649afcf3a --- /dev/null +++ b/src/GDMLPlugin/GDMLPlugin_Ellipsoid.h @@ -0,0 +1,110 @@ +// 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 GDMLPLUGIN_ELLIPSOID_H_ +#define GDMLPLUGIN_ELLIPSOID_H_ + +#include +#include +#include + +class GeomAPI_Shape; +class ModelAPI_ResultBody; + +/**\class GDMLPlugin_Ellipsoid + * \ingroup Plugins + * \brief Feature for creation of a GDML Ellipsoid solid. + */ +class GDMLPlugin_Ellipsoid : public ModelAPI_Feature +{ + public: + /// Cone segment kind + inline static const std::string& ID() + { + static const std::string MY_CONESEGMENT_ID("Ellipsoid"); + return MY_CONESEGMENT_ID; + } + /// attribute name of the inner radius at base of cone + inline static const std::string& AX_ID() + { + static const std::string MY_AX_ID("ax"); + return MY_AX_ID; + } + /// attribute name of the outer radius at base of cone + inline static const std::string& BY_ID() + { + static const std::string MY_BY_ID("by"); + return MY_BY_ID; + } + /// attribute name of the inner radius at top of cone + inline static const std::string& CZ_ID() + { + static const std::string MY_CZ_ID("cz"); + return MY_CZ_ID; + } + /// attribute name of the outer radius at top of cone + inline static const std::string& ZCUT1_ID() + { + static const std::string MY_ZCUT1_ID("zcut1"); + return MY_ZCUT1_ID; + } + /// attribute name of the outer radius at top of cone + inline static const std::string& USE_ZCUT1_ID() + { + static const std::string MY_USE_ZCUT1_ID("use_zcut1"); + return MY_USE_ZCUT1_ID; + } + /// attribute name of the outer radius at top of cone + inline static const std::string& USE_ZCUT2_ID() + { + static const std::string MY_USE_ZCUT2_ID("use_zcut2"); + return MY_USE_ZCUT2_ID; + } + /// attribute name of the outer radius at top of cone + inline static const std::string& ZCUT2_ID() + { + static const std::string MY_ZCUT2_ID("zcut2"); + return MY_ZCUT2_ID; + } + + /// Returns the kind of a feature + GDMLPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = GDMLPlugin_Ellipsoid::ID(); + return MY_KIND; + } + + /// Creates a new part document if needed + GDMLPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + GDMLPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + GDMLPlugin_Ellipsoid(); + + private: + /// Load Naming data structure of the feature to the document + void loadNamingDS(std::shared_ptr theEllipsoidAlgo, + std::shared_ptr theResultEllipsoid); + +}; + +#endif // GDMLPLUGIN_ELLIPSOID_H_ diff --git a/src/GDMLPlugin/GDMLPlugin_Plugin.cpp b/src/GDMLPlugin/GDMLPlugin_Plugin.cpp index 28ff7cea4..9dba4a099 100644 --- a/src/GDMLPlugin/GDMLPlugin_Plugin.cpp +++ b/src/GDMLPlugin/GDMLPlugin_Plugin.cpp @@ -23,6 +23,7 @@ #include #include +#include // the only created instance of this plugin static GDMLPlugin_Plugin* MY_GDML_INSTANCE = new GDMLPlugin_Plugin(); @@ -37,7 +38,10 @@ FeaturePtr GDMLPlugin_Plugin::createFeature(std::string theFeatureID) { if (theFeatureID == GDMLPlugin_ConeSegment::ID()) { return FeaturePtr(new GDMLPlugin_ConeSegment); + } else if (theFeatureID == GDMLPlugin_Ellipsoid::ID()) { + return FeaturePtr(new GDMLPlugin_Ellipsoid); } + // feature of such kind is not found return FeaturePtr(); } diff --git a/src/GDMLPlugin/ellipsoid_widget.xml b/src/GDMLPlugin/ellipsoid_widget.xml new file mode 100644 index 000000000..62da54f8e --- /dev/null +++ b/src/GDMLPlugin/ellipsoid_widget.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + +