Salome HOME
caf2f1a4932e59f25011d7280a057ea938ccf87f
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintHorizontalValidator.py
1 """
2     TestConstraintHorizontalValidator.py
3     It tests validation of horizontal and vertical segments in H and V constraints to avoid
4     selection segments that already have one of these constraint"
5 """
6
7 #=========================================================================
8 # of the test
9 #=========================================================================
10 from salome.shaper import model
11 from ModelAPI import *
12 import math
13 #=========================================================================
14 # Creation of a part
15 #=========================================================================
16 model.begin()
17 partSet = model.moduleDocument()
18 Part_1 = model.addPart(partSet)
19 Part_1_doc = Part_1.document()
20 #=========================================================================
21 # Creation of a sketch
22 #=========================================================================
23 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
24 SketchLine_1 = Sketch_1.addLine(20, 20, 40, 80)
25 SketchLine_2 = Sketch_1.addLine(40, 80, 60, 40)
26 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
27 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
28 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
29 model.do()
30 #=========================================================================
31 # Checking that sketch and constraints become invalid when to one line
32 # two horizontal/vertical constraints are applied in any combination
33 #=========================================================================
34 aFactory = ModelAPI_Session.get().validators()
35 assert(aFactory.validate(Sketch_1.feature()))
36 assert(Sketch_1.feature().error() != '')
37 #=========================================================================
38 # Remove duplicated Vertical constraints
39 #=========================================================================
40 Part_1_doc.removeFeature(SketchConstraintVertical_1.feature())
41 assert(aFactory.validate(Sketch_1.feature()))
42 model.do()
43 #=========================================================================
44 # Checking that after excess constraints are removed or undone,
45 # sketch becomes valid.
46 #=========================================================================
47 assert(aFactory.validate(Sketch_1.feature()))
48 assert(Sketch_1.feature().error() == '')
49
50 assert(model.checkPythonDump())