From: azv Date: Mon, 16 May 2016 09:26:59 +0000 (+0300) Subject: Update unit-tests for SketchPlugin. Test case for the Projection has been added X-Git-Tag: V_2.3.1~89 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ad84ec41d7f40729d3aef2a1a3fdb4e102d84b82;p=modules%2Fshaper.git Update unit-tests for SketchPlugin. Test case for the Projection has been added --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 3e842fe3e..944181bf5 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -122,11 +122,12 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestConstraintEqual.py TestConstraintTangent.py TestConstraintMirror.py - #TestConstraintAngle.py + TestConstraintAngle.py TestConstraintMiddlePoint.py TestMultiRotation.py TestMultiTranslation.py TestFillet.py TestRectangle.py + TestProjection.py TestHighload.py TestSnowflake.py) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index ea131563f..962ddfbc8 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -61,75 +61,8 @@ void SketchPlugin_ConstraintDistance::execute() return; double aDistance = calculateCurrentDistance(); - if(aDistance >= 0) { + if(aDistance >= 0) anAttrValue->setValue(aDistance); - } - - // the value should to be computed here, not in the getAISObject in order to change the model value - // inside the object transaction. This is important for creating a constraint by preselection. - // The display of the presentation in this case happens after the transaction commit - std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - if(!aFlyOutAttr->isInitialized()) - compute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT()); -} - -bool SketchPlugin_ConstraintDistance::compute(const std::string& theAttributeId) -{ - if (theAttributeId != SketchPlugin_Constraint::FLYOUT_VALUE_PNT()) - return false; - - if (!sketch()) - return false; - - std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(attribute(theAttributeId)); - if (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance) - return false; - - DataPtr aData = data(); - std::shared_ptr aPlane = SketchPlugin_Sketch::plane(sketch()); - std::shared_ptr aPoint_A = SketcherPrs_Tools::getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_A(), aPlane); - std::shared_ptr aPoint_B = SketcherPrs_Tools::getFeaturePoint( - aData, SketchPlugin_Constraint::ENTITY_B(), aPlane); - - std::shared_ptr aPnt_A; - std::shared_ptr aPnt_B; - - if (aPoint_A && aPoint_B) { - aPnt_A = aPoint_A->pnt(); - aPnt_B = aPoint_B->pnt(); - } else if (!aPoint_A && aPoint_B) { - FeaturePtr aLine = SketcherPrs_Tools::getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_A()); - if (aLine) { - aPnt_B = aPoint_B->pnt(); - aPnt_A = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_B); - } - } else if (aPoint_A && !aPoint_B) { - FeaturePtr aLine = SketcherPrs_Tools::getFeatureLine( - aData, SketchPlugin_Constraint::ENTITY_B()); - if (aLine) { - aPnt_A = aPoint_A->pnt(); - aPnt_B = SketcherPrs_Tools::getProjectionPoint(aLine, aPnt_A); - } - } - if (!aPnt_A || !aPnt_B) - return false; - - std::shared_ptr aPoint1 = sketch()->to3D(aPnt_A->x(), aPnt_A->y()); - std::shared_ptr aPoint2 = sketch()->to3D(aPnt_B->x(), aPnt_B->y()); - // it is not possible to create lin2d on the points with equal position - if (aPoint1->distance(aPoint2) < tolerance) - return false; - - std::shared_ptr aLine = std::shared_ptr(new GeomAPI_Lin2d(aPnt_A, aPnt_B)); - double aDist = aPoint1->distance(aPoint2)/5.; - std::shared_ptr aFPnt = aLine->shiftedLocation(aDist); - aFlyOutAttr->setValue(aFPnt); - - return true; } //************************************************************************************* diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h index 4edc829a4..ef9e3eb1a 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.h @@ -47,11 +47,6 @@ class SketchPlugin_ConstraintDistance : public SketchPlugin_ConstraintBase /// \brief Creates a new part document if needed SKETCHPLUGIN_EXPORT virtual void execute(); - /// Computes the attribute value on the base of other attributes if the value can be computed - /// \param theAttributeId an attribute index to be computed - /// \return a boolean value about it is computed - SKETCHPLUGIN_EXPORT virtual bool compute(const std::string& theAttributeId); - /// \brief Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); diff --git a/src/SketchPlugin/Test/TestConstraintAngle.py b/src/SketchPlugin/Test/TestConstraintAngle.py index 43b8ff000..bc0214d2b 100644 --- a/src/SketchPlugin/Test/TestConstraintAngle.py +++ b/src/SketchPlugin/Test/TestConstraintAngle.py @@ -46,6 +46,10 @@ def angle(theLine1, theLine2): __updated__ = "2015-09-18" +ANGLE_DIRECT = 0 +ANGLE_COMPLEMENTARY = 1 +ANGLE_BACKWARD = 2 + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() #========================================================================= @@ -83,15 +87,16 @@ aSession.finishOperation() ANGLE_DEGREE = 30. aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintAngle") -anAngleVal = aConstraint.real("ConstraintValue") +aConstraint.integer("AngleType").setValue(ANGLE_DIRECT) +anAngleVal = aConstraint.real("AngleValue") refattrA = aConstraint.refattr("ConstraintEntityA") refattrB = aConstraint.refattr("ConstraintEntityB") assert (not anAngleVal.isInitialized()) assert (not refattrA.isInitialized()) assert (not refattrB.isInitialized()) -anAngleVal.setValue(ANGLE_DEGREE) refattrA.setObject(aSketchLineA.firstResult()) refattrB.setObject(aSketchLineB.firstResult()) +anAngleVal.setValue(ANGLE_DEGREE) aConstraint.execute() aSession.finishOperation() assert (anAngleVal.isInitialized()) @@ -117,6 +122,17 @@ aConstraint.execute() aSession.finishOperation() assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE) #========================================================================= +# Change angle type +#========================================================================= +aSession.startOperation() +aConstraint.integer("AngleType").setValue(ANGLE_COMPLEMENTARY) +aSession.finishOperation() +assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE) +aSession.startOperation() +aConstraint.integer("AngleType").setValue(ANGLE_BACKWARD) +aSession.finishOperation() +assert (angle(aSketchLineA, aSketchLineB) == NEW_ANGLE_DEGREE) +#========================================================================= # TODO: improve test # 1. remove constraint, move line's start point to # check that constraint are not applied diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index 18998c5fa..75ea58854 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -104,6 +104,8 @@ assert (aLineResult is not None) aConstraint.execute() refattrA.setAttr(aSketchPointCoords) refattrB.setAttr(aLineAStartPoint) +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +aFlyoutPoint.setValue(50.0, 100.0) aSession.finishOperation() assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) @@ -152,6 +154,8 @@ aLineResult = aSketchLine.firstResult() assert (aLineResult is not None) refattrA.setObject(aLineResult) refattrB.setAttr(aSketchPointCoords) +aFlyoutPoint = geomDataAPI_Point2D(aConstraint.attribute("ConstraintFlyoutValuePnt")) +aFlyoutPoint.setValue(50.0, 100.0) aSession.finishOperation() assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) diff --git a/src/SketchPlugin/Test/TestConstraintRadius.py b/src/SketchPlugin/Test/TestConstraintRadius.py index b3bacf265..edc37350b 100644 --- a/src/SketchPlugin/Test/TestConstraintRadius.py +++ b/src/SketchPlugin/Test/TestConstraintRadius.py @@ -26,6 +26,16 @@ import math __updated__ = "2014-10-28" +def distancePointPoint(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) + + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() #========================================================================= @@ -72,6 +82,12 @@ aCircleRadius = aSketchCircle.real("CircleRadius") anCircleCentr.setValue(-25., -25) aCircleRadius.setValue(25.) aSession.finishOperation() +# Change the radius of the arc +aSession.startOperation() +RADIUS = 40 +anArcRadius = aSketchArc.real("ArcRadius") +anArcRadius.setValue(RADIUS) +aSession.finishOperation() #========================================================================= # Make a constraint to keep the radius of the arc #========================================================================= @@ -79,7 +95,7 @@ aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintRadius") aRadius = aConstraint.real("ConstraintValue") aRefObject = aConstraint.refattr("ConstraintEntityA") -aResult = aSketchArc.firstResult() +aResult = aSketchArc.lastResult() assert (aResult is not None) aRefObject.setObject(modelAPI_ResultConstruction(aResult)) aConstraint.execute() @@ -93,7 +109,7 @@ aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintRadius") aRadius = aConstraint.real("ConstraintValue") aRefObject = aConstraint.refattr("ConstraintEntityA") -aResult = aSketchCircle.firstResult() +aResult = aSketchCircle.lastResult() assert (aResult is not None) aRefObject.setObject(modelAPI_ResultConstruction(aResult)) aConstraint.execute() @@ -106,23 +122,18 @@ assert (aRefObject.isInitialized()) # 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.) +assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10) +assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10) anArcPrevEndPointX = anArcEndPoint.x() anArcPrevEndPointY = anArcEndPoint.y() -assert (anArcPrevEndPointX == 50.) -assert (anArcPrevEndPointY == 0.) # Move one point of the arc aSession.startOperation() anArcStartPoint.setValue(0, 60) aSession.finishOperation() -assert (anArcCentr.x() == 10.) -assert (anArcCentr.y() == 10.) -# MPV: it just projects back to the circle the moved start point -#assert (anArcEndPoint.x() != anArcPrevEndPointX) -#assert (anArcEndPoint.y() != anArcPrevEndPointY) +assert (anArcEndPoint.x() != anArcPrevEndPointX) +assert (anArcEndPoint.y() != anArcPrevEndPointY) +assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10) +assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10) #========================================================================= # 4. Move the centr or the point of the arc # 5. Check radius is the same diff --git a/src/SketchPlugin/Test/TestProjection.py b/src/SketchPlugin/Test/TestProjection.py new file mode 100644 index 000000000..909d079be --- /dev/null +++ b/src/SketchPlugin/Test/TestProjection.py @@ -0,0 +1,139 @@ +""" + TestProjection.py + Unit test of SketchPlugin_Projection class + +""" +from GeomDataAPI import * +from ModelAPI import * +import math +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2016-05-16" + + +#========================================================================= +# Start of test +#========================================================================= +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch")) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Create a line, circle and arc +#========================================================================= +aSession.startOperation() +aLine = aSketchFeature.addFeature("SketchLine") +aLineStart = geomDataAPI_Point2D(aLine.attribute("StartPoint")) +aLineEnd = geomDataAPI_Point2D(aLine.attribute("EndPoint")) +aLineStart.setValue(10., 10.) +aLineEnd.setValue(40., 30.) + +aCircle = aSketchFeature.addFeature("SketchCircle") +aCircleCenter = geomDataAPI_Point2D(aCircle.attribute("CircleCenter")) +aCircleRadius = aCircle.real("CircleRadius") +aCircleCenter.setValue(-25., -25) +aCircleRadius.setValue(25.) + +anArc = aSketchFeature.addFeature("SketchArc") +anArcCenter = geomDataAPI_Point2D(anArc.attribute("ArcCenter")) +anArcStart = geomDataAPI_Point2D(anArc.attribute("ArcStartPoint")) +anArcEnd = geomDataAPI_Point2D(anArc.attribute("ArcEndPoint")) +anArcCenter.setValue(10., 10.) +anArcStart.setValue(50., 0.) +anArcEnd.setValue(0., 50.) +aSession.finishOperation() +#========================================================================= +# Create another sketch +#========================================================================= +aSession.startOperation() +aSketchFeature = featureToCompositeFeature(aDocument.addFeature("Sketch")) +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 10) +dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSession.finishOperation() +#========================================================================= +# Project all features onto the new sketch +#========================================================================= +aSession.startOperation() +anExtLineRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchLine_1")) +assert(anExtLineRes) +anExtLineShape = anExtLineRes.shape() +assert(anExtLineShape) +aLineProjector = aSketchFeature.addFeature("SketchProjection") +aLineProjector.selection("ExternalFeature").setValue(anExtLineRes, anExtLineShape) +aLineProjector.execute() + +anExtCircRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchCircle_1_2")) +assert(anExtCircRes) +anExtCircShape = anExtCircRes.shape() +assert(anExtCircShape) +aCircleProjector = aSketchFeature.addFeature("SketchProjection") +aCircleProjector.selection("ExternalFeature").setValue(anExtCircRes, anExtCircShape) +aCircleProjector.execute() + +anExtArcRes = modelAPI_Result(aDocument.objectByName("Construction", "SketchArc_1_2")) +assert(anExtArcRes) +anExtArcShape = anExtArcRes.shape() +assert(anExtArcShape) +anArcProjector = aSketchFeature.addFeature("SketchProjection") +anArcProjector.selection("ExternalFeature").setValue(anExtArcRes, anExtArcShape) +anArcProjector.execute() +aSession.finishOperation() +#========================================================================= +# Check projection coordinates +#========================================================================= +aProjLine = ModelAPI_Feature.feature(aLineProjector.refattr("ProjectedFeature").object()) +assert(aProjLine) +aProjLineStart = geomDataAPI_Point2D(aProjLine.attribute("StartPoint")) +aProjLineEnd = geomDataAPI_Point2D(aProjLine.attribute("EndPoint")) +assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10) +assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10) +assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10) +assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10) + +aProjCircle = ModelAPI_Feature.feature(aCircleProjector.refattr("ProjectedFeature").object()) +assert(aProjCircle) +aProjCircleCenter = geomDataAPI_Point2D(aProjCircle.attribute("CircleCenter")) +aProjCircleRadius = aProjCircle.real("CircleRadius") +assert(math.fabs(aProjCircleCenter.x() - aCircleCenter.x()) < 1.e-10) +assert(math.fabs(aProjCircleCenter.y() - aCircleCenter.y()) < 1.e-10) +assert(math.fabs(aProjCircleRadius.value() - aCircleRadius.value()) < 1.e-10) + +aProjArc = ModelAPI_Feature.feature(anArcProjector.refattr("ProjectedFeature").object()) +aProjArcCenter = geomDataAPI_Point2D(aProjArc.attribute("ArcCenter")) +aProjArcStart = geomDataAPI_Point2D(aProjArc.attribute("ArcStartPoint")) +aProjArcEnd = geomDataAPI_Point2D(aProjArc.attribute("ArcEndPoint")) +assert(math.fabs(aProjArcCenter.x() - anArcCenter.x()) < 1.e-10) +assert(math.fabs(aProjArcCenter.y() - anArcCenter.y()) < 1.e-10) +assert(math.fabs(aProjArcStart.x() - anArcStart.x()) < 1.e-10) +assert(math.fabs(aProjArcStart.y() - anArcStart.y()) < 1.e-10) +assert(math.fabs(aProjArcEnd.x() - anArcEnd.x()) < 1.e-10) +assert(math.fabs(aProjArcEnd.y() - anArcEnd.y()) < 1.e-10) +#========================================================================= +# Move original feature and check the projection is agreed +#========================================================================= +aSession.startOperation() +aLineStart.setValue(20., 0.) +aSession.finishOperation() +assert(math.fabs(aProjLineStart.x() - aLineStart.x()) < 1.e-10) +assert(math.fabs(aProjLineStart.y() - aLineStart.y()) < 1.e-10) +assert(math.fabs(aProjLineEnd.x() - aLineEnd.x()) < 1.e-10) +assert(math.fabs(aProjLineEnd.y() - aLineEnd.y()) < 1.e-10) +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchPlugin/Test/TestSketchArcCircle.py b/src/SketchPlugin/Test/TestSketchArcCircle.py index 9ab1394e0..83169611b 100644 --- a/src/SketchPlugin/Test/TestSketchArcCircle.py +++ b/src/SketchPlugin/Test/TestSketchArcCircle.py @@ -21,9 +21,39 @@ #========================================================================= from GeomDataAPI import * from ModelAPI import * +import math __updated__ = "2014-10-28" + +#========================================================================= +# Auxiliary functions +#========================================================================= + +def angle(theCenter, theFirst, theLast): + """ + subroutine to calculate angle given by 3 points + """ + aDirX1 = theFirst.x() - theCenter.x() + aDirY1 = theFirst.y() - theCenter.y() + aLen1 = math.hypot(aDirX1, aDirY1) + aDirX2 = theLast.x() - theCenter.x() + aDirY2 = theLast.y() - theCenter.y() + aLen2 = math.hypot(aDirX2, aDirY2) + aDot = aDirX1 * aDirX2 + aDirY1 * aDirY2 + anAngle = math.acos(aDot / aLen1 / aLen2) + return round(anAngle * 180. / math.pi, 6) + +def distancePointPoint(thePointA, thePointB): + """ + subroutine to calculate distance between two points + result of calculated distance is has 10**-5 precision + """ + xdiff = math.pow((thePointA.x() - thePointB.x()), 2) + ydiff = math.pow((thePointA.y() - thePointB.y()), 2) + return round(math.sqrt(xdiff + ydiff), 5) + + aSession = ModelAPI_Session.get() aDocument = aSession.moduleDocument() #========================================================================= @@ -83,34 +113,36 @@ assert (anArcEndPoint.y() == 0.0) # Edit the arc: # 1. Move whole arc # 2. Change the start point +# 3. Change the radius of arc +# 4. Change arc's angle #========================================================================= - -# MPV: movement now is done little bit in different way, just move points causes changing them -# back t okeep the radius unchanged (projection back to the initial circle) -#aSession.startOperation() -#deltaX, deltaY = 5., 10. -#anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY) -#anArcStartPoint.setValue( -# anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY) -#anArcEndPoint.setValue(anArcEndPoint.x() + deltaX, anArcEndPoint.y() + deltaY) -#aSession.finishOperation() -#assert (anArcCentr.y() == 20) -#assert (anArcStartPoint.x() == 5) -#assert (anArcStartPoint.y() == 60) -#assert (anArcEndPoint.x() == 55) -#assert (anArcEndPoint.y() == 10) -## Change the start point -#aSession.startOperation() -#anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y()) -#aPrevEndPointX = anArcEndPoint.x() -#aPrevEndPointY = anArcEndPoint.y() -#aSession.finishOperation() -#assert (anArcCentr.x() == 15) -#assert (anArcCentr.y() == 20) -#assert (anArcStartPoint.x() == 10) -#assert (anArcStartPoint.y() == 60) -#assert (anArcEndPoint.x() != aPrevEndPointX) -#assert (anArcEndPoint.y() != aPrevEndPointY) +aSession.startOperation() +deltaX, deltaY = 5., 10. +anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY) +aSession.finishOperation() +assert (anArcCentr.x() == 15) +assert (anArcCentr.y() == 20) +assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - distancePointPoint(anArcCentr, anArcEndPoint)) < 1.e-10) +# Change the start point +aSession.startOperation() +anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y()) +aSession.finishOperation() +assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - distancePointPoint(anArcCentr, anArcEndPoint)) < 1.e-10) +# Change radius +RADIUS = 50 +aSession.startOperation() +anArcRadius = aSketchArc.real("ArcRadius") +anArcRadius.setValue(RADIUS) +aSession.finishOperation() +assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10) +assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10) +# Change angle +ANGLE = 120 +aSession.startOperation() +anArcAngle = aSketchArc.real("ArcAngle") +anArcAngle.setValue(ANGLE) +aSession.finishOperation() +assert (math.fabs(angle(anArcCentr, anArcStartPoint, anArcEndPoint) - ANGLE) < 1.e-7) #========================================================================= # Check results of the Arc #========================================================================= @@ -164,5 +196,38 @@ assert (anCircleCentr.x() == 10) assert (anCircleCentr.y() == 60) assert (aCircleRadius.value() == 20) #========================================================================= +# Create an arc, tangent to the line +#========================================================================= +aSession.startOperation() +aSketchLine = aSketchFeature.addFeature("SketchLine") +aLineStart = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) +aLineEnd = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) +aLineStart.setValue(0., 0.) +aLineEnd.setValue(50., 0.) +aSession.finishOperation() +aSession.startOperation() +aSketchArcTangent = aSketchFeature.addFeature("SketchArc") +aSketchArcTangent.string("ArcType").setValue("Tangent") +anArcEndPoint = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcEndPoint")) +aTangent = aSketchArcTangent.refattr("ArcTangentPoint") +aTangent.setAttr(aLineEnd) +anArcEndPoint.setValue(51., 1.) +anArcEndPoint.setValue(100., 25.) +aSession.finishOperation() +anArcCenter = geomDataAPI_Point2D(aSketchArcTangent.attribute("ArcCenter")) +assert(anArcCenter.x() == 50.) +#========================================================================= +# Create an arc, tangent to the previous arc +#========================================================================= +aSession.startOperation() +aSketchArcTangent2 = aSketchFeature.addFeature("SketchArc") +aSketchArcTangent2.string("ArcType").setValue("Tangent") +anArcEndPoint2 = geomDataAPI_Point2D(aSketchArcTangent2.attribute("ArcEndPoint")) +aTangent = aSketchArcTangent2.refattr("ArcTangentPoint") +aTangent.setAttr(anArcEndPoint) +anArcEndPoint2.setValue(anArcEndPoint.x() + 1, anArcEndPoint.y() + 1) +anArcEndPoint2.setValue(50., 50.) +aSession.finishOperation() +#========================================================================= # End of test #=========================================================================