From f6cb1fdedc4af583c05faf3f4f55fe67b49e211a Mon Sep 17 00:00:00 2001 From: sbh Date: Fri, 26 Sep 2014 19:06:02 +0400 Subject: [PATCH] Test corrected according to changes in the API --- src/ConstructionPlugin/Test/TestPointName.py | 24 +++++--- src/ModelAPI/ModelAPI_Document.h | 9 +-- src/ModelAPI/Test/TestUndoRedo.py | 49 ++++++++------- .../Test/TestConstraintConcidence.py | 20 +++---- .../Test/TestConstraintDistance.py | 20 +++---- src/SketchPlugin/Test/TestConstraintLength.py | 45 ++++++++------ .../Test/TestConstraintParallel.py | 60 +++++++++++-------- .../Test/TestConstraintPerpendicular.py | 48 ++++++++------- src/SketchPlugin/Test/TestConstraintRadius.py | 36 +++++------ src/SketchPlugin/Test/TestSketchArcCircle.py | 32 +++++----- src/SketchPlugin/Test/TestSketchPointLine.py | 16 ++--- 11 files changed, 201 insertions(+), 158 deletions(-) diff --git a/src/ConstructionPlugin/Test/TestPointName.py b/src/ConstructionPlugin/Test/TestPointName.py index 06e70e64f..740bd52df 100644 --- a/src/ConstructionPlugin/Test/TestPointName.py +++ b/src/ConstructionPlugin/Test/TestPointName.py @@ -1,11 +1,19 @@ from ModelAPI import * -p = ModelAPI_PluginManager.get() -f = p.rootDocument().addFeature("Point") -f_name = f.data().name() -f.execute() -doc = p.rootDocument() -f1 = doc.object("Construction", 0) -f1_name = f1.data().name() +aSession = ModelAPI_Session.get() +aDoc = aSession.moduleDocument() -assert (f_name == f1_name) +aSession.startOperation() +aFeature = aDoc.addFeature("Point") +aFeatureData = aFeature.data() +aFeatureData.real("x").setValue(0.) +aFeatureData.real("y").setValue(0.) +aFeatureData.real("z").setValue(0.) +aFeatureName = aFeatureData.name() +aFeature.execute() +aSession.finishOperation() + +aFeature1 = aDoc.object("Construction", 0) +aFeature1Name = aFeature1.data().name() + +assert (aFeatureName == aFeature1Name) diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 1a5aee9bf..773ec389c 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -41,8 +41,8 @@ public: virtual boost::shared_ptr addFeature(std::string theID) = 0; //! Removes the feature from the document - virtual void removeFeature( - boost::shared_ptr theFeature, const bool theCheck = true) = 0; + virtual void removeFeature(boost::shared_ptr theFeature, + const bool theCheck = true) = 0; ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist virtual boost::shared_ptr subDocument(std::string theDocID) = 0; @@ -54,8 +54,9 @@ public: //! \param theGroupID group that contains an object //! \param theIndex zero-based index of feature in the group //! \param theHidden if it is true, it counts also the features that are not in tree - virtual boost::shared_ptr - object(const std::string& theGroupID, const int theIndex, const bool theHidden = false) = 0; + virtual boost::shared_ptr object(const std::string& theGroupID, + const int theIndex, + const bool theHidden = false) = 0; //! Returns the number of objects in the group of objects //! If theHidden is true, it counts also the features that are not in tree diff --git a/src/ModelAPI/Test/TestUndoRedo.py b/src/ModelAPI/Test/TestUndoRedo.py index 74a1315cd..1d0a37209 100644 --- a/src/ModelAPI/Test/TestUndoRedo.py +++ b/src/ModelAPI/Test/TestUndoRedo.py @@ -1,26 +1,33 @@ from ModelAPI import * -plugin_manager = ModelAPI_PluginManager.get() -doc = plugin_manager.rootDocument() -assert(not doc.canUndo()) -assert(not doc.canRedo()) +aSession = ModelAPI_Session.get() +aDoc = aSession.moduleDocument() +assert(not aSession.canUndo()) +assert(not aSession.canRedo()) -doc.startOperation() -feature = doc.addFeature("Point") -feature_name = feature.data().name() -assert(feature_name == "Point_1") +aSession.startOperation() +aFeature = aDoc.addFeature("Point") +aFeatureData = aFeature.data() +# Since validators are introduced we have to initialize all +# the feature's attributes +aFeatureData.real("x").setValue(1.) +aFeatureData.real("y").setValue(-1.) +aFeatureData.real("z").setValue(0.) +aFeatureName = aFeatureData.name() +assert(aFeatureName == "Point_1") -feature.execute() -doc.finishOperation(); -assert(doc.size("Construction") == 1) -assert(doc.canUndo()) -assert(not doc.canRedo()) +aFeature.execute() +aSession.finishOperation() -doc.undo() -assert(doc.size("Construction") == 0) -assert(not doc.canUndo()) -assert(doc.canRedo()) +assert(aDoc.size("Construction") == 1) +assert(aSession.canUndo()) +assert(not aSession.canRedo()) -doc.redo() -assert(doc.size("Construction") == 1) -assert(doc.canUndo()) -assert(not doc.canRedo()) +aSession.undo() +assert(aDoc.size("Construction") == 0) +assert(not aSession.canUndo()) +assert(aSession.canRedo()) + +aSession.redo() +assert(aDoc.size("Construction") == 1) +assert(aSession.canUndo()) +assert(not aSession.canRedo()) diff --git a/src/SketchPlugin/Test/TestConstraintConcidence.py b/src/SketchPlugin/Test/TestConstraintConcidence.py index bca011f74..da616ce62 100644 --- a/src/SketchPlugin/Test/TestConstraintConcidence.py +++ b/src/SketchPlugin/Test/TestConstraintConcidence.py @@ -24,12 +24,12 @@ from ModelAPI import * __updated__ = "2014-07-28" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -40,11 +40,11 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Create a line and an arc #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") aSketchArc = aDocument.addFeature("SketchArc") aSketchReflist.append(aSketchArc) @@ -65,11 +65,11 @@ aLineEndPoint = geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint")) # Lets initialize line start at circle's end: aLineStartPoint.setValue(50., 0.) aLineEndPoint.setValue(100., 25.) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Link arc's end and line's start points with concidence constraint #========================================================================= -aDocument.startOperation() +aSession.startOperation() aConstraint = aDocument.addFeature("SketchConstraintCoincidence") aSketchReflist.append(aConstraint) aConstraintData = aConstraint.data() @@ -77,7 +77,7 @@ reflistA = aConstraintData.refattr("ConstraintEntityA") reflistB = aConstraintData.refattr("ConstraintEntityB") reflistA.setAttr(anArcEndPoint) reflistB.setAttr(aLineStartPoint) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Check values and move one constrainted object #========================================================================= @@ -87,12 +87,12 @@ assert (aLineStartPoint.x() == 50) assert (aLineStartPoint.y() == 0) deltaX = deltaY = 40. # move line -aDocument.startOperation() +aSession.startOperation() aLineStartPoint.setValue(aLineStartPoint.x() + deltaX, aLineStartPoint.y() + deltaY) aLineEndPoint.setValue(aLineEndPoint.x() + deltaX, aLineEndPoint.y() + deltaY) -aDocument.finishOperation() +aSession.finishOperation() # check that arc's points are moved also assert (anArcEndPoint.x() == aLineStartPoint.x()) assert (anArcEndPoint.y() == aLineStartPoint.y()) diff --git a/src/SketchPlugin/Test/TestConstraintDistance.py b/src/SketchPlugin/Test/TestConstraintDistance.py index bd978fa03..2d84321be 100644 --- a/src/SketchPlugin/Test/TestConstraintDistance.py +++ b/src/SketchPlugin/Test/TestConstraintDistance.py @@ -38,12 +38,12 @@ def distance(pointA, pointB): ydiff = math.pow((pointA.y() - pointB.y()), 2) return round(math.sqrt(xdiff + ydiff), 5) -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -54,11 +54,11 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Create a point and a line #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") aSketchPoint = aDocument.addFeature("SketchPoint") aSketchReflist.append(aSketchPoint) @@ -73,12 +73,12 @@ aLineAStartPoint = geomDataAPI_Point2D( aLineAEndPoint = geomDataAPI_Point2D(aSketchLine.data().attribute("EndPoint")) aLineAStartPoint.setValue(0., 25.) aLineAEndPoint.setValue(100., 25.) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Make a constraint to keep the distance #========================================================================= assert (distance(aSketchPointCoords, aLineAStartPoint) != 25.) -aDocument.startOperation() +aSession.startOperation() aConstraint = aDocument.addFeature("SketchConstraintDistance") aSketchReflist.append(aConstraint) aConstraintData = aConstraint.data() @@ -93,7 +93,7 @@ aLineResult = aSketchLine.firstResult() assert (aLineResult is not None) refattrA.setAttr(aSketchPointCoords) refattrB.setAttr(aLineAStartPoint) -aDocument.finishOperation() +aSession.finishOperation() assert (aDistance.isInitialized()) assert (refattrA.isInitialized()) assert (refattrB.isInitialized()) @@ -101,10 +101,10 @@ assert (refattrB.isInitialized()) # Move line, check that distance is constant #========================================================================= assert (distance(aSketchPointCoords, aLineAStartPoint) == 25.) -aDocument.startOperation() +aSession.startOperation() aLineAStartPoint.setValue(0., 40.) aLineAEndPoint.setValue(100., 40.) -aDocument.finishOperation() +aSession.finishOperation() assert (distance(aSketchPointCoords, aLineAStartPoint) == 25.) #========================================================================= # TODO: improve test diff --git a/src/SketchPlugin/Test/TestConstraintLength.py b/src/SketchPlugin/Test/TestConstraintLength.py index 5cfdd78f4..28f032e4a 100644 --- a/src/SketchPlugin/Test/TestConstraintLength.py +++ b/src/SketchPlugin/Test/TestConstraintLength.py @@ -15,14 +15,14 @@ from ModelAPI import * # Initialization of the test #========================================================================= -__updated__ = "2014-07-29" +__updated__ = "2014-09-26" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -33,11 +33,11 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Create a line with length 100 #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") aSketchLineA = aDocument.addFeature("SketchLine") aSketchReflist.append(aSketchLineA) @@ -46,24 +46,25 @@ aLineAStartPoint = geomDataAPI_Point2D( aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.data().attribute("EndPoint")) aLineAStartPoint.setValue(0., 25.) aLineAEndPoint.setValue(100., 25.) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Make a constraint to keep the length #========================================================================= -aDocument.startOperation() -aCoincidenceConstraint = aDocument.addFeature("SketchConstraintLength") -aSketchReflist.append(aCoincidenceConstraint) -aConstraintData = aCoincidenceConstraint.data() -aLength = aConstraintData.real("ConstraintValue") +aSession.startOperation() +aLengthConstraint = aDocument.addFeature("SketchConstraintLength") +aSketchReflist.append(aLengthConstraint) +aConstraintData = aLengthConstraint.data() refattrA = aConstraintData.refattr("ConstraintEntityA") -assert (not aLength.isInitialized()) +aLength = aConstraintData.real("ConstraintValue") assert (not refattrA.isInitialized()) -# aLength.setValue(100.) -# refattrA.setObject(aSketchLineA) +assert (not aLength.isInitialized()) + aResult = aSketchLineA.firstResult() assert (aResult is not None) refattrA.setObject(modelAPI_ResultConstruction(aResult)) -aDocument.finishOperation() +# aLength.setValue(100.) +aLengthConstraint.execute() +aSession.finishOperation() assert (aLength.isInitialized()) assert (refattrA.isInitialized()) #========================================================================= @@ -75,15 +76,23 @@ assert (aLineAStartPoint.x() == 0) assert (aLineAStartPoint.y() == 25) assert (aLineAEndPoint.x() == 100) assert (aLineAEndPoint.y() == 25) -aDocument.startOperation() +aSession.startOperation() aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y()) -aDocument.finishOperation() +aSession.finishOperation() assert (aLineAStartPoint.y() == 25) assert (aLineAEndPoint.y() == 25) # length of the line is the same assert (aLineAEndPoint.x() - aLineAStartPoint.x() == 100) #========================================================================= +# Change the length value of the constraint +#========================================================================= +aSession.startOperation() +aLength.setValue(140.) +aLengthConstraint.execute() +aSession.finishOperation() +assert (aLineAEndPoint.x() - aLineAStartPoint.x() == 140) +#========================================================================= # TODO: improve test # 1. remove constraint, move line's start point to # check that constraint are not applied diff --git a/src/SketchPlugin/Test/TestConstraintParallel.py b/src/SketchPlugin/Test/TestConstraintParallel.py index c68314966..aa244cee7 100644 --- a/src/SketchPlugin/Test/TestConstraintParallel.py +++ b/src/SketchPlugin/Test/TestConstraintParallel.py @@ -15,14 +15,14 @@ from ModelAPI import * # Initialization of the test #========================================================================= -__updated__ = "2014-07-29" +__updated__ = "2014-09-26" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -33,11 +33,11 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Create two lines which are not parallel #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") # line A aSketchLineA = aDocument.addFeature("SketchLine") @@ -57,20 +57,22 @@ aLineBEndPoint = geomDataAPI_Point2D( aSketchLineB.data().attribute("EndPoint")) aLineBStartPoint.setValue(0., 50) aLineBEndPoint.setValue(80., 75) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Make a constraint to keep the length of the line constant # to parallel perpendicular constraint collapsing line to point #========================================================================= -aDocument.startOperation() -aLengthConstraint = aDocument.addFeature("SketchConstraintLength") -aSketchReflist.append(aLengthConstraint) -aLengthConstraintData = aLengthConstraint.data() -refattrA = aLengthConstraintData.refattr("ConstraintEntityA") -aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult()) -assert (aResultA is not None) -refattrA.setObject(aResultA) -aDocument.finishOperation() +for eachFeature in [aSketchLineA, aSketchLineB]: + aSession.startOperation() + aLengthConstraint = aDocument.addFeature("SketchConstraintLength") + aSketchReflist.append(aLengthConstraint) + aLengthConstraintData = aLengthConstraint.data() + refattrA = aLengthConstraintData.refattr("ConstraintEntityA") + aResultA = modelAPI_ResultConstruction(eachFeature.firstResult()) + assert (aResultA is not None) + refattrA.setObject(aResultA) + aLengthConstraint.execute() + aSession.finishOperation() # Coordinates of lines should not be changed after this constraint assert (aLineAStartPoint.x() == 0) assert (aLineAStartPoint.y() == 25) @@ -83,19 +85,26 @@ assert (aLineBEndPoint.y() == 75) #========================================================================= # Link lines with parallel constraint #========================================================================= -aDocument.startOperation() +aSession.startOperation() aParallelConstraint = aDocument.addFeature("SketchConstraintParallel") aSketchReflist.append(aParallelConstraint) aConstraintData = aParallelConstraint.data() refattrA = aConstraintData.refattr("ConstraintEntityA") refattrB = aConstraintData.refattr("ConstraintEntityB") # aResultA is already defined for the length constraint +aResultA = modelAPI_ResultConstruction(eachFeature.firstResult()) aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult()) assert (aResultB is not None) refattrA.setObject(aResultA) refattrB.setObject(aResultB) -aDocument.finishOperation() -# print "Link lines with parallel constraint" +aParallelConstraint.execute() +aSession.finishOperation() +#========================================================================= +# Check values and move one constrainted object +#========================================================================= +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() @@ -104,16 +113,17 @@ aDocument.finishOperation() # print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y() # print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x() # print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y() -#========================================================================= -# Check values and move one constrainted object -#========================================================================= -deltaX = deltaY = 10. -# rotate line, check that reference's line points are moved also +aLineBStartPointXPrev = aLineBStartPoint.x() +aLineBStartPointYPrev = aLineBStartPoint.y() +aLineBEndPointXPrev = aLineBEndPoint.x() +aLineBEndPointYPrev = aLineBEndPoint.y() +aSession.startOperation() 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" +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() diff --git a/src/SketchPlugin/Test/TestConstraintPerpendicular.py b/src/SketchPlugin/Test/TestConstraintPerpendicular.py index 8f8f253de..192f1d9ac 100644 --- a/src/SketchPlugin/Test/TestConstraintPerpendicular.py +++ b/src/SketchPlugin/Test/TestConstraintPerpendicular.py @@ -22,14 +22,14 @@ from ModelAPI import * # Initialization of the test #========================================================================= -__updated__ = "2014-07-29" +__updated__ = "2014-09-26" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -40,11 +40,11 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Create two lines which are already perpendicular #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") # line A aSketchLineA = aDocument.addFeature("SketchLine") @@ -64,20 +64,24 @@ aLineBEndPoint = geomDataAPI_Point2D( aSketchLineB.data().attribute("EndPoint")) aLineBStartPoint.setValue(25., 40.) aLineBEndPoint.setValue(25., 125.) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Make a constraint to keep the length of the line constant # to prevent perpendicular constraint collapsing line to point #========================================================================= -aDocument.startOperation() -aLengthConstraint = aDocument.addFeature("SketchConstraintLength") -aSketchReflist.append(aLengthConstraint) -aLengthConstraintData = aLengthConstraint.data() -refattrA = aLengthConstraintData.refattr("ConstraintEntityA") -aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult()) -assert (aResultA is not None) -refattrA.setObject(aResultA) -aDocument.finishOperation() + +for eachFeature in [aSketchLineA, aSketchLineB]: + aSession.startOperation() + aLengthConstraint = aDocument.addFeature("SketchConstraintLength") + aSketchReflist.append(aLengthConstraint) + aLengthConstraintData = aLengthConstraint.data() + refattrA = aLengthConstraintData.refattr("ConstraintEntityA") + aResultA = modelAPI_ResultConstruction(eachFeature.firstResult()) + assert (aResultA is not None) + refattrA.setObject(aResultA) + aLengthConstraint.execute() + aSession.finishOperation() + # Coordinates of lines should not be changed after this constraint assert (aLineAStartPoint.x() == 0) assert (aLineAStartPoint.y() == 25) @@ -90,10 +94,11 @@ assert (aLineBEndPoint.y() == 125) #========================================================================= # Link lines with perpendicular constraint #========================================================================= -aDocument.startOperation() -aParallelConstraint = aDocument.addFeature("SketchConstraintParallel") -aSketchReflist.append(aParallelConstraint) -aConstraintData = aParallelConstraint.data() +aSession.startOperation() +aPerpendicularConstraint = aDocument.addFeature( + "SketchConstraintPerpendicular") +aSketchReflist.append(aPerpendicularConstraint) +aConstraintData = aPerpendicularConstraint.data() refattrA = aConstraintData.refattr("ConstraintEntityA") refattrB = aConstraintData.refattr("ConstraintEntityB") # aResultA is already defined for the length constraint @@ -101,7 +106,8 @@ aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult()) assert (aResultB is not None) refattrA.setObject(aResultA) refattrB.setObject(aResultB) -aDocument.finishOperation() +aPerpendicularConstraint.execute() +aSession.finishOperation() #========================================================================= # Check values and move one constrainted object #========================================================================= diff --git a/src/SketchPlugin/Test/TestConstraintRadius.py b/src/SketchPlugin/Test/TestConstraintRadius.py index 885c385d7..630beb124 100644 --- a/src/SketchPlugin/Test/TestConstraintRadius.py +++ b/src/SketchPlugin/Test/TestConstraintRadius.py @@ -24,14 +24,14 @@ import math # Initialization of the test #========================================================================= -__updated__ = "2014-07-29" +__updated__ = "2014-09-26" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -42,11 +42,11 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Creation of an arc and a circle #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") aSketchArc = aDocument.addFeature("SketchArc") aSketchReflist.append(aSketchArc) @@ -58,9 +58,9 @@ anArcStartPoint = geomDataAPI_Point2D( anArcStartPoint.setValue(0., 50.) anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint")) anArcEndPoint.setValue(50., 0.) -aDocument.finishOperation() +aSession.finishOperation() # Circle -aDocument.startOperation() +aSession.startOperation() aSketchCircle = aDocument.addFeature("SketchCircle") aSketchReflist.append(aSketchCircle) aSketchCircleData = aSketchCircle.data() @@ -69,11 +69,11 @@ anCircleCentr = geomDataAPI_Point2D( aCircleRadius = aSketchCircleData.real("CircleRadius") anCircleCentr.setValue(-25., -25) aCircleRadius.setValue(25.) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Make a constraint to keep the radius of the arc #========================================================================= -aDocument.startOperation() +aSession.startOperation() aConstraint = aDocument.addFeature("SketchConstraintRadius") aSketchReflist.append(aConstraint) aConstraintData = aConstraint.data() @@ -82,13 +82,14 @@ aRefObject = aConstraintData.refattr("ConstraintEntityA") aResult = aSketchArc.firstResult() assert (aResult is not None) aRefObject.setObject(modelAPI_ResultConstruction(aResult)) -aDocument.finishOperation() +aConstraint.execute() +aSession.finishOperation() assert (aRadius.isInitialized()) assert (aRefObject.isInitialized()) #========================================================================= # Make a constraint to keep the radius of the circle #========================================================================= -aDocument.startOperation() +aSession.startOperation() aConstraint = aDocument.addFeature("SketchConstraintRadius") aSketchReflist.append(aConstraint) aConstraintData = aConstraint.data() @@ -97,7 +98,8 @@ aRefObject = aConstraintData.refattr("ConstraintEntityA") aResult = aSketchCircle.firstResult() assert (aResult is not None) aRefObject.setObject(modelAPI_ResultConstruction(aResult)) -aDocument.finishOperation() +aConstraint.execute() +aSession.finishOperation() assert (aRadius.isInitialized()) assert (aRefObject.isInitialized()) #========================================================================= @@ -115,9 +117,9 @@ anArcPrevEndPointY = anArcEndPoint.y() assert (anArcPrevEndPointX == 50.) assert (anArcPrevEndPointY == 0.) # Move one point of the arc -aDocument.startOperation() +aSession.startOperation() anArcStartPoint.setValue(0., 60) -aDocument.finishOperation() +aSession.finishOperation() assert (anArcCentr.x() == 10.) assert (anArcCentr.y() == 10.) assert (anArcEndPoint.x() != anArcPrevEndPointX) @@ -129,9 +131,9 @@ assert (anArcEndPoint.y() != anArcPrevEndPointY) assert (anCircleCentr.x() == -25) assert (anCircleCentr.y() == -25) assert (aCircleRadius.value() == 25) -aDocument.startOperation() +aSession.startOperation() anCircleCentr.setValue(100., 100.) -aDocument.finishOperation() +aSession.finishOperation() assert (anCircleCentr.x() == 100) assert (anCircleCentr.y() == 100) assert (aCircleRadius.value() == 25) diff --git a/src/SketchPlugin/Test/TestSketchArcCircle.py b/src/SketchPlugin/Test/TestSketchArcCircle.py index 304f0e334..4223d5c35 100644 --- a/src/SketchPlugin/Test/TestSketchArcCircle.py +++ b/src/SketchPlugin/Test/TestSketchArcCircle.py @@ -24,12 +24,12 @@ from ModelAPI import * __updated__ = "2014-07-25" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") aSketchFeatureData = aSketchFeature.data() origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) @@ -40,13 +40,13 @@ diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY")) diry.setValue(0, 1, 0) norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm")) norm.setValue(0, 0, 1) -aDocument.finishOperation() +aSession.finishOperation() #========================================================================= # Creation of an arc # 1. Test SketchPlugin_Arc attributes # 2. #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") assert (not aSketchReflist.isInitialized()) assert (aSketchReflist.size() == 0) @@ -70,7 +70,7 @@ assert (anArcEndPoint.x() == 0) assert (anArcEndPoint.y() == 0) assert (not anArcEndPoint.isInitialized()) anArcEndPoint.setValue(50., 0.) -aDocument.finishOperation() +aSession.finishOperation() # check that values have been changed aSketchReflist = aSketchFeatureData.reflist("Features") assert (aSketchReflist.size() == 1) @@ -86,12 +86,12 @@ assert (anArcEndPoint.y() == 0.0) # 1. Move whole arc # 2. Change the start point #=============================================================================== -aDocument.startOperation() +aSession.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() +aSession.finishOperation() assert (anArcCentr.x() == 15) assert (anArcCentr.y() == 20) assert (anArcStartPoint.x() == 5) @@ -99,11 +99,11 @@ assert (anArcStartPoint.y() == 60) assert (anArcEndPoint.x() == 55) assert (anArcEndPoint.y() == 10) # Change the start point -aDocument.startOperation() +aSession.startOperation() anArcStartPoint.setValue(anArcStartPoint.x() + deltaX, anArcStartPoint.y()) aPrevEndPointX = anArcEndPoint.x() aPrevEndPointY = anArcEndPoint.y() -aDocument.finishOperation() +aSession.finishOperation() assert (anArcCentr.x() == 15) assert (anArcCentr.y() == 20) assert (anArcStartPoint.x() == 10) @@ -123,7 +123,7 @@ assert (not aShape.isNull()) # 1. Test SketchPlugin_Circle.h attributes # 2. ModelAPI_AttributeDouble attribute #=============================================================================== -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") # Arc is already added assert (aSketchReflist.size() == 1) @@ -146,21 +146,21 @@ aCircleRadius.setValue(25.) assert (anCircleCentr.x() == -25) assert (anCircleCentr.y() == -25) assert (aCircleRadius.value() == 25) -aDocument.finishOperation() +aSession.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() +aSession.startOperation() anCircleCentr.setValue(10, 60) -aDocument.finishOperation() +aSession.finishOperation() assert (anCircleCentr.x() == 10) assert (anCircleCentr.y() == 60) assert (aCircleRadius.value() == 25) -aDocument.startOperation() +aSession.startOperation() aCircleRadius.setValue(int(20)) -aDocument.finishOperation() +aSession.finishOperation() assert (anCircleCentr.x() == 10) assert (anCircleCentr.y() == 60) assert (aCircleRadius.value() == 20) diff --git a/src/SketchPlugin/Test/TestSketchPointLine.py b/src/SketchPlugin/Test/TestSketchPointLine.py index d5c675528..dd90e27fd 100644 --- a/src/SketchPlugin/Test/TestSketchPointLine.py +++ b/src/SketchPlugin/Test/TestSketchPointLine.py @@ -6,12 +6,12 @@ from ModelAPI import * __updated__ = "2014-07-24" -aPluginManager = ModelAPI_PluginManager.get() -aDocument = aPluginManager.rootDocument() +aSession = ModelAPI_Session.get() +aDocument = aSession.moduleDocument() #========================================================================= # Creation of a sketch #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchFeature = aDocument.addFeature("Sketch") assert (aSketchFeature.getKind() == "Sketch") aSketchFeatureData = aSketchFeature.data() @@ -23,7 +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() +aSession.finishOperation() # check that values have been changed origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin")) assert (origin.x() == 0) @@ -44,7 +44,7 @@ assert (norm.z() == 1) #========================================================================= # Creation of a point #========================================================================= -aDocument.startOperation() +aSession.startOperation() aSketchReflist = aSketchFeatureData.reflist("Features") assert (not aSketchReflist.isInitialized()) assert(aSketchReflist.size() == 0) @@ -60,7 +60,7 @@ assert (not coords.isInitialized()) # Simulate SketchPlugin_Point::move(...) coords.setValue(10., 10.) assert (coords.isInitialized()) -aDocument.finishOperation() +aSession.finishOperation() # check that values have been changed aSketchReflist = aSketchFeatureData.reflist("Features") assert (aSketchReflist.size() == 1) @@ -72,7 +72,7 @@ assert (coords.y() == 10.0) #=============================================================================== # Creation of a line #=============================================================================== -aDocument.startOperation() +aSession.startOperation() aSketchLine = aDocument.addFeature("SketchLine") assert (aSketchLine.getKind() == "SketchLine") aSketchReflist.append(aSketchLine) @@ -92,7 +92,7 @@ aLineStartPoint.setValue(50., 50.) aLineEndPoint.setValue(60., 60.) assert (aLineStartPoint.isInitialized()) assert (aLineEndPoint.isInitialized()) -aDocument.finishOperation() +aSession.finishOperation() # check that values have been changed aSketchLineData = aSketchLine.data() aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint")) -- 2.39.2