From: Nicolas RECHATIN Date: Thu, 22 Jul 2021 14:24:14 +0000 (+0200) Subject: swig OperaAPI files - not tested X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=532d7a239667a2b1286e21a47f8a9adeec72e1cb;p=modules%2Fshaper.git swig OperaAPI files - not tested --- 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..380623402 --- /dev/null +++ b/src/OperaAPI/OperaAPI_addVolume.cpp @@ -0,0 +1,97 @@ +// 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& theVolumeList) +: ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setMedium(theMedium); + setVolumeList(theVolumeList); + } +} + +//================================================================================================== +OperaAPI_addVolume::~OperaAPI_addVolume() {} + +//================================================================================================== +void OperaAPI_addVolume::setMedium(const ModelHighAPI_Double& theMedium) +{ + fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); + + execute(); +} + +//================================================================================================== +void OperaAPI_addVolume::setVolumeList(const std::list& theVolumeList) +{ + fillAttribute(theVolumeList, 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::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) +{ + std::shared_ptr aFeature = thePart->addFeature(OperaAPI_addVolume::ID()); + return VolumePtr(new OperaAPI_addVolume(aFeature)); +} + +//================================================================================================== +VolumePtr addVolume(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theMedium, + const std::list& theVolumeList) +{ + std::shared_ptr aFeature = thePart->addFeature(OperaAPI_addVolume::ID()); + aFeature->selectionList(OperaPlugin_Volume::LIST_ID())->setGeometricalSelection(true); + return VolumePtr(new OperaAPI_addVolume(aFeature, theMedium, theVolumeList)); +} diff --git a/src/OperaAPI/OperaAPI_addVolume.h b/src/OperaAPI/OperaAPI_addVolume.h new file mode 100644 index 000000000..913e4d8d3 --- /dev/null +++ b/src/OperaAPI/OperaAPI_addVolume.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 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& theVolumeList); + + /// Destructor. + OPERAAPI_EXPORT + virtual ~OperaAPI_addVolume(); + + INTERFACE_2(OperaPlugin_Volume::ID(), + medium, OperaPlugin_Volume::MEDIUM(), + ModelAPI_AttributeString, /** Volume medium */, + volumeList, OperaPlugin_Volume::LIST_ID(), + ModelAPI_AttributeSelectionList, /** Group list*/) + + /// Set medium + OPERAAPI_EXPORT + void setMedium(const ModelHighAPI_Double& theMedium); + + /// Set main objects list. + OPERAAPI_EXPORT + void setVolumeList(const std::list& theVolumeList); + + /// 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& theVolumeList); + +#endif // OperaAPI_addVolume_H_ diff --git a/src/OperaPlugin/OperaPlugin_Volume.cpp b/src/OperaPlugin/OperaPlugin_Volume.cpp index c033b9302..e8e4c3a9a 100644 --- a/src/OperaPlugin/OperaPlugin_Volume.cpp +++ b/src/OperaPlugin/OperaPlugin_Volume.cpp @@ -27,6 +27,9 @@ #include #include +#include +#include + #include #include #include @@ -36,22 +39,88 @@ 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(OperaPlugin_Volume::MEDIUM(), ModelAPI_AttributeString::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 + data()->addAttribute(MEDIUM(), ModelAPI_AttributeString::typeId()); + data()->addAttribute(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() { - if (results().empty() || firstResult()->isDisabled()) { // just create result if not exists - ResultPtr aVolume = document()->createVolume(data()); - setResult(aVolume); + std::string aCopiesMedium = string(MEDIUM())->value(); + if (aCopiesMedium.empty()) + { + setError("Error: Medium cannot be empty."); + return; + } + + AttributeSelectionListPtr aList = selectionList(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 aShape = shapeOfSelection(aSel); + if (!aShape.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 << "_" << (aSelIndex + anInd); + aName = aNameStr.str(); + } while (anExistingNames.count(aName)); + anExistingNames.insert(aName); + + std::shared_ptr aResultVolume = document()->createVolume(data(), aResultIndex); + aResultVolume->data()->setName(aName); + // to make sub-results also names with a similar name temporarily rename the feature + std::wstring anOrigName = name(); + data()->setName(aBaseName); + + aResultVolume->store(aResult); //TODO : CRASH, works with BODY + + data()->setName(anOrigName); + aResultVolume->loadFirstLevel(aResult, "Copy"); + setResult(aResultVolume, aResultIndex++); } + removeResults(aResultIndex); } 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