1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 from salome.shaper import model
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
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)
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)]
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)
54 model.checkBooleansResult(Polyline_1, model, 1, [0], [0], [0], [4], [4*2])
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)
62 model.checkBooleansResult(Polyline_2, model, 1, [0], [0], [0], [5], [5*2])
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)
70 model.testNbResults(Polyline_3, 0)
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)
78 model.testNbResults(Polyline_4, 0)
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)
86 model.testNbResults(Polyline_5, 0)
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)
94 model.testNbResults(Polyline_6, 0)
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)
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]
113 Polyline_7 = model.addPolyline3D(Part_2_doc, points, False)
116 model.checkBooleansResult(Polyline_7, model, 1, [0], [0], [0], [7], [7*2])
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)
125 points = [model.selection("VERTEX", name) for name in point_names]
127 Polyline_8 = model.addPolyline3D(Part_3_doc, points, True)
130 model.checkBooleansResult(Polyline_8, model, 1, [0], [0], [0], [8], [8*2])
132 # =============================================================================
133 # Test 9. Create polyline using equal vertices
134 # =============================================================================
135 Part_4 = model.addPart(partSet)
136 Part_4_doc = Part_4.document()
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")
143 Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
146 model.testNbResults(Polyline_9, 0)
148 # =============================================================================
149 # Test 10. Check subshapes naming
150 # =============================================================================
151 model.testHaveNamingSubshapes(Polyline_1, model, Part_1_doc)
154 # =============================================================================
155 # Test 11. Check Python dump
156 # =============================================================================
157 assert(model.checkPythonDump())