Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchPlugin / Test / TestIntersectionWithSpline.py
1 # Copyright (C) 2018-2019  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 """
21     TestIntersectionWithSpline.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", "5")
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
36 SketchArc_1 = Sketch_1.addArc(-20, 0, -12.51615726667241, -49.43674845641531, -67.51615726667241, 15.56325154358469, False)
37 SketchLine_1 = Sketch_1.addLine(-67.51615726667241, 15.56325154358469, -12.51615726667241, 15.56325154358469)
38 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_1.startPoint())
39 SketchLine_2 = Sketch_1.addLine(-12.51615726667241, 15.56325154358469, -12.51615726667241, -49.43674845641531)
40 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
41 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_2.endPoint())
42 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
43 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
44 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
45 SketchLine_3 = SketchProjection_1.createdFeature()
46 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.center(), SketchLine_3.result())
47 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 50)
48 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 65)
49 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchArc_1.center(), SketchAPI_Line(SketchLine_3).startPoint(), 20)
50 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_1.result(), 55)
51 model.do()
52 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2r-SketchLine_1f-SketchLine_2f")], model.selection(), 25, 25)
53 Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/From_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_1/To_Face]")])
54 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchArc_1_2r-SketchLine_1f-SketchLine_2f")])
55 Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1"), model.selection("FACE", "Face_1_1")])
56 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
57 SketchLine_4 = Sketch_2.addLine(-34.11217447219568, 40, 20, -37.28019411294778)
58 SketchLine_5 = Sketch_2.addLine(20, -37.28019411294778, 20, 40)
59 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
60 SketchLine_6 = Sketch_2.addLine(20, 40, -34.11217447219568, 40)
61 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
62 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchLine_4.startPoint(), SketchLine_6.endPoint())
63 SketchConstraintVertical_2 = Sketch_2.setVertical(SketchLine_5.result())
64 SketchConstraintHorizontal_2 = Sketch_2.setHorizontal(SketchLine_6.result())
65 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
66 SketchPoint_1 = SketchProjection_2.createdFeature()
67 SketchConstraintDistance_1 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_5.result(), 20, True)
68 SketchConstraintDistance_2 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_6.result(), 40, True)
69 SketchConstraintDistance_3 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_4.result(), "D", True)
70 SketchConstraintAngle_1 = Sketch_2.setAngle(SketchLine_5.result(), SketchLine_4.result(), 35)
71 model.do()
72 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_4r-SketchLine_5f-SketchLine_6f")], model.selection(), 10, 10)
73 ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [], model.selection(), 10, 0, [model.selection("SOLID", "Extrusion_2_1")])
74 Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchLine_4"))
75 SketchIntersectionPoint_1 = Sketch_3.addIntersectionPoint(model.selection("EDGE", "Intersection_1_1"), False)
76 [SketchPoint_2, SketchPoint_3] = SketchIntersectionPoint_1.intersectionPoints()
77 SketchCircle_1 = Sketch_3.addCircle(-33.22640570408476, 0, 5)
78 SketchConstraintCoincidence_8 = Sketch_3.setCoincident(SketchCircle_1.center(), SketchAPI_Point(SketchPoint_2).coordinates())
79 SketchCircle_2 = Sketch_3.addCircle(21.47998214403209, 0, 5)
80 SketchConstraintCoincidence_9 = Sketch_3.setCoincident(SketchCircle_2.center(), SketchAPI_Point(SketchPoint_3).coordinates())
81 SketchConstraintEqual_1 = Sketch_3.setEqual(SketchCircle_1.results()[1], SketchCircle_2.results()[1])
82 SketchConstraintRadius_2 = Sketch_3.setRadius(SketchCircle_1.results()[1], 5)
83 ExtrusionFuse_1.setNestedSketch(Sketch_3)
84 model.do()
85
86 assert(SketchIntersectionPoint_1.feature().results().size() == 2)
87
88 model.testNbResults(ExtrusionFuse_1, 1)
89 model.testNbSubResults(ExtrusionFuse_1, [0])
90 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
91 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [9])
92 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
93 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
94 model.testResultsVolumes(ExtrusionFuse_1, [43388.789797644698410294950008392])
95
96 # change parameter and check intersection validity
97 ParamD.setValue(15)
98 model.do();
99
100 assert(SketchIntersectionPoint_1.feature().results().size() == 2)
101
102 model.testNbResults(ExtrusionFuse_1, 1)
103 model.testNbSubResults(ExtrusionFuse_1, [0])
104 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
105 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [9])
106 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
107 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
108 model.testResultsVolumes(ExtrusionFuse_1, [64385.484780074148147832602262497])
109
110 # change parameter and check single intersection
111 ParamD.setValue(25)
112 model.do();
113
114 assert(SketchIntersectionPoint_1.feature().results().size() == 1)
115
116 model.testNbResults(ExtrusionFuse_1, 1)
117 model.testNbSubResults(ExtrusionFuse_1, [0])
118 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
119 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [9])
120 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
121 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
122 model.testResultsVolumes(ExtrusionFuse_1, [89638.890852351003559306263923645])
123
124 # change parameter and check intersection is NOT valid now
125 ParamD.setValue(50)
126 model.do();
127
128 assert(SketchIntersectionPoint_1.feature().results().empty())
129
130 # revert parameter to original value and reset coincidences
131 ParamD.setValue(5)
132 model.do()
133 [SketchPoint_2, SketchPoint_3] = SketchIntersectionPoint_1.intersectionPoints()
134 SketchConstraintCoincidence_8 = Sketch_3.setCoincident(SketchCircle_1.center(), SketchAPI_Point(SketchPoint_2).coordinates())
135 SketchConstraintCoincidence_9 = Sketch_3.setCoincident(SketchCircle_2.center(), SketchAPI_Point(SketchPoint_3).coordinates())
136 model.do()
137
138 assert(SketchIntersectionPoint_1.feature().results().size() == 2)
139
140 model.testNbResults(ExtrusionFuse_1, 1)
141 model.testNbSubResults(ExtrusionFuse_1, [0])
142 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
143 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [9])
144 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
145 model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
146 model.testResultsVolumes(ExtrusionFuse_1, [43388.789797644698410294950008392])
147
148 model.end()
149
150 assert(model.checkPythonDump())