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)
virtual boost::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
//! Removes the feature from the document
- virtual void removeFeature(
- boost::shared_ptr<ModelAPI_Feature> theFeature, const bool theCheck = true) = 0;
+ virtual void removeFeature(boost::shared_ptr<ModelAPI_Feature> 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<ModelAPI_Document> subDocument(std::string theDocID) = 0;
//! \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<ModelAPI_Object>
- object(const std::string& theGroupID, const int theIndex, const bool theHidden = false) = 0;
+ virtual boost::shared_ptr<ModelAPI_Object> 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
from ModelAPI import *\r
-plugin_manager = ModelAPI_PluginManager.get()\r
-doc = plugin_manager.rootDocument()\r
-assert(not doc.canUndo())\r
-assert(not doc.canRedo()) \r
+aSession = ModelAPI_Session.get()\r
+aDoc = aSession.moduleDocument()\r
+assert(not aSession.canUndo())\r
+assert(not aSession.canRedo())\r
\r
-doc.startOperation()\r
-feature = doc.addFeature("Point")\r
-feature_name = feature.data().name()\r
-assert(feature_name == "Point_1")\r
+aSession.startOperation()\r
+aFeature = aDoc.addFeature("Point")\r
+aFeatureData = aFeature.data()\r
+# Since validators are introduced we have to initialize all\r
+# the feature's attributes\r
+aFeatureData.real("x").setValue(1.)\r
+aFeatureData.real("y").setValue(-1.)\r
+aFeatureData.real("z").setValue(0.)\r
+aFeatureName = aFeatureData.name()\r
+assert(aFeatureName == "Point_1")\r
\r
-feature.execute()\r
-doc.finishOperation();\r
-assert(doc.size("Construction") == 1)\r
-assert(doc.canUndo())\r
-assert(not doc.canRedo()) \r
+aFeature.execute()\r
+aSession.finishOperation()\r
\r
-doc.undo()\r
-assert(doc.size("Construction") == 0)\r
-assert(not doc.canUndo())\r
-assert(doc.canRedo())\r
+assert(aDoc.size("Construction") == 1)\r
+assert(aSession.canUndo())\r
+assert(not aSession.canRedo())\r
\r
-doc.redo()\r
-assert(doc.size("Construction") == 1)\r
-assert(doc.canUndo())\r
-assert(not doc.canRedo())\r
+aSession.undo()\r
+assert(aDoc.size("Construction") == 0)\r
+assert(not aSession.canUndo())\r
+assert(aSession.canRedo())\r
+\r
+aSession.redo()\r
+assert(aDoc.size("Construction") == 1)\r
+assert(aSession.canUndo())\r
+assert(not aSession.canRedo())\r
__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"))
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)
# 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()
reflistB = aConstraintData.refattr("ConstraintEntityB")
reflistA.setAttr(anArcEndPoint)
reflistB.setAttr(aLineStartPoint)
-aDocument.finishOperation()
+aSession.finishOperation()
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
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())
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"))
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)
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()
assert (aLineResult is not None)
refattrA.setAttr(aSketchPointCoords)
refattrB.setAttr(aLineAStartPoint)
-aDocument.finishOperation()
+aSession.finishOperation()
assert (aDistance.isInitialized())
assert (refattrA.isInitialized())
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
# 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"))
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)
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())
#=========================================================================
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
# 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"))
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")
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)
#=========================================================================
# 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()
# 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()
# 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"))
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")
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)
#=========================================================================
# 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
assert (aResultB is not None)
refattrA.setObject(aResultA)
refattrB.setObject(aResultB)
-aDocument.finishOperation()
+aPerpendicularConstraint.execute()
+aSession.finishOperation()
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
# 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"))
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)
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()
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()
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()
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())
#=========================================================================
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)
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)
__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"))
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)
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)
# 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)
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)
# 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)
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)
__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()
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)
#=========================================================================
# Creation of a point
#=========================================================================
-aDocument.startOperation()
+aSession.startOperation()
aSketchReflist = aSketchFeatureData.reflist("Features")
assert (not aSketchReflist.isInitialized())
assert(aSketchReflist.size() == 0)
# 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)
#===============================================================================
# Creation of a line
#===============================================================================
-aDocument.startOperation()
+aSession.startOperation()
aSketchLine = aDocument.addFeature("SketchLine")
assert (aSketchLine.getKind() == "SketchLine")
aSketchReflist.append(aSketchLine)
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"))