From: azv Date: Tue, 17 Mar 2015 11:50:51 +0000 (+0300) Subject: Adjusting test cases for Equal and Tangent constraints X-Git-Tag: V_1.1.0~122^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8434ca0db4587171c770518d8da833c172384ece;p=modules%2Fshaper.git Adjusting test cases for Equal and Tangent constraints --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index d1499da27..e2fc76829 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -93,7 +93,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestConstraintConcidence.py TestConstraintLength.py TestConstraintDistance.py -# TestConstraintParallel.py + TestConstraintParallel.py TestConstraintPerpendicular.py TestConstraintRadius.py TestConstraintRigid.py @@ -101,6 +101,5 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestConstraintVertical.py TestConstraintEqual.py TestConstraintTangent.py - TestConstraintParallel.py TestHighload.py TestSnowflake.py) diff --git a/src/SketchPlugin/Test/TestConstraintEqual.py b/src/SketchPlugin/Test/TestConstraintEqual.py index 66bfc3db2..09f8f076d 100644 --- a/src/SketchPlugin/Test/TestConstraintEqual.py +++ b/src/SketchPlugin/Test/TestConstraintEqual.py @@ -61,8 +61,8 @@ aSession.startOperation() aConstraintEqRad = aSketchFeature.addFeature("SketchConstraintEqual") aRefObjectA = aConstraintEqRad.refattr("ConstraintEntityA") aRefObjectB = aConstraintEqRad.refattr("ConstraintEntityB") -aResultA = modelAPI_ResultConstruction(aSketchArc.firstResult()) -aResultB = modelAPI_ResultConstruction(aSketchCircle.firstResult()) +aResultA = modelAPI_ResultConstruction(aSketchArc.lastResult()) +aResultB = modelAPI_ResultConstruction(aSketchCircle.lastResult()) assert (aResultA is not None) assert (aResultB is not None) aRefObjectA.setObject(aResultA) @@ -72,11 +72,8 @@ aSession.finishOperation() aCircRadius = aCircleRadius.value(); anArcVecX = anArcStartPoint.x() - anArcCentr.x(); anArcVecY = anArcStartPoint.y() - anArcCentr.y(); -anArcRadius = math.sqrt(anArcVecX * anArcVecX + anArcVecY * anArcVecY) -print anArcStartPoint.x(), anArcStartPoint.y() -print anArcCentr.x(), anArcCentr.y() -print aCircRadius, anArcRadius -assert (aCircRadius == anArcRadius) +anArcRadius = math.sqrt(anArcVecX**2 + anArcVecY**2) +assert (math.fabs(aCircRadius - anArcRadius) <= 1.e-10) #========================================================================= # Creation of two different lines #========================================================================= @@ -116,7 +113,7 @@ aVecY = aLine1StartPoint.y() - aLine1EndPoint.y(); aLine1Len = math.sqrt(anArcVecX * anArcVecX + anArcVecY * anArcVecY) aVecX = aLine2StartPoint.x() - aLine2EndPoint.x(); aVecY = aLine2StartPoint.y() - aLine2EndPoint.y(); -aLine2Len = math.sqrt(anArcVecX * anArcVecX + anArcVecY * anArcVecY) +aLine2Len = math.sqrt(anArcVecX**2 + anArcVecY**2) assert (aLine1Len == aLine2Len) #========================================================================= # End of test diff --git a/src/SketchPlugin/Test/TestConstraintTangent.py b/src/SketchPlugin/Test/TestConstraintTangent.py index 2eeb02514..df753488a 100644 --- a/src/SketchPlugin/Test/TestConstraintTangent.py +++ b/src/SketchPlugin/Test/TestConstraintTangent.py @@ -36,7 +36,9 @@ norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")) norm.setValue(0, 0, 1) aSession.finishOperation() #========================================================================= -# Creation of an arc and a line +# TEST 1. Arc-line tangency +#========================================================================= +# Creation of an arc and two lines #========================================================================= # Arc aSession.startOperation() @@ -48,23 +50,39 @@ anArcStartPoint.setValue(0., 50.) anArcEndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcEndPoint")) anArcEndPoint.setValue(50., 0.) aSession.finishOperation() -# Line +# Line 1 aSession.startOperation() aSketchLine1 = aSketchFeature.addFeature("SketchLine") -aLineStartPoint = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint")) -aLineEndPoint = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint")) -aLineStartPoint.setValue(0., 50.) -aLineEndPoint.setValue(0., 100.) +aLine1StartPoint = geomDataAPI_Point2D(aSketchLine1.attribute("StartPoint")) +aLine1EndPoint = geomDataAPI_Point2D(aSketchLine1.attribute("EndPoint")) +aLine1StartPoint.setValue(0., 50.) +aLine1EndPoint.setValue(0., 100.) +aSession.finishOperation() +# Line 2 +aSession.startOperation() +aSketchLine2 = aSketchFeature.addFeature("SketchLine") +aLine2StartPoint = geomDataAPI_Point2D(aSketchLine2.attribute("StartPoint")) +aLine2EndPoint = geomDataAPI_Point2D(aSketchLine2.attribute("EndPoint")) +aLine2StartPoint.setValue(50., 0.) +aLine2EndPoint.setValue(100., 0.) aSession.finishOperation() #========================================================================= -# Link arc start point and line's point by the coincidence constraint +# Link arc points and lines points by the coincidence constraint #========================================================================= aSession.startOperation() aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") reflistA = aConstraint.refattr("ConstraintEntityA") reflistB = aConstraint.refattr("ConstraintEntityB") reflistA.setAttr(anArcStartPoint) -reflistB.setAttr(aLineStartPoint) +reflistB.setAttr(aLine1StartPoint) +aConstraint.execute() +aSession.finishOperation() +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") +reflistA = aConstraint.refattr("ConstraintEntityA") +reflistB = aConstraint.refattr("ConstraintEntityB") +reflistA.setAttr(anArcEndPoint) +reflistB.setAttr(aLine2StartPoint) aConstraint.execute() aSession.finishOperation() #========================================================================= @@ -74,7 +92,7 @@ aSession.startOperation() aTangency = aSketchFeature.addFeature("SketchConstraintTangent") aRefObjectA = aTangency.refattr("ConstraintEntityA") aRefObjectB = aTangency.refattr("ConstraintEntityB") -anObjectA = modelAPI_ResultConstruction(aSketchArc1.firstResult()) +anObjectA = modelAPI_ResultConstruction(aSketchArc1.lastResult()) anObjectB = modelAPI_ResultConstruction(aSketchLine1.firstResult()) assert (anObjectA is not None) assert (anObjectB is not None) @@ -84,14 +102,125 @@ aTangency.execute() aSession.finishOperation() anArcVecX = anArcStartPoint.x() - anArcCentr.x() anArcVecY = anArcStartPoint.y() - anArcCentr.y() -aLineVecX = aLineEndPoint.x() - aLineStartPoint.x() -aLineVecY = aLineEndPoint.y() - aLineStartPoint.y() +aLineVecX = aLine1EndPoint.x() - aLine1StartPoint.x() +aLineVecY = aLine1EndPoint.y() - aLine1StartPoint.y() +aDot = anArcVecX * aLineVecX + anArcVecY * aLineVecY +assert(math.fabs(aDot) <= 1.e-12) +#========================================================================= +# Add tangency constraint for arc and second line and check correctness +#========================================================================= +aSession.startOperation() +aTangency = aSketchFeature.addFeature("SketchConstraintTangent") +aRefObjectA = aTangency.refattr("ConstraintEntityA") +aRefObjectB = aTangency.refattr("ConstraintEntityB") +anObjectA = modelAPI_ResultConstruction(aSketchArc1.lastResult()) +anObjectB = modelAPI_ResultConstruction(aSketchLine2.firstResult()) +assert (anObjectA is not None) +assert (anObjectB is not None) +aRefObjectA.setObject(anObjectA) +aRefObjectB.setObject(anObjectB) +aTangency.execute() +aSession.finishOperation() +anArcVecX = anArcEndPoint.x() - anArcCentr.x() +anArcVecY = anArcEndPoint.y() - anArcCentr.y() +aLineVecX = aLine2EndPoint.x() - aLine2StartPoint.x() +aLineVecY = aLine2EndPoint.y() - aLine2StartPoint.y() aDot = anArcVecX * aLineVecX + anArcVecY * aLineVecY -print anArcVecX, anArcVecY -print aLineVecX, aLineVecY -print aDot -print aLineStartPoint.x(), aLineStartPoint.y(), aLineEndPoint.x(), aLineEndPoint.y() -assert(aDot == 0.) +assert(math.fabs(aDot) <= 1.e-12) + +#========================================================================= +# TEST 2. Arc-arc tangency +#========================================================================= +# Creation of arcs +#========================================================================= +# Arc 1 +aSession.startOperation() +aSketchArc1 = aSketchFeature.addFeature("SketchArc") +anArc1Centr = geomDataAPI_Point2D(aSketchArc1.attribute("ArcCenter")) +anArc1Centr.setValue(10., 10.) +anArc1StartPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcStartPoint")) +anArc1StartPoint.setValue(50., 0.) +anArc1EndPoint = geomDataAPI_Point2D(aSketchArc1.attribute("ArcEndPoint")) +anArc1EndPoint.setValue(0., 50.) +aSession.finishOperation() +# Arc 2 +aSession.startOperation() +aSketchArc2 = aSketchFeature.addFeature("SketchArc") +anArc2Centr = geomDataAPI_Point2D(aSketchArc2.attribute("ArcCenter")) +anArc2Centr.setValue(-10., 10.) +anArc2StartPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcStartPoint")) +anArc2StartPoint.setValue(0., 50.) +anArc2EndPoint = geomDataAPI_Point2D(aSketchArc2.attribute("ArcEndPoint")) +anArc2EndPoint.setValue(-50., 0.) +aSession.finishOperation() +#========================================================================= +# Link points of arcs by the coincidence constraint +#========================================================================= +aSession.startOperation() +aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") +reflistA = aConstraint.refattr("ConstraintEntityA") +reflistB = aConstraint.refattr("ConstraintEntityB") +reflistA.setAttr(anArc1EndPoint) +reflistB.setAttr(anArc2StartPoint) +aConstraint.execute() +aSession.finishOperation() +#========================================================================= +# Add tangency constraint and check correctness +#========================================================================= +aSession.startOperation() +aTangency = aSketchFeature.addFeature("SketchConstraintTangent") +aRefObjectA = aTangency.refattr("ConstraintEntityA") +aRefObjectB = aTangency.refattr("ConstraintEntityB") +anObjectA = modelAPI_ResultConstruction(aSketchArc1.lastResult()) +anObjectB = modelAPI_ResultConstruction(aSketchArc2.lastResult()) +assert (anObjectA is not None) +assert (anObjectB is not None) +aRefObjectA.setObject(anObjectA) +aRefObjectB.setObject(anObjectB) +aTangency.execute() +aSession.finishOperation() +anArc1VecX = anArc1EndPoint.x() - anArc1Centr.x() +anArc1VecY = anArc1EndPoint.y() - anArc1Centr.y() +anArc2VecX = anArc2StartPoint.x() - anArc2Centr.x() +anArc2VecY = anArc2StartPoint.y() - anArc2Centr.y() +aCross = anArc1VecX * anArc2VecY - anArc1VecY * anArc2VecX +assert(math.fabs(aCross) <= 1.e-12) + +#========================================================================= +# TEST 3. Tangency between non-connected objects should be wrong +#========================================================================= +# Store data +aLine2StartPointPrev = (aLine2StartPoint.x(), aLine2StartPoint.y()) +aLine2EndPointPrev = (aLine2EndPoint.x(), aLine2EndPoint.y()) +anArc2CenterPrev = (anArc2Centr.x(), anArc2Centr.y()) +anArc2StartPointPrev = (anArc2StartPoint.x(), anArc2StartPoint.y()) +anArc2EndPointPrev = (anArc2EndPoint.x(), anArc2EndPoint.y()) +#========================================================================= +# Add tangency between arc2 and line2 +#========================================================================= +aSession.startOperation() +aTangency = aSketchFeature.addFeature("SketchConstraintTangent") +aRefObjectA = aTangency.refattr("ConstraintEntityA") +aRefObjectB = aTangency.refattr("ConstraintEntityB") +anObjectA = modelAPI_ResultConstruction(aSketchArc2.lastResult()) +anObjectB = modelAPI_ResultConstruction(aSketchLine2.firstResult()) +assert (anObjectA is not None) +assert (anObjectB is not None) +aRefObjectA.setObject(anObjectA) +aRefObjectB.setObject(anObjectB) +aTangency.execute() +aSession.finishOperation() +# Check that nothing is changed +aLine2StartPointNew = (aLine2StartPoint.x(), aLine2StartPoint.y()) +aLine2EndPointNew = (aLine2EndPoint.x(), aLine2EndPoint.y()) +anArc2CenterNew = (anArc2Centr.x(), anArc2Centr.y()) +anArc2StartPointNew = (anArc2StartPoint.x(), anArc2StartPoint.y()) +anArc2EndPointNew = (anArc2EndPoint.x(), anArc2EndPoint.y()) +assert(aLine2StartPointNew == aLine2StartPointPrev) +assert(aLine2EndPointNew == aLine2EndPointPrev) +assert(anArc2CenterNew == anArc2CenterPrev) +assert(anArc2StartPointNew == anArc2StartPointPrev) +assert(anArc2EndPointNew == anArc2EndPointPrev) #========================================================================= # End of test #=========================================================================