From ece2e7c31810af283e8a526521a425281798eefe Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 3 Oct 2019 18:38:55 +0300 Subject: [PATCH] Fix for the issue #3031 : Wrong group result after move to the end --- src/CollectionPlugin/CMakeLists.txt | 1 + src/CollectionPlugin/Test/Test3031.py | 47 ++++++++++++++++++++++++++ src/Model/Model_AttributeSelection.cpp | 42 ++++++++++++++++++++++- 3 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/CollectionPlugin/Test/Test3031.py diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index ee604e01f..65cac240e 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -156,4 +156,5 @@ ADD_UNIT_TESTS( Test2977.py TestGroupWholeResult1.py TestGroupWholeResult2.py + Test3031.py ) diff --git a/src/CollectionPlugin/Test/Test3031.py b/src/CollectionPlugin/Test/Test3031.py new file mode 100644 index 000000000..a96f09ff5 --- /dev/null +++ b/src/CollectionPlugin/Test/Test3031.py @@ -0,0 +1,47 @@ +# 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 +# + +# Test of movement of the group of whole result with different results shape types: only one shape type must be in the moved group +from salome.shaper import model +from GeomAPI import * + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_1.addCircle(17.20575221238938, 2.793141592920342, 8.375699762004958) +model.do() +Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ")) +SketchLine_1 = Sketch_2.addLine(24.25155410709516, 6.639479956172791, 20.59251568321609, -12.31511385947313) +model.do() +Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")]) +Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_2/SketchLine_1")]) +Group_1 = model.addGroup(Part_1_doc, "Edges", [model.selection("EDGE", "Edge_1_1")]) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("FACE", "Face_1_1"), model.selection("EDGE", "Edge_1_1")], 20190506) +model.do() +# move group after the partition +Part_1_doc.moveFeature(Group_1.feature(), Partition_1.feature()) +model.end() + +# check that only two edges are in the group result, no face +assert(len(Group_1.feature().results())==1) +model.testNbSubShapes(Group_1, GeomAPI_Shape.EDGE, [2]) + +assert(model.checkPythonDump()) diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index e7a974e2e..a5ec3df32 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1598,6 +1598,42 @@ void Model_AttributeSelection::updateInHistory(bool& theRemove) aListShapeType = GeomAPI_Shape::FACE; } + // issue #3031: skip topology if there is more convenient shape type presents in the + // same context as a result of this + bool isWholeResult = myParent && myParent->isWholeResultAllowed() && !aSubShape.get(); + GeomAPI_Shape::ShapeType allowedType = GeomAPI_Shape::SHAPE; + if (isWholeResult) { + std::list::iterator aNewCont = aNewContexts.begin(); + TopTools_ListIteratorOfListOfShape aNewValues(aValShapes); + for(; aNewCont != aNewContexts.end(); aNewCont++, aNewValues.Next()) { + if (aNewValues.Value().IsNull()) { // only for the whole context + GeomAPI_Shape::ShapeType aShapeType = (*aNewCont)->shape()->shapeType(); + if (allowedType == GeomAPI_Shape::SHAPE) { // just set this one + allowedType = aShapeType; + } else { + GeomAPI_Shape::ShapeType anAllowed = allowedType; + if (anAllowed != aShapeType) { // select the best, nearest to the origin + GeomAPI_Shape::ShapeType anOldShapeType = aContext->shape()->shapeType(); + GeomAPI_Shape::ShapeType aDeltaAllowed = + (GeomAPI_Shape::ShapeType)(anOldShapeType - anAllowed); + if (aDeltaAllowed < 0) + aDeltaAllowed = (GeomAPI_Shape::ShapeType)(-aDeltaAllowed); + GeomAPI_Shape::ShapeType aDeltaThis = + (GeomAPI_Shape::ShapeType)(anOldShapeType - aShapeType); + if (aDeltaThis < 0) + aDeltaThis = (GeomAPI_Shape::ShapeType)(-aDeltaThis); + if (aDeltaThis == aDeltaAllowed) { // equal distance to context, select complicated + if (anOldShapeType < anAllowed) + allowedType = aShapeType; + } else if (aDeltaAllowed > aDeltaThis) { // this wins + allowedType = aShapeType; + } + } + } + } + } + } + std::list::iterator aNewCont = aNewContexts.begin(); TopTools_ListIteratorOfListOfShape aNewValues(aValShapes); bool aFirst = true; // first is set to this, next are appended to parent @@ -1605,6 +1641,10 @@ void Model_AttributeSelection::updateInHistory(bool& theRemove) if (aSkippedContext.count(*aNewCont)) continue; + if (isWholeResult && aNewValues.Value().IsNull()) + if ((*aNewCont)->shape()->shapeType() != allowedType) + continue; // there is better result exists with the better shape type (issue #3031) + GeomShapePtr aValueShape; if (!aNewValues.Value().IsNull()) { aValueShape = std::make_shared(); @@ -1619,7 +1659,7 @@ void Model_AttributeSelection::updateInHistory(bool& theRemove) } if (aListShapeType != GeomAPI_Shape::SHAPE && aListShapeType != aShapeShapeType) { // exception is for whole results selected - if (!myParent || !myParent->isWholeResultAllowed() || aSubShape.get()) { + if (!isWholeResult) { continue; } } -- 2.39.2