Salome HOME
4dc395924f5f8e0f2d3752c62538005a0916f86a
[modules/shaper.git] / src / FeaturesPlugin / Test / TestImportResultWithGroups2.py
1 # Copyright (C) 2021-2023  CEA, EDF
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from salome.shaper import model
21
22 model.begin()
23 partSet = model.moduleDocument()
24
25 ### Create Part 1
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28
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")])
31
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")])
37
38 model.do()
39
40 ### Create Part 2
41 Part_2 = model.addPart(partSet)
42 Part_2_doc = Part_2.document()
43
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")])
46
47 model.end()
48
49 from GeomAPI import *
50 from ModelAPI import *
51 import math
52
53 TOLERANCE = 1.e-7
54
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])
64
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())
79         res1It.next()
80         res2It.next()
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())
84
85 assert(model.checkPythonDump())