From 36707acdcb478c8dfa5608a49537a5c8cb8454bc Mon Sep 17 00:00:00 2001 From: mpv Date: Tue, 26 Nov 2019 13:53:56 +0300 Subject: [PATCH] Added unit tests for selection of the whole feature in group for the task #3082 : To be able to create a group on a whole feature --- src/CollectionPlugin/CMakeLists.txt | 2 + .../Test/TestGroupWholeFeature1.py | 65 +++++++++++++++++++ .../Test/TestGroupWholeFeature2.py | 58 +++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/CollectionPlugin/Test/TestGroupWholeFeature1.py create mode 100644 src/CollectionPlugin/Test/TestGroupWholeFeature2.py diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index 3b0fa5738..a02f2aa66 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -158,4 +158,6 @@ ADD_UNIT_TESTS( TestGroupWholeResult1.py TestGroupWholeResult2.py Test3031.py + TestGroupWholeFeature1.py + TestGroupWholeFeature2.py ) diff --git a/src/CollectionPlugin/Test/TestGroupWholeFeature1.py b/src/CollectionPlugin/Test/TestGroupWholeFeature1.py new file mode 100644 index 000000000..ef512a9dc --- /dev/null +++ b/src/CollectionPlugin/Test/TestGroupWholeFeature1.py @@ -0,0 +1,65 @@ +# 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 +# + +# Tests python API for the whole feature (all results) in group selection +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Extrusion_1 = model.addExtrusion(Part_1_doc, [], model.selection(), 10, 0) +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_1.addCircle(0, 0, 10) +Extrusion_1.setNestedSketch(Sketch_1) +Group_1 = model.addGroup(Part_1_doc, "Vertices", [model.selection("COMPOUND", "all-in-Extrusion_1")]) +Group_1.setName("CylVertices") +Group_1.result().setName("CylVertices") +Group_2 = model.addGroup(Part_1_doc, "Edges", [model.selection("COMPOUND", "all-in-Extrusion_1")]) +Group_2.setName("CylEdges") +Group_2.result().setName("CylEdges") +Group_3 = model.addGroup(Part_1_doc, "Faces", [model.selection("COMPOUND", "all-in-Extrusion_1")]) +Group_3.setName("CylFaces") +Group_3.result().setName("CylFaces") +Group_4 = model.addGroup(Part_1_doc, "Solids", [model.selection("COMPOUND", "all-in-Extrusion_1")]) +Group_4.setName("CylSolid") +Group_4.result().setName("CylSolid") +model.end() + +from GeomAPI import GeomAPI_ShapeIterator + +# group variable, type of selection, number of expected sub-shapes, sub-shapes type +test_list = [(Group_1, "Vertices", 2, 7), (Group_2, "Edges", 3, 6), (Group_3, "Faces", 3, 4), (Group_4, "Solids", 1, 2)] +for test in test_list: + assert(test[0].groupList().selectionType() == test[1]) + assert(len(test[0].results()) == 1) + assert(test[0].result().shapeType() == "COMPOUND") + + aResultShape = test[0].feature().firstResult().shape() + anIter = GeomAPI_ShapeIterator(aResultShape) + aNum = 0 + while anIter.more(): + aShape = anIter.current() + assert(aShape.shapeType() == test[3]) + aNum = aNum + 1 + anIter.next() + + assert(aNum == test[2]) + +assert(model.checkPythonDump()) diff --git a/src/CollectionPlugin/Test/TestGroupWholeFeature2.py b/src/CollectionPlugin/Test/TestGroupWholeFeature2.py new file mode 100644 index 000000000..8229de9d9 --- /dev/null +++ b/src/CollectionPlugin/Test/TestGroupWholeFeature2.py @@ -0,0 +1,58 @@ +# 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 +# + +# Tests python API for the whole feature (all results) in group selection +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")) +SketchLine_1 = Sketch_1.addLine(-12, 15, -12, -15) +SketchLine_2 = Sketch_1.addLine(-12, -15, 12, 15) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchLine_3 = Sketch_1.addLine(12, 15, 12, -15) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchLine_4 = Sketch_1.addLine(12, -15, -12, 15) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_4f"), model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r")], model.selection(), 10, 0) +Group_1 = model.addGroup(Part_1_doc, "Vertices", [model.selection("COMPOUND", "all-in-Extrusion_1")]) +model.end() + +# check the group result: it must be compound of 12 vertices +assert(Group_1.groupList().selectionType() == "Vertices") +assert(len(Group_1.results()) == 1) +assert(Group_1.result().shapeType() == "COMPOUND") + +from GeomAPI import GeomAPI_ShapeIterator +aResultShape = Group_1.feature().firstResult().shape() +anIter = GeomAPI_ShapeIterator(aResultShape) +aNum = 0 +while anIter.more(): + anEdge = anIter.current() + assert(anEdge.isVertex()) + aNum = aNum + 1 + anIter.next() + +assert(aNum == 12) + +assert(model.checkPythonDump()) -- 2.39.2