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