SketchPlugin_ConstraintCoincidence
static const std::string MY_CONSTRAINT_COINCIDENCE_ID("SketchConstraintCoincidence");
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
"""
from GeomDataAPI import *
# Initialization of the test
#=========================================================================
-__updated__ = "2014-07-28"
+__updated__ = "2014-10-28"
-aPluginManager = ModelAPI_PluginManager.get()
-aDocument = aPluginManager.rootDocument()
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
#=========================================================================
# Creation of a sketch
#=========================================================================
-aDocument.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
-diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
norm.setValue(0, 0, 1)
-aDocument.finishOperation()
+aSession.finishOperation()
#=========================================================================
# Create a line and an arc
#=========================================================================
-aDocument.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
-aSketchArc = aDocument.addFeature("SketchArc")
-aSketchReflist.append(aSketchArc)
-aSketchArcData = aSketchArc.data()
-anArcCentr = geomDataAPI_Point2D(aSketchArcData.attribute("ArcCenter"))
+aSession.startOperation()
+aSketchArc = aSketchFeature.addFeature("SketchArc")
+anArcCentr = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
anArcStartPoint = geomDataAPI_Point2D(
- aSketchArcData.attribute("ArcStartPoint"))
-anArcEndPoint = geomDataAPI_Point2D(aSketchArcData.attribute("ArcEndPoint"))
-aSketchFeature = aDocument.addFeature("SketchConstraintCoincidence")
+ aSketchArc.attribute("ArcStartPoint"))
+anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
anArcCentr.setValue(10., 10.)
anArcStartPoint.setValue(0., 50.)
anArcEndPoint.setValue(50., 0.)
-aSketchLine = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLine)
-aSketchLineData = aSketchLine.data()
-aLineStartPoint = geomDataAPI_Point2D(aSketchLineData.attribute("StartPoint"))
-aLineEndPoint = geomDataAPI_Point2D(aSketchLineData.attribute("EndPoint"))
+aSketchLine = aSketchFeature.addFeature("SketchLine")
+aLineStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+aLineEndPoint = geomDataAPI_Point2D(aSketchLine.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()
-aCoincidenceConstraint = aDocument.addFeature("SketchConstraintCoincidence")
-aConstraintData = aCoincidenceConstraint.data()
-reflistA = aConstraintData.refattr("ConstraintEntityA")
-reflistB = aConstraintData.refattr("ConstraintEntityB")
+aSession.startOperation()
+aConstraint = aSketchFeature.addFeature("SketchConstraintCoincidence")
+reflistA = aConstraint.refattr("ConstraintEntityA")
+reflistB = aConstraint.refattr("ConstraintEntityB")
reflistA.setAttr(anArcEndPoint)
reflistB.setAttr(aLineStartPoint)
-aDocument.finishOperation()
+aConstraint.execute()
+aSession.finishOperation()
#=========================================================================
# Check values and move one constrainted object
#=========================================================================
assert (aLineStartPoint.y() == 0)
deltaX = deltaY = 40.
# move line
-aDocument.startOperation()
-aLineStartPoint.setValue(aLineStartPoint.x() + deltaX,
+aSession.startOperation()
+anArcStartPoint.setValue(aLineStartPoint.x() + deltaX,
aLineStartPoint.y() + deltaY)
-aLineEndPoint.setValue(aLineEndPoint.x() + deltaX,
+anArcEndPoint.setValue(aLineEndPoint.x() + deltaX,
aLineEndPoint.y() + deltaY)
-aDocument.finishOperation()
+aSession.finishOperation()
# check that arc's points are moved also
-print ("assert anArcEndPoint.x() == %d" % anArcEndPoint.x())
-print ("assert anArcEndPoint.y() == %d" % anArcEndPoint.y())
-print ("assert aLineStartPoint.x() == %d" % aLineStartPoint.x())
-print ("assert aLineStartPoint.y() == %d" % aLineStartPoint.y())
+assert (anArcEndPoint.x() == aLineStartPoint.x())
+assert (anArcEndPoint.y() == aLineStartPoint.y())
#=========================================================================
# TODO: improve test
# 1. remove constraint, move line to check that constraint are not applied