Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / SketchPlugin / Test / Test1577.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     Test1577.py
23     Test case for issue #1577 "distance constraint change sign"
24 """
25
26 from salome.shaper import model
27 import math
28
29 model.begin()
30 partSet = model.moduleDocument()
31 Part_1 = model.addPart(partSet)
32 Part_1_doc = Part_1.document()
33 model.addParameter(Part_1_doc, "Base_Off", "5.875")
34 model.addParameter(Part_1_doc, "Base_H", "3")
35 model.addParameter(Part_1_doc, "Base_B", "1.5")
36 model.addParameter(Part_1_doc, "Wall_R", "6.188")
37 model.addParameter(Part_1_doc, "Wall_T1", "0.089")
38 model.addParameter(Part_1_doc, "Wall_T2", "0.261")
39 model.addParameter(Part_1_doc, "Wall_H", "12.465")
40 model.addParameter(Part_1_doc, "StrGal_B", "0.75")
41 model.addParameter(Part_1_doc, "StrGal_H", "1.8")
42 model.addParameter(Part_1_doc, "StrGal_BU", "0.6")
43 model.addParameter(Part_1_doc, "StrGal_Inc", "0.2")
44 model.addParameter(Part_1_doc, "Bracket_H", "1.2")
45 model.addParameter(Part_1_doc, "Bracket_B", "0.15")
46 model.addParameter(Part_1_doc, "Bracket_B1", "0.256")
47 model.addParameter(Part_1_doc, "Bracket_B2", "0.094")
48 model.addParameter(Part_1_doc, "Bracket_H1", "1.226")
49 model.addParameter(Part_1_doc, "Cover_R", "9.794")
50 model.addParameter(Part_1_doc, "Cover_T", "0.082")
51 model.addParameter(Part_1_doc, "Cover_T1", "0.125")
52 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
53 SketchPoint_1 = Sketch_1.addPoint(0, 2.425)
54 SketchConstraintRigid_1 = Sketch_1.setFixed(SketchPoint_1.coordinates())
55 SketchLine_1 = Sketch_1.addLine(6.277, 12.18846022232796, 6.277, -8.121250994790044)
56 SketchLine_1.setAuxiliary(True)
57 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
58 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_1.result(), "Wall_R+Wall_T1", False)
59 SketchLine_2 = Sketch_1.addLine(6.538, -3.45, 7.777, -3.45)
60 SketchLine_3 = Sketch_1.addLine(7.777, -3.45, 7.777, -6.45)
61 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
62 SketchLine_4 = Sketch_1.addLine(7.777, -6.45, 0, -6.45)
63 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
64 SketchLine_5 = Sketch_1.addLine(0, -6.45, 0, -3.45)
65 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
66 SketchLine_6 = Sketch_1.addLine(0, -3.45, 6.188, -3.45)
67 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
68 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_3.result())
69 SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_5.result())
70 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_6.result())
71 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_2.result())
72 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_4.result())
73 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_6.result(), "Base_Off", False)
74 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchPoint_1.coordinates(), SketchLine_2.result(), "Base_Off", False)
75 SketchConstraintDistance_4 = Sketch_1.setDistance(SketchLine_2.endPoint(), SketchLine_4.result(), "Base_H", False)
76 SketchConstraintDistance_5 = Sketch_1.setDistance(SketchLine_4.startPoint(), SketchLine_1.result(), "Base_B", False)
77 SketchConstraintDistance_6 = Sketch_1.setDistance(SketchLine_5.startPoint(), SketchLine_1.result(), "Wall_R+Wall_T1", False)
78 SketchConstraintDistance_7 = Sketch_1.setDistance(SketchLine_6.endPoint(), SketchLine_1.result(), "Wall_T1", False)
79 SketchConstraintDistance_8 = Sketch_1.setDistance(SketchLine_1.result(), SketchLine_2.startPoint(), "Wall_T2", False)
80 SketchLine_7 = Sketch_1.addLine(5.677, -4.05, 6.877, -4.05)
81 SketchLine_8 = Sketch_1.addLine(6.877, -4.05, 7.027, -4.25)
82 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
83 SketchLine_9 = Sketch_1.addLine(7.027, -4.25, 7.027, -5.85)
84 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint())
85 SketchLine_10 = Sketch_1.addLine(7.027, -5.85, 5.527, -5.85)
86 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint())
87 SketchLine_11 = Sketch_1.addLine(5.527, -5.85, 5.527, -4.25)
88 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
89 SketchLine_12 = Sketch_1.addLine(5.527, -4.25, 5.677, -4.05)
90 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_11.endPoint(), SketchLine_12.startPoint())
91 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_7.startPoint(), SketchLine_12.endPoint())
92 SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_9.result())
93 SketchConstraintVertical_5 = Sketch_1.setVertical(SketchLine_11.result())
94 SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_7.result())
95 SketchConstraintHorizontal_5 = Sketch_1.setHorizontal(SketchLine_10.result())
96 SketchConstraintDistance_9 = Sketch_1.setDistance(SketchLine_10.endPoint(), SketchLine_1.result(), "StrGal_B", False)
97 SketchConstraintDistance_10 = Sketch_1.setDistance(SketchLine_10.startPoint(), SketchLine_1.result(), "StrGal_B", False)
98 SketchConstraintDistance_11 = Sketch_1.setDistance(SketchLine_12.endPoint(), SketchLine_1.result(), "StrGal_BU", False)
99 SketchConstraintDistance_12 = Sketch_1.setDistance(SketchLine_7.endPoint(), SketchLine_1.result(), "StrGal_BU", False)
100 SketchConstraintDistance_13 = Sketch_1.setDistance(SketchLine_7.endPoint(), SketchLine_10.result(), "StrGal_H", False)
101 SketchConstraintDistance_14 = Sketch_1.setDistance(SketchLine_7.endPoint(), SketchLine_2.result(), 0.6, True)
102 SketchConstraintDistance_15 = Sketch_1.setDistance(SketchLine_9.startPoint(), SketchLine_7.result(), "StrGal_Inc", False)
103 SketchConstraintDistance_16 = Sketch_1.setDistance(SketchLine_11.endPoint(), SketchLine_7.result(), "StrGal_Inc", False)
104 SketchLine_13 = Sketch_1.addLine(6.188, -3.45, 6.188, 0.287301537219)
105 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_13.startPoint())
106 SketchLine_14 = Sketch_1.addLine(6.538, -3.45, 6.538, -1.380737101082)
107 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchLine_14.startPoint())
108 SketchLine_15 = Sketch_1.addLine(6.538, -1.380737101082, 6.366, -1.102730661365)
109 SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchLine_14.endPoint(), SketchLine_15.startPoint())
110 SketchLine_16 = Sketch_1.addLine(6.366, -1.102730661365, 6.366, 0.21779992729)
111 SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_15.endPoint(), SketchLine_16.startPoint())
112 SketchConstraintVertical_6 = Sketch_1.setVertical(SketchLine_13.result())
113 SketchConstraintVertical_7 = Sketch_1.setVertical(SketchLine_14.result())
114 SketchConstraintVertical_8 = Sketch_1.setVertical(SketchLine_16.result())
115 SketchConstraintDistance_17 = Sketch_1.setDistance(SketchLine_16.endPoint(), SketchLine_1.result(), "Wall_T1", False)
116 model.do()
117
118 # store coordinates of the gallery
119 Lines = [SketchLine_7, SketchLine_8, SketchLine_9, SketchLine_10, SketchLine_11, SketchLine_12]
120 RefCoorindates = []
121 for line in Lines:
122     RefCoorindates.append(line.startPoint().x())
123     RefCoorindates.append(line.startPoint().y())
124     RefCoorindates.append(line.endPoint().x())
125     RefCoorindates.append(line.endPoint().y())
126
127 SketchConstraintDistance_18 = Sketch_1.setDistance(SketchLine_14.endPoint(), SketchLine_2.result(), "Wall_H", True)
128 model.do()
129
130 # check coordinates of lines are not changed
131 TOLERANCE = 1e-6
132 index = 0
133 for line in Lines:
134     assert(math.fabs(line.startPoint().x() - RefCoorindates[index]) < TOLERANCE)
135     assert(math.fabs(line.startPoint().y() - RefCoorindates[index + 1]) < TOLERANCE)
136     assert(math.fabs(line.endPoint().x() - RefCoorindates[index + 2]) < TOLERANCE)
137     assert(math.fabs(line.endPoint().y() - RefCoorindates[index + 3]) < TOLERANCE)
138     index += 4
139
140 model.end()