1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 | using System.Windows.Forms;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
10 | public class IntValueVM : SingleValueVM<int> {
|
---|
11 | public override Type JsonItemType => typeof(IntJsonItem);
|
---|
12 |
|
---|
13 | protected override int MinTypeValue => int.MinValue;
|
---|
14 | protected override int MaxTypeValue => int.MaxValue;
|
---|
15 |
|
---|
16 | public override JsonItemBaseControl GetControl() =>
|
---|
17 | new JsonItemIntValueControl(this);
|
---|
18 | }
|
---|
19 |
|
---|
20 | public class DoubleValueVM : SingleValueVM<double> {
|
---|
21 | public override Type JsonItemType => typeof(DoubleJsonItem);
|
---|
22 |
|
---|
23 | protected override double MinTypeValue => double.MinValue;
|
---|
24 | protected override double MaxTypeValue => double.MaxValue;
|
---|
25 |
|
---|
26 | public override JsonItemBaseControl GetControl() =>
|
---|
27 | new JsonItemDoubleValueControl(this);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public class BoolValueVM : SingleValueVM<bool> {
|
---|
31 | public override Type JsonItemType => typeof(BoolJsonItem);
|
---|
32 |
|
---|
33 | protected override bool MinTypeValue => false;
|
---|
34 | protected override bool MaxTypeValue => true;
|
---|
35 |
|
---|
36 | public override JsonItemBaseControl GetControl() =>
|
---|
37 | new JsonItemBoolControl(this);
|
---|
38 | }
|
---|
39 |
|
---|
40 | public abstract class SingleValueVM<T> : JsonItemVMBase {
|
---|
41 |
|
---|
42 | public T Value {
|
---|
43 | get => Cast(Item.Value);
|
---|
44 | set {
|
---|
45 | Item.Value = value;
|
---|
46 | OnPropertyChange(this, nameof(Value));
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public T MinRange {
|
---|
51 | get => Cast(Item.Range.First());
|
---|
52 | set {
|
---|
53 | SetRange(value, Item.Range.Last());
|
---|
54 | OnPropertyChange(this, nameof(MinRange));
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public T MaxRange {
|
---|
59 | get => Cast(Item.Range.Last());
|
---|
60 | set {
|
---|
61 | SetRange(Item.Range.First(), value);
|
---|
62 | OnPropertyChange(this, nameof(MaxRange));
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | private bool enableMinRange = false;
|
---|
67 | public bool EnableMinRange {
|
---|
68 | get => enableMinRange;
|
---|
69 | set {
|
---|
70 | enableMinRange = value;
|
---|
71 | if (!enableMinRange)
|
---|
72 | MinRange = MinTypeValue;
|
---|
73 | OnPropertyChange(this, nameof(EnableMinRange));
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | private bool enableMaxRange = false;
|
---|
78 | public bool EnableMaxRange {
|
---|
79 | get => enableMaxRange;
|
---|
80 | set {
|
---|
81 | enableMaxRange = value;
|
---|
82 | if (!enableMaxRange)
|
---|
83 | MaxRange = MaxTypeValue;
|
---|
84 | OnPropertyChange(this, nameof(EnableMaxRange));
|
---|
85 | }
|
---|
86 | }
|
---|
87 |
|
---|
88 | private T Cast(object obj) => (T)Convert.ChangeType(obj, typeof(T));
|
---|
89 |
|
---|
90 | private void SetRange(object min, object max) {
|
---|
91 | object[] range = new object[] { min, max };
|
---|
92 | Item.Range = range;
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected abstract T MinTypeValue { get; }
|
---|
96 | protected abstract T MaxTypeValue { get; }
|
---|
97 | }
|
---|
98 | }
|
---|