Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces07.py
1 # Copyright (C) 2014-2023  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 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 SketchLine_5 = Sketch_1.addLine(-10, 20, 5, 40)
52 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_5.startPoint(), SketchLine_3.result())
53 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_1.result())
54 SketchConstraintDistanceHorizontal_2 = Sketch_1.setHorizontalDistance(SketchLine_2.endPoint(), SketchLine_5.startPoint(), 20)
55 SketchConstraintDistanceHorizontal_3 = Sketch_1.setHorizontalDistance(SketchLine_5.endPoint(), SketchLine_1.startPoint(), 15)
56 model.do()
57 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")
58
59 from GeomAPI import GeomAPI_Shape
60
61 model.testNbResults(Extrusion_1, 1)
62 model.testNbSubResults(Extrusion_1, [2])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
64 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
65 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [48])
66 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [96])
67 model.testResultsVolumes(Extrusion_1, [47540.6])
68
69 # change radius of cylinder
70 ParamR.setValue(10)
71 model.do()
72 model.testNbResults(Extrusion_1, 1)
73 model.testNbSubResults(Extrusion_1, [2])
74 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
75 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [9])
76 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [28])
77 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [56])
78 model.testResultsVolumes(Extrusion_1, [3141.59265])
79
80 # check the intersected boundaries are processed well
81 ParamR.setValue(30)
82 model.do()
83 model.testNbResults(Extrusion_1, 1)
84 model.testNbSubResults(Extrusion_1, [2])
85 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
86 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [11])
87 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [42])
88 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [84])
89 model.testResultsVolumes(Extrusion_1, [25176.8518])
90
91 ParamR.setValue(40);
92 model.do()
93 model.testNbResults(Extrusion_1, 1)
94 model.testNbSubResults(Extrusion_1, [2])
95 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
96 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
97 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [48])
98 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [96])
99 model.testResultsVolumes(Extrusion_1, [36812.03])
100
101 # change offsetting "To" face
102 ParamTo.setValue(-20)
103 model.do()
104 model.testNbResults(Extrusion_1, 1)
105 model.testNbSubResults(Extrusion_1, [2])
106 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
107 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [10])
108 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [36])
109 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [72])
110 model.testResultsVolumes(Extrusion_1, [12566.37])
111
112 ParamTo.setValue(20)
113 model.do()
114 model.testNbResults(Extrusion_1, 1)
115 model.testNbSubResults(Extrusion_1, [2])
116 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
117 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
118 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [48])
119 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [96])
120 model.testResultsVolumes(Extrusion_1, [57985.85])
121
122 # offset "From" face
123 ParamFrom.setValue(20)
124 model.do()
125 model.testNbResults(Extrusion_1, 1)
126 model.testNbSubResults(Extrusion_1, [2])
127 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
128 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
129 model.testResultsVolumes(Extrusion_1, [37985.85])
130
131 ParamFrom.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, [2])
136 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
137 model.testResultsVolumes(Extrusion_1, [77985.85])
138
139 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
140
141 model.end()
142
143 assert(model.checkPythonDump())