1 # Copyright (C) 2018-2019 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 email : webmaster.salome@opencascade.com
20 from salome.shaper import model
21 from SketchAPI import *
22 from ModelAPI import *
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
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])
40 # case 1: undo the error
42 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
45 model.checkSketchErrorDegenerated(Sketch_1)
47 model.checkSketch(Sketch_1)
49 # case 2: remove degeneracy-producting constraint
51 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
53 model.checkSketchErrorDegenerated(Sketch_1)
54 Part_1_doc.removeFeature(aCoincidence.feature())
57 model.checkSketch(Sketch_1)
59 # case 3: remove degenerated edge
61 aCoincidence = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_1).startPoint(), SketchCircle_1.center())
63 model.checkSketchErrorDegenerated(Sketch_1)
64 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchCircle_1.feature()]))
67 model.checkSketch(Sketch_1)
70 #######################################
71 # Test 2. Make a line degenerated
72 #######################################
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()
83 # case 1: undo the error
85 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
86 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
89 model.checkSketchErrorDegenerated(Sketch_2)
92 model.checkSketch(Sketch_2)
94 # case 2: remove degeneracy-producting constraint
96 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
97 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
99 model.checkSketchErrorDegenerated(Sketch_2)
100 Part_1_doc.removeFeature(aParallel1.feature())
101 Part_1_doc.removeFeature(aParallel2.feature())
104 model.checkSketch(Sketch_2)
106 # case 3: remove degenerated edge
108 aParallel1 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_3.result())
109 aParallel2 = Sketch_2.setParallel(SketchLine_2.result(), SketchLine_4.result())
111 model.checkSketchErrorDegenerated(Sketch_2)
112 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_2.feature()]))
115 model.checkSketch(Sketch_2)
118 #######################################
119 # Test 3. Make an arc degenerated
120 #######################################
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)
127 # case 1: undo the error
129 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
131 model.checkSketchErrorDegenerated(Sketch_3)
134 model.checkSketch(Sketch_3)
136 # case 2: remove degeneracy-producting constraint
138 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
140 model.checkSketchErrorDegenerated(Sketch_3)
141 Part_1_doc.removeFeature(aCoincidence.feature())
143 model.checkSketch(Sketch_3)
145 # case 3: remove degenerated edge
147 aCoincidence = Sketch_3.setCoincident(SketchArc_1.startPoint(), SketchArc_1.endPoint())
149 model.checkSketchErrorDegenerated(Sketch_3)
150 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchArc_1.feature()]))
152 assert(Sketch_3.solverError().value() == "")