Salome HOME
Merge remote-tracking branch 'origin/CEA_2019'
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintRadius.py
index 9ba906752f4c4210ffdc93479bae3e83d25752ae..fbfa56093179be4c19b7d6ad9ba994006e1bb92d 100644 (file)
@@ -1,7 +1,26 @@
+# Copyright (C) 2014-2019  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
+#
+
 """
     TestConstraintRadius.py
     Unit test of SketchPlugin_ConstraintRadius class
-    
+
     SketchPlugin_Constraint
         static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
         static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
@@ -9,7 +28,7 @@
         static const std::string MY_ENTITY_B("ConstraintEntityB");
         static const std::string MY_ENTITY_C("ConstraintEntityC");
         static const std::string MY_ENTITY_D("ConstraintEntityD");
-        
+
     SketchPlugin_ConstraintRadius
         static const std::string MY_CONSTRAINT_RADIUS_ID("SketchConstraintRadius");
         data()->addAttribute(SketchPlugin_Constraint::VALUE(),    ModelAPI_AttributeDouble::typeId());
@@ -28,15 +47,6 @@ from salome.shaper import model
 
 __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()
@@ -58,11 +68,11 @@ aSession.finishOperation()
 #=========================================================================
 aSession.startOperation()
 aSketchArc = aSketchFeature.addFeature("SketchArc")
-anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
 anArcCentr.setValue(10., 10.)
-anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
+anArcStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
 anArcStartPoint.setValue(0., 50.)
-anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
 anArcEndPoint.setValue(50., 0.)
 aSession.finishOperation()
 assert (model.dof(aSketchFeature) == 5)
@@ -81,22 +91,16 @@ assert (model.dof(aSketchFeature) == 5)
 # Circle
 aSession.startOperation()
 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
-anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
-aCircleRadius = aSketchCircle.real("CircleRadius")
+anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center"))
+aCircleRadius = aSketchCircle.real("circle_radius")
 anCircleCentr.setValue(-25., -25)
 aCircleRadius.setValue(25.)
 aSession.finishOperation()
 assert (model.dof(aSketchFeature) == 8)
-# Change the radius of the arc
-aSession.startOperation()
-RADIUS = 40
-anArcRadius = aSketchArc.real("ArcRadius")
-anArcRadius.setValue(RADIUS)
-aSession.finishOperation()
-assert (model.dof(aSketchFeature) == 8)
 #=========================================================================
 # Make a constraint to keep the radius of the arc
 #=========================================================================
+RADIUS = 40
 aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
 aRadius = aConstraint.real("ConstraintValue")
@@ -104,7 +108,7 @@ aRefObject = aConstraint.refattr("ConstraintEntityA")
 aResult = aSketchArc.lastResult()
 assert (aResult is not None)
 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
-aConstraint.execute()
+aRadius.setValue(RADIUS)
 aSession.finishOperation()
 assert (aRadius.isInitialized())
 assert (aRefObject.isInitialized())
@@ -119,19 +123,21 @@ aRefObject = aConstraint.refattr("ConstraintEntityA")
 aResult = aSketchCircle.lastResult()
 assert (aResult is not None)
 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
-aConstraint.execute()
+aRadius.setValue(RADIUS)
 aSession.finishOperation()
 assert (aRadius.isInitialized())
 assert (aRefObject.isInitialized())
 assert (model.dof(aSketchFeature) == 6)
 #=========================================================================
 # Perform some actions and checks:
-# 1. Check that constraints does not changes values
+# 1. Check that constraints does not change values
 # 2. Move one point of the arc
 # 3. Check that second point is moved also
 #=========================================================================
-assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10)
-assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10)
+distCS = model.distancePointPoint(anArcCentr, anArcStartPoint)
+distCE = model.distancePointPoint(anArcCentr, anArcEndPoint)
+assert (math.fabs(distCS - RADIUS) < 1.e-10)
+assert (math.fabs(distCE - RADIUS) < 1.e-10)
 anArcPrevEndPointX = anArcEndPoint.x()
 anArcPrevEndPointY = anArcEndPoint.y()
 # Move one point of the arc
@@ -140,8 +146,10 @@ anArcStartPoint.setValue(0, 60)
 aSession.finishOperation()
 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)
+distCS = model.distancePointPoint(anArcCentr, anArcStartPoint)
+distCE = model.distancePointPoint(anArcCentr, anArcEndPoint)
+assert (math.fabs(distCS - RADIUS) < 1.e-10)
+assert (math.fabs(distCE - RADIUS) < 1.e-10)
 assert (model.dof(aSketchFeature) == 6)
 #=========================================================================
 # 4. Move the centr or the point of the arc
@@ -149,13 +157,13 @@ assert (model.dof(aSketchFeature) == 6)
 #=========================================================================
 assert (anCircleCentr.x() == -25)
 assert (anCircleCentr.y() == -25)
-assert (aCircleRadius.value() == 25)
+assert (aCircleRadius.value() == RADIUS)
 aSession.startOperation()
 anCircleCentr.setValue(100., 100.)
 aSession.finishOperation()
 assert (anCircleCentr.x() == 100)
 assert (anCircleCentr.y() == 100)
-assert (aCircleRadius.value() == 25)
+assert (aCircleRadius.value() == RADIUS)
 assert (model.dof(aSketchFeature) == 6)
 #=========================================================================
 # End of test