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