]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchPlugin/Test/TestConstraintRadius.py
Salome HOME
Update unit-tests for SketchPlugin. Test case for the Projection has been added
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintRadius.py
index afe60ba4f4971bb09d57c0ea3e9d08f63e28533e..edc37350bb130c8c020e10802f4cdf37b6e15d61 100644 (file)
@@ -12,9 +12,9 @@
         
     SketchPlugin_ConstraintRadius
         static const std::string MY_CONSTRAINT_RADIUS_ID("SketchConstraintRadius");
-        data()->addAttribute(SketchPlugin_Constraint::VALUE(),    ModelAPI_AttributeDouble::type());
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
-        data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type());
+        data()->addAttribute(SketchPlugin_Constraint::VALUE(),    ModelAPI_AttributeDouble::typeId());
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+        data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
 
 """
 from GeomDataAPI import *
@@ -26,6 +26,16 @@ import math
 
 __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()
 #=========================================================================
@@ -33,13 +43,11 @@ aDocument = aSession.moduleDocument()
 #=========================================================================
 aSession.startOperation()
 aSketchCommonFeature = aDocument.addFeature("Sketch")
-aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature)
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
 origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
 dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeature.attribute("DirY"))
-diry.setValue(0, 1, 0)
 norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
 aSession.finishOperation()
@@ -55,6 +63,17 @@ anArcStartPoint.setValue(0., 50.)
 anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
 anArcEndPoint.setValue(50., 0.)
 aSession.finishOperation()
+# Test changing the arc start/end point
+aSession.startOperation()
+anArcStartPoint.setValue(anArcStartPoint.x(), 40.)
+anArcStartPoint.setValue(0., 50.)
+assert (math.hypot(anArcStartPoint.x() - 0., anArcStartPoint.y() - 50.) < 1.e-10)
+aSession.finishOperation()
+aSession.startOperation()
+anArcEndPoint.setValue(40., anArcEndPoint.y())
+anArcEndPoint.setValue(50., 0.)
+assert (math.hypot(anArcEndPoint.x() - 50., anArcEndPoint.y() - 0.) < 1.e-10)
+aSession.finishOperation()
 # Circle
 aSession.startOperation()
 aSketchCircle = aSketchFeature.addFeature("SketchCircle")
@@ -63,6 +82,12 @@ aCircleRadius = aSketchCircle.real("CircleRadius")
 anCircleCentr.setValue(-25., -25)
 aCircleRadius.setValue(25.)
 aSession.finishOperation()
+# Change the radius of the arc
+aSession.startOperation()
+RADIUS = 40
+anArcRadius = aSketchArc.real("ArcRadius")
+anArcRadius.setValue(RADIUS)
+aSession.finishOperation()
 #=========================================================================
 # Make a constraint to keep the radius of the arc
 #=========================================================================
@@ -70,7 +95,7 @@ aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
 aRadius = aConstraint.real("ConstraintValue")
 aRefObject = aConstraint.refattr("ConstraintEntityA")
-aResult = aSketchArc.firstResult()
+aResult = aSketchArc.lastResult()
 assert (aResult is not None)
 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
 aConstraint.execute()
@@ -84,7 +109,7 @@ aSession.startOperation()
 aConstraint = aSketchFeature.addFeature("SketchConstraintRadius")
 aRadius = aConstraint.real("ConstraintValue")
 aRefObject = aConstraint.refattr("ConstraintEntityA")
-aResult = aSketchCircle.firstResult()
+aResult = aSketchCircle.lastResult()
 assert (aResult is not None)
 aRefObject.setObject(modelAPI_ResultConstruction(aResult))
 aConstraint.execute()
@@ -97,22 +122,18 @@ assert (aRefObject.isInitialized())
 # 2. Move one point of the arc
 # 3. Check that second point is moved also
 #=========================================================================
-assert (anArcCentr.x() == 10.)
-assert (anArcCentr.y() == 10.)
-assert (anArcStartPoint.x() == 0.)
-assert (anArcStartPoint.y() == 50.)
+assert (math.fabs(distancePointPoint(anArcCentr, anArcStartPoint) - RADIUS) < 1.e-10)
+assert (math.fabs(distancePointPoint(anArcCentr, anArcEndPoint) - RADIUS) < 1.e-10)
 anArcPrevEndPointX = anArcEndPoint.x()
 anArcPrevEndPointY = anArcEndPoint.y()
-assert (anArcPrevEndPointX == 50.)
-assert (anArcPrevEndPointY == 0.)
 # Move one point of the arc
 aSession.startOperation()
-anArcStartPoint.setValue(0., 60)
+anArcStartPoint.setValue(0, 60)
 aSession.finishOperation()
-assert (anArcCentr.x() == 10.)
-assert (anArcCentr.y() == 10.)
 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)
 #=========================================================================
 # 4. Move the centr or the point of the arc
 # 5. Check radius is the same