Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / Test19115.py
1 # Copyright (C) 2020-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 GeomAPI import *
21 from salome.shaper import model
22
23 model.begin()
24 partSet = model.moduleDocument()
25 Part_1 = model.addPart(partSet)
26 Part_1_doc = Part_1.document()
27 model.addParameter(Part_1_doc, "h", "1")
28 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 0.5, "h")
29 Cylinder_2 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 0.1, "h")
30 Cylinder_3 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 0.4, "h")
31 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOY"), 0.1, False)
32 Partition_1_objects = [model.selection("SOLID", "Cylinder_1_1"), model.selection("SOLID", "Cylinder_2_1"), model.selection("SOLID", "Cylinder_3_1"), model.selection("FACE", "Plane_1"), model.selection("FACE", "PartSet/YOZ"), model.selection("FACE", "PartSet/XOZ")]
33 Partition_1 = model.addPartition(Part_1_doc, Partition_1_objects, keepSubResults = True)
34 Box_1 = model.addBox(Part_1_doc, 0.7, 0.1, 0.05)
35 Translation_1 = model.addTranslation(Part_1_doc, [model.selection("SOLID", "Box_1_1")], 0, -0.05, "0.75*h")
36 Recover_1 = model.addRecover(Part_1_doc, Partition_1, [Cylinder_1.result()])
37 Cut_1 = model.addCut(Part_1_doc, [model.selection("SOLID", "Translation_1_1")], [model.selection("SOLID", "Recover_1_1")], keepSubResults = True)
38 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Partition_1_1_14/Modified_Face&PartSet/XOZ/XOZ")])
39 Recover_2 = model.addRecover(Part_1_doc, Face_1, [Partition_1.result()], True)
40 Partition_2 = model.addPartition(Part_1_doc, [model.selection("COMPSOLID", "Recover_2_1"), model.selection("SOLID", "Cut_1_1")], keepSubResults = True)
41 model.end()
42
43 Fuse_objects = [model.selection("SOLID", "Partition_2_1_14"), model.selection("SOLID", "Partition_2_1_25"), model.selection("SOLID", "Partition_2_1_24")]
44
45
46 import time
47
48 tStart = time.time()
49
50 model.begin()
51 Union_1 = model.addUnion(Part_1_doc, Fuse_objects, keepSubResults = True)
52 model.do()
53
54 tUnion = time.time() - tStart
55
56 model.testNbResults(Union_1, 1)
57 model.testNbSubResults(Union_1, [23])
58 model.testNbSubShapes(Union_1, GeomAPI_Shape.SOLID, [23])
59 model.testNbSubShapes(Union_1, GeomAPI_Shape.FACE, [139])
60 model.testNbSubShapes(Union_1, GeomAPI_Shape.EDGE, [550])
61 model.testNbSubShapes(Union_1, GeomAPI_Shape.VERTEX, [1100])
62 model.testResultsVolumes(Union_1, [0.78640233633346512398532])
63
64 model.begin()
65 Part_1_doc.removeFeature(Union_1.feature())
66 model.end()
67
68 tStart = time.time()
69
70 model.begin()
71 Fuse_1 = model.addFuse(Part_1_doc, Fuse_objects, keepSubResults = True)
72 model.do()
73
74 tFuse = time.time() - tStart
75
76 model.testNbResults(Fuse_1, 1)
77 model.testNbSubResults(Fuse_1, [23])
78 model.testNbSubShapes(Fuse_1, GeomAPI_Shape.SOLID, [23])
79 model.testNbSubShapes(Fuse_1, GeomAPI_Shape.FACE, [139])
80 model.testNbSubShapes(Fuse_1, GeomAPI_Shape.EDGE, [550])
81 model.testNbSubShapes(Fuse_1, GeomAPI_Shape.VERTEX, [1100])
82 model.testResultsVolumes(Fuse_1, [0.78640233633346512398532])
83
84 print("Elapsed time of Union: {}".format(tUnion))
85 print("Elapsed time of Fuse: {}".format(tFuse))
86
87 assert(tFuse <= tUnion * 1.5)