From: Nicolas RECHATIN Date: Tue, 27 Jul 2021 14:06:09 +0000 (+0200) Subject: Add new Feature Volume for OPERA X-Git-Tag: OPERA_v0.5-s990~1^2^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5081522522ff18e59ed3cb00a5057e7bf65edbb3;p=modules%2Fshaper.git Add new Feature Volume for OPERA --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c566338c3..0e36ac329 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,6 +168,7 @@ ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/BuildPlugin) ADD_SUBDIRECTORY (src/PrimitivesPlugin) +ADD_SUBDIRECTORY (src/OperaPlugin) ADD_SUBDIRECTORY (src/GDMLPlugin) ADD_SUBDIRECTORY (src/FeaturesPlugin) ADD_SUBDIRECTORY (src/CollectionPlugin) @@ -196,6 +197,7 @@ ADD_SUBDIRECTORY (src/CollectionAPI) ADD_SUBDIRECTORY (src/ParametersAPI) ADD_SUBDIRECTORY (src/PartSetAPI) ADD_SUBDIRECTORY (src/PrimitivesAPI) +ADD_SUBDIRECTORY (src/OperaAPI) ADD_SUBDIRECTORY (src/SketchAPI) ADD_SUBDIRECTORY (src/GDMLAPI) ADD_SUBDIRECTORY (src/ConnectorAPI) diff --git a/src/CTestTestfileInstall.cmake b/src/CTestTestfileInstall.cmake index b52f407b3..daabb1b56 100644 --- a/src/CTestTestfileInstall.cmake +++ b/src/CTestTestfileInstall.cmake @@ -47,4 +47,5 @@ SUBDIRS(ConnectorAPI ModelGeomAlgo Locale test_API + OperaPlugin ) diff --git a/src/Config/plugins.xml.in b/src/Config/plugins.xml.in index 7c23b377e..a9e6b148f 100644 --- a/src/Config/plugins.xml.in +++ b/src/Config/plugins.xml.in @@ -6,6 +6,7 @@ + diff --git a/src/OperaAPI/CMakeLists.txt b/src/OperaAPI/CMakeLists.txt new file mode 100644 index 000000000..a9da8f181 --- /dev/null +++ b/src/OperaAPI/CMakeLists.txt @@ -0,0 +1,88 @@ +# Copyright (C) 2014-2021 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(Common) + +SET(PROJECT_HEADERS + OperaAPI.h + OperaAPI_Volume.h +) + +SET(PROJECT_SOURCES + OperaAPI_Volume.cpp +) + +SET(PROJECT_LIBRARIES + ModelAPI + ModelHighAPI +) + +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/Events + ${PROJECT_SOURCE_DIR}/src/ModelAPI + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI +) + +# Plugin headers dependency +INCLUDE_DIRECTORIES( + ${PROJECT_SOURCE_DIR}/src/GeomAPI + ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI + ${PROJECT_SOURCE_DIR}/src/GeomDataAPI + ${PROJECT_SOURCE_DIR}/src/OperaPlugin +) + +ADD_DEFINITIONS(-DOperaAPI_EXPORTS ${OpenCASCADE_DEFINITIONS}) +ADD_LIBRARY(OperaAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(OperaAPI ${PROJECT_LIBRARIES}) + +# SWIG wrapper + +INCLUDE(PythonAPI) + +SET_SOURCE_FILES_PROPERTIES(OperaAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(OperaAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +SET(SWIG_LINK_LIBRARIES + OperaAPI + ModelHighAPI + ModelAPI + ${PYTHON_LIBRARIES} +) +SET(CMAKE_SWIG_FLAGS -threads -w325,321,302,362,322,383,403) + +SET(SWIG_MODULE_OperaAPI_EXTRA_DEPS ${SWIG_MODULE_OperaAPI_EXTRA_DEPS} + ${PROJECT_SOURCE_DIR}/src/ModelHighAPI/ModelHighAPI.i + doxyhelp.i + ${PROJECT_HEADERS} +) + +IF(${CMAKE_VERSION} VERSION_GREATER "3.8.0") + SWIG_ADD_LIBRARY(OperaAPI LANGUAGE python SOURCES OperaAPI.i ${PROJECT_HEADERS}) +ELSE() + SWIG_ADD_MODULE(OperaAPI python OperaAPI.i ${PROJECT_HEADERS}) +ENDIF() +SWIG_LINK_LIBRARIES(OperaAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_OperaAPI PROPERTIES DEBUG_OUTPUT_NAME _OperaAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _OperaAPI DESTINATION ${SHAPER_INSTALL_SWIG}) +INSTALL(TARGETS OperaAPI DESTINATION ${SHAPER_INSTALL_BIN}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/OperaAPI.py DESTINATION ${SHAPER_INSTALL_SWIG}) diff --git a/src/OperaAPI/OperaAPI.h b/src/OperaAPI/OperaAPI.h new file mode 100644 index 000000000..8a1808b1e --- /dev/null +++ b/src/OperaAPI/OperaAPI.h @@ -0,0 +1,37 @@ +// Copyright (C) 2014-2021 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 OPERAAPI_H +#define OPERAAPI_H + +#if defined OPERAAPI_EXPORTS +#if defined WIN32 +#define OPERAAPI_EXPORT __declspec( dllexport ) +#else +#define OPERAAPI_EXPORT +#endif +#else +#if defined WIN32 +#define OPERAAPI_EXPORT __declspec( dllimport ) +#else +#define OPERAAPI_EXPORT +#endif +#endif + +#endif //OPERAAPI_H diff --git a/src/OperaAPI/OperaAPI.i b/src/OperaAPI/OperaAPI.i new file mode 100644 index 000000000..6bbadc525 --- /dev/null +++ b/src/OperaAPI/OperaAPI.i @@ -0,0 +1,44 @@ +// Copyright (C) 2014-2021 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 +// + +/* OperaAPI.i */ + +%module OperaAPI + +%{ + #include "OperaAPI_swig.h" +%} + +%include "doxyhelp.i" + +// import other modules +%import "ModelHighAPI.i" + +// to avoid error on this +#define OPERAAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_shared_ptr.i" + +// shared pointers +%shared_ptr(OperaAPI_Volume) + +// all supported interfaces +%include "OperaAPI_Volume.h" diff --git a/src/OperaAPI/OperaAPI_Volume.cpp b/src/OperaAPI/OperaAPI_Volume.cpp new file mode 100644 index 000000000..cf7dd40c9 --- /dev/null +++ b/src/OperaAPI/OperaAPI_Volume.cpp @@ -0,0 +1,84 @@ +// Copyright (C) 2014-2021 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 "OperaAPI_Volume.h" + +#include +#include + +//================================================================================================== +OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + + +//================================================================================================== +OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFeature, + const std::string& theMedium, + const std::list& theObjectsList) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(theMedium, medium()); + setObjectsList(theObjectsList); + } +} + +//================================================================================================== +OperaAPI_Volume::~OperaAPI_Volume() +{ +} + +//================================================================================================== +void OperaAPI_Volume::setMedium(const std::string& theMedium) +{ + fillAttribute(theMedium, medium()); + execute(); +} + +//================================================================================================== +void OperaAPI_Volume::setObjectsList(const std::list& theObjectsList) +{ + fillAttribute(theObjectsList, objectsList()); + execute(); +} + +//================================================================================================== +void OperaAPI_Volume::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeStringPtr anAttrMedium = aBase->string(OperaPlugin_Volume::MEDIUM_ID()); + theDumper << aBase << " = model.addVolume(" << aDocName << ", " << anAttrMedium << ", "; + + AttributeSelectionListPtr anAttrList = + aBase->selectionList(OperaPlugin_Volume::OBJECTS_LIST_ID()); + theDumper << anAttrList << ")" << std::endl; +} + +//================================================================================================== +VolumePtr addVolume(const std::shared_ptr& thePart, + const std::string& theMedium, + const std::list& theObjectsList) +{ + std::shared_ptr aFeature = thePart->addFeature(OperaAPI_Volume::ID()); + return VolumePtr(new OperaAPI_Volume(aFeature, theMedium, theObjectsList)); +} diff --git a/src/OperaAPI/OperaAPI_Volume.h b/src/OperaAPI/OperaAPI_Volume.h new file mode 100644 index 000000000..78aca0374 --- /dev/null +++ b/src/OperaAPI/OperaAPI_Volume.h @@ -0,0 +1,80 @@ +// Copyright (C) 2014-2021 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 OPERAAPI_VOLUME_H_ +#define OPERAAPI_VOLUME_H_ + +#include "OperaAPI.h" +#include + +#include +#include + +class ModelHighAPI_Selection; + +/// \class OperaAPI_Volume +/// \ingroup CPPHighAPI +/// \brief Interface for Volume feature. +class OperaAPI_Volume: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + OPERAAPI_EXPORT + explicit OperaAPI_Volume(const std::shared_ptr& theFeature); + + /// Constructor with values. + OPERAAPI_EXPORT + explicit OperaAPI_Volume(const std::shared_ptr& theFeature, + const std::string& theMedium, + const std::list& theObjectList); + + /// Destructor. + OPERAAPI_EXPORT + virtual ~OperaAPI_Volume(); + + INTERFACE_2(OperaPlugin_Volume::ID(), + medium, OperaPlugin_Volume::MEDIUM_ID(), + ModelAPI_AttributeString, /** Medium */, + objectsList, OperaPlugin_Volume::OBJECTS_LIST_ID(), + ModelAPI_AttributeSelectionList, /** Objects list*/) + + /// Set medium + OPERAAPI_EXPORT + void setMedium(const std::string& theMedium); + + /// Set main objects list. + OPERAAPI_EXPORT + void setObjectsList(const std::list& theObjectsList); + + /// Dump wrapped feature + OPERAAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer Volume feature +typedef std::shared_ptr VolumePtr; + +/// \ingroup CPPHighAPI +/// \brief Create Volume feature. +OPERAAPI_EXPORT +VolumePtr addVolume(const std::shared_ptr& thePart, + const std::string& theMedium, + const std::list& theObjectsList); + +#endif // OPERAAPI_VOLUME_H_ diff --git a/src/OperaAPI/OperaAPI_swig.h b/src/OperaAPI/OperaAPI_swig.h new file mode 100644 index 000000000..eaa088dc9 --- /dev/null +++ b/src/OperaAPI/OperaAPI_swig.h @@ -0,0 +1,28 @@ +// Copyright (C) 2014-2021 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 OPERAAPI_SWIG_H_ +#define OPERAAPI_SWIG_H_ + + #include + + #include "OperaAPI.h" + #include "OperaAPI_Volume.h" + +#endif // OPERAAPI_SWIG_H_ diff --git a/src/OperaPlugin/CMakeLists.txt b/src/OperaPlugin/CMakeLists.txt new file mode 100644 index 000000000..a1f7fd600 --- /dev/null +++ b/src/OperaPlugin/CMakeLists.txt @@ -0,0 +1,87 @@ +# Copyright (C) 2014-2021 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 +# + +SET(PROJECT_HEADERS + OperaPlugin.h + OperaPlugin_Plugin.h + OperaPlugin_Volume.h +) + +SET(PROJECT_SOURCES + OperaPlugin_Plugin.cpp + OperaPlugin_Volume.cpp + +) + +SET(XML_RESOURCES + plugin-Opera.xml + volume_widget.xml +) + +SET(TEXT_RESOURCES + OperaPlugin_msg_fr.ts +) + +SOURCE_GROUP ("XML Files" FILES ${XML_RESOURCES}) +SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES}) + +INCLUDE_DIRECTORIES( + ../ModelAPI + ../GeomAPI + ../GeomAlgoAPI + ../Events +) + +SET(PROJECT_LIBRARIES + Events + ModelAPI + GeomAPI + GeomAlgoAPI +) + +ADD_DEFINITIONS(-DOPERAPLUGIN_EXPORTS) +ADD_LIBRARY(OperaPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES} ${TEXT_RESOURCES}) +TARGET_LINK_LIBRARIES(OperaPlugin ${PROJECT_LIBRARIES}) + +INSTALL(TARGETS OperaPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) +INSTALL(FILES ${XML_RESOURCES} ${TEXT_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) +INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Opera) + +include(tests.set) + +ADD_UNIT_TESTS(${TEST_NAMES}) + +if(${HAVE_SALOME}) + enable_testing() + set(TEST_INSTALL_DIRECTORY "${SALOME_SHAPER_INSTALL_TESTS}/OperaPlugin") + + install(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) + install(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) + + set(TMP_TESTS_NAMES) + foreach(tfile ${TEST_NAMES}) + list(APPEND TMP_TESTS_NAMES "Test/${tfile}") + endforeach(tfile ${TEST_NAMES}) + + install(FILES ${TMP_TESTS_NAMES} DESTINATION ${TEST_INSTALL_DIRECTORY}) +endif(${HAVE_SALOME}) + + diff --git a/src/OperaPlugin/CTestTestfileInstall.cmake b/src/OperaPlugin/CTestTestfileInstall.cmake new file mode 100644 index 000000000..42056d5fe --- /dev/null +++ b/src/OperaPlugin/CTestTestfileInstall.cmake @@ -0,0 +1,29 @@ +# Copyright (C) 2021 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(tests.set) + +#SET(SALOME_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/salome_test_driver.py") +#SET(TIMEOUT 300) + +foreach(tfile ${TEST_NAMES}) + set(TEST_NAME ${COMPONENT_NAME}_${tfile}) + add_test(${TEST_NAME} python ${tfile}) + set_tests_properties(${TEST_NAME} PROPERTIES LABELS "${SALOME_TEST_LABEL_ADV}") +endforeach() diff --git a/src/OperaPlugin/OperaPlugin.h b/src/OperaPlugin/OperaPlugin.h new file mode 100644 index 000000000..85a17bfac --- /dev/null +++ b/src/OperaPlugin/OperaPlugin.h @@ -0,0 +1,37 @@ +// Copyright (C) 2014-2021 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 OPERAPLUGIN_H +#define OPERAPLUGIN_H + +#if defined OPERAPLUGIN_EXPORTS +#if defined WIN32 +#define OPERAPLUGIN_EXPORT __declspec( dllexport ) +#else +#define OPERAPLUGIN_EXPORT +#endif +#else +#if defined WIN32 +#define OPERAPLUGIN_EXPORT __declspec( dllimport ) +#else +#define OPERAPLUGIN_EXPORT +#endif +#endif + +#endif diff --git a/src/OperaPlugin/OperaPlugin_Plugin.cpp b/src/OperaPlugin/OperaPlugin_Plugin.cpp new file mode 100644 index 000000000..894925751 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Plugin.cpp @@ -0,0 +1,43 @@ +// Copyright (C) 2014-2021 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 + +// the only created instance of this plugin +static OperaPlugin_Plugin* MY_PRIMITIVES_INSTANCE = new OperaPlugin_Plugin(); + +OperaPlugin_Plugin::OperaPlugin_Plugin() +{ + // register this plugin + ModelAPI_Session::get()->registerPlugin(this); +} + +FeaturePtr OperaPlugin_Plugin::createFeature(std::string theFeatureID) +{ + if (theFeatureID == OperaPlugin_Volume::ID()) { + return FeaturePtr(new OperaPlugin_Volume); + } else { + return FeaturePtr(); + } +} diff --git a/src/OperaPlugin/OperaPlugin_Plugin.h b/src/OperaPlugin/OperaPlugin_Plugin.h new file mode 100644 index 000000000..a68e29f25 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Plugin.h @@ -0,0 +1,43 @@ +// Copyright (C) 2014-2021 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 OperaPlugin_Plugin_H_ +#define OperaPlugin_Plugin_H_ + +#include "OperaPlugin.h" +#include +#include + +/**\class OperaPlugin_Plugin + * \ingroup Plugins + * \brief The main class managing Opera Features as plugins. + */ +class OPERAPLUGIN_EXPORT OperaPlugin_Plugin : public ModelAPI_Plugin +{ + public: + /// Creates the feature object of this plugin by the feature string ID + virtual FeaturePtr createFeature(std::string theFeatureID); + + public: + /// Default constructor + OperaPlugin_Plugin(); + +}; + +#endif diff --git a/src/OperaPlugin/OperaPlugin_Volume.cpp b/src/OperaPlugin/OperaPlugin_Volume.cpp new file mode 100644 index 000000000..57393a226 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Volume.cpp @@ -0,0 +1,117 @@ +// Copyright (C) 2014-2021 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 +#include +#include + +#include +#include + +//================================================================================================= +OperaPlugin_Volume::OperaPlugin_Volume() // Nothing to do during instantiation +{ +} + +//================================================================================================= +static GeomShapePtr shapeOfSelection(AttributeSelectionPtr theSel) { + GeomShapePtr aResult; + FeaturePtr aSelFeature = theSel->contextFeature(); + if (aSelFeature.get()) { + if (aSelFeature->results().empty()) // if selected feature has no results, make nothing + return aResult; + if (aSelFeature->results().size() == 1) { // for one sub-result don't make compound + aResult = aSelFeature->firstResult()->shape(); + } + } + if (!aResult.get()) + aResult = theSel->value(); + if (!aResult.get()) { + if (theSel->context().get()) + aResult = theSel->context()->shape(); + } + return aResult; +} + +//================================================================================================= +void OperaPlugin_Volume::initAttributes() +{ + // Get Medium + data()->addAttribute(MEDIUM_ID(), ModelAPI_AttributeString::typeId()); + + // Get Objects + data()->addAttribute(OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); +} + +//================================================================================================= +void OperaPlugin_Volume::execute() +{ + std::string aCopiesMedium = string(MEDIUM_ID())->value(); + if (aCopiesMedium.empty()) + { + setError("Error: Medium cannot be empty."); + return; + } + + int aResultIndex = 0; + + AttributeSelectionListPtr aList = selectionList(OBJECTS_LIST_ID()); + std::wstring aBaseName; + for (int aSelIndex = 0; aSelIndex < aList->size(); aSelIndex++) { + AttributeSelectionPtr aSel = aList->value(aSelIndex); + GeomShapePtr aResult; + FeaturePtr aSelFeature = aSel->contextFeature(); + if (aSelFeature.get()) { + if (aSelFeature->results().empty()) // if selected feature has no results, make nothing + continue; + if (aSelFeature->results().size() == 1) { // for one sub-result don't make compound + aResult = aSelFeature->firstResult()->shape(); + } + } + if (!aResult.get()) + aResult = aSel->value(); + if (!aResult.get()) { + if (aSel->context().get()) + aResult = aSel->context()->shape(); + } + + // Handle naming : Volume_ + std::wstring aName; + std::set anExistingNames; + std::wstring aBaseName = aSel->context() ? aSel->context()->data()->name() : + aSel->contextFeature()->firstResult()->data()->name(); + do { + std::wostringstream aNameStr; + aNameStr << "Volume_" << aBaseName; + aName = aNameStr.str(); + } while (anExistingNames.count(aName)); + anExistingNames.insert(aName); + + ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->data()->setName(aName); + aResultBody->store(aResult); + setResult(aResultBody, aResultIndex++); + } + // Remove the rest results if there were produced in the previous pass. + removeResults(aResultIndex); +} diff --git a/src/OperaPlugin/OperaPlugin_Volume.h b/src/OperaPlugin/OperaPlugin_Volume.h new file mode 100644 index 000000000..be8b73824 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Volume.h @@ -0,0 +1,74 @@ +// Copyright (C) 2014-2021 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 OperaPlugin_Volume_H_ +#define OperaPlugin_Volume_H_ + +#include +#include + +class GeomAPI_Shape; +class ModelAPI_ResultBody; + +/**\class OperaPlugin_Volume + * \ingroup Plugins + * \brief Feature for creation of a Volume using solids. + * + * Volume creates Volume object - This volume takes selected solids shape + * and transform the result to a volume with a medium for OPERA. + */ +class OperaPlugin_Volume : public ModelAPI_Feature +{ + public: + /// Volume kind + inline static const std::string& ID() + { + static const std::string MY_VOLUME_ID("Volume"); + return MY_VOLUME_ID; + } + inline static const std::string& MEDIUM_ID() + { + static const std::string MY_MEDIUM_ID("medium"); + return MY_MEDIUM_ID; + } + /// attribute name of selected entities list + inline static const std::string& OBJECTS_LIST_ID() + { + static const std::string MY_OBJECTS_LIST_ID("objects_list"); + return MY_OBJECTS_LIST_ID; + } + + // Creates a new part document if needed + OPERAPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + OPERAPLUGIN_EXPORT virtual void initAttributes(); + + /// Returns the kind of a feature + OPERAPLUGIN_EXPORT virtual const std::string& getKind() + { + static std::string MY_KIND = OperaPlugin_Volume::ID(); + return MY_KIND; + } + + /// Use plugin manager for features creation + OperaPlugin_Volume(); +}; + +#endif diff --git a/src/OperaPlugin/OperaPlugin_msg_fr.ts b/src/OperaPlugin/OperaPlugin_msg_fr.ts new file mode 100644 index 000000000..aca1a8815 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_msg_fr.ts @@ -0,0 +1,57 @@ + + + + + + workshop + + Volume + Volume + + + + + Volume + + Volume + Volume + + + Create a volume + Créer un volume + + + + + Volume:medium + + Medium + Milieu + + + Please input the volumes medium + Veuillez indiquer le milieu des volumes + + + + + Volume:objects_list + + Objects + Objets + + + Select solid objects + Sélectionnez les solides + + + + + Volume:objects_list + + Attribute "%1" is not initialized. + Sélectionnez les solides. + + + + diff --git a/src/OperaPlugin/Test/TestVolume.py b/src/OperaPlugin/Test/TestVolume.py new file mode 100755 index 000000000..66538baca --- /dev/null +++ b/src/OperaPlugin/Test/TestVolume.py @@ -0,0 +1,82 @@ +# Copyright (C) 2014-2021 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 +# + +""" + TestVolume.py + Test case of OperaPlugin_Volume +""" +#========================================================================= +# Initialization of the test +#========================================================================= +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +### Create two box (one for error case) +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Box_2 = model.addBox(Part_1_doc, 10, 10, 10) + +### Create a cylinder +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) + +### Create a sphere +Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), 10) + +### Create a volume from the box +Volume_1 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Box_1_1")]) + +### Create a volume from the cylinder and the sphere +Volume_2 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Sphere_1_1")]) +Volume_2.setMedium("Eau") + +#Checks +from GeomAPI import GeomAPI_Shape + +model.testNbResults(Volume_1, 1) +model.testNbSubResults(Volume_1, [0]) +model.testNbSubShapes(Volume_1, GeomAPI_Shape.SOLID, [1]) +model.testNbSubShapes(Volume_1, GeomAPI_Shape.FACE, [6]) +model.testHaveNamingFaces(Volume_1, model, Part_1_doc) + +model.testNbResults(Volume_2, 2) +model.testNbSubResults(Volume_2, [0, 0]) +model.testNbSubShapes(Volume_2, GeomAPI_Shape.SOLID, [1, 1]) +model.testNbSubShapes(Volume_2, GeomAPI_Shape.FACE, [3, 1]) + +### Create a volume with no medium +Volume_3 = model.addVolume(Part_1_doc, "", [model.selection("SOLID", "Box_2_1")]) +model.testNbResults(Volume_3, 0) +assert(Volume_3.feature().error() == "Error: Medium cannot be empty.") + +### Create a volume with no shapes +Volume_4 = model.addVolume(Part_1_doc, "Error", []) +model.testNbResults(Volume_4, 0) +assert(Volume_4.feature().error() == "Attribute \"objects_list\" is not initialized.") + +### Create a volume with bad shapes +Volume_5 = model.addVolume(Part_1_doc, "Bad Shape", [model.selection("VERTEX", "PartSet/Origin")]) +model.testNbResults(Volume_5, 0) +assert(Volume_5.feature().error() == "It does not contain element with acceptable shape type. The type should be one of the next: solid") + +#========================================================================= +# End of test +#========================================================================= diff --git a/src/OperaPlugin/doc/OperaPlugin.rst b/src/OperaPlugin/doc/OperaPlugin.rst new file mode 100644 index 000000000..f61f280bd --- /dev/null +++ b/src/OperaPlugin/doc/OperaPlugin.rst @@ -0,0 +1,13 @@ + +.. _operaPlugin: + +Opera plug-in +================== + +The Opera plug-in provides a set of common operations to ROOT geometry. It implements the following features: + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + volumeFeature.rst diff --git a/src/OperaPlugin/doc/TUI_volume.rst b/src/OperaPlugin/doc/TUI_volume.rst new file mode 100644 index 000000000..3f3ecbd0f --- /dev/null +++ b/src/OperaPlugin/doc/TUI_volume.rst @@ -0,0 +1,11 @@ + + .. _tui_create_volume: + +Create Volume +============= + +.. literalinclude:: examples/volume.py + :linenos: + :language: python + +:download:`Download this script ` diff --git a/src/OperaPlugin/doc/examples/volume.py b/src/OperaPlugin/doc/examples/volume.py new file mode 100644 index 000000000..a21ef5396 --- /dev/null +++ b/src/OperaPlugin/doc/examples/volume.py @@ -0,0 +1,12 @@ +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() + +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Volume_1 = model.addVolume(Part_1_doc, "Air", [model.selection("SOLID", "Box_1_1")]) + +model.do() +model.end() diff --git a/src/OperaPlugin/doc/images/Volume.png b/src/OperaPlugin/doc/images/Volume.png new file mode 100644 index 000000000..281fc7197 Binary files /dev/null and b/src/OperaPlugin/doc/images/Volume.png differ diff --git a/src/OperaPlugin/doc/images/Volume1.png b/src/OperaPlugin/doc/images/Volume1.png new file mode 100644 index 000000000..4e8a1d2a8 Binary files /dev/null and b/src/OperaPlugin/doc/images/Volume1.png differ diff --git a/src/OperaPlugin/doc/images/Volume_button.png b/src/OperaPlugin/doc/images/Volume_button.png new file mode 100644 index 000000000..a078653ae Binary files /dev/null and b/src/OperaPlugin/doc/images/Volume_button.png differ diff --git a/src/OperaPlugin/doc/volumeFeature.rst b/src/OperaPlugin/doc/volumeFeature.rst new file mode 100644 index 000000000..8ea5c8548 --- /dev/null +++ b/src/OperaPlugin/doc/volumeFeature.rst @@ -0,0 +1,43 @@ +.. |Volume_button.icon| image:: images/Volume_button.png + +Volume +------ + +Volume feature creates a basic object used in bulding the ROOT geometrical hierarchy. + +To create a Volume in the active part: + +#. select in the Main Menu *Opera - > Volume* item or +#. click |Volume_button.icon| **Volume** button in the toolbar: + +Volume is created by a value and a list of solids + +.. figure:: images/Volume.png + :align: center + +Input fields: + +- **Medium** defines the name of the medium; +- **Objects** defines the list of solid objects + +**TUI Command**: + +.. py:function:: + model.addVolume(Part_doc, medium, model.selection[("SOLID", ...), ...]) + + :param part: The current part object. + :param string: A medium name. + :param list: A list of solids. + :return: Result object. + +Result +"""""" + +One solid for each selected solid in the volume list with according medium + +.. figure:: images/Volume1.png + :align: center + + Volume created + +**See Also** a sample TUI Script of :ref:`tui_create_volume` operation. diff --git a/src/OperaPlugin/icons/Volume.png b/src/OperaPlugin/icons/Volume.png new file mode 100644 index 000000000..32da1330a Binary files /dev/null and b/src/OperaPlugin/icons/Volume.png differ diff --git a/src/OperaPlugin/plugin-Opera.xml b/src/OperaPlugin/plugin-Opera.xml new file mode 100644 index 000000000..f16bf394b --- /dev/null +++ b/src/OperaPlugin/plugin-Opera.xml @@ -0,0 +1,14 @@ + + + + + + + + + diff --git a/src/OperaPlugin/tests.set b/src/OperaPlugin/tests.set new file mode 100644 index 000000000..019d00b2f --- /dev/null +++ b/src/OperaPlugin/tests.set @@ -0,0 +1,22 @@ +# Copyright (C) 2021 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 +# + +SET(TEST_NAMES + TestVolume.py +) diff --git a/src/OperaPlugin/volume_widget.xml b/src/OperaPlugin/volume_widget.xml new file mode 100644 index 000000000..a0cbd22b7 --- /dev/null +++ b/src/OperaPlugin/volume_widget.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/src/PythonAPI/Test/TestFeatures.py b/src/PythonAPI/Test/TestFeatures.py index 0431d5e45..ae3041ab7 100644 --- a/src/PythonAPI/Test/TestFeatures.py +++ b/src/PythonAPI/Test/TestFeatures.py @@ -104,6 +104,9 @@ class FeaturesTestCase(FeaturesFixture): import PrimitivesAPI PrimitivesAPI.PrimitivesAPI_Box(self.part.addFeature("Box")) + import OperaAPI + OperaAPI.OperaAPI_Volume(self.part.addFeature("Volume")) + import ParametersAPI ParametersAPI.ParametersAPI_Parameter(self.part.addFeature("Parameter")) diff --git a/src/PythonAPI/model/__init__.py b/src/PythonAPI/model/__init__.py index 6e2d15b70..eb043c97f 100644 --- a/src/PythonAPI/model/__init__.py +++ b/src/PythonAPI/model/__init__.py @@ -42,5 +42,6 @@ from .collection import * from .parameter import * from .partset import * from .primitives import * +from .opera import * from .gdml import * from .tests import * diff --git a/src/PythonAPI/model/opera/__init__.py b/src/PythonAPI/model/opera/__init__.py new file mode 100644 index 000000000..a13965476 --- /dev/null +++ b/src/PythonAPI/model/opera/__init__.py @@ -0,0 +1,22 @@ +# Copyright (C) 2016-2021 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 +# +"""Package for Opera plugin for SHAPER Opera. +""" + +from OperaAPI import addVolume diff --git a/src/SHAPERGUI/resources/LightApp.xml.in b/src/SHAPERGUI/resources/LightApp.xml.in index 33908724f..6d303a073 100644 --- a/src/SHAPERGUI/resources/LightApp.xml.in +++ b/src/SHAPERGUI/resources/LightApp.xml.in @@ -22,6 +22,9 @@ +
+ +