Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/MatrixValueVM.cs @ 17444

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

#3026:

  • added property Description in IJsonItem and updated all construction calls
  • updated UnsupportedJsonItem with unsupported property Description
  • updated JsonItemBaseControl and JsonItemVMBase for new property Description
File size: 1.7 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 DoubleMatrixValueVM : MatrixValueVM<double> {
11    public override Type JsonItemType => typeof(DoubleMatrixJsonItem);
12    public override JsonItemBaseControl GetControl() =>
13      new JsonItemDoubleMatrixValueControl(this);
14
15    public override double[][] Value {
16      get => ((DoubleMatrixJsonItem)Item).Value;
17      set {
18        ((DoubleMatrixJsonItem)Item).Value = value;
19        OnPropertyChange(this, nameof(Value));
20      }
21    }
22
23    protected override double MinTypeValue => double.MinValue;
24
25    protected override double MaxTypeValue => double.MaxValue;
26  }
27
28  public abstract class MatrixValueVM<T> : RangedValueBaseVM<T> {
29
30    public MatrixValueVM() {}
31    public void SetCellValue(object obj, int col, int row) {
32      T[][] tmp = Value;
33     
34      if (row >= tmp.Length) { // increasing array
35        T[][] newArr = new T[row + 1][];
36        Array.Copy(tmp, 0, newArr, 0, tmp.Length);
37        newArr[row] = new T[0];
38        tmp = newArr;
39      }
40      for(int i = 0; i < tmp.Length; ++i) {
41        if(col >= tmp[i].Length) {
42          T[] newArr = new T[col + 1];
43          Array.Copy(tmp[i], 0, newArr, 0, tmp[i].Length);
44          tmp[i] = newArr;
45        }
46      }
47      tmp[row][col] = (T)Convert.ChangeType(obj.ToString().Replace(",","."),
48                                            typeof(T),
49                                            System.Globalization.CultureInfo.InvariantCulture);
50      Value = tmp;
51    }
52
53    public abstract T[][] Value { get; set; }
54
55  }
56}
Note: See TracBrowser for help on using the repository browser.