Salome HOME
67579a66bbab7b2c9058006d817c8dbbcccba093
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces11.py
1 # Copyright (C) 2014-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
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 SketchLine_1 = Sketch_1.addLine(6.339745962155468, 15, 23.66025403784453, 15)
43 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchCircle_1.results()[1])
44 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchCircle_1.results()[1])
45 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
46 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), "rCircle/2", True)
47 model.do()
48 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r-SketchCircle_1_2r-SketchLine_1r"), model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r-SketchLine_1f")], model.selection(), model.selection("FACE", "Sphere_1_1/Face_1"), "offsetTo", model.selection("FACE", "Cylinder_1_1/Face_1"), "offsetFrom")
49
50 from GeomAPI import GeomAPI_Shape
51
52 model.testNbResults(Extrusion_1, 1)
53 model.testNbSubResults(Extrusion_1, [2])
54 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [4])
55 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [18])
56 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
57 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
58 model.testResultsVolumes(Extrusion_1, [10878.5462])
59
60 # change radius of sketch circle
61 ParamRCir.setValue(17)
62 model.do()
63 model.testNbResults(Extrusion_1, 1)
64 model.testNbSubResults(Extrusion_1, [3])
65 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [3])
66 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [17])
67 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [66])
68 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [132])
69 model.testResultsVolumes(Extrusion_1, [32102.71838])
70
71 # change radius of sphere and check failure
72 ParamRSph.setValue(15)
73 model.do()
74 model.testNbResults(Extrusion_1, 1)
75 model.testNbSubResults(Extrusion_1, [2])
76 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
77 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [13])
78 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [61])
79 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [122])
80 model.testResultsVolumes(Extrusion_1, [41289.10946])
81
82 # change radius of sketch circle and check failure
83 ParamRCir.setValue(10)
84 model.do()
85 assert(Extrusion_1.feature().error() != "")
86
87 # revert failure
88 ParamRSph.setValue(45);
89 model.do()
90 model.testNbResults(Extrusion_1, 1)
91 model.testNbSubResults(Extrusion_1, [2])
92 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [4])
93 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [18])
94 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
95 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
96 model.testResultsVolumes(Extrusion_1, [7083.567842])
97
98 # change radius of cylinder
99 ParamRCyl.setValue(10)
100 model.do()
101 model.testNbResults(Extrusion_1, 1)
102 model.testNbSubResults(Extrusion_1, [2])
103 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
104 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [13])
105 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [54])
106 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [108])
107 model.testResultsVolumes(Extrusion_1, [22295.845141])
108
109 ParamRCyl.setValue(50)
110 model.do()
111 model.testNbResults(Extrusion_1, 1)
112 model.testNbSubResults(Extrusion_1, [2])
113 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [4])
114 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [18])
115 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
116 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
117 model.testResultsVolumes(Extrusion_1, [6805.1007457])
118
119 # change offsetting "To" face
120 ParamTo.setValue(-20)
121 model.do()
122 model.testNbResults(Extrusion_1, 1)
123 model.testNbSubResults(Extrusion_1, [2])
124 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
125 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [14])
126 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
127 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
128 model.testResultsVolumes(Extrusion_1, [26158.63076])
129
130 # revert failure
131 ParamTo.setValue(20)
132 model.do()
133 model.testNbResults(Extrusion_1, 1)
134 model.testNbSubResults(Extrusion_1, [2])
135 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [4])
136 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [18])
137 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
138 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
139 model.testResultsVolumes(Extrusion_1, [7626.2279286])
140
141 # offset "From" face
142 ParamFrom.setValue(20)
143 model.do()
144 model.testNbResults(Extrusion_1, 1)
145 model.testNbSubResults(Extrusion_1, [2])
146 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [4])
147 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [18])
148 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
149 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
150 model.testResultsVolumes(Extrusion_1, [21514.8965])
151
152 ParamFrom.setValue(-20)
153 model.do()
154 model.testNbResults(Extrusion_1, 1)
155 model.testNbSubResults(Extrusion_1, [2])
156 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [4])
157 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [18])
158 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [60])
159 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [120])
160 model.testResultsVolumes(Extrusion_1, [5427.194275658])
161
162 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
163
164 model.end()
165
166 assert(model.checkPythonDump())