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 |
|
---|
8 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
9 |
|
---|
10 | public class DoubleArrayValueVM : ArrayValueVM<double, DoubleArrayJsonItem> {
|
---|
11 | public override Type JsonItemType => typeof(DoubleArrayJsonItem);
|
---|
12 |
|
---|
13 | protected override double MinTypeValue => double.MinValue;
|
---|
14 |
|
---|
15 | protected override double MaxTypeValue => double.MaxValue;
|
---|
16 |
|
---|
17 | public override JsonItemBaseControl Control =>
|
---|
18 | new JsonItemBaseControl(this, new JsonItemDoubleArrayValueControl(this));
|
---|
19 |
|
---|
20 | public override double[] Value {
|
---|
21 | get => ((DoubleArrayJsonItem)Item).Value;
|
---|
22 | set {
|
---|
23 | ((DoubleArrayJsonItem)Item).Value = value;
|
---|
24 | OnPropertyChange(this, nameof(Value));
|
---|
25 | }
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public class IntArrayValueVM : ArrayValueVM<int, IntArrayJsonItem> {
|
---|
30 | public override Type JsonItemType => typeof(IntArrayJsonItem);
|
---|
31 |
|
---|
32 | protected override int MinTypeValue => int.MinValue;
|
---|
33 |
|
---|
34 | protected override int MaxTypeValue => int.MaxValue;
|
---|
35 |
|
---|
36 | public override JsonItemBaseControl Control =>
|
---|
37 | new JsonItemBaseControl(this, new JsonItemIntArrayValueControl(this));
|
---|
38 |
|
---|
39 | public override int[] Value {
|
---|
40 | get => ((IntArrayJsonItem)Item).Value;
|
---|
41 | set {
|
---|
42 | ((IntArrayJsonItem)Item).Value = value;
|
---|
43 | OnPropertyChange(this, nameof(Value));
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | public abstract class ArrayValueVM<T, JsonItemType> : RangedValueBaseVM<T>, IArrayJsonItemVM
|
---|
49 | where JsonItemType : IArrayJsonItem {
|
---|
50 |
|
---|
51 | public ArrayValueVM() { }
|
---|
52 |
|
---|
53 | public void SetIndexValue(T data, int index) {
|
---|
54 | T[] tmp = Value;
|
---|
55 | if(index >= tmp.Length) { // increasing array
|
---|
56 | T[] newArr = new T[index+1];
|
---|
57 | Array.Copy(tmp, 0, newArr, 0, tmp.Length);
|
---|
58 | tmp = newArr;
|
---|
59 | }
|
---|
60 | tmp[index] = data;
|
---|
61 | Value = tmp;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public abstract T[] Value { get; set; }
|
---|
65 | public bool Resizable {
|
---|
66 | get => ((IArrayJsonItem)Item).Resizable;
|
---|
67 | set {
|
---|
68 | ((IArrayJsonItem)Item).Resizable = value;
|
---|
69 | OnPropertyChange(this, nameof(IArrayJsonItemVM.Resizable));
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|