Salome HOME
Issue #2130: arc is done not as desired
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintDistance.py
index 9f64238c7c9c104e67fff37efd2021d9a345db19..a5c80ae7c0e212f535b62eb2ab0c1881077b1a24 100644 (file)
@@ -22,6 +22,8 @@
 from GeomDataAPI import *
 from ModelAPI import *
 import math
+from salome.shaper import model
+
 #=========================================================================
 # Initialization of the test
 #=========================================================================
@@ -29,15 +31,6 @@ import math
 __updated__ = "2014-10-28"
 
 
-def distancePointPoint(pointA, pointB):
-    """
-    subroutine to calculate distance between two points
-    result of calculated distance is has 10**-5 precision
-    """
-    xdiff = math.pow((pointA.x() - pointB.x()), 2)
-    ydiff = math.pow((pointA.y() - pointB.y()), 2)
-    return round(math.sqrt(xdiff + ydiff), 5)
-
 def distancePointLine(point, line):
     """
     subroutine to calculate distance between point and line
@@ -76,7 +69,7 @@ aSession.finishOperation()
 aSession.startOperation()
 aSketchPoint = aSketchFeature.addFeature("SketchPoint")
 aSketchPointCoords = geomDataAPI_Point2D(
-    aSketchPoint.attribute("PointCoordindates"))
+    aSketchPoint.attribute("PointCoordinates"))
 aSketchPointCoords.setValue(50., 50.)
 aSketchLine = aSketchFeature.addFeature("SketchLine")
 aLineAStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
@@ -84,11 +77,12 @@ aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
 aLineAStartPoint.setValue(0., 25.)
 aLineAEndPoint.setValue(100., 25.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 6)
 #=========================================================================
 # Make a constraint to keep the distance
 #=========================================================================
 PT_PT_DIST = 25.
-aDist = distancePointPoint(aSketchPointCoords, aLineAStartPoint);
+aDist = model.distancePointPoint(aSketchPointCoords, aLineAStartPoint);
 assert (aDist != PT_PT_DIST)
 aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
@@ -104,20 +98,26 @@ assert (aLineResult is not None)
 aConstraint.execute()
 refattrA.setAttr(aSketchPointCoords)
 refattrB.setAttr(aLineAStartPoint)
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
+# set flyout point then abort operation, after that check the Distance is correct
+aSession.startOperation()
 aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
 aFlyoutPoint.setValue(50.0, 100.0)
-aSession.finishOperation()
+aSession.abortOperation()
 assert (refattrA.isInitialized())
 assert (refattrB.isInitialized())
 assert (aDistance.isInitialized())
 assert math.fabs(aDistance.value() - aDist) < 1.e-4, "Distance values are different: {0} != {1}".format(aDistance.value(), aDist)
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Change distance value
 #=========================================================================
 aSession.startOperation()
 aDistance.setValue(PT_PT_DIST)
 aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Move line, check that distance is constant
 #=========================================================================
@@ -125,7 +125,8 @@ aSession.startOperation()
 aLineAStartPoint.setValue(0., 40.)
 aLineAEndPoint.setValue(100., 40.)
 aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) < 1.e-10)
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Remove constraint, check the points are unconstrained now
 #=========================================================================
@@ -135,7 +136,8 @@ aSession.finishOperation()
 aSession.startOperation()
 aSketchPointCoords.setValue(0., 0.)
 aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) > 1.e-10)
+assert (math.fabs(model.distancePointPoint(aSketchPointCoords, aLineAStartPoint) - PT_PT_DIST) > 1.e-10)
+assert (model.dof(aSketchFeature) == 6)
 
 #=========================================================================
 # Add distance between point and line
@@ -154,13 +156,18 @@ aLineResult = aSketchLine.firstResult()
 assert (aLineResult is not None)
 refattrA.setObject(aLineResult)
 refattrB.setAttr(aSketchPointCoords)
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
+# set flyout point then abort operation, after that check the Distance is correct
+aSession.startOperation()
 aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt"))
 aFlyoutPoint.setValue(50.0, 100.0)
-aSession.finishOperation()
+aSession.abortOperation()
 assert (refattrA.isInitialized())
 assert (refattrB.isInitialized())
 assert (aDistance.isInitialized())
 assert math.fabs(aDistance.value() - aDist) < 1.e-4, "Distance values are different: {0} != {1}".format(aDistance.value(), aDist)
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Change distance value
 #=========================================================================
@@ -168,6 +175,7 @@ aSession.startOperation()
 aDistance.setValue(PT_LINE_DIST)
 aSession.finishOperation()
 assert (math.fabs(distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10)
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Set distance between line boundaries
 #=========================================================================
@@ -175,10 +183,10 @@ aSession.startOperation()
 refattrA.setAttr(aLineAStartPoint)
 refattrB.setAttr(aLineAEndPoint)
 aSession.finishOperation()
-assert (math.fabs(distancePointPoint(aLineAStartPoint, aLineAEndPoint) - PT_LINE_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointPoint(aLineAStartPoint, aLineAEndPoint) - PT_LINE_DIST) < 1.e-10)
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # End of test
 #=========================================================================
 
-import model
 assert(model.checkPythonDump())