1 ## Copyright (C) 2018-20xx CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 from salome.shaper import model
22 from SketchAPI import *
23 from ModelAPI import *
26 partSet = model.moduleDocument()
27 Part_1 = model.addPart(partSet)
28 Part_1_doc = Part_1.document()
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])
41 # case 1: undo the error
43 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
46 model.checkSketchErrorDegenerated(Sketch_1)
48 model.checkSketch(Sketch_1)
50 # case 2: remove degeneracy-producting constraint
52 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
54 model.checkSketchErrorDegenerated(Sketch_1)
55 Part_1_doc.removeFeature(aCoincidence.feature())
58 model.checkSketch(Sketch_1)
60 # case 3: remove degenerated edge
62 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
64 model.checkSketchErrorDegenerated(Sketch_1)
65 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchCircle_1.feature()]))
68 model.checkSketch(Sketch_1)
71 #######################################
72 # Test 2. Make a line degenerated
73 #######################################
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()
84 # case 1: undo the error
86 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
87 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
90 model.checkSketchErrorDegenerated(Sketch_2)
93 model.checkSketch(Sketch_2)
95 # case 2: remove degeneracy-producting constraint
97 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
98 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
100 model.checkSketchErrorDegenerated(Sketch_2)
101 Part_1_doc.removeFeature(aParallel1.feature())
102 Part_1_doc.removeFeature(aParallel2.feature())
105 model.checkSketch(Sketch_2)
107 # case 3: remove degenerated edge
109 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
110 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
112 model.checkSketchErrorDegenerated(Sketch_2)
113 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_2.feature()]))
116 model.checkSketch(Sketch_2)
119 #######################################
120 # Test 3. Make an arc degenerated
121 #######################################
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)
128 # case 1: undo the error
130 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
132 model.checkSketchErrorDegenerated(Sketch_3)
135 model.checkSketch(Sketch_3)
137 # case 2: remove degeneracy-producting constraint
139 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
141 model.checkSketchErrorDegenerated(Sketch_3)
142 Part_1_doc.removeFeature(aCoincidence.feature())
144 model.checkSketch(Sketch_3)
146 # case 3: remove degenerated edge
148 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
150 model.checkSketchErrorDegenerated(Sketch_3)
151 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchArc_1.feature()]))
153 assert(Sketch_3.solverError().value() == "")