From: sbh Date: Fri, 21 Nov 2014 13:13:27 +0000 (+0300) Subject: Python unit tests updated and extended. X-Git-Tag: V_0.6.0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1264006edf1221473f3a70ef31bcee6bbf78d23b;p=modules%2Fshaper.git Python unit tests updated and extended. * TestBoolean, TestExtrusion of FeaturesPlugin added * TestConstraintRigid of SketchPlugin added * Some errors tests corrected. --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 5b8f1c075..4b4ce8e11 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -1,4 +1,5 @@ INCLUDE(Common) +INCLUDE(UnitTest) SET(PROJECT_HEADERS FeaturesPlugin.h @@ -42,3 +43,6 @@ TARGET_LINK_LIBRARIES(FeaturesPlugin ${PROJECT_LIBRARIES}) INSTALL(TARGETS FeaturesPlugin DESTINATION plugins) INSTALL(FILES ${XML_RESOURCES} DESTINATION plugins) + +ADD_UNIT_TESTS(TestExtrusion.py + TestBoolean.py) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h index 021b99da6..e9f28ae1d 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Boolean.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Boolean.h @@ -16,8 +16,8 @@ class FeaturesPlugin_Boolean : public ModelAPI_Feature /// Extrusion kind inline static const std::string& ID() { - static const std::string MY_CUT_ID("Boolean"); - return MY_CUT_ID; + static const std::string MY_ID("Boolean"); + return MY_ID; } /// attribute name of referenced object inline static const std::string& OBJECT_ID() @@ -34,8 +34,8 @@ class FeaturesPlugin_Boolean : public ModelAPI_Feature /// attribute name of operation type inline static const std::string& TYPE_ID() { - static const std::string MY_TOOL_ID("bool_type"); - return MY_TOOL_ID; + static const std::string MY_TYPE_ID("bool_type"); + return MY_TYPE_ID; } enum { diff --git a/src/FeaturesPlugin/Test/TestBoolean.py b/src/FeaturesPlugin/Test/TestBoolean.py new file mode 100644 index 000000000..63f189172 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestBoolean.py @@ -0,0 +1,121 @@ +""" + TestBoolean.py + Unit test of FeaturesPlugin_Boolean class + + class FeaturesPlugin_Boolean + static const std::string MY_ID("Boolean"); + static const std::string MY_OBJECT_ID("main_object"); + static const std::string MY_TOOL_ID("tool_object"); + static const std::string MY_TYPE_ID("bool_type"); + + data()->addAttribute(FeaturesPlugin_Boolean::OBJECT_ID(), ModelAPI_AttributeReference::type()); + data()->addAttribute(FeaturesPlugin_Boolean::TOOL_ID(), ModelAPI_AttributeReference::type()); + data()->addAttribute(FeaturesPlugin_Boolean::TYPE_ID(), ModelAPI_AttributeInteger::type()); +""" +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * + +__updated__ = "2014-11-21" + +aSession = ModelAPI_Session.get() +# Create a part for extrusions & boolean +aSession.startOperation() +aPartFeature = aSession.moduleDocument().addFeature("Part") +aPart = aSession.activeDocument() +aSession.finishOperation() +#========================================================================= +# Create a sketch with circle to extrude +#========================================================================= +aSession.startOperation() +aCircleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aCircleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aCircleSketchFeature.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aCircleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSketchCircle = aCircleSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(10., 10.) +aCircleRadius.setValue(50.) +aSession.finishOperation() +#========================================================================= +# Create a sketch with triangle to extrude +#========================================================================= +aSession.startOperation() +aTriangleSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch")) +origin = geomDataAPI_Point(aTriangleSketchFeature.attribute("Origin")) +origin.setValue(0, 0, 0) +dirx = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirX")) +dirx.setValue(1, 0, 0) +diry = geomDataAPI_Dir(aTriangleSketchFeature.attribute("DirY")) +diry.setValue(0, 1, 0) +norm = geomDataAPI_Dir(aTriangleSketchFeature.attribute("Norm")) +norm.setValue(0, 0, 1) +aSketchLineA = aTriangleSketchFeature.addFeature("SketchLine") +aSketchLineB = aTriangleSketchFeature.addFeature("SketchLine") +aSketchLineC = aTriangleSketchFeature.addFeature("SketchLine") +aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint")) +aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint")) +aLineAStartPoint.setValue(25., 25.) +aLineAEndPoint.setValue(100., 25.) +aLineBStartPoint.setValue(100., 25.) +aLineBEndPoint.setValue(60., 75.) +aLineCStartPoint.setValue(60., 75.) +aLineCEndPoint.setValue(25., 25.) +aSession.finishOperation() +#========================================================================= +# Make extrusion on circle (cylinder) and triangle (prism) +#========================================================================= +# Build shape from sketcher results +aSession.startOperation() +extrudedObjects = [] +for eachSketchFeature in [aCircleSketchFeature, aTriangleSketchFeature]: + # Build sketch faces + aSketchResult = eachSketchFeature.firstResult() + aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape() + origin = geomDataAPI_Point(eachSketchFeature.attribute("Origin")).pnt() + dirX = geomDataAPI_Dir(eachSketchFeature.attribute("DirX")).dir() + dirY = geomDataAPI_Dir(eachSketchFeature.attribute("DirY")).dir() + norm = geomDataAPI_Dir(eachSketchFeature.attribute("Norm")).dir() + aSketchFaces = ShapeList() + GeomAlgoAPI_SketchBuilder.createFaces( + origin, dirX, dirY, norm, aSketchEdges, aSketchFaces) + # Create extrusion on them + anExtrusionFt = aPart.addFeature("Extrusion") + anExtrusionFt.selection("extrusion_face").setValue( + aSketchResult, aSketchFaces[0]) + anExtrusionFt.real("extrusion_size").setValue(50) + anExtrusionFt.boolean("extrusion_reverse").setValue(False) + anExtrusionFt.execute() + extrudedObjects.append(modelAPI_ResultBody(anExtrusionFt.firstResult())) +aSession.finishOperation() +#========================================================================= +# Create a pacman as boolean cut of the prism from the cylinder +#========================================================================= +aSession.startOperation() +aBooleanFt = aPart.addFeature("Boolean") +aBooleanFt.reference("main_object").setValue(extrudedObjects[0]) +aBooleanFt.reference("tool_object").setValue(extrudedObjects[1]) +kBooleanTypeCut = 0 +aBooleanFt.integer("bool_type").setValue(kBooleanTypeCut) +aBooleanFt.execute() +aSession.finishOperation() + +assert (len(aBooleanFt.results()) > 0) +aBooleanResult = modelAPI_ResultBody(aBooleanFt.firstResult()) +assert (aBooleanResult is not None) +#========================================================================= +# End of test +#========================================================================= diff --git a/src/FeaturesPlugin/Test/TestExtrusion.py b/src/FeaturesPlugin/Test/TestExtrusion.py new file mode 100644 index 000000000..1f60c4ed9 --- /dev/null +++ b/src/FeaturesPlugin/Test/TestExtrusion.py @@ -0,0 +1,89 @@ +""" + TestExtrusion.py + Unit test of FeaturesPlugin_Extrusion class + + class FeaturesPlugin_Extrusion : public ModelAPI_Feature + static const std::string MY_EXTRUSION_ID("Extrusion"); + static const std::string MY_FACE_ID("extrusion_face"); + static const std::string MY_SIZE_ID("extrusion_size"); + static const std::string MY_REVERSE_ID("extrusion_reverse"); + + data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type()); + data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type()); + data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type()); +""" +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * +from GeomDataAPI import * +from GeomAlgoAPI import * + +__updated__ = "2014-11-21" + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +# Create a part for extrusion +aSession.startOperation() +aPartFeature = aDocument.addFeature("Part") +aSession.finishOperation() +assert (len(aPartFeature.results()) == 1) +# Another way is: +# aPart = aSession.activeDocument() +aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) +aPart = aPartResult.partDoc() +#========================================================================= +# Create a sketch circle to extrude +#========================================================================= +aSession.startOperation() +aSketchFeature = modelAPI_CompositeFeature(aPart.addFeature("Sketch")) +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) +# Create circle +aSketchCircle = aSketchFeature.addFeature("SketchCircle") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) +aCircleRadius = aSketchCircle.real("CircleRadius") +anCircleCentr.setValue(50., 50) +aCircleRadius.setValue(20.) +aSession.finishOperation() +#========================================================================= +# Make extrusion on circle +#========================================================================= +# Build shape from sketcher results +aSketchResult = aSketchFeature.firstResult() +aSketchEdges = modelAPI_ResultConstruction(aSketchResult).shape() +origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")).pnt() +dirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX")).dir() +dirY = geomDataAPI_Dir(aSketchFeature.attribute("DirY")).dir() +norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm")).dir() +aSketchFaces = ShapeList() +GeomAlgoAPI_SketchBuilder.createFaces( + origin, dirX, dirY, norm, aSketchEdges, aSketchFaces) +assert (len(aSketchFaces) > 0) +assert (aSketchFaces[0] is not None) +# Create extrusion +aSession.startOperation() +anExtrusionFt = aPart.addFeature("Extrusion") +assert (anExtrusionFt.getKind() == "Extrusion") +anExtrusionFt.selection("extrusion_face").setValue( + aSketchResult, aSketchFaces[0]) +anExtrusionFt.real("extrusion_size").setValue(50) +anExtrusionFt.boolean("extrusion_reverse").setValue(False) +anExtrusionFt.execute() +aSession.finishOperation() +assert (anExtrusionFt.real("extrusion_size").value() == 50.0) +assert (anExtrusionFt.boolean("extrusion_reverse").value() == False) + +# Check extrusion results +assert (len(anExtrusionFt.results()) > 0) +anExtrusionResult = modelAPI_ResultBody(anExtrusionFt.firstResult()) +assert (anExtrusionResult is not None) +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 4d46a6271..593f10bd8 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -78,4 +78,5 @@ ADD_UNIT_TESTS(TestSketchPointLine.py TestConstraintDistance.py TestConstraintParallel.py TestConstraintPerpendicular.py - TestConstraintRadius.py) + TestConstraintRadius.py + TestConstraintRigid.py) diff --git a/src/SketchPlugin/Test/TestConstraintConcidence.py b/src/SketchPlugin/Test/TestConstraintConcidence.py index 35e9ac0c8..772c94b96 100644 --- a/src/SketchPlugin/Test/TestConstraintConcidence.py +++ b/src/SketchPlugin/Test/TestConstraintConcidence.py @@ -30,7 +30,8 @@ aDocument = aSession.moduleDocument() # Creation of a sketch #========================================================================= aSession.startOperation() -aSketchFeature = aDocument.addFeature("Sketch") +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = modelAPI_CompositeFeature(aSketchCommonFeature) origin = geomDataAPI_Point(aSketchFeature.attribute("Origin")) origin.setValue(0, 0, 0) dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX")) @@ -44,19 +45,15 @@ aSession.finishOperation() # Create a line and an arc #========================================================================= aSession.startOperation() -aSketchReflist = aSketchFeature.reflist("Features") -aSketchArc = aDocument.addFeature("SketchArc") -aSketchReflist.append(aSketchArc) +aSketchArc = aSketchFeature.addFeature("SketchArc") anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter")) anArcStartPoint = geomDataAPI_Point2D( aSketchArc.attribute("ArcStartPoint")) anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint")) -aSketchFeature = aDocument.addFeature("SketchConstraintCoincidence") anArcCentr.setValue(10., 10.) anArcStartPoint.setValue(0., 50.) anArcEndPoint.setValue(50., 0.) -aSketchLine = aDocument.addFeature("SketchLine") -aSketchReflist.append(aSketchLine) +aSketchLine = aSketchFeature.addFeature("SketchLine") aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint")) aLineEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint")) # Lets initialize line start at circle's end: @@ -67,12 +64,12 @@ aSession.finishOperation() # Link arc's end and line's start points with concidence constraint #========================================================================= aSession.startOperation() -aConstraint = aDocument.addFeature("SketchConstraintCoincidence") -aSketchReflist.append(aConstraint) +aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") reflistA = aConstraint.refattr("ConstraintEntityA") reflistB = aConstraint.refattr("ConstraintEntityB") reflistA.setAttr(anArcEndPoint) reflistB.setAttr(aLineStartPoint) +aConstraint.execute() aSession.finishOperation() #========================================================================= # Check values and move one constrainted object diff --git a/src/SketchPlugin/Test/TestConstraintParallel.py b/src/SketchPlugin/Test/TestConstraintParallel.py index 18fbc6832..052e9272a 100644 --- a/src/SketchPlugin/Test/TestConstraintParallel.py +++ b/src/SketchPlugin/Test/TestConstraintParallel.py @@ -55,15 +55,15 @@ aSession.finishOperation() # Make a constraint to keep the length of the line constant # to parallel perpendicular constraint collapsing line to point #========================================================================= +aSession.startOperation() for eachFeature in [aSketchLineA, aSketchLineB]: - aSession.startOperation() aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength") refattrA = aLengthConstraint.refattr("ConstraintEntityA") aResultA = modelAPI_ResultConstruction(eachFeature.firstResult()) assert (aResultA is not None) refattrA.setObject(aResultA) aLengthConstraint.execute() - aSession.finishOperation() +aSession.finishOperation() # Coordinates of lines should not be changed after this constraint assert (aLineAStartPoint.x() == 0) assert (aLineAStartPoint.y() == 25) @@ -81,8 +81,9 @@ aParallelConstraint = aSketchFeature.addFeature("SketchConstraintParallel") refattrA = aParallelConstraint.refattr("ConstraintEntityA") refattrB = aParallelConstraint.refattr("ConstraintEntityB") # aResultA is already defined for the length constraint -aResultA = modelAPI_ResultConstruction(eachFeature.firstResult()) +aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult()) aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult()) +assert (aResultA is not None) assert (aResultB is not None) refattrA.setObject(aResultA) refattrB.setObject(aResultB) @@ -93,34 +94,19 @@ aSession.finishOperation() #========================================================================= deltaX = deltaY = 10. # rotate line, check that reference's line points are moved also -# print "Rotate line, check that reference's line points are moved also" -# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() -# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() -# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() -# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() -# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() -# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() -# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() -# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() -aLineBStartPointXPrev = aLineBStartPoint.x() -aLineBStartPointYPrev = aLineBStartPoint.y() -aLineBEndPointXPrev = aLineBEndPoint.x() -aLineBEndPointYPrev = aLineBEndPoint.y() +aLineBStartPointPrev = (aLineBStartPoint.x(), aLineBStartPoint.y()) +aLineBEndPointPrev = (aLineBEndPoint.x(), aLineBEndPoint.y()) aSession.startOperation() aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y() + deltaY) aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, aLineAEndPoint.y() - deltaY) aSession.finishOperation() -# print "After transformation:" -# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() -# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() -# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() -# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() -# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() -# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() -# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() -# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +aLineBStartPointNew = (aLineBStartPoint.x(), aLineBStartPoint.y()) +aLineBEndPointNew = (aLineBEndPoint.x(), aLineBEndPoint.y()) + +assert (aLineBStartPointPrev != aLineBStartPointNew) +assert (aLineBEndPointPrev != aLineBEndPointNew) #========================================================================= # End of test #========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintPerpendicular.py b/src/SketchPlugin/Test/TestConstraintPerpendicular.py index 38b605f23..2f9c6bf06 100644 --- a/src/SketchPlugin/Test/TestConstraintPerpendicular.py +++ b/src/SketchPlugin/Test/TestConstraintPerpendicular.py @@ -49,10 +49,10 @@ aSession.startOperation() aSketchLineA = aSketchFeature.addFeature("SketchLine") aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) -# line B -aSketchLineB = aSketchFeature.addFeature("SketchLine") aLineAStartPoint.setValue(0., 25) aLineAEndPoint.setValue(85., 25) +# line B +aSketchLineB = aSketchFeature.addFeature("SketchLine") aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) aLineBStartPoint.setValue(25., 40.) @@ -62,16 +62,15 @@ aSession.finishOperation() # Make a constraint to keep the length of the line constant # to prevent perpendicular constraint collapsing line to point #========================================================================= - +aSession.startOperation() for eachFeature in [aSketchLineA, aSketchLineB]: - aSession.startOperation() aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength") - refattrA = aLengthConstraint.refattr("ConstraintEntityA") - aResultA = modelAPI_ResultConstruction(eachFeature.firstResult()) - assert (aResultA is not None) - refattrA.setObject(aResultA) + eachRefattr = aLengthConstraint.refattr("ConstraintEntityA") + eachResult = modelAPI_ResultConstruction(eachFeature.firstResult()) + assert (eachResult is not None) + eachRefattr.setObject(eachResult) aLengthConstraint.execute() - aSession.finishOperation() +aSession.finishOperation() # Coordinates of lines should not be changed after this constraint assert (aLineAStartPoint.x() == 0) @@ -86,12 +85,12 @@ assert (aLineBEndPoint.y() == 125) # Link lines with perpendicular constraint #========================================================================= aSession.startOperation() -aPerpendicularConstraint = aSketchFeature.addFeature( - "SketchConstraintPerpendicular") +aPerpendicularConstraint = aSketchFeature.addFeature("SketchConstraintPerpendicular") refattrA = aPerpendicularConstraint.refattr("ConstraintEntityA") refattrB = aPerpendicularConstraint.refattr("ConstraintEntityB") -# aResultA is already defined for the length constraint +aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult()) aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult()) +assert (aResultA is not None) assert (aResultB is not None) refattrA.setObject(aResultA) refattrB.setObject(aResultB) @@ -100,46 +99,27 @@ aSession.finishOperation() #========================================================================= # Check values and move one constrainted object #========================================================================= -# print "Check values and move one constrainted object" -# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() -# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() -# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() -# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() -# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() -# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() -# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() -# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +aLineBStartPointPrev = (aLineBStartPoint.x(),aLineBStartPoint.y()) +aLineBEndPointPrev = (aLineBEndPoint.x(),aLineBEndPoint.y()) deltaX = deltaY = 5. # move line without rotation, # check that reference's line points are not changed also -aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, - aLineAStartPoint.y() + deltaY) -aLineAEndPoint.setValue(aLineAEndPoint.x() + deltaX, - aLineAEndPoint.y() + deltaY) -# print "move line without rotation" -# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() -# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() -# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() -# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() -# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() -# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() -# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() -# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() - -# rotate line, check that reference's line points are moved also -aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, - aLineAStartPoint.y() + deltaY) -aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, - aLineAEndPoint.y() - deltaY) -# print "Rotate line, check that reference's line points are moved also" -# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x() -# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y() -# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x() -# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y() -# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x() -# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() -# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() -# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() +aSession.startOperation() +aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y() + deltaY) +aLineAEndPoint.setValue(aLineAEndPoint.x() + deltaX, aLineAEndPoint.y() + deltaY) +aSession.finishOperation() +assert (aLineBStartPointPrev == (aLineBStartPoint.x(), aLineBStartPoint.y())) +assert (aLineBEndPointPrev == (aLineBEndPoint.x(), aLineBEndPoint.y())) +aLineBStartPointPrev = (aLineBStartPoint.x(),aLineBStartPoint.y()) +aLineBEndPointPrev = (aLineBEndPoint.x(),aLineBEndPoint.y()) +# rotate line, +# check that reference's line points are moved also +aSession.startOperation() +aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y() + deltaY) +aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, aLineAEndPoint.y() - deltaY) +aSession.finishOperation() +assert (aLineBStartPointPrev != (aLineBStartPoint.x(), aLineBStartPoint.y())) +assert (aLineBEndPointPrev != (aLineBEndPoint.x(), aLineBEndPoint.y())) #========================================================================= # End of test #========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintRigid.py b/src/SketchPlugin/Test/TestConstraintRigid.py new file mode 100644 index 000000000..9f6eaf31a --- /dev/null +++ b/src/SketchPlugin/Test/TestConstraintRigid.py @@ -0,0 +1,135 @@ +""" + TestConstraintRigid.py + Unit test of SketchPlugin_ConstraintRigid class + + SketchPlugin_Constraint + static const std::string MY_CONSTRAINT_VALUE("ConstraintValue"); + static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); + static const std::string MY_ENTITY_A("ConstraintEntityA"); + 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_ConstraintRigid + static const std::string MY_CONSTRAINT_RIGID_ID("SketchConstraintRigid"); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + +""" +from GeomDataAPI import * +from ModelAPI import * +from GeomAPI import * +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2014-11-21" + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = modelAPI_CompositeFeature(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() +#========================================================================= +# Create a triangle ABC +#========================================================================= +aSession.startOperation() +aSketchLineA = aSketchFeature.addFeature("SketchLine") +aSketchLineB = aSketchFeature.addFeature("SketchLine") +aSketchLineC = aSketchFeature.addFeature("SketchLine") +aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint")) +aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint")) +aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint")) +aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint")) +aLineCStartPoint = geomDataAPI_Point2D(aSketchLineC.attribute("StartPoint")) +aLineCEndPoint = geomDataAPI_Point2D(aSketchLineC.attribute("EndPoint")) +aLineAStartPoint.setValue(25., 25.) +aLineAEndPoint.setValue(100., 25.) +aLineBStartPoint.setValue(100., 25.) +aLineBEndPoint.setValue(60., 75.) +aLineCStartPoint.setValue(60., 75.) +aLineCEndPoint.setValue(25., 25.) +aSession.finishOperation() +# Store initial values of lines +kLineAStart = (aLineAStartPoint.x(), aLineAStartPoint.y()) +kLineAEnd = (aLineAEndPoint.x(), aLineAEndPoint.y()) +kLineBStart = (aLineBStartPoint.x(), aLineBStartPoint.y()) +kLineBEnd = (aLineBEndPoint.x(), aLineBEndPoint.y()) +kLineCStart = (aLineCStartPoint.x(), aLineCStartPoint.y()) +kLineCEnd = (aLineCEndPoint.x(), aLineCEndPoint.y()) +#========================================================================= +# Link triange lines with concidence +#========================================================================= +concidenceLinks = zip([aLineBStartPoint, aLineCStartPoint, aLineAStartPoint], + [aLineAEndPoint, aLineBEndPoint, aLineCEndPoint]) +aSession.startOperation() +for eachLink in concidenceLinks: + aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence") + reflistA = aConstraint.refattr("ConstraintEntityA") + reflistB = aConstraint.refattr("ConstraintEntityB") + reflistA.setAttr(eachLink[0]) + reflistB.setAttr(eachLink[1]) + aConstraint.execute() +aSession.finishOperation() + +# Check that constarints doesn't affected lines' values +assert (kLineAStart == (aLineAStartPoint.x(), aLineAStartPoint.y())) +assert (kLineAEnd == (aLineAEndPoint.x(), aLineAEndPoint.y())) +assert (kLineBStart == (aLineBStartPoint.x(), aLineBStartPoint.y())) +assert (kLineBEnd == (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (kLineCStart == (aLineCStartPoint.x(), aLineCStartPoint.y())) +assert (kLineCEnd == (aLineCEndPoint.x(), aLineCEndPoint.y())) +#========================================================================= +# Make line A rigid +#========================================================================= +aSession.startOperation() +aRigidConstraint = aSketchFeature.addFeature("SketchConstraintRigid") +eachRefattr = aRigidConstraint.refattr("ConstraintEntityA") +lineResults = aSketchLineA.results() +for eachResult in lineResults: + if eachResult.shape().isEdge(): + break +aResult = modelAPI_ResultConstruction(eachResult) +assert (aResult is not None) +eachRefattr.setObject(aResult) +# aRigidConstraint.execute() +aSession.finishOperation() + +# Check that constarints doesn't affected lines' values +assert (kLineAStart == (aLineAStartPoint.x(), aLineAStartPoint.y())) +assert (kLineAEnd == (aLineAEndPoint.x(), aLineAEndPoint.y())) +assert (kLineBStart == (aLineBStartPoint.x(), aLineBStartPoint.y())) +assert (kLineBEnd == (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (kLineCStart == (aLineCStartPoint.x(), aLineCStartPoint.y())) +assert (kLineCEnd == (aLineCEndPoint.x(), aLineCEndPoint.y())) +#========================================================================= +# Check that +#========================================================================= +aSession.startOperation() +aLineBEndPoint.setValue(90., 150.) +aSession.finishOperation() +# Check that constarint keep features' values +assert (kLineAStart == (aLineAStartPoint.x(), aLineAStartPoint.y())) +assert (kLineAEnd == (aLineAEndPoint.x(), aLineAEndPoint.y())) +assert (kLineBStart == (aLineBStartPoint.x(), aLineBStartPoint.y())) +assert (kLineBEnd != (aLineBEndPoint.x(), aLineBEndPoint.y())) +assert (kLineCStart != (aLineCStartPoint.x(), aLineCStartPoint.y())) +assert (kLineCEnd == (aLineCEndPoint.x(), aLineCEndPoint.y())) +#========================================================================= +# TODO: improve test +# 1. remove constraint, move line to check that constraint are not applied +#========================================================================= +#========================================================================= +# End of test +#========================================================================= diff --git a/src/SketchPlugin/Test/TestHighload.py b/src/SketchPlugin/Test/TestHighload.py new file mode 100644 index 000000000..e2ca33704 --- /dev/null +++ b/src/SketchPlugin/Test/TestHighload.py @@ -0,0 +1,36 @@ +""" + TestHighload.py +""" +from GeomDataAPI import * +from ModelAPI import * +from GeomAPI import * +#========================================================================= +# Initialization of the test +#========================================================================= + +__updated__ = "2014-11-21" + +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() +#========================================================================= +# Creation of a sketch +#========================================================================= +aSession.startOperation() +aSketchCommonFeature = aDocument.addFeature("Sketch") +aSketchFeature = modelAPI_CompositeFeature(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() +#========================================================================= +# TODO: implement test +#========================================================================= +assert (False) +#========================================================================= +# End of test +#=========================================================================