Salome HOME
Task 2.3. Sketch Point created by intersectionPoints
[modules/shaper.git] / src / SketchPlugin / Test / TestIntersectionWithLine.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     TestIntersectionWithLine.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", "40")
36 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
37 SketchLine_1 = Sketch_1.addLine(0, 0, 50, 0)
38 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
39 SketchPoint_1 = SketchProjection_1.createdFeature()
40 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchPoint_1.result())
41 SketchLine_2 = Sketch_1.addLine(50, 0, 50, 10)
42 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
43 SketchLine_3 = Sketch_1.addLine(50, 10, 40, 10)
44 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
45 SketchLine_4 = Sketch_1.addLine(40, 10, 40, 30)
46 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
47 SketchLine_5 = Sketch_1.addLine(40, 30, 50, 30)
48 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
49 SketchLine_6 = Sketch_1.addLine(50, 30, 50, 40)
50 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
51 SketchLine_7 = Sketch_1.addLine(50, 40, 0, 50)
52 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
53 SketchLine_8 = Sketch_1.addLine(0, 50, 0, 0)
54 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
55 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_8.endPoint())
56 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
57 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
58 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_5.result())
59 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
60 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
61 SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_8.result())
62 SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_2.result(), SketchLine_6.result())
63 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_6.result())
64 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 50)
65 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_8.result(), 50)
66 SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_2.result(), 10)
67 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_1.startPoint(), SketchLine_4.startPoint(), "D")
68 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.endPoint(), SketchLine_7.startPoint(), 40, True)
69 model.do()
70 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f-SketchLine_7f-SketchLine_8f")], model.selection(), 10, 0)
71 ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), 5, 5, [model.selection("SOLID", "Extrusion_1_1")])
72 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face_5"))
73 SketchIntersectionPoint_1 = Sketch_2.addIntersectionPoint(model.selection("EDGE", "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_1"))
74 [SketchPoint_2] = SketchIntersectionPoint_1.intersectionPoints()
75 SketchCircle_1 = Sketch_2.addCircle(40, 10, 5)
76 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchCircle_1.center())
77 SketchConstraintRadius_1 = Sketch_2.setRadius(SketchCircle_1.results()[1], 5)
78 ExtrusionCut_1.setNestedSketch(Sketch_2)
79 model.do()
80
81 assert(SketchIntersectionPoint_1.feature().results().empty() == False)
82
83 model.testNbResults(ExtrusionCut_1, 1)
84 model.testNbSubResults(ExtrusionCut_1, [0])
85 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
86 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [13])
87 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [66])
88 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [132])
89 model.testResultsVolumes(ExtrusionCut_1, [20303.650459150881943060085177422])
90
91 # change parameter and check intersection validity
92 ParamD.setValue(35)
93 model.do();
94
95 assert(SketchIntersectionPoint_1.feature().results().empty() == False)
96
97 model.testNbResults(ExtrusionCut_1, 1)
98 model.testNbSubResults(ExtrusionCut_1, [0])
99 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
100 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [13])
101 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [66])
102 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [132])
103 model.testResultsVolumes(ExtrusionCut_1, [19303.650459150881943060085177422])
104
105 # change parameter and check the intersection is not valid now
106 ParamD.setValue(60)
107 model.do();
108 assert(SketchIntersectionPoint_1.feature().results().empty() == True)
109
110 # change parameter to initial value and check intersection validity
111 ParamD.setValue(40)
112 model.do();
113 # coincidence of circle center and intersection point is lost on previous step, restore it
114 [SketchPoint_2] = SketchIntersectionPoint_1.intersectionPoints()
115 Sketch_2.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchCircle_1.center())
116 model.do()
117
118 assert(SketchIntersectionPoint_1.feature().results().empty() == False)
119
120 model.testNbResults(ExtrusionCut_1, 1)
121 model.testNbSubResults(ExtrusionCut_1, [0])
122 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.SOLID, [1])
123 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.FACE, [13])
124 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.EDGE, [66])
125 model.testNbSubShapes(ExtrusionCut_1, GeomAPI_Shape.VERTEX, [132])
126 model.testResultsVolumes(ExtrusionCut_1, [20303.650459150881943060085177422])
127
128 model.end()
129
130 assert(model.checkPythonDump())