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> {
|
---|
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 GetControl() => new JsonItemDoubleArrayValueControl(this);
|
---|
18 |
|
---|
19 | public override double[] Value {
|
---|
20 | get => ((DoubleArrayJsonItem)Item).Value;
|
---|
21 | set {
|
---|
22 | ((DoubleArrayJsonItem)Item).Value = value;
|
---|
23 | OnPropertyChange(this, nameof(Value));
|
---|
24 | }
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | public class IntArrayValueVM : ArrayValueVM<int> {
|
---|
29 | public override Type JsonItemType => typeof(IntArrayJsonItem);
|
---|
30 |
|
---|
31 | protected override int MinTypeValue => int.MinValue;
|
---|
32 |
|
---|
33 | protected override int MaxTypeValue => int.MaxValue;
|
---|
34 |
|
---|
35 | public override JsonItemBaseControl GetControl() => new JsonItemIntArrayValueControl(this);
|
---|
36 |
|
---|
37 | public override int[] Value {
|
---|
38 | get => ((IntArrayJsonItem)Item).Value;
|
---|
39 | set {
|
---|
40 | ((IntArrayJsonItem)Item).Value = value;
|
---|
41 | OnPropertyChange(this, nameof(Value));
|
---|
42 | }
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | public abstract class ArrayValueVM<T> : RangedValueBaseVM<T> {
|
---|
47 |
|
---|
48 | public ArrayValueVM() {
|
---|
49 | //base.ItemChanged += OnItemChanged;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void SetIndexValue(object obj, int index) {
|
---|
53 | T[] tmp = Value;
|
---|
54 | if(index >= tmp.Length) { // increasing array
|
---|
55 | T[] newArr = new T[index+1];
|
---|
56 | Array.Copy(tmp, 0, newArr, 0, tmp.Length);
|
---|
57 | tmp = newArr;
|
---|
58 | }
|
---|
59 | tmp[index] = (T)Convert.ChangeType(obj, typeof(T));
|
---|
60 | Value = tmp;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public abstract T[] Value { get; set; }
|
---|
64 | }
|
---|
65 | }
|
---|