Salome HOME
b31464667f6fe1ae5107c44769b3014cf821a4e3
[modules/shaper.git] / src / BuildPlugin / Test / TestPolyline.py
1 # Copyright (C) 2014-2023  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 # Create document
23 model.begin()
24 partSet = model.moduleDocument()
25 Part_1 = model.addPart(partSet)
26 Part_1_doc = Part_1.document()
27
28 # Create sketch
29 #
30 #  2         4
31 #
32 #       3
33 #
34 #  1         5
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
36 SketchPoint_1 = Sketch_1.addPoint(0, 0)
37 SketchPoint_2 = Sketch_1.addPoint(0, 50)
38 SketchPoint_3 = Sketch_1.addPoint(25, 25)
39 SketchPoint_4 = Sketch_1.addPoint(50, 50)
40 SketchPoint_5 = Sketch_1.addPoint(50, 0)
41 model.do()
42
43 # Get sketch points
44 base_name = "Sketch_1/SketchPoint_"
45 p_1, p_2, p_3, p_4, p_5 = [model.selection("VERTEX", base_name + str(i + 1)) for i in range(0, 5)]
46
47 # =============================================================================
48 # Test 1. Create unclosed polyline 1-2-3-4-5
49 # =============================================================================
50 Polyline_1 = model.addPolyline3D(Part_1_doc, [p_1, p_2, p_3, p_4, p_5], False)
51 model.do()
52
53 model.checkResult(Polyline_1, model, 1, [0], [0], [0], [4], [4*2])
54
55 # =============================================================================
56 # Test 2. Create closed polyline 1-2-3-4-5-1
57 # =============================================================================
58 Polyline_2 = model.addPolyline3D(Part_1_doc, [p_1, p_2, p_3, p_4, p_5], True)
59 model.do()
60
61 model.checkResult(Polyline_2, model, 1, [0], [0], [0], [5], [5*2])
62
63 # =============================================================================
64 # Test 3. Try to create self-intersected unclosed polyline 2-5-4-1
65 # =============================================================================
66 Polyline_3 = model.addPolyline3D(Part_1_doc, [p_2, p_5, p_4, p_1], False)
67 model.do()
68
69 model.testNbResults(Polyline_3, 0)
70
71 # =============================================================================
72 # Test 4. Try to create self-intersected closed polyline 2-4-1-5-2
73 # =============================================================================
74 Polyline_4 = model.addPolyline3D(Part_1_doc, [p_2, p_4, p_1, p_5], True)
75 model.do()
76
77 model.testNbResults(Polyline_4, 0)
78
79 # =============================================================================
80 # Test 5. Try to create closed polyline 1-2-1
81 # =============================================================================
82 Polyline_5 = model.addPolyline3D(Part_1_doc, [p_1, p_2], True)
83 model.do()
84
85 model.testNbResults(Polyline_5, 0)
86
87 # =============================================================================
88 # Test 6. Try to create unclosed polyline on a single point 3
89 # =============================================================================
90 Polyline_6 = model.addPolyline3D(Part_1_doc, [p_3], False)
91 model.do()
92
93 model.testNbResults(Polyline_6, 0)
94
95 # =============================================================================
96 # Test 7. Create unclosed polyline on box vertices
97 # =============================================================================
98 Part_2 = model.addPart(partSet)
99 Part_2_doc = Part_2.document()
100 Box_1 = model.addBox(Part_2_doc, 10, 10, 10)
101
102 point_names = ("[Box_1_1/Back][Box_1_1/Left][Box_1_1/Bottom]",
103                "[Box_1_1/Back][Box_1_1/Left][Box_1_1/Top]",
104                "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Top]",
105                "[Box_1_1/Front][Box_1_1/Left][Box_1_1/Bottom]",
106                "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Bottom]",
107                "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Top]",
108                "[Box_1_1/Back][Box_1_1/Right][Box_1_1/Top]",
109                "[Box_1_1/Back][Box_1_1/Right][Box_1_1/Bottom]")
110 points = [model.selection("VERTEX", name) for name in point_names]
111
112 Polyline_7 = model.addPolyline3D(Part_2_doc, points, False)
113 model.do()
114
115 model.checkResult(Polyline_7, model, 1, [0], [0], [0], [7], [7*2])
116
117 # =============================================================================
118 # Test 8. Create closed polyline on box vertices
119 # =============================================================================
120 Part_3 = model.addPart(partSet)
121 Part_3_doc = Part_3.document()
122 Box_1 = model.addBox(Part_3_doc, 10, 10, 10)
123
124 points = [model.selection("VERTEX", name) for name in point_names]
125
126 Polyline_8 = model.addPolyline3D(Part_3_doc, points, True)
127 model.do()
128
129 model.checkResult(Polyline_8, model, 1, [0], [0], [0], [8], [8*2])
130
131 # =============================================================================
132 # Test 9. Create polyline using equal vertices
133 # =============================================================================
134 Part_4 = model.addPart(partSet)
135 Part_4_doc = Part_4.document()
136
137 Point_1 = model.addPoint(Part_4_doc, 0, 0, 0)
138 Point_2 = model.addPoint(Part_4_doc, 0, 0, 0)
139 P_1 = model.selection("VERTEX", "Point_1")
140 P_2 = model.selection("VERTEX", "Point_2")
141
142 Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
143 model.do()
144
145 model.testNbResults(Polyline_9, 0)
146
147 # =============================================================================
148 # Test 10. Check subshapes naming
149 # =============================================================================
150 model.testHaveNamingSubshapes(Polyline_1, model, Part_1_doc)
151 model.end()
152
153 # =============================================================================
154 # Test 11. Check Python dump
155 # =============================================================================
156 assert(model.checkPythonDump())