From f0a31a9dc4176410dd941d6aaae01a7e042cad86 Mon Sep 17 00:00:00 2001 From: Nicolas RECHATIN Date: Tue, 27 Jul 2021 16:06:09 +0200 Subject: [PATCH] WIP addVolume Feature with results --- CMakeLists.txt | 1 + src/Config/plugins.xml.in | 1 + src/OperaAPI/CMakeLists.txt | 88 +++++ src/OperaAPI/OperaAPI.h | 37 ++ src/OperaAPI/OperaAPI_addVolume.cpp | 89 +++++ src/OperaAPI/OperaAPI_addVolume.h | 81 +++++ src/OperaPlugin/CMakeLists.txt | 66 ++++ src/OperaPlugin/OperaPlugin.h | 37 ++ src/OperaPlugin/OperaPlugin_Plugin.cpp | 47 +++ src/OperaPlugin/OperaPlugin_Plugin.h | 43 +++ src/OperaPlugin/OperaPlugin_Volume.cpp | 124 +++++++ src/OperaPlugin/OperaPlugin_Volume.h | 82 +++++ src/OperaPlugin/OperaPlugin_msg_fr.ts | 408 +++++++++++++++++++++++ src/OperaPlugin/Test/TestAddVolume.py | 83 +++++ src/OperaPlugin/addvolume_widget.xml | 12 + src/OperaPlugin/doc/addvolumeFeature.rst | 136 ++++++++ src/OperaPlugin/icons/addVolume.png | Bin 0 -> 528 bytes src/OperaPlugin/plugin-Opera.xml | 10 + src/OperaPlugin/tests.set | 22 ++ src/PythonAPI/model/__init__.py | 1 + src/PythonAPI/model/opera/__init__.py | 22 ++ 21 files changed, 1390 insertions(+) create mode 100644 src/OperaAPI/CMakeLists.txt create mode 100644 src/OperaAPI/OperaAPI.h create mode 100644 src/OperaAPI/OperaAPI_addVolume.cpp create mode 100644 src/OperaAPI/OperaAPI_addVolume.h create mode 100644 src/OperaPlugin/CMakeLists.txt create mode 100644 src/OperaPlugin/OperaPlugin.h create mode 100644 src/OperaPlugin/OperaPlugin_Plugin.cpp create mode 100644 src/OperaPlugin/OperaPlugin_Plugin.h create mode 100644 src/OperaPlugin/OperaPlugin_Volume.cpp create mode 100644 src/OperaPlugin/OperaPlugin_Volume.h create mode 100644 src/OperaPlugin/OperaPlugin_msg_fr.ts create mode 100644 src/OperaPlugin/Test/TestAddVolume.py create mode 100644 src/OperaPlugin/addvolume_widget.xml create mode 100644 src/OperaPlugin/doc/addvolumeFeature.rst create mode 100644 src/OperaPlugin/icons/addVolume.png create mode 100644 src/OperaPlugin/plugin-Opera.xml create mode 100644 src/OperaPlugin/tests.set create mode 100644 src/PythonAPI/model/opera/__init__.py diff --git a/CMakeLists.txt b/CMakeLists.txt index c566338c3..18d0dd973 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) 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..009c9f63b --- /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_addVolume.h +) + +SET(PROJECT_SOURCES + OperaAPI_addVolume.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/PrimitivesPlugin +) + +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..093042bb2 --- /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 //PRIMITIVESAPI_H diff --git a/src/OperaAPI/OperaAPI_addVolume.cpp b/src/OperaAPI/OperaAPI_addVolume.cpp new file mode 100644 index 000000000..8764ba593 --- /dev/null +++ b/src/OperaAPI/OperaAPI_addVolume.cpp @@ -0,0 +1,89 @@ +// 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_addVolume.h" + +#include +#include + +//================================================================================================== +OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +//================================================================================================== +OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theMedium, + const std::list& theObjectList) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); + setObjectList(theObjectList); + } +} + +//================================================================================================== +OperaAPI_addVolume::~OperaAPI_addVolume() {} + +//================================================================================================== +void OperaAPI_addVolume::setMedium(const ModelHighAPI_Double& theMedium) +{ + fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); + + execute(); +} + +//================================================================================================== +void OperaAPI_addVolume::setObjectList(const std::list& theObjectList) +{ + fillAttribute(theObjectList, myvolumeList); + + execute(); +} + +//================================================================================================== +void OperaAPI_addVolume::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeStringPtr anAttrMedium = aBase->string(OperaPlugin_Volume::MEDIUM()); + theDumper << aBase << " = model.addVolume(" << aDocName << ", " << anAttrMedium << ", "; + + AttributeSelectionListPtr anAttrList = aBase->selectionList(OperaPlugin_Volume::VOLUME_LIST_ID()); + if (anAttrList->isWholeResultAllowed() && !anAttrList->selectionType().empty()) + theDumper<<"\""<selectionType()<<"\", "; + theDumper << anAttrList; + if (anAttrList->isGeometricalSelection()) + theDumper <<", True"; + theDumper << ")" << std::endl; +} + +//================================================================================================== +VolumePtr addVolume(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theMedium, + const std::list& theObjectList) +{ + std::shared_ptr aFeature = thePart->addFeature(OperaAPI_addVolume::ID()); + aFeature->selectionList(OperaPlugin_Volume::VOLUME_LIST_ID())->setGeometricalSelection(true); + return VolumePtr(new OperaAPI_addVolume(aFeature, theMedium, theObjectList)); +} diff --git a/src/OperaAPI/OperaAPI_addVolume.h b/src/OperaAPI/OperaAPI_addVolume.h new file mode 100644 index 000000000..6205698af --- /dev/null +++ b/src/OperaAPI/OperaAPI_addVolume.h @@ -0,0 +1,81 @@ +// 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_ADDVOLUME_H_ +#define OPERAAPI_ADDVOLUME_H_ + +#include "OperaAPI.h" +#include + +#include +#include + +class ModelHighAPI_Double; +class ModelHighAPI_Selection; + +/// \class OperaAPI_addVolume +/// \ingroup CPPHighAPI +/// \brief Interface for primitive Box feature. +class OperaAPI_addVolume: public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + OPERAAPI_EXPORT + explicit OperaAPI_addVolume(const std::shared_ptr& theFeature); + + /// Constructor with values. + OPERAAPI_EXPORT + OperaAPI_addVolume(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theMedium, + const std::list& theObjectList); + + /// Destructor. + OPERAAPI_EXPORT + virtual ~OperaAPI_addVolume(); + + INTERFACE_2(OperaPlugin_Volume::ID(), + medium, OperaPlugin_Volume::MEDIUM(), + ModelAPI_AttributeString, /** Volume medium */, + volumeList, OperaPlugin_Volume::VOLUME_LIST_ID(), + ModelAPI_AttributeSelectionList, /** Group list*/) + + /// Set medium + OPERAAPI_EXPORT + void setMedium(const ModelHighAPI_Double& theMedium); + + /// Set main objects list. + OPERAAPI_EXPORT + void setObjectList(const std::list& theObjectList); + + /// Dump wrapped feature + OPERAAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer addVolume feature +typedef std::shared_ptr VolumePtr; + +/// \ingroup CPPHighAPI +/// \brief Create addVolume feature. +OPERAAPI_EXPORT +VolumePtr addVolume(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theMedium, + const std::list& theObjectList); + +#endif // OperaAPI_addVolume_H_ diff --git a/src/OperaPlugin/CMakeLists.txt b/src/OperaPlugin/CMakeLists.txt new file mode 100644 index 000000000..be7b24ea5 --- /dev/null +++ b/src/OperaPlugin/CMakeLists.txt @@ -0,0 +1,66 @@ +# 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 + addvolume_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) + + 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..25c7762ec --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Plugin.cpp @@ -0,0 +1,47 @@ +// 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 + +// 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 { + // else if (theFeatureID == OperaPlugin_addNode::ID()){ + // return FeaturePtr(new OperaPlugin_addNode); + return FeaturePtr(); + } +} diff --git a/src/OperaPlugin/OperaPlugin_Plugin.h b/src/OperaPlugin/OperaPlugin_Plugin.h new file mode 100644 index 000000000..b4fd54ca7 --- /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 Primitive 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..709364328 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Volume.cpp @@ -0,0 +1,124 @@ +// 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 + +#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(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(VOLUME_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + + // // //Get Objects + // AttributeSelectionListPtr aList = std::dynamic_pointer_cast( + // data()->addAttribute(LIST_ID(), ModelAPI_AttributeSelectionList::typeId())); + // aList->setWholeResultAllowed(true); // allow to select the whole result +} + +//================================================================================================= +void OperaPlugin_Volume::execute() +{ + std::string aCopiesMedium = string(MEDIUM())->value(); + if (aCopiesMedium.empty()) + { + setError("Error: Medium cannot be empty."); + return; + } + + AttributeSelectionListPtr aList = selectionList(VOLUME_LIST_ID()); + int aResultIndex = 0; + std::set anExistingNames; // to avoid names duplication + for (int aSelIndex = 0; aSelIndex < aList->size(); aSelIndex++) { + AttributeSelectionPtr aSel = aList->value(aSelIndex); + GeomShapePtr aResult = shapeOfSelection(aSel); + if (!aResult.get()) + continue; + // std::shared_ptr aCopyBuilder(new GeomAlgoAPI_Copy(aShape, false, false)); + // std::string anError; + // if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aCopyBuilder, getKind(), anError)) { + // setError(anError); + // return; + // } + // GeomShapePtr aResult = aCopyBuilder->shape(); + + std::wstring aBaseName = aSel->context() ? aSel->context()->data()->name() : + aSel->contextFeature()->firstResult()->data()->name(); + std::wstring aName; + int anInd = 0; + do { + anInd++; + std::wostringstream aNameStr; + aNameStr << "Volume_" << aBaseName; + aName = aNameStr.str(); + } while (anExistingNames.count(aName)); + anExistingNames.insert(aName); + + std::shared_ptr aResultBody = document()->createBody(data(), aResultIndex); + aResultBody->data()->setName(aName); + // to make sub-results also names with a similar name temporarily rename the feature + // std::wstring anOrigName = name(); + // data()->setName(aBaseName); + aResultBody->store(aResult); + // data()->setName(anOrigName); + // aResultBody->loadFirstLevel(aResult, "Copy"); + setResult(aResultBody, aResultIndex++); + } + removeResults(aResultIndex); +} diff --git a/src/OperaPlugin/OperaPlugin_Volume.h b/src/OperaPlugin/OperaPlugin_Volume.h new file mode 100644 index 000000000..1480ebb48 --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_Volume.h @@ -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 +// + +#ifndef OperaPlugin_Volume_H_ +#define OperaPlugin_Volume_H_ + +#include +#include +#include + +class GeomAPI_Shape; +class ModelAPI_ResultBody; + +/**\class OperaPlugin_Volume + * \ingroup Plugins + * \brief Feature for creation of a box primitive using various methods. + * + * Box creates a cuboid - Parallelepiped with 6 rectangular faces. It can be built via three + * methods : using two points that define a diagonal, a point that define a center and 3 lengths + * that define the half-lengths on X, Y and Z-axes, or using 3 lengths that define the + * rectangular dimensions. + */ +class OperaPlugin_Volume : public ModelAPI_Feature +{ + public: + /// Box kind + inline static const std::string& ID() + { + static const std::string MY_VOLUME_ID("addVolume"); + return MY_VOLUME_ID; + } + inline static const std::string& MEDIUM() + { + static const std::string MY_MEDIUM_ID("medium"); + return MY_MEDIUM_ID; + } + /// attribute name of selected entities list + inline static const std::string& VOLUME_LIST_ID() + { + static const std::string MY_VOLUME_LIST_ID("volume_list"); + return MY_VOLUME_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(); + + private: + // + void loadNamingDS(std::shared_ptr theBoxAlgo, + std::shared_ptr theResultBox); +}; + +#endif diff --git a/src/OperaPlugin/OperaPlugin_msg_fr.ts b/src/OperaPlugin/OperaPlugin_msg_fr.ts new file mode 100644 index 000000000..22d0de57f --- /dev/null +++ b/src/OperaPlugin/OperaPlugin_msg_fr.ts @@ -0,0 +1,408 @@ + + + + + + workshop + + Primitives + Primitives + + + Box + Boîte + + + Cone + Cône + + + Cylinder + Cylindre + + + Sphere + Sphère + + + Torus + Tore + + + + + Box + + Box + Boîte + + + Create a box + Créer une boîte + + + + Box:CreationMethod + + By dimensions + Par dimensions + + + By two points + Par deux points + + + + Box:FirstPoint + + First point + Premier point + + + Select a first point + Sélectionnez un premier point + + + + Box:FirstPoint + + Attribute "%1" is not initialized. + Sélectionnez un premier point. + + + + Box:SecondPoint + + Attribute "%1" is not initialized. + Sélectionnez un deuxième point. + + + + Box:SecondPoint + + Second point + Deuxième point + + + Select a second point + Sélectionnez un deuxième point + + + + Box:dx + + DX + DX + + + Dimension in X + Dimension en X + + + + Box:dy + + DY + DY + + + Dimension in Y + Dimension en Y + + + + Box:dz + + DZ + DZ + + + Dimension in Z + Dimension en Z + + + + + Cone + + Cone + Cône + + + Create a Cone + Créer un cône + + + + Cone:axis + + Select the axis of the cone + Sélectionnez l'axe du cône + + + Attribute "%1" is not initialized. + Sélectionnez l'axe du cône + + + axis + axe + + + + Cone:base_point + + Select the center of the base of the cone + Sélectionnez le centre de la base du cône + + + base_point + point de base + + + + Cone:base_radius + + Base radius + Rayon de la base + + + Enter the base radius of the cone + Entrez le rayon de base du cône + + + + Cone:height + + Enter the height of the cone + Entrez la hauteur du cône + + + height + hauteur + + + + Cone:top_radius + + Enter the top radius of the cone + Entrez le rayon supérieur du cône + + + Top radius + Rayon supérieur + + + + Cone:base_point + + Attribute "%1" is not initialized. + Sélectionnez le centre de la base du cône. + + + + Cone:base_point:GeomValidators_ConstructionComposite + + The result is empty + Le résultat est vide + + + + + Cylinder + + Create a cylinder + Créer un cylindre + + + Cylinder + Cylindre + + + + Cylinder:CreationMethod + + Cylinder + Cylindre + + + Portion of cylinder + Portion de cylindre + + + + Cylinder:angle + + Enter the angle of the portion of the cylinder + Entrez l'angle de la portion du cylindre + + + angle + angle + + + + Cylinder:axis + + Select the axis of the cylinder + Sélectionnez l'axe du cylindre. + + + Attribute "%1" is not initialized. + Sélectionnez l'axe du cylindre. + + + axis + axe + + + + Cylinder:base_point + + Select the center of the base of the cylinder + Sélectionnez le centre de la base du cylindre + + + base_point + point de base + + + + Cylinder:height + + Enter the height of the cylinder + Entrez la hauteur du cylindre + + + height + hauteur + + + + Cylinder:radius + + Enter the radius of the cylinder + Entrez le rayon du cylindre + + + radius + rayon + + + + Cylinder:base_point + + Attribute "%1" is not initialized. + Sélectionnez le centre de la base du cylindre. + + + + Cylinder:base_point:GeomValidators_ConstructionComposite + + The result is empty + Le résultat est vide + + + + + Sphere + + Create a sphere + Créer une sphère + + + Sphere + Sphère + + + + Sphere:center_point + + Center point + Point central + + + Select a center point + Sélectionnez un point central. + + + Attribute "%1" is not initialized. + Sélectionnez un point central. + + + + Sphere:radius + + Enter a radius + Entrez un rayon + + + Radius + Rayon + + + + + Torus + + Create a Torus + Créer un tore + + + Torus + Tore + + + + Torus:axis + + Select the axis of the torus + Sélectionnez l'axe du tore. + + + Attribute "%1" is not initialized. + Sélectionnez l'axe du tore. + + + axis + axe + + + + Torus:base_point + + Select the center of the torus + Sélectionnez le centre du tore. + + + Attribute "%1" is not initialized. + Sélectionnez le centre du tore. + + + base_point + point de base + + + + Torus:radius + + Enter the radius of the torus + Entrez le rayon du tore + + + Radius + Rayon + + + + Torus:ring_radius + + Enter the ring radius of the torus + Entrez le rayon de l'anneau du tore + + + Ring radius + Rayon de l'anneau + + + + diff --git a/src/OperaPlugin/Test/TestAddVolume.py b/src/OperaPlugin/Test/TestAddVolume.py new file mode 100644 index 000000000..a8b70d72c --- /dev/null +++ b/src/OperaPlugin/Test/TestAddVolume.py @@ -0,0 +1,83 @@ +# 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 +# + +""" + TestAddVolume.py + Test case of OperaPlugin_addVolume +""" +#========================================================================= +# 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 a Box, a Torus and a Cylinder +#========================================================================= +Box_1 = model.addBox(Part_1_doc, 10, 20, 10) +Torus_1 = model.addTorus(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 15, 3) +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10) + +#========================================================================= +# Create one Volume +#========================================================================= + +Volume_1 = model.addVolume(Part_1_doc, "Test_medium", [model.selection("SOLID", "Box_1")]) + +#========================================================================= +# Check results +#========================================================================= + +from GeomAPI import GeomAPI_Shape + +# TODO : Check this +# TODO : Do I need a testNbVolume ?? +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) + +#========================================================================= +# Create two volumes at once +#========================================================================= + +Volume_2 = model.addVolume(Part_1_doc, "Test_medium_2", [model.selection("SOLID", "Torus_1"), + model.selection("SOLID", "Cylinder_1")]) + +#========================================================================= +# Check results +#========================================================================= + +# TODO : Check this + +model.testNbResults(Volume_2, 2) +model.testNbSubResults(Volume_2, [0]) +model.testNbSubShapes(Volume_2, GeomAPI_Shape.SOLID, [2]) + +#========================================================================= +# End of test +#========================================================================= + +from salome.shaper import model +assert(model.checkPythonDump()) diff --git a/src/OperaPlugin/addvolume_widget.xml b/src/OperaPlugin/addvolume_widget.xml new file mode 100644 index 000000000..042e18492 --- /dev/null +++ b/src/OperaPlugin/addvolume_widget.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/src/OperaPlugin/doc/addvolumeFeature.rst b/src/OperaPlugin/doc/addvolumeFeature.rst new file mode 100644 index 000000000..e91466c20 --- /dev/null +++ b/src/OperaPlugin/doc/addvolumeFeature.rst @@ -0,0 +1,136 @@ +.. |Box_button.icon| image:: images/Box_button.png + +Box +=== + +Box feature creates a box solid. + +To create a Box in the active part: + +#. select in the Main Menu *Primitives - > Box* item or +#. click |Box_button.icon| **Box** button in the toolbar: + +There are 3 algorithms for creation of a Box: + +.. figure:: images/box_dxyz_32x32.png + :align: left + :height: 24px + +**By dimensions** + +.. figure:: images/box_2pt_32x32.png + :align: left + :height: 24px + +**By two points** + +.. figure:: images/box_pt_dxyz_32x32.png + :align: left + :height: 24px + +**By coordinates of a point and dimensions** + +-------------------------------------------------------------------------------- + +By dimensions +------------- + +Box is created by dimensions along X, Y, Z axis starting from the origin. + +.. figure:: images/Box_dimensions.png + :align: center + +Input fields: + +- **DX**, **DY**, **DZ** define dimensions of the box along the corresponding coordinate axes. + +**TUI Command**: + +.. py:function:: model.addBox(Part_doc, DX, DY, DZ) + + :param part: The current part object. + :param real: Size along X. + :param real: Size along Y. + :param real: Size along Z. + :return: Result object. + +Result +"""""" + +A solid box based on the origin of coordinates and with edges parallel to the coordinate axes. + +.. figure:: images/Box1.png + :align: center + +**See Also** a sample TUI Script of a :ref:`tui_create_boxdim` operation. + +By two points +------------- + +Box is created by two points of the box diagonal. + +.. figure:: images/Box_2points.png + :align: center + +Input fields: + +- **Point 1** and **Point 2** define diagonal points of the box selected in 3D OCC viewer or object browser. + +**TUI Command**: + +.. py:function:: model.addBox(Part_doc, point1, point2) + + :param part: The current part object. + :param object: First vertex of diagonal. + :param object: Second vertex of diagonal. + :return: Result object. + +Result +"""""" + +A solid box based on two points and with edges parallel to the coordinate axes. + +.. figure:: images/Box2.png + :align: center + + Created boxes + +**See Also** a sample TUI Script of :ref:`tui_create_boxpnt` operation. + +By coordinates of a point and dimensions +---------------------------------------- + +Box is created by dimensions along X, Y, Z axis starting from the point of coordinates (x,y,z). + +.. figure:: images/Box_ptAndDims.png + :align: center + +Input fields: + +- **OX**, **OY**, **OZ** define coordinates of the center of box. +- **DX**, **DY**, **DZ** define dimensions (hafl length) of the box along the corresponding coordinate axes. + +**TUI Command**: + +.. py:function:: model.addBox(Part_doc, OX, OY, OZ, DX, DY, DZ) + + :param part: The current part object. + :param real: X coordinate of the center point + :param real: Y coordinate of the center point + :param real: Z coordinate of the center point + :param real: Half size along X. + :param real: Half size along Y. + :param real: Half size along Z. + :return: Result object. + +Result +"""""" + +A solid box whose point coordinates are the center and the dimensions are half lengths on one side and the other on the axes relative to the center. + +.. figure:: images/Box3.png + :align: center + + Created boxes + +**See Also** a sample TUI Script of :ref:`tui_create_boxptdim` operation. diff --git a/src/OperaPlugin/icons/addVolume.png b/src/OperaPlugin/icons/addVolume.png new file mode 100644 index 0000000000000000000000000000000000000000..2b0757b055f0b982a04cb52ab53c3379201c1720 GIT binary patch literal 528 zcmV+r0`L8aP)JbVQ%cRr!A&B|pKN<0S6TADd;jclklM62=H^q+<@gwOR+B!^n@>TR2>pR;iRgul~ zD|EDWS2Cne-7T({{_dU%tHpv`@8U-JYJ!xzOhDc z^ZDfk)>$>#31HaRqEcG&Io zT@(QT903azn9OSU_^2X$d?e~^mn6|TGd^W<@I1}TIRIpScCOHBvFN!_6a^#G6H*z^ z8^6zJE+HTOalzyB6BwZWsUVh!V{vs^VvKmWpTB4GkceYpc~MGfs#`b+M)E3nh{xa$ zEJ?Dax`q8<1o*szU%|krKd>aqvg{TPLnmK3;ak1W3@G`jfDoi8HMC{Q0Pq3wp^%jP S=9FOo0000=Iz)3 literal 0 HcmV?d00001 diff --git a/src/OperaPlugin/plugin-Opera.xml b/src/OperaPlugin/plugin-Opera.xml new file mode 100644 index 000000000..97914e06a --- /dev/null +++ b/src/OperaPlugin/plugin-Opera.xml @@ -0,0 +1,10 @@ + + + + + + + + + diff --git a/src/OperaPlugin/tests.set b/src/OperaPlugin/tests.set new file mode 100644 index 000000000..805968390 --- /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 + TestAddVolume.py +) 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 -- 2.39.2