#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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.Linq; using System.Windows.Forms; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.MainForm; using HeuristicLab.Visualization; namespace HeuristicLab.VariableInteractionNetworks.Views { public class DirectedGraphChartMode : SelectChartMode { public DirectedGraphChartMode(DirectedGraphChart control) : base(control) { } public DirectedGraphChart Control { get { return (DirectedGraphChart)chartControl; } } public override void HandleOnMouseDoubleClick(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; if (sp is RectangularPrimitiveBase) { var vertex = Control.GetVertex(sp) as IVertex; if (vertex != null) { var content = vertex.Data as IContent; if (content != null) { MainFormManager.MainForm.ShowContent(content); } } } } finally { chartControl.ResumeRendering(); } break; } } finally { base.HandleOnMouseDown(sender, e); } } public override void HandleOnMouseMove(object sender, MouseEventArgs e) { try { 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))) { var lp = p as LabeledPrimitive; if (lp == null) continue; p.Move(previousWorldLocation, offset); var rect = lp.Primitive as Rectangle; var ell = lp.Primitive as Ellipse; if (rect == null && ell == null) continue; var v = Control.GetVertex(p); if (v == null) continue; // ends of outgoing arcs need to be properly adjusted foreach (var arc in v.InArcs) { var r = (LabeledPrimitive)Control.GetVertexShape(arc.Source); var line = (Line)Control.GetArcShape(arc); var tmp = new Line(this.chartControl.Chart, r.Primitive.Center(), lp.Primitive.Center()); var intersect = rect == null ? ell.ComputeIntersect(tmp) : rect.ComputeIntersect(tmp); if (intersect.Any()) line.SetPosition(tmp.Start, intersect.First()); } foreach (var arc in v.OutArcs) { var r = (LabeledPrimitive)Control.GetVertexShape(arc.Target); rect = r.Primitive as Rectangle; ell = r.Primitive as Ellipse; var line = (Line)Control.GetArcShape(arc); var tmp = new Line(this.chartControl.Chart, lp.Primitive.Center(), r.Primitive.Center()); var intersect = rect == null ? ell.ComputeIntersect(tmp) : rect.ComputeIntersect(tmp); if (intersect.Any()) line.SetPosition(tmp.Start, intersect.First()); } } } finally { chartControl.ResumeRendering(); } break; } } finally { base.HandleOnMouseMove(sender, e); } } } }