Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestImportResultWithGroups1.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 Box_1 = model.addBox(Part_1_doc, 10, 10, 10)
29 ### Create Groups
30 Group_1 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Left"), model.selection("FACE", "Box_1_1/Top")])
31 Group_2 = model.addGroup(Part_1_doc, "Faces", [model.selection("FACE", "Box_1_1/Front"), model.selection("FACE", "Box_1_1/Top")])
32 GroupAddition_1 = model.addGroupAddition(Part_1_doc, [model.selection("COMPOUND", "Group_1"), model.selection("COMPOUND", "Group_2")])
33
34 model.do()
35
36 ### Create Part 2
37 Part_2 = model.addPart(partSet)
38 Part_2_doc = Part_2.document()
39 ImportResult_1 = model.addImportResult(Part_2_doc, [model.selection("SOLID", "Part_1/Box_1_1")])
40
41 model.end()
42
43 from GeomAPI import *
44 from ModelAPI import *
45 import math
46
47 TOLERANCE = 1.e-7
48
49 assert(ImportResult_1.feature().error() == "")
50 model.testNbResults(ImportResult_1, 1)
51 model.testNbSubResults(ImportResult_1, [0])
52 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.SOLID, [1])
53 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.FACE, [6])
54 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.EDGE, [24])
55 model.testNbSubShapes(ImportResult_1, GeomAPI_Shape.VERTEX, [48])
56 model.testResultsVolumes(ImportResult_1, [1000])
57 model.testResultsAreas(ImportResult_1, [600])
58
59 # check groups are the same in both parts
60 assert(Part_1_doc.size("Groups") == Part_2_doc.size("Groups"))
61 for ind in range(0, Part_1_doc.size("Groups")):
62     res1 = objectToResult(Part_1_doc.object("Groups", ind))
63     res2 = objectToResult(Part_2_doc.object("Groups", ind))
64     assert(res1 is not None)
65     assert(res2 is not None)
66     res1It = GeomAPI_ShapeExplorer(res1.shape(), GeomAPI_Shape.FACE)
67     res2It = GeomAPI_ShapeExplorer(res2.shape(), GeomAPI_Shape.FACE)
68     while res1It.more() and res2It.more():
69         shape1 = res1It.current()
70         shape2 = res2It.current()
71         assert(shape1.shapeType() == shape2.shapeType())
72         res1It.next()
73         res2It.next()
74     p1 = res1.shape().middlePoint()
75     p2 = res2.shape().middlePoint()
76     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())
77
78 assert(model.checkPythonDump())