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