Salome HOME
Updated copyright comment
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces09.py
1 # Copyright (C) 2014-2024  CEA, EDF
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
22 from salome.shaper import model
23
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 ParamR = model.addParameter(Part_1_doc, "R", "50")
29 ParamSize = model.addParameter(Part_1_doc, "Size", "50")
30 ParamFrom = model.addParameter(Part_1_doc, "offsetFrom", "0")
31 ParamTo = model.addParameter(Part_1_doc, "offsetTo", "0")
32 Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), "R")
33 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Sphere_1_1"), model.selection("FACE", "PartSet/XOZ")])
34 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOZ"), 10, False)
35 Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1"))
36 SketchLine_1 = Sketch_1.addLine(50, -50, -50, -50)
37 SketchLine_2 = Sketch_1.addLine(-50, -50, -50, 50)
38 SketchLine_3 = Sketch_1.addLine(-50, 50, 50, 50)
39 SketchLine_4 = Sketch_1.addLine(50, 50, 50, -50)
40 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
41 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
42 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
43 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
44 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
45 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
46 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
47 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
48 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
49 SketchPoint_1 = SketchProjection_1.createdFeature()
50 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_4.result(), "Size", True)
51 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_2.result(), "Size", True)
52 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.result(), "Size", True)
53 SketchConstraintDistance_4 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_3.result(), "Size", True)
54 model.do()
55 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")])
56 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
57 SketchLine_5 = Sketch_2.addLine(20, -15, 20, 20)
58 SketchLine_6 = Sketch_2.addLine(20, 20, -15, 20)
59 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
60 SketchConstraintVertical_3 = Sketch_2.setVertical(SketchLine_5.result())
61 SketchConstraintHorizontal_3 = Sketch_2.setHorizontal(SketchLine_6.result())
62 SketchArc_1 = Sketch_2.addArc(0, 0, -15, 20, 20, -15, False)
63 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchArc_1.startPoint())
64 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchArc_1.endPoint(), SketchLine_5.startPoint())
65 SketchConstraintEqual_1 = Sketch_2.setEqual(SketchLine_5.result(), SketchLine_6.result())
66 SketchConstraintDistance_5 = Sketch_2.setDistance(SketchArc_1.center(), SketchLine_5.result(), 20, True)
67 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
68 SketchPoint_2 = SketchProjection_2.createdFeature()
69 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchArc_1.center())
70 SketchConstraintRadius_1 = Sketch_2.setRadius(SketchArc_1.results()[1], 25)
71 SketchLine_7 = Sketch_2.addLine(-15, 20, 20, -15)
72 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
73 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_7.endPoint())
74 model.do()
75 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchArc_1_2f-SketchLine_7r"), model.selection("FACE", "Sketch_2/Face-SketchLine_5r-SketchLine_6f-SketchLine_7f")], model.selection(), model.selection("FACE", "Partition_1_1_2/Modified_Face&Sphere_1_1/Face_1"), "offsetTo", model.selection("FACE", "Face_1_1"), "offsetFrom")
76
77 from GeomAPI import GeomAPI_Shape
78
79 model.testNbResults(Extrusion_1, 1)
80 model.testNbSubResults(Extrusion_1, [2])
81 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
82 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
83 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [30])
84 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [60])
85 model.testResultsVolumes(Extrusion_1, [100878.6])
86
87 # change radius of sphere and check failure
88 ParamR.setValue(10)
89 model.do()
90 assert(Extrusion_1.feature().error() != "")
91
92 # revert failure, check the intersected boundaries are processed well
93 ParamR.setValue(30)
94 model.do()
95 model.testNbResults(Extrusion_1, 1)
96 model.testNbSubResults(Extrusion_1, [2])
97 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
98 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
99 model.testResultsVolumes(Extrusion_1, [60964.23998])
100
101 ParamR.setValue(40);
102 model.do()
103 model.testNbResults(Extrusion_1, 1)
104 model.testNbSubResults(Extrusion_1, [2])
105 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
106 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
107 model.testResultsVolumes(Extrusion_1, [81651.666])
108
109 # change size of the face
110 ParamSize.setValue(10)
111 model.do()
112 model.testNbResults(Extrusion_1, 1)
113 model.testNbSubResults(Extrusion_1, [2])
114 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
115 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
116 model.testResultsVolumes(Extrusion_1, [81651.666])
117
118 # change offsetting "To" face and check failure
119 ParamTo.setValue(-20)
120 model.do()
121 assert(Extrusion_1.feature().error() != "")
122
123 # revert failure
124 ParamTo.setValue(20)
125 model.do()
126 model.testNbResults(Extrusion_1, 1)
127 model.testNbSubResults(Extrusion_1, [2])
128 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
129 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
130 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [30])
131 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [60])
132 model.testResultsVolumes(Extrusion_1, [119535.04])
133
134 # offset "From" face
135 ParamFrom.setValue(20)
136 model.do()
137 model.testNbResults(Extrusion_1, 1)
138 model.testNbSubResults(Extrusion_1, [2])
139 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
140 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
141 model.testResultsVolumes(Extrusion_1, [84126.377])
142
143 ParamFrom.setValue(-20)
144 model.do()
145 model.testNbResults(Extrusion_1, 1)
146 model.testNbSubResults(Extrusion_1, [2])
147 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
148 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
149 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [30])
150 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [60])
151 model.testResultsVolumes(Extrusion_1, [154943.7])
152
153 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
154
155 model.end()
156
157 assert(model.checkPythonDump())