]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Simplification and refactoring of unit tests for SketchPlugin
authorazv <azv@opencascade.com>
Thu, 11 May 2017 12:35:09 +0000 (15:35 +0300)
committerazv <azv@opencascade.com>
Thu, 11 May 2017 12:35:09 +0000 (15:35 +0300)
18 files changed:
src/ModelHighAPI/ModelHighAPI_RefAttr.cpp
src/ModelHighAPI/ModelHighAPI_RefAttr.h
src/PythonAPI/model/sketcher/__init__.py
src/PythonAPI/model/sketcher/tests.py [new file with mode: 0644]
src/PythonAPI/model/sketcher/tools.py
src/PythonAPI/model/tests/tests.py
src/SketchPlugin/Test/TestArcBehavior.py
src/SketchPlugin/Test/TestConstraintDistance.py
src/SketchPlugin/Test/TestConstraintTangent.py
src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py
src/SketchPlugin/Test/TestCreateArcByTangentEdge.py
src/SketchPlugin/Test/TestCreateArcByThreePoints.py
src/SketchPlugin/Test/TestCreateArcChangeType.py
src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py
src/SketchPlugin/Test/TestCreateCircleByThreePoints.py
src/SketchPlugin/Test/TestCreateCircleChangeType.py
src/SketchPlugin/Test/TestFillet.py
src/SketchPlugin/Test/TestFilletInteracting.py

index 776f40f4b4adf0226283866f8214d57c470eb7ce..5ab6cb60f27e93bedbdf04097d3f526e0a25a7db 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include "ModelHighAPI_Interface.h"
@@ -69,3 +70,13 @@ bool ModelHighAPI_RefAttr::isEmpty() const
 {
   return !(myAttribute && myObject);
 }
+
+//--------------------------------------------------------------------------------------
+void ModelHighAPI_RefAttr::fillMessage(
+    const std::shared_ptr<ModelAPI_ObjectMovedMessage>& theMessage) const
+{
+  switch (myVariantType) {
+  case VT_ATTRIBUTE: theMessage->setMovedAttribute(myAttribute); return;
+  case VT_OBJECT: theMessage->setMovedObject(myObject); return;
+  }
+}
index d2ada9e9087b21e7d8836b7ed508a9768091310c..adc00b228faf09f1e56ffab61386d18d58f031eb 100644 (file)
@@ -18,6 +18,7 @@ class ModelAPI_Attribute;
 class ModelAPI_AttributeRefAttr;
 class ModelAPI_AttributeRefAttrList;
 class ModelAPI_Object;
