Salome HOME
Issue #2130: arc is done not as desired
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintEqual.py
index 959a0be1cbaf8736916862d5d1320a405c7f639b..5c518e99a8bc0505c0e41dda7bf60c1f234f2b08 100644 (file)
@@ -11,6 +11,8 @@
 from GeomDataAPI import *
 from ModelAPI import *
 import math
+from salome.shaper import model
+
 #=========================================================================
 # Initialization of the test
 #=========================================================================
@@ -28,12 +30,12 @@ def externalSketch(theDoc):
     dirx.setValue(1, 0, 0)
     norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
     norm.setValue(0, 0, 1)
-    # add circle
-    circle = aSketchFeature.addFeature("SketchCircle")
-    circleCenter = geomDataAPI_Point2D(circle.attribute("CircleCenter"))
-    circleRadius = circle.real("CircleRadius")
-    circleCenter.setValue(-50., 50.)
-    circleRadius.setValue(10.)
+    # add circle defined by 3 points
+    circle = aSketchFeature.addFeature("SketchMacroCircle")
+    circle.string("circle_type").setValue("circle_type_by_three_points")
+    geomDataAPI_Point2D(circle.attribute("first_point")).setValue(-40., 50.)
+    geomDataAPI_Point2D(circle.attribute("second_point")).setValue(-50., 60.)
+    geomDataAPI_Point2D(circle.attribute("third_point")).setValue(-60., 50.)
     # add line
     line = aSketchFeature.addFeature("SketchLine")
     lineStart = geomDataAPI_Point2D(line.attribute("StartPoint"))
@@ -48,16 +50,6 @@ def lineLength(theLine):
     aVecY = aLineStart.y() - aLineEnd.y()
     return math.hypot(aVecX, aVecY)
 
-def arcLength(theArc):
-    aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
-    aStart  = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint"))
-    aEnd    = geomDataAPI_Point2D(theArc.attribute("ArcEndPoint"))
-    # use the law of cosines to calculate angular length of arc
-    aRadius = math.hypot(aStart.x() - aCenter.x(), aStart.y() - aCenter.y())
-    aDist2 = (aEnd.x()-aStart.x())**2 + (aEnd.y()-aStart.y())**2
-    anAngle = math.acos(1. - aDist2 / (2. * aRadius**2))
-    return aRadius * anAngle
-
 
 #=========================================================================
 # Start of test
@@ -88,21 +80,23 @@ aSession.finishOperation()
 #=========================================================================
 aSession.startOperation()
 aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
 anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
 anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
 anArcEndPoint.setValue(50., 0.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
 # Circle
 aSession.startOperation()
 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
 anCircleCentr.setValue(-25., -25.)
 aCircleRadius.setValue(25.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
 #=========================================================================
 # A constraint to make equal radii of arc and circle
 #=========================================================================
@@ -123,21 +117,19 @@ anArcVecX = anArcStartPoint.x() - anArcCentr.x()
 anArcVecY = anArcStartPoint.y() - anArcCentr.y()
 anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2)
 assert (math.fabs(aCircRadius - anArcRadius) <= 1.e-10)
+assert (model.dof(aSketchFeature) == 7)
 #=========================================================================
 # A constraint to make equal radii of arc and external circle
 #=========================================================================
 aSession.startOperation()
-anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1"))
-assert(anExtCircRes)
-anExtCircShape = anExtCircRes.shape()
-assert(anExtCircShape)
 anExtCircle = aSketchFeature.addFeature("SketchCircle")
-anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("CircleCenter"))
-anExtCircleRadius = anExtCircle.real("CircleRadius")
+anExtCircleCenter = geomDataAPI_Point2D(anExtCircle.attribute("circle_center"))
+anExtCircleRadius = anExtCircle.real("circle_radius")
 anExtCircleCenter.setValue(-50., 50.)
 anExtCircleRadius.setValue(10.)
