Salome HOME
048ae7fc03315e68b7f725b97950676c053ab83c
[modules/shaper.git] / src / SketchPlugin / Test / Test2427.py
1 # Copyright (C) 2018-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 """
21     Test2427.py
22     Test case for issue #2427 "error in sketch solver"
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 SketchLine_1 = Sketch_1.addLine(0, 0, 9.085455512028094, 9.085455512028094)
35 SketchLine_1.setAuxiliary(True)
36 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
37 SketchLine_2 = SketchProjection_1.createdFeature()
38 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_2.result(), SketchLine_1.result(), 45)
39 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchAPI_Line(SketchLine_2).startPoint())
40 SketchArc_1 = Sketch_1.addArc(0, 0, 3.427521359192312, 2.062061427864143, 2.06206142786378, 3.427521359191917, True)
41 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_1.center())
42 SketchLine_3 = Sketch_1.addLine(6, 7.365459931328136, 6, 12)
43 SketchLine_4 = Sketch_1.addLine(6, 12, -6, 12)
44 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
45 SketchLine_5 = Sketch_1.addLine(-6, 12, -6, 7.365459931328136)
46 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
47 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 4)
48 SketchLine_6 = Sketch_1.addLine(-5.8309518948453, -7.5, -11, -7.5)
49 SketchLine_7 = Sketch_1.addLine(-11, -7.5, -11, -10)
50 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
51 SketchLine_8 = Sketch_1.addLine(-11, -10, 11, -10)
52 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_7.endPoint(), SketchLine_8.startPoint())
53 SketchLine_9 = Sketch_1.addLine(11, -10, 11, -7.5)
54 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchLine_9.startPoint())
55 SketchLine_10 = Sketch_1.addLine(11, -7.5, 5.830951894845301, -7.5)
56 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_9.endPoint(), SketchLine_10.startPoint())
57 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_6.result())
58 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_10.result())
59 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_8.result())
60 SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_4.result())
61 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_7.result())
62 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_9.result())
63 SketchConstraintVertical_3 = Sketch_1.setVertical(SketchLine_3.result())
64 SketchConstraintVertical_4 = Sketch_1.setVertical(SketchLine_5.result())
65 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_8.result(), 22)
66 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_4.result(), 12)
67 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_4.result(), SketchLine_7.endPoint(), 22, True)
68 SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_7.result(), 2.5)
69 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_8.endPoint(), SketchLine_2.result(), 10, True)
70 SketchPoint_1 = Sketch_1.addPoint(0, -10)
71 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchPoint_1.coordinates(), SketchLine_8.result())
72 SketchConstraintMiddle_1 = Sketch_1.setMiddlePoint(SketchLine_8.result(), SketchPoint_1.coordinates())
73 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
74 SketchLine_11 = SketchProjection_2.createdFeature()
75 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchLine_11.result(), SketchPoint_1.coordinates())
76 SketchLine_12 = Sketch_1.addLine(2.06206142786378, 3.427521359191917, 6, 7.365459931328136)
77 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_12.startPoint())
78 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_3.startPoint())
79 SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_12.result(), SketchLine_1.result())
80 SketchLine_13 = Sketch_1.addLine(3.427521359192312, 2.062061427864143, 8.000256151511394, 5.123075395720331)
81 SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_13.startPoint())
82 SketchArc_2 = Sketch_1.addArc(0, 0, 8.000256151511394, 5.123075395720331, 5.830951894845301, -7.5, True)
83 SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_2.center())
84 SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchArc_2.startPoint(), SketchLine_13.endPoint())
85 SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_10.endPoint(), SketchArc_2.endPoint())
86 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchArc_2.results()[1], 9.5)
87 SketchLine_14 = Sketch_1.addLine(3.427521359192312, 2.062061427864143, 2.06206142786378, 3.427521359191917)
88 SketchLine_14.setAuxiliary(True)
89 SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_14.startPoint())
90 SketchConstraintCoincidence_18 = Sketch_1.setCoincident(SketchLine_14.endPoint(), SketchArc_1.endPoint())
91 SketchPoint_2 = Sketch_1.addPoint(2.744791393527834, 2.744791393527835)
92 SketchConstraintCoincidence_19 = Sketch_1.setCoincident(SketchPoint_2.coordinates(), SketchLine_14.result())
93 SketchConstraintMiddle_2 = Sketch_1.setMiddlePoint(SketchLine_14.result(), SketchPoint_2.coordinates())
94 SketchConstraintCoincidence_20 = Sketch_1.setCoincident(SketchLine_14.result(), SketchPoint_2.coordinates())
95 SketchConstraintCoincidence_21 = Sketch_1.setCoincident(SketchPoint_2.coordinates(), SketchLine_1.result())
96 SketchArc_3 = Sketch_1.addArc(0, 0, -6, 7.365459931328136, -5.8309518948453, -7.5, False)
97 SketchConstraintCoincidence_22 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchArc_3.startPoint())
98 SketchConstraintCoincidence_23 = Sketch_1.setCoincident(SketchLine_6.startPoint(), SketchArc_3.endPoint())
99 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchArc_2.results()[1], SketchArc_3.results()[1])
100 SketchPoint_3 = Sketch_1.addPoint(0, 12)
101 SketchConstraintMiddle_3 = Sketch_1.setMiddlePoint(SketchLine_4.result(), SketchPoint_3.coordinates())
102 SketchConstraintCoincidence_24 = Sketch_1.setCoincident(SketchPoint_3.coordinates(), SketchLine_11.result())
103 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_7.result(), SketchLine_9.result())
104 SketchConstraintEqual_3 = Sketch_1.setEqual(SketchLine_6.result(), SketchLine_10.result())
105 SketchConstraintEqual_4 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_5.result())
106 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchLine_13.endPoint(), SketchLine_12.result(), 3, True)
107 SketchConstraintCoincidence_25 = Sketch_1.setCoincident(SketchArc_3.center(), SketchLine_1.result())
108 model.do()
109 model.end()
110
111
112 # Test 1. Add constraint to make auxiliary line degenerated, then undo
113 model.begin()
114 aParallel = Sketch_1.setParallel(SketchLine_1.result(), SketchLine_13.result())
115 model.do()
116 model.end()
117 model.checkSketchErrorDegenerated(Sketch_1)
118 model.undo()
119 model.checkSketch(Sketch_1)
120
121 # Test 2. Add constraint to make auxiliary line degenerated, then remove such constraint
122 model.begin()
123 aParallel = Sketch_1.setParallel(SketchLine_1.result(), SketchLine_13.result())
124 model.do()
125 model.checkSketchErrorDegenerated(Sketch_1)
126 Part_1_doc.removeFeature(aParallel.feature())
127 model.do()
128 model.end()
129 model.checkSketch(Sketch_1)
130
131 assert(model.checkPythonDump())