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