Salome HOME
Unit test for changing arc type during creation.
authorazv <azv@opencascade.com>
Thu, 6 Apr 2017 14:36:56 +0000 (17:36 +0300)
committerazv <azv@opencascade.com>
Thu, 6 Apr 2017 14:37:18 +0000 (17:37 +0300)
Obsolete test case for arc has been removed.

src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/TestCreateArc.py [deleted file]
src/SketchPlugin/Test/TestCreateArcChangeType.py [new file with mode: 0644]

index 45020553ae7e6d26578f2c298cf6e6d73d677ea4..d9aa0c5dadc288890e78120859c019649ed80c3c 100644 (file)
@@ -129,7 +129,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py
                TestCreateArcByCenterStartEnd.py
                TestCreateArcByThreePoints.py
                TestCreateArcByTangentEdge.py
-               TestCreateArcChangeType.py
+               TestCreateArcChangeType.py
                TestCreateCircleByCenterAndPassed.py
                TestCreateCircleByThreePoints.py
                TestCreateCircleChangeType.py
diff --git a/src/SketchPlugin/Test/TestCreateArc.py b/src/SketchPlugin/Test/TestCreateArc.py
deleted file mode 100644 (file)
index 936981d..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-"""
-    TestCreateArc.py
-
-    static const std::string MY_SKETCH_ARC_ID("SketchArc");
-    static const std::string MY_CENTER_ID = "ArcCenter";
-    static const std::string MY_START_ID = "ArcStartPoint";
-    static const std::string MY_END_ID = "ArcEndPoint";
-    data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::typeId());
-    data()->addAttribute(SketchPlugin_Arc::START_ID(),  GeomDataAPI_Point2D::typeId());
-    data()->addAttribute(SketchPlugin_Arc::END_ID(),    GeomDataAPI_Point2D::typeId());
-"""
-
-#=========================================================================
-# Initialization of the test
-#=========================================================================
-from GeomDataAPI import *
-from ModelAPI import *
-import math
-
-__updated__ = "2014-10-28"
-
-
-#=========================================================================
-# Auxiliary functions
-#=========================================================================
-
-def angle(theCenter, theFirst, theLast):
-    """
-    subroutine to calculate angle given by 3 points
-    """
-    aDirX1 = theFirst.x() - theCenter.x()
-    aDirY1 = theFirst.y() - theCenter.y()
-    aLen1 = math.hypot(aDirX1, aDirY1)
-    aDirX2 = theLast.x() - theCenter.x()
-    aDirY2 = theLast.y() - theCenter.y()
-    aLen2 = math.hypot(aDirX2, aDirY2)
-    aDot = aDirX1 * aDirX2 + aDirY1 * aDirY2
-    anAngle = math.acos(aDot / aLen1 / aLen2)
-    return round(anAngle * 180. / math.pi, 6)
-
-def distancePointPoint(thePointA, thePointB):
-    """
-    subroutine to calculate distance between two points
-    result of calculated distance is has 10**-5 precision
-    """
-    xdiff = math.pow((thePointA.x() - thePointB.x()), 2)
-    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()
-#=========================================================================
-# Creation of a sketch
-#=========================================================================
-aSession.startOperation()
-#aSketchFeature = aDocument.addFeature("Sketch")
-aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
-origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
-origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
-dirx.setValue(1, 0, 0)
-norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
-norm.setValue(0, 0, 1)
-aSession.finishOperation()
-#=========================================================================
-# Creation of an arc
-# 1. Test SketchPlugin_Arc attributes
-# 2.
-#=========================================================================
-aSession.startOperation()
-aSketchReflist = aSketchFeature.reflist("Features")
-assert (not aSketchReflist.isInitialized())
-assert (aSketchReflist.size() == 0)
-assert (len(aSketchReflist.list()) == 0)
-aSketchArc = aSketchFeature.addFeature("SketchArc")
-assert (aSketchArc.getKind() == "SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
-assert (not anArcCentr.isInitialized())
-anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(
-    aSketchArc.attribute("ArcStartPoint"))
-assert (not anArcStartPoint.isInitialized())
-anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
-assert (not anArcEndPoint.isInitialized())
-anArcEndPoint.setValue(50., 0.)
-aSession.finishOperation()
-# check that values have been changed
-aSketchReflist = aSketchFeature.reflist("Features")
-assert (aSketchReflist.size() == 1)
-assert (len(aSketchReflist.list()) == 1)
-assert (anArcCentr.x() == 10.0)
-assert (anArcCentr.y() == 10.0)
-assert (anArcStartPoint.x() == 0.0)
-assert (anArcStartPoint.y() == 50.0)
-assert (anArcEndPoint.x() == 50.0)
-assert (anArcEndPoint.y() == 0.0)
-#=========================================================================
-# Edit the arc:
-# 1. Move whole arc
-# 2. Change the start point
-# 3. Change the radius of arc
-# 4. Change arc's angle
-#=========================================================================
-aSession.startOperation()
-deltaX, deltaY = 5., 10.
-anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY)
-aSession.finishOperation()
-assert (anArcCentr.x() == 15)
-assert (anArcCentr.y() == 20)
-assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - distancePointPoint(anArcCentr, anArcEndPoint)) < 1.e-10)
-# Change the start point
-aSession.startOperation()
-anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y())
-aSession.finishOperation()
-assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - distancePointPoint(anArcCentr, anArcEndPoint)) < 1.e-10)
-# Change radius
-RADIUS = 50
-aSession.startOperation()
-anArcRadius = aSketchArc.real("ArcRadius")
-anArcRadius.setValue(RADIUS)
-aSession.finishOperation()
-assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10)
-assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10)
-# Change angle
-ANGLE = 120
-aSession.startOperation()
-anArcAngle = aSketchArc.real("ArcAngle")
-anArcAngle.setValue(ANGLE)
-aSession.finishOperation()
-assert (math.fabs(angle(anArcCentr, anArcStartPoint, anArcEndPoint) - ANGLE) < 1.e-7)
-#=========================================================================
-# Check results of the Arc
-#=========================================================================
-aResult = aSketchArc.firstResult()
-aResultConstruction = modelAPI_ResultConstruction(aResult)
-aShape = aResultConstruction.shape()
-assert (aShape is not None)
-assert (not aShape.isNull())
-#=========================================================================
-# Create an arc, tangent to the line
-#=========================================================================
-aSession.startOperation()
-aSketchLine = aSketchFeature.addFeature("SketchLine")
-aLineStart = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
-aLineEnd = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
-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"))
-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"))
-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
-#=========================================================================
-aSession.startOperation()
-aSketchArcTangent2 = aSketchFeature.addFeature("SketchArc")
-aSketchArcTangent2.string("ArcType").setValue("Tangent")
-anArcEndPoint2 = geomDataAPI_Point2D(aSketchArcTangent2.attribute("ArcEndPoint"))
-aTangent = aSketchArcTangent2.refattr("ArcTangentPoint")
-aTangent.setAttr(anArcEndPoint)
-anArcEndPoint2.setValue(50., 150.)
-aSession.finishOperation()
-#=========================================================================
-# End of test
-#=========================================================================
-
-from salome.shaper import model
-assert(model.checkPythonDump())
diff --git a/src/SketchPlugin/Test/TestCreateArcChangeType.py b/src/SketchPlugin/Test/TestCreateArcChangeType.py
new file mode 100644 (file)
index 0000000..92a876c
--- /dev/null
@@ -0,0 +1,230 @@
+"""
+    TestCreateArcChangeType.py
+
+    Test attributes reset when changing creation method of an arc on-the-fly
+"""
+
+#=========================================================================
+# Initialization of the test
+#=========================================================================
+from GeomDataAPI import *
+from GeomAPI import *
+from ModelAPI import *
+from SketchAPI import SketchAPI_Sketch
+from salome.shaper import model
+import math
+
+__updated__ = "2017-04-06"
+
+
+##=========================================================================
+## Auxiliary functions
+##=========================================================================
+
+def assertNotInitializedByCenterAndPassed(theMacroArc):
+    # check points
+    aCenterPoint = geomDataAPI_Point2D(theMacroArc.attribute("center_point"))
+    aStartPoint = geomDataAPI_Point2D(theMacroArc.attribute("start_point_1"))
+    aEndPoint = geomDataAPI_Point2D(theMacroArc.attribute("end_point_1"))
+    assert (not aCenterPoint.isInitialized())
+    assert (not aStartPoint.isInitialized())
+    assert (not aEndPoint.isInitialized())
+    # check references
+    aCenterPointRef = theMacroArc.refattr("center_point_ref")
+    aStartPointRef = theMacroArc.refattr("start_point_ref")
+    aEndPointRef = theMacroArc.refattr("end_point_ref")
+    assert (not aCenterPointRef.isInitialized())
+    assert (not aStartPointRef.isInitialized())
+    assert (not aEndPointRef.isInitialized())
+
+def assertNotInitializedByThreePoints(theMacroArc):
+    # check points
+    aStartPoint = geomDataAPI_Point2D(theMacroArc.attribute("start_point_2"))
+    aEndPoint = geomDataAPI_Point2D(theMacroArc.attribute("end_point_2"))
+    aPassedPoint = geomDataAPI_Point2D(theMacroArc.attribute("passed_point"))
+    assert (not aStartPoint.isInitialized())
+    assert (not aEndPoint.isInitialized())
+    assert (not aPassedPoint.isInitialized())
+    # check references
+    aStartPointRef = theMacroArc.refattr("start_point_ref")
+    aEndPointRef = theMacroArc.refattr("end_point_ref")
+    aPassedPointRef = theMacroArc.refattr("passed_point_ref")
+    assert (not aStartPointRef.isInitialized())
+    assert (not aEndPointRef.isInitialized())
+    assert (not aPassedPointRef.isInitialized())
+
+def assertNotInitializedByTangentEdge(theMacroArc):
+    # check end point
+    aEndPoint = geomDataAPI_Point2D(theMacroArc.attribute("end_point_3"))
+    assert (not aEndPoint.isInitialized())
+    # check references
+    aTangentPointRef = theMacroArc.refattr("passed_point_ref")
+    aEndPointRef = theMacroArc.refattr("end_point_ref")
+    assert (not aTangentPointRef.isInitialized())
+    assert (not aEndPointRef.isInitialized())
+
+def verifyLastArc(theSketch, theCenter, theStart, theEnd):
+    """
+    subroutine to verify position of last arc in the sketch
+    """
+    aLastArc = model.lastSubFeature(theSketch, "SketchArc")
+    aCenterPnt = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
+    aStartPnt = geomDataAPI_Point2D(aLastArc.attribute("start_point"))
+    aEndPnt = geomDataAPI_Point2D(aLastArc.attribute("end_point"))
+    if len(theCenter):
+        verifyPointCoordinates(aCenterPnt, theCenter[0], theCenter[1])
+    if len(theStart):
+        verifyPointCoordinates(aStartPnt, theStart[0], theStart[1])
+    if len(theEnd):
+        verifyPointCoordinates(aEndPnt, theEnd[0], theEnd[1])
+    model.assertSketchArc(aLastArc)
+
+def verifyPointCoordinates(thePoint, theX, theY):
+    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.id(), thePoint.x(), thePoint.y(), theX, theY)
+
+
+#=========================================================================
+# Start of test
+#=========================================================================
+
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
+#=========================================================================
+# Creation of a sketch
+#=========================================================================
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
+origin.setValue(0, 0, 0)
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
+dirx.setValue(1, 0, 0)
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
+norm.setValue(0, 0, 1)
+aSession.finishOperation()
+aSketch = SketchAPI_Sketch(aSketchFeature)
+
+#=========================================================================
+# Creation of auxiliary features
+#=========================================================================
+aSession.startOperation()
+aSession.startOperation()
+aLine = aSketchFeature.addFeature("SketchLine")
+aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+aLineStart.setValue(10., 0.)
+aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
+aLineEnd.setValue(10., 50.)
+aSession.finishOperation()
+
+aSession.startOperation()
+#=========================================================================
+# Test 1. Create an arc as a macro-feature and check all attributes are not initialized
+#=========================================================================
+anArc = aSketchFeature.addFeature("SketchMacroArc")
+assert (anArc.getKind() == "SketchMacroArc")
+aCenterPoint = geomDataAPI_Point2D(anArc.attribute("center_point"))
+aPassedPoint = geomDataAPI_Point2D(anArc.attribute("passed_point"))
+aStartPoint1 = geomDataAPI_Point2D(anArc.attribute("start_point_1"))
+aStartPoint2 = geomDataAPI_Point2D(anArc.attribute("start_point_2"))
+aEndPoint1 = geomDataAPI_Point2D(anArc.attribute("end_point_1"))
+aEndPoint2 = geomDataAPI_Point2D(anArc.attribute("end_point_2"))
+aEndPoint3 = geomDataAPI_Point2D(anArc.attribute("end_point_3"))
+aTangentPoint = anArc.refattr("tangent_point")
+aCenterPointRef = anArc.refattr("center_point_ref")
+aStartPointRef = anArc.refattr("start_point_ref")
+aEndPointRef = anArc.refattr("end_point_ref")
+aPassedPointRef = anArc.refattr("passed_point_ref")
+assertNotInitializedByCenterAndPassed(anArc)
+assertNotInitializedByThreePoints(anArc)
+assertNotInitializedByTangentEdge(anArc)
+anArcType = anArc.string("arc_type")
+assert (not anArcType.isInitialized())
+#=========================================================================
+# Test 2. Initialize center of arc, check the three points are not initialized
+#=========================================================================
+anArcType.setValue("by_center_and_points")
+aCenterPoint.setValue(-25., -25.)
+assertNotInitializedByThreePoints(anArc)
+assertNotInitializedByTangentEdge(anArc)
+#=========================================================================
+# Test 3. Change type of circle and check the attributes related to center and passed point became uninitilized
+#=========================================================================
+anArcType.setValue("by_three_points")
+assertNotInitializedByCenterAndPassed(anArc)
+assertNotInitializedByTangentEdge(anArc)
+#=========================================================================
+# Test 4. Initialize two points and change type, they should became uninitialized
+#=========================================================================
+aStartPoint2.setValue(-10., 10.)
+aEndPoint2.setValue(10., 10.)
+anArcType.setValue("by_center_and_points")
+assertNotInitializedByThreePoints(anArc)
+assertNotInitializedByTangentEdge(anArc)
+#=========================================================================
+# Test 5. Initialize center and passed points then change the type
+#=========================================================================
+aCenterPoint.setValue(-25., -25.)
+aStartPoint1.setValue(0., 0.)
+aEndPoint1.setValue(-50., 0.)
+anArcType.setValue("by_three_points")
+assertNotInitializedByCenterAndPassed(anArc)
+assertNotInitializedByTangentEdge(anArc)
+#=========================================================================
+# Test 6. Initialize all three points then change the type twice
+#=========================================================================
+aStartPoint2.setValue(-10., 10.)
+aEndPoint2.setValue(10., 10.)
+aPassedPoint.setValue(0., 0.)
+anArcType.setValue("by_tangent_edge")
+assertNotInitializedByThreePoints(anArc)
+anArcType.setValue("by_center_and_points")
+assertNotInitializedByTangentEdge(anArc)
+anArcType.setValue("by_three_points")
+assertNotInitializedByCenterAndPassed(anArc)
+#=========================================================================
+# Test 7. Initialize first and third points then change the type
+#=========================================================================
+aStartPointRef.setAttr(aLineStart)
+aStartPoint2.setValue(aLineStart.pnt())
+aPassedPointRef.setObject(aLine.lastResult())
+aPassedPoint.setValue(aLineEnd.pnt())
+anArcType.setValue("by_tangent_edge")
+assertNotInitializedByCenterAndPassed(anArc)
+assertNotInitializedByThreePoints(anArc)
+#=========================================================================
+# Test 8. Initialize tangent point then change type
+#=========================================================================
+aTangentPoint.setAttr(aLineEnd)
+anArcType.setValue("by_three_points")
+assertNotInitializedByCenterAndPassed(anArc)
+assertNotInitializedByTangentEdge(anArc)
+#=========================================================================
+# Test 9. Initialize tangent point and end point then change type
+#=========================================================================
+anArcType.setValue("by_tangent_edge")
+aTangentPoint.setAttr(aLineEnd)
+aEndPoint3.setValue(50., 50.)
+anArcType.setValue("by_center_and_points")
+assertNotInitializedByThreePoints(anArc)
+assertNotInitializedByTangentEdge(anArc)
+#=========================================================================
+# Test 10. Initialize center and passed points and finish operation
+#=========================================================================
+aCenterPointRef.setObject(aLine.lastResult())
+aCenterPoint.setValue((aLineStart.x() + aLineEnd.x()) * 0.5, (aLineStart.y() + aLineEnd.y()) * 0.5)
+aStartPointRef.setAttr(aLineStart)
+aStartPoint1.setValue(aLineStart.pnt())
+aEndPointRef.setObject(aLine.lastResult())
+aEndPoint1.setValue(aLineEnd.pnt())
+aSession.finishOperation()
+
+NB_FEATURES_EXPECTED = 5 # line, arc and three coincidences
+assert (aSketchFeature.numberOfSubs() == NB_FEATURES_EXPECTED), "Number of features in sketch {}, expected {}".format(aSketchFeature.numberOfSubs(), NB_FEATURES_EXPECTED)
+verifyLastArc(aSketchFeature, [], [aLineStart.x(), aLineStart.y()], [])
+
+#=========================================================================
+# End of test
+#=========================================================================
+
+from salome.shaper import model
+assert(model.checkPythonDump())