From 4d17967148788d2336a0f10530bc5eb739ae4ef1 Mon Sep 17 00:00:00 2001 From: sbh Date: Tue, 29 Jul 2014 14:10:19 +0400 Subject: [PATCH] Tests for distance, parallel, perpendicular and radius constraints added --- src/SketchPlugin/CMakeLists.txt | 6 +- .../Test/TestConstraintDistance.py | 119 ++++++++++++++ src/SketchPlugin/Test/TestConstraintLength.py | 6 +- .../Test/TestConstraintParallel.py | 127 +++++++++++++++ .../Test/TestConstraintPerpendicular.py | 150 ++++++++++++++++++ src/SketchPlugin/Test/TestConstraintRadius.py | 140 ++++++++++++++++ 6 files changed, 544 insertions(+), 4 deletions(-) create mode 100644 src/SketchPlugin/Test/TestConstraintDistance.py create mode 100644 src/SketchPlugin/Test/TestConstraintParallel.py create mode 100644 src/SketchPlugin/Test/TestConstraintPerpendicular.py create mode 100644 src/SketchPlugin/Test/TestConstraintRadius.py diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index b6d8467a2..0b2870fa8 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -64,4 +64,8 @@ INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) ADD_UNIT_TESTS(TestSketchPointLine.py TestSketchArcCircle.py TestConstraintConcidence.py - TestConstraintLength.py) + TestConstraintLength.py + TestConstraintDistance.py + TestConstraintParallel.py + TestConstraintPerpendicular.py + TestConstraintRadius.py) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py new file mode 100644 index 000000000..bd978fa03 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -0,0 +1,119 @@ +""" + TestConstraintDistance.py + Unit test of SketchPlugin_ConstraintDistance class + + SketchPlugin_Constraint + static const std::string MY_CONSTRAINT_VALUE("ConstraintValue"); + static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); + static const std::string MY_ENTITY_A("ConstraintEntityA"); + static const std::string MY_ENTITY_B("ConstraintEntityB"); + static const std::string MY_ENTITY_C("ConstraintEntityC"); + static const std::string MY_ENTITY_D("ConstraintEntityD"); + + SketchPlugin_ConstraintDistance + static const std::string MY_CONSTRAINT_DISTANCE_ID("SketchConstraintDistance"); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); + + +""" +from GeomDataAPI import * +from ModelAPI import * +import math +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2014-07-29" + + +def distance(pointA, pointB): + """ + subroutine to calculate distance between two points + result of calculated distance is has 10**-5 precision + """ + xdiff = math.pow((pointA.x() - pointB.x()), 2) + ydiff = math.pow((pointA.y() - pointB.y()), 2) + return round(math.sqrt(xdiff + ydiff), 5) + +aPluginManager = ModelAPI_PluginManager.get() +aDocument = aPluginManager.rootDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aDocument.startOperation() +aSketchFeature = aDocument.addFeature("Sketch") +aSketchFeatureData = aSketchFeature.data() +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm.setValue(0, 0, 1) +aDocument.finishOperation() +#========================================================================= +# Create a point and a line +#========================================================================= +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +aSketchPoint = aDocument.addFeature("SketchPoint") +aSketchReflist.append(aSketchPoint) +aSketchPointData = aSketchPoint.data() +aSketchPointCoords = geomDataAPI_Point2D( + aSketchPointData.attribute("PointCoordindates")) +aSketchPointCoords.setValue(50., 50.) +aSketchLine = aDocument.addFeature("SketchLine") +aSketchReflist.append(aSketchLine) +aLineAStartPoint = geomDataAPI_Point2D( + aSketchLine.data().attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.data().attribute("EndPoint")) +aLineAStartPoint.setValue(0., 25.) +aLineAEndPoint.setValue(100., 25.) +aDocument.finishOperation() +#========================================================================= +# Make a constraint to keep the distance +#========================================================================= +assert (distance(aSketchPointCoords, aLineAStartPoint) != 25.) +aDocument.startOperation() +aConstraint = aDocument.addFeature("SketchConstraintDistance") +aSketchReflist.append(aConstraint) +aConstraintData = aConstraint.data() +aDistance = aConstraintData.real("ConstraintValue") +refattrA = aConstraintData.refattr("ConstraintEntityA") +refattrB = aConstraintData.refattr("ConstraintEntityB") +assert (not aDistance.isInitialized()) +assert (not refattrA.isInitialized()) +assert (not refattrB.isInitialized()) +aDistance.setValue(25.) +aLineResult = aSketchLine.firstResult() +assert (aLineResult is not None) +refattrA.setAttr(aSketchPointCoords) +refattrB.setAttr(aLineAStartPoint) +aDocument.finishOperation() +assert (aDistance.isInitialized()) +assert (refattrA.isInitialized()) +assert (refattrB.isInitialized()) +#========================================================================= +# Move line, check that distance is constant +#========================================================================= +assert (distance(aSketchPointCoords, aLineAStartPoint) == 25.) +aDocument.startOperation() +aLineAStartPoint.setValue(0., 40.) +aLineAEndPoint.setValue(100., 40.) +aDocument.finishOperation() +assert (distance(aSketchPointCoords, aLineAStartPoint) == 25.) +#========================================================================= +# TODO: improve test +# 1. remove constraint, move line's start point to +# check that constraint are not applied +# 2. check constrained distance between: +# * point and line +# * two lines +#========================================================================= +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintLength.py b/src/SketchPlugin/Test/TestConstraintLength.py index fe4539c39..ef6dd0e67 100644 --- a/src/SketchPlugin/Test/TestConstraintLength.py +++ b/src/SketchPlugin/Test/TestConstraintLength.py @@ -1,6 +1,6 @@ """ - TestConstraints.py - Base for all constaints tests. + TestConstraintLength.py + Unit test of SketchPlugin_ConstraintLength class SketchPlugin_ConstraintLength static const std::string MY_CONSTRAINT_LENGTH_ID("SketchConstraintLength"); @@ -15,7 +15,7 @@ from ModelAPI import * # Initialization of the test #========================================================================= -__updated__ = "2014-07-28" +__updated__ = "2014-07-29" aPluginManager = ModelAPI_PluginManager.get() aDocument = aPluginManager.rootDocument() diff --git a/src/SketchPlugin/Test/TestConstraintParallel.py b/src/SketchPlugin/Test/TestConstraintParallel.py new file mode 100644 index 000000000..c68314966 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintParallel.py @@ -0,0 +1,127 @@ +""" + TestConstraintParallel.py + Unit test of SketchPlugin_ConstraintParallel class + + SketchPlugin_ConstraintParallel + static const std::string MY_CONSTRAINT_PARALLEL_ID("SketchConstraintParallel"); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); + +""" +from GeomDataAPI import * +from ModelAPI import * +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2014-07-29" + +aPluginManager = ModelAPI_PluginManager.get() +aDocument = aPluginManager.rootDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aDocument.startOperation() +aSketchFeature = aDocument.addFeature("Sketch") +aSketchFeatureData = aSketchFeature.data() +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm.setValue(0, 0, 1) +aDocument.finishOperation() +#========================================================================= +# Create two lines which are not parallel +#========================================================================= +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +# line A +aSketchLineA = aDocument.addFeature("SketchLine") +aSketchReflist.append(aSketchLineA) +aLineAStartPoint = geomDataAPI_Point2D( + aSketchLineA.data().attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D( + aSketchLineA.data().attribute("EndPoint")) +aSketchLineB = aDocument.addFeature("SketchLine") +aLineAStartPoint.setValue(0., 25) +aLineAEndPoint.setValue(85., 25) +# line B +aSketchReflist.append(aSketchLineB) +aLineBStartPoint = geomDataAPI_Point2D( + aSketchLineB.data().attribute("StartPoint")) +aLineBEndPoint = geomDataAPI_Point2D( + aSketchLineB.data().attribute("EndPoint")) +aLineBStartPoint.setValue(0., 50) +aLineBEndPoint.setValue(80., 75) +aDocument.finishOperation() +#========================================================================= +# Make a constraint to keep the length of the line constant +# to parallel perpendicular constraint collapsing line to point +#========================================================================= +aDocument.startOperation() +aLengthConstraint = aDocument.addFeature("SketchConstraintLength") +aSketchReflist.append(aLengthConstraint) +aLengthConstraintData = aLengthConstraint.data() +refattrA = aLengthConstraintData.refattr("ConstraintEntityA") +aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult()) +assert (aResultA is not None) +refattrA.setObject(aResultA) +aDocument.finishOperation() +# Coordinates of lines should not be changed after this constraint +assert (aLineAStartPoint.x() == 0) +assert (aLineAStartPoint.y() == 25) +assert (aLineAEndPoint.x() == 85) +assert (aLineAEndPoint.y() == 25) +assert (aLineBStartPoint.x() == 0) +assert (aLineBStartPoint.y() == 50) +assert (aLineBEndPoint.x() == 80) +assert (aLineBEndPoint.y() == 75) +#========================================================================= +# Link lines with parallel constraint +#========================================================================= +aDocument.startOperation() +aParallelConstraint = aDocument.addFeature("SketchConstraintParallel") +aSketchReflist.append(aParallelConstraint) +aConstraintData = aParallelConstraint.data() +refattrA = aConstraintData.refattr("ConstraintEntityA") +refattrB = aConstraintData.refattr("ConstraintEntityB") +# aResultA is already defined for the length constraint +aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult()) +assert (aResultB is not None) +refattrA.setObject(aResultA) +refattrB.setObject(aResultB) +aDocument.finishOperation() +# print "Link lines with parallel constraint" +# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() +# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() +# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() +# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() +# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() +# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() +# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() +# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +#========================================================================= +# Check values and move one constrainted object +#========================================================================= +deltaX = deltaY = 10. +# rotate line, check that reference's line points are moved also +aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, + aLineAStartPoint.y() + deltaY) +aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, + aLineAEndPoint.y() - deltaY) +# print "Rotate line, check that reference's line points are moved also" +# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() +# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() +# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() +# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() +# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() +# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() +# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() +# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintPerpendicular.py b/src/SketchPlugin/Test/TestConstraintPerpendicular.py new file mode 100644 index 000000000..8f8f253de --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintPerpendicular.py @@ -0,0 +1,150 @@ +""" + TestConstraintPerpendicular.py + Unit test of SketchPlugin_ConstraintPerpendicular class + + SketchPlugin_Constraint + static const std::string MY_CONSTRAINT_VALUE("ConstraintValue"); + static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); + static const std::string MY_ENTITY_A("ConstraintEntityA"); + static const std::string MY_ENTITY_B("ConstraintEntityB"); + static const std::string MY_ENTITY_C("ConstraintEntityC"); + static const std::string MY_ENTITY_D("ConstraintEntityD"); + + SketchPlugin_ConstraintPerpendicular + static const std::string MY_CONSTRAINT_PERPENDICULAR_ID("SketchConstraintPerpendicular"); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); +""" +from GeomDataAPI import * +from ModelAPI import * +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2014-07-29" + +aPluginManager = ModelAPI_PluginManager.get() +aDocument = aPluginManager.rootDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aDocument.startOperation() +aSketchFeature = aDocument.addFeature("Sketch") +aSketchFeatureData = aSketchFeature.data() +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm.setValue(0, 0, 1) +aDocument.finishOperation() +#========================================================================= +# Create two lines which are already perpendicular +#========================================================================= +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +# line A +aSketchLineA = aDocument.addFeature("SketchLine") +aSketchReflist.append(aSketchLineA) +aLineAStartPoint = geomDataAPI_Point2D( + aSketchLineA.data().attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D( + aSketchLineA.data().attribute("EndPoint")) +aSketchLineB = aDocument.addFeature("SketchLine") +aLineAStartPoint.setValue(0., 25) +aLineAEndPoint.setValue(85., 25) +# line B +aSketchReflist.append(aSketchLineB) +aLineBStartPoint = geomDataAPI_Point2D( + aSketchLineB.data().attribute("StartPoint")) +aLineBEndPoint = geomDataAPI_Point2D( + aSketchLineB.data().attribute("EndPoint")) +aLineBStartPoint.setValue(25., 40.) +aLineBEndPoint.setValue(25., 125.) +aDocument.finishOperation() +#========================================================================= +# Make a constraint to keep the length of the line constant +# to prevent perpendicular constraint collapsing line to point +#========================================================================= +aDocument.startOperation() +aLengthConstraint = aDocument.addFeature("SketchConstraintLength") +aSketchReflist.append(aLengthConstraint) +aLengthConstraintData = aLengthConstraint.data() +refattrA = aLengthConstraintData.refattr("ConstraintEntityA") +aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult()) +assert (aResultA is not None) +refattrA.setObject(aResultA) +aDocument.finishOperation() +# Coordinates of lines should not be changed after this constraint +assert (aLineAStartPoint.x() == 0) +assert (aLineAStartPoint.y() == 25) +assert (aLineAEndPoint.x() == 85) +assert (aLineAEndPoint.y() == 25) +assert (aLineBStartPoint.x() == 25) +assert (aLineBStartPoint.y() == 40) +assert (aLineBEndPoint.x() == 25) +assert (aLineBEndPoint.y() == 125) +#========================================================================= +# Link lines with perpendicular constraint +#========================================================================= +aDocument.startOperation() +aParallelConstraint = aDocument.addFeature("SketchConstraintParallel") +aSketchReflist.append(aParallelConstraint) +aConstraintData = aParallelConstraint.data() +refattrA = aConstraintData.refattr("ConstraintEntityA") +refattrB = aConstraintData.refattr("ConstraintEntityB") +# aResultA is already defined for the length constraint +aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult()) +assert (aResultB is not None) +refattrA.setObject(aResultA) +refattrB.setObject(aResultB) +aDocument.finishOperation() +#========================================================================= +# Check values and move one constrainted object +#========================================================================= +# print "Check values and move one constrainted object" +# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() +# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() +# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() +# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() +# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() +# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() +# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() +# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +deltaX = deltaY = 5. +# move line without rotation, +# check that reference's line points are not changed also +aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, + aLineAStartPoint.y() + deltaY) +aLineAEndPoint.setValue(aLineAEndPoint.x() + deltaX, + aLineAEndPoint.y() + deltaY) +# print "move line without rotation" +# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() +# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() +# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() +# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() +# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() +# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() +# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() +# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() + +# rotate line, check that reference's line points are moved also +aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, + aLineAStartPoint.y() + deltaY) +aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, + aLineAEndPoint.y() - deltaY) +# print "Rotate line, check that reference's line points are moved also" +# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() +# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() +# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() +# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() +# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() +# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() +# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() +# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintRadius.py b/src/SketchPlugin/Test/TestConstraintRadius.py new file mode 100644 index 000000000..885c385d7 --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintRadius.py @@ -0,0 +1,140 @@ +""" + TestConstraintRadius.py + Unit test of SketchPlugin_ConstraintRadius class + + SketchPlugin_Constraint + static const std::string MY_CONSTRAINT_VALUE("ConstraintValue"); + static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); + static const std::string MY_ENTITY_A("ConstraintEntityA"); + static const std::string MY_ENTITY_B("ConstraintEntityB"); + static const std::string MY_ENTITY_C("ConstraintEntityC"); + static const std::string MY_ENTITY_D("ConstraintEntityD"); + + SketchPlugin_ConstraintRadius + static const std::string MY_CONSTRAINT_RADIUS_ID("SketchConstraintRadius"); + data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); + +""" +from GeomDataAPI import * +from ModelAPI import * +import math +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2014-07-29" + +aPluginManager = ModelAPI_PluginManager.get() +aDocument = aPluginManager.rootDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aDocument.startOperation() +aSketchFeature = aDocument.addFeature("Sketch") +aSketchFeatureData = aSketchFeature.data() +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm.setValue(0, 0, 1) +aDocument.finishOperation() +#========================================================================= +# Creation of an arc and a circle +#========================================================================= +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +aSketchArc = aDocument.addFeature("SketchArc") +aSketchReflist.append(aSketchArc) +aSketchArcData = aSketchArc.data() +anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter")) +anArcCentr.setValue(10., 10.) +anArcStartPoint = geomDataAPI_Point2D( + aSketchArcData.attribute("ArcStartPoint")) +anArcStartPoint.setValue(0., 50.) +anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint")) +anArcEndPoint.setValue(50., 0.) +aDocument.finishOperation() +# Circle +aDocument.startOperation() +aSketchCircle = aDocument.addFeature("SketchCircle") +aSketchReflist.append(aSketchCircle) +aSketchCircleData = aSketchCircle.data() +anCircleCentr = geomDataAPI_Point2D( + aSketchCircleData.attribute("CircleCenter")) +aCircleRadius = aSketchCircleData.real("CircleRadius") +anCircleCentr.setValue(-25., -25) +aCircleRadius.setValue(25.) +aDocument.finishOperation() +#========================================================================= +# Make a constraint to keep the radius of the arc +#========================================================================= +aDocument.startOperation() +aConstraint = aDocument.addFeature("SketchConstraintRadius") +aSketchReflist.append(aConstraint) +aConstraintData = aConstraint.data() +aRadius = aConstraintData.real("ConstraintValue") +aRefObject = aConstraintData.refattr("ConstraintEntityA") +aResult = aSketchArc.firstResult() +assert (aResult is not None) +aRefObject.setObject(modelAPI_ResultConstruction(aResult)) +aDocument.finishOperation() +assert (aRadius.isInitialized()) +assert (aRefObject.isInitialized()) +#========================================================================= +# Make a constraint to keep the radius of the circle +#========================================================================= +aDocument.startOperation() +aConstraint = aDocument.addFeature("SketchConstraintRadius") +aSketchReflist.append(aConstraint) +aConstraintData = aConstraint.data() +aRadius = aConstraintData.real("ConstraintValue") +aRefObject = aConstraintData.refattr("ConstraintEntityA") +aResult = aSketchCircle.firstResult() +assert (aResult is not None) +aRefObject.setObject(modelAPI_ResultConstruction(aResult)) +aDocument.finishOperation() +assert (aRadius.isInitialized()) +assert (aRefObject.isInitialized()) +#========================================================================= +# Perform some actions and checks: +# 1. Check that constraints does not changes values +# 2. Move one point of the arc +# 3. Check that second point is moved also +#========================================================================= +assert (anArcCentr.x() == 10.) +assert (anArcCentr.y() == 10.) +assert (anArcStartPoint.x() == 0.) +assert (anArcStartPoint.y() == 50.) +anArcPrevEndPointX = anArcEndPoint.x() +anArcPrevEndPointY = anArcEndPoint.y() +assert (anArcPrevEndPointX == 50.) +assert (anArcPrevEndPointY == 0.) +# Move one point of the arc +aDocument.startOperation() +anArcStartPoint.setValue(0., 60) +aDocument.finishOperation() +assert (anArcCentr.x() == 10.) +assert (anArcCentr.y() == 10.) +assert (anArcEndPoint.x() != anArcPrevEndPointX) +assert (anArcEndPoint.y() != anArcPrevEndPointY) +#========================================================================= +# 4. Move the centr or the point of the arc +# 5. Check radius is the same +#========================================================================= +assert (anCircleCentr.x() == -25) +assert (anCircleCentr.y() == -25) +assert (aCircleRadius.value() == 25) +aDocument.startOperation() +anCircleCentr.setValue(100., 100.) +aDocument.finishOperation() +assert (anCircleCentr.x() == 100) +assert (anCircleCentr.y() == 100) +assert (aCircleRadius.value() == 25) +#========================================================================= +# End of test +#========================================================================= -- 2.39.2