Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces13.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 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 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/SketchLine_3"), model.selection("EDGE", "Sketch_1/SketchLine_4")]
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"), model.selection("EDGE", "Edge_1_4")]
55 Extrusion_1 = model.addExtrusion(Part_1_doc, Extrusion_1_objects, model.selection("EDGE", "PartSet/OY"), model.selection("FACE", "Cylinder_1_1/Face_1"), "offsetTo", model.selection(), "offsetFrom")
56
57 from GeomAPI import GeomAPI_Shape
58
59 model.testNbResults(Extrusion_1, 4)
60 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
62 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
64 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
65 model.testResultsAreas(Extrusion_1, [2377.030013, 800, 2377.030013, 916.515139])
66
67 # change radius of cylinder
68 ParamR.setValue(10)
69 model.do()
70 assert(Extrusion_1.feature().error() != "")
71
72 ParamR.setValue(30)
73 model.do()
74 assert(Extrusion_1.feature().error() != "")
75
76 # revert failure and check the intersected boundaries are processed well
77 ParamR.setValue(40);
78 model.do()
79 model.testNbResults(Extrusion_1, 4)
80 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
81 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
82 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
83 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
84 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
85 model.testResultsAreas(Extrusion_1, [1840.601542, 529.150262, 1840.601542, 692.820323])
86
87 # change offsetting "To" face
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, 4)
96 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
97 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
98 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
99 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
100 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
101 model.testResultsAreas(Extrusion_1, [2899.292521, 1039.2304845, 2899.292521, 1131.3708499])
102
103 # offset "From" face
104 ParamFrom.setValue(20)
105 model.do()
106 model.testNbResults(Extrusion_1, 4)
107 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
108 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
109 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
110 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
111 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
112 model.testResultsAreas(Extrusion_1, [3899.292521, 1439.2304845, 3899.292521, 1531.3708499])
113
114 ParamFrom.setValue(-20)
115 model.do()
116 model.testNbResults(Extrusion_1, 4)
117 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
118 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
119 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
120 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
121 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
122 model.testResultsAreas(Extrusion_1, [1899.292521, 639.2304845, 1899.292521, 731.3708499])
123
124 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
125
126 model.end()
127
128 assert(model.checkPythonDump())