]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Unit test for filter horizontal and vertical segments in H and V constraints
authornds <nds@opencascade.com>
Wed, 26 Apr 2017 11:17:58 +0000 (14:17 +0300)
committernds <nds@opencascade.com>
Wed, 26 Apr 2017 11:17:58 +0000 (14:17 +0300)
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/TestConstraintHorizontalValidator.py [new file with mode: 0644]

index 1d18e369d568ec9870959279337c8ca678f3457c..3f8723de769fc39c98c174d936917702ccd3b06a 100644 (file)
@@ -142,6 +142,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                TestConstraintRadius.py
                TestConstraintFixed.py
                TestConstraintHorizontal.py
+               TestConstraintHorizontalValidator.py
                TestConstraintVertical.py
                TestConstraintEqual.py
                TestConstraintTangent.py
diff --git a/src/SketchPlugin/Test/TestConstraintHorizontalValidator.py b/src/SketchPlugin/Test/TestConstraintHorizontalValidator.py
new file mode 100644 (file)
index 0000000..ff225fb
--- /dev/null
@@ -0,0 +1,57 @@
+"""
+    TestConstraintHorizontalValidator.py
+    It tests validation of horizontal and vertical segments in H and V constraints to avoid
+    selection segments that already have one of these constraint"
+"""
+
+#=========================================================================
+# of the test
+#=========================================================================
+from salome.shaper import model
+from ModelAPI import *
+import math
+#=========================================================================
+# Creation of a part
+#=========================================================================
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOZ"))
+SketchLine_1 = Sketch_1.addLine(20, 20, 40, 80)
+SketchLine_1.setName("SketchLine_1")
+SketchLine_1.result().setName("SketchLine_1")
+SketchLine_2 = Sketch_1.addLine(40, 80, 60, 40)
+SketchLine_2.setName("SketchLine_2")
+SketchLine_2.result().setName("SketchLine_2")
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_1.result())
+SketchConstraintHorizontal_1.setName("SketchConstraintHorizontal_1")
+SketchConstraintVertical_1.setName("SketchConstraintVertical_1")
+model.do()
+#=========================================================================
+# Checking that sketch and constraints become invalid when to one line
+# two horizontal/vertical constraints are applied in any combination
+#=========================================================================
+aFactory = ModelAPI_Session.get().validators()
+assert(aFactory.validate(Sketch_1.feature()))
+assert(Sketch_1.feature().error() == "Sketch objects are not defined")
+#=========================================================================
+# Remove duplicated Vertical constraints
+#=========================================================================
+Part_1_doc.removeFeature(SketchConstraintVertical_1.feature())
+assert(aFactory.validate(Sketch_1.feature()))
+model.do()
+#=========================================================================
+# Checking that after excess constraints are removed or undone,
+# sketch becomes valid.
+#=========================================================================
+assert(aFactory.validate(Sketch_1.feature()))
+assert(Sketch_1.feature().error() == '')
+
+#assert(model.checkPythonDump())