Salome HOME
fe2614320fc3357a3753d9efe62c84957a1bdf7d
[modules/shaper.git] / src / SketchPlugin / Test / TestIntersectionChangeEdge.py
1 # Copyright (C) 2018-2022  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     TestIntersectionChangeEdge.py
22     Unit test of SketchPlugin_IntersectionPoint class
23 """
24
25 from SketchAPI import *
26
27 from salome.shaper import model
28
29 model.begin()
30 partSet = model.moduleDocument()
31 Part_1 = model.addPart(partSet)
32 Part_1_doc = Part_1.document()
33 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
34 SketchArc_1 = Sketch_1.addArc(0, 0, 13.75, -26.66341125962693, -24.98309575119448, 16.60857991180005, False)
35 SketchArc_2 = Sketch_1.addArc(0, 0, 53.75, -26.66341125962693, -53.75, -26.66341125962693, False)
36 SketchLine_1 = Sketch_1.addLine(13.75, -26.66341125962693, 53.75, -26.66341125962693)
37 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.startPoint())
38 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchArc_2.startPoint(), SketchLine_1.endPoint())
39 SketchLine_2 = Sketch_1.addLine(-24.98309575119448, 16.60857991180005, -53.75, -26.66341125962693)
40 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_2.startPoint())
41 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchLine_2.endPoint())
42 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
43 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchArc_2.center(), SketchArc_1.center())
44 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_2.result(), SketchArc_1.results()[1])
45 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_1.result())
46 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 30)
47 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
48 SketchPoint_1 = SketchProjection_1.createdFeature()
49 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchArc_2.center(), SketchAPI_Point(SketchPoint_1).coordinates())
50 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchArc_2.results()[1], 60)
51 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 40)
52 model.do()
53 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1f-SketchArc_2_2f-SketchLine_2r-SketchArc_1_2r")], model.selection(), 50, 50)
54 Filling_1 = model.addFilling(Part_1_doc, [model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/From_Face]"), model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_2_2][Extrusion_1_1/To_Face]")])
55 Plane_4 = model.addPlane(Part_1_doc, model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/To_Face]"), model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_1/From_Face]"), False)
56 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Plane_1"))
57 SketchProjection_2 = Sketch_2.addProjection(model.selection("VERTEX", "Sketch_1/SketchArc_1"), False)
58 SketchPoint_2 = SketchProjection_2.createdFeature()
59 SketchLine_3 = Sketch_2.addLine(-70, 60, 70, 60)
60 SketchLine_4 = Sketch_2.addLine(70, 60, 70, -60)
61 SketchLine_5 = Sketch_2.addLine(70, -60, -70, -60)
62 SketchLine_6 = Sketch_2.addLine(-70, -60, -70, 60)
63 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint())
64 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
65 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
66 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
67 SketchConstraintHorizontal_2 = Sketch_2.setHorizontal(SketchLine_3.result())
68 SketchConstraintVertical_1 = Sketch_2.setVertical(SketchLine_4.result())
69 SketchConstraintHorizontal_3 = Sketch_2.setHorizontal(SketchLine_5.result())
70 SketchConstraintVertical_2 = Sketch_2.setVertical(SketchLine_6.result())
71 SketchConstraintDistance_1 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_5.result(), 60, True)
72 SketchConstraintDistance_2 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_3.result(), 60, True)
73 SketchConstraintDistance_3 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_4.result(), 70, True)
74 SketchConstraintDistance_4 = Sketch_2.setDistance(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_6.result(), 70, True)
75 model.do()
76 Face_1 = model.addFace(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchLine_3r")])
77 Intersection_1 = model.addIntersection(Part_1_doc, [model.selection("FACE", "Filling_1_1"), model.selection("FACE", "Face_1_1")])
78
79 # set different edges used for intersection and check reference data: number of intersection points and their coordinates
80 REF_DATA = [("Sketch_1/SketchArc_1_2", 1, [[30, 0]]),
81             ("Sketch_1/SketchLine_2", 1, [[-36.024358588836, 0]]),
82             ("Sketch_1/SketchArc_2_2", 2, [[60, 0], [-60, 0]]),
83             ("Sketch_1/SketchLine_1", 0, []),
84             ("[Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_1_2][Extrusion_1_1/To_Face]", 1, [[30, 50]]),
85             ("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_2][Extrusion_1_1/To_Face]", 1, [[-36.024358588836, 50]]),
86             ("[Extrusion_1_1/Generated_Face&Sketch_1/SketchArc_2_2][Extrusion_1_1/To_Face]", 2, [[60, 50], [-60, 50]]),
87             ("[Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_1][Extrusion_1_1/To_Face]", 0, []),
88             ("Intersection_1_1", 2, [[41.6438615258, -11.6181750315], [-0.0515933488223, -11.6181750315]])]
89 TOLERANCE = 1.e-7
90
91 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
92 SketchIntersectionPoint_1 = Sketch_3.addIntersectionPoint(model.selection("EDGE", "Intersection_1_1"), True)
93 model.do()
94
95 for ref in REF_DATA:
96     SketchIntersectionPoint_1.setByExternalEdgeName(ref[0])
97     aPoints = SketchIntersectionPoint_1.intersectionPoints()
98     assert(len(aPoints) == ref[1]), "Intersection with edge {} produce {} points, expected {}".format(ref[0], aPoints.size(), ref[1])
99     # check coordinates
100     ind = 0
101     for p in aPoints:
102         pnt = SketchAPI_Point(p)
103         delta = (pnt.coordinates().x() - ref[2][ind][0])**2 + (pnt.coordinates().y() - ref[2][ind][1])**2
104         assert(delta < TOLERANCE * TOLERANCE), "Wrong coordinates of intersection with edge {}: ({}, {}) != expected ({}, {})".format(ref[0], pnt.coordinates().x(), pnt.coordinates().y(), ref[2][ind][0], ref[2][ind][1])
105         ind += 1
106 model.do()
107
108 model.end()
109
110 assert(model.checkPythonDump())