Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17484


Ignore:
Timestamp:
03/23/20 15:16:55 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • fixed a bug with JsonItemMultiValueControl -> the size of the matrix should now be saved correctly
  • fixed a bug with RegressionProblemDataConverter -> should now set the row/col sizes correctly
  • simplified the code for saving matrix data in JsonItemMultiValueControl, MatrixValueVM and ArrayValueVM
  • removed unnecessary casts
Location:
branches/3026_IntegrationIntoSymSpace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/ArrayValueVM.cs

    r17473 r17484  
    2020   
    2121    public override double[] Value {
    22       get => ((DoubleArrayJsonItem)Item).Value;
     22      get => Item.Value;
    2323      set {
    24         ((DoubleArrayJsonItem)Item).Value = value;
     24        Item.Value = value;
    2525        OnPropertyChange(this, nameof(Value));
    2626      }
     
    3939   
    4040    public override int[] Value {
    41       get => ((IntArrayJsonItem)Item).Value;
     41      get => Item.Value;
    4242      set {
    43         ((IntArrayJsonItem)Item).Value = value;
     43        Item.Value = value;
    4444        OnPropertyChange(this, nameof(Value));
    4545      }
     
    5252   
    5353    public ArrayValueVM() { }
    54 
    55     public void SetIndexValue(T data, int index) {
    56       T[] tmp = Value;
    57       if(index >= tmp.Length) { // increasing array
    58         T[] newArr = new T[index+1];
    59         Array.Copy(tmp, 0, newArr, 0, tmp.Length);
    60         tmp = newArr;
    61       }
    62       tmp[index] = data;
    63       Value = tmp;
    64     }
    65 
     54   
    6655    public abstract T[] Value { get; set; }
    6756    public bool Resizable {
    68       get => ((IArrayJsonItem)Item).Resizable;
     57      get => Item.Resizable;
    6958      set {
    70         ((IArrayJsonItem)Item).Resizable = value;
     59        Item.Resizable = value;
    7160        OnPropertyChange(this, nameof(IArrayJsonItemVM.Resizable));
    7261      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/MatrixValueVM.cs

    r17473 r17484  
    1515
    1616    public override double[][] Value {
    17       get => ((DoubleMatrixJsonItem)Item).Value;
     17      get => Item.Value;
    1818      set {
    19         ((DoubleMatrixJsonItem)Item).Value = value;
     19        Item.Value = value;
    2020        OnPropertyChange(this, nameof(Value));
    2121      }
     
    3232    public abstract T[][] Value { get; set; }
    3333    public bool RowsResizable {
    34       get => ((IMatrixJsonItem)Item).RowsResizable;
     34      get => Item.RowsResizable;
    3535      set {
    36         ((IMatrixJsonItem)Item).RowsResizable = value;
     36        Item.RowsResizable = value;
    3737        OnPropertyChange(this, nameof(RowsResizable));
    3838      }
     
    4040
    4141    public bool ColumnsResizable {
    42       get => ((IMatrixJsonItem)Item).ColumnsResizable;
     42      get => Item.ColumnsResizable;
    4343      set {
    44         ((IMatrixJsonItem)Item).ColumnsResizable = value;
     44        Item.ColumnsResizable = value;
    4545        OnPropertyChange(this, nameof(ColumnsResizable));
    4646      }
     
    4848
    4949    public IEnumerable<string> RowNames {
    50       get => ((JsonItemType)Item).RowNames;
     50      get => Item.RowNames;
    5151      set {
    52         ((JsonItemType)Item).RowNames = value;
     52        Item.RowNames = value;
    5353        OnPropertyChange(this, nameof(RowNames));
    5454      }
    5555    }
    5656    public IEnumerable<string> ColumnNames {
    57       get => ((JsonItemType)Item).ColumnNames;
     57      get => Item.ColumnNames;
    5858      set {
    59         ((JsonItemType)Item).ColumnNames = value;
     59        Item.ColumnNames = value;
    6060        OnPropertyChange(this, nameof(ColumnNames));
    6161      }
    6262    }
    63 
    64     public void SetCellValue(T data, int row, int col) {
    65      
    66       T[][] tmp = Value;
    67      
    68       // increase y
    69       if (row >= tmp.Length) { // increasing array
    70         T[][] newArr = new T[row + 1][];
    71         Array.Copy(tmp, 0, newArr, 0, tmp.Length);
    72         newArr[row] = new T[0];
    73         tmp = newArr;
    74       }
    75 
    76       // increase x
    77       for(int i = 0; i < tmp.Length; ++i) {
    78         if(col >= tmp[i].Length) {
    79           T[] newArr = new T[col + 1];
    80           Array.Copy(tmp[i], 0, newArr, 0, tmp[i].Length);
    81           tmp[i] = newArr;
    82         }
    83       }
    84 
    85       tmp[row][col] = data;
    86       Value = tmp;
    87     }
    8863  }
    8964}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r17481 r17484  
    4646        treeView.Nodes.Add(parent);
    4747        treeView.ExpandAll();
    48        
     48        panelParameterDetails.Controls.Clear();
     49        panelResultDetails.Controls.Clear();
     50
    4951      }
    5052    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemMultiValueControl.cs

    r17473 r17484  
    1414    public JsonItemDoubleMatrixValueControl(DoubleMatrixValueVM vm) : base(vm, vm.Value) { }
    1515   
    16     protected override void SaveCellData(double data, int row, int col) {
     16    protected override void Save() {
    1717      DoubleMatrixValueVM vm = VM as DoubleMatrixValueVM;
    18       vm.SetCellValue(data, row, col);
     18      vm.Value = Matrix;
    1919    }
    2020   
     
    2424    public JsonItemIntArrayValueControl(IntArrayValueVM vm) : base(vm, vm.Value) { }
    2525   
    26     protected override void SaveCellData(int data, int row, int col) {
     26    protected override void Save() {
    2727      IntArrayValueVM vm = VM as IntArrayValueVM;
    28       vm.SetIndexValue(data, row);
     28      vm.Value = Matrix[0];
    2929    }
    3030   
     
    3434    public JsonItemDoubleArrayValueControl(DoubleArrayValueVM vm) : base(vm, vm.Value) { }
    3535   
    36     protected override void SaveCellData(double data, int row, int col) {
     36    protected override void Save() {
    3737      DoubleArrayValueVM vm = VM as DoubleArrayValueVM;
    38       vm.SetIndexValue(data, row);
     38      vm.Value = Matrix[0];
    3939    }
    4040   
     
    4747    private int Columns { get; set; }
    4848
    49     private T[][] Matrix { get; set; }
     49    protected T[][] Matrix { get; set; }
    5050   
    5151    protected IEnumerable<string> RowNames {
     
    108108    }
    109109   
    110     protected abstract void SaveCellData(T data, int row, int col);
    111 
    112     private void InitSizeConfiguration(int? rows, int? columns) {
    113       if(rows != null) {
    114         checkBoxRows.CheckedChanged += CheckBoxRows_CheckedChanged;
    115         textBoxRows.Text = rows.ToString();
    116       } else {
    117         checkBoxRows.Enabled = false;
    118         textBoxRows.ReadOnly = true;
    119       }
    120 
    121       if (columns != null) {
    122         checkBoxColumns.CheckedChanged += CheckBoxColumns_CheckedChanged;
    123         textBoxColumns.Text = columns.ToString();
    124       } else {
    125         checkBoxColumns.Enabled = false;
    126         textBoxColumns.ReadOnly = true;
    127       }
    128     }
     110    protected abstract void Save();
    129111
    130112    private void RefreshMatrix() {
     
    135117      Matrix = new T[Columns][];
    136118     
     119      // add columns
    137120      for (int c = 0; c < Columns; ++c) {
    138121        string name = $"Column {c}";
     
    142125      }
    143126
     127      // copy data from old matrix into new
    144128      for (int c = 0; c < Columns; ++c) {
    145129        T[] newCol = new T[Rows];
     
    149133      }
    150134
     135      // add rows
    151136      if(Rows > 0 && Columns > 0) {
    152137        dataGridView.Rows.Add(Rows);
     
    165150    }
    166151
     152    #region Init
     153    private void InitSizeConfiguration(int? rows, int? columns) {
     154      if (rows != null) {
     155        checkBoxRows.CheckedChanged += CheckBoxRows_CheckedChanged;
     156        textBoxRows.Text = rows.ToString();
     157      } else {
     158        checkBoxRows.Enabled = false;
     159        textBoxRows.ReadOnly = true;
     160      }
     161
     162      if (columns != null) {
     163        checkBoxColumns.CheckedChanged += CheckBoxColumns_CheckedChanged;
     164        textBoxColumns.Text = columns.ToString();
     165      } else {
     166        checkBoxColumns.Enabled = false;
     167        textBoxColumns.ReadOnly = true;
     168      }
     169    }
     170
    167171    private void InitRangeBinding() {
    168172      NumericRangeControl = numericRangeControl1;
     
    174178        false, DataSourceUpdateMode.OnPropertyChanged);
    175179    }
    176 
     180    #endregion
     181
     182    #region Validation
    177183    private void textBoxRows_Validating(object sender, CancelEventArgs e) {
    178184      if (string.IsNullOrWhiteSpace(textBoxRows.Text)) {
     
    204210      }
    205211    }
    206    
     212    #endregion
     213
     214    #region Events
    207215    private void textBoxRows_TextChanged(object sender, EventArgs e) {
    208216      if(!textBoxRows.ReadOnly && int.TryParse(textBoxRows.Text, out int r) && Rows != r) {
    209217        Rows = r;
    210218        RefreshMatrix();
     219        Save();
    211220      }
    212221    }
     
    216225        Columns = c;
    217226        RefreshMatrix();
     227        Save();
    218228      }
    219229    }
     
    232242                                            typeof(T),
    233243                                            System.Globalization.CultureInfo.InvariantCulture);
    234       SaveCellData(Matrix[e.ColumnIndex][e.RowIndex], e.ColumnIndex, e.RowIndex);
    235     }
     244      //Save(Matrix[e.ColumnIndex][e.RowIndex], e.ColumnIndex, e.RowIndex);
     245      Save();
     246    }
     247    #endregion
    236248  }
    237249}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs

    r17473 r17484  
    4444    }
    4545
    46 
    4746    #region Helper
    4847    private bool GetOperatorState(string name, IJsonItem data) {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/RegressionProblemDataConverter.cs

    r17473 r17484  
    2929      dynamic val = (dynamic)item;
    3030      object dataset = (object)val.Dataset;
     31      var rows = dataset.GetType().GetField("rows", flags);
     32      rows.SetValue(dataset, matrix.Value[0].Length);
     33
     34      var variableNames = dataset.GetType().GetField("variableNames", flags);
     35      variableNames.SetValue(dataset, matrix.RowNames);
     36
    3137      var dataInfo = dataset.GetType().GetField("variableValues", flags);
    3238      dataInfo.SetValue(dataset, dictTmp);
Note: See TracChangeset for help on using the changeset viewer.