Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/BoxChart/EmptyBoxChartElementGenerator.cs @ 17460

Last change on this file since 17460 was 16995, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

File size: 3.5 KB
Line 
1using System;
2using System.Drawing;
3using System.Text;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Optimization;
8using HeuristicLab.Parameters;
9using HEAL.Attic;
10
11namespace HeuristicLab.Analysis.FitnessLandscape.BoxCharts {
12
13  [StorableType("A3B05023-AFF2-4550-A78C-F0513F308316")]
14  public class EmptyBoxChartElementGenerator : ParameterizedNamedItem, IBoxChartElementGenerator {
15
16    public ValueParameter<IntValue> XParameter {
17      get { return (ValueParameter<IntValue>)Parameters["X"]; }
18    }
19    public ValueParameter<IntValue> YParameter {
20      get { return (ValueParameter<IntValue>)Parameters["Y"]; }
21    }
22    public ValueParameter<IntValue> RowSpanParameter {
23      get { return (ValueParameter<IntValue>)Parameters["RowSpan"]; }
24    }
25    public ValueParameter<IntValue> ColSpanParameter {
26      get { return (ValueParameter<IntValue>)Parameters["ColSpan"]; }
27    }
28
29    public int X {
30      get { return XParameter.Value.Value; }
31      set { XParameter.Value.Value = value; }
32    }
33    public int Y {
34      get { return YParameter.Value.Value; }
35      set { YParameter.Value.Value = value; }
36    }
37    public int ColSpan {
38      get { return ColSpanParameter.Value.Value; }
39      set { ColSpanParameter.Value.Value = value; }
40    }
41    public int RowSpan {
42      get { return RowSpanParameter.Value.Value; }
43      set { RowSpanParameter.Value.Value = value; }
44    }
45
46    #region Construction & Cloning
47    [StorableConstructor]
48    protected EmptyBoxChartElementGenerator(StorableConstructorFlag _) : base(_) { }
49    protected EmptyBoxChartElementGenerator(EmptyBoxChartElementGenerator original, Cloner cloner) : base(original, cloner) {
50      RegisterEvents();
51    }
52    public EmptyBoxChartElementGenerator() {
53      Parameters.Add(new ValueParameter<IntValue>("X", "The x coordinate of the generated element.", new IntValue(0)));
54      Parameters.Add(new ValueParameter<IntValue>("Y", "The y coordinate of the generated element.", new IntValue(0)));
55      Parameters.Add(new ValueParameter<IntValue>("RowSpan", "The number of rows occupied by the generated element.", new IntValue(1)));
56      Parameters.Add(new ValueParameter<IntValue>("ColSpan", "The number of columns occupied by the generated element.", new IntValue(1)));
57      RegisterEvents();
58      if (GetType() == typeof(EmptyBoxChartElementGenerator))
59        UpdateName();
60    }
61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new EmptyBoxChartElementGenerator(this, cloner);
63    }
64    [StorableHook(HookType.AfterDeserialization)]
65    private void AfterDeserialization() {
66      RegisterEvents();
67    }
68    #endregion
69
70    private void RegisterEvents() {
71      XParameter.ToStringChanged += new EventHandler(Parameters_Changed);
72      YParameter.ToStringChanged += new EventHandler(Parameters_Changed);
73      RowSpanParameter.ToStringChanged +=new EventHandler(Parameters_Changed);
74      ColSpanParameter.ToStringChanged += new EventHandler(Parameters_Changed);
75    }
76
77    private void Parameters_Changed(object sender, EventArgs e) {
78      UpdateName();
79    }
80
81    protected virtual string CalculateName() {
82      var sb = new StringBuilder();
83      sb.AppendFormat("({0}, {1})", X, Y);
84      if (RowSpan != 1 || ColSpan != 1)
85        sb.AppendFormat("+[{0}, {1}]", ColSpan, RowSpan);
86      return sb.ToString();
87    }
88
89    protected void UpdateName() {
90      name = CalculateName();
91      OnNameChanged();
92    }
93
94    public virtual void Draw(IRun run, Graphics g) { }
95  }
96}
Note: See TracBrowser for help on using the repository browser.