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> {
|
---|
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 | }
|
---|