Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17464 was 17464, checked in by dpiringe, 5 years ago

#3026:

  • Runner now uses SymbolicDataAnalysisExpressionMATLABFormatter to save instances of ISymbolicRegressionSolution
  • refactored user controls for detail view of json items, now they do not inherit from JsonItemBaseControl -> JsonItemBaseControl uses now an extra control
    • this change was made for fluid repositioning of controls (e.g. when no ActualName is present)
File size: 2.2 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, 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}
Note: See TracBrowser for help on using the repository browser.