Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestIntersectionWithCircle.py
1 # Copyright (C) 2018-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 """
21     TestIntersectionWithCircle.py
22     Unit test of SketchPlugin_IntersectionPoint class
23 """
24
25 from GeomAPI import *
26 from SketchAPI import *
27
28 from salome.shaper import model
29
30 model.begin()
31 partSet = model.moduleDocument()
32 Part_1 = model.addPart(partSet)
33 Part_1_doc = Part_1.document()
34 ParamD = model.addParameter(Part_1_doc, "D", "12")
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
36 SketchLine_1 = Sketch_1.addLine(21.25834261322606, 21.25834261322606, 0, 0)
37 SketchLine_2 = Sketch_1.addLine(0, 0, 50, -4.088404617988313e-023)
38 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
39 SketchLine_3 = Sketch_1.addLine(50, -4.088404617988313e-023, 50, 50)
40 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
41 SketchLine_4 = Sketch_1.addLine(50, 50, 28.74165738677394, 28.74165738677394)
42 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
43 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
44 SketchPoint_1 = SketchProjection_1.createdFeature()
45 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchAPI_Point(SketchPoint_1).coordinates())
46 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_2.result())
47 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_3.result())
48 SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_4.result(), SketchLine_1.result())
49 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_3.result())
50 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_1.result(), SketchLine_4.result())
51 SketchArc_1 = Sketch_1.addArc(31, 19, 21.25834261322606, 21.25834261322606, 28.74165738677394, 28.74165738677394, False)
52 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_1.startPoint())
53 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchArc_1.endPoint())
54 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 50)
55 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 10)
56 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_2.result(), 19, True)
57 model.do()
58 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchArc_1_2r")], model.selection(), 10, 0)
59 Plane_4 = model.addPlane(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2"), "D", True)
60 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1"))
61 SketchIntersectionPoint_1 = Sketch_2.addIntersectionPoint(model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_1/To_Face]"), True)
62 SketchIntersectionPoint_1.result().setName("SketchIntersectionPoint_1")
63 [SketchPoint_2, SketchPoint_3] = SketchIntersectionPoint_1.intersectionPoints()
64 SketchCircle_1 = Sketch_2.addCircle(38.14142842854285, 10, 1)
65 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchCircle_1.center(), SketchAPI_Point(SketchPoint_2).coordinates())
66 SketchConstraintRadius_2 = Sketch_2.setRadius(SketchCircle_1.results()[1], 1)
67 SketchLine_5 = Sketch_2.addLine(23.85857157145715, 10.5, 23.85857157145715, 5)
68 SketchLine_6 = Sketch_2.addLine(22.85857157145715, 6, 22.85857157145715, 10.5)
69 SketchLine_7 = Sketch_2.addLine(22.85857157145715, 10.5, 23.85857157145715, 10.5)
70 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
71 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_5.startPoint(), SketchLine_7.endPoint())
72 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_5.result())
73 SketchConstraintVertical_2 = Sketch_2.setVertical(SketchLine_5.result())
74 SketchConstraintVertical_3 = Sketch_2.setVertical(SketchLine_6.result())
75 SketchConstraintHorizontal_2 = Sketch_2.setHorizontal(SketchLine_7.result())
76 SketchConstraintDistanceHorizontal_1 = Sketch_2.setHorizontalDistance(SketchLine_6.endPoint(), SketchLine_5.startPoint(), 1)
77 SketchConstraintDistanceVertical_1 = Sketch_2.setVerticalDistance(SketchLine_5.startPoint(), SketchAPI_Point(SketchPoint_3).coordinates(), 0.5)
78 SketchArc_2 = Sketch_2.addArc(23.85857157145715, 6, 23.85857157145715, 5, 22.85857157145715, 6, True)
79 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_5.result(), SketchArc_2.center())
80 SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchArc_2.startPoint())
81 SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchArc_2.endPoint(), SketchLine_6.startPoint())
82 SketchConstraintDistanceVertical_2 = Sketch_2.setVerticalDistance(SketchAPI_Point(SketchPoint_3).coordinates(), SketchArc_2.startPoint(), 5)
83 SketchConstraintTangent_1 = Sketch_2.setTangent(SketchArc_2.results()[1], SketchLine_6.result())
84 model.do()
85 RevolutionCut_1 = model.addRevolutionCut(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_7r-SketchLine_6r-SketchArc_2_2f-SketchLine_5r")], model.selection("EDGE", "Sketch_2/SketchLine_5"), 360, 0, [model.selection("SOLID", "Extrusion_1_1")])
86 ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchCircle_1_2f")], model.selection(), 5, 5, [model.selection("SOLID", "RevolutionCut_1_1")])
87 model.do()
88
89 assert(SketchIntersectionPoint_1.feature().results().size() == 2)
90
91 model.testNbResults(ExtrusionCut_1, 1)
92 model.testNbSubResults(ExtrusionCut_1, [0])
93 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
94 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [13])
95 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [66])
96 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [132])
97 model.testResultsVolumes(ExtrusionCut_1, [9451.611727849665840039961040020])
98
99 # change parameter and check intersection validity
100 ParamD.setValue(15)
101 model.do();
102
103 assert(SketchIntersectionPoint_1.feature().results().size() == 2)
104
105 model.testNbResults(ExtrusionCut_1, 1)
106 model.testNbSubResults(ExtrusionCut_1, [0])
107 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
108 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [14])
109 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [74])
110 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [148])
111 model.testResultsVolumes(ExtrusionCut_1, [9451.152473626798382611013948917])
112
113 # change parameter and check intersection validity
114 ParamD.setValue(19)
115 model.do();
116
117 assert(SketchIntersectionPoint_1.feature().results().size() == 2)
118
119 model.testNbResults(ExtrusionCut_1, 1)
120 model.testNbSubResults(ExtrusionCut_1, [0])
121 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
122 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [14])
123 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [74])
124 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [148])
125 model.testResultsVolumes(ExtrusionCut_1, [9448.046243665688962209969758987])
126
127 # change parameter and check intersection validity
128 ParamD.setValue(23)
129 model.do();
130
131 assert(SketchIntersectionPoint_1.feature().results().size() == 1)
132
133 model.testNbResults(ExtrusionCut_1, 1)
134 model.testNbSubResults(ExtrusionCut_1, [0])
135 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
136 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [10])
137 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [50])
138 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [100])
139 model.testResultsVolumes(ExtrusionCut_1, [9458.635858820198336616158485413])
140
141 # change parameter and check intersection validity
142 ParamD.setValue(29)
143 model.do();
144
145 assert(SketchIntersectionPoint_1.feature().results().size() == 1)
146
147 model.testNbResults(ExtrusionCut_1, 1)
148 model.testNbSubResults(ExtrusionCut_1, [0])
149 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
150 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [9])
151 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [42])
152 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [84])
153 model.testResultsVolumes(ExtrusionCut_1, [9463.846034357124153757467865944])
154
155 model.end()
156
157 assert(model.checkPythonDump())