+class ModelAPI_ObjectMovedMessage;
 class ModelHighAPI_Interface;
 //--------------------------------------------------------------------------------------
 /**\class ModelHighAPI_RefAttr
@@ -55,6 +56,10 @@ public:
   MODELHIGHAPI_EXPORT
   bool isEmpty() const;
 
+  /// Fill moved message by the attribute or object
+  MODELHIGHAPI_EXPORT
+  void fillMessage(const std::shared_ptr<ModelAPI_ObjectMovedMessage>& theMessage) const;
+
 private:
   enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType;
   std::shared_ptr<ModelAPI_Attribute> myAttribute;
index b015b4278170b469d81fa7d734d14f4812bb448f..8c0319a1ecab2b26d8bd563a03aface7855dc7c8 100644 (file)
@@ -3,3 +3,4 @@
 
 from SketchAPI import addSketch
 from tools import *
+from tests import *
diff --git a/src/PythonAPI/model/sketcher/tests.py b/src/PythonAPI/model/sketcher/tests.py
new file mode 100644 (file)
index 0000000..d59a5e2
--- /dev/null
@@ -0,0 +1,76 @@
+# Author: Artem Zhidkov
+# Copyright (C) 2017-20xx CEA/DEN, EDF R&D
+
+from ModelAPI import *
+from GeomDataAPI import *
+import ModelHighAPI
+import math
+from salome.shaper.model.sketcher import tools
+
+TOLERANCE = 1.e-7
+
+def assertPoint(thePoint, theCoords):
+    """ Verifies coordinates of the point
+    """
+    aPoint = tools.toPoint(thePoint)
+    assert aPoint.x() == theCoords[0] and aPoint.y() == theCoords[1], "Wrong '{}' point ({}, {}), expected ({}, {})".format(thePoint.id(), aPoint.x(), aPoint.y(), theCoords[0], theCoords[1])
+
+
+def assertLine(theLine, theStart, theEnd):
+    """ Verifies coordinates of line extremities
+    """
+    aLine = tools.toSketchFeature(theLine)
+
+    aStartPnt = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+    aEndPnt = geomDataAPI_Point2D(aLine.attribute("EndPoint"))
+    if len(theStart):
+        assertPoint(aStartPnt, theStart)
+    if len(theEnd):
+        assertPoint(aEndPnt, theEnd)
+
+
+def assertCircle(theCircle, theCenter, theRadius):
+    """ Verifies attributes of circle
+    """
+    aCircle = tools.toSketchFeature(theCircle)
+
+    aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
+    if len(theCenter):
+        assertPoint(aCenter, theCenter)
+
+    aRadius = aCircle.real("circle_radius")
+    assert aRadius.value() == theRadius, "Wrong circle radius {}, expected {}".format(aRadius.value(), theRadius)
+
+
+def assertArc(theArc, theCenter, theStart, theEnd):
+    """ Verifies coordinates of arc points and the consistency of the arc.
+        Some of points may be empty lists.
+    """
+    anArc = tools.toSketchFeature(theArc)
+
+    aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
+    aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
+    aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
+    if len(theCenter):
+        assertPoint(aCenterPnt, theCenter)
+    if len(theStart):
+        assertPoint(aStartPnt, theStart)
+    if len(theEnd):
+        assertPoint(aEndPnt, theEnd)
+
+    assertArcValidity(anArc)
+
+
+def assertArcValidity(theArc):
+    """ Tests whether the arc is correctly defined
+    """
+    anArc = tools.toSketchFeature(theArc)
+
+    aCenterPnt = geomDataAPI_Point2D(anArc.attribute("center_point"))
+    aStartPnt = geomDataAPI_Point2D(anArc.attribute("start_point"))
+    aEndPnt = geomDataAPI_Point2D(anArc.attribute("end_point"))
+    aRadius = anArc.real("radius")
+    aDistCS = tools.distancePointPoint(aCenterPnt, aStartPnt)
+    aDistCE = tools.distancePointPoint(aCenterPnt, aEndPnt)
+    assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
+    assert math.fabs(aRadius.value() - aDistCS) < TOLERANCE, "Wrong arc: radius is {0}, expected {1}".format(aRadius.value(), aDistCS)
index 0a17f6aeaede8eafbefdd10bd541440af51b9ef0..57936dd8520d57f58d1f35f0a82c5c87a2f662ee 100644 (file)
@@ -2,7 +2,8 @@
 # Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 import ModelHighAPI
-import GeomDataAPI
+from GeomDataAPI import *
+import math
 
 def addPolyline(sketch, *coords):
     """Add a poly-line to sketch.
@@ -52,14 +53,21 @@ def dof(sketch):
     return int(filter(str.isdigit, aSketch.string("SolverDOF").value()))
 
 def distancePointPoint(thePoint1, thePoint2):
-    aGeomPnt1 = thePoint1
-    aGeomPnt2 = thePoint2
-    if issubclass(type(thePoint1), GeomDataAPI.GeomDataAPI_Point2D):
-        aGeomPnt1 = thePoint1.pnt()
-    if issubclass(type(thePoint2), GeomDataAPI.GeomDataAPI_Point2D):
-        aGeomPnt2 = thePoint2.pnt()
+    aGeomPnt1 = toPoint(thePoint1)
+    aGeomPnt2 = toPoint(thePoint2)
     return aGeomPnt1.distance(aGeomPnt2)
 
+def distancePointLine(thePoint, theLine):
+    aPoint = toPoint(thePoint)
+    aLine = toSketchFeature(theLine)
+
+    aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint")).pnt().xy()
+    aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint")).pnt().xy()
+    aLineDir = aLineEnd.decreased(aLineStart)
+    aLineLen = aLineEnd.distance(aLineStart)
+    aPntDir = aPoint.xy().decreased(aLineStart)
+    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
+
 def lastSubFeature(theSketch, theKind):
     """
     obtains last feature of given kind from the sketch
@@ -68,3 +76,18 @@ def lastSubFeature(theSketch, theKind):
         aSub = theSketch.subFeature(anIndex)
         if (aSub.getKind() == theKind):
             return aSub
+
+def toSketchFeature(theEntity):
+    """ Converts entity to sketch feature if possible
+    """
+    if issubclass(type(theEntity), ModelHighAPI.ModelHighAPI_Interface):
+        return theEntity.feature()
+    else:
+        return theEntity
+
+def toPoint(thePoint):
+    if issubclass(type(thePoint), GeomDataAPI_Point2D):
+        return thePoint.pnt()
+    else:
+        aPoint = toSketchFeature(thePoint)
+        return geomDataAPI_Point2D(aPoint.attribute("PointCoordinates")).pnt()
index 84e84c6a6d30f462f624a461c118b193cb27ead0..d76504e01d175be61209444bd67ccb9d483b5146 100644 (file)
@@ -3,9 +3,6 @@ from GeomAPI import *
 from GeomDataAPI import *
 from ModelAPI import ModelAPI_Feature
 import math
-from salome.shaper.model import sketcher
-
-TOLERANCE = 1.e-7
 
 aShapeTypes = {
   GeomAPI_Shape.SOLID:  "GeomAPI_Shape.SOLID",
@@ -157,15 +154,3 @@ def testNbSubFeatures(theComposite, theKindOfSub, theExpectedCount):
     if aFeature is not None and aFeature.getKind() == theKindOfSub:
        count += 1
   assert (count == theExpectedCount), "Number of sub-features of type {}: {}, expected {}".format(theKindOfSub, count, theExpectedCount)
-
-def assertSketchArc(theArcFeature):
-  """ Tests whether the arc is correctly defined
-  """
-  aCenterPnt = geomDataAPI_Point2D(theArcFeature.attribute("center_point"))
-  aStartPnt = geomDataAPI_Point2D(theArcFeature.attribute("start_point"))
-  aEndPnt = geomDataAPI_Point2D(theArcFeature.attribute("end_point"))
-  aRadius = theArcFeature.real("radius")
-  aDistCS = sketcher.tools.distancePointPoint(aCenterPnt, aStartPnt)
-  aDistCE = sketcher.tools.distancePointPoint(aCenterPnt, aEndPnt)
-  assert math.fabs(aDistCS - aDistCE) < TOLERANCE, "Wrong arc: center-start distance {}, center-end distance {}".format(aDistCS, aDistCE)
-  assert math.fabs(aRadius.value() -aDistCS) < TOLERANCE, "Wrong arc: radius is {0}, expected {1}".format(aRadius.value(), aDistCS)
index 2f8c3f4dbec2575cf10dadadff8aa07247a97122..46ab36ff14a1050ee1df2183d1f82976e5834f73 100644 (file)
@@ -143,12 +143,12 @@ for aDelta in range(0, 20):
   aSession.startOperation()
   anArcStartPoint.setValue(sx, sy+aDelta) # move start point
   aSession.finishOperation()
-  model.assertSketchArc(aSketchArc)
+  model.assertArcValidity(aSketchArc)
 for aDelta in range(20, -1, -1):
   aSession.startOperation()
   anArcStartPoint.setValue(sx, sy+aDelta) # move start point
   aSession.finishOperation()
-  model.assertSketchArc(aSketchArc)
+  model.assertArcValidity(aSketchArc)
 #=========================================================================
 # Test that movement of end point of arc does not break the arc
 #=========================================================================
@@ -160,9 +160,9 @@ for aDelta in range(0, 20):
   aSession.startOperation()
   anArcEndPoint.setValue(sx+aDelta, sy) # move end point
   aSession.finishOperation()
-  model.assertSketchArc(aSketchArc)
+  model.assertArcValidity(aSketchArc)
 for aDelta in range(20, -1, -1):
   aSession.startOperation()
   anArcEndPoint.setValue(sx+aDelta, sy) # move end point
   aSession.finishOperation()
-  model.assertSketchArc(aSketchArc)
+  model.assertArcValidity(aSketchArc)
index a5c80ae7c0e212f535b62eb2ab0c1881077b1a24..b4b7debdd2404e9647d454d8ab90cae059399849 100644 (file)
@@ -31,23 +31,6 @@ from salome.shaper import model
 __updated__ = "2014-10-28"
 
 
-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()
 #=========================================================================
@@ -143,7 +126,7 @@ assert (model.dof(aSketchFeature) == 6)
 # Add distance between point and line
 #=========================================================================
 PT_LINE_DIST = 50.
-aDist = distancePointLine(aSketchPointCoords, aSketchLine)
+aDist = model.distancePointLine(aSketchPointCoords, aSketchLine)
 aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintDistance")
 aDistance = aConstraint.real("ConstraintValue")
@@ -174,7 +157,7 @@ assert (model.dof(aSketchFeature) == 5)
 aSession.startOperation()
 aDistance.setValue(PT_LINE_DIST)
 aSession.finishOperation()
-assert (math.fabs(distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10)
+assert (math.fabs(model.distancePointLine(aSketchPointCoords, aSketchLine) - PT_LINE_DIST) < 1.e-10)
 assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Set distance between line boundaries
index fb18f3325bc8deddf9b6c0c05591511d01290d2d..359d8ad95af7767ea487018e0e9aec3a1899d264 100644 (file)
@@ -20,23 +20,6 @@ from salome.shaper import model
 
 __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)
-
 def checkArcLineTangency(theArc, theLine):
     """
     subroutine to check that the line is tangent to arc/circle
@@ -48,7 +31,7 @@ def checkArcLineTangency(theArc, theLine):
         aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
         aStartPnt = geomDataAPI_Point2D(theArc.attribute("start_point"))
         aRadius = model.distancePointPoint(aStartPnt, aCenter)
-    aDist = distancePointLine(aCenter, theLine)
+    aDist = model.distancePointLine(aCenter, theLine)
     assert math.fabs(aDist - aRadius) < 2.e-5, "aDist = {0}, aRadius = {1}".format(aDist, aRadius)
 
 def checkArcArcTangency(theArc1, theArc2):
index f8fbb67dd15dca3ab9bcf8283765aff32b7de2fd..e3b43bfb2d030cdde4b503adea7abadde87049f1 100644 (file)
@@ -32,22 +32,10 @@ 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)
+    model.assertArc(aLastArc, theCenter, theStart, theEnd)
 
 def verifyPointOnLine(thePoint, theLine):
-    aDistance = distancePointLine(thePoint, theLine)
+    aDistance = model.distancePointLine(thePoint, theLine)
     assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
 
 def verifyPointOnCircle(thePoint, theCircular):
@@ -62,14 +50,6 @@ def verifyPointOnCircle(thePoint, theCircular):
         return
     assert math.fabs(model.distancePointPoint(aCenterPoint, thePoint) - aRadius) < TOLERANCE
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
-    aLineDir = aLineEnd.decreased(aLineStart)
-    aLineLen = aLineEnd.distance(aLineStart)
-    aPntDir = thePoint.pnt().xy().decreased(aLineStart)
-    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
 
 aSession = ModelAPI_Session.get()
 aDocument = aSession.moduleDocument()
@@ -223,7 +203,7 @@ aEndRef.setObject(aLine.lastResult())
 aEnd.setValue(aLineStart[0], aLineStart[1])
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 8), "Number of subs {}".format(aSketchFeature.numberOfSubs())
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
+model.assertPoint(aPointCoord, aPointCoordinates)
 verifyLastArc(aSketchFeature, [aPrevArcStart.x(), aPrevArcStart.y()], aPointCoordinates, [])
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
 
@@ -259,11 +239,8 @@ aEnd.setValue(aLineEndPoint.pnt())
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 12), "Number of subs {}".format(aSketchFeature.numberOfSubs())
 # check connected features do not change their positions
-verifyPointCoordinates(aPrevArcCenter, aPrevArcCenterXY[0], aPrevArcCenterXY[1])
-verifyPointCoordinates(aPrevArcStart, aPrevArcStartXY[0], aPrevArcStartXY[1])
-verifyPointCoordinates(aPrevArcEnd, aPrevArcEndXY[0], aPrevArcEndXY[1])
-verifyPointCoordinates(aLineStartPoint, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aLineEndPoint, aLineEnd[0], aLineEnd[1])
+model.assertArc(aPrevArc, aPrevArcCenterXY, aPrevArcStartXY, aPrevArcEndXY)
+model.assertLine(aLine, aLineStart, aLineEnd)
 # verify newly created arc
 anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
 aCenter = geomDataAPI_Point2D(anArc.attribute("center_point"))
index a59e9299f399ac9d9720a39892e728c3f90e52ff..bc36b2c3acb7a537c1a08c00ce8cd38d5c3b4996 100644 (file)
@@ -32,19 +32,7 @@ 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)
+    model.assertArc(aLastArc, theCenter, theStart, theEnd)
 
 def verifyTangent(theFeature1, theFeature2):
     anArcs = []
@@ -79,19 +67,11 @@ def verifyArcLineTangent(theArc, theLine):
     aStart  = geomDataAPI_Point2D(theArc.attribute("start_point"))
     aRadius = model.distancePointPoint(aStart, aCenter)
 
-    aDistCL = distancePointLine(aCenter, theLine)
+    aDistCL = model.distancePointLine(aCenter, theLine)
     assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Arc and line do not tangent"
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
-    aLineDir = aLineEnd.decreased(aLineStart)
-    aLineLen = aLineEnd.distance(aLineStart)
-    aPntDir = thePoint.pnt().xy().decreased(aLineStart)
-    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
 def verifyPointOnLine(thePoint, theLine):
-    aDistance = distancePointLine(thePoint, theLine)
+    aDistance = model.distancePointLine(thePoint, theLine)
     assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
 
 
index d136ceab4bdf6ee83dad1c0581ab91d30c9584a8..f59df62fad7cdb9dca356f21057b43737e72c6b9 100644 (file)
@@ -28,13 +28,10 @@ def verifyLastArc(theSketch, theX, theY, theR):
     """
     aLastArc = model.lastSubFeature(theSketch, "SketchArc")
     aCenter = geomDataAPI_Point2D(aLastArc.attribute("center_point"))
-    verifyPointCoordinates(aCenter, theX, theY)
+    model.assertPoint(aCenter, [theX, theY])
     aRadius = aLastArc.real("radius")
     assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
 
-def verifyPointCoordinates(thePoint, theX, theY):
-    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
-
 def verifyPointOnArc(thePoint, theArc):
     aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
     aDistCP = model.distancePointPoint(aCenter, thePoint)
@@ -58,17 +55,9 @@ def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2):
 def verifyTangentArcLine(theArc, theLine):
     aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
     aRadius = theArc.real("radius").value()
-    aDistCL = distancePointLine(aCenter, theLine)
+    aDistCL = model.distancePointLine(aCenter, theLine)
     assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
-    aLineDir = aLineEnd.decreased(aLineStart)
-    aLineLen = aLineEnd.distance(aLineStart)
-    aPntDir = thePoint.pnt().xy().decreased(aLineStart)
-    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
 
 #=========================================================================
 # Start of test
@@ -158,9 +147,9 @@ anArcPnt3.setValue(aLineStart[0], aLineStart[1])
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 7)
 # check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoodinates)
+model.assertPoint(aStartPnt, aLineStart)
 # check newly created arc passes through the points
 anArc = model.lastSubFeature(aSketchFeature, "SketchArc")
 verifyPointOnArc(aPrevCenter, anArc)
@@ -189,9 +178,9 @@ anArcPnt3.setValue(20, 25)
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 9)
 # check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoodinates[0], aPointCoodinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoodinates)
+model.assertPoint(aStartPnt, aLineStart)
 # check sub-features
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
 model.testNbSubFeatures(aSketch, "SketchConstraintTangent", 1)
index 92a876cd1f506457144f09d649064ebd36a61a3f..6db1e1dfd0e150fa18f51b7f401d6c9482289f2c 100644 (file)
@@ -68,19 +68,7 @@ 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)
+    model.assertArc(aLastArc, theCenter, theStart, theEnd)
 
 
 #=========================================================================
index a7b453b74ab4718c2822726fb2d86829f133aae6..8a73a150bc6cb386554c4931b1994f77b32c5f5b 100644 (file)
@@ -27,16 +27,10 @@ def verifyLastCircle(theSketch, theX, theY, theR):
     subroutine to verify position of last circle in the sketch
     """
     aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
-    aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
-    verifyPointCoordinates(aCenter, theX, theY)
-    aRadius = aLastCircle.real("circle_radius")
-    assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-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)
+    model.assertCircle(aLastCircle, [theX, theY], theR)
 
 def verifyPointOnLine(thePoint, theLine):
-    aDistance = distancePointLine(thePoint, theLine)
+    aDistance = model.distancePointLine(thePoint, theLine)
     assert aDistance < TOLERANCE, "Point is not on Line, distance: {0}".format(aDistance)
 
 def verifyTangentCircles(theCircle1, theCircle2):
@@ -49,14 +43,6 @@ def verifyTangentCircles(theCircle1, theCircle2):
     aRDiff = math.fabs(aRadius1 - aRadius2)
     assert math.fabs(aRSum - aDistCC) < TOLERANCE or math.fabs(aRDiff - aDistCC) < TOLERANCE, "Circles do not tangent"
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
-    aLineDir = aLineEnd.decreased(aLineStart)
-    aLineLen = aLineEnd.distance(aLineStart)
-    aPntDir = thePoint.pnt().xy().decreased(aLineStart)
-    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
 
 #=========================================================================
 # Start of test
@@ -162,7 +148,7 @@ aPassed.setValue(aPrevCenter.pnt())
 aRadius = model.distancePointPoint(aPrevCenter, aPointCoord)
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 6)
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
+model.assertPoint(aPointCoord, aPointCoordinates)
 verifyLastCircle(aSketchFeature, aPointCoord.x(), aPointCoord.y(), aRadius)
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 2)
 
@@ -203,14 +189,13 @@ aRadius = model.distancePointPoint(aCenter, aPassed)
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 10)
 # check connected features do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
 assert(aPrevCircle.real("circle_radius").value() == aPrevRadius)
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1])
+model.assertLine(aLine, aLineStart, aLineEnd)
 # verify newly created circle
 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
 aCenter = geomDataAPI_Point2D(aCircle.attribute("circle_center"))
-verifyPointCoordinates(aCenter, anExpectedCenter[0], anExpectedCenter[1])
+model.assertPoint(aCenter, anExpectedCenter)
 verifyPointOnLine(aCenter, aLine)
 verifyTangentCircles(aCircle, aPrevCircle)
 model.testNbSubFeatures(aSketch, "SketchConstraintCoincidence", 3)
index ddee805b2f7b77ab972ba6a43ab0ee3da32959ac..79a4a1c3014a5e01ee38ebc358600ed9d1671cb3 100644 (file)
@@ -27,13 +27,7 @@ def verifyLastCircle(theSketch, theX, theY, theR):
     subroutine to verify position of last circle in the sketch
     """
     aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
-    aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
-    verifyPointCoordinates(aCenter, theX, theY)
-    aRadius = aLastCircle.real("circle_radius")
-    assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-def verifyPointCoordinates(thePoint, theX, theY):
-    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
+    model.assertCircle(aLastCircle, [theX, theY], theR)
 
 def verifyPointOnCircle(thePoint, theCircle):
     aCircleCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
@@ -66,17 +60,9 @@ def verifyTangentCircular(theDistBetweenCenters, theRadius1, theRadius2):
 def verifyTangentCircleLine(theCircle, theLine):
     aCenter = geomDataAPI_Point2D(theCircle.attribute("circle_center"))
     aRadius = theCircle.real("circle_radius").value()
-    aDistCL = distancePointLine(aCenter, theLine)
+    aDistCL = model.distancePointLine(aCenter, theLine)
     assert math.fabs(aDistCL - aRadius) < TOLERANCE, "Circle and line are not tangent"
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")).pnt().xy()
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")).pnt().xy()
-    aLineDir = aLineEnd.decreased(aLineStart)
-    aLineLen = aLineEnd.distance(aLineStart)
-    aPntDir = thePoint.pnt().xy().decreased(aLineStart)
-    return math.fabs(aPntDir.cross(aLineDir) / aLineLen)
-
 
 #=========================================================================
 # Start of test
@@ -166,9 +152,9 @@ aCirclePnt3.setValue(aLineStart[0], aLineStart[1])
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 7)
 # check the points do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
-verifyPointCoordinates(aPointCoord, aPointCoordinates[0], aPointCoordinates[1])
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
+model.assertPoint(aPointCoord, aPointCoordinates)
+model.assertPoint(aStartPnt, aLineStart)
 # check newly created circle passes through the points
 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
 verifyPointOnCircle(aPrevCenter, aCircle)
@@ -215,13 +201,10 @@ aCirclePnt3.setValue(anArcCenter[0] + anArcRadius, anArcCenter[1])
 aSession.finishOperation()
 assert (aSketchFeature.numberOfSubs() == 12)
 # check the tangent entities do not change their positions
-verifyPointCoordinates(aPrevCenter, aPrevCenterXY[0], aPrevCenterXY[1])
+model.assertPoint(aPrevCenter, aPrevCenterXY)
 assert (aPrevCircle.real("circle_radius").value() == aPrevCircleRadius)
-verifyPointCoordinates(aStartPnt, aLineStart[0], aLineStart[1])
-verifyPointCoordinates(aEndPnt, aLineEnd[0], aLineEnd[1])
-verifyPointCoordinates(anArcCenterPnt, anArcCenter[0], anArcCenter[1])
-verifyPointCoordinates(anArcStartPnt, anArcStart[0], anArcStart[1])
-verifyPointCoordinates(anArcEndPnt, anArcEnd[0], anArcEnd[1])
+model.assertLine(aLine, aLineStart, aLineEnd)
+model.assertArc(anArc, anArcCenter, anArcStart, anArcEnd)
 # check newly created circle passes through the points
 aCircle = model.lastSubFeature(aSketchFeature, "SketchCircle")
 verifyTangentCircles(aCircle, aPrevCircle)
index 8041ae1b575966174576717009eb36c8a7acc206..853c74bffbfca90fc7c53f0eae0a700ab3bb9a32 100644 (file)
@@ -52,13 +52,7 @@ def verifyLastCircle(theSketch, theX, theY, theR):
     subroutine to verify position of last circle in the sketch
     """
     aLastCircle = model.lastSubFeature(theSketch, "SketchCircle")
-    aCenter = geomDataAPI_Point2D(aLastCircle.attribute("circle_center"))
-    verifyPointCoordinates(aCenter, theX, theY)
-    aRadius = aLastCircle.real("circle_radius")
-    assert aRadius.value() == theR, "Wrong radius {0}, expected {1}".format(aRadius.value(), theR)
-
-def verifyPointCoordinates(thePoint, theX, theY):
-    assert thePoint.x() == theX and thePoint.y() == theY, "Wrong '{0}' point ({1}, {2}), expected ({3}, {4})".format(thePoint.attributeType(), thePoint.x(), thePoint.y(), theX, theY)
+    model.assertCircle(aLastCircle, [theX, theY], theR)
 
 
 #=========================================================================
index a52ce5a5cc37af35de8cbc48f4a854411d880105..9a8319f6a622c9c9a1bc8d9265395f2e1460d803 100644 (file)
@@ -105,7 +105,7 @@ def checkSmoothness(theSketch):
 
 def checkArcLineSmoothness(theArc, theLine):
     aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
-    aDistance = distancePointLine(aCenter, theLine)
+    aDistance = model.distancePointLine(aCenter, theLine)
     aRadius = arcRadius(theArc)
     assert(math.fabs(aRadius - aDistance) < TOLERANCE)
 
@@ -142,16 +142,6 @@ def arcRadius(theArc):
     aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
     return model.distancePointPoint(aCenter, aStart)
 
-def distancePointLine(thePoint, theLine):
-    aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
-    aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
-    aLength = model.distancePointPoint(aLineStart, aLineEnd)
-
-    aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
-    aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
-    aCross = aDir1x * aDir2y - aDir1y * aDir2x
-    return math.fabs(aCross) / aLength
-
 
 #=========================================================================
 # Initialization of the test
index 9653c3cf006837da06f346f863ca51e4382e6800..9486fb6a9f496f572cefd06204855016ffb6c6ae 100644 (file)
@@ -15,7 +15,7 @@ __updated__ = "2017-03-06"
 
 def isArcLineSmooth(theArc, theLine, theTolerance):
   aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
-  aDistance = distancePointLine(aCenter, theLine)
+  aDistance = model.distancePointLine(aCenter, theLine)
   aRadius = arcRadius(theArc)
   return math.fabs(aRadius - aDistance) < theTolerance
 
@@ -34,15 +34,6 @@ def arcRadius(theArc):
   aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
   return model.distancePointPoint(aCenter, aStart)
 
-def distancePointLine(thePoint, theLine):
-  aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
-  aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
-  aLength = model.distancePointPoint(aLineStart, aLineEnd)
-  aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
-  aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
-  aCross = aDir1x * aDir2y - aDir1y * aDir2x
-  return math.fabs(aCross) / aLength
-
 
 
 class TestFilletInteracting(unittest.TestCase):