Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces18.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 Edge_1_objects = [model.selection("EDGE", "Sketch_1/SketchLine_1"), model.selection("EDGE", "Sketch_1/SketchLine_2"), model.selection("EDGE", "Sketch_1/SketchArc_1_2")]
53 Edge_1 = model.addEdge(Part_1_doc, Edge_1_objects)
54 Extrusion_1_objects = [model.selection("EDGE", "Edge_1_1"), model.selection("EDGE", "Edge_1_2"), model.selection("EDGE", "Edge_1_3")]
55 Extrusion_1 = model.addExtrusion(Part_1_doc, Extrusion_1_objects, model.selection("EDGE", "PartSet/OY"), model.selection("FACE", "Partition_1_1_2/Modified_Face&Cone_1_1/Face_1"), "offsetTo", model.selection("FACE", "Plane_2"), "offsetFrom")
56
57 from GeomAPI import GeomAPI_Shape
58
59 model.testNbResults(Extrusion_1, 3)
60 model.testNbSubResults(Extrusion_1, [0, 0, 0])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0])
62 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 5])
64 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 10])
65 model.testResultsAreas(Extrusion_1, [1309.42058662, 1016.82520496, 2589.5946928])
66
67 # change radius of sphere and check failure
68 ParamR.setValue(10)
69 model.do()
70 assert(Extrusion_1.feature().error() != "")
71
72 # revert failure, check the intersected boundaries are processed well
73 ParamR.setValue(40)
74 model.do()
75 model.testNbResults(Extrusion_1, 3)
76 model.testNbSubResults(Extrusion_1, [0, 0, 0])
77 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0])
78 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1])
79 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 5])
80 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 10])
81 model.testResultsAreas(Extrusion_1, [1081.93830116, 793.80218227, 2095.8021933])
82
83 # change offsetting "To" face and check failure
84 ParamTo.setValue(-20)
85 model.do()
86 assert(Extrusion_1.feature().error() != "")
87
88 # revert failure
89 ParamTo.setValue(8)
90 model.do()
91 model.testNbResults(Extrusion_1, 3)
92 model.testNbSubResults(Extrusion_1, [0, 0, 0])
93 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0])
94 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1])
95 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 5])
96 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 10])
97 model.testResultsAreas(Extrusion_1, [1314.8586588, 1022.169915122, 2601.32913399])
98
99 # offset "From" face
100 ParamFrom.setValue(20)
101 model.do()
102 model.testNbResults(Extrusion_1, 3)
103 model.testNbSubResults(Extrusion_1, [0, 0, 0])
104 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0])
105 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1])
106 model.testResultsAreas(Extrusion_1, [825.71966141, 533.030917699, 1551.6191757579])
107
108 ParamFrom.setValue(-20)
109 model.do()
110 model.testNbResults(Extrusion_1, 3)
111 model.testNbSubResults(Extrusion_1, [0, 0, 0])
112 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0])
113 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1])
114 model.testResultsAreas(Extrusion_1, [1803.997656259, 1511.308912545, 3651.0390970659])
115
116 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
117
118 model.end()
119
120 assert(model.checkPythonDump())