1 # Copyright (C) 2017-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
21 TestConstraintHorizontalValidator.py
22 It tests validation of horizontal and vertical segments in H and V constraints to avoid
23 selection segments that already have one of these constraint"
26 #=========================================================================
28 #=========================================================================
29 from salome.shaper import model
30 from ModelAPI import *
32 #=========================================================================
34 #=========================================================================
36 partSet = model.moduleDocument()
37 Part_1 = model.addPart(partSet)
38 Part_1_doc = Part_1.document()
39 #=========================================================================
40 # Creation of a sketch
41 #=========================================================================
42 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
43 SketchLine_1 = Sketch_1.addLine(20, 20, 40, 80)
44 SketchLine_2 = Sketch_1.addLine(40, 80, 60, 40)
45 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
46 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
47 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
49 #=========================================================================
50 # Checking that sketch and constraints become invalid when to one line
51 # two horizontal/vertical constraints are applied in any combination
52 #=========================================================================
53 aFactory = ModelAPI_Session.get().validators()
54 assert(aFactory.validate(Sketch_1.feature()))
55 assert(Sketch_1.feature().error() != '')
56 #=========================================================================
57 # Remove duplicated Vertical constraints
58 #=========================================================================
59 Part_1_doc.removeFeature(SketchConstraintVertical_1.feature())
60 assert(aFactory.validate(Sketch_1.feature()))
62 #=========================================================================
63 # Checking that after excess constraints are removed or undone,
64 # sketch becomes valid.
65 #=========================================================================
66 assert(aFactory.validate(Sketch_1.feature()))
67 assert(Sketch_1.feature().error() == '')
69 assert(model.checkPythonDump())