Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13108 was 13108, checked in by jkarder, 8 years ago

#1265: moved previousLocation assignment to ChartMode class

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 ToolTip { get { return "Select"; } }
31
32    public SelectChartMode(ChartControl control) : base(control) { }
33
34    public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
35      base.HandleOnKeyDown(sender, e);
36
37      switch (e.KeyCode) {
38        case Keys.Delete:
39          if (e.KeyCode == Keys.Delete) {
40            try {
41              chartControl.SuspendRendering();
42              foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives)
43                chartControl.Chart.Group.Remove(primitive);
44            } finally { chartControl.ResumeRendering(); }
45          }
46          break;
47      }
48    }
49
50    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
51      base.HandleOnMouseDown(sender, e);
52
53      try {
54        chartControl.SuspendRendering();
55        var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
56        foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
57          sp.Selected = false;
58        var p = chartControl.Chart.GetPrimitive(e.Location);
59        if (p != null) p.Selected = true;
60      } finally { chartControl.ResumeRendering(); }
61    }
62
63    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
64      base.HandleOnMouseUp(sender, e);
65
66      switch (e.Button) {
67        case MouseButtons.Middle:
68          try {
69            chartControl.SuspendRendering();
70            foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
71              p.Selected = false;
72          } finally { chartControl.ResumeRendering(); }
73          break;
74      }
75    }
76
77    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
78      try {
79        cursor = chartControl.Chart.GetCursor(e.Location);
80
81        switch (e.Button) {
82          case MouseButtons.Left:
83            var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation);
84            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
85            var offset = worldLocation - previousWorldLocation;
86            try {
87              chartControl.SuspendRendering();
88              foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
89                primitive.Move(previousWorldLocation, offset);
90            } finally { chartControl.ResumeRendering(); }
91            break;
92        }
93      } finally {
94        chartControl.PictureBox.Update();
95        base.HandleOnMouseMove(sender, e);
96      }
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.