Changeset 17431
- Timestamp:
- 02/10/20 16:46:09 (5 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 1 added
- 6 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/HeuristicLab.JsonInterface.OptimizerIntegration.csproj
r17420 r17431 97 97 <Compile Include="ViewModels\ArrayValueVM.cs" /> 98 98 <Compile Include="ViewModels\JsonItemVMBase.cs" /> 99 <Compile Include="ViewModels\MatrixValueVM.cs" /> 99 100 <Compile Include="ViewModels\RangedValueBaseVM.cs" /> 100 101 <Compile Include="ViewModels\RangeVM.cs" /> … … 108 109 </Compile> 109 110 <Compile Include="FileManager.cs" /> 110 <Compile Include="Views\JsonItem ArrayValueControl.cs">111 <SubType>UserControl</SubType> 112 </Compile> 113 <Compile Include="Views\JsonItem ArrayValueControl.Designer.cs">114 <DependentUpon>JsonItem ArrayValueControl.cs</DependentUpon>111 <Compile Include="Views\JsonItemMultiValueControl.cs"> 112 <SubType>UserControl</SubType> 113 </Compile> 114 <Compile Include="Views\JsonItemMultiValueControl.Designer.cs"> 115 <DependentUpon>JsonItemMultiValueControl.cs</DependentUpon> 115 116 </Compile> 116 117 <Compile Include="Views\JsonItemBoolControl.cs"> … … 199 200 <DependentUpon>ExportJsonDialog.cs</DependentUpon> 200 201 </EmbeddedResource> 201 <EmbeddedResource Include="Views\JsonItem ArrayValueControl.resx">202 <DependentUpon>JsonItem ArrayValueControl.cs</DependentUpon>202 <EmbeddedResource Include="Views\JsonItemMultiValueControl.resx"> 203 <DependentUpon>JsonItemMultiValueControl.cs</DependentUpon> 203 204 </EmbeddedResource> 204 205 <EmbeddedResource Include="Views\JsonItemBoolControl.resx"> -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/JsonItemBaseControl.cs
r17417 r17431 21 21 VM = vm; 22 22 23 checkBoxActive.DataBindings.Add("Checked", VM, nameof(JsonItemVMBase.Selected)); 23 checkBoxActive.DataBindings.Add("Checked", VM, nameof(JsonItemVMBase.Selected), 24 false, DataSourceUpdateMode.OnPropertyChanged); 24 25 textBoxName.DataBindings.Add("Text", VM, nameof(JsonItemVMBase.Name)); 25 26 textBoxActualName.DataBindings.Add("Text", VM, nameof(JsonItemVMBase.ActualName)); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ArrayValueVM.cs
r17420 r17431 16 16 17 17 public override JsonItemBaseControl GetControl() => new JsonItemDoubleArrayValueControl(this); 18 19 p rotected override void OnItemChanged(){20 IList<IndexedArrayValueVM> list = new List<IndexedArrayValueVM>();21 var arr = ((DoubleArrayJsonItem)Item).Value;22 for(int i = 0; i < arr.Length; ++i) {23 list.Add(new IndexedArrayValueVM(arr, i));18 19 public override double[] Value { 20 get => ((DoubleArrayJsonItem)Item).Value; 21 set { 22 ((DoubleArrayJsonItem)Item).Value = value; 23 OnPropertyChange(this, nameof(Value)); 24 24 } 25 Value = list.ToArray();26 25 } 27 26 } … … 35 34 36 35 public override JsonItemBaseControl GetControl() => new JsonItemIntArrayValueControl(this); 37 38 p rotected override void OnItemChanged(){39 IList<IndexedArrayValueVM> list = new List<IndexedArrayValueVM>();40 var arr = ((IntArrayJsonItem)Item).Value;41 for (int i = 0; i < arr.Length; ++i) {42 list.Add(new IndexedArrayValueVM(arr, i));36 37 public override int[] Value { 38 get => ((IntArrayJsonItem)Item).Value; 39 set { 40 ((IntArrayJsonItem)Item).Value = value; 41 OnPropertyChange(this, nameof(Value)); 43 42 } 44 Value = list.ToArray();45 43 } 46 44 } 47 45 48 46 public abstract class ArrayValueVM<T> : RangedValueBaseVM<T> { 49 50 public class IndexedArrayValueVM : INotifyPropertyChanged { 51 private T[] arr; 52 private int index; 53 54 public IndexedArrayValueVM(T[] arr, int index) { 55 this.arr = arr; 56 this.index = index; 57 } 58 59 public T Value { 60 get => arr[index]; 61 set { 62 arr[index] = value; 63 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value))); 64 } 65 } 66 67 public event PropertyChangedEventHandler PropertyChanged; 47 48 public ArrayValueVM() { 49 //base.ItemChanged += OnItemChanged; 68 50 } 69 51 70 public ArrayValueVM() { 71 base.ItemChanged += OnItemChanged; 52 public void SetIndexValue(object obj, int index) { 53 T[] tmp = Value; 54 if(index >= tmp.Length) { // increasing array 55 T[] newArr = new T[index+1]; 56 Array.Copy(tmp, 0, newArr, 0, tmp.Length); 57 tmp = newArr; 58 } 59 tmp[index] = (T)Convert.ChangeType(obj, typeof(T)); 60 Value = tmp; 72 61 } 73 62 74 protected abstract void OnItemChanged(); 75 76 IndexedArrayValueVM[] vms; 77 public IndexedArrayValueVM[] Value { 78 get => vms; 79 set { 80 vms = value; 81 OnPropertyChange(this, nameof(Value)); 82 } 83 } 63 public abstract T[] Value { get; set; } 84 64 } 85 65 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVMBase.cs
r17420 r17431 2 2 using System.Collections.Generic; 3 3 using System.ComponentModel; 4 using System.Drawing; 4 5 using System.Linq; 5 6 using System.Text; 6 7 using System.Threading.Tasks; 8 using System.Windows.Forms; 7 9 8 10 namespace HeuristicLab.JsonInterface.OptimizerIntegration { … … 19 21 } 20 22 } 23 24 public TreeNode TreeNode { get; set; } 25 public TreeView TreeView { get; set; } 21 26 22 27 protected void OnPropertyChange(object sender, string propertyName) { … … 37 42 set { 38 43 selected = value; 44 if(TreeNode != null) 45 TreeNode.ForeColor = (selected ? Color.Black : Color.Red); 46 if (TreeView != null) 47 TreeView.Refresh(); 39 48 OnPropertyChange(this, nameof(Selected)); 40 49 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs
r17417 r17431 85 85 VMs.Add(vm); 86 86 vm.Item = item; 87 vm.TreeNode = node; 88 vm.TreeView = treeView; 87 89 UserControl control = vm.GetControl(); 88 90 if (control != null) { -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemMultiValueControl.Designer.cs
r17430 r17431 1 1 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 2 partial class JsonItem ArrayValueControl{2 partial class JsonItemMultiValueControl<T> { 3 3 /// <summary> 4 4 /// Required designer variable. -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemMultiValueControl.cs
r17430 r17431 10 10 11 11 namespace HeuristicLab.JsonInterface.OptimizerIntegration { 12 13 public class JsonItemIntArrayValueControl : JsonItemArrayValueControl { 14 public JsonItemIntArrayValueControl(IntArrayValueVM vm) : base(vm, vm.Value) { } 12 13 public class JsonItemDoubleMatrixValueControl : JsonItemMultiValueControl<double> { 14 15 public JsonItemDoubleMatrixValueControl(DoubleMatrixValueVM vm) : base(vm, vm.Value) { } 16 protected override void SaveCellData(object data, int col, int row) { 17 DoubleMatrixValueVM vm = VM as DoubleMatrixValueVM; 18 vm.SetCellValue(data, col, row); 19 } 15 20 } 16 21 17 public class JsonItemDoubleArrayValueControl : JsonItemArrayValueControl { 22 public class JsonItemIntArrayValueControl : JsonItemMultiValueControl<int> { 23 public JsonItemIntArrayValueControl(IntArrayValueVM vm) : base(vm, vm.Value) { } 24 25 protected override void SaveCellData(object data, int col, int row) { 26 IntArrayValueVM vm = VM as IntArrayValueVM; 27 vm.SetIndexValue(data, row); 28 } 29 } 30 31 public class JsonItemDoubleArrayValueControl : JsonItemMultiValueControl<double> { 18 32 public JsonItemDoubleArrayValueControl(DoubleArrayValueVM vm) : base(vm, vm.Value) { } 33 34 protected override void SaveCellData(object data, int col, int row) { 35 DoubleArrayValueVM vm = VM as DoubleArrayValueVM; 36 vm.SetIndexValue(data, row); 37 } 19 38 } 20 39 21 public abstract partial class JsonItem ArrayValueControl: JsonItemBaseControl {40 public abstract partial class JsonItemMultiValueControl<T> : JsonItemBaseControl { 22 41 protected NumericRangeControl NumericRangeControl { get; set; } 23 42 24 public JsonItem ArrayValueControl(JsonItemVMBase vm, object dataSource) : base(vm) {43 public JsonItemMultiValueControl(JsonItemVMBase vm, T[][] matrix) : base(vm) { 25 44 InitializeComponent(); 26 dataGridView.DataSource = dataSource; 45 int rows = matrix.Length; 46 int cols = matrix.Max(x => x.Length); 47 48 // columns must added first 49 for (int c = 0; c < cols; ++c) { 50 dataGridView.Columns.Add($"Column {c}", $"Column {c}"); 51 } 52 53 dataGridView.Rows.Add(rows); 54 for (int c = 0; c < cols; ++c) { 55 for(int r = 0; r < rows; ++r) { 56 dataGridView[c, r].Value = matrix[r][c]; 57 } 58 } 59 60 dataGridView.CellEndEdit += DataGridView_CellEndEdit; 61 InitRangeBinding(); 62 } 63 64 public JsonItemMultiValueControl(JsonItemVMBase vm, T[] array) : base(vm) { 65 InitializeComponent(); 66 int length = array.Length; 67 68 dataGridView.Columns.Add("Value", "Value"); 69 dataGridView.Rows.Add(length); 70 for(int i = 0; i < length; ++i) { 71 dataGridView[0, i].Value = array[i]; 72 } 73 dataGridView.CellEndEdit += DataGridView_CellEndEdit; 74 InitRangeBinding(); 75 } 76 77 private void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { 78 SaveCellData(dataGridView[e.ColumnIndex, e.RowIndex].Value, e.ColumnIndex, e.RowIndex); 79 } 80 81 protected abstract void SaveCellData(object data, int col, int row); 82 83 /* 84 public JsonItemMultiValueControl(JsonItemVMBase vm, object dataSource) : base(vm) { 85 InitializeComponent(); 86 dataGridView.DataSource = dataSource; 87 88 InitRangeBinding(); 89 } 90 */ 91 private void InitRangeBinding() { 27 92 NumericRangeControl = numericRangeControl1; 28 29 93 NumericRangeControl.TBMinRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM.MinRange)); 30 94 NumericRangeControl.TBMaxRange.DataBindings.Add("Text", VM, nameof(RangedValueBaseVM.MaxRange)); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/GenericJsonItem.cs
r17417 r17431 13 13 public class JsonItem<V,R> : JsonItem { 14 14 public new V Value { 15 get { 16 if(base.Value is IConvertible) 17 return (V)Convert.ChangeType(base.Value, typeof(V)); 18 19 if(base.Value is JToken token) 20 return token.ToObject<V>(); 21 22 return (V)base.Value; 23 } 15 get => ConvertObject(base.Value); 24 16 set => base.Value = value; 25 17 } 26 18 27 19 public new IEnumerable<R> Range { 28 20 get => base.Range?.Cast<R>(); 29 21 set => base.Range = value.Cast<object>(); 30 22 } 23 24 private V ConvertObject(object obj) { 25 if (obj is IConvertible) 26 return (V)Convert.ChangeType(obj, typeof(V)); 27 28 if (obj is JToken token) 29 return token.ToObject<V>(); 30 31 return (V)obj; 32 } 31 33 } 32 34 }
Note: See TracChangeset
for help on using the changeset viewer.