Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionTracking.Views/3.4/VisualGenealogyGraphArc.cs @ 11763

Last change on this file since 11763 was 10271, checked in by bburlacu, 11 years ago

#1772: Fixed namespaces.

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 HeuristicLab.Visualization;
25
26namespace HeuristicLab.EvolutionTracking.Views {
27  public class VisualGenealogyGraphArc : Line {
28    public VisualGenealogyGraphNode Source;
29    public VisualGenealogyGraphNode Target;
30
31    public VisualGenealogyGraphArc(IChart chart, PointD start, PointD end)
32      : base(chart, start, end) {
33    }
34    public VisualGenealogyGraphArc(IChart chart, double x1, double y1, double x2, double y2)
35      : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
36    }
37    public VisualGenealogyGraphArc(IChart chart, PointD start, PointD end, Pen pen)
38      : base(chart, start, end, pen) {
39    }
40    public VisualGenealogyGraphArc(IChart chart, VisualGenealogyGraphNode source, VisualGenealogyGraphNode target, Pen pen)
41      : base(chart, source.Center, target.Center, pen) {
42      Source = source;
43      Target = target;
44      UpdatePosition();
45    }
46    public VisualGenealogyGraphArc(IChart chart, double x1, double y1, double x2, double y2, Pen pen)
47      : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen) {
48    }
49
50    internal void UpdatePosition() {
51      if (Source.Equals(Target)) return;
52      // calculate the positions of the arc ends so that virtually the line will go through the centers of the two elliptical node shapes
53      PointD c1 = Source.Center;
54      PointD c2 = Target.Center;
55      double x = Math.Abs(c1.X - c2.X);
56      double y = Math.Abs(c1.Y - c2.Y);
57      double theta = Math.Atan(y / x); // returns angle in radians
58      // compute the intersection point between an ellipse-shaped node and a line passing through its center with the angular coordinate theta
59      PointD p1 = Source.CalculateIntersection(theta);
60      PointD p2 = Target.CalculateIntersection(theta);
61      // translate coordinates to real-world values
62      double p1X, p1Y, p2X, p2Y;
63      if (c1.X > c2.X) {
64        p1X = c1.X - p1.X;
65        p2X = c2.X + p2.X;
66      } else {
67        p1X = c1.X + p1.X;
68        p2X = c2.X - p2.X;
69      }
70      if (c1.Y > c2.Y) {
71        p1Y = c1.Y - p1.Y;
72        p2Y = c2.Y + p2.Y;
73      } else {
74        p1Y = c1.Y + p1.Y;
75        p2Y = c2.Y - p1.Y;
76      }
77      if (double.IsNaN(p1X) || double.IsNaN(p1Y) || double.IsNaN(p2X) || double.IsNaN(p2Y))
78        throw new Exception("Error calculating arc position.");
79      p1.X = p1X;
80      p1.Y = p1Y;
81      p2.X = p2X;
82      p2.Y = p2Y;
83      SetPosition(p1, p2);
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.