Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.EvolutionaryTracking.Views/3.4/Primitives/PrimitiveGroup.cs @ 10265

Last change on this file since 10265 was 10264, checked in by bburlacu, 11 years ago

#1772: Created new branch for the redesigned version of the tracking plugin

File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Collections.Generic;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Visualization;
27
28namespace HeuristicLab.EvolutionaryTracking.Views.Primitives {
29  // a class representing a primitive group with an area defined by the LowerLeft and UpperRight points
30  // the area is important for deciding which group was selected and for layouting
31  public class PrimitiveGroup : Group, ILayoutNode<ISymbolicExpressionTree> {
32    // two points to determine the area of the primitive group
33    private PointF lowerLeft;
34    public PointF LowerLeft {
35      get { return lowerLeft; }
36      set { lowerLeft = value; }
37    }
38    private PointF upperRight;
39    public PointF UpperRight {
40      get { return upperRight; }
41      set { upperRight = value; }
42    }
43
44    public PrimitiveGroup(IChart chart)
45      : base(chart) {
46      lowerLeft = new PointF();
47      upperRight = new PointF();
48    }
49
50    public SizeF Size {
51      get { return new SizeF(upperRight.X - lowerLeft.X, upperRight.Y - lowerLeft.Y); }
52    }
53
54    public void UpdateBounds() {
55      // update corner points
56      var primitives = Primitives.Where(p => p is RectangularPrimitiveBase).Cast<RectangularPrimitiveBase>().ToList();
57      var xmin = (float)primitives.Min(p => p.LowerLeft.X);
58      var ymin = (float)primitives.Min(p => p.LowerLeft.Y);
59      LowerLeft = new PointF(xmin, ymin);
60
61      var xmax = (float)primitives.Max(p => p.UpperRight.X);
62      var ymax = (float)primitives.Max(p => p.UpperRight.Y);
63      UpperRight = new PointF(xmax, ymax);
64    }
65    public override void AddRange(IEnumerable<IPrimitive> primitives) {
66      foreach (var primitive in primitives)
67        Add(primitive);
68    }
69    public override void Move(Offset delta) {
70      base.Move(delta);
71      UpdateBounds();
72    }
73    public bool IsLeaf {
74      get { return Children == null || Children.Count == 0; }
75    }
76    public ILayoutNode<ISymbolicExpressionTree> NextLeft {
77      get {
78        return Children == null ? Thread : Children.First();
79      }
80    }
81    public ILayoutNode<ISymbolicExpressionTree> NextRight {
82      get {
83        return Children == null ? Thread : Children.Last();
84      }
85    }
86    public ILayoutNode<ISymbolicExpressionTree> LeftSibling {
87      get {
88        if (Parent == null) return null;
89        return Number == 0 ? null : Parent.Children[Number - 1];
90      }
91    }
92    public ILayoutNode<ISymbolicExpressionTree> LeftmostSibling {
93      get {
94        if (Parent == null) return null;
95        return Number == 0 ? null : Parent.Children[0];
96      }
97    }
98
99    public ILayoutNode<ISymbolicExpressionTree> Thread { get; set; }
100    public ILayoutNode<ISymbolicExpressionTree> Ancestor { get; set; }
101    public ILayoutNode<ISymbolicExpressionTree> Parent { get; set; }
102    public List<ILayoutNode<ISymbolicExpressionTree>> Children { get; set; }
103    public float Mod { get; set; }
104    public float Prelim { get; set; }
105    public float Change { get; set; }
106    public float Shift { get; set; }
107    public int Number { get; set; }
108    public int Level { get; set; }
109    public float X { get; set; }
110    public float Y { get; set; }
111
112    public ISymbolicExpressionTree Content { get; set; }
113  }
114}
Note: See TracBrowser for help on using the repository browser.