Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/SelectChartMode.cs @ 13717

Last change on this file since 13717 was 13717, checked in by bburlacu, 8 years ago

#1265: Updated license year to 2016.

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Drawing;
23using System.Linq;
24using System.Windows.Forms;
25using HeuristicLab.Common.Resources;
26
27namespace HeuristicLab.Visualization {
28  public class SelectChartMode : ChartMode {
29    public override Image Image { get { return VSImageLibrary.Pointer; } }
30    public override string Text { get { return "&Select"; } }
31    public override string ToolTipText { get { return "Select"; } }
32
33    public SelectChartMode(ChartControl control) : base(control) { }
34
35    protected override void OnDeselected() {
36      try {
37        chartControl.SuspendRendering();
38        foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
39          p.Selected = false;
40      } finally {
41        chartControl.ResumeRendering();
42        base.OnDeselected();
43      }
44    }
45
46    public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
47      try {
48        switch (e.KeyCode) {
49          case Keys.Delete:
50            try {
51              chartControl.SuspendRendering();
52              foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
53                chartControl.Chart.Group.Remove(p);
54            } finally { chartControl.ResumeRendering(); }
55            break;
56        }
57      } finally {
58        base.HandleOnKeyDown(sender, e);
59      }
60    }
61
62    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
63      try {
64        switch (e.Button) {
65          case MouseButtons.Left:
66            try {
67              chartControl.SuspendRendering();
68              var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
69              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
70                p.Selected = false;
71              var sp = chartControl.Chart.GetPrimitive(e.Location);
72              if (sp != null) sp.Selected = true;
73            } finally { chartControl.ResumeRendering(); }
74            break;
75        }
76      } finally {
77        base.HandleOnMouseDown(sender, e);
78      }
79    }
80
81    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
82      try {
83        cursor = chartControl.Chart.GetCursor(e.Location);
84
85        switch (e.Button) {
86          case MouseButtons.Left:
87            var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation);
88            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
89            var offset = worldLocation - previousWorldLocation;
90            try {
91              chartControl.SuspendRendering();
92              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
93                p.Move(previousWorldLocation, offset);
94            } finally { chartControl.ResumeRendering(); }
95            break;
96        }
97      } finally {
98        chartControl.UpdatePicture();
99        base.HandleOnMouseMove(sender, e);
100      }
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.