--- /dev/null
+# 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})
--- /dev/null
+// 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
--- /dev/null
+// 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 <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Tools.h>
+
+//==================================================================================================
+OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+ initialize();
+}
+
+//==================================================================================================
+OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Double& theMedium,
+ const std::list<ModelHighAPI_Selection>& 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<ModelHighAPI_Selection>& 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<<"\""<<anAttrList->selectionType()<<"\", ";
+ theDumper << anAttrList;
+ if (anAttrList->isGeometricalSelection())
+ theDumper <<", True";
+ theDumper << ")" << std::endl;
+}
+
+//==================================================================================================
+VolumePtr addVolume(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theMedium)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(OperaAPI_addVolume::ID());
+ return VolumePtr(new OperaAPI_addVolume(aFeature));
+}
+
+//==================================================================================================
+VolumePtr addVolume(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theMedium,
+ const std::list<ModelHighAPI_Selection>& theVolumeList)
+{
+ std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(OperaAPI_addVolume::ID());
+ aFeature->selectionList(OperaPlugin_Volume::LIST_ID())->setGeometricalSelection(true);
+ return VolumePtr(new OperaAPI_addVolume(aFeature, theMedium, theVolumeList));
+}
--- /dev/null
+// 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 <OperaPlugin_Volume.h>
+
+#include <ModelHighAPI_Interface.h>
+#include <ModelHighAPI_Macro.h>
+
+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<ModelAPI_Feature>& theFeature);
+
+ /// Constructor with values.
+ OPERAAPI_EXPORT
+ OperaAPI_addVolume(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+ const ModelHighAPI_Double& theMedium,
+ const std::list<ModelHighAPI_Selection>& 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<ModelHighAPI_Selection>& theVolumeList);
+
+ /// Dump wrapped feature
+ OPERAAPI_EXPORT
+ virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer addVolume feature
+typedef std::shared_ptr<OperaAPI_addVolume> VolumePtr;
+
+/// \ingroup CPPHighAPI
+/// \brief Create addVolume feature.
+OPERAAPI_EXPORT
+VolumePtr addVolume(const std::shared_ptr<ModelAPI_Document>& thePart,
+ const ModelHighAPI_Double& theMedium,
+ const std::list<ModelHighAPI_Selection>& theVolumeList);
+
+#endif // OperaAPI_addVolume_H_
#include <ModelAPI_ResultVolume.h>
#include <ModelAPI_Tools.h>
+#include <GeomAlgoAPI_Copy.h>
+#include <GeomAlgoAPI_Tools.h>
+
#include <sstream>
#include <memory>
#include <iostream>
{
}
+//=================================================================================================
+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<ModelAPI_AttributeSelectionList>(
- 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<ModelAPI_AttributeSelectionList>(
+ // 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<std::wstring> 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<GeomAlgoAPI_Copy> 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<ModelAPI_ResultVolume> 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);
}
--- /dev/null
+# 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