]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #3031 : Wrong group result after move to the end
authormpv <mpv@opencascade.com>
Thu, 3 Oct 2019 15:38:55 +0000 (18:38 +0300)
committermpv <mpv@opencascade.com>
Thu, 3 Oct 2019 15:38:55 +0000 (18:38 +0300)
src/CollectionPlugin/CMakeLists.txt
src/CollectionPlugin/Test/Test3031.py [new file with mode: 0644]
src/Model/Model_AttributeSelection.cpp

index ee604e01f08100bf67ee7839aed96d8a3313eb51..65cac240e27667755d5258d1143d1ef9ce37975d 100644 (file)
@@ -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 (file)
index 0000000..a96f09f
--- /dev/null
@@ -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())
index e7a974e2e9f10be824427173820da54894455d5d..a5ec3df3217fbcfda3c0a194ecb33a1d967318f9 100644 (file)
@@ -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<ResultPtr>::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<ResultPtr>::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<GeomAPI_Shape>();
@@ -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;
         }
       }