Salome HOME
Merge branch 'V9_9_BR'
[modules/shaper.git] / src / SketchPlugin / Test / TestChangeSketchPlane2.py
1 # Copyright (C) 2019-2022  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 SketchAPI import *
21 from salome.shaper import model
22 import math
23
24 def checkMiddlePoint(feature, x, y, z, tolerance = 1.e-6):
25     shape = feature.results()[0].resultSubShapePair()[0].shape()
26     assert(shape is not None)
27     middlePoint = shape.middlePoint()
28     assert(math.fabs(middlePoint.x() - x) < tolerance), "X: {} != {}".format(middlePoint.x(), x)
29     assert(math.fabs(middlePoint.y() - y) < tolerance), "Y: {} != {}".format(middlePoint.y(), y)
30     assert(math.fabs(middlePoint.z() - z) < tolerance), "Z: {} != {}".format(middlePoint.z(), z)
31
32 model.begin()
33 partSet = model.moduleDocument()
34 Part_1 = model.addPart(partSet)
35 Part_1_doc = Part_1.document()
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37 SketchLine_1 = Sketch_1.addLine(0, 0, 20, 0)
38 SketchLine_2 = Sketch_1.addLine(20, 0, 30, 20)
39 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
40 SketchLine_3 = Sketch_1.addLine(30, 20, 50, 20)
41 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
42 SketchLine_4 = Sketch_1.addLine(50, 20, 50, 40)
43 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
44 SketchLine_5 = Sketch_1.addLine(50, 40, 0, 40)
45 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
46 SketchLine_6 = Sketch_1.addLine(0, 40, 0, 0)
47 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
48 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_6.endPoint())
49 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
50 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
51 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_5.result())
52 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_6.result())
53 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
54 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_5.result(), 50)
55 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_6.result(), 40)
56 SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_4.result(), 20)
57 SketchConstraintLength_4 = Sketch_1.setLength(SketchLine_3.result(), 20)
58 SketchConstraintLength_5 = Sketch_1.setLength(SketchLine_1.result(), 20)
59 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
60 SketchPoint_1 = SketchProjection_1.createdFeature()
61 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchAPI_Point(SketchPoint_1).coordinates())
62 model.do()
63 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f")], model.selection(), 30, 0)
64 ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [], model.selection(), 10, 0, [model.selection("SOLID", "Extrusion_1_1")])
65 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3"))
66 SketchCircle_1 = Sketch_2.addCircle(33, 25, 5)
67 SketchConstraintRadius_1 = Sketch_2.setRadius(SketchCircle_1.results()[1], 5)
68 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3]"), False)
69 SketchLine_7 = SketchProjection_2.createdFeature()
70 SketchConstraintDistance_1 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_7.result(), 3, True)
71 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_3][Extrusion_1_1/To_Face]"), False)
72 SketchLine_8 = SketchProjection_3.createdFeature()
73 SketchConstraintDistance_2 = Sketch_2.setDistance(SketchCircle_1.center(), SketchLine_8.result(), 5, True)
74 ExtrusionFuse_1.setNestedSketch(Sketch_2)
75 Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionFuse_1_1/Modified_Face&Extrusion_1_1/To_Face"))
76 SketchIntersectionPoint_1 = Sketch_3.addIntersectionPoint(model.selection("EDGE", "[ExtrusionFuse_1_1/Generated_Face&Sketch_2/SketchCircle_1_2][ExtrusionFuse_1_1/To_Face]"), False)
77 [SketchPoint_2] = SketchIntersectionPoint_1.intersectionPoints()
78 SketchLine_9 = Sketch_3.addLine(33.5, 10, 32.5, 10)
79 SketchLine_10 = Sketch_3.addLine(32.5, 10, 32.5, 17)
80 SketchLine_11 = Sketch_3.addLine(32.5, 17, 33.5, 17)
81 SketchLine_12 = Sketch_3.addLine(33.5, 17, 33.5, 10)
82 SketchConstraintCoincidence_8 = Sketch_3.setCoincident(SketchLine_12.endPoint(), SketchLine_9.startPoint())
83 SketchConstraintCoincidence_9 = Sketch_3.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint())
84 SketchConstraintCoincidence_10 = Sketch_3.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
85 SketchConstraintCoincidence_11 = Sketch_3.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint())
86 SketchConstraintHorizontal_4 = Sketch_3.setHorizontal(SketchLine_9.result())
87 SketchConstraintVertical_3 = Sketch_3.setVertical(SketchLine_10.result())
88 SketchConstraintHorizontal_5 = Sketch_3.setHorizontal(SketchLine_11.result())
89 SketchConstraintVertical_4 = Sketch_3.setVertical(SketchLine_12.result())
90 SketchConstraintMiddle_1 = Sketch_3.setMiddlePoint(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_9.result())
91 SketchConstraintLength_6 = Sketch_3.setLength(SketchLine_9.result(), 1)
92 SketchConstraintLength_7 = Sketch_3.setLength(SketchLine_12.result(), 7)
93 model.do()
94 ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_3/Face-SketchLine_12r-SketchLine_11r-SketchLine_10r-SketchLine_9r")], model.selection(), 0, 1, [model.selection("SOLID", "ExtrusionFuse_1_1")])
95 model.end()
96
97 SKETCH_DOF = 0
98 model.checkSketch(Sketch_1, SKETCH_DOF)
99 model.checkSketch(Sketch_2, SKETCH_DOF)
100 model.checkSketch(Sketch_3, SKETCH_DOF)
101
102 from GeomAPI import GeomAPI_Shape
103
104 model.testNbResults(ExtrusionCut_1, 1)
105 model.testNbSubResults(ExtrusionCut_1, [0])
106 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
107 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [15])
108 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [78])
109 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [156])
110 model.testResultsVolumes(ExtrusionCut_1, [45760.2175339])
111
112 checkMiddlePoint(ExtrusionCut_1, 21.09174756, 23.41211647, 15.165448698)
113
114 # change plane of Fuse's sketch
115 model.begin()
116 Sketch_2.setPlane(model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"))
117 model.end()
118
119 model.checkSketch(Sketch_1, SKETCH_DOF)
120 model.checkSketch(Sketch_2, SKETCH_DOF)
121 model.checkSketch(Sketch_3, SKETCH_DOF)
122
123 model.testNbResults(ExtrusionCut_1, 1)
124 model.testNbSubResults(ExtrusionCut_1, [0])
125 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
126 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [14])
127 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [68])
128 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [136])
129 model.testResultsVolumes(ExtrusionCut_1, [45778.45658456])
130
131 checkMiddlePoint(ExtrusionCut_1, 21.0948367, 23.919988, 15.169366862)
132
133 # undo the change
134 model.undo()
135 # and set another
136 model.begin()
137 Sketch_2.setPlane(model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2"))
138 model.end()
139
140 model.checkSketch(Sketch_1, SKETCH_DOF)
141 model.checkSketch(Sketch_2, SKETCH_DOF)
142 model.checkSketch(Sketch_3, SKETCH_DOF)
143
144 model.testNbResults(ExtrusionCut_1, 1)
145 model.testNbSubResults(ExtrusionCut_1, [0])
146 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
147 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [18])
148 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [97])
149 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [194])
150 model.testResultsVolumes(ExtrusionCut_1, [45338.366732291])
151
152 checkMiddlePoint(ExtrusionCut_1, 21.00046446, 23.51391548, 15.073978)
153
154 # undo the change again
155 model.undo()
156 # and set another which fails the projection
157 model.begin()
158 Sketch_2.setPlane(model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_6"))
159 model.end()
160 assert(SketchProjection_3.feature().error() != "")
161 # undo the error
162 model.undo()
163
164 model.begin()
165 Sketch_3.setPlane(model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_4"), True)
166 model.end()
167
168 model.checkSketch(Sketch_1, SKETCH_DOF)
169 model.checkSketch(Sketch_2, SKETCH_DOF)
170 model.checkSketch(Sketch_3, 2)
171
172 model.testNbResults(ExtrusionCut_1, 1)
173 model.testNbSubResults(ExtrusionCut_1, [0])
174 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
175 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [16])
176 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [76])
177 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [152])
178 model.testResultsVolumes(ExtrusionCut_1, [45760.15911273])
179
180 checkMiddlePoint(ExtrusionCut_1, 21.08920837, 23.40914618, 15.16787737)
181
182 assert(model.checkPythonDump())