X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestFillet.py;h=a8b1f08b3a1ea82e8c37d56ee83d81b1c6a495fd;hb=d0f078983d5f74d45a6f28b3a4dfe8feadb2cdf7;hp=39762ed778d19ded02d0327425bad2adb1d5d321;hpb=31ec33a178048ac144d83e3d8e31e131afbb4f14;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestFillet.py b/src/SketchPlugin/Test/TestFillet.py index 39762ed77..a8b1f08b3 100644 --- a/src/SketchPlugin/Test/TestFillet.py +++ b/src/SketchPlugin/Test/TestFillet.py @@ -1,3 +1,23 @@ +## Copyright (C) 2014-2017 CEA/DEN, EDF R&D +## +## This library is free software; you can redistribute it and/or +## modify it under the terms of the GNU Lesser General Public +## License as published by the Free Software Foundation; either +## version 2.1 of the License, or (at your option) any later version. +## +## This library is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public +## License along with this library; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## +## See http:##www.salome-platform.org/ or +## email : webmaster.salome@opencascade.com +## + """ TestFillet.py Unit test of SketchPlugin_Fillet class @@ -75,9 +95,9 @@ def createSketch2(theSketch): allFeatures.append(aSketchLine) # Arc aSketchArc = theSketch.addFeature("SketchArc") - aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint")) - aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint")) - aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter")) + aStartPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("start_point")) + aEndPoint2 = geomDataAPI_Point2D(aSketchArc.attribute("end_point")) + aCenterPoint = geomDataAPI_Point2D(aSketchArc.attribute("center_point")) aCenterPoint.setValue(20., 10.) aStartPoint2.setValue(10., 10.) aEndPoint2.setValue(20., 0.) @@ -104,15 +124,15 @@ def checkSmoothness(theSketch): checkArcLineSmoothness(aConnectedFeatures[1], aConnectedFeatures[0]) def checkArcLineSmoothness(theArc, theLine): - aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter")) - aDistance = distancePointLine(aCenter, theLine) + aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) + aDistance = model.distancePointLine(aCenter, theLine) aRadius = arcRadius(theArc) assert(math.fabs(aRadius - aDistance) < TOLERANCE) def checkArcArcSmoothness(theArc1, theArc2): - aCenter1 = geomDataAPI_Point2D(theArc1.attribute("ArcCenter")) - aCenter2 = geomDataAPI_Point2D(theArc2.attribute("ArcCenter")) - aDistance = distancePointPoint(aCenter1, aCenter2) + aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point")) + aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point")) + aDistance = model.distancePointPoint(aCenter1, aCenter2) aRadius1 = arcRadius(theArc1) aRadius2 = arcRadius(theArc2) aRadSum = aRadius1 + aRadius2 @@ -138,22 +158,9 @@ def connectedFeatures(theCoincidence): return [aFeatureA, aFeatureB] def arcRadius(theArc): - aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter")) - aStart = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint")) - return distancePointPoint(aCenter, aStart) - -def distancePointPoint(thePoint1, thePoint2): - return math.hypot(thePoint1.x() - thePoint2.x(), thePoint1.y() - thePoint2.y()) - -def distancePointLine(thePoint, theLine): - aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint")) - aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint")) - aLength = 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 + aCenter = geomDataAPI_Point2D(theArc.attribute("center_point")) + aStart = geomDataAPI_Point2D(theArc.attribute("start_point")) + return model.distancePointPoint(aCenter, aStart) #========================================================================= @@ -197,7 +204,17 @@ aSession.finishOperation() # Verify the objects of fillet are created #========================================================================= checkSmoothness(aSketchFeature) -assert model.dof(aSketchFeature) == 14, "PlaneGCS limitation: if you see this message, then maybe PlaneGCS has solved DoF for sketch with fillet correctly (expected DoF = 10, observed = {0}".format(model.dof(aSketchFeature)) +assert (model.dof(aSketchFeature) == 10) +#========================================================================= +# Move a line and check the fillet is correct +#========================================================================= +DELTA_X = DELTA_Y = 10. +aSession.startOperation() +aEndPoint1.setValue(aEndPoint1.x() + DELTA_X, aEndPoint1.y() + DELTA_Y) +aSession.finishOperation() +checkSmoothness(aSketchFeature) +assert (model.dof(aSketchFeature) == 10) + #========================================================================= # Create another sketch @@ -228,12 +245,21 @@ aSession.finishOperation() # Verify the objects of fillet are created #========================================================================= checkSmoothness(aSketchFeature) -assert model.dof(aSketchFeature) == 10, "PlaneGCS limitation: if you see this message, then maybe PlaneGCS has solved DoF for sketch with fillet correctly (expected DoF = 8, observed = {0}".format(model.dof(aSketchFeature)) +assert (model.dof(aSketchFeature) == 8) +#========================================================================= +# Move a line and check the fillet is correct +#========================================================================= +DELTA_X = 1. +DELTA_Y = -2. +aSession.startOperation() +aStartPoint1.setValue(aStartPoint1.x() + DELTA_X, aStartPoint1.y() + DELTA_Y) +aSession.finishOperation() +checkSmoothness(aSketchFeature) +assert (model.dof(aSketchFeature) == 8) #========================================================================= # End of test #========================================================================= # TODO: Improve Fillet test case by moving one of filleted objectes and check coincidence and tangency are correct -# TODO: Checking of Python dump has been disabled until the Fillet redesigned. -#assert(model.checkPythonDump()) +assert(model.checkPythonDump())