Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Tools/EllipseTool.cs @ 18242

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

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

File size: 2.5 KB
Line 
1using System.Drawing;
2
3namespace Netron.Diagramming.Core {
4  /// <summary>
5  /// Tool to draw an ellipse on the canvas
6  /// <seealso cref="RectangleTool"/>
7  /// </summary>
8  public class EllipseTool : AbstractDrawingTool {
9    #region Fields
10
11    #endregion
12
13    #region Properties
14
15    #endregion
16
17    #region Constructor
18    public EllipseTool()
19      : base("Ellipse Tool") {
20    }
21    public EllipseTool(string name)
22      : base(name) {
23
24    }
25    #endregion
26
27    #region Methods
28
29    // ------------------------------------------------------------------
30    /// <summary>
31    /// Activates the tool - the cursor is set to the Cursors.DrawRectangle.
32    /// </summary>
33    // ------------------------------------------------------------------
34    protected override void OnActivateTool() {
35      base.OnActivateTool();
36      Cursor = CursorPalette.DrawEllipse;
37    }
38
39    /// <summary>
40    /// Handles the mouse move event.
41    /// </summary>
42    /// <param name="e">The <see cref="T:System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
43    protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) {
44      base.OnMouseMove(e);
45      if (IsActive && started) {
46        Point point = new Point(e.X, e.Y);
47        Controller.View.PaintGhostEllipse(startingPoint, point);
48        Controller.View.Invalidate(System.Drawing.Rectangle.Inflate(Controller.View.Ghost.Rectangle, 20, 20));
49      }
50    }
51
52
53    /// <summary>
54    /// This method will be called when the user has finished drawing a ghost rectangle or bundle
55    /// and initiates the actual creation of a bundle and the addition to the model via the appropriate command.
56    /// </summary>
57    protected override void GhostDrawingComplete() {
58      if ((IsActive == false) ||
59          (started == false)) {
60        return;
61      }
62
63      try {
64        SimpleEllipse shape = new SimpleEllipse(this.Controller.Model);
65        shape.Width = (int)Rectangle.Width;
66        shape.Height = (int)Rectangle.Height;
67        AddShapeCommand cmd = new AddShapeCommand(
68            this.Controller,
69            shape,
70            new Point((int)Rectangle.X, (int)Rectangle.Y));
71        this.Controller.UndoManager.AddUndoCommand(cmd);
72        cmd.Redo();
73      }
74      catch {
75        base.Controller.DeactivateTool(this);
76        Controller.View.Invalidate();
77        throw;
78      }
79
80      //base.Controller.DeactivateTool(this);
81    }
82
83
84    #endregion
85  }
86
87}
Note: See TracBrowser for help on using the repository browser.