Salome HOME
5c0d7bf80e28260b268a0ca38cfaacdc853391d6
[modules/shaper.git] / src / FeaturesPlugin / Test / TestMeasurementDistance.py
1 # Copyright (C) 2014-2023  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 from salome.shaper import model
21
22 import math
23
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 model.addParameter(Part_1_doc, "R", "50")
29 model.addParameter(Part_1_doc, "L", "40")
30 model.addParameter(Part_1_doc, "H", "20")
31 Point_2 = model.addPoint(Part_1_doc, 0, 100, 100)
32 Plane_4 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OX"), model.selection("VERTEX", "Point_1"), False)
33 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
34 SketchCircle_1 = Sketch_1.addCircle(50, 50, 50)
35 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "R")
36 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
37 SketchLine_1 = SketchProjection_1.createdFeature()
38 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_1.result(), SketchCircle_1.results()[1])
39 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
40 SketchLine_2 = SketchProjection_2.createdFeature()
41 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchLine_2.result(), SketchCircle_1.results()[1])
42 SketchLine_3 = Sketch_1.addLine(70, 40, 30, 40)
43 SketchLine_4 = Sketch_1.addLine(30, 40, 30, 60)
44 SketchLine_5 = Sketch_1.addLine(30, 60, 70, 60)
45 SketchLine_6 = Sketch_1.addLine(70, 60, 70, 40)
46 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint())
47 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
48 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
49 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
50 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result())
51 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result())
52 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result())
53 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result())
54 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_3.result(), "L")
55 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_4.result(), "H")
56 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_4.startPoint(), SketchCircle_1.center(), "L/2")
57 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_4.startPoint(), SketchCircle_1.center(), "H/2")
58 model.do()
59 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f")], model.selection(), model.selection("FACE", "Plane_1"), 0, model.selection(), 10)
60 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
61 SketchArc_1 = Sketch_2.addArc(100, 48.41229182762603, 87.5, 0, 87.5, 96.82458365525073, False)
62 SketchArc_2 = Sketch_2.addArc(0, 48.41229182762603, 87.5, 0, 87.5, 96.82458365525073, False)
63 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchArc_1.startPoint(), SketchArc_2.startPoint())
64 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchArc_2.endPoint(), SketchArc_1.endPoint())
65 SketchConstraintRadius_2 = Sketch_2.setRadius(SketchArc_1.results()[1], "R")
66 SketchConstraintRadius_3 = Sketch_2.setRadius(SketchArc_2.results()[1], "2*R")
67 SketchLine_7 = Sketch_2.addLine(0, 48.41229182762603, 100, 48.41229182762603)
68 SketchLine_7.setAuxiliary(True)
69 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchArc_2.center(), SketchLine_7.startPoint())
70 SketchConstraintCoincidence_8 = Sketch_2.setCoincident(SketchArc_1.center(), SketchLine_7.endPoint())
71 SketchConstraintHorizontal_3 = Sketch_2.setHorizontal(SketchLine_7.result())
72 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OY"), False)
73 SketchLine_8 = SketchProjection_3.createdFeature()
74 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchArc_1.startPoint(), SketchLine_8.result())
75 SketchProjection_4 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OZ"), False)
76 SketchLine_9 = SketchProjection_4.createdFeature()
77 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_7.startPoint(), SketchLine_9.result())
78 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchLine_7.endPoint(), SketchArc_2.results()[1])
79 SketchConstraintMirror_1 = Sketch_2.addMirror(SketchLine_9.result(), [SketchArc_2.results()[1], SketchArc_1.results()[1]])
80 [SketchArc_3, SketchArc_4] = SketchConstraintMirror_1.mirrored()
81 model.do()
82 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_2")], model.selection(), 100, 0)
83 model.do()
84
85 TOLERANCE = 1.e-6
86
87 # reference data
88 REF_DATA = [(model.selection("VERTEX", "PartSet/Origin"),
89              model.selection("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face]"),
90              122.4744871,
91              "NA"),
92             (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face]"),
93              model.selection("VERTEX", "Sketch_2/SketchArc_1"),
94              36.94403089,
95              "NA"),
96             (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face]"),
97              model.selection("EDGE", "([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face])([Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/To_Face])"),
98              0,
99              100.0),
100             (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face]"),
101              model.selection("EDGE", "[Extrusion_2_1/Generated_Face&Sketch_2/SketchArc_1_2][Extrusion_2_1/To_Face]"),
102              16.00781059,
103              176.710217655),
104             (model.selection("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2][Extrusion_1_1/From_Face]"),
105              model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchArc_1_2"),
106              8.412291828,
107              "NA"),
108             (model.selection("VERTEX", "Sketch_1/SketchCircle_1_2__cc"),
109              model.selection("FACE", "Plane_1"),
110              35.35533906,
111              "NA"),
112             (model.selection("FACE", "Extrusion_2_2/From_Face"),
113              model.selection("FACE", "Extrusion_2_2/To_Face"),
114              100,
115              100),
116             (model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2"),
117              model.selection("FACE", "Extrusion_2_1/Generated_Face&Sketch_2/SketchArc_1_2"),
118              0,
119              165.799606),
120             (model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchLine_5"),
121              model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_1/SketchCircle_1_2"),
122              27.63932023,
123              40.0),
124             (model.selection("SOLID", "Extrusion_1_1"),
125              model.selection("FACE", "Extrusion_2_1/To_Face"),
126              12.5,
127              "NA"),
128             (model.selection("SOLID", "Extrusion_1_1"),
129              model.selection("SOLID", "Extrusion_2_1"),
130              0,
131              "NA"),
132             (model.selection("SOLID", "Extrusion_1_1"),
133              model.selection("SOLID", "Extrusion_2_2"),
134              87.5,
135              "NA")
136            ]
137
138 for ref in REF_DATA:
139     dist = model.measureDistance(Part_1_doc, ref[0], ref[1])
140     assert(math.fabs(dist - ref[2]) < TOLERANCE), "Distance {} differs from expected value {}".format(dist, ref[2])
141     if ref[3] != "NA":
142         prox = model.shapeProximity(Part_1_doc, ref[0], ref[1])
143         assert(math.fabs(prox - ref[3]) < TOLERANCE), "Proximity {} differs from expected value {}".format(prox, ref[3])
144
145 model.end()