From: azv Date: Wed, 21 Aug 2019 08:57:12 +0000 (+0300) Subject: Issue #2977: Impossible to select Group in Substract group X-Git-Tag: VEDF2019Lot4~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cd768ab63335367ea2a81d5d86500fa5d151c676;p=modules%2Fshaper.git Issue #2977: Impossible to select Group in Substract group Set correct selection type for the operations on groups. --- diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index cfdaaa8e7..251b91ffe 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS CollectionPlugin_Group.h CollectionPlugin_GroupAddition.h CollectionPlugin_GroupIntersection.h + CollectionPlugin_GroupOperation.h CollectionPlugin_GroupSubstraction.h CollectionPlugin_Field.h CollectionPlugin_WidgetCreator.h @@ -49,6 +50,7 @@ SET(PROJECT_SOURCES CollectionPlugin_Group.cpp CollectionPlugin_GroupAddition.cpp CollectionPlugin_GroupIntersection.cpp + CollectionPlugin_GroupOperation.cpp CollectionPlugin_GroupSubstraction.cpp CollectionPlugin_Field.cpp CollectionPlugin_WidgetCreator.cpp @@ -144,4 +146,5 @@ ADD_UNIT_TESTS( TestGroupSubstraction.py TestGroupSubstraction_Error1.py TestGroupSubstraction_Error2.py + Test2977.py ) diff --git a/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp b/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp index c27826ce8..042633cfe 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp +++ b/src/CollectionPlugin/CollectionPlugin_GroupAddition.cpp @@ -83,5 +83,8 @@ void CollectionPlugin_GroupAddition::execute() aCompound = aSubs.empty() ? GeomShapePtr() : GeomAlgoAPI_CompoundBuilder::compound(aSubs); aGroup->store(aCompound); + // update the type of selection + updateGroupType(LIST_ID()); + setResult(aGroup); } diff --git a/src/CollectionPlugin/CollectionPlugin_GroupAddition.h b/src/CollectionPlugin/CollectionPlugin_GroupAddition.h index 17b1ed1c6..850c7d797 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupAddition.h +++ b/src/CollectionPlugin/CollectionPlugin_GroupAddition.h @@ -21,15 +21,15 @@ #define COLLECTIONPLUGIN_GROUPADDITION_H_ #include "CollectionPlugin.h" -#include "CollectionPlugin_Group.h" +#include "CollectionPlugin_GroupOperation.h" /**\class CollectionPlugin_GroupAddition * \ingroup Plugins * \brief Merge several groups of same shape type into single group. */ -class CollectionPlugin_GroupAddition : public CollectionPlugin_Group +class CollectionPlugin_GroupAddition : public CollectionPlugin_GroupOperation { - public: +public: /// Extrusion kind inline static const std::string& ID() { @@ -56,9 +56,6 @@ class CollectionPlugin_GroupAddition : public CollectionPlugin_Group /// Request for initialization of data model of the feature: adding all attributes COLLECTIONPLUGIN_EXPORT virtual void initAttributes(); - /// Result of groups is created on the fly and don't stored to the document - COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;} - /// Use plugin manager for features creation CollectionPlugin_GroupAddition(); diff --git a/src/CollectionPlugin/CollectionPlugin_GroupIntersection.cpp b/src/CollectionPlugin/CollectionPlugin_GroupIntersection.cpp index e74ba4786..55f5200b5 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupIntersection.cpp +++ b/src/CollectionPlugin/CollectionPlugin_GroupIntersection.cpp @@ -96,6 +96,9 @@ void CollectionPlugin_GroupIntersection::execute() removeResults(0); } else { + // update the type of selection + updateGroupType(LIST_ID()); + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aCommon); aGroup->store(aCompound); setResult(aGroup); diff --git a/src/CollectionPlugin/CollectionPlugin_GroupIntersection.h b/src/CollectionPlugin/CollectionPlugin_GroupIntersection.h index 115f3f544..72b0984a3 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupIntersection.h +++ b/src/CollectionPlugin/CollectionPlugin_GroupIntersection.h @@ -21,15 +21,15 @@ #define COLLECTIONPLUGIN_GROUPINTERSECTION_H_ #include "CollectionPlugin.h" -#include "CollectionPlugin_Group.h" +#include "CollectionPlugin_GroupOperation.h" /**\class CollectionPlugin_GroupIntersection * \ingroup Plugins * \brief Merge several groups of same shape type into single group. */ -class CollectionPlugin_GroupIntersection : public CollectionPlugin_Group +class CollectionPlugin_GroupIntersection : public CollectionPlugin_GroupOperation { - public: +public: /// Extrusion kind inline static const std::string& ID() { @@ -56,9 +56,6 @@ class CollectionPlugin_GroupIntersection : public CollectionPlugin_Group /// Request for initialization of data model of the feature: adding all attributes COLLECTIONPLUGIN_EXPORT virtual void initAttributes(); - /// Result of groups is created on the fly and don't stored to the document - COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;} - /// Use plugin manager for features creation CollectionPlugin_GroupIntersection(); diff --git a/src/CollectionPlugin/CollectionPlugin_GroupOperation.cpp b/src/CollectionPlugin/CollectionPlugin_GroupOperation.cpp new file mode 100644 index 000000000..d8965f131 --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_GroupOperation.cpp @@ -0,0 +1,36 @@ +// 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 "CollectionPlugin_GroupOperation.h" + +#include + +void CollectionPlugin_GroupOperation::updateGroupType(const std::string& theAttributeName) +{ + AttributeSelectionListPtr aSelected = selectionList(theAttributeName); + if (aSelected->size()) { + FeaturePtr aFirstGroup = ModelAPI_Feature::feature(aSelected->value(0)->context()); + if (aFirstGroup) { + AttributeSelectionListPtr aFirstGroupShapes = + aFirstGroup->selectionList(CollectionPlugin_Group::LIST_ID()); + if (aFirstGroupShapes) + aSelected->setSelectionType(aFirstGroupShapes->selectionType()); + } + } +} diff --git a/src/CollectionPlugin/CollectionPlugin_GroupOperation.h b/src/CollectionPlugin/CollectionPlugin_GroupOperation.h new file mode 100644 index 000000000..fb47e990e --- /dev/null +++ b/src/CollectionPlugin/CollectionPlugin_GroupOperation.h @@ -0,0 +1,41 @@ +// 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 COLLECTIONPLUGIN_GROUPOPERATION_H_ +#define COLLECTIONPLUGIN_GROUPOPERATION_H_ + +#include "CollectionPlugin.h" +#include "CollectionPlugin_Group.h" + +/**\class CollectionPlugin_GroupOperation + * \ingroup Plugins + * \brief Base class for operations on groups. + */ +class CollectionPlugin_GroupOperation : public CollectionPlugin_Group +{ +public: + /// Result of groups is created on the fly and don't stored to the document + COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;} + +protected: + /// Updates the type of selection list based on types of selected groups + void updateGroupType(const std::string& theAttributeName); +}; + +#endif diff --git a/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.cpp b/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.cpp index 18f0acad5..9d39711ae 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.cpp +++ b/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.cpp @@ -101,6 +101,9 @@ void CollectionPlugin_GroupSubstraction::execute() removeResults(0); } else { + // update the type of selection + updateGroupType(LIST_ID()); + GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aCut); aGroup->store(aCompound); setResult(aGroup); diff --git a/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.h b/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.h index 3fcd74339..0b4f8ead0 100644 --- a/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.h +++ b/src/CollectionPlugin/CollectionPlugin_GroupSubstraction.h @@ -21,15 +21,15 @@ #define COLLECTIONPLUGIN_GROUPSUBSTRACTION_H_ #include "CollectionPlugin.h" -#include "CollectionPlugin_Group.h" +#include "CollectionPlugin_GroupOperation.h" /**\class CollectionPlugin_GroupSubstraction * \ingroup Plugins * \brief Remove all elements in "objects" groups which contain in "tools" groups. */ -class CollectionPlugin_GroupSubstraction : public CollectionPlugin_Group +class CollectionPlugin_GroupSubstraction : public CollectionPlugin_GroupOperation { - public: +public: /// Extrusion kind inline static const std::string& ID() { @@ -62,9 +62,6 @@ class CollectionPlugin_GroupSubstraction : public CollectionPlugin_Group /// Request for initialization of data model of the feature: adding all attributes COLLECTIONPLUGIN_EXPORT virtual void initAttributes(); - /// Result of groups is created on the fly and don't stored to the document - COLLECTIONPLUGIN_EXPORT virtual bool isPersistentResult() {return true;} - /// Use plugin manager for features creation CollectionPlugin_GroupSubstraction(); diff --git a/src/CollectionPlugin/Test/Test2977.py b/src/CollectionPlugin/Test/Test2977.py new file mode 100644 index 000000000..26568fee0 --- /dev/null +++ b/src/CollectionPlugin/Test/Test2977.py @@ -0,0 +1,44 @@ +# Copyright (C) 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/Left"), model.selection("FACE", "Box_1_1/Top")]) +Group_2 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Top")]) +Group_3 = model.addGroup(Part_1_doc, [model.selection("FACE", "Box_1_1/Top")]) +GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")]) +GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "GroupAddition_1")], [model.selection("COMPOUND", "Group_3")]) +model.end() + +from GeomAPI import * + +model.testNbResults(GroupSubstraction_1, 1) +model.testNbSubResults(GroupSubstraction_1, [0]) +model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.SOLID, [0]) +model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.FACE, [2]) +model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.EDGE, [8]) +model.testNbSubShapes(GroupSubstraction_1, GeomAPI_Shape.VERTEX, [16]) +model.testResultsVolumes(GroupSubstraction_1, [200]) + +assert(model.checkPythonDump())