Salome HOME
87189dd471f99b87926ff9e63ae891d51ccd40aa
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces08.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 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 SketchLine_5 = Sketch_1.addLine(-10, 20, 5, 40)
53 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_5.startPoint(), SketchLine_3.result())
54 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_1.result())
55 SketchConstraintDistanceHorizontal_2 = Sketch_1.setHorizontalDistance(SketchLine_2.endPoint(), SketchLine_5.startPoint(), 20)
56 SketchConstraintDistanceHorizontal_3 = Sketch_1.setHorizontalDistance(SketchLine_5.endPoint(), SketchLine_1.startPoint(), 15)
57 model.do()
58 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_5f"), model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_5r-SketchLine_3f-SketchLine_4f")], model.selection(), model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"), "offsetTo", model.selection(), "offsetFrom")
59
60 from GeomAPI import GeomAPI_Shape
61
62 model.testNbResults(Extrusion_1, 1)
63 model.testNbSubResults(Extrusion_1, [2])
64 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
65 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
66 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [48])
67 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [96])
68 model.testResultsVolumes(Extrusion_1, [97540.6])
69
70 # change radius of cylinder and check failure
71 ParamR.setValue(10)
72 model.do()
73 assert(Extrusion_1.feature().error() != "")
74
75 # revert failure, 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, [2])
80 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
81 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
82 model.testResultsVolumes(Extrusion_1, [75176.8518])
83
84 ParamR.setValue(40);
85 model.do()
86 model.testNbResults(Extrusion_1, 1)
87 model.testNbSubResults(Extrusion_1, [2])
88 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
89 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
90 model.testResultsVolumes(Extrusion_1, [86812.03])
91
92 # change offsetting "To" face and check failure
93 ParamTo.setValue(-25)
94 model.do()
95 assert(Extrusion_1.feature().error() != "")
96
97 # revert failure
98 ParamTo.setValue(20)
99 model.do()
100 model.testNbResults(Extrusion_1, 1)
101 model.testNbSubResults(Extrusion_1, [2])
102 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
103 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
104 model.testResultsVolumes(Extrusion_1, [107985.85])
105
106 # offset "From" face
107 ParamFrom.setValue(20)
108 model.do()
109 model.testNbResults(Extrusion_1, 1)
110 model.testNbSubResults(Extrusion_1, [2])
111 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
112 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
113 model.testResultsVolumes(Extrusion_1, [87985.85])
114
115 ParamFrom.setValue(-20)
116 model.do()
117 model.testNbResults(Extrusion_1, 1)
118 model.testNbSubResults(Extrusion_1, [2])
119 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
120 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [12])
121 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [48])
122 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [96])
123 model.testResultsVolumes(Extrusion_1, [127985.85])
124
125 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
126
127 model.end()
128
129 assert(model.checkPythonDump())