Salome HOME
b68df371107eb2fa7339b080d9ab089ae334d227
[modules/shaper.git] / src / CollectionPlugin / Test / TestCreateShapesFromGroups.py
1 # Copyright (C) 2021  CEA/DEN, EDF R&D
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
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28
29 ### Create Box
30 Box_1 = model.addBox(Part_1_doc, 10, 10, 1)
31
32 ### Create RevolutionFuse
33 RevolutionFuse_1 = model.addRevolutionFuse(Part_1_doc, [], model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), 80, 0, [model.selection("SOLID", "Box_1_1")])
34
35 ### Create Sketch
36 Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Top"))
37
38 ### Create SketchArc
39 SketchArc_1 = Sketch_1.addArc(4.7, 4.9, 1.8, 3.2, 7.6, 3.2, True)
40
41 ### Create SketchArc
42 SketchArc_2 = Sketch_1.addArc(4.7, 4.9, 1.4, 3.2, 8.1, 3.2, True)
43
44 ### Create SketchLine
45 SketchLine_1 = Sketch_1.addLine(1.4, 3.2, 1.8, 3.2)
46 Sketch_1.setCoincident(SketchArc_2.startPoint(), SketchLine_1.startPoint())
47 Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
48
49 ### Create SketchLine
50 SketchLine_2 = Sketch_1.addLine(7.6, 3.2, 8.1, 3.2)
51 Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_2.startPoint())
52 Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchLine_2.endPoint())
53 Sketch_1.setCoincident(SketchArc_1.center(), SketchArc_2.center())
54 Sketch_1.setHorizontal(SketchLine_1.result())
55 Sketch_1.setCollinear(SketchLine_1.result(), SketchLine_2.result())
56 Sketch_1.setRadius(SketchArc_1.results()[1], 3.5)
57 Sketch_1.setRadius(SketchArc_2.results()[1], 4)
58 RevolutionFuse_1.setNestedSketch(Sketch_1)
59
60 ### Create Group
61 Group_1_objects = [model.selection("FACE", "RevolutionFuse_1_1/Modified_Face&Box_1_1/Top"),
62                    model.selection("FACE", "RevolutionFuse_1_1/Generated_Face&Sketch_1/SketchArc_1_2"),
63                    model.selection("FACE", "RevolutionFuse_1_1/Generated_Face&Sketch_1/SketchArc_2_2"),
64                    model.selection("FACE", "RevolutionFuse_1_1/To_Face")]
65 Group_1 = model.addGroup(Part_1_doc, "Faces", Group_1_objects)
66 Group_1.setName("Group_faces")
67 Group_1.result().setName("Group_faces")
68
69 ### Create GroupShape
70 GroupShape_1 = model.addGroupShape(Part_1_doc, [model.selection("COMPOUND", "Group_faces")])
71 GroupShape_1.result().setName("GroupShape_1")
72
73 ### Create Shell
74 Shell_1 = model.addShell(Part_1_doc, [model.selection("COMPOUND", "GroupShape_1")])
75 Shell_1.result().setName("Shell_1_1")
76
77 ### Create Group
78 Group_2_objects = [model.selection("EDGE", "[RevolutionFuse_1_1/To_Face][GroupShape_1_1_3/GroupShape_1_1_3]"),
79                    model.selection("EDGE", "[GroupShape_1_1_3/GroupShape_1_1_3][new_weak_name_1]"),
80                    model.selection("EDGE", "[GroupShape_1_1_3/GroupShape_1_1_3][new_weak_name_4]")]
81 Group_2 = model.addGroup(Part_1_doc, "Edges", Group_2_objects)
82 Group_2.setName("Group_edges")
83 Group_2.result().setName("Group_edges")
84
85 ### Create GroupShape
86 GroupShape_2 = model.addGroupShape(Part_1_doc, [model.selection("COMPOUND", "Group_edges")])
87 GroupShape_2.result().setName("GroupShape_2")
88
89 ### Create Wire
90 Wire_1_objects = [model.selection("EDGE", "GroupShape_2_1_2"),
91                   model.selection("EDGE", "GroupShape_2_1_3"),
92                   model.selection("EDGE", "GroupShape_2_1_1")]
93 Wire_1 = model.addWire(Part_1_doc, Wire_1_objects, False)
94 Wire_1.result().setName("Wire_1_1")
95
96 model.end()
97
98 #=============================================================================
99 # Tests :
100 #=============================================================================
101 # Group of edges :
102 model.checkResult(Wire_1, model, 1, [0], [0], [0], [3], [6])
103 r=Wire_1.defaultResult()
104 s=r.shape()
105 dim=s.computeSize()
106 dim=dim[1:]
107 dx=abs(dim[3]-dim[0])
108 dy=abs(dim[4]-dim[1])
109 dz=abs(dim[5]-dim[2])
110 print(dx,dy,dz)
111 tol=1e-06
112 assert(abs(dx-7.0000002) <= tol)
113 assert(abs(dy-2.6261643) <= tol)
114 assert(abs(dz-8.46802318) <= tol)