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