Salome HOME
96ef8db51d6e382cfb3f88e7b07258a3a3410dce
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces19.py
1 # Copyright (C) 2014-2021  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 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 Wire_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 Wire_1 = model.addWire(Part_1_doc, Wire_1_objects)
54 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection("EDGE", "PartSet/OY"), model.selection("FACE", "Cylinder_1_1/Face_1"), "offsetTo", model.selection(), "offsetFrom")
55
56 from GeomAPI import GeomAPI_Shape
57
58 model.testNbResults(Extrusion_1, 1)
59 model.testNbSubResults(Extrusion_1, [0])
60 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
61 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
62 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [16])
63 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [32])
64 model.testResultsAreas(Extrusion_1, [6470.575165134267])
65
66 # change radius of cylinder
67 ParamR.setValue(10)
68 model.do()
69 model.testNbResults(Extrusion_1, 1)
70 model.testNbSubResults(Extrusion_1, [2])
71 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
72 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
73 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4])
74 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8])
75 model.testResultsAreas(Extrusion_1, [314.159265359])
76
77 ParamR.setValue(30)
78 model.do()
79 model.testNbResults(Extrusion_1, 1)
80 model.testNbSubResults(Extrusion_1, [0])
81 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
82 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [3])
83 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [10])
84 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [20])
85 model.testResultsAreas(Extrusion_1, [2964.89877572])
86
87 # check the intersected boundaries are processed well
88 ParamR.setValue(40);
89 model.do()
90 model.testNbResults(Extrusion_1, 1)
91 model.testNbSubResults(Extrusion_1, [0])
92 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
93 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
94 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [16])
95 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [32])
96 model.testResultsAreas(Extrusion_1, [4903.173668915])
97
98 # change offsetting "To" face
99 ParamTo.setValue(-20)
100 model.do()
101 model.testNbResults(Extrusion_1, 1)
102 model.testNbSubResults(Extrusion_1, [2])
103 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
104 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [2])
105 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [4])
106 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [8])
107 model.testResultsAreas(Extrusion_1, [1256.637061267])
108
109 ParamTo.setValue(20)
110 model.do()
111 model.testNbResults(Extrusion_1, 1)
112 model.testNbSubResults(Extrusion_1, [0])
113 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
114 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
115 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [16])
116 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [32])
117 model.testResultsAreas(Extrusion_1, [7969.186376787])
118
119 # offset "From" face
120 ParamFrom.setValue(20)
121 model.do()
122 model.testNbResults(Extrusion_1, 1)
123 model.testNbSubResults(Extrusion_1, [0])
124 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
125 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
126 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [16])
127 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [32])
128 model.testResultsAreas(Extrusion_1, [5169.186376787])
129
130 ParamFrom.setValue(-20)
131 model.do()
132 model.testNbResults(Extrusion_1, 1)
133 model.testNbSubResults(Extrusion_1, [0])
134 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [0])
135 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [4])
136 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [16])
137 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [32])
138 model.testResultsAreas(Extrusion_1, [10769.186376787])
139
140 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
141
142 model.end()
143
144 assert(model.checkPythonDump())