From 25f46537f08b316f7174a5fb5cbd7b2dcdf7f549 Mon Sep 17 00:00:00 2001 From: Nicolas RECHATIN Date: Thu, 29 Jul 2021 13:52:26 +0200 Subject: [PATCH] volume v1.0 working, check test --- CMakeLists.txt | 1 + src/OperaAPI/CMakeLists.txt | 4 +- src/OperaAPI/OperaAPI.h | 2 +- ...aAPI_addVolume.cpp => OperaAPI_Volume.cpp} | 22 +++++----- ...OperaAPI_addVolume.h => OperaAPI_Volume.h} | 40 +++++++++---------- src/OperaPlugin/CMakeLists.txt | 2 +- src/OperaPlugin/OperaPlugin_Volume.cpp | 8 ++-- src/OperaPlugin/OperaPlugin_Volume.h | 2 +- .../Test/{TestAddVolume.py => TestVolume.py} | 8 ++-- src/OperaPlugin/plugin-Opera.xml | 10 ++--- src/OperaPlugin/tests.set | 2 +- ...addvolume_widget.xml => volume_widget.xml} | 0 src/PythonAPI/Test/TestFeatures.py | 3 ++ src/PythonAPI/model/opera/__init__.py | 2 +- 14 files changed, 56 insertions(+), 50 deletions(-) rename src/OperaAPI/{OperaAPI_addVolume.cpp => OperaAPI_Volume.cpp} (79%) rename src/OperaAPI/{OperaAPI_addVolume.h => OperaAPI_Volume.h} (61%) rename src/OperaPlugin/Test/{TestAddVolume.py => TestVolume.py} (92%) rename src/OperaPlugin/{addvolume_widget.xml => volume_widget.xml} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18d0dd973..0e36ac329 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,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/OperaAPI/CMakeLists.txt b/src/OperaAPI/CMakeLists.txt index 009c9f63b..bd057baf0 100644 --- a/src/OperaAPI/CMakeLists.txt +++ b/src/OperaAPI/CMakeLists.txt @@ -21,11 +21,11 @@ INCLUDE(Common) SET(PROJECT_HEADERS OperaAPI.h - OperaAPI_addVolume.h + OperaAPI_Volume.h ) SET(PROJECT_SOURCES - OperaAPI_addVolume.cpp + OperaAPI_Volume.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/OperaAPI/OperaAPI.h b/src/OperaAPI/OperaAPI.h index 093042bb2..8a1808b1e 100644 --- a/src/OperaAPI/OperaAPI.h +++ b/src/OperaAPI/OperaAPI.h @@ -34,4 +34,4 @@ #endif #endif -#endif //PRIMITIVESAPI_H +#endif //OPERAAPI_H diff --git a/src/OperaAPI/OperaAPI_addVolume.cpp b/src/OperaAPI/OperaAPI_Volume.cpp similarity index 79% rename from src/OperaAPI/OperaAPI_addVolume.cpp rename to src/OperaAPI/OperaAPI_Volume.cpp index 8764ba593..b90926804 100644 --- a/src/OperaAPI/OperaAPI_addVolume.cpp +++ b/src/OperaAPI/OperaAPI_Volume.cpp @@ -17,20 +17,20 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "OperaAPI_addVolume.h" +#include "OperaAPI_Volume.h" #include #include //================================================================================================== -OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& theFeature) +OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFeature) : ModelHighAPI_Interface(theFeature) { initialize(); } //================================================================================================== -OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& theFeature, +OperaAPI_Volume::OperaAPI_Volume(const std::shared_ptr& theFeature, const ModelHighAPI_Double& theMedium, const std::list& theObjectList) : ModelHighAPI_Interface(theFeature) @@ -42,10 +42,10 @@ OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& } //================================================================================================== -OperaAPI_addVolume::~OperaAPI_addVolume() {} +OperaAPI_Volume::~OperaAPI_Volume() {} //================================================================================================== -void OperaAPI_addVolume::setMedium(const ModelHighAPI_Double& theMedium) +void OperaAPI_Volume::setMedium(const ModelHighAPI_Double& theMedium) { fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); @@ -53,7 +53,7 @@ void OperaAPI_addVolume::setMedium(const ModelHighAPI_Double& theMedium) } //================================================================================================== -void OperaAPI_addVolume::setObjectList(const std::list& theObjectList) +void OperaAPI_Volume::setObjectList(const std::list& theObjectList) { fillAttribute(theObjectList, myvolumeList); @@ -61,13 +61,13 @@ void OperaAPI_addVolume::setObjectList(const std::list& } //================================================================================================== -void OperaAPI_addVolume::dump(ModelHighAPI_Dumper& theDumper) const +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()); - theDumper << aBase << " = model.addVolume(" << aDocName << ", " << anAttrMedium << ", "; + theDumper << aBase << " = model.Volume(" << aDocName << ", " << anAttrMedium << ", "; AttributeSelectionListPtr anAttrList = aBase->selectionList(OperaPlugin_Volume::VOLUME_LIST_ID()); if (anAttrList->isWholeResultAllowed() && !anAttrList->selectionType().empty()) @@ -79,11 +79,11 @@ void OperaAPI_addVolume::dump(ModelHighAPI_Dumper& theDumper) const } //================================================================================================== -VolumePtr addVolume(const std::shared_ptr& thePart, +VolumePtr Volume(const std::shared_ptr& thePart, const ModelHighAPI_Double& theMedium, const std::list& theObjectList) { - std::shared_ptr aFeature = thePart->addFeature(OperaAPI_addVolume::ID()); + std::shared_ptr aFeature = thePart->addFeature(OperaAPI_Volume::ID()); aFeature->selectionList(OperaPlugin_Volume::VOLUME_LIST_ID())->setGeometricalSelection(true); - return VolumePtr(new OperaAPI_addVolume(aFeature, theMedium, theObjectList)); + return VolumePtr(new OperaAPI_Volume(aFeature, theMedium, theObjectList)); } diff --git a/src/OperaAPI/OperaAPI_addVolume.h b/src/OperaAPI/OperaAPI_Volume.h similarity index 61% rename from src/OperaAPI/OperaAPI_addVolume.h rename to src/OperaAPI/OperaAPI_Volume.h index 6205698af..cf7f49045 100644 --- a/src/OperaAPI/OperaAPI_addVolume.h +++ b/src/OperaAPI/OperaAPI_Volume.h @@ -17,8 +17,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef OPERAAPI_ADDVOLUME_H_ -#define OPERAAPI_ADDVOLUME_H_ +#ifndef OPERAAPI_VOLUME_H_ +#define OPERAAPI_VOLUME_H_ #include "OperaAPI.h" #include @@ -29,31 +29,31 @@ class ModelHighAPI_Double; class ModelHighAPI_Selection; -/// \class OperaAPI_addVolume +/// \class OperaAPI_Volume /// \ingroup CPPHighAPI /// \brief Interface for primitive Box feature. -class OperaAPI_addVolume: public ModelHighAPI_Interface +class OperaAPI_Volume: public ModelHighAPI_Interface { public: /// Constructor without values. OPERAAPI_EXPORT - explicit OperaAPI_addVolume(const std::shared_ptr& theFeature); + explicit OperaAPI_Volume(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); + OperaAPI_Volume(const std::shared_ptr& theFeature, + const ModelHighAPI_Double& theMedium, + const std::list& theObjectList); /// Destructor. OPERAAPI_EXPORT - virtual ~OperaAPI_addVolume(); + virtual ~OperaAPI_Volume(); INTERFACE_2(OperaPlugin_Volume::ID(), - medium, OperaPlugin_Volume::MEDIUM(), - ModelAPI_AttributeString, /** Volume medium */, - volumeList, OperaPlugin_Volume::VOLUME_LIST_ID(), - ModelAPI_AttributeSelectionList, /** Group list*/) + medium, OperaPlugin_Volume::MEDIUM(), + ModelAPI_AttributeString, /** Volume medium */, + volumeList, OperaPlugin_Volume::VOLUME_LIST_ID(), + ModelAPI_AttributeSelectionList, /** Group list*/) /// Set medium OPERAAPI_EXPORT @@ -68,14 +68,14 @@ public: virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; -/// Pointer addVolume feature -typedef std::shared_ptr VolumePtr; +/// Pointer Volume feature +typedef std::shared_ptr VolumePtr; /// \ingroup CPPHighAPI -/// \brief Create addVolume feature. +/// \brief Create Volume feature. OPERAAPI_EXPORT -VolumePtr addVolume(const std::shared_ptr& thePart, - const ModelHighAPI_Double& theMedium, - const std::list& theObjectList); +VolumePtr Volume(const std::shared_ptr& thePart, + const ModelHighAPI_Double& theMedium, + const std::list& theObjectList); -#endif // OperaAPI_addVolume_H_ +#endif // OperaAPI_Volume_H_ diff --git a/src/OperaPlugin/CMakeLists.txt b/src/OperaPlugin/CMakeLists.txt index be7b24ea5..fd574c6b8 100644 --- a/src/OperaPlugin/CMakeLists.txt +++ b/src/OperaPlugin/CMakeLists.txt @@ -31,7 +31,7 @@ SET(PROJECT_SOURCES SET(XML_RESOURCES plugin-Opera.xml - addvolume_widget.xml + volume_widget.xml ) SET(TEXT_RESOURCES diff --git a/src/OperaPlugin/OperaPlugin_Volume.cpp b/src/OperaPlugin/OperaPlugin_Volume.cpp index 571e481e5..1a285745e 100644 --- a/src/OperaPlugin/OperaPlugin_Volume.cpp +++ b/src/OperaPlugin/OperaPlugin_Volume.cpp @@ -64,7 +64,7 @@ void OperaPlugin_Volume::initAttributes() { // Get Medium data()->addAttribute(MEDIUM(), ModelAPI_AttributeString::typeId()); - + // Get Objects data()->addAttribute(VOLUME_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); } @@ -101,9 +101,11 @@ void OperaPlugin_Volume::execute() aResult = aSel->context()->shape(); } - std::set anExistingNames; - std::wstring aBaseName = aSel->context()->name(); + // Handle naming : Volume_ std::wstring aName; + std::set anExistingNames; + std::wstring aBaseName = aSel->context() ? aSel->context()->data()->name() : + aSel->contextFeature()->firstResult()->data()->name(); int anInd = 0; do { anInd++; diff --git a/src/OperaPlugin/OperaPlugin_Volume.h b/src/OperaPlugin/OperaPlugin_Volume.h index 1480ebb48..a31e92176 100644 --- a/src/OperaPlugin/OperaPlugin_Volume.h +++ b/src/OperaPlugin/OperaPlugin_Volume.h @@ -42,7 +42,7 @@ class OperaPlugin_Volume : public ModelAPI_Feature /// Box kind inline static const std::string& ID() { - static const std::string MY_VOLUME_ID("addVolume"); + static const std::string MY_VOLUME_ID("Volume"); return MY_VOLUME_ID; } inline static const std::string& MEDIUM() diff --git a/src/OperaPlugin/Test/TestAddVolume.py b/src/OperaPlugin/Test/TestVolume.py similarity index 92% rename from src/OperaPlugin/Test/TestAddVolume.py rename to src/OperaPlugin/Test/TestVolume.py index a8b70d72c..09da4da42 100644 --- a/src/OperaPlugin/Test/TestAddVolume.py +++ b/src/OperaPlugin/Test/TestVolume.py @@ -18,8 +18,8 @@ # """ - TestAddVolume.py - Test case of OperaPlugin_addVolume + TestVolume.py + Test case of OperaPlugin_Volume """ #========================================================================= # Initialization of the test @@ -42,7 +42,7 @@ Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Or # Create one Volume #========================================================================= -Volume_1 = model.addVolume(Part_1_doc, "Test_medium", [model.selection("SOLID", "Box_1")]) +Volume_1 = model.Volume(Part_1_doc, "Test_medium", [model.selection("SOLID", "Box_1")]) #========================================================================= # Check results @@ -62,7 +62,7 @@ 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"), +Volume_2 = model.Volume(Part_1_doc, "Test_medium_2", [model.selection("SOLID", "Torus_1"), model.selection("SOLID", "Cylinder_1")]) #========================================================================= diff --git a/src/OperaPlugin/plugin-Opera.xml b/src/OperaPlugin/plugin-Opera.xml index 3fe8fce5e..9691814c6 100644 --- a/src/OperaPlugin/plugin-Opera.xml +++ b/src/OperaPlugin/plugin-Opera.xml @@ -2,13 +2,13 @@ - + helpfile="volumeFeature.html"> + diff --git a/src/OperaPlugin/tests.set b/src/OperaPlugin/tests.set index 805968390..019d00b2f 100644 --- a/src/OperaPlugin/tests.set +++ b/src/OperaPlugin/tests.set @@ -18,5 +18,5 @@ # SET(TEST_NAMES - TestAddVolume.py + TestVolume.py ) diff --git a/src/OperaPlugin/addvolume_widget.xml b/src/OperaPlugin/volume_widget.xml similarity index 100% rename from src/OperaPlugin/addvolume_widget.xml rename to src/OperaPlugin/volume_widget.xml 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/opera/__init__.py b/src/PythonAPI/model/opera/__init__.py index a13965476..b30e3def7 100644 --- a/src/PythonAPI/model/opera/__init__.py +++ b/src/PythonAPI/model/opera/__init__.py @@ -19,4 +19,4 @@ """Package for Opera plugin for SHAPER Opera. """ -from OperaAPI import addVolume +from OperaAPI import Volume -- 2.39.2