Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestSignedDistancePointLine.py
1 # Copyright (C) 2017-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 from salome.shaper import model
20 import math
21
22 TOLERANCE = 1.e-5
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, "clearance", "210")
29 model.addParameter(Part_1_doc, "wheel_R", "203")
30 model.addParameter(Part_1_doc, "arc_R", "wheel_R+70")
31 model.addParameter(Part_1_doc, "hood_height", "290")
32 HeightParam = model.addParameter(Part_1_doc, "height", "900")
33 LengthParam = model.addParameter(Part_1_doc, "length", "1460")
34 PosParam = model.addParameter(Part_1_doc, "position", "71.99905090248758")
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
36 SketchLine_1 = Sketch_1.addLine(-281.378739745974, 78.99909999999998, -98.87873974597397, 78.99909999999998)
37 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
38 SketchArc_1 = Sketch_1.addArc(174.031501908677, 71.9991, -98.87873974597397, 78.99909999999998, 446.941743563328, 78.9991, True)
39 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchArc_1.startPoint())
40 SketchArc_2 = Sketch_1.addArc(-554.288981400625, 71.9991, -281.378739745974, 78.99909999999998, -827.1992230552759, 78.9991, False)
41 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_2.startPoint())
42 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchLine_1.result())
43 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_1.result())
44 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchArc_2.center(), SketchLine_1.result(), "clearance-wheel_R", True)
45 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchArc_1.center(), SketchLine_1.result(), "clearance-wheel_R", True)
46 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchArc_2.results()[1], SketchArc_1.results()[1])
47 SketchCircle_1 = Sketch_1.addCircle(-554.288981400625, 71.9991, 203)
48 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchArc_2.center(), SketchCircle_1.center())
49 SketchCircle_2 = Sketch_1.addCircle(174.031501908677, 71.9991, 203)
50 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.center(), SketchCircle_2.center())
51 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "wheel_R")
52 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchCircle_1.results()[1], SketchCircle_2.results()[1])
53 SketchLine_2 = Sketch_1.addLine(-827.1992230552759, 78.9991, -960.4001854579536, 78.9991)
54 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchLine_2.startPoint())
55 SketchLine_3 = Sketch_1.addLine(-960.4001854579536, 78.9991, -960.4001854579536, 368.9991)
56 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
57 SketchLine_4 = Sketch_1.addLine(-891.6236641114499, 437.7756213465037, -540.5628729569305, 437.7756213465037)
58 SketchLine_5 = Sketch_1.addLine(-540.5628729569305, 437.7756213465037, -349.330908394406, 768.9991)
59 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
60 SketchLine_6 = Sketch_1.addLine(-349.330908394406, 768.9991, 308.3678499795216, 768.9991)
61 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
62 SketchLine_7 = Sketch_1.addLine(308.3678499795216, 768.9991, 499.5998145420464, 437.7756213465038)
63 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
64 SketchLine_8 = Sketch_1.addLine(499.5998145420464, 437.7756213465038, 499.5998145420464, 78.9991)
65 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
66 SketchLine_9 = Sketch_1.addLine(499.5998145420464, 78.9991, 446.941743563328, 78.9991)
67 SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint())
68 SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_9.endPoint())
69 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_2.result())
70 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_4.result())
71 SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_6.result())
72 SketchConstraintHorizontal_5 = Sketch_1.setHorizontal(SketchLine_9.result())
73 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_3.result())
74 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_8.result())
75 SketchArc_3 = Sketch_1.addArc(-891.6236641114499, 368.9991, -891.6236641114499, 437.7756213465037, -960.4001854579536, 368.9991, False)
76 SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchArc_3.startPoint(), SketchLine_4.startPoint())
77 SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchArc_3.endPoint(), SketchLine_3.endPoint())
78 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_3.results()[1], SketchLine_3.result())
79 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchArc_3.results()[1], SketchLine_4.result())
80 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_5.result(), SketchLine_4.result(), 120.0000000000006)
81 SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchLine_8.startPoint(), SketchLine_4.result())
82 SketchConstraintAngle_2 = Sketch_1.setAngleBackward(SketchLine_7.result(), SketchLine_6.result(), 120.0000000000006)
83 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchArc_2.center(), SketchLine_2.startPoint(), "arc_R", True)
84 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_2.endPoint(), SketchLine_5.endPoint(), "height-clearance")
85 SketchConstraintDistance_4 = Sketch_1.setDistance(SketchLine_2.endPoint(), SketchLine_9.startPoint(), "length", True)
86 SketchConstraintDistance_5 = Sketch_1.setDistance(SketchLine_3.endPoint(), SketchLine_2.result(), "hood_height", True)
87 SketchLine_10 = Sketch_1.addLine(model.selection("EDGE", "PartSet/OX"))
88 SketchConstraintDistance_6 = Sketch_1.setDistance(SketchCircle_2.center(), SketchLine_10.result(), "position", True)
89 SketchPoint_1 = Sketch_1.addPoint(-910.4001854579535, 347.7756213465037)
90 SketchPoint_2 = Sketch_1.addPoint(-910.9041532173604, 297.7781612460398)
91 SketchConstraintDistance_7 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_3.result(), 50, True)
92 SketchConstraintDistance_8 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_4.result(), 90, True)
93 SketchConstraintDistance_9 = Sketch_1.setDistance(SketchPoint_2.coordinates(), SketchPoint_1.coordinates(), 50, True)
94 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), "length/8")
95 model.do()
96 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchArc_1_2r-SketchLine_9r-SketchLine_8r-SketchLine_7r-SketchLine_6r-SketchLine_5r-SketchLine_4r-SketchArc_3_2f-SketchLine_3r-SketchLine_2r-SketchArc_2_2r")], model.selection(), 500, 0)
97 Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), model.selection("FACE", "Sketch_1/Face-SketchCircle_2_2f")], model.selection(), 500, -400)
98 Extrusion_3 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f"), model.selection("FACE", "Sketch_1/Face-SketchCircle_2_2f")], model.selection(), 100, 0)
99 model.do()
100
101 # Verify point-line signed distance
102 dist1 = model.signedDistancePointLine(SketchArc_1.center(), SketchLine_1)
103 dist2 = model.signedDistancePointLine(SketchArc_2.center(), SketchLine_1)
104 dist3 = model.signedDistancePointLine(SketchLine_3.endPoint(), SketchLine_2)
105 dist4 = model.signedDistancePointLine(SketchPoint_1, SketchLine_3)
106 dist5 = model.signedDistancePointLine(SketchPoint_1, SketchLine_4)
107
108 PosParam.setValue(300)
109 model.do()
110 curDist1 = model.signedDistancePointLine(SketchArc_1.center(), SketchLine_1)
111 curDist2 = model.signedDistancePointLine(SketchArc_2.center(), SketchLine_1)
112 curDist3 = model.signedDistancePointLine(SketchLine_3.endPoint(), SketchLine_2)
113 curDist4 = model.signedDistancePointLine(SketchPoint_1, SketchLine_3)
114 curDist5 = model.signedDistancePointLine(SketchPoint_1, SketchLine_4)
115 assert(math.fabs(dist1 - curDist1) < TOLERANCE), "Expected {}, actual {}".format(dist1, curDist1)
116 assert(math.fabs(dist2 - curDist2) < TOLERANCE), "Expected {}, actual {}".format(dist2, curDist2)
117 assert(math.fabs(dist3 - curDist3) < TOLERANCE), "Expected {}, actual {}".format(dist3, curDist3)
118 assert(math.fabs(dist4 - curDist4) < TOLERANCE), "Expected {}, actual {}".format(dist4, curDist4)
119 assert(math.fabs(dist5 - curDist5) < TOLERANCE), "Expected {}, actual {}".format(dist5, curDist5)
120
121 LengthParam.setValue(2000)
122 model.do()
123 curDist1 = model.signedDistancePointLine(SketchArc_1.center(), SketchLine_1)
124 curDist2 = model.signedDistancePointLine(SketchArc_2.center(), SketchLine_1)
125 curDist3 = model.signedDistancePointLine(SketchLine_3.endPoint(), SketchLine_2)
126 curDist4 = model.signedDistancePointLine(SketchPoint_1, SketchLine_3)
127 curDist5 = model.signedDistancePointLine(SketchPoint_1, SketchLine_4)
128 assert(math.fabs(dist1 - curDist1) < TOLERANCE), "Expected {}, actual {}".format(dist1, curDist1)
129 assert(math.fabs(dist2 - curDist2) < TOLERANCE), "Expected {}, actual {}".format(dist2, curDist2)
130 assert(math.fabs(dist3 - curDist3) < TOLERANCE), "Expected {}, actual {}".format(dist3, curDist3)
131 assert(math.fabs(dist4 - curDist4) < TOLERANCE), "Expected {}, actual {}".format(dist4, curDist4)
132 assert(math.fabs(dist5 - curDist5) < TOLERANCE), "Expected {}, actual {}".format(dist5, curDist5)
133
134 HeightParam.setValue(1200)
135 model.do()
136 curDist1 = model.signedDistancePointLine(SketchArc_1.center(), SketchLine_1)
137 curDist2 = model.signedDistancePointLine(SketchArc_2.center(), SketchLine_1)
138 curDist3 = model.signedDistancePointLine(SketchLine_3.endPoint(), SketchLine_2)
139 curDist4 = model.signedDistancePointLine(SketchPoint_1, SketchLine_3)
140 curDist5 = model.signedDistancePointLine(SketchPoint_1, SketchLine_4)
141 assert(math.fabs(dist1 - curDist1) < TOLERANCE), "Expected {}, actual {}".format(dist1, curDist1)
142 assert(math.fabs(dist2 - curDist2) < TOLERANCE), "Expected {}, actual {}".format(dist2, curDist2)
143 assert(math.fabs(dist3 - curDist3) < TOLERANCE), "Expected {}, actual {}".format(dist3, curDist3)
144 assert(math.fabs(dist4 - curDist4) < TOLERANCE), "Expected {}, actual {}".format(dist4, curDist4)
145 assert(math.fabs(dist5 - curDist5) < TOLERANCE), "Expected {}, actual {}".format(dist5, curDist5)
146
147 model.end()