Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ArrayValueVM.cs @ 17473

Last change on this file since 17473 was 17473, checked in by dpiringe, 4 years ago

#3026:

  • refactored inheritance structure of json items, now the default JsonItem is an abstract class without properties Value and Range -> splitted up into new interfaces
  • updated view models for new json item structure
  • updated SingleLineArrayJsonWriter
File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using System.Windows.Forms;
8
9namespace HeuristicLab.JsonInterface.OptimizerIntegration {
10
11  public class DoubleArrayValueVM : ArrayValueVM<double, DoubleArrayJsonItem> {
12    public override Type TargetedJsonItemType => typeof(DoubleArrayJsonItem);
13
14    protected override double MinTypeValue => double.MinValue;
15
16    protected override double MaxTypeValue => double.MaxValue;
17
18    public override UserControl Control =>
19      new JsonItemDoubleArrayValueControl(this);
20   
21    public override double[] Value {
22      get => ((DoubleArrayJsonItem)Item).Value;
23      set {
24        ((DoubleArrayJsonItem)Item).Value = value;
25        OnPropertyChange(this, nameof(Value));
26      }
27    }
28  }
29
30  public class IntArrayValueVM : ArrayValueVM<int, IntArrayJsonItem> {
31    public override Type TargetedJsonItemType => typeof(IntArrayJsonItem);
32
33    protected override int MinTypeValue => int.MinValue;
34
35    protected override int MaxTypeValue => int.MaxValue;
36
37    public override UserControl Control =>
38      new JsonItemBaseControl(this, new JsonItemIntArrayValueControl(this));
39   
40    public override int[] Value {
41      get => ((IntArrayJsonItem)Item).Value;
42      set {
43        ((IntArrayJsonItem)Item).Value = value;
44        OnPropertyChange(this, nameof(Value));
45      }
46    }
47  }
48
49  public abstract class ArrayValueVM<T, JsonItemType> : RangedValueBaseVM<T, JsonItemType>, IArrayJsonItemVM
50    where T : IComparable
51    where JsonItemType : class, IArrayJsonItem, IIntervalRestrictedJsonItem<T> {
52   
53    public ArrayValueVM() { }
54
55    public void SetIndexValue(T data, int index) {
56      T[] tmp = Value;
57      if(index >= tmp.Length) { // increasing array
58        T[] newArr = new T[index+1];
59        Array.Copy(tmp, 0, newArr, 0, tmp.Length);
60        tmp = newArr;
61      }
62      tmp[index] = data;
63      Value = tmp;
64    }
65
66    public abstract T[] Value { get; set; }
67    public bool Resizable {
68      get => ((IArrayJsonItem)Item).Resizable;
69      set {
70        ((IArrayJsonItem)Item).Resizable = value;
71        OnPropertyChange(this, nameof(IArrayJsonItemVM.Resizable));
72      }
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.