Salome HOME
Update unit-tests for SketchPlugin (part II).
authorazv <azv@opencascade.com>
Mon, 16 May 2016 11:38:35 +0000 (14:38 +0300)
committerazv <azv@opencascade.com>
Mon, 16 May 2016 11:38:35 +0000 (14:38 +0300)
src/SketchPlugin/Test/TestConstraintTangent.py
src/SketchPlugin/Test/TestSketchArcCircle.py

index 5329c5de22416a42ca456a9d1ba6b54cc06d86a6..48ed166d71ea7483baa738cab02ab2e3affde54e 100644 (file)
@@ -18,6 +18,24 @@ import math
 
 __updated__ = "2015-03-17"
 
+def distancePointLine(point, line):
+    """
+    subroutine to calculate distance between point and line
+    result of calculated distance is has 10**-5 precision
+    """
+    aStartPoint = geomDataAPI_Point2D(line.attribute("StartPoint"))
+    aEndPoint = geomDataAPI_Point2D(line.attribute("EndPoint"))
+    # orthogonal direction
+    aDirX = -(aEndPoint.y() - aStartPoint.y())
+    aDirY = (aEndPoint.x() - aStartPoint.x())
+    aLen = math.sqrt(aDirX**2 + aDirY**2)
+    aDirX = aDirX / aLen
+    aDirY = aDirY / aLen
+    aVecX = point.x() - aStartPoint.x()
+    aVecY = point.y() - aStartPoint.y()
+    return round(math.fabs(aVecX * aDirX + aVecY * aDirY), 5)
+
+
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
 #=========================================================================
@@ -253,6 +271,37 @@ anArc3VecY = anArc3StartPoint.y() - anArc3Center.y()
 aLen = aLen * math.sqrt(anArc3VecX**2 + anArc3VecY**2)
 aCross = anArc1VecX * anArc3VecY - anArc1VecY * anArc3VecX
 assert math.fabs(aCross) <= 2.e-6 * aLen, "Observed cross product: {0}".format(aCross)
+
+#=========================================================================
+# TEST 5. Creating of tangency between line and circle
+#=========================================================================
+aSession.startOperation()
+aLine = aSketchFeature.addFeature("SketchLine")
+aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
+aLineStart.setValue(100., 100.)
+aLineEnd.setValue(200., 200.)
+aCircle = aSketchFeature.addFeature("SketchCircle")
+aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("CircleCenter"))
+aCircleRadius = aCircle.real("CircleRadius")
+aCircleCenter.setValue(150., 100.)
+aCircleRadius.setValue(20.)
+aSession.finishOperation()
+
+aSession.startOperation()
+aTangency = aSketchFeature.addFeature("SketchConstraintTangent")
+aRefObjectA = aTangency.refattr("ConstraintEntityA")
+aRefObjectB = aTangency.refattr("ConstraintEntityB")
+anObjectA = modelAPI_ResultConstruction(aLine.lastResult())
+anObjectB = modelAPI_ResultConstruction(aCircle.lastResult())
+assert (anObjectA is not None)
+assert (anObjectB is not None)
+aRefObjectA.setObject(anObjectA)
+aRefObjectB.setObject(anObjectB)
+aTangency.execute()
+aSession.finishOperation()
+
+assert(math.fabs(distancePointLine(aCircleCenter, aLine) - aCircleRadius.value()) < 1.e-10)
 #=========================================================================
 # End of test
 #=========================================================================
index 83169611b8cdd4eea39f2b68b9d6a035057a0c4d..e15964a1be155c845b494128d02da898d26f6157 100644 (file)
@@ -212,6 +212,8 @@ anArcEndPoint = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcEndPoint"))
 aTangent = aSketchArcTangent.refattr("ArcTangentPoint")
 aTangent.setAttr(aLineEnd)
 anArcEndPoint.setValue(51., 1.)
+aSession.finishOperation()
+aSession.startOperation()
 anArcEndPoint.setValue(100., 25.)
 aSession.finishOperation()
 anArcCenter = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcCenter"))
@@ -226,6 +228,8 @@ anArcEndPoint2 = geomDataAPI_Point2D(aSketchArcTangent2.attribute("ArcEndPoint")
 aTangent = aSketchArcTangent2.refattr("ArcTangentPoint")
 aTangent.setAttr(anArcEndPoint)
 anArcEndPoint2.setValue(anArcEndPoint.x() + 1, anArcEndPoint.y() + 1)
+aSession.finishOperation()
+aSession.startOperation()
 anArcEndPoint2.setValue(50., 50.)
 aSession.finishOperation()
 #=========================================================================