Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1265_HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/SelectChartMode.cs @ 18242

Last change on this file since 18242 was 13798, checked in by jkarder, 9 years ago

#1265: worked on visualization

  • fixed bug in primitive selection
  • added SelectedPrimitivesChanged event
File size: 3.9 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;
23using System.Drawing;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Common.Resources;
27
28namespace HeuristicLab.Visualization {
29  public class SelectChartMode : ChartMode {
30    public override Image Image { get { return VSImageLibrary.Pointer; } }
31    public override string Text { get { return "&Select"; } }
32    public override string ToolTipText { get { return "Select"; } }
33
34    public SelectChartMode(ChartControl control) : base(control) {
35      localShortcuts.Add(new Shortcut(Keys.Delete) { DownAction = DeleteSelectedPrimitives });
36    }
37
38    protected override void OnDeselected() {
39      try {
40        chartControl.SuspendRendering();
41        foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
42          p.Selected = false;
43      } finally {
44        chartControl.ResumeRendering();
45        base.OnDeselected();
46      }
47    }
48
49    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
50      try {
51        switch (e.Button) {
52          case MouseButtons.Left:
53            try {
54              chartControl.SuspendRendering();
55              var sp = chartControl.Chart.GetPrimitive(e.Location);
56              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(x => x != sp))
57                p.Selected = false;
58              if (sp != null) sp.Selected = true;
59              OnSelectedPrimitivesChanged();
60            } finally { chartControl.ResumeRendering(); }
61            break;
62        }
63      } finally {
64        base.HandleOnMouseDown(sender, e);
65      }
66    }
67
68    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
69      try {
70        cursor = chartControl.Chart.GetCursor(e.Location);
71
72        switch (e.Button) {
73          case MouseButtons.Left:
74            var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation);
75            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
76            var offset = worldLocation - previousWorldLocation;
77            try {
78              chartControl.SuspendRendering();
79              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
80                p.Move(previousWorldLocation, offset);
81            } finally { chartControl.ResumeRendering(); }
82            break;
83        }
84      } finally {
85        chartControl.UpdatePicture();
86        base.HandleOnMouseMove(sender, e);
87      }
88    }
89
90    protected virtual void DeleteSelectedPrimitives() {
91      try {
92        chartControl.SuspendRendering();
93        foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
94          chartControl.Chart.Group.Remove(p);
95        OnSelectedPrimitivesChanged();
96      } finally { chartControl.ResumeRendering(); }
97    }
98
99    public event EventHandler SelectedPrimitivesChanged;
100    protected virtual void OnSelectedPrimitivesChanged() {
101      var handler = SelectedPrimitivesChanged;
102      if (handler != null) handler(this, EventArgs.Empty);
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.