From f3ad05e50c4a462c08c31990706c8cc6acc646ac Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 30 Jul 2019 10:06:28 +0300 Subject: [PATCH] Issue #2951: "Opposite to an edge" problems Add a wire explorer to iterate edges of wire according to connectivity order. --- src/FiltersPlugin/CMakeLists.txt | 1 + .../FiltersPlugin_OppositeToEdge.cpp | 24 +- src/FiltersPlugin/Test/Test2946.py | 4 +- src/FiltersPlugin/Test/Test2951.py | 227 ++++++++++++++++++ .../Test/TestFilter_OppositeToEdge.py | 76 ++++++ .../Test/TestFilter_OppositeToEdge_Exclude.py | 76 ++++++ src/GeomAPI/CMakeLists.txt | 2 + src/GeomAPI/GeomAPI_WireExplorer.cpp | 63 +++++ src/GeomAPI/GeomAPI_WireExplorer.h | 64 +++++ 9 files changed, 529 insertions(+), 8 deletions(-) create mode 100644 src/FiltersPlugin/Test/Test2951.py create mode 100644 src/GeomAPI/GeomAPI_WireExplorer.cpp create mode 100644 src/GeomAPI/GeomAPI_WireExplorer.h diff --git a/src/FiltersPlugin/CMakeLists.txt b/src/FiltersPlugin/CMakeLists.txt index f4dd05839..62482f88e 100644 --- a/src/FiltersPlugin/CMakeLists.txt +++ b/src/FiltersPlugin/CMakeLists.txt @@ -179,4 +179,5 @@ ADD_UNIT_TESTS( TestFilter_TopoConnectedFaces_Prop_Exclude_Face2.py TestFilter_TopoConnectedFaces_Prop_Exclude_Face3.py Test2946.py + Test2951.py ) diff --git a/src/FiltersPlugin/FiltersPlugin_OppositeToEdge.cpp b/src/FiltersPlugin/FiltersPlugin_OppositeToEdge.cpp index 6e0e0d8a3..bf5805e15 100644 --- a/src/FiltersPlugin/FiltersPlugin_OppositeToEdge.cpp +++ b/src/FiltersPlugin/FiltersPlugin_OppositeToEdge.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include #include @@ -51,12 +53,21 @@ static GeomShapePtr oppositeEdgeInQuadFace(const GeomShapePtr theEdge, int aNbEdges = 0; int anOriginalEdgeIndex = -THE_QUAD; GeomShapePtr anOppositeEdge; - GeomAPI_ShapeExplorer anExp(theFace, GeomAPI_Shape::EDGE); + GeomAPI_ShapeExplorer aWExp(theFace, GeomAPI_Shape::WIRE); + GeomWirePtr aWire = aWExp.current()->wire(); + aWExp.next(); + if (aWExp.more()) { + // face with a hole is not a quadrangle + return anOppositeEdge; + } + + GeomAPI_WireExplorer anExp(aWire); while (anExp.more()) { if (anExp.current()->isSame(theEdge)) anOriginalEdgeIndex = aNbEdges; else if (aNbEdges == anOriginalEdgeIndex + THE_QUAD / 2) { - anOppositeEdge = anExp.current(); + if (anOriginalEdgeIndex < THE_QUAD) + anOppositeEdge = anExp.current(); if (aNbEdges >= THE_QUAD) break; } @@ -70,7 +81,7 @@ static GeomShapePtr oppositeEdgeInQuadFace(const GeomShapePtr theEdge, break; } if (!anOppositeEdge) - anExp.reinit(); + anExp.init(aWire); } } return anOppositeEdge; @@ -133,8 +144,11 @@ bool FiltersPlugin_OppositeToEdge::isOk(const GeomShapePtr& theShape, const Resu if (myCachedShapes.empty()) { ResultBodyPtr aBaseResult = ModelAPI_Tools::bodyOwner(aList->context(), true); - if (!aBaseResult.get()) - return false; + if (!aBaseResult.get()) { + aBaseResult = std::dynamic_pointer_cast(aList->context()); + if (!aBaseResult.get()) + return false; + } cacheOppositeEdges(aBaseResult->shape(), anEdge, const_cast(this)->myCachedShapes); diff --git a/src/FiltersPlugin/Test/Test2946.py b/src/FiltersPlugin/Test/Test2946.py index b75bf1fdb..1ffef2200 100644 --- a/src/FiltersPlugin/Test/Test2946.py +++ b/src/FiltersPlugin/Test/Test2946.py @@ -16,6 +16,7 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # + from SketchAPI import * from salome.shaper import model @@ -82,9 +83,6 @@ SketchConstraintCoincidence_26 = Sketch_1.setCoincident(SketchArc_7.endPoint(), SketchConstraintCoincidence_27 = Sketch_1.setCoincident(SketchArc_8.startPoint(), SketchLine_1.result()) model.do() Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_8_2f-SketchLine_7f-SketchArc_1_2f-SketchLine_4r-SketchArc_5_2f-SketchLine_8f-SketchArc_2_2f-SketchLine_5r-SketchArc_6_2f-SketchLine_9f-SketchArc_3_2f-SketchLine_6r-SketchArc_7_2f-SketchLine_3f-SketchArc_4_2f-SketchLine_1r-SketchCircle_1_2r")], model.selection(), 10, 0) -#Group_1_objects = [model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_7][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_8][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_9][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/To_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face]"), model.filters(Part_1_doc, [model.addFilter(name = "OnPlane", args = [model.selection()])])] -#Group_1 = model.addGroup(Part_1_doc, Group_1_objects) -#model.do() Filters = model.filters(Part_1_doc, [model.addFilter(name = "OnPlane", args = [model.selection("FACE", "Extrusion_1_1/To_Face")])]) model.end() diff --git a/src/FiltersPlugin/Test/Test2951.py b/src/FiltersPlugin/Test/Test2951.py new file mode 100644 index 000000000..7729e0a41 --- /dev/null +++ b/src/FiltersPlugin/Test/Test2951.py @@ -0,0 +1,227 @@ +# 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 SketchAPI import * + +from salome.shaper import model + +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")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchCircle_1 = Sketch_1.addCircle(0, 0, 25) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchPoint_1.result(), SketchCircle_1.center()) +SketchLine_1 = Sketch_1.addLine(-35, 23, -35, -23) +SketchLine_2 = Sketch_1.addLine(-35, -23, -28, -23) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(-28, -23, -23, -28) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchLine_4 = Sketch_1.addLine(-23, -28, -23, -35) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchLine_5 = Sketch_1.addLine(-23, -35, 23, -35) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint()) +SketchLine_6 = Sketch_1.addLine(23, -35, 23, -28) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint()) +SketchLine_7 = Sketch_1.addLine(23, -28, 28, -23) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint()) +SketchLine_8 = Sketch_1.addLine(28, -23, 35, -23) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint()) +SketchLine_9 = Sketch_1.addLine(35, -23, 35, 23) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint()) +SketchLine_10 = Sketch_1.addLine(35, 23, 28, 23) +SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint()) +SketchLine_11 = Sketch_1.addLine(28, 23, 23, 28) +SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint()) +SketchLine_12 = Sketch_1.addLine(23, 28, 23, 35) +SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint()) +SketchLine_13 = Sketch_1.addLine(23, 35, -23, 35) +SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_13.startPoint()) +SketchLine_14 = Sketch_1.addLine(-23, 35, -23, 28) +SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint()) +SketchLine_15 = Sketch_1.addLine(-23, 28, -28, 23) +SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_14.endPoint(), SketchLine_15.startPoint()) +SketchLine_16 = Sketch_1.addLine(-28, 23, -35, 23) +SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_15.endPoint(), SketchLine_16.startPoint()) +SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_16.endPoint()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_9.result()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_13.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result()) +SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_2.result()) +SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_2.result(), SketchLine_8.result()) +SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_16.result()) +SketchConstraintCollinear_2 = Sketch_1.setCollinear(SketchLine_16.result(), SketchLine_10.result()) +SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_4.result()) +SketchConstraintCollinear_3 = Sketch_1.setCollinear(SketchLine_4.result(), SketchLine_14.result()) +SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_6.result()) +SketchConstraintCollinear_4 = Sketch_1.setCollinear(SketchLine_6.result(), SketchLine_12.result()) +SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_4.result()) +SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_16.result(), SketchLine_14.result()) +SketchConstraintEqual_3 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_16.result()) +SketchConstraintEqual_4 = Sketch_1.setEqual(SketchLine_14.result(), SketchLine_12.result()) +SketchConstraintEqual_5 = Sketch_1.setEqual(SketchLine_12.result(), SketchLine_10.result()) +SketchConstraintEqual_6 = Sketch_1.setEqual(SketchLine_10.result(), SketchLine_8.result()) +SketchConstraintEqual_7 = Sketch_1.setEqual(SketchLine_6.result(), SketchLine_4.result()) +SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_9.result(), 35, True) +SketchConstraintDistance_2 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), 35, True) +SketchConstraintDistance_3 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_5.result(), 35, True) +SketchConstraintDistance_4 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_13.result(), 35, True) +SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 25) +SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 7) +SketchConstraintDistance_5 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_4.result(), 23, True) +SketchConstraintDistance_6 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_2.result(), 23, True) +SketchConstraintDistance_7 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_12.result(), 23, True) +SketchConstraintDistance_8 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_16.result(), 23, True) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f-SketchLine_7f-SketchLine_8f-SketchLine_9f-SketchLine_10f-SketchLine_11f-SketchLine_12f-SketchLine_13f-SketchLine_14f-SketchLine_15f-SketchLine_16f-SketchCircle_1_2r")], model.selection(), 10, 0) +Filters = model.filters(Part_1_doc, [model.addFilter(name = "OppositeToEdge", args = [model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_9][Extrusion_1_1/To_Face]")])]) +model.end() + +from GeomAPI import * + +Reference = {} +ExtrusionResult = Extrusion_1.result().resultSubShapePair()[0] +exp = GeomAPI_ShapeExplorer(ExtrusionResult.shape(), GeomAPI_Shape.EDGE) +# edges on face 1 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 2 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 3 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 4 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 5 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 6 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 7 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 8 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 9 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = True; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = True; exp.next() +# edges on face 10 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 11 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 12 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 13 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 14 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 15 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 16 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 17 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 18 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = True; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +# edges on face 19 +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = True; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +Reference[model.selection(ExtrusionResult, exp.current())] = False; exp.next() +assert(not exp.more()) + +model.checkFilter(Part_1_doc, model, Filters, Reference) diff --git a/src/FiltersPlugin/Test/TestFilter_OppositeToEdge.py b/src/FiltersPlugin/Test/TestFilter_OppositeToEdge.py index 8233491c3..86b9b99af 100644 --- a/src/FiltersPlugin/Test/TestFilter_OppositeToEdge.py +++ b/src/FiltersPlugin/Test/TestFilter_OppositeToEdge.py @@ -54,34 +54,72 @@ while exp.more(): # sub-result 0 SubResult = Partition_1.result().subResult(0).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +assert(not exp.more()) # sub-result 1 SubResult = Partition_1.result().subResult(1).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +assert(not exp.more()) # sub-result 2 SubResult = Partition_1.result().subResult(2).resultSubShapePair()[0] @@ -100,18 +138,37 @@ while exp.more(): # sub-result 4 SubResult = Partition_1.result().subResult(4).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +assert(not exp.more()) # sub-result 5 SubResult = Partition_1.result().subResult(5).resultSubShapePair()[0] @@ -123,18 +180,37 @@ while exp.more(): # sub-result 6 SubResult = Partition_1.result().subResult(6).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +assert(not exp.more()) # sub-result 7 SubResult = Partition_1.result().subResult(7).resultSubShapePair()[0] diff --git a/src/FiltersPlugin/Test/TestFilter_OppositeToEdge_Exclude.py b/src/FiltersPlugin/Test/TestFilter_OppositeToEdge_Exclude.py index b33e409e4..2af1de6da 100644 --- a/src/FiltersPlugin/Test/TestFilter_OppositeToEdge_Exclude.py +++ b/src/FiltersPlugin/Test/TestFilter_OppositeToEdge_Exclude.py @@ -54,34 +54,72 @@ while exp.more(): # sub-result 0 SubResult = Partition_1.result().subResult(0).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +assert(not exp.more()) # sub-result 1 SubResult = Partition_1.result().subResult(1).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +assert(not exp.more()) # sub-result 2 SubResult = Partition_1.result().subResult(2).resultSubShapePair()[0] @@ -100,18 +138,37 @@ while exp.more(): # sub-result 4 SubResult = Partition_1.result().subResult(4).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +assert(not exp.more()) # sub-result 5 SubResult = Partition_1.result().subResult(5).resultSubShapePair()[0] @@ -123,18 +180,37 @@ while exp.more(): # sub-result 6 SubResult = Partition_1.result().subResult(6).resultSubShapePair()[0] exp = GeomAPI_ShapeExplorer(SubResult.shape(), GeomAPI_Shape.EDGE) +# edges of face 1 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 2 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 3 Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() Reference[model.selection(SubResult, exp.current())] = True; exp.next() Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 4 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +# edges of face 5 +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +# edges of face 6 +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +Reference[model.selection(SubResult, exp.current())] = False; exp.next() +Reference[model.selection(SubResult, exp.current())] = True; exp.next() +assert(not exp.more()) # sub-result 7 SubResult = Partition_1.result().subResult(7).resultSubShapePair()[0] diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 92aecd7c4..cade6fc2f 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -67,6 +67,7 @@ SET(PROJECT_HEADERS GeomAPI_Cone.h GeomAPI_Torus.h GeomAPI_Box.h + GeomAPI_WireExplorer.h ) SET(PROJECT_SOURCES @@ -112,6 +113,7 @@ SET(PROJECT_SOURCES GeomAPI_Cone.cpp GeomAPI_Torus.cpp GeomAPI_Box.cpp + GeomAPI_WireExplorer.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAPI/GeomAPI_WireExplorer.cpp b/src/GeomAPI/GeomAPI_WireExplorer.cpp new file mode 100644 index 000000000..efd37a0ae --- /dev/null +++ b/src/GeomAPI/GeomAPI_WireExplorer.cpp @@ -0,0 +1,63 @@ +// 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 +#include + +#include + +#define MY_EXPLORER implPtr() + +GeomAPI_WireExplorer::GeomAPI_WireExplorer() + : GeomAPI_Interface(new BRepTools_WireExplorer()) +{ +} + +GeomAPI_WireExplorer::GeomAPI_WireExplorer(const GeomWirePtr& theWire) + : GeomAPI_Interface(new BRepTools_WireExplorer(theWire->impl())) +{ +} + +void GeomAPI_WireExplorer::init(const GeomWirePtr& theWire) +{ + MY_EXPLORER->Init(theWire->impl()); +} + +bool GeomAPI_WireExplorer::more() const +{ + return MY_EXPLORER->More() == Standard_True; +} + +void GeomAPI_WireExplorer::next() +{ + MY_EXPLORER->Next(); +} + +std::shared_ptr GeomAPI_WireExplorer::current() +{ + const TopoDS_Shape& aShape = MY_EXPLORER->Current(); + std::shared_ptr aGeomShape(new GeomAPI_Shape()); + aGeomShape->setImpl(new TopoDS_Shape(aShape)); + return aGeomShape; +} + +void GeomAPI_WireExplorer::clear() +{ + MY_EXPLORER->Clear(); +} diff --git a/src/GeomAPI/GeomAPI_WireExplorer.h b/src/GeomAPI/GeomAPI_WireExplorer.h new file mode 100644 index 000000000..432858299 --- /dev/null +++ b/src/GeomAPI/GeomAPI_WireExplorer.h @@ -0,0 +1,64 @@ +// 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 GeomAPI_WireExplorer_H_ +#define GeomAPI_WireExplorer_H_ + +#include +#include + +class GeomAPI_Shape; +class GeomAPI_Wire; + +/** \class GeomAPI_WireExplorer + * \ingroup DataModel + * \brief This class is used to explore edges of wire in the order of connectivity. + */ +class GeomAPI_WireExplorer : public GeomAPI_Interface +{ +public: + /// Default constructor. Creates an empty explorer, becomes usefull after Init. + GEOMAPI_EXPORT GeomAPI_WireExplorer(); + + /** \brief Constructs an iterator on a wire. + * \param[in] theWire a wire to explore. + */ + GEOMAPI_EXPORT GeomAPI_WireExplorer(const std::shared_ptr& theWire); + + /** \brief Resets this explorer. + * \param[in] theWire a wire to explore. + */ + GEOMAPI_EXPORT void init(const std::shared_ptr& theWire); + + /// \return true if there are more shapes in the exploration. + GEOMAPI_EXPORT bool more() const; + + /// Moves to the next Shape in the exploration or do nothing + /// if there are no more shapes to explore. + GEOMAPI_EXPORT void next(); + + /// \return the current shape in the exploration or empty pointer + /// if this explorer has no more shapes to explore. + GEOMAPI_EXPORT std::shared_ptr current(); + + /// Clears the content of the explorer. It will return False on more(). + GEOMAPI_EXPORT void clear(); +}; + +#endif \ No newline at end of file -- 2.30.2