Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/LayoutNode.cs @ 15612

Last change on this file since 15612 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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.Collections.Generic;
24using System.Linq;
25
26namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
27  internal class LayoutNode<T> : object where T : class {
28    public float Width { get; set; }
29    public float Height { get; set; }
30
31    public LayoutNode<T> NextLeft {
32      get {
33        return Children == null ? Thread : Children.First();
34      }
35    }
36    public LayoutNode<T> NextRight {
37      get {
38        return Children == null ? Thread : Children.Last();
39      }
40    }
41    public LayoutNode<T> LeftSibling {
42      get {
43        if (Parent == null) return null;
44        return Number == 0 ? null : Parent.Children[Number - 1];
45      }
46    }
47    public LayoutNode<T> LeftmostSibling {
48      get {
49        if (Parent == null) return null;
50        return Number == 0 ? null : Parent.Children[0];
51      }
52    }
53
54    public LayoutNode<T> Thread { get; set; }
55    public LayoutNode<T> Ancestor { get; set; }
56    public LayoutNode<T> Parent { get; set; }
57    public List<LayoutNode<T>> Children { get; set; }
58    public float Mod { get; set; }
59    public float Prelim { get; set; }
60    public float Change { get; set; }
61    public float Shift { get; set; }
62    public int Number { get; set; }
63    public int Level { get; set; }
64    public float X { get; set; }
65    public float Y { get; set; }
66
67    public bool IsLeaf {
68      get { return Children == null || Children.Count == 0; }
69    }
70
71    private T content;
72    public T Content {
73      get { return content; }
74      set {
75        if (value == null)
76          throw new ArgumentNullException("LayoutNode: Content cannot be null.");
77        content = value;
78      }
79    }
80    /// <summary>
81    /// Translate the position of the layout node according to the given offsets
82    /// </summary>
83    /// <param name="dx"></param>
84    /// <param name="dy"></param>
85    public void Translate(float dx, float dy) {
86      X += dx;
87      Y += dy;
88    }
89
90    public void ResetCoordinates() {
91      X = 0;
92      Y = 0;
93    }
94
95    /// <summary>
96    /// Reset layout-related parameters
97    /// </summary>
98    public void Reset() {
99      Ancestor = this;
100      Thread = null;
101      Change = 0;
102      Shift = 0;
103      Prelim = 0;
104      Mod = 0;
105      ResetCoordinates();
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.