Salome HOME
e089f982b3ab6af83ae61030a6d66b039cd92b28
[modules/shaper.git] / src / FeaturesPlugin / Test / TestExtrusion_ByFaces10.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 from GeomAPI import GeomAPI_Shape
22
23 from salome.shaper import model
24
25 model.begin()
26 partSet = model.moduleDocument()
27 Part_1 = model.addPart(partSet)
28 Part_1_doc = Part_1.document()
29 ParamR = model.addParameter(Part_1_doc, "R", "50")
30 ParamSize = model.addParameter(Part_1_doc, "Size", "50")
31 ParamFrom = model.addParameter(Part_1_doc, "offsetFrom", "0")
32 ParamTo = model.addParameter(Part_1_doc, "offsetTo", "0")
33 Sphere_1 = model.addSphere(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), "R")
34 Partition_1 = model.addPartition(Part_1_doc, [model.selection("SOLID", "Sphere_1_1"), model.selection("FACE", "PartSet/XOZ")])
35 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "PartSet/XOZ"), 30, False)
36 Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1"))
37 SketchLine_1 = Sketch_1.addLine(50, -50, -50, -50)
38 SketchLine_2 = Sketch_1.addLine(-50, -50, -50, 50)
39 SketchLine_3 = Sketch_1.addLine(-50, 50, 50, 50)
40 SketchLine_4 = Sketch_1.addLine(50, 50, 50, -50)
41 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint())
42 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
43 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
44 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
45 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
46 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
47 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
48 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
49 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
50 SketchPoint_1 = SketchProjection_1.createdFeature()
51 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_4.result(), "Size", True)
52 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_2.result(), "Size", True)
53 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.result(), "Size", True)
54 SketchConstraintDistance_4 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_3.result(), "Size", True)
55 model.do()
56 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_4r-SketchLine_3r-SketchLine_2r-SketchLine_1r")])
57 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
58 SketchLine_5 = Sketch_2.addLine(20, -40.3112887414928, 20, 20)
59 SketchLine_6 = Sketch_2.addLine(20, 20, -40.31128874149281, 20.00000000000001)
60 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
61 SketchConstraintVertical_3 = Sketch_2.setVertical(SketchLine_5.result())
62 SketchConstraintHorizontal_3 = Sketch_2.setHorizontal(SketchLine_6.result())
63 SketchArc_1 = Sketch_2.addArc(0, 0, -40.31128874149281, 20.00000000000001, 20, -40.3112887414928, False)
64 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchArc_1.startPoint())
65 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchArc_1.endPoint(), SketchLine_5.startPoint())
66 SketchConstraintEqual_1 = Sketch_2.setEqual(SketchLine_5.result(), SketchLine_6.result())
67 SketchConstraintDistance_5 = Sketch_2.setDistance(SketchArc_1.center(), SketchLine_5.result(), 20, True)
68 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
69 SketchPoint_2 = SketchProjection_2.createdFeature()
70 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchArc_1.center())
71 SketchConstraintRadius_1 = Sketch_2.setRadius(SketchArc_1.results()[1], 45)
72 SketchLine_7 = Sketch_2.addLine(20, 20, -31.81980515339464, -31.81980515339464)
73 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_7.startPoint())
74 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchArc_1.results()[1])
75 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchArc_1.center(), SketchLine_7.result())
76 model.do()
77 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection(), model.selection("FACE", "Partition_1_1_1/Modified_Face&Sphere_1_1/Face_1"), "offsetTo", model.selection("FACE", "Face_1_1"), "offsetFrom")
78
79 # extrusion have to fail because of several results with shared topology
80 assert(Extrusion_1.feature().error() != "")
81
82 # change radius of sphere and check failure
83 ParamR.setValue(10)
84 model.do()
85 assert(Extrusion_1.feature().error() != "")
86
87 ParamR.setValue(45)
88 model.do()
89 assert(Extrusion_1.feature().error() != "")
90
91 # change offsetting "To" face and check failure
92 ParamTo.setValue(-20)
93 model.do()
94 assert(Extrusion_1.feature().error() != "")
95
96 # revert failure
97 ParamTo.setValue(20)
98 model.do()
99 model.testNbResults(Extrusion_1, 1)
100 model.testNbSubResults(Extrusion_1, [2])
101 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
102 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [10])
103 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [36])
104 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [72])
105 model.testResultsVolumes(Extrusion_1, [105008.93])
106
107 # offset "From" face
108 ParamFrom.setValue(20)
109 model.do()
110 model.testNbResults(Extrusion_1, 1)
111 model.testNbSubResults(Extrusion_1, [2])
112 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
113 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [10])
114 model.testResultsVolumes(Extrusion_1, [179594.5])
115
116 # check failure
117 ParamFrom.setValue(-20)
118 model.do()
119 assert(Extrusion_1.feature().error() != "")
120
121 # revert failure
122 ParamTo.setValue(0)
123 model.do()
124 model.testNbResults(Extrusion_1, 1)
125 model.testNbSubResults(Extrusion_1, [2])
126 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [2])
127 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [10])
128 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [39])
129 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [78])
130 model.testResultsVolumes(Extrusion_1, [62569.416])
131
132 model.testHaveNamingSubshapes(Extrusion_1, model, Part_1_doc)
133
134 model.end()
135
136 assert(model.checkPythonDump())