1 # Copyright (C) 2021-2022 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from salome.shaper import model
23 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
29 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
30 Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Top")])
32 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
33 Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Cylinder_1_1/Face_1"), model.selection("FACE", "Box_1_1/Front")])
34 Group_3 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Cylinder_1_1/Face_1")])
35 GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
36 GroupSubstraction_1 = model.addGroupSubstraction(Part_1_doc, [model.selection("COMPOUND", "GroupAddition_1")], [model.selection("COMPOUND", "Group_3")])
41 Part_2 = model.addPart(partSet)
42 Part_2_doc = Part_2.document()
44 ### Create ImportResult
45 ImportResult_1 = model.addImportResult(Part_2_doc, [model.selection("SOLID", "Part_1/Box_1_1"), model.selection("SOLID", "Part_1/Cylinder_1_1")])
50 from ModelAPI import *
55 assert(ImportResult_1.feature().error() == "")
56 model.testNbResults(ImportResult_1, 2)
57 model.testNbSubResults(ImportResult_1, [0, 0])
58 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.SOLID, [1, 1])
59 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.FACE, [6, 3])
60 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.EDGE, [24, 6])
61 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.VERTEX, [48, 12])
62 model.testResultsVolumes(ImportResult_1, [1000, 785.3981634])
63 model.testResultsAreas(ImportResult_1, [600, 471.238898])
65 # check groups are the same in both parts
66 assert(Part_1_doc.size("Groups") == Part_2_doc.size("Groups"))
67 REFIND = [0, 1, 3, 4, 2]
68 for ind in range(0, Part_1_doc.size("Groups")):
69 res1 = objectToResult(Part_1_doc.object("Groups", REFIND[ind]))
70 res2 = objectToResult(Part_2_doc.object("Groups", ind))
71 assert(res1 is not None)
72 assert(res2 is not None)
73 res1It = GeomAPI_ShapeExplorer(res1.shape(), GeomAPI_Shape.FACE)
74 res2It = GeomAPI_ShapeExplorer(res2.shape(), GeomAPI_Shape.FACE)
75 while res1It.more() and res2It.more():
76 shape1 = res1It.current()
77 shape2 = res2It.current()
78 assert(shape1.shapeType() == shape2.shapeType())
81 p1 = res1.shape().middlePoint()
82 p2 = res2.shape().middlePoint()
83 assert(math.fabs(p1.x() - p2.x()) <= TOLERANCE and math.fabs(p1.y() - p2.y()) <= TOLERANCE and math.fabs(p1.z() - p2.z()) <= TOLERANCE), "({}, {}, {}) != ({}, {}, {})".format(p1.x(), p1.y(), p1.z(), p2.x(), p2.y(), p2.z())
85 assert(model.checkPythonDump())