-anExtCircle.selection("External").setValue(anExtCircRes, anExtCircShape)
+anExtCircle.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchCircle_1_2")
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 7)
 aSession.startOperation()
 aConstraintEqRad2 = aSketchFeature.addFeature("SketchConstraintEqual")
 aRefObjectA = aConstraintEqRad2.refattr("ConstraintEntityA")
@@ -150,6 +142,7 @@ anArcVecX = anArcStartPoint.x() - anArcCentr.x()
 anArcVecY = anArcStartPoint.y() - anArcCentr.y()
 anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2)
 assert (math.fabs(anExtCircleRadius.value() - anArcRadius) <= 1.e-10)
+assert (model.dof(aSketchFeature) == 6)
 
 #=========================================================================
 # Creation of two different lines
@@ -170,6 +163,7 @@ aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint"))
 aLine2StartPoint.setValue(0., 0.)
 aLine2EndPoint.setValue(-1., 10.)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 14)
 #=========================================================================
 # A constraint to make equal lengths of lines
 #=========================================================================
@@ -188,22 +182,20 @@ aSession.finishOperation()
 aLine1Len = lineLength(aSketchLine1)
 aLine2Len = lineLength(aSketchLine2)
 assert (math.fabs(aLine1Len - aLine2Len) < 1.e-10)
+assert (model.dof(aSketchFeature) == 13)
 #=========================================================================
 # A constraint to make equal length of line with external line
 #=========================================================================
 aSession.startOperation()
-anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1"))
-assert(anExtLineRes)
-anExtLineShape = anExtLineRes.shape()
-assert(anExtLineShape)
 anExtLine = aSketchFeature.addFeature("SketchLine")
 anExtLineStart = geomDataAPI_Point2D(anExtLine.attribute("StartPoint"))
 anExtLineEnd = geomDataAPI_Point2D(anExtLine.attribute("EndPoint"))
 anExtLineStart.setValue(-40., 35.)
 anExtLineEnd.setValue(-60., 25.)
-anExtLine.selection("External").setValue(anExtLineRes, anExtLineShape)
+anExtLine.selection("External").selectSubShape("EDGE", "Sketch_1/Edge-SketchLine_1")
 anExtLineLen = lineLength(anExtLine)
 aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 13)
 aSession.startOperation()
 aConstraintEqLen2 = aSketchFeature.addFeature("SketchConstraintEqual")
 aRefObjectA = aConstraintEqLen2.refattr("ConstraintEntityA")
@@ -215,28 +207,16 @@ aLine1Len = lineLength(aSketchLine1)
 aLine2Len = lineLength(aSketchLine2)
 assert (math.fabs(aLine1Len - anExtLineLen) < 1.e-10)
 assert (math.fabs(aLine2Len - anExtLineLen) < 1.e-10)
-
+assert (model.dof(aSketchFeature) == 12)
 #=========================================================================
-# A constraint to make equal lengths of line and arc
+# Remove costraint to check the DOF
 #=========================================================================
-# Third Line
 aSession.startOperation()
-aSketchLine3 = aSketchFeature.addFeature("SketchLine")
-aLine3StartPoint = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint"))
-aLine3EndPoint = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint"))
-aLine3StartPoint.setValue(20., 15.)
-aLine3EndPoint.setValue(20., 25.)
+aDocument.removeFeature(aConstraintEqLen2)
 aSession.finishOperation()
-aSession.startOperation()
-anEqArcLineLen = aSketchFeature.addFeature("SketchConstraintEqual")
-aRefObjectA = anEqArcLineLen.refattr("ConstraintEntityA")
-aRefObjectB = anEqArcLineLen.refattr("ConstraintEntityB")
-aRefObjectA.setObject(aSketchArc.lastResult())
-aRefObjectB.setObject(aSketchLine3.lastResult())
-aSession.finishOperation()
-aLine3Len = lineLength(aSketchLine3)
-anArcLen = arcLength(aSketchArc)
-assert (math.fabs(aLine3Len - anArcLen) < 1.e-7)
+assert (model.dof(aSketchFeature) == 13)
 #=========================================================================
 # End of test
 #=========================================================================
+
+assert(model.checkPythonDump())