From 9f5b6610cba342b24f54cc27e2485ef14c715ce7 Mon Sep 17 00:00:00 2001 From: Nicolas RECHATIN Date: Fri, 23 Jul 2021 12:08:20 +0200 Subject: [PATCH] WIP Test.py files + test on store() --- src/ModelAPI/ModelAPI_ResultBody.cpp | 18 +++++++ src/ModelAPI/ModelAPI_ResultBody.h | 7 +++ src/ModelAPI/ModelAPI_ResultMeta.cpp | 14 ------ src/ModelAPI/ModelAPI_ResultMeta.h | 2 +- src/ModelAPI/ModelAPI_ResultVolume.cpp | 18 +++++++ src/ModelAPI/ModelAPI_ResultVolume.h | 7 +++ src/OperaAPI/OperaAPI_addVolume.cpp | 22 +++------ src/OperaAPI/OperaAPI_addVolume.h | 6 +-- src/OperaPlugin/Test/TestAddVolume.py | 67 ++++++++++++++++++++++++++ src/OperaPlugin/tests.set | 22 +++++++++ 10 files changed, 150 insertions(+), 33 deletions(-) create mode 100644 src/OperaPlugin/Test/TestAddVolume.py create mode 100644 src/OperaPlugin/tests.set diff --git a/src/ModelAPI/ModelAPI_ResultBody.cpp b/src/ModelAPI/ModelAPI_ResultBody.cpp index 0d88bef99..72032d980 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.cpp +++ b/src/ModelAPI/ModelAPI_ResultBody.cpp @@ -19,6 +19,10 @@ #include "ModelAPI_ResultBody.h" +#include +#include +#include + ModelAPI_ResultBody::ModelAPI_ResultBody() {} ModelAPI_ResultBody::~ModelAPI_ResultBody() {} @@ -34,3 +38,17 @@ void ModelAPI_ResultBody::setDisplayed(const bool theDisplay) for (int i = 0; i < numberOfSubs(); i++) subResult(i)->setDisplayed(theDisplay); } + +void ModelAPI_ResultBody::store(const GeomShapePtr& theShape, + const bool theIsStoreSameShapes) +{ + myBuilder->store(theShape, theIsStoreSameShapes); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theShape); +} diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 53cd19109..f058378b3 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -44,6 +44,13 @@ class ModelAPI_ResultBody : public ModelAPI_ResultMeta public: MODELAPI_EXPORT virtual ~ModelAPI_ResultBody(); + /// \brief Stores the shape (called by the execution method). + /// param[in] theShape shape to store. + /// param[in] theIsStoreSameShapes if false stores reference to the same shape + /// if it is already in document. + MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape, + const bool theIsStoreSameShapes = true); + // /// Returns the group identifier of this result MODELAPI_EXPORT virtual std::string groupName(); diff --git a/src/ModelAPI/ModelAPI_ResultMeta.cpp b/src/ModelAPI/ModelAPI_ResultMeta.cpp index 337f8f488..6c313d301 100644 --- a/src/ModelAPI/ModelAPI_ResultMeta.cpp +++ b/src/ModelAPI/ModelAPI_ResultMeta.cpp @@ -33,20 +33,6 @@ ModelAPI_ResultMeta::~ModelAPI_ResultMeta() { } -void ModelAPI_ResultMeta::store(const GeomShapePtr& theShape, - const bool theIsStoreSameShapes) -{ - myBuilder->store(theShape, theIsStoreSameShapes); - myConnect = ConnectionNotComputed; - - static Events_Loop* aLoop = Events_Loop::loop(); - static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); - static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); - aECreator->sendUpdated(data()->owner(), aRedispEvent); - - updateSubs(theShape); -} - void ModelAPI_ResultMeta::storeGenerated(const GeomShapePtr& theFromShape, const GeomShapePtr& theToShape) { diff --git a/src/ModelAPI/ModelAPI_ResultMeta.h b/src/ModelAPI/ModelAPI_ResultMeta.h index 56bfb788f..59633e54e 100644 --- a/src/ModelAPI/ModelAPI_ResultMeta.h +++ b/src/ModelAPI/ModelAPI_ResultMeta.h @@ -76,7 +76,7 @@ public: /// param[in] theIsStoreSameShapes if false stores reference to the same shape /// if it is already in document. MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape, - const bool theIsStoreSameShapes = true); + const bool theIsStoreSameShapes = true) = 0; /// Stores the generated shape (called by the execution method). MODELAPI_EXPORT virtual void storeGenerated(const GeomShapePtr& theFromShape, diff --git a/src/ModelAPI/ModelAPI_ResultVolume.cpp b/src/ModelAPI/ModelAPI_ResultVolume.cpp index 99175e884..7994fa64e 100644 --- a/src/ModelAPI/ModelAPI_ResultVolume.cpp +++ b/src/ModelAPI/ModelAPI_ResultVolume.cpp @@ -19,6 +19,10 @@ #include "ModelAPI_ResultVolume.h" +#include +#include +#include + ModelAPI_ResultVolume::ModelAPI_ResultVolume() {} ModelAPI_ResultVolume::~ModelAPI_ResultVolume() {} @@ -34,3 +38,17 @@ void ModelAPI_ResultVolume::setDisplayed(const bool theDisplay) for (int i = 0; i < numberOfSubs(); i++) subResult(i)->setDisplayed(theDisplay); } + +void ModelAPI_ResultVolume::store(const GeomShapePtr& theShape, + const bool theIsStoreSameShapes) +{ + myBuilder->store(theShape, theIsStoreSameShapes); + myConnect = ConnectionNotComputed; + + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + aECreator->sendUpdated(data()->owner(), aRedispEvent); + + updateSubs(theShape); +} diff --git a/src/ModelAPI/ModelAPI_ResultVolume.h b/src/ModelAPI/ModelAPI_ResultVolume.h index e8c0cd276..23f65c557 100644 --- a/src/ModelAPI/ModelAPI_ResultVolume.h +++ b/src/ModelAPI/ModelAPI_ResultVolume.h @@ -36,6 +36,13 @@ class ModelAPI_ResultVolume : public ModelAPI_ResultMeta public: MODELAPI_EXPORT virtual ~ModelAPI_ResultVolume(); + /// \brief Stores the shape (called by the execution method). + /// param[in] theShape shape to store. + /// param[in] theIsStoreSameShapes if false stores reference to the same shape + /// if it is already in document. + MODELAPI_EXPORT virtual void store(const GeomShapePtr& theShape, + const bool theIsStoreSameShapes = true); + /// Returns the group identifier of this result MODELAPI_EXPORT std::string groupName(); diff --git a/src/OperaAPI/OperaAPI_addVolume.cpp b/src/OperaAPI/OperaAPI_addVolume.cpp index 380623402..5ae722369 100644 --- a/src/OperaAPI/OperaAPI_addVolume.cpp +++ b/src/OperaAPI/OperaAPI_addVolume.cpp @@ -32,12 +32,12 @@ OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& //================================================================================================== OperaAPI_addVolume::OperaAPI_addVolume(const std::shared_ptr& theFeature, const ModelHighAPI_Double& theMedium, - const std::list& theVolumeList) + const std::list& theObjectList) : ModelHighAPI_Interface(theFeature) { if(initialize()) { - setMedium(theMedium); - setVolumeList(theVolumeList); + fillAttribute(OperaPlugin_Volume::MEDIUM(), medium()); + setObjectList(theObjectList); } } @@ -53,9 +53,9 @@ void OperaAPI_addVolume::setMedium(const ModelHighAPI_Double& theMedium) } //================================================================================================== -void OperaAPI_addVolume::setVolumeList(const std::list& theVolumeList) +void OperaAPI_addVolume::setObjectList(const std::list& theObjectList) { - fillAttribute(theVolumeList, myvolumeList); + fillAttribute(theObjectList, myvolumeList); execute(); } @@ -78,20 +78,12 @@ void OperaAPI_addVolume::dump(ModelHighAPI_Dumper& theDumper) const 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) + const std::list& theObjectList) { 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)); + return VolumePtr(new OperaAPI_addVolume(aFeature, theMedium, theObjectList)); } diff --git a/src/OperaAPI/OperaAPI_addVolume.h b/src/OperaAPI/OperaAPI_addVolume.h index 913e4d8d3..8476ee0e0 100644 --- a/src/OperaAPI/OperaAPI_addVolume.h +++ b/src/OperaAPI/OperaAPI_addVolume.h @@ -44,7 +44,7 @@ public: OPERAAPI_EXPORT OperaAPI_addVolume(const std::shared_ptr& theFeature, const ModelHighAPI_Double& theMedium, - const std::list& theVolumeList); + const std::list& theObjectList); /// Destructor. OPERAAPI_EXPORT @@ -62,7 +62,7 @@ public: /// Set main objects list. OPERAAPI_EXPORT - void setVolumeList(const std::list& theVolumeList); + void setObjectList(const std::list& theObjectList); /// Dump wrapped feature OPERAAPI_EXPORT @@ -77,6 +77,6 @@ typedef std::shared_ptr VolumePtr; OPERAAPI_EXPORT VolumePtr addVolume(const std::shared_ptr& thePart, const ModelHighAPI_Double& theMedium, - const std::list& theVolumeList); + const std::list& theObjectList); #endif // OperaAPI_addVolume_H_ diff --git a/src/OperaPlugin/Test/TestAddVolume.py b/src/OperaPlugin/Test/TestAddVolume.py new file mode 100644 index 000000000..c696b8fc7 --- /dev/null +++ b/src/OperaPlugin/Test/TestAddVolume.py @@ -0,0 +1,67 @@ +# 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 +# + +""" + TestBoolean.py + Unit test of FeaturesPlugin_Group class + + class FeaturesPlugin_Group + static const std::string MY_GROUP_ID("Group"); + static const std::string MY_GROUP_LIST_ID("group_list"); + + data()->addAttribute(FeaturesPlugin_Group::LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); +""" +#========================================================================= +# Initialization of the test +#========================================================================= + +#========================================================================= +# Create a Box +#========================================================================= + +#========================================================================= +# Create a Torus +#========================================================================= + +#========================================================================= +# Create a Cylinder +#========================================================================= + +#========================================================================= +# Create one Volume +#========================================================================= + +#========================================================================= +# Check results +#========================================================================= + +#========================================================================= +# Create two volumes at once +#========================================================================= + +#========================================================================= +# Check results +#========================================================================= + +#========================================================================= +# End of test +#========================================================================= + +from salome.shaper import model +assert(model.checkPythonDump()) 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 +) -- 2.39.2