Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • renamed JsonItemArrayValueControl to JsonItemMultiValueControl
  • extracted converter logic from property Value in JsonItem<V,R> into new private method ConvertObject
  • added references to TreeNode and TreeView in JsonItemVMBase -> for additional user feedback when enabling/disabling an item (changes the fore color of referenced node)
  • changed implementation and interplay between ArrayValueVM and JsonItemMultiValueControl -> removed the direct access of property DataSource of DataGridView -> now: dynamically adds new columns/rows and accesses grid cells manually (better handling with matrices)
  • added new VM MatrixValueVM
File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace 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}
Note: See TracBrowser for help on using the repository browser.