Salome HOME
Copyright update 2022
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces14.py
1 # Copyright (C) 2014-2022  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 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")]
54 Edge_1 = model.addEdge(Part_1_doc, Edge_1_objects)
55 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")]
56 Extrusion_1 = model.addExtrusion(Part_1_doc, Extrusion_1_objects, model.selection("EDGE", "PartSet/OY"), model.selection("FACE", "Translation_1_1/MF:Translated&Cylinder_1_1/Face_1"), "offsetTo", model.selection(), "offsetFrom")
57
58 from GeomAPI import GeomAPI_Shape
59
60 model.testNbResults(Extrusion_1, 4)
61 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
62 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
64 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
65 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
66 model.testResultsAreas(Extrusion_1, [4877.030013, 1800, 4877.030013, 1916.515139])
67
68 # change radius of cylinder and check failure
69 ParamR.setValue(10)
70 model.do()
71 assert(Extrusion_1.feature().error() != "")
72
73 ParamR.setValue(30)
74 model.do()
75 assert(Extrusion_1.feature().error() != "")
76
77 # revert failure, check the intersected boundaries are processed well
78 ParamR.setValue(40);
79 model.do()
80 model.testNbResults(Extrusion_1, 4)
81 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
82 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
83 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
84 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
85 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
86 model.testResultsAreas(Extrusion_1, [4340.6015418, 1529.1502622, 4340.6015418, 1692.820323])
87
88 # change offsetting "To" face and check failure
89 ParamTo.setValue(-20)
90 model.do()
91 assert(Extrusion_1.feature().error() != "")
92
93 # revert failure
94 ParamTo.setValue(20)
95 model.do()
96 model.testNbResults(Extrusion_1, 4)
97 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
98 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
99 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
100 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
101 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
102 model.testResultsAreas(Extrusion_1, [5399.2925211, 2039.2304845, 5399.2925212, 2131.37085])
103
104 # offset "From" face
105 ParamFrom.setValue(20)
106 model.do()
107 model.testNbResults(Extrusion_1, 4)
108 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
109 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
110 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
111 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
112 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
113 model.testResultsAreas(Extrusion_1, [6399.2925211, 2439.2304845, 6399.2925212, 2531.37085])
114
115 ParamFrom.setValue(-20)
116 model.do()
117 model.testNbResults(Extrusion_1, 4)
118 model.testNbSubResults(Extrusion_1, [0, 0, 0, 0])
119 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0, 0, 0, 0])
120 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [1, 1, 1, 1])
121 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4, 4, 4, 4])
122 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8, 8, 8, 8])
123 model.testResultsAreas(Extrusion_1, [4399.2925211, 1639.2304845, 4399.2925212, 1731.37085])
124
125 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
126
127 model.end()
128
129 assert(model.checkPythonDump())