From cdbd7bd80d6cc3ae4f184293476b4109539b2d18 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 10 Jul 2019 08:26:45 +0300 Subject: [PATCH] Fix incorrect result of selection of filter "F12: Topologically connected faces". --- .../FiltersPlugin_TopoConnectedFaces.py | 3 + src/FiltersPlugin/Test/TestFilters_Mixed.py | 71 +++++++++++++++++++ src/GeomAPI/GeomAPI_Shape.cpp | 21 ++++-- 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/FiltersPlugin/Test/TestFilters_Mixed.py diff --git a/src/FiltersPlugin/FiltersPlugin_TopoConnectedFaces.py b/src/FiltersPlugin/FiltersPlugin_TopoConnectedFaces.py index 7176e34e0..6f27040e9 100644 --- a/src/FiltersPlugin/FiltersPlugin_TopoConnectedFaces.py +++ b/src/FiltersPlugin/FiltersPlugin_TopoConnectedFaces.py @@ -64,6 +64,9 @@ class FiltersPlugin_TopoConnectedFaces(ModelAPI_Filter): if anOwner is None: return False topLevelShape = anOwner.shape() + if not topLevelShape.isSubShape(selectedShape): + return False; + mapVFAlgo = mapShapesAndAncestors(topLevelShape, GeomAPI_Shape.VERTEX, GeomAPI_Shape.FACE) mapVF = mapVFAlgo.map() mapEFAlgo = mapShapesAndAncestors(topLevelShape, GeomAPI_Shape.EDGE, GeomAPI_Shape.FACE) diff --git a/src/FiltersPlugin/Test/TestFilters_Mixed.py b/src/FiltersPlugin/Test/TestFilters_Mixed.py new file mode 100644 index 000000000..c81cd5b45 --- /dev/null +++ b/src/FiltersPlugin/Test/TestFilters_Mixed.py @@ -0,0 +1,71 @@ +# 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 +from GeomAPI import * + +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) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Top")) +SketchCircle_1 = Sketch_1.addCircle(5, 5, 3) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), False) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), 5, True) +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Top]"), False) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_2.result(), 5, True) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 3) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchCircle_1_2r_wire")], model.selection(), 5, 0) +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchCircle_1_2r_wire")], model.selection(), 10, -5) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "RelativeToSolid", args = [model.selection("SOLID", "Box_1_1"), "not_in"]), + model.addFilter(name = "TopoConnectedFaces", args = [model.selection("VERTEX", "[Extrusion_2_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_2_1/To_Face]")])]) +model.end() + +Reference = {} +# Faces of the box +ResultBox = Box_1.result().resultSubShapePair()[0] +exp = GeomAPI_ShapeExplorer(ResultBox.shape(), GeomAPI_Shape.FACE) +while exp.more(): + Reference[model.selection(ResultBox, exp.current())] = False + exp.next() + +# Faces of the first cylinder +ResultCylinder_1 = Extrusion_1.result().resultSubShapePair()[0] +exp = GeomAPI_ShapeExplorer(ResultCylinder_1.shape(), GeomAPI_Shape.FACE) +while exp.more(): + Reference[model.selection(ResultCylinder_1, exp.current())] = False + exp.next() + +# Faces of the second cylinder +ResultCylinder_2 = Extrusion_2.result().resultSubShapePair()[0] +exp = GeomAPI_ShapeExplorer(ResultCylinder_2.shape(), GeomAPI_Shape.FACE) +Reference[model.selection(ResultCylinder_2, exp.current())] = True; exp.next() +Reference[model.selection(ResultCylinder_2, exp.current())] = False; exp.next() +Reference[model.selection(ResultCylinder_2, exp.current())] = True; exp.next() + +model.checkFilter(Part_1_doc, model, Filters, Reference) + +model.begin() +Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_2_1/To_Face"), model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_1/SketchCircle_1_2"), Filters]) +model.end() +assert(model.checkPythonDump()) diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp index 634cd575d..99b27729f 100644 --- a/src/GeomAPI/GeomAPI_Shape.cpp +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -718,7 +718,15 @@ bool GeomAPI_Shape::isSelfIntersected(const int theLevelOfCheck) const bool GeomAPI_Shape::Comparator::operator()(const std::shared_ptr& theShape1, const std::shared_ptr& theShape2) const { - return theShape1->impl().TShape() < theShape2->impl().TShape(); + const TopoDS_Shape& aShape1 = theShape1->impl(); + const TopoDS_Shape& aShape2 = theShape2->impl(); + bool isLess = aShape1.TShape() < aShape2.TShape(); + if (aShape1.TShape() == aShape2.TShape()) { + Standard_Integer aHash1 = aShape1.Location().HashCode(IntegerLast()); + Standard_Integer aHash2 = aShape2.Location().HashCode(IntegerLast()); + isLess = aHash1 < aHash2; + } + return isLess; } bool GeomAPI_Shape::ComparatorWithOri::operator()( @@ -727,7 +735,12 @@ bool GeomAPI_Shape::ComparatorWithOri::operator()( { const TopoDS_Shape& aShape1 = theShape1->impl(); const TopoDS_Shape& aShape2 = theShape2->impl(); - return (aShape1.TShape() < aShape2.TShape()) || - (aShape1.TShape() == aShape2.TShape() && - aShape1.Orientation() < aShape2.Orientation()); + bool isLess = aShape1.TShape() < aShape2.TShape(); + if (aShape1.TShape() == aShape2.TShape()) { + Standard_Integer aHash1 = aShape1.Location().HashCode(IntegerLast()); + Standard_Integer aHash2 = aShape2.Location().HashCode(IntegerLast()); + isLess = (aHash1 < aHash2) || + (aHash1 == aHash2 && aShape1.Orientation() < aShape2.Orientation()); + } + return isLess; } -- 2.39.2