using System.Drawing; namespace Netron.Diagramming.Core { /// /// ICommand implementation of the move action /// class MoveCommand : Command { #region Fields IBundle bundle; IController controller; Point delta; #endregion #region Properties /// /// Gets the shape. /// /// The shape. public CollectionBase Entities { get { return bundle.Entities; } } #endregion #region Constructor /// /// Initializes a new instance of the class. /// /// The controller. /// The bundle. /// The delta. public MoveCommand(IController controller, IBundle bundle, Point delta) : base(controller) { this.Text = "Move " + bundle.EntityName; this.controller = controller; this.delta = delta; this.bundle = bundle; } #endregion #region Methods /// /// Perform redo of this command. /// public override void Redo() { bundle.MoveBy(delta); //invalidate the space before the move Rectangle rec = bundle.Rectangle; rec.Offset(-delta.X, -delta.Y); rec.Inflate(20, 20); bundle.Invalidate(rec);//same as an invalidate on the controller level //invalidate the current neighborhood of the bundle bundle.Invalidate(); } /// /// Perform undo of this command. /// public override void Undo() { bundle.MoveBy(new Point(-delta.X, -delta.Y)); //invert the vector //invalidate the space before the move Rectangle rec = bundle.Rectangle; rec.Offset(delta.X, delta.Y); rec.Inflate(20, 20); bundle.Invalidate(rec);//same as an invalidate on the controller level //invalidate the current neighborhood of the bundle bundle.Invalidate(); } #endregion } }