Salome HOME
Test cases for issues #1673, #1966 and #1967
[modules/shaper.git] / src / SketchPlugin / Test / TestSketchArcCircle.py
index e15964a1be155c845b494128d02da898d26f6157..677de24e523be038dd8b17d27c8626809829dc00 100644 (file)
@@ -53,6 +53,19 @@ def distancePointPoint(thePointA, thePointB):
     ydiff = math.pow((thePointA.y() - thePointB.y()), 2)
     return round(math.sqrt(xdiff + ydiff), 5)
 
+def dot(thePoint11, thePoint12, thePoint21, thePoint22):
+    """
+    subroutine to calculate dit product between lines given by their points
+    """
+    aDirX1 = thePoint12.x() - thePoint11.x()
+    aDirY1 = thePoint12.y() - thePoint11.y()
+    aLen1 = math.hypot(aDirX1, aDirY1)
+    aDirX2 = thePoint22.x() - thePoint21.x()
+    aDirY2 = thePoint22.y() - thePoint21.y()
+    aLen2 = math.hypot(aDirX2, aDirY2)
+    aDot = aDirX1 * aDirX2 + aDirY1 * aDirY2
+    return aDot / aLen1 / aLen2
+
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -83,19 +96,13 @@ assert (len(aSketchReflist.list()) == 0)
 aSketchArc = aSketchFeature.addFeature("SketchArc")
 assert (aSketchArc.getKind() == "SketchArc")
 anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
-assert (anArcCentr.x() == 0)
-assert (anArcCentr.y() == 0)
 assert (not anArcCentr.isInitialized())
 anArcCentr.setValue(10., 10.)
 anArcStartPoint = geomDataAPI_Point2D(
     aSketchArc.attribute("ArcStartPoint"))
-assert (anArcStartPoint.x() == 0)
-assert (anArcStartPoint.y() == 0)
 assert (not anArcStartPoint.isInitialized())
 anArcStartPoint.setValue(0., 50.)
 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
-assert (anArcEndPoint.x() == 0)
-assert (anArcEndPoint.y() == 0)
 assert (not anArcEndPoint.isInitialized())
 anArcEndPoint.setValue(50., 0.)
 aSession.finishOperation()
@@ -164,14 +171,11 @@ assert (len(aSketchReflist.list()) == 1)
 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
 assert (aSketchCircle.getKind() == "SketchCircle")
 anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-assert (anCircleCentr.x() == 0)
-assert (anCircleCentr.y() == 0)
 assert (not anCircleCentr.isInitialized())
 aCircleRadius = aSketchCircle.real("CircleRadius")
 assert (type(aCircleRadius) == ModelAPI_AttributeDouble)
 # ModelAPI_AttributeDouble.typeId() is checked in ModelAPI_TestConstants
 assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.typeId())
-assert (aCircleRadius.value() == 0)
 anCircleCentr.setValue(-25., -25)
 aCircleRadius.setValue(25.)
 assert (anCircleCentr.x() == -25)
@@ -206,6 +210,12 @@ aLineStart.setValue(0., 0.)
 aLineEnd.setValue(50., 0.)
 aSession.finishOperation()
 aSession.startOperation()
+aFixed = aSketchFeature.addFeature("SketchConstraintRigid")
+aRefObjectA = aFixed.refattr("ConstraintEntityA")
+aRefObjectA.setObject(modelAPI_ResultConstruction(aSketchLine.lastResult()))
+aFixed.execute()
+aSession.finishOperation()
+aSession.startOperation()
 aSketchArcTangent = aSketchFeature.addFeature("SketchArc")
 aSketchArcTangent.string("ArcType").setValue("Tangent")
 anArcEndPoint = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcEndPoint"))
@@ -217,7 +227,8 @@ aSession.startOperation()
 anArcEndPoint.setValue(100., 25.)
 aSession.finishOperation()
 anArcCenter = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcCenter"))
-assert(anArcCenter.x() == 50.)
+aDot = dot(anArcCenter, aLineEnd, aLineStart, aLineEnd)
+assert math.fabs(aDot) <= 2.e-4, "Observed dot product: {0}".format(aDot)
 #=========================================================================
 # Create an arc, tangent to the previous arc
 #=========================================================================
@@ -227,11 +238,11 @@ aSketchArcTangent2.string("ArcType").setValue("Tangent")
 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.)
+anArcEndPoint2.setValue(50., 150.)
 aSession.finishOperation()
 #=========================================================================
 # End of test
 #=========================================================================
+
+from salome.shaper import model
+assert(model.checkPythonDump())