#region License Information /* HeuristicLab * Copyright (C) 2002-2010 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; using System.Drawing; using HeuristicLab.Visualization; namespace HeuristicLab.EvolutionTracking.Views { public class VisualGenealogyGraphArc : Line { public VisualGenealogyGraphNode Source; public VisualGenealogyGraphNode Target; public VisualGenealogyGraphArc(IChart chart, PointD start, PointD end) : base(chart, start, end) { } public VisualGenealogyGraphArc(IChart chart, double x1, double y1, double x2, double y2) : this(chart, new PointD(x1, y1), new PointD(x2, y2)) { } public VisualGenealogyGraphArc(IChart chart, PointD start, PointD end, Pen pen) : base(chart, start, end, pen) { } public VisualGenealogyGraphArc(IChart chart, VisualGenealogyGraphNode source, VisualGenealogyGraphNode target, Pen pen) : base(chart, source.Center, target.Center, pen) { Source = source; Target = target; UpdatePosition(); } public VisualGenealogyGraphArc(IChart chart, double x1, double y1, double x2, double y2, Pen pen) : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen) { } internal void UpdatePosition() { if (Source.Equals(Target)) return; // calculate the positions of the arc ends so that virtually the line will go through the centers of the two elliptical node shapes PointD c1 = Source.Center; PointD c2 = Target.Center; double x = Math.Abs(c1.X - c2.X); double y = Math.Abs(c1.Y - c2.Y); double theta = Math.Atan(y / x); // returns angle in radians // compute the intersection point between an ellipse-shaped node and a line passing through its center with the angular coordinate theta PointD p1 = Source.CalculateIntersection(theta); PointD p2 = Target.CalculateIntersection(theta); // translate coordinates to real-world values double p1X, p1Y, p2X, p2Y; if (c1.X > c2.X) { p1X = c1.X - p1.X; p2X = c2.X + p2.X; } else { p1X = c1.X + p1.X; p2X = c2.X - p2.X; } if (c1.Y > c2.Y) { p1Y = c1.Y - p1.Y; p2Y = c2.Y + p2.Y; } else { p1Y = c1.Y + p1.Y; p2Y = c2.Y - p1.Y; } if (double.IsNaN(p1X) || double.IsNaN(p1Y) || double.IsNaN(p2X) || double.IsNaN(p2Y)) throw new Exception("Error calculating arc position."); p1.X = p1X; p1.Y = p1Y; p2.X = p2X; p2.Y = p2Y; SetPosition(p1, p2); } } }