From dc252f25ab1beab0a3bd945945022ac4ee85a74a Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 12 Sep 2019 17:30:54 +0300 Subject: [PATCH] Test for the whole feature selected in group and BOP of groups for export to GEOM through XAO. --- .../Test/TestExportToGEOMPartSet.py | 2 +- .../Test/TestExportToGEOMWholeFeature.py | 130 ++++++++++++++++++ .../Test/TestExportToGEOMWholeResult.py | 1 - src/ConnectorAPI/Test/tests.set | 1 + 4 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 src/ConnectorAPI/Test/TestExportToGEOMWholeFeature.py diff --git a/src/ConnectorAPI/Test/TestExportToGEOMPartSet.py b/src/ConnectorAPI/Test/TestExportToGEOMPartSet.py index a3d4d7223..63d409e3c 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOMPartSet.py +++ b/src/ConnectorAPI/Test/TestExportToGEOMPartSet.py @@ -114,7 +114,7 @@ model.begin() model.exportToGEOM(Part_1_doc) model.end() -# check that in GEOM module there are reuslts: +# check that in GEOM module there are results: # extrusion of the first part # extrusion with group of the second part # extrusion with filed of the third part diff --git a/src/ConnectorAPI/Test/TestExportToGEOMWholeFeature.py b/src/ConnectorAPI/Test/TestExportToGEOMWholeFeature.py new file mode 100644 index 000000000..53e2897a7 --- /dev/null +++ b/src/ConnectorAPI/Test/TestExportToGEOMWholeFeature.py @@ -0,0 +1,130 @@ +# 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 +# +import salome + +from SketchAPI import * +from salome.shaper import model + +from salome.geom import geomBuilder + +import os +import tempfile + +salome.salome_init(1) +geompy = geomBuilder.New() + +## Get the last object published in the GEOM section of the object browser +def getGEOMShape(index): + sb = salome.myStudy.NewBuilder() + comp = salome.myStudy.FindComponent("GEOM") + obj = None + if comp: + iterator = salome.myStudy.NewChildIterator( comp ) + sobj = None + i = index + 1 + while iterator.More() and i: + sobj = iterator.Value() + iterator.Next() + i = i - 1 + if i == 0 and sobj: + obj = sobj.GetObject() + else: + raise Exception("GEOM component " + str(index) + " not found.") + return obj + +## Get the sub-object i of an object in the object browser +# Numerotation starts at 1 +def getSubObject(obj, i): + ok, sub_sobj = salome.ObjectToSObject(obj).FindSubObject(i) + if not ok: + raise Exception("No child found at %i for %s"%(i, obj.GetName())) + sub_obj = sub_sobj.GetObject() + return sub_obj + + +def testExportToGEOM(): + 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("YOZ")) + 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()) + SketchCircle_2 = Sketch_1.addCircle(20, -15, 20) + SketchCircle_3 = Sketch_1.addCircle(0, 25, 24.7213595499958) + SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchCircle_1.results()[1], SketchCircle_3.center()) + SketchCircle_4 = Sketch_1.addCircle(-20, -15, 20) + SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchCircle_1.results()[1], SketchCircle_4.center()) + SketchConstraintTangent_1 = Sketch_1.setTangent(SketchCircle_4.results()[1], SketchCircle_2.results()[1]) + SketchConstraintTangent_2 = Sketch_1.setTangent(SketchCircle_3.results()[1], SketchCircle_2.results()[1]) + SketchConstraintTangent_3 = Sketch_1.setTangent(SketchCircle_4.results()[1], SketchCircle_3.results()[1]) + SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchCircle_2.center(), SketchCircle_1.results()[1]) + SketchConstraintEqual_1 = Sketch_1.setEqual(SketchCircle_2.results()[1], SketchCircle_4.results()[1]) + SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_2.results()[1], 20) + SketchConstraintRadius_2 = Sketch_1.setRadius(SketchCircle_1.results()[1], 25) + SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OZ"), False) + SketchLine_1 = SketchProjection_2.createdFeature() + SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_1.result(), SketchCircle_3.center()) + model.do() + Extrusion_1_objects = [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchCircle_4_2r-SketchCircle_4_2r-SketchCircle_3_2r"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchCircle_3_2r-SketchCircle_2_2r-SketchCircle_2_2r"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchCircle_2_2r-SketchCircle_4_2r")] + Extrusion_1 = model.addExtrusion(Part_1_doc, Extrusion_1_objects, model.selection(), 10, 0) + # select all results of an extrusion feature + Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("COMPSOLID", "all-in-Extrusion_1")]) + Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("SOLID", "Extrusion_1_2")]) + GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "Group_1")], [model.selection("COMPOUND", "Group_2")]) + model.do() + model.exportToGEOM(Part_1_doc) + model.end() + + # check that in GEOM module there are 3-SOLIDs-reuslts, with 2 groups each + shape1 = getGEOMShape(0) + assert(shape1) + assert(shape1.GetName() == "Extrusion_1_1") + assert(geompy.NumberOfSolids(shape1) == 1) + assert(salome.ObjectToSObject(shape1).FindSubObject(1)[1]) + assert(salome.ObjectToSObject(shape1).FindSubObject(1)[1].GetName() == "Group_1") + assert(salome.ObjectToSObject(shape1).FindSubObject(2)[1]) + assert(salome.ObjectToSObject(shape1).FindSubObject(2)[1].GetName() == "GroupSubstraction_1") + + shape2 = getGEOMShape(1) + assert(shape2) + assert(shape2.GetName() == "Extrusion_1_2") + assert(geompy.NumberOfSolids(shape2) == 1) + assert(salome.ObjectToSObject(shape2).FindSubObject(1)[1]) + assert(salome.ObjectToSObject(shape2).FindSubObject(1)[1].GetName() == "Group_1") + assert(salome.ObjectToSObject(shape2).FindSubObject(2)[1]) + assert(salome.ObjectToSObject(shape2).FindSubObject(2)[1].GetName() == "Group_2") + + shape3 = getGEOMShape(2) + assert(shape3) + assert(shape3.GetName() == "Extrusion_1_3") + assert(geompy.NumberOfSolids(shape3) == 1) + assert(salome.ObjectToSObject(shape3).FindSubObject(1)[1]) + assert(salome.ObjectToSObject(shape3).FindSubObject(1)[1].GetName() == "Group_1") + assert(salome.ObjectToSObject(shape3).FindSubObject(2)[1]) + assert(salome.ObjectToSObject(shape3).FindSubObject(2)[1].GetName() == "GroupSubstraction_1") + + shape4 = getGEOMShape(3) + assert(not shape4) + + +if __name__ == '__main__': + testExportToGEOM() diff --git a/src/ConnectorAPI/Test/TestExportToGEOMWholeResult.py b/src/ConnectorAPI/Test/TestExportToGEOMWholeResult.py index 24f6ecded..009f1f190 100644 --- a/src/ConnectorAPI/Test/TestExportToGEOMWholeResult.py +++ b/src/ConnectorAPI/Test/TestExportToGEOMWholeResult.py @@ -86,7 +86,6 @@ def testExportToGEOM(): Group_2 = model.addGroup(Part_1_doc, "FACE", [model.selection("COMPSOLID", "Partition_1_1")]) model.do() - # First export to GEOM model.exportToGEOM(Part_1_doc) model.end() diff --git a/src/ConnectorAPI/Test/tests.set b/src/ConnectorAPI/Test/tests.set index 0be506a45..2c4eac504 100644 --- a/src/ConnectorAPI/Test/tests.set +++ b/src/ConnectorAPI/Test/tests.set @@ -22,5 +22,6 @@ SET(TEST_NAMES TestExportToGEOMAllGroupsAndFields TestExportToGEOMPartSet TestExportToGEOMWholeResult + TestExportToGEOMWholeFeature Test2882 ) -- 2.39.2