From 11c03dec886fc348614782ffbbf2be3210efaca4 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 8 Aug 2019 09:43:07 +0300 Subject: [PATCH] Task 2.5. Combination operations on Groups (issue #2935) Python dump and unit tests for Group Addition operation. --- src/CollectionAPI/CMakeLists.txt | 2 + src/CollectionAPI/CollectionAPI.i | 3 + .../CollectionAPI_GroupAddition.cpp | 70 ++++++++++++++++++ .../CollectionAPI_GroupAddition.h | 74 +++++++++++++++++++ src/CollectionPlugin/CMakeLists.txt | 2 + .../Test/TestGroupAddition.py | 42 +++++++++++ .../Test/TestGroupAddition_Error.py | 33 +++++++++ src/Model/Model_AttributeSelection.cpp | 5 +- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 4 +- src/PythonAPI/model/collection/__init__.py | 1 + 10 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 src/CollectionAPI/CollectionAPI_GroupAddition.cpp create mode 100644 src/CollectionAPI/CollectionAPI_GroupAddition.h create mode 100644 src/CollectionPlugin/Test/TestGroupAddition.py create mode 100644 src/CollectionPlugin/Test/TestGroupAddition_Error.py diff --git a/src/CollectionAPI/CMakeLists.txt b/src/CollectionAPI/CMakeLists.txt index 0b2815bdd..f9ca6033b 100644 --- a/src/CollectionAPI/CMakeLists.txt +++ b/src/CollectionAPI/CMakeLists.txt @@ -22,11 +22,13 @@ INCLUDE(Common) SET(PROJECT_HEADERS CollectionAPI.h CollectionAPI_Group.h + CollectionAPI_GroupAddition.h CollectionAPI_Field.h ) SET(PROJECT_SOURCES CollectionAPI_Group.cpp + CollectionAPI_GroupAddition.cpp CollectionAPI_Field.cpp ) diff --git a/src/CollectionAPI/CollectionAPI.i b/src/CollectionAPI/CollectionAPI.i index c27d56cb2..2dee7dd08 100644 --- a/src/CollectionAPI/CollectionAPI.i +++ b/src/CollectionAPI/CollectionAPI.i @@ -29,6 +29,7 @@ #include "CollectionAPI.h" #include "CollectionAPI_Group.h" + #include "CollectionAPI_GroupAddition.h" #include "CollectionAPI_Field.h" #endif // CollectionAPI_swig_H_ @@ -66,8 +67,10 @@ // shared pointers %shared_ptr(CollectionAPI_Group) +%shared_ptr(CollectionAPI_GroupAddition) %shared_ptr(CollectionAPI_Field) // all supported interfaces %include "CollectionAPI_Group.h" +%include "CollectionAPI_GroupAddition.h" %include "CollectionAPI_Field.h" diff --git a/src/CollectionAPI/CollectionAPI_GroupAddition.cpp b/src/CollectionAPI/CollectionAPI_GroupAddition.cpp new file mode 100644 index 000000000..d0fecada7 --- /dev/null +++ b/src/CollectionAPI/CollectionAPI_GroupAddition.cpp @@ -0,0 +1,70 @@ +// Copyright (C) 2014-2019 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 "CollectionAPI_GroupAddition.h" + +#include +#include + +CollectionAPI_GroupAddition::CollectionAPI_GroupAddition( + const std::shared_ptr& theFeature) + : ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +CollectionAPI_GroupAddition::CollectionAPI_GroupAddition( + const std::shared_ptr& theFeature, + const std::list& theGroupList) + : ModelHighAPI_Interface(theFeature) +{ + if(initialize()) { + setGroupList(theGroupList); + } +} + +CollectionAPI_GroupAddition::~CollectionAPI_GroupAddition() +{ +} + +void CollectionAPI_GroupAddition::setGroupList( + const std::list& theGroupList) +{ + fillAttribute(theGroupList, mygroupList); + execute(); +} + +void CollectionAPI_GroupAddition::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeSelectionListPtr anAttrList = + aBase->selectionList(CollectionPlugin_GroupAddition::LIST_ID()); + + theDumper << aBase << " = model.addGroupAddition(" << aDocName << ", " + << anAttrList << ")" << std::endl; +} + +GroupAdditionPtr addGroupAddition(const std::shared_ptr& thePart, + const std::list& theGroupList) +{ + std::shared_ptr aFeature = thePart->addFeature(CollectionAPI_GroupAddition::ID()); + return GroupAdditionPtr(new CollectionAPI_GroupAddition(aFeature, theGroupList)); +} diff --git a/src/CollectionAPI/CollectionAPI_GroupAddition.h b/src/CollectionAPI/CollectionAPI_GroupAddition.h new file mode 100644 index 000000000..c6395300d --- /dev/null +++ b/src/CollectionAPI/CollectionAPI_GroupAddition.h @@ -0,0 +1,74 @@ +// Copyright (C) 2014-2019 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 CollectionAPI_GroupAddition_H_ +#define CollectionAPI_GroupAddition_H_ + +#include "CollectionAPI.h" + +#include + +#include +#include + +class ModelHighAPI_Dumper; +class ModelHighAPI_Selection; + +/// \class CollectionAPI_GroupAddition +/// \ingroup CPPHighAPI +/// \brief Interface for Group feature. +class CollectionAPI_GroupAddition : public ModelHighAPI_Interface +{ +public: + /// Constructor without values. + COLLECTIONAPI_EXPORT + explicit CollectionAPI_GroupAddition(const std::shared_ptr& theFeature); + + /// Constructor with values. + COLLECTIONAPI_EXPORT + CollectionAPI_GroupAddition(const std::shared_ptr& theFeature, + const std::list& theGroupList); + + /// Destructor. + COLLECTIONAPI_EXPORT + virtual ~CollectionAPI_GroupAddition(); + + INTERFACE_1(CollectionPlugin_GroupAddition::ID(), + groupList, CollectionPlugin_GroupAddition::LIST_ID(), + ModelAPI_AttributeSelectionList, /** Group list*/) + + /// Set main objects. + COLLECTIONAPI_EXPORT + void setGroupList(const std::list& theGroupList); + + /// Dump wrapped feature + COLLECTIONAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; +}; + +/// Pointer on Group Addition object. +typedef std::shared_ptr GroupAdditionPtr; + +/// \ingroup CPPHighAPI +/// \brief Create Group Addition feature. +COLLECTIONAPI_EXPORT +GroupAdditionPtr addGroupAddition(const std::shared_ptr& thePart, + const std::list& theGroupsList); + +#endif // CollectionAPI_Group_H_ diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index 921596cdd..a19513883 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -133,4 +133,6 @@ ADD_UNIT_TESTS( TestGroupMove19.py TestGroupMove20.py TestGroupShareTopology.py + TestGroupAddition.py + TestGroupAddition_Error.py ) diff --git a/src/CollectionPlugin/Test/TestGroupAddition.py b/src/CollectionPlugin/Test/TestGroupAddition.py new file mode 100644 index 000000000..de66eb527 --- /dev/null +++ b/src/CollectionPlugin/Test/TestGroupAddition.py @@ -0,0 +1,42 @@ +# Copyright (C) 2014-2019 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 +# + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Box_1_1/Left")]) +Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Top")]) +GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")]) +model.end + +from GeomAPI import * + +model.testNbResults(GroupAddition_1, 1) +model.testNbSubResults(GroupAddition_1, [0]) +model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.FACE, [3]) +model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.EDGE, [12]) +model.testNbSubShapes(GroupAddition_1, GeomAPI_Shape.VERTEX, [24]) +model.testResultsVolumes(GroupAddition_1, [300]) + +assert(model.checkPythonDump()) diff --git a/src/CollectionPlugin/Test/TestGroupAddition_Error.py b/src/CollectionPlugin/Test/TestGroupAddition_Error.py new file mode 100644 index 000000000..ad6934da2 --- /dev/null +++ b/src/CollectionPlugin/Test/TestGroupAddition_Error.py @@ -0,0 +1,33 @@ +# Copyright (C) 2014-2019 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 +# + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Top"), model.selection("FACE", "Box_1_1/Left")]) +Group_2 = model.addGroup(Part_1_doc, [model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Bottom]"), model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Right]")]) +GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")]) +GroupAddition_2 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("FACE", "Box_1_1/Front")]) +model.end + +assert(GroupAddition_1.feature().error() != "") diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 26b45f7c8..ff194dac5 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -896,8 +896,11 @@ void Model_AttributeSelection::selectSubShape( // the whole result selection check if (aSubShapeName.find('/') == std::string::npos) { ObjectPtr aRes = aDoc->objectByName(ModelAPI_ResultConstruction::group(), aSubShapeName); - if (!aRes.get()) + if (!aRes.get()) { aRes = aDoc->objectByName(ModelAPI_ResultBody::group(), aSubShapeName); + if (!aRes.get()) + aRes = aDoc->objectByName(ModelAPI_ResultGroup::group(), aSubShapeName); + } if (aRes.get()) { setValue(aRes, anEmptyShape); return; diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 409f1b430..ef6f1ee62 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -289,7 +290,8 @@ static void getShapeAndContext(const AttributeSelectionPtr& theAttrSelect, if (theAttrSelect->isGeometricalSelection() && theShape.get() && theShape->shapeType() == GeomAPI_Shape::COMPOUND && theContext.get() && !theShape->isEqual(theContext->shape()) && - theContext->groupName() != ModelAPI_ResultPart::group()) { + theContext->groupName() != ModelAPI_ResultPart::group() && + theContext->groupName() != ModelAPI_ResultGroup::group()) { GeomAPI_ShapeIterator anIt(theShape); theShape = anIt.current(); } diff --git a/src/PythonAPI/model/collection/__init__.py b/src/PythonAPI/model/collection/__init__.py index 5718df5f5..96b7089ce 100644 --- a/src/PythonAPI/model/collection/__init__.py +++ b/src/PythonAPI/model/collection/__init__.py @@ -20,3 +20,4 @@ """ from CollectionAPI import addGroup, addField +from CollectionAPI import addGroupAddition -- 2.39.2