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