From: sbh Date: Fri, 25 Jul 2014 07:57:40 +0000 (+0400) Subject: Tests for sketch Arc and circle added. X-Git-Tag: V_0.4.4~146^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3f1432c6f96c69d1928173941dfd9e473dffcbdc;p=modules%2Fshaper.git Tests for sketch Arc and circle added. --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index cbcfdc7a8..990495c08 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -61,4 +61,5 @@ INCLUDE_DIRECTORIES( INSTALL(TARGETS SketchPlugin DESTINATION plugins) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) -ADD_UNIT_TESTS(TestSketchPointLine.py) +ADD_UNIT_TESTS(TestSketchPointLine.py + TestSketchArcCircle.py) diff --git a/src/SketchPlugin/Test/TestSketchArcCircle.py b/src/SketchPlugin/Test/TestSketchArcCircle.py new file mode 100644 index 000000000..304f0e334 --- /dev/null +++ b/src/SketchPlugin/Test/TestSketchArcCircle.py @@ -0,0 +1,169 @@ +""" + TestSketchArcCircle.py + + static const std::string MY_SKETCH_ARC_ID("SketchArc"); + static const std::string MY_CENTER_ID = "ArcCenter"; + static const std::string MY_START_ID = "ArcStartPoint"; + static const std::string MY_END_ID = "ArcEndPoint"; + data()->addAttribute(SketchPlugin_Arc::CENTER_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Arc::START_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Arc::END_ID(), GeomDataAPI_Point2D::type()); + + static const std::string MY_CIRCLE_ID("SketchCircle"); + static const std::string MY_CIRCLE_CENTER_ID("CircleCenter"); + static const std::string MY_CIRCLE_RADIUS_ID("CircleRadius"); + data()->addAttribute(SketchPlugin_Circle::CENTER_ID(), GeomDataAPI_Point2D::type()); + data()->addAttribute(SketchPlugin_Circle::RADIUS_ID(), ModelAPI_AttributeDouble::type()); +""" + +#========================================================================= +# Initialization of the test +#========================================================================= +from GeomDataAPI import * +from ModelAPI import * + +__updated__ = "2014-07-25" + +aPluginManager = ModelAPI_PluginManager.get() +aDocument = aPluginManager.rootDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aDocument.startOperation() +aSketchFeature = aDocument.addFeature("Sketch") +aSketchFeatureData = aSketchFeature.data() +origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) +norm.setValue(0, 0, 1) +aDocument.finishOperation() +#========================================================================= +# Creation of an arc +# 1. Test SketchPlugin_Arc attributes +# 2. +#========================================================================= +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +assert (not aSketchReflist.isInitialized()) +assert (aSketchReflist.size() == 0) +assert (len(aSketchReflist.list()) == 0) +aSketchArc = aDocument.addFeature("SketchArc") +assert (aSketchArc.getKind() == "SketchArc") +aSketchReflist.append(aSketchArc) +aSketchArcData = aSketchArc.data() +anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter")) +assert (anArcCentr.x() == 0) +assert (anArcCentr.y() == 0) +assert (not anArcCentr.isInitialized()) +anArcCentr.setValue(10.,10.) +anArcStartPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcStartPoint")) +assert (anArcStartPoint.x() == 0) +assert (anArcStartPoint.y() == 0) +assert (not anArcStartPoint.isInitialized()) +anArcStartPoint.setValue(0., 50.) +anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint")) +assert (anArcEndPoint.x() == 0) +assert (anArcEndPoint.y() == 0) +assert (not anArcEndPoint.isInitialized()) +anArcEndPoint.setValue(50., 0.) +aDocument.finishOperation() +# check that values have been changed +aSketchReflist = aSketchFeatureData.reflist("Features") +assert (aSketchReflist.size() == 1) +assert (len(aSketchReflist.list()) == 1) +assert (anArcCentr.x() == 10.0) +assert (anArcCentr.y() == 10.0) +assert (anArcStartPoint.x() == 0.0) +assert (anArcStartPoint.y() == 50.0) +assert (anArcEndPoint.x() == 50.0) +assert (anArcEndPoint.y() == 0.0) +#=============================================================================== +# Edit the arc: +# 1. Move whole arc +# 2. Change the start point +#=============================================================================== +aDocument.startOperation() +deltaX, deltaY = 5., 10. +anArcCentr.setValue(anArcCentr.x() + deltaX, anArcCentr.y() + deltaY) +anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y() + deltaY) +anArcEndPoint.setValue(anArcEndPoint.x() + deltaX, anArcEndPoint.y() + deltaY) +aDocument.finishOperation() +assert (anArcCentr.x() == 15) +assert (anArcCentr.y() == 20) +assert (anArcStartPoint.x() == 5) +assert (anArcStartPoint.y() == 60) +assert (anArcEndPoint.x() == 55) +assert (anArcEndPoint.y() == 10) +# Change the start point +aDocument.startOperation() +anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y()) +aPrevEndPointX = anArcEndPoint.x() +aPrevEndPointY = anArcEndPoint.y() +aDocument.finishOperation() +assert (anArcCentr.x() == 15) +assert (anArcCentr.y() == 20) +assert (anArcStartPoint.x() == 10) +assert (anArcStartPoint.y() == 60) +assert (anArcEndPoint.x() != aPrevEndPointX) +assert (anArcEndPoint.y() != aPrevEndPointY) +#========================================================================= +# Check results of the Arc +#========================================================================= +aResult = aSketchArc.firstResult() +aResultConstruction = modelAPI_ResultConstruction(aResult) +aShape = aResultConstruction.shape() +assert (aShape is not None) +assert (not aShape.isNull()) +#=============================================================================== +# Create a circle +# 1. Test SketchPlugin_Circle.h attributes +# 2. ModelAPI_AttributeDouble attribute +#=============================================================================== +aDocument.startOperation() +aSketchReflist = aSketchFeatureData.reflist("Features") +# Arc is already added +assert (aSketchReflist.size() == 1) +assert (len(aSketchReflist.list()) == 1) +aSketchCircle = aDocument.addFeature("SketchCircle") +assert (aSketchCircle.getKind() == "SketchCircle") +aSketchReflist.append(aSketchCircle) +aSketchCircleData = aSketchCircle.data() +anCircleCentr = geomDataAPI_Point2D(aSketchCircleData.attribute("CircleCenter")) +assert (anCircleCentr.x() == 0) +assert (anCircleCentr.y() == 0) +assert (not anCircleCentr.isInitialized()) +aCircleRadius = aSketchCircleData.real("CircleRadius"); +assert (type(aCircleRadius) == ModelAPI_AttributeDouble) +# ModelAPI_AttributeDouble.type() is checked in ModelAPI_TestConstants +assert (aCircleRadius.attributeType() == ModelAPI_AttributeDouble.type()) +assert (aCircleRadius.value() == 0) +anCircleCentr.setValue(-25., -25) +aCircleRadius.setValue(25.) +assert (anCircleCentr.x() == -25) +assert (anCircleCentr.y() == -25) +assert (aCircleRadius.value() == 25) +aDocument.finishOperation() +#=============================================================================== +# Edit the Cricle +# 1. Check that changing the centr of a circle does not affects radius +# 2. and vise versa; also check that int is acceptable as well as a real +#=============================================================================== +aDocument.startOperation() +anCircleCentr.setValue(10, 60) +aDocument.finishOperation() +assert (anCircleCentr.x() == 10) +assert (anCircleCentr.y() == 60) +assert (aCircleRadius.value() == 25) +aDocument.startOperation() +aCircleRadius.setValue(int(20)) +aDocument.finishOperation() +assert (anCircleCentr.x() == 10) +assert (anCircleCentr.y() == 60) +assert (aCircleRadius.value() == 20) +#=============================================================================== +# End of test +#=============================================================================== diff --git a/src/SketchPlugin/Test/TestSketchPointLine.py b/src/SketchPlugin/Test/TestSketchPointLine.py index a03ca8fdf..d5c675528 100644 --- a/src/SketchPlugin/Test/TestSketchPointLine.py +++ b/src/SketchPlugin/Test/TestSketchPointLine.py @@ -23,6 +23,7 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) +aDocument.finishOperation() # check that values have been changed origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) assert (origin.x() == 0) @@ -40,7 +41,6 @@ norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) assert (norm.x() == 0) assert (norm.y() == 0) assert (norm.z() == 1) -aDocument.finishOperation() #========================================================================= # Creation of a point #========================================================================= @@ -60,6 +60,7 @@ assert (not coords.isInitialized()) # Simulate SketchPlugin_Point::move(...) coords.setValue(10., 10.) assert (coords.isInitialized()) +aDocument.finishOperation() # check that values have been changed aSketchReflist = aSketchFeatureData.reflist("Features") assert (aSketchReflist.size() == 1) @@ -68,7 +69,6 @@ aSketchPointData = aSketchPoint.data() coords = geomDataAPI_Point2D(aSketchPointData.attribute("PointCoordindates")) assert (coords.x() == 10.0) assert (coords.y() == 10.0) -aDocument.finishOperation() #=============================================================================== # Creation of a line #=============================================================================== @@ -92,6 +92,7 @@ aLineStartPoint.setValue(50., 50.) aLineEndPoint.setValue(60., 60.) assert (aLineStartPoint.isInitialized()) assert (aLineEndPoint.isInitialized()) +aDocument.finishOperation() # check that values have been changed aSketchLineData = aSketchLine.data() aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint")) @@ -100,7 +101,6 @@ assert (aLineStartPoint.x() == 50.0) assert (aLineStartPoint.y() == 50.0) assert (aLineEndPoint.x() == 60.0) assert (aLineEndPoint.y() == 60.0) -aDocument.finishOperation() #=============================================================================== # Check the results #===============================================================================