[10264] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using HeuristicLab.Visualization;
|
---|
| 26 |
|
---|
[10271] | 27 | namespace HeuristicLab.EvolutionTracking.Views {
|
---|
[10264] | 28 | public class VisualGenealogyGraphNode : Ellipse {
|
---|
[10269] | 29 | public IGenealogyGraphNode Data { get; internal set; }
|
---|
[10264] | 30 | private List<VisualGenealogyGraphArc> incomingArcs = new List<VisualGenealogyGraphArc>();
|
---|
| 31 | private List<VisualGenealogyGraphArc> outgoingArcs = new List<VisualGenealogyGraphArc>();
|
---|
| 32 |
|
---|
| 33 | public List<VisualGenealogyGraphArc> IncomingArcs {
|
---|
| 34 | get { return incomingArcs; }
|
---|
| 35 | set { incomingArcs = value; }
|
---|
| 36 | }
|
---|
| 37 | public List<VisualGenealogyGraphArc> OutgoingArcs {
|
---|
| 38 | get { return outgoingArcs; }
|
---|
| 39 | set { outgoingArcs = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public float LineWidth {
|
---|
| 43 | get { return Pen.Width; }
|
---|
| 44 | set { Pen.Width = value; }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public VisualGenealogyGraphNode(IChart chart, PointD lowerLeft, PointD upperRight)
|
---|
| 48 | : base(chart, lowerLeft, upperRight) {
|
---|
| 49 | }
|
---|
| 50 | public VisualGenealogyGraphNode(IChart chart, double x1, double y1, double x2, double y2)
|
---|
| 51 | : this(chart, new PointD(x1, y1), new PointD(x2, y2)) {
|
---|
| 52 | }
|
---|
| 53 | public VisualGenealogyGraphNode(IChart chart, PointD lowerLeft, PointD upperRight, Pen pen, Brush brush)
|
---|
| 54 | : base(chart, lowerLeft, upperRight, pen, brush) {
|
---|
| 55 | }
|
---|
| 56 | public VisualGenealogyGraphNode(IChart chart, double x1, double y1, double x2, double y2, Pen pen, Brush brush)
|
---|
| 57 | : this(chart, new PointD(x1, y1), new PointD(x2, y2), pen, brush) {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | // compute the intersection point of an ellipse and a line passing through its center with the angular coordinate theta
|
---|
| 61 | public PointD CalculateIntersection(double theta) {
|
---|
| 62 | double sin = Math.Sin(theta);
|
---|
| 63 | double cos = Math.Cos(theta);
|
---|
| 64 | double a = Size.Width / 2;
|
---|
| 65 | double b = Size.Height / 2;
|
---|
| 66 | double r = a * b / Math.Sqrt(Math.Pow(a * sin, 2) + Math.Pow(b * cos, 2)); // radius at intersection point
|
---|
| 67 | double rx = r * cos; // X-component (relative to the origin/center of the ellipse)
|
---|
| 68 | double ry = r * sin; // Y-component (relative to the origin/center of the ellipse)
|
---|
| 69 | return new PointD(rx, ry);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[10730] | 72 | public override void SetPosition(PointD lowerLeft, PointD upperRight) {
|
---|
| 73 | base.SetPosition(lowerLeft, upperRight);
|
---|
[10264] | 74 | foreach (var a in IncomingArcs) a.UpdatePosition();
|
---|
| 75 | foreach (var a in OutgoingArcs) a.UpdatePosition();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | public PointD Center {
|
---|
| 79 | get { return new PointD((LowerLeft.X + UpperRight.X) / 2, (LowerLeft.Y + UpperRight.Y) / 2); }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public override void Draw(Graphics graphics) {
|
---|
| 83 | Point p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
|
---|
| 84 | Size s = Chart.TransformWorldToPixel(Size);
|
---|
[10730] | 85 | if (Brush != null) {
|
---|
[10264] | 86 | graphics.FillEllipse(Brush, p.X, p.Y, s.Width, s.Height);
|
---|
[10730] | 87 | graphics.DrawEllipse(Pen, p.X, p.Y, s.Width, s.Height);
|
---|
| 88 | if (Data.IsElite) {
|
---|
| 89 | graphics.DrawEllipse(Pen, p.X + 2, p.Y + 2, s.Width - 4, s.Height - 4);
|
---|
| 90 | }
|
---|
[10264] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | }
|
---|