X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FTest%2FTestFillet.py;h=a8b1f08b3a1ea82e8c37d56ee83d81b1c6a495fd;hb=28038c772769f15a06376fa01d55529e7daa1aa9;hp=fd5ce78bf0d2485d463b3b7a899125b1c1c9b99e;hpb=7470f1b70a31ce0483e168395a43db9c9c93589e;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/Test/TestFillet.py b/src/SketchPlugin/Test/TestFillet.py index fd5ce78bf..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 @@ -123,7 +143,7 @@ def getCoincidences(theSketch): aCoincidences = [] for anIndex in range(0, theSketch.numberOfSubs()): aSubFeature = theSketch.subFeature(anIndex) - if aSubFeature.getKind == "SketchConstraintCoincidence": + if aSubFeature.getKind() == "SketchConstraintCoincidence": anEntityA = aSubFeature.refattr("ConstraintEntityA") anEntityB = aSubFeature.refattr("ConstraintEntityB") if not anEntityA.isObject() and not anEntityB.isObject(): @@ -131,27 +151,16 @@ def getCoincidences(theSketch): return aCoincidences def connectedFeatures(theCoincidence): - anEntityA = aSubFeature.refattr("ConstraintEntityA") - anEntityB = aSubFeature.refattr("ConstraintEntityB") - return [anEntityA.attr().owner(), anEntityB.attr().owner()] + anEntityA = theCoincidence.refattr("ConstraintEntityA") + anEntityB = theCoincidence.refattr("ConstraintEntityB") + aFeatureA = ModelAPI.ModelAPI_Feature.feature(anEntityA.attr().owner()) + aFeatureB = ModelAPI.ModelAPI_Feature.feature(anEntityB.attr().owner()) + 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) #========================================================================= @@ -195,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 @@ -226,10 +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: Checking of Python dump has been disabled until the Fillet redesigned. -#assert(model.checkPythonDump()) +# TODO: Improve Fillet test case by moving one of filleted objectes and check coincidence and tangency are correct + +assert(model.checkPythonDump())