/// <summary> /// /// </summary> /// <param name="pt"></param> private void MoveVertex(System.Drawing.Point pt) { if (this.Controller == null || this.View == null) { return; } if (this.editMode != EditMode.Moving || this.trackingNode == null) { return; } if (this.View.Grid.SnapToGrid) { pt = this.View.SnapPointToGrid(pt); } IPoints objPoints = this.trackingNode as IPoints; if (objPoints != null) { this.View.Refresh(this.trackingRect); ITransform objXform = this.trackingNode as ITransform; PointF[] ptWorld = new PointF[1] { this.View.ViewToWorld(this.View.DeviceToView(pt)) }; if (objXform != null) { Matrix worldTransform = objXform.WorldTransform; worldTransform.Invert(); worldTransform.TransformPoints(ptWorld); } objPoints.SetPoint(this.vertexIdx, ptWorld[0]); int prevStack = Global.SelectMatrixStack(Global.TemporaryStack); Global.MatrixStack.Clear(); ITransform nodeTrans = this.trackingNode as ITransform; if (nodeTrans != null) { Global.MatrixStack.Push(nodeTrans.ParentTransform); } IGraphics nodeGrfx = this.trackingNode as IGraphics; if (nodeGrfx != null) { this.trackingPath = nodeGrfx.GraphicsPath; } Global.SelectMatrixStack(prevStack); this.trackingRect = this.View.DrawTrackingPath(this.trackingPath); } }
/// <summary> /// Moves the vertex of the node by the specified amount. /// </summary> /// <param name="cmdTarget">Unused</param> /// <returns>true if successful, otherwise false</returns> /// <remarks> /// The node must support the IPoints interface. The IPoints.SetPoint /// method is used to move the point by the specified offset. /// </remarks> public override bool Do(object cmdTarget) { bool success = false; if (this.Node != null) { IPoints objPoints = this.Node as IPoints; if (objPoints != null) { ITransform objTransform = this.Node as ITransform; Matrix worldXform = null; Matrix invWorldXform = null; if (objTransform != null) { worldXform = objTransform.WorldTransform; invWorldXform = worldXform.Clone(); invWorldXform.Invert(); } if (this.vertexIdx >= 0 && this.vertexIdx < objPoints.PointCount) { PointF[] pt = new PointF[1] { objPoints.GetPoint(this.vertexIdx) }; if (worldXform != null) { worldXform.TransformPoints(pt); } pt[0].X += this.dx; pt[0].Y += this.dy; if (invWorldXform != null) { invWorldXform.TransformPoints(pt); } objPoints.SetPoint(this.vertexIdx, pt[0]); success = true; } } } return(success); }
/// <summary> /// Moves the vertex back to the position it was in before the /// command was executed. /// </summary> /// <returns>true if successful, otherwise false</returns> public override bool Undo() { bool success = false; if (this.Node != null) { IPoints objPoints = this.Node as IPoints; if (objPoints != null) { if (this.vertexIdx >= 0 && this.vertexIdx < objPoints.PointCount) { PointF pt = objPoints.GetPoint(this.vertexIdx); pt.X -= this.dx; pt.Y -= this.dy; objPoints.SetPoint(this.vertexIdx, pt); success = true; } } } return(success); }
/// <summary> /// /// </summary> /// <param name="node"></param> /// <param name="vertexIdx"></param> /// <param name="startingPt"></param> private void BeginVertexMove(INode node, int vertexIdx, System.Drawing.Point startingPt) { this.node = node; this.vertexIdx = vertexIdx; if (this.View.Grid.SnapToGrid) { this.startingPoint = this.View.SnapPointToGrid(startingPt); } else { this.startingPoint = startingPt; } this.trackingNode = null; this.trackingPath = null; if (this.Controller == null || this.View == null) { return; } if (this.node != null) { this.node = node; this.trackingNode = (INode)this.node.Clone(); IPoints objPoints = this.trackingNode as IPoints; if (objPoints != null) { ITransform objXform = this.trackingNode as ITransform; PointF[] ptWorld = new PointF[1] { this.View.ViewToWorld(this.View.DeviceToView(startingPt)) }; if (objXform != null) { Matrix worldTransform = objXform.WorldTransform; worldTransform.Invert(); worldTransform.TransformPoints(ptWorld); } objPoints.SetPoint(this.vertexIdx, ptWorld[0]); } int prevStack = Global.SelectMatrixStack(Global.TemporaryStack); Global.MatrixStack.Clear(); ITransform nodeTrans = this.trackingNode as ITransform; if (nodeTrans != null) { Global.MatrixStack.Push(nodeTrans.ParentTransform); } IGraphics nodeGrfx = this.trackingNode as IGraphics; if (nodeGrfx != null) { this.trackingPath = nodeGrfx.GraphicsPath; } Global.SelectMatrixStack(prevStack); this.trackingRect = this.View.DrawTrackingPath(this.trackingPath); this.editMode = EditMode.Moving; } }