From: mpv Date: Mon, 30 Mar 2020 14:09:37 +0000 (+0300) Subject: Fix for the issue #3195 : The groups built by "Group Addtion" are not in ShaperResults X-Git-Tag: V9_5_0a2~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cb749258f33b7de231da5bb50140407c0599d30;p=modules%2Fshaper.git Fix for the issue #3195 : The groups built by "Group Addtion" are not in ShaperResults --- diff --git a/src/ConnectorAPI/Test/Test3195.py b/src/ConnectorAPI/Test/Test3195.py new file mode 100644 index 000000000..301c3d6d5 --- /dev/null +++ b/src/ConnectorAPI/Test/Test3195.py @@ -0,0 +1,52 @@ +# 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 +# +import sys +import salome + +salome.salome_init() +### +### SHAPER component +### +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, "Faces", [model.selection("FACE", "Box_1_1/Left")]) +Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Front")]) +GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")]) +model.end() + +### +### SHAPERSTUDY component +### + +model.publishToShaperStudy() +# check that addition is in the SHAPERSTUDY + +from SHAPERSTUDY_utils import findOrCreateComponent, getStudy +c = findOrCreateComponent() +aSOIter = getStudy().NewChildIterator(c) +aSO = aSOIter.Value() +aSOIter = getStudy().NewChildIterator(aSO) +aSOIter.Next() +aSOIter.Next() +aSOIter.Next() +assert(aSOIter.Value().GetName() == GroupAddition_1.name()) diff --git a/src/ConnectorAPI/Test/tests.set b/src/ConnectorAPI/Test/tests.set index 6e74d9960..9d58214e5 100644 --- a/src/ConnectorAPI/Test/tests.set +++ b/src/ConnectorAPI/Test/tests.set @@ -26,4 +26,5 @@ SET(TEST_NAMES Test2882 Test17917 Test18887 + Test3195 ) diff --git a/src/ModelAPI/ModelAPI_Tools.cpp b/src/ModelAPI/ModelAPI_Tools.cpp index 3b0cd3701..8a19702d6 100644 --- a/src/ModelAPI/ModelAPI_Tools.cpp +++ b/src/ModelAPI/ModelAPI_Tools.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include +#include #define RECURSE_TOP_LEVEL 50 @@ -1034,6 +1036,52 @@ std::list referencedFeatures( if (aFeat.get() && (theFeatureKind.empty() || aFeat->getKind() == theFeatureKind)) aResSet.insert(aFeat); } + // check also Group-operations that may refer to groups - add them for theFeatureKind "Group" + if (theFeatureKind == "Group") { + std::set aGroupOperations; + for(bool aNeedIterate = true; aNeedIterate; ) { + std::set::iterator aResIter = aResSet.begin(); + for(; aResIter != aResSet.end(); aResIter++) { + std::list::const_iterator aGroupRes = (*aResIter)->results().cbegin(); + for(; aGroupRes != (*aResIter)->results().cend(); aGroupRes++) { + const std::set& aRefs = (*aGroupRes)->data()->refsToMe(); + std::set::const_iterator aRef = aRefs.cbegin(); + for(; aRef != aRefs.cend(); aRef++) { + FeaturePtr aFeat = std::dynamic_pointer_cast((*aRef)->owner()); + if (aFeat.get() && !aGroupOperations.count(aFeat) && !aFeat->results().empty() && + aFeat->firstResult()->groupName() == ModelAPI_ResultGroup::group()) { + // iterate results of this group operation because it may be without theTarget shape + GeomShapePtr aTargetShape = theTarget->shape(); + bool anIsIn = false; + std::list::const_iterator anOpRes = aFeat->results().cbegin(); + for(; anOpRes != aFeat->results().cend() && !anIsIn; anOpRes++) { + GeomShapePtr anOpShape = (*anOpRes)->shape(); + if (!anOpShape.get() || anOpShape->isNull()) + continue; + for(GeomAPI_ShapeIterator aSubIt(anOpShape); aSubIt.more(); aSubIt.next()) { + if (aTargetShape->isSubShape(aSubIt.current(), false)) { + anIsIn = true; + break; + } + } + } + if (anIsIn) + aGroupOperations.insert(aFeat); + } + } + } + } + // insert all new group operations into result and if they are, check for next dependencies + aNeedIterate = false; + std::set::iterator aGroupOpIter = aGroupOperations.begin(); + for(; aGroupOpIter != aGroupOperations.end(); aGroupOpIter++) { + if (aResSet.find(*aGroupOpIter) == aResSet.end()) { + aResSet.insert(*aGroupOpIter); + aNeedIterate = true; + } + } + } + } std::list aResList; std::set::iterator aResIter = aResSet.begin();