Salome HOME
87925f5061fa27ed101254ff8f26a39b0ab2a15e
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces05.py
1 # Copyright (C) 2014-2023  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 ParamRSph = model.addParameter(Part_1_doc, "rSphere", "50")
29 ParamRCyl = model.addParameter(Part_1_doc, "rCyl", "30")
30 ParamRCir = model.addParameter(Part_1_doc, "rCircle", "10")
31 ParamFrom = model.addParameter(Part_1_doc, "offsetFrom", "0")
32 ParamTo = model.addParameter(Part_1_doc, "offsetTo", "0")
33 Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), "rSphere")
34 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), "rCyl", 100)
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
36 SketchCircle_1 = Sketch_1.addCircle(15, 20, 10)
37 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "rCircle")
38 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
39 SketchPoint_1 = SketchProjection_1.createdFeature()
40 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchCircle_1.center(), 15)
41 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchCircle_1.center(), 20)
42 model.do()
43 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), model.selection("FACE", "Sphere_1_1/Face_1"), "offsetTo", model.selection("FACE", "Cylinder_1_1/Face_1"), "offsetFrom")
44
45 from GeomAPI import GeomAPI_Shape
46
47 model.testNbResults(Extrusion_1, 1)
48 model.testNbSubResults(Extrusion_1, [2])
49 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
50 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
51 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
52 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
53 model.testResultsVolumes(Extrusion_1, [10878.5462])
54
55 # change radius of sketch circle
56 ParamRCir.setValue(17)
57 model.do()
58 model.testNbResults(Extrusion_1, 1)
59 model.testNbSubResults(Extrusion_1, [0])
60 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [5])
62 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [18])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [36])
64 model.testResultsVolumes(Extrusion_1, [32102.718377])
65
66 # change radius of sphere and check failure
67 ParamRSph.setValue(10)
68 model.do()
69 model.testNbResults(Extrusion_1, 1)
70 model.testNbSubResults(Extrusion_1, [0])
71 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
72 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
73 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [18])
74 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [36])
75 model.testResultsVolumes(Extrusion_1, [42694.3277614])
76
77 # change radius of sketch circle and check failure
78 ParamRCir.setValue(10)
79 model.do()
80 assert(Extrusion_1.feature().error() != "")
81
82 # revert failure
83 ParamRSph.setValue(45);
84 model.do()
85 model.testNbResults(Extrusion_1, 1)
86 model.testNbSubResults(Extrusion_1, [2])
87 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
88 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
89 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
90 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
91 model.testResultsVolumes(Extrusion_1, [7083.567843])
92
93 # change radius of cylinder
94 ParamRCyl.setValue(10)
95 model.do()
96 model.testNbResults(Extrusion_1, 1)
97 model.testNbSubResults(Extrusion_1, [0])
98 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
99 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [5])
100 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
101 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
102 model.testResultsVolumes(Extrusion_1, [22295.845141])
103
104 ParamRCyl.setValue(50)
105 model.do()
106 model.testNbResults(Extrusion_1, 1)
107 model.testNbSubResults(Extrusion_1, [2])
108 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
109 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
110 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
111 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
112 model.testResultsVolumes(Extrusion_1, [6805.1007457])
113
114 # change offsetting "To" face
115 ParamTo.setValue(-20)
116 model.do()
117 model.testNbResults(Extrusion_1, 1)
118 model.testNbSubResults(Extrusion_1, [0])
119 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
120 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [5])
121 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [18])
122 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [36])
123 model.testResultsVolumes(Extrusion_1, [26158.63076])
124
125 # revert failure
126 ParamTo.setValue(20)
127 model.do()
128 model.testNbResults(Extrusion_1, 1)
129 model.testNbSubResults(Extrusion_1, [2])
130 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
131 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
132 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
133 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
134 model.testResultsVolumes(Extrusion_1, [7626.2279286])
135
136 # offset "From" face
137 ParamFrom.setValue(20)
138 model.do()
139 model.testNbResults(Extrusion_1, 1)
140 model.testNbSubResults(Extrusion_1, [2])
141 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
142 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
143 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
144 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
145 model.testResultsVolumes(Extrusion_1, [21514.8965])
146
147 ParamFrom.setValue(-20)
148 model.do()
149 model.testNbResults(Extrusion_1, 1)
150 model.testNbSubResults(Extrusion_1, [2])
151 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
152 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
153 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
154 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
155 model.testResultsVolumes(Extrusion_1, [5427.194275658])
156
157 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
158
159 model.end()
160
161 assert(model.checkPythonDump())