Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/RangeVM.cs @ 17446

Last change on this file since 17446 was 17446, checked in by dpiringe, 4 years ago

#3026:

  • made interfaces for array/matrix JsonItems and for their VMs aswell (IArrayJsonItem, IArrayJsonItemVM, IMatrixJsonItem, IMatrixJsonItemVM), incl. base classes (ArrayJsonItemBase, ArrayValueVM, MatrixJsonItemBase, MatrixValueVM)
  • changed inheritance structure for already existing array/matrix JsonItems -> they inherit now from new base array/matrix base classes
  • added input elements to configure the size of an matrix or array in JsonItemMultiValueControl (incl. VM binding and validation)
  • splitted file JsonItems.cs into separate files for their corresponding types (IntJsonItems.cs, DoubleJsonItems.cs, BoolJsonItems.cs, StringJsonItem.cs, DateTimeJsonItem.cs)
  • changed location of deserialization of json values from JsonTemplateInstantiator into IJsonItem (implemented in JsonItem and set to virtual, overridden in MatrixJsonItemBase and ArrayJsonItemBase)
  • added new CLI argument StringArgument
  • some little UI improvements (location fixes, anchor fixes, ...)
File size: 1.5 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 IntRangeVM : RangeVM<int> {
11    public override Type JsonItemType => typeof(IntRangeJsonItem);
12
13    protected override int MinTypeValue => int.MinValue;
14
15    protected override int MaxTypeValue => int.MaxValue;
16
17    public override JsonItemBaseControl Control =>
18      new JsonItemRangeControl(this);
19  }
20
21  public class DoubleRangeVM : RangeVM<double> {
22    public override Type JsonItemType => typeof(DoubleRangeJsonItem);
23
24    protected override double MinTypeValue => double.MinValue;
25
26    protected override double MaxTypeValue => double.MaxValue;
27
28    public override JsonItemBaseControl Control =>
29      new JsonItemRangeControl(this);
30  }
31
32  public abstract class RangeVM<T> : RangedValueBaseVM<T> {
33
34    public T MinValue {
35      get => Cast(((Array)Item.Value).GetValue(0));
36      set {
37        SetValue(value, ((Array)Item.Value).GetValue(1));
38        OnPropertyChange(this, nameof(MinValue));
39      }
40    }
41
42    public T MaxValue {
43      get => Cast(((Array)Item.Value).GetValue(1));
44      set {
45        SetValue(((Array)Item.Value).GetValue(0), value);
46        OnPropertyChange(this, nameof(MaxValue));
47      }
48    }
49
50    private void SetValue(object min, object max) =>
51      Item.Value = new object[] { min, max };
52  }
53}
Note: See TracBrowser for help on using the repository browser.