Salome HOME
Issues #2850, #2860: Change type of angle while Python Dump, because the configuratio...
[modules/shaper.git] / src / SketchPlugin / Test / TestFillet.py
index 39762ed778d19ded02d0327425bad2adb1d5d321..e2535877587a4d0b1b0e3bde273957678be10011 100644 (file)
@@ -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<mailto:webmaster.salome@opencascade.com>
+##
+
 """
     TestFillet.py
     Unit test of SketchPlugin_Fillet class
@@ -5,7 +25,6 @@
     SketchPlugin_Fillet
         static const std::string MY_CONSTRAINT_FILLET_ID("SketchFillet");
         data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());
         data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
         data()->addAttribute(SketchPlugin_Constraint::ENTITY_C(), ModelAPI_AttributeRefAttrList::typeId());
 
@@ -75,9 +94,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 +123,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 +157,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 +203,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 +244,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())