Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionaryTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/VisualGenealogyGraphArc.cs @ 7792

Last change on this file since 7792 was 7779, checked in by bburlacu, 12 years ago

#1772: Implemented new View, improved functionality (tracking of fragments and operators)

File size: 3.1 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.EvolutionaryTracking.Views {
27  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      // calculate the positions of the arc ends so that virtually the line will go through the centers of the two elliptical node shapes
52      PointD c1 = Source.Center;
53      PointD c2 = Target.Center;
54      double x = Math.Abs(c1.X - c2.X);
55      double y = Math.Abs(c1.Y - c2.Y);
56      double theta = Math.Atan(y / x); // returns angle in radians
57      // compute the intersection point between an ellipse-shaped node and a line passing through its center with the angular coordinate theta
58      PointD p1 = Source.CalculateIntersection(theta);
59      PointD p2 = Target.CalculateIntersection(theta);
60      // translate coordinates to real-world values
61      double p1X, p1Y, p2X, p2Y;
62      if (c1.X > c2.X) {
63        p1X = c1.X - p1.X;
64        p2X = c2.X + p2.X;
65      } else {
66        p1X = c1.X + p1.X;
67        p2X = c2.X - p2.X;
68      }
69      if (c1.Y > c2.Y) {
70        p1Y = c1.Y - p1.Y;
71        p2Y = c2.Y + p2.Y;
72      } else {
73        p1Y = c1.Y + p1.Y;
74        p2Y = c2.Y - p1.Y;
75      }
76      p1.X = p1X;
77      p1.Y = p1Y;
78      p2.X = p2X;
79      p2.Y = p2Y;
80      SetPosition(p1, p2);
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.