Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / SketchPlugin / Test / TestDegeneratedGeometry.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 from salome.shaper import model
22 from SketchAPI import *
23 from ModelAPI import *
24
25 model.begin()
26 partSet = model.moduleDocument()
27 Part_1 = model.addPart(partSet)
28 Part_1_doc = Part_1.document()
29
30 #######################################
31 # Test 1. Make a circle degenerated
32 #######################################
33 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
34 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
35 SketchLine_1 = SketchProjection_1.createdFeature()
36 SketchCircle_1 = Sketch_1.addCircle(25, 20, 25)
37 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_1.result(), SketchCircle_1.results()[1])
38 model.do()
39 model.end()
40
41 # case 1: undo the error
42 model.begin()
43 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
44 model.do()
45 model.end()
46 model.checkSketchErrorDegenerated(Sketch_1)
47 model.undo()
48 model.checkSketch(Sketch_1)
49
50 # case 2: remove degeneracy-producting constraint
51 model.begin()
52 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
53 model.do()
54 model.checkSketchErrorDegenerated(Sketch_1)
55 Part_1_doc.removeFeature(aCoincidence.feature())
56 model.do()
57 model.end()
58 model.checkSketch(Sketch_1)
59
60 # case 3: remove degenerated edge
61 model.begin()
62 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
63 model.do()
64 model.checkSketchErrorDegenerated(Sketch_1)
65 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchCircle_1.feature()]))
66 model.do()
67 model.end()
68 model.checkSketch(Sketch_1)
69
70
71 #######################################
72 # Test 2. Make a line degenerated
73 #######################################
74 model.begin()
75 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
76 SketchLine_2 = Sketch_2.addLine(15, 15, 40, 40)
77 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OX"), True)
78 SketchLine_3 = SketchProjection_2.createdFeature()
79 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/OY"), True)
80 SketchLine_4 = SketchProjection_3.createdFeature()
81 model.do()
82 model.end()
83
84 # case 1: undo the error
85 model.begin()
86 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
87 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
88 model.do()
89 model.end()
90 model.checkSketchErrorDegenerated(Sketch_2)
91 model.undo()
92 model.do()
93 model.checkSketch(Sketch_2)
94
95 # case 2: remove degeneracy-producting constraint
96 model.begin()
97 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
98 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
99 model.do()
100 model.checkSketchErrorDegenerated(Sketch_2)
101 Part_1_doc.removeFeature(aParallel1.feature())
102 Part_1_doc.removeFeature(aParallel2.feature())
103 model.do()
104 model.end()
105 model.checkSketch(Sketch_2)
106
107 # case 3: remove degenerated edge
108 model.begin()
109 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
110 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
111 model.do()
112 model.checkSketchErrorDegenerated(Sketch_2)
113 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_2.feature()]))
114 model.do()
115 model.end()
116 model.checkSketch(Sketch_2)
117
118
119 #######################################
120 # Test 3. Make an arc degenerated
121 #######################################
122 model.begin()
123 Sketch_3 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
124 SketchArc_1 = Sketch_3.addArc(-23.95261096318143, -9.48105223640866, -4.386575834490306, -17.91131183048461, -20.45766592507274, 11.53523589116715, False)
125 model.do()
126 model.end()
127
128 # case 1: undo the error
129 model.begin()
130 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
131 model.do()
132 model.end()
133 model.checkSketchErrorDegenerated(Sketch_3)
134 model.undo()
135 model.do()
136 model.checkSketch(Sketch_3)
137
138 # case 2: remove degeneracy-producting constraint
139 model.begin()
140 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
141 model.do()
142 model.checkSketchErrorDegenerated(Sketch_3)
143 Part_1_doc.removeFeature(aCoincidence.feature())
144 model.do()
145 model.end()
146 model.checkSketch(Sketch_3)
147
148 # case 3: remove degenerated edge
149 model.begin()
150 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
151 model.do()
152 model.checkSketchErrorDegenerated(Sketch_3)
153 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchArc_1.feature()]))
154 model.do()
155 model.end()
156 assert(Sketch_3.solverError().value() == "")