Salome HOME
Merge remote-tracking branch 'remotes/origin/master' into Dev_2.8.0
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintHorizontalValidator.py
1 ## Copyright (C) 2017  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
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 """
22     TestConstraintHorizontalValidator.py
23     It tests validation of horizontal and vertical segments in H and V constraints to avoid
24     selection segments that already have one of these constraint"
25 """
26
27 #=========================================================================
28 # of the test
29 #=========================================================================
30 from salome.shaper import model
31 from ModelAPI import *
32 import math
33 #=========================================================================
34 # Creation of a part
35 #=========================================================================
36 model.begin()
37 partSet = model.moduleDocument()
38 Part_1 = model.addPart(partSet)
39 Part_1_doc = Part_1.document()
40 #=========================================================================
41 # Creation of a sketch
42 #=========================================================================
43 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
44 SketchLine_1 = Sketch_1.addLine(20, 20, 40, 80)
45 SketchLine_2 = Sketch_1.addLine(40, 80, 60, 40)
46 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
47 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
48 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
49 model.do()
50 #=========================================================================
51 # Checking that sketch and constraints become invalid when to one line
52 # two horizontal/vertical constraints are applied in any combination
53 #=========================================================================
54 aFactory = ModelAPI_Session.get().validators()
55 assert(aFactory.validate(Sketch_1.feature()))
56 assert(Sketch_1.feature().error() != '')
57 #=========================================================================
58 # Remove duplicated Vertical constraints
59 #=========================================================================
60 Part_1_doc.removeFeature(SketchConstraintVertical_1.feature())
61 assert(aFactory.validate(Sketch_1.feature()))
62 model.do()
63 #=========================================================================
64 # Checking that after excess constraints are removed or undone,
65 # sketch becomes valid.
66 #=========================================================================
67 assert(aFactory.validate(Sketch_1.feature()))
68 assert(Sketch_1.feature().error() == '')
69
70 assert(model.checkPythonDump())