Salome HOME
Merge branch 'Results_Hierarchy'
[modules/shaper.git] / src / BuildPlugin / Test / TestInterpolation.py
1 ## Copyright (C) 2014-2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 from salome.shaper import model
22
23 # Create document
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28
29 # Create sketch
30 #
31 #  2         4
32 #
33 #       3
34 #
35 #  1         5
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37 SketchPoint_1 = Sketch_1.addPoint(0, 0)
38 SketchPoint_2 = Sketch_1.addPoint(0, 50)
39 SketchPoint_3 = Sketch_1.addPoint(25, 25)
40 SketchPoint_4 = Sketch_1.addPoint(50, 50)
41 SketchPoint_5 = Sketch_1.addPoint(50, 0)
42
43 SketchLine_1 = Sketch_1.addLine(0, 0, -45, -45)
44 SketchLine_2 = Sketch_1.addLine(0, 0, 45, 45)
45 model.do()
46
47 # Get sketch points
48 base_name = "Sketch_1/Vertex-SketchPoint_"
49 p_1, p_2, p_3, p_4, p_5 = [model.selection("VERTEX", base_name + str(i + 1)) for i in range(0, 5)]
50
51 # Get sketch edges
52 Tangent_1 = model.selection("EDGE", "Sketch_1/Edge-SketchLine_1")
53 Tangent_2 = model.selection("EDGE", "Sketch_1/Edge-SketchLine_2")
54
55 # =============================================================================
56 # Test 1. Create curve 1-2-3-4-5, closed off, reorder off, without tangents
57 # =============================================================================
58 Interpolation_1 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4, p_5], False, False)
59 model.do()
60
61 model.checkResult(Interpolation_1, model, 1, [0], [0], [0], [1], [2])
62
63 # =============================================================================
64 # Test 2. Create curve 1-2-3-4-5-1, closed on, reorder off, without tangents
65 # =============================================================================
66 Interpolation_2 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4, p_5], True, False)
67 model.do()
68
69 model.checkResult(Interpolation_2, model, 1, [0], [0], [0], [1], [2])
70
71 # =============================================================================
72 # Test 3. Create curve 1-2-3-4, closed off, reorder on, without tangents
73 # =============================================================================
74 Interpolation_3 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4], False, True)
75 model.do()
76
77 model.checkResult(Interpolation_3, model, 1, [0], [0], [0], [1], [2])
78
79 # =============================================================================
80 # Test 4. Create curve 1-2-3-5, closed on, reorder on, without tangents
81 # =============================================================================
82 Interpolation_4 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_5], True, True)
83 model.do()
84
85 model.checkResult(Interpolation_4, model, 1, [0], [0], [0], [1], [2])
86
87 # =============================================================================
88 # Test 5. Create curve 1-2-3-4-5, closed off, reorder off, with tangents
89 # =============================================================================
90
91 Interpolation_5 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_3, p_4, p_5],
92                                          Tangent_1, Tangent_2, False, False)
93 model.do()
94
95 model.checkResult(Interpolation_5, model, 1, [0], [0], [0], [1], [2])
96
97 # =============================================================================
98 # Test 6. Try to create closed curve 1-2-1, closed off, reorder off, without tangents
99 # =============================================================================
100 Interpolation_6 = model.addInterpolation(Part_1_doc, [p_1, p_2, p_1], False, False)
101 model.do()
102
103 model.testNbResults(Interpolation_6, 0)
104
105 # =============================================================================
106 # Test 7. Try to create curve on a single point 3
107 # =============================================================================
108 Interpolation_7 = model.addInterpolation(Part_1_doc, [p_3], False, False)
109 model.do()
110
111 model.testNbResults(Interpolation_7, 0)
112
113 # =============================================================================
114 # Test 8. Create curve on box vertices, closed off, reorder off, without tangents
115 # =============================================================================
116 Part_2 = model.addPart(partSet)
117 Part_2_doc = Part_2.document()
118 Box_1 = model.addBox(Part_2_doc, 10, 10, 10)
119
120 point_names = ("Box_1_1/Back&Box_1_1/Left&Box_1_1/Bottom",
121                "Box_1_1/Back&Box_1_1/Left&Box_1_1/Top",
122                "Box_1_1/Front&Box_1_1/Left&Box_1_1/Top",
123                "Box_1_1/Front&Box_1_1/Left&Box_1_1/Bottom",
124                "Box_1_1/Front&Box_1_1/Right&Box_1_1/Bottom",
125                "Box_1_1/Front&Box_1_1/Right&Box_1_1/Top",
126                "Box_1_1/Back&Box_1_1/Right&Box_1_1/Top",
127                "Box_1_1/Back&Box_1_1/Right&Box_1_1/Bottom")
128 points = [model.selection("VERTEX", name) for name in point_names]
129
130 Interpolation_8 = model.addInterpolation(Part_2_doc, points, False, False)
131 model.do()
132
133 model.checkResult(Interpolation_8, model, 1, [0], [0], [0], [1], [2])
134
135 # =============================================================================
136 # Test 9. Create curve on box vertices, closed off, reorder off, with tangents
137 # =============================================================================
138 Part_3 = model.addPart(partSet)
139 Part_3_doc = Part_3.document()
140 Box_1 = model.addBox(Part_3_doc, 20, 30, 40)
141
142 points = [model.selection("VERTEX", name) for name in point_names]
143 Tangent_1 = model.selection("EDGE", "Box_1_1/Back&Box_1_1/Top")
144 Tangent_2 = model.selection("EDGE", "Box_1_1/Left&Box_1_1/Top")
145
146 Interpolation_9 = model.addInterpolation(Part_3_doc, points,
147                                          Tangent_1, Tangent_2, False, False)
148 model.do()
149
150 model.checkResult(Interpolation_9, model, 1, [0], [0], [0], [1], [2])
151
152 # =============================================================================
153 # Test 10. Create curve using equal vertices
154 # =============================================================================
155 Part_4 = model.addPart(partSet)
156 Part_4_doc = Part_4.document()
157
158 Point_1 = model.addPoint(Part_4_doc, 0, 0, 0)
159 Point_2 = model.addPoint(Part_4_doc, 0, 0, 0)
160 P_1 = model.selection("VERTEX", "Point_1")
161 P_2 = model.selection("VERTEX", "Point_2")
162
163 Interpolation_10 = model.addInterpolation(Part_4_doc, [P_1, P_2],
164                                           False, False)
165 model.do()
166 model.testNbResults(Interpolation_10, 0)
167
168 # =============================================================================
169 # Test 11. Check subshapes naming
170 # =============================================================================
171 model.testHaveNamingSubshapes(Interpolation_5, model, Part_1_doc)
172 model.testHaveNamingSubshapes(Interpolation_9, model, Part_3_doc)
173 model.end()
174
175 # =============================================================================
176 # Test 12. Check Python dump
177 # =============================================================================
178 assert(model.checkPythonDump())