Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/MatrixValueVM.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.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() => new JsonItemDoubleMatrixValueControl(this);
13
14    public override double[][] Value {
15      get => ((DoubleMatrixJsonItem)Item).Value;
16      set {
17        ((DoubleMatrixJsonItem)Item).Value = value;
18        OnPropertyChange(this, nameof(Value));
19      }
20    }
21
22    protected override double MinTypeValue => double.MinValue;
23
24    protected override double MaxTypeValue => double.MaxValue;
25  }
26
27  public abstract class MatrixValueVM<T> : RangedValueBaseVM<T> {
28
29    public MatrixValueVM() {}
30    public void SetCellValue(object obj, int col, int row) {
31      T[][] tmp = Value;
32     
33      if (row >= tmp.Length) { // increasing array
34        T[][] newArr = new T[row + 1][];
35        Array.Copy(tmp, 0, newArr, 0, tmp.Length);
36        newArr[row] = new T[0];
37        tmp = newArr;
38      }
39      for(int i = 0; i < tmp.Length; ++i) {
40        if(col >= tmp[i].Length) {
41          T[] newArr = new T[col + 1];
42          Array.Copy(tmp[i], 0, newArr, 0, tmp[i].Length);
43          tmp[i] = newArr;
44        }
45      }
46      tmp[row][col] = (T)Convert.ChangeType(obj.ToString().Replace(",","."),
47                                            typeof(T),
48                                            System.Globalization.CultureInfo.InvariantCulture);
49      Value = tmp;
50    }
51
52    public abstract T[][] Value { get; set; }
53
54  }
55}
Note: See TracBrowser for help on using the repository browser.