Salome HOME
513c5234bfb6097637271a9a0d0fa3d34b1054be
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintHorizontalValidator.py
1 # Copyright (C) 2017-2022  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 """
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"
24 """
25
26 #=========================================================================
27 # of the test
28 #=========================================================================
29 from salome.shaper import model
30 from ModelAPI import *
31 import math
32 #=========================================================================
33 # Creation of a part
34 #=========================================================================
35 model.begin()
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())
48 model.do()
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()))
61 model.do()
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() == '')
68
69 assert(model.checkPythonDump())