#region License Information /* HeuristicLab * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Drawing; using System.Linq; using System.Windows.Forms; using HeuristicLab.Common.Resources; namespace HeuristicLab.Visualization { public class SelectChartMode : ChartMode { public override Image Image { get { return VSImageLibrary.Pointer; } } public override string Text { get { return "&Select"; } } public override string ToolTipText { get { return "Select"; } } public SelectChartMode(ChartControl control) : base(control) { } protected override void OnDeselected() { try { chartControl.SuspendRendering(); foreach (var p in chartControl.Chart.Group.SelectedPrimitives) p.Selected = false; } finally { chartControl.ResumeRendering(); base.OnDeselected(); } } public override void HandleOnKeyDown(object sender, KeyEventArgs e) { try { switch (e.KeyCode) { case Keys.Delete: try { chartControl.SuspendRendering(); foreach (var p in chartControl.Chart.Group.SelectedPrimitives) chartControl.Chart.Group.Remove(p); } finally { chartControl.ResumeRendering(); } break; } } finally { base.HandleOnKeyDown(sender, e); } } public override void HandleOnMouseDown(object sender, MouseEventArgs e) { try { switch (e.Button) { case MouseButtons.Left: try { chartControl.SuspendRendering(); var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation))) p.Selected = false; var sp = chartControl.Chart.GetPrimitive(e.Location); if (sp != null) sp.Selected = true; } finally { chartControl.ResumeRendering(); } break; } } finally { base.HandleOnMouseDown(sender, e); } } public override void HandleOnMouseMove(object sender, MouseEventArgs e) { try { cursor = chartControl.Chart.GetCursor(e.Location); switch (e.Button) { case MouseButtons.Left: var previousWorldLocation = chartControl.Chart.TransformPixelToWorld(previousLocation); var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location); var offset = worldLocation - previousWorldLocation; try { chartControl.SuspendRendering(); foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation))) p.Move(previousWorldLocation, offset); } finally { chartControl.ResumeRendering(); } break; } } finally { chartControl.UpdatePicture(); base.HandleOnMouseMove(sender, e); } } } }