Salome HOME
Copyright update 2020
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces17.py
1 # Copyright (C) 2014-2020  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 model.do()
43 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "Sketch_1/SketchCircle_1_2")])
44 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("EDGE", "Edge_1_1")], model.selection("EDGE", "PartSet/OY"), model.selection("FACE", "Sphere_1_1/Face_1"), "offsetTo", model.selection("FACE", "Cylinder_1_1/Face_1"), "offsetFrom")
45
46 from GeomAPI import GeomAPI_Shape
47
48 model.testNbResults(Extrusion_1, 1)
49 model.testNbSubResults(Extrusion_1, [2])
50 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
51 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
52 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [8])
53 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [16])
54 model.testResultsVolumes(Extrusion_1, [2178.8497332])
55
56 # change radius of sketch circle
57 ParamRCir.setValue(17)
58 model.do()
59 model.testNbResults(Extrusion_1, 1)
60 model.testNbSubResults(Extrusion_1, [0])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
62 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [10])
64 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [20])
65 model.testResultsVolumes(Extrusion_1, [3960.00723])
66
67 # change radius of sphere
68 ParamRSph.setValue(10)
69 model.do()
70 model.testNbResults(Extrusion_1, 1)
71 model.testNbSubResults(Extrusion_1, [0])
72 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
73 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1])
74 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [5])
75 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [10])
76 model.testResultsVolumes(Extrusion_1, [3658.7714])
77
78 # change radius of sketch circle and check failure
79 ParamRCir.setValue(10)
80 model.do()
81 assert(Extrusion_1.feature().error() != "")
82
83 # revert failure
84 ParamRSph.setValue(45);
85 model.do()
86 model.testNbResults(Extrusion_1, 1)
87 model.testNbSubResults(Extrusion_1, [2])
88 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
89 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
90 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [8])
91 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [16])
92 model.testResultsVolumes(Extrusion_1, [1398.72992867])
93
94 # change radius of cylinder
95 ParamRCyl.setValue(10)
96 model.do()
97 model.testNbResults(Extrusion_1, 1)
98 model.testNbSubResults(Extrusion_1, [0])
99 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
100 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1])
101 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [6])
102 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [12])
103 model.testResultsVolumes(Extrusion_1, [4194.25709])
104
105 ParamRCyl.setValue(50)
106 model.do()
107 model.testNbResults(Extrusion_1, 1)
108 model.testNbSubResults(Extrusion_1, [2])
109 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
110 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
111 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [8])
112 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [16])
113 model.testResultsVolumes(Extrusion_1, [1433.0518])
114
115 # change offsetting "To" face
116 ParamTo.setValue(-20)
117 model.do()
118 model.testNbResults(Extrusion_1, 1)
119 model.testNbSubResults(Extrusion_1, [0])
120 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
121 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1])
122 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [10])
123 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [20])
124 model.testResultsVolumes(Extrusion_1, [5078.347278])
125
126 # revert failure
127 ParamTo.setValue(20)
128 model.do()
129 model.testNbResults(Extrusion_1, 1)
130 model.testNbSubResults(Extrusion_1, [2])
131 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
132 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
133 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [8])
134 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [16])
135 model.testResultsVolumes(Extrusion_1, [1504.36096473])
136
137 # offset "From" face
138 ParamFrom.setValue(20)
139 model.do()
140 model.testNbResults(Extrusion_1, 1)
141 model.testNbSubResults(Extrusion_1, [2])
142 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
143 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
144 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [8])
145 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [16])
146 model.testResultsVolumes(Extrusion_1, [4336.142699])
147
148 ParamFrom.setValue(-20)
149 model.do()
150 model.testNbResults(Extrusion_1, 1)
151 model.testNbSubResults(Extrusion_1, [2])
152 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
153 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
154 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [8])
155 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [16])
156 model.testResultsVolumes(Extrusion_1, [1118.8887326])
157
158 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
159
160 model.end()
161
162 assert(model.checkPythonDump())