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