From dddb164bbd94e2a397f1f9ce80c931d1ca3dac19 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 11 May 2017 15:35:09 +0300 Subject: [PATCH] Simplification and refactoring of unit tests for SketchPlugin --- src/ModelHighAPI/ModelHighAPI_RefAttr.cpp | 11 +++ src/ModelHighAPI/ModelHighAPI_RefAttr.h | 5 ++ src/PythonAPI/model/sketcher/__init__.py | 1 + src/PythonAPI/model/sketcher/tests.py | 76 +++++++++++++++++++ src/PythonAPI/model/sketcher/tools.py | 37 +++++++-- src/PythonAPI/model/tests/tests.py | 15 ---- src/SketchPlugin/Test/TestArcBehavior.py | 8 +- .../Test/TestConstraintDistance.py | 21 +---- .../Test/TestConstraintTangent.py | 19 +---- .../Test/TestCreateArcByCenterStartEnd.py | 33 ++------ .../Test/TestCreateArcByTangentEdge.py | 26 +------ .../Test/TestCreateArcByThreePoints.py | 27 ++----- .../Test/TestCreateArcChangeType.py | 14 +--- .../Test/TestCreateCircleByCenterAndPassed.py | 27 ++----- .../Test/TestCreateCircleByThreePoints.py | 33 ++------ .../Test/TestCreateCircleChangeType.py | 8 +- src/SketchPlugin/Test/TestFillet.py | 12 +-- .../Test/TestFilletInteracting.py | 11 +-- 18 files changed, 164 insertions(+), 220 deletions(-) create mode 100644 src/PythonAPI/model/sketcher/tests.py diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp index 776f40f4b..5ab6cb60f 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include "ModelHighAPI_Interface.h" @@ -69,3 +70,13 @@ bool ModelHighAPI_RefAttr::isEmpty() const { return !(myAttribute && myObject); } + +//-------------------------------------------------------------------------------------- +void ModelHighAPI_RefAttr::fillMessage( + const std::shared_ptr& theMessage) const +{ + switch (myVariantType) { + case VT_ATTRIBUTE: theMessage->setMovedAttribute(myAttribute); return; + case VT_OBJECT: theMessage->setMovedObject(myObject); return; + } +} diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.h b/src/ModelHighAPI/ModelHighAPI_RefAttr.h index d2ada9e90..adc00b228 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.h +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.h @@ -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& theMessage) const; + private: enum VariantType { VT_ATTRIBUTE, VT_OBJECT } myVariantType; std::shared_ptr myAttribute; diff --git a/src/PythonAPI/model/sketcher/__init__.py b/src/PythonAPI/model/sketcher/__init__.py index b015b4278..8c0319a1e 100644 --- a/src/PythonAPI/model/sketcher/__init__.py +++ b/src/PythonAPI/model/sketcher/__init__.py @@ -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 index 000000000..d59a5e21d --- /dev/null +++ b/src/PythonAPI/model/sketcher/tests.py @@ -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) diff --git a/src/PythonAPI/model/sketcher/tools.py b/src/PythonAPI/model/sketcher/tools.py index 0a17f6aea..57936dd85 100644 --- a/src/PythonAPI/model/sketcher/tools.py +++ b/src/PythonAPI/model/sketcher/tools.py @@ -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() diff --git a/src/PythonAPI/model/tests/tests.py b/src/PythonAPI/model/tests/tests.py index 84e84c6a6..d76504e01 100644 --- a/src/PythonAPI/model/tests/tests.py +++ b/src/PythonAPI/model/tests/tests.py @@ -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) diff --git a/src/SketchPlugin/Test/TestArcBehavior.py b/src/SketchPlugin/Test/TestArcBehavior.py index 2f8c3f4db..46ab36ff1 100644 --- a/src/SketchPlugin/Test/TestArcBehavior.py +++ b/src/SketchPlugin/Test/TestArcBehavior.py @@ -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) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index a5c80ae7c..b4b7debdd 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -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 diff --git a/src/SketchPlugin/Test/TestConstraintTangent.py b/src/SketchPlugin/Test/TestConstraintTangent.py index fb18f3325..359d8ad95 100644 --- a/src/SketchPlugin/Test/TestConstraintTangent.py +++ b/src/SketchPlugin/Test/TestConstraintTangent.py @@ -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): diff --git a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py index f8fbb67dd..e3b43bfb2 100644 --- a/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py +++ b/src/SketchPlugin/Test/TestCreateArcByCenterStartEnd.py @@ -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")) diff --git a/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py b/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py index a59e9299f..bc36b2c3a 100644 --- a/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py +++ b/src/SketchPlugin/Test/TestCreateArcByTangentEdge.py @@ -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) diff --git a/src/SketchPlugin/Test/TestCreateArcByThreePoints.py b/src/SketchPlugin/Test/TestCreateArcByThreePoints.py index d136ceab4..f59df62fa 100644 --- a/src/SketchPlugin/Test/TestCreateArcByThreePoints.py +++ b/src/SketchPlugin/Test/TestCreateArcByThreePoints.py @@ -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) diff --git a/src/SketchPlugin/Test/TestCreateArcChangeType.py b/src/SketchPlugin/Test/TestCreateArcChangeType.py index 92a876cd1..6db1e1dfd 100644 --- a/src/SketchPlugin/Test/TestCreateArcChangeType.py +++ b/src/SketchPlugin/Test/TestCreateArcChangeType.py @@ -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) #========================================================================= diff --git a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py index a7b453b74..8a73a150b 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py +++ b/src/SketchPlugin/Test/TestCreateCircleByCenterAndPassed.py @@ -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) diff --git a/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py b/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py index ddee805b2..79a4a1c30 100644 --- a/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py +++ b/src/SketchPlugin/Test/TestCreateCircleByThreePoints.py @@ -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) diff --git a/src/SketchPlugin/Test/TestCreateCircleChangeType.py b/src/SketchPlugin/Test/TestCreateCircleChangeType.py index 8041ae1b5..853c74bff 100644 --- a/src/SketchPlugin/Test/TestCreateCircleChangeType.py +++ b/src/SketchPlugin/Test/TestCreateCircleChangeType.py @@ -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) #========================================================================= diff --git a/src/SketchPlugin/Test/TestFillet.py b/src/SketchPlugin/Test/TestFillet.py index a52ce5a5c..9a8319f6a 100644 --- a/src/SketchPlugin/Test/TestFillet.py +++ b/src/SketchPlugin/Test/TestFillet.py @@ -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 diff --git a/src/SketchPlugin/Test/TestFilletInteracting.py b/src/SketchPlugin/Test/TestFilletInteracting.py index 9653c3cf0..9486fb6a9 100644 --- a/src/SketchPlugin/Test/TestFilletInteracting.py +++ b/src/SketchPlugin/Test/TestFilletInteracting.py @@ -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): -- 2.39.2