using System; using System.Drawing; namespace Netron.Diagramming.Core { /// /// ICommand implementation of the AddShape action /// public class AddShapeCommand : Command { #region Fields IShape shape; Point location; #endregion #region Properties public IShape Shape { get { return shape; } } #endregion #region Methods /// /// Initializes a new instance of the class. /// /// The controller. /// The shape. /// The location. public AddShapeCommand( IController controller, IShape shape, Point location) : base(controller) { if (shape == null) throw new ArgumentNullException("The shape is 'null' and cannot be inserted."); this.Text = "Add " + shape.EntityName; this.location = location; this.shape = shape; } /// /// Perform redo of this command. /// public override void Redo() { Controller.Model.AddShape(shape); shape.Transform(location.X, location.Y, shape.Width, shape.Height); Rectangle rec = shape.Rectangle; rec.Inflate(20, 20); Controller.View.Invalidate(rec); } /// /// Perform undo of this command. /// public override void Undo() { Rectangle rec = shape.Rectangle; rec.Inflate(20, 20); Controller.Model.RemoveShape(shape); Controller.View.Invalidate(rec); } #endregion } }