1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Linq;
|
---|
5 | using System.Text;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.JsonInterface.OptimizerIntegration {
|
---|
9 |
|
---|
10 | public class DoubleMatrixValueVM : MatrixValueVM<double, DoubleMatrixJsonItem> {
|
---|
11 | public override Type JsonItemType => typeof(DoubleMatrixJsonItem);
|
---|
12 | public override JsonItemBaseControl Control => null;
|
---|
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, JsonItemType> : RangedValueBaseVM<T>, IMatrixJsonItemVM
|
---|
29 | where JsonItemType : IMatrixJsonItem {
|
---|
30 | public abstract T[][] Value { get; set; }
|
---|
31 | public bool RowsResizable {
|
---|
32 | get => ((IMatrixJsonItem)Item).RowsResizable;
|
---|
33 | set {
|
---|
34 | ((IMatrixJsonItem)Item).RowsResizable = value;
|
---|
35 | OnPropertyChange(this, nameof(RowsResizable));
|
---|
36 | }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public bool ColumnsResizable {
|
---|
40 | get => ((IMatrixJsonItem)Item).ColumnsResizable;
|
---|
41 | set {
|
---|
42 | ((IMatrixJsonItem)Item).ColumnsResizable = value;
|
---|
43 | OnPropertyChange(this, nameof(ColumnsResizable));
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void SetCellValue(T data, int row, int col) {
|
---|
48 |
|
---|
49 | T[][] tmp = Value;
|
---|
50 |
|
---|
51 | // increase y
|
---|
52 | if (row >= tmp.Length) { // increasing array
|
---|
53 | T[][] newArr = new T[row + 1][];
|
---|
54 | Array.Copy(tmp, 0, newArr, 0, tmp.Length);
|
---|
55 | newArr[row] = new T[0];
|
---|
56 | tmp = newArr;
|
---|
57 | }
|
---|
58 |
|
---|
59 | // increase x
|
---|
60 | for(int i = 0; i < tmp.Length; ++i) {
|
---|
61 | if(col >= tmp[i].Length) {
|
---|
62 | T[] newArr = new T[col + 1];
|
---|
63 | Array.Copy(tmp[i], 0, newArr, 0, tmp[i].Length);
|
---|
64 | tmp[i] = newArr;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | tmp[row][col] = data;
|
---|
69 | Value = tmp;
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|