1 # Copyright (C) 2014-2020 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 email : webmaster.salome@opencascade.com
20 from salome.shaper import model
24 partSet = model.moduleDocument()
25 Part_1 = model.addPart(partSet)
26 Part_1_doc = Part_1.document()
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)
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)]
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)
53 model.checkResult(Polyline_1, model, 1, [0], [0], [0], [4], [4*2])
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)
61 model.checkResult(Polyline_2, model, 1, [0], [0], [0], [5], [5*2])
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)
69 model.testNbResults(Polyline_3, 0)
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)
77 model.testNbResults(Polyline_4, 0)
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)
85 model.testNbResults(Polyline_5, 0)
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)
93 model.testNbResults(Polyline_6, 0)
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)
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]
112 Polyline_7 = model.addPolyline3D(Part_2_doc, points, False)
115 model.checkResult(Polyline_7, model, 1, [0], [0], [0], [7], [7*2])
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)
124 points = [model.selection("VERTEX", name) for name in point_names]
126 Polyline_8 = model.addPolyline3D(Part_3_doc, points, True)
129 model.checkResult(Polyline_8, model, 1, [0], [0], [0], [8], [8*2])
131 # =============================================================================
132 # Test 9. Create polyline using equal vertices
133 # =============================================================================
134 Part_4 = model.addPart(partSet)
135 Part_4_doc = Part_4.document()
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")
142 Polyline_9 = model.addPolyline3D(Part_4_doc, [P_1, P_2], False)
145 model.testNbResults(Polyline_9, 0)
147 # =============================================================================
148 # Test 10. Check subshapes naming
149 # =============================================================================
150 model.testHaveNamingSubshapes(Polyline_1, model, Part_1_doc)
153 # =============================================================================
154 # Test 11. Check Python dump
155 # =============================================================================
156 assert(model.checkPythonDump())