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 |
|
---|
22 | using System.Drawing;
|
---|
23 | using System.Linq;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Common.Resources;
|
---|
26 |
|
---|
27 | namespace 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 | public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
|
---|
36 | try {
|
---|
37 | switch (e.KeyCode) {
|
---|
38 | case Keys.Delete:
|
---|
39 | try {
|
---|
40 | chartControl.SuspendRendering();
|
---|
41 | foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives)
|
---|
42 | chartControl.Chart.Group.Remove(primitive);
|
---|
43 | } finally { chartControl.ResumeRendering(); }
|
---|
44 |
|
---|
45 | break;
|
---|
46 | }
|
---|
47 | } finally {
|
---|
48 | base.HandleOnKeyDown(sender, e);
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
|
---|
53 | try {
|
---|
54 | switch (e.Button) {
|
---|
55 | case MouseButtons.Left:
|
---|
56 | try {
|
---|
57 | chartControl.SuspendRendering();
|
---|
58 | var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
|
---|
59 | foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
|
---|
60 | sp.Selected = false;
|
---|
61 | var p = chartControl.Chart.GetPrimitive(e.Location);
|
---|
62 | if (p != null) p.Selected = true;
|
---|
63 | } finally { chartControl.ResumeRendering(); }
|
---|
64 | break;
|
---|
65 | }
|
---|
66 | } finally {
|
---|
67 | base.HandleOnMouseDown(sender, e);
|
---|
68 | }
|
---|
69 | }
|
---|
70 |
|
---|
71 | public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
|
---|
72 | try {
|
---|
73 | cursor = chartControl.Chart.GetCursor(e.Location);
|
---|
74 |
|
---|
75 | switch (e.Button) {
|
---|
76 | case MouseButtons.Left:
|
---|
77 | var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation);
|
---|
78 | var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
|
---|
79 | var offset = worldLocation - previousWorldLocation;
|
---|
80 | try {
|
---|
81 | chartControl.SuspendRendering();
|
---|
82 | foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
|
---|
83 | primitive.Move(previousWorldLocation, offset);
|
---|
84 | } finally { chartControl.ResumeRendering(); }
|
---|
85 | break;
|
---|
86 | }
|
---|
87 | } finally {
|
---|
88 | chartControl.UpdatePicture();
|
---|
89 | base.HandleOnMouseMove(sender, e);
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|