Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces06.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 Cone_1 = model.addCone(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), "R", "R/5", "R")
32 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Cone_1_1"), model.selection("FACE", "PartSet/XOZ")])
33 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOZ"), 20, False)
34 Plane_5 = model.addPlane(Part_1_doc, model.selection("FACE", "Plane_1"), model.selection("EDGE", "PartSet/OZ"), 330)
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
36 SketchLine_1 = Sketch_1.addLine(10, 8.819660112501044, 10, 30)
37 SketchLine_2 = Sketch_1.addLine(10, 30, -11.18033988749895, 30)
38 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
39 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
40 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_2.result())
41 SketchArc_1 = Sketch_1.addArc(0, 20, -11.18033988749895, 30, 10, 8.819660112501044, False)
42 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchArc_1.startPoint())
43 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_1.startPoint())
44 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_2.result())
45 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_1.result(), 10, True)
46 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 15)
47 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OZ"), False)
48 SketchLine_3 = SketchProjection_1.createdFeature()
49 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.center(), SketchLine_3.result())
50 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchAPI_Line(SketchLine_3).startPoint(), SketchArc_1.center(), 20)
51 model.do()
52 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchArc_1_2f")], model.selection(), model.selection("FACE", "Partition_1_1_2/Modified_Face&Cone_1_1/Face_1"), "offsetTo", model.selection("FACE", "Plane_2"), "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, [5])
60 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [20])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [40])
62 model.testResultsVolumes(Extrusion_1, [31363.4963946])
63
64 # change radius of sphere and check failure
65 ParamR.setValue(10)
66 model.do()
67 assert(Extrusion_1.feature().error() != "")
68
69 # revert failure, check the intersected boundaries are processed well
70 ParamR.setValue(40)
71 model.do()
72 model.testNbResults(Extrusion_1, 1)
73 model.testNbSubResults(Extrusion_1, [0])
74 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
75 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [5])
76 model.testResultsVolumes(Extrusion_1, [25645.0102138])
77
78 # change offsetting "To" face and check failure
79 ParamTo.setValue(-20)
80 model.do()
81 assert(Extrusion_1.feature().error() != "")
82
83 # revert failure
84 ParamTo.setValue(8)
85 model.do()
86 model.testNbResults(Extrusion_1, 1)
87 model.testNbSubResults(Extrusion_1, [0])
88 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
89 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [5])
90 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [20])
91 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [40])
92 model.testResultsVolumes(Extrusion_1, [31501.9671234])
93
94 # offset "From" face
95 ParamFrom.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, [5])
101 model.testResultsVolumes(Extrusion_1, [18737.752452])
102
103 ParamFrom.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, [5])
109 model.testResultsVolumes(Extrusion_1, [44266.1817647])
110
111 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
112
113 model.end()
114
115 assert(model.checkPythonDump())