Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceOverhaul/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/UndoRedo/Commands/AddShapeCommand.cs

Last change on this file was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 1.7 KB
Line 
1using System;
2using System.Drawing;
3namespace Netron.Diagramming.Core {
4  /// <summary>
5  /// ICommand implementation of the AddShape action
6  /// </summary>
7  public class AddShapeCommand : Command {
8    #region Fields
9    IShape shape;
10    Point location;
11    #endregion
12
13    #region Properties
14    public IShape Shape {
15      get { return shape; }
16    }
17    #endregion
18
19
20
21    #region Methods
22    /// <summary>
23    /// Initializes a new instance of the <see cref="T:AddShapeCommand"/> class.
24    /// </summary>
25    /// <param name="controller">The controller.</param>
26    /// <param name="shape">The shape.</param>
27    /// <param name="location">The location.</param>
28    public AddShapeCommand(
29        IController controller,
30        IShape shape,
31        Point location)
32      : base(controller) {
33      if (shape == null)
34        throw new ArgumentNullException("The shape is 'null' and cannot be inserted.");
35      this.Text = "Add " + shape.EntityName;
36
37      this.location = location;
38      this.shape = shape;
39    }
40
41    /// <summary>
42    /// Perform redo of this command.
43    /// </summary>
44    public override void Redo() {
45      Controller.Model.AddShape(shape);
46
47      shape.Transform(location.X, location.Y, shape.Width, shape.Height);
48      Rectangle rec = shape.Rectangle;
49      rec.Inflate(20, 20);
50      Controller.View.Invalidate(rec);
51    }
52
53    /// <summary>
54    /// Perform undo of this command.
55    /// </summary>
56    public override void Undo() {
57      Rectangle rec = shape.Rectangle;
58      rec.Inflate(20, 20);
59      Controller.Model.RemoveShape(shape);
60
61      Controller.View.Invalidate(rec);
62
63    }
64
65    #endregion
66
67  }
68
69}
Note: See TracBrowser for help on using the repository browser.