Salome HOME
Unit test for filter horizontal and vertical segments in H and V constraints
[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_1.setName("SketchLine_1")
26 SketchLine_1.result().setName("SketchLine_1")
27 SketchLine_2 = Sketch_1.addLine(40, 80, 60, 40)
28 SketchLine_2.setName("SketchLine_2")
29 SketchLine_2.result().setName("SketchLine_2")
30 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
31 SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
32 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
33 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
34 SketchConstraintHorizontal_1.setName("SketchConstraintHorizontal_1")
35 SketchConstraintVertical_1.setName("SketchConstraintVertical_1")
36 model.do()
37 #=========================================================================
38 # Checking that sketch and constraints become invalid when to one line
39 # two horizontal/vertical constraints are applied in any combination
40 #=========================================================================
41 aFactory = ModelAPI_Session.get().validators()
42 assert(aFactory.validate(Sketch_1.feature()))
43 assert(Sketch_1.feature().error() == "Sketch objects are not defined")
44 #=========================================================================
45 # Remove duplicated Vertical constraints
46 #=========================================================================
47 Part_1_doc.removeFeature(SketchConstraintVertical_1.feature())
48 assert(aFactory.validate(Sketch_1.feature()))
49 model.do()
50 #=========================================================================
51 # Checking that after excess constraints are removed or undone,
52 # sketch becomes valid.
53 #=========================================================================
54 assert(aFactory.validate(Sketch_1.feature()))
55 assert(Sketch_1.feature().error() == '')
56
57 #assert(model.checkPythonDump())