Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces01.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 ParamR = model.addParameter(Part_1_doc, "R", "50")
29 ParamFrom = model.addParameter(Part_1_doc, "offsetFrom", "0")
30 ParamTo = model.addParameter(Part_1_doc, "offsetTo", "0")
31 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), "R", 100, 180)
32 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
33 SketchLine_1 = Sketch_1.addLine(20, 40, -30, 40)
34 SketchLine_2 = Sketch_1.addLine(-30, 40, -30, 20)
35 SketchLine_3 = Sketch_1.addLine(-30, 20, 20, 20)
36 SketchLine_4 = Sketch_1.addLine(20, 20, 20, 40)
37 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
38 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
39 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
40 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
41 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
42 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
43 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
44 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
45 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_3.result(), 50)
46 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), 20)
47 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
48 SketchPoint_1 = SketchProjection_1.createdFeature()
49 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_3.endPoint(), 20)
50 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_3.endPoint(), 20)
51 model.do()
52 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), model.selection("FACE", "Cylinder_1_1/Face_1"), "offsetTo", model.selection(), "offsetFrom")
53
54 from GeomAPI import GeomAPI_Shape
55
56 model.testNbResults(Extrusion_1, 1)
57 model.testNbSubResults(Extrusion_1, [0])
58 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
59 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
60 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [24])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [48])
62 model.testResultsVolumes(Extrusion_1, [47540.6])
63
64 # change radius of cylinder
65 ParamR.setValue(10)
66 model.do()
67 model.testNbResults(Extrusion_1, 1)
68 model.testNbSubResults(Extrusion_1, [0])
69 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
70 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
71 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [12])
72 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [24])
73 model.testResultsVolumes(Extrusion_1, [3141.59265])
74
75 # check the intersected boundaries are processed well
76 ParamR.setValue(30)
77 model.do()
78 model.testNbResults(Extrusion_1, 1)
79 model.testNbSubResults(Extrusion_1, [0])
80 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
81 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [5])
82 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [18])
83 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [36])
84 model.testResultsVolumes(Extrusion_1, [25176.8518])
85
86 ParamR.setValue(40);
87 model.do()
88 model.testNbResults(Extrusion_1, 1)
89 model.testNbSubResults(Extrusion_1, [0])
90 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
91 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
92 model.testResultsVolumes(Extrusion_1, [36812.03])
93
94 # change offsetting "To" face
95 ParamTo.setValue(-20)
96 model.do()
97 model.testNbResults(Extrusion_1, 1)
98 model.testNbSubResults(Extrusion_1, [0])
99 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
100 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
101 model.testResultsVolumes(Extrusion_1, [12566.37])
102
103 ParamTo.setValue(20)
104 model.do()
105 model.testNbResults(Extrusion_1, 1)
106 model.testNbSubResults(Extrusion_1, [0])
107 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
108 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
109 model.testResultsVolumes(Extrusion_1, [57985.85])
110
111 # offset "From" face
112 ParamFrom.setValue(20)
113 model.do()
114 model.testNbResults(Extrusion_1, 1)
115 model.testNbSubResults(Extrusion_1, [0])
116 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
117 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
118 model.testResultsVolumes(Extrusion_1, [37985.85])
119
120 ParamFrom.setValue(-20)
121 model.do()
122 model.testNbResults(Extrusion_1, 1)
123 model.testNbSubResults(Extrusion_1, [0])
124 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
125 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [6])
126 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [24])
127 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [48])
128 model.testResultsVolumes(Extrusion_1, [77985.85])
129
130 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
131
132 model.end()
133
134 assert(model.checkPythonDump())