Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17410 for branches


Ignore:
Timestamp:
01/28/20 14:53:45 (4 years ago)
Author:
dpiringe
Message:

#3026:

  • deleted JsonItemArrayControl and JsonItemDefaultControl
  • redesigned architecture for JsonItem: now there are different types of JsonItem (IntJsonItem, BoolJsonItem, ...) -> for better type safety and expandability
  • fixed bug in BaseConverter for GetMinValue and GetMaxValue for IntValue, but ignored for other value types (DoubleValue, DateTimeValue, ...) because the redesign of JsonItem-Architecture can make these two methods obsolet soon
  • fixed bug in JsonItemConverter to prevent null pointer exceptions
  • refactored value and range converters -> removed complicated generic ValueTypeValueConverter and ValueRangeConverter and implemented the necessary methods directly in concrete classes (improves readability and removes the need of reflection)
  • redesigned view handling in OptimizerIntegration -> dynamically seaches for JsonItemVMBase implementations, which are connected with a view
    • this enables better scaling with more user controls
  • JsonItemVMBase implements MVVM architecture
Location:
branches/3026_IntegrationIntoSymSpace
Files:
7 added
5 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/HeuristicLab.JsonInterface.OptimizerIntegration.csproj

    r17405 r17410  
    7878  </ItemGroup>
    7979  <ItemGroup>
     80    <Compile Include="Interfaces\IJsonItemValueParser.cs" />
     81    <Compile Include="Parser\JsonItemDoubleValueParser.cs" />
     82    <Compile Include="Parser\JsonItemIntValueParser.cs" />
    8083    <Compile Include="Properties\Resources.Designer.cs">
    8184      <AutoGen>True</AutoGen>
     
    9598      <DependentUpon>NumericRangeControl.cs</DependentUpon>
    9699    </Compile>
     100    <Compile Include="ViewModels\JsonItemVMBase.cs" />
     101    <Compile Include="ViewModels\RangeVM.cs" />
     102    <Compile Include="ViewModels\SingleValueVM.cs" />
     103    <Compile Include="ViewModels\StringValueVM.cs" />
    97104    <Compile Include="Views\ExportJsonDialog.cs">
    98105      <SubType>Form</SubType>
     
    102109    </Compile>
    103110    <Compile Include="FileManager.cs" />
    104     <Compile Include="Views\JsonItemArrayControl.cs">
    105       <SubType>UserControl</SubType>
    106     </Compile>
    107     <Compile Include="Views\JsonItemArrayControl.Designer.cs">
    108       <DependentUpon>JsonItemArrayControl.cs</DependentUpon>
    109     </Compile>
    110111    <Compile Include="Views\JsonItemBoolControl.cs">
    111112      <SubType>UserControl</SubType>
     
    113114    <Compile Include="Views\JsonItemBoolControl.Designer.cs">
    114115      <DependentUpon>JsonItemBoolControl.cs</DependentUpon>
    115     </Compile>
    116     <Compile Include="Views\JsonItemDefaultControl.cs">
    117       <SubType>UserControl</SubType>
    118     </Compile>
    119     <Compile Include="Views\JsonItemDefaultControl.Designer.cs">
    120       <DependentUpon>JsonItemDefaultControl.cs</DependentUpon>
    121116    </Compile>
    122117    <Compile Include="Views\JsonItemRangeControl.cs">
     
    199194    <EmbeddedResource Include="Views\ExportJsonDialog.resx">
    200195      <DependentUpon>ExportJsonDialog.cs</DependentUpon>
    201     </EmbeddedResource>
    202     <EmbeddedResource Include="Views\JsonItemArrayControl.resx">
    203       <DependentUpon>JsonItemArrayControl.cs</DependentUpon>
    204196    </EmbeddedResource>
    205197    <EmbeddedResource Include="Views\JsonItemBoolControl.resx">
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/JsonItemBaseControl.Designer.cs

    r17405 r17410  
    5151      this.checkBoxActive.TabIndex = 2;
    5252      this.checkBoxActive.UseVisualStyleBackColor = true;
    53       this.checkBoxActive.CheckedChanged += new System.EventHandler(this.checkBoxActive_CheckedChanged);
    5453      //
    5554      // textBoxActualName
     
    6160      this.textBoxActualName.Size = new System.Drawing.Size(404, 20);
    6261      this.textBoxActualName.TabIndex = 12;
    63       this.textBoxActualName.TextChanged += new System.EventHandler(this.textBoxActualName_TextChanged);
    6462      //
    6563      // labelActualName
     
    8280      this.textBoxName.Size = new System.Drawing.Size(404, 20);
    8381      this.textBoxName.TabIndex = 10;
    84       this.textBoxName.TextChanged += new System.EventHandler(this.textBoxName_TextChanged);
    8582      //
    8683      // label1
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/JsonItemBaseControl.cs

    r17405 r17410  
    1111namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1212  public partial class JsonItemBaseControl : UserControl {
    13     public JsonItemVM VM { get; set; }
     13    private JsonItemVMBase VM { get; set; }
    1414
    1515    private JsonItemBaseControl() {
     
    1717    }
    1818
    19     public JsonItemBaseControl(JsonItemVM vm) {
     19    public JsonItemBaseControl(JsonItemVMBase vm) {
    2020      InitializeComponent();
    2121      VM = vm;
    22       checkBoxActive.Checked = VM.Selected;
    23       textBoxName.Text = VM.Item.Name;
     22
     23      checkBoxActive.DataBindings.Add("Checked", VM, nameof(JsonItemVMBase.Selected));
     24      textBoxName.DataBindings.Add("Text", VM, nameof(JsonItemVMBase.Name));
     25      textBoxActualName.DataBindings.Add("Text", VM, nameof(JsonItemVMBase.ActualName));
     26
     27      //checkBoxActive.Checked = VM.Selected;
     28      //textBoxName.Text = VM.Item.Name;
    2429      if (string.IsNullOrWhiteSpace(VM.Item.ActualName))
    2530        textBoxActualName.ReadOnly = true;
     
    2732        textBoxActualName.Text = VM.Item.ActualName;
    2833    }
    29 
    30     private void checkBoxActive_CheckedChanged(object sender, EventArgs e) {
    31       VM.Selected = checkBoxActive.Checked;
    32     }
    33 
    34     private void textBoxName_TextChanged(object sender, EventArgs e) {
    35       VM.Item.Name = textBoxName.Text;
    36     }
    37 
    38     private void textBoxActualName_TextChanged(object sender, EventArgs e) {
    39       VM.Item.ActualName = textBoxActualName.Text;
    40     }
    4134  }
    4235}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.Designer.cs

    r17405 r17410  
    1 namespace HeuristicLab.JsonInterface.OptimizerIntegration.Shared {
     1namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    22  partial class NumericRangeControl {
    33    /// <summary>
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Shared/NumericRangeControl.cs

    r17405 r17410  
    1010using System.Globalization;
    1111
    12 namespace HeuristicLab.JsonInterface.OptimizerIntegration.Shared {
     12namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1313  public partial class NumericRangeControl : UserControl {
    1414
     
    2222    }
    2323    public bool IsDouble { get; set; }
    24 
    25 
    2624
    2725    public NumericRangeControl() {
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/ViewModels/JsonItemVM.cs

    r17406 r17410  
    22using System.Collections;
    33using System.Collections.Generic;
     4using System.ComponentModel;
    45using System.Linq;
    56using System.Text;
    67using System.Threading.Tasks;
     8using System.Windows.Forms;
    79
    810namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    9   public delegate void OnSelectionChangeHandler(JsonItemVM sender, bool selection);
    10   public delegate void OnChildAddedHandler(JsonItemVM sender, JsonItemVM child);
    1111
    12   public class JsonItemVM {
    13     public IJsonItem Item { get; set; }
     12  //TODO: controls/views only initcomponents and delegate events to this, this has parsers and other actions?
     13  // maybe different VMs?
     14  public class JsonItemVM : JsonItemVMBase {
    1415
    15     private IList<JsonItemVM> children = new List<JsonItemVM>();
    16     public IEnumerable<JsonItemVM> Children {
    17       get => children;
    18     }
     16    public override Type JsonItemType => typeof(JsonItem);
    1917
    20     public JsonItemVM Parent { get; set; }
     18    //protected IJsonItemValueParser Parser { get; set; }
     19    //child tree
     20    //private IList<JsonItemVM> nodes = new List<JsonItemVM>();
     21
     22    //public IEnumerable<JsonItemVM> Nodes { get => nodes; }
     23    //public JsonItemVM Parent { get; private set; }
     24
    2125
    2226    private bool selected = true;
    2327    public bool Selected {
    24       get => selected; 
     28      get => selected;
    2529      set {
    2630        selected = value;
    27         OnSelectionChange?.Invoke(this, Selected);
    28       } 
     31        OnPropertyChange(this, nameof(Selected));
     32      }
    2933    }
    3034
    31     public event OnSelectionChangeHandler OnSelectionChange;
    32     public event OnChildAddedHandler OnChildAdded;
    33 
    34     public JsonItemVM(IJsonItem item) {
    35       this.Item = item;
     35    public string Name {
     36      get => Item.Name;
     37      set {
     38        Item.Name = value;
     39        OnPropertyChange(this, nameof(Name));
     40      }
    3641    }
    3742
    38     public void AddChild(JsonItemVM vm) {
    39       children.Add(vm);
    40       vm.Parent = this;
    41       OnChildAdded?.Invoke(this, vm);
     43    public string ActualName {
     44      get => Item.ActualName;
     45      set {
     46        Item.ActualName = value;
     47        OnPropertyChange(this, nameof(ActualName));
     48      }
    4249    }
     50    public override JsonItemBaseControl GetControl() {
     51      return new JsonItemBaseControl(this);
     52    }
     53
     54
     55    /*
     56    public abstract UserControl Control { get; }
     57
     58    public void OnSelectChange(object sender, EventArgs e) {
     59      CheckBox checkBox = sender as CheckBox;
     60      Selected = checkBox.Checked;
     61    }
     62
     63    public void OnNameChange(object sender, EventArgs e) {
     64      TextBox textBox = sender as TextBox;
     65      Item.Name = textBox.Text;
     66    }
     67
     68    public void OnActualNameChange(object sender, EventArgs e) {
     69      TextBox textBox = sender as TextBox;
     70      Item.ActualName = textBox.Text;
     71    }
     72
     73    public abstract void OnValueChange(object sender, EventArgs e);
     74
     75    public abstract void OnRangeChange(object sender, EventArgs e);
     76    */
    4377  }
    4478}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/ExportJsonDialog.cs

    r17406 r17410  
    1212using HeuristicLab.Common;
    1313using HeuristicLab.Optimization;
     14using HeuristicLab.PluginInfrastructure;
    1415
    1516namespace HeuristicLab.JsonInterface.OptimizerIntegration {
     
    3031        vms = new List<JsonItemVM>();
    3132        treeView.Nodes.Clear();
    32 
     33       
    3334        optimizer = content as IOptimizer;
    3435        root = JsonItemConverter.Extract(optimizer);
    3536        TreeNode parent = new TreeNode(root.Name);
     37     
    3638        BuildTreeNode(parent, root);
    3739        treeView.Nodes.Add(parent);
     
    3941    }
    4042
     43    private IDictionary<Type, JsonItemVMBase> VMs { get; set; }
     44
     45
     46    private void InitCache() {
     47      VMs = new Dictionary<Type, JsonItemVMBase>();
     48      foreach (var vm in ApplicationManager.Manager.GetInstances<JsonItemVMBase>()) {
     49        VMs.Add(vm.JsonItemType, vm);
     50      }
     51    }
     52
    4153    public ExportJsonDialog() {
    4254      InitializeComponent();
     55      InitCache();
    4356    }
    4457
     
    6780    }
    6881
    69     private JsonItemVM BuildTreeNode(TreeNode node, IJsonItem item) {
    70       JsonItemVM vm = new JsonItemVM(item);
     82    private void BuildTreeNode(TreeNode node, IJsonItem item) {
    7183
    72       vms.Add(vm);
    73       ctrlCollection.Add(node.GetHashCode(), GenerateControl(vm));
    74       if (item.Children != null) {
    75         foreach (var c in item.Children) {
    76           if (IsDrawableItem(c)) {
    77             if (c is ResultItem) {
     84      if (VMs.TryGetValue(item.GetType(), out JsonItemVMBase vm)) {
     85        //vm.Item = item;
     86        //UserControl control = vm.GetControl();
     87        //if (control != null) {
     88        //  control.Dock = DockStyle.Fill;
     89        //  control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
     90        //}
     91        //ctrlCollection.Add(node.GetHashCode(), control);
     92        if (item.Children != null) {
     93          foreach (var c in item.Children) {
     94            if (IsDrawableItem(c)) {
     95              if (c is ResultItem) {
    7896
    79             } else {
    80               TreeNode childNode = new TreeNode(c.Name);
    81               node.Nodes.Add(childNode);
    82               vm.AddChild(BuildTreeNode(childNode, c));
     97              } else {
     98                TreeNode childNode = new TreeNode(c.Name);
     99                node.Nodes.Add(childNode);
     100                BuildTreeNode(childNode, c);
     101                //vm.AddChild(BuildTreeNode(childNode, c));
     102              }
    83103            }
    84104          }
    85105        }
     106      } else {
     107        Console.WriteLine();
    86108      }
    87      
    88       return vm;
    89109    }
    90110
     
    109129      }
    110130    }
    111 
    112     private UserControl GenerateControl(JsonItemVM vm) {
    113       IJsonItem item = vm.Item;
    114       UserControl control = null;
    115       if (!(item is UnsupportedJsonItem)) {
    116         if (item.Value is string && item.Range != null) {
    117           control = new JsonItemValidValuesControl(vm);
    118         } else if (item.Value is bool && item.Range != null) {
    119           control = new JsonItemBoolControl(vm);
    120         } else if (item.Value is int && item.Range != null) {
    121           control = new JsonItemValueControl(vm, false);
    122         } else if (item.Value is double && item.Range != null) {
    123           control = new JsonItemValueControl(vm, true);
    124         } else if (item.Value is Array) {
    125           Array arr = (Array)item.Value;
    126           if (arr.Length == 2 && arr.GetValue(0) is int && item.Range != null)
    127             control = new JsonItemRangeControl(vm, false);
    128           else if (arr.Length == 2 && arr.GetValue(0) is double && item.Range != null)
    129             control = new JsonItemRangeControl(vm, true);
    130           else if (arr.Rank == 1 && arr.GetValue(0) is double) {
    131             control = new JsonItemArrayControl(vm);
    132           }
    133         } else {
    134           control = new JsonItemBaseControl(vm);
    135         }
    136         if (control != null) {
    137           control.Dock = DockStyle.Fill;
    138           control.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
    139         }
    140       }
    141       return control;
    142     }
    143131  }
    144132}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBoolControl.Designer.cs

    r17405 r17410  
    3838      this.checkBoxValue.TabIndex = 19;
    3939      this.checkBoxValue.UseVisualStyleBackColor = true;
    40       this.checkBoxValue.CheckStateChanged += new System.EventHandler(this.checkBoxValue_CheckStateChanged);
    4140      //
    4241      // label2
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemBoolControl.cs

    r17404 r17410  
    1111namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1212  public partial class JsonItemBoolControl : JsonItemBaseControl {
    13     public JsonItemBoolControl(JsonItemVM vm) : base(vm) {
     13
     14    public JsonItemBoolControl(BoolValueVM vm) : base(vm) {
    1415      InitializeComponent();
    15       checkBoxValue.Checked = (bool)vm.Item.Value;
     16      //checkBoxValue.Checked = (bool)vm.Item.Value;
    1617    }
    17 
     18    /*
    1819    private void checkBoxValue_CheckStateChanged(object sender, EventArgs e) {
    1920      VM.Item.Value = checkBoxValue.Checked;
    2021    }
     22    */
    2123  }
    2224}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemRangeControl.Designer.cs

    r17405 r17410  
    2929      this.label4 = new System.Windows.Forms.Label();
    3030      this.label2 = new System.Windows.Forms.Label();
    31       this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration.Shared.NumericRangeControl();
     31      this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration.NumericRangeControl();
    3232      this.groupBox1.SuspendLayout();
    3333      this.SuspendLayout();
     
    5656      this.textBoxValueTo.Size = new System.Drawing.Size(230, 20);
    5757      this.textBoxValueTo.TabIndex = 3;
    58       this.textBoxValueTo.Leave += new System.EventHandler(this.textBoxValueTo_Leave);
    5958      //
    6059      // textBoxValueFrom
     
    6463      this.textBoxValueFrom.Size = new System.Drawing.Size(230, 20);
    6564      this.textBoxValueFrom.TabIndex = 2;
    66       this.textBoxValueFrom.Leave += new System.EventHandler(this.textBoxValueFrom_Leave);
    6765      //
    6866      // label4
     
    9492      this.numericRangeControl1.Size = new System.Drawing.Size(487, 112);
    9593      this.numericRangeControl1.TabIndex = 18;
    96       this.numericRangeControl1.Load += new System.EventHandler(this.numericRangeControl1_Load);
    9794      //
    9895      // JsonItemRangeControl
     
    120117    private System.Windows.Forms.Label label4;
    121118    private System.Windows.Forms.Label label2;
    122     private Shared.NumericRangeControl numericRangeControl1;
     119    private NumericRangeControl numericRangeControl1;
    123120  }
    124121}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemRangeControl.cs

    r17405 r17410  
    1212namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1313  public partial class JsonItemRangeControl : JsonItemBaseControl {
    14     bool isDouble = false;
    15     object[] range = new object[2];
    16     object[] value = new object[2];
    1714
    18     public JsonItemRangeControl(JsonItemVM vm, bool isDouble) : base(vm) {
     15    public JsonItemRangeControl(DoubleRangeVM vm) : base(vm) {
    1916      InitializeComponent();
     17      /*
    2018      this.isDouble = isDouble;
    2119      textBoxValueFrom.Text = ((Array)VM.Item.Value).GetValue(0).ToString();
     
    2321      textBoxValueFrom.Text = VM.Item.Range.First().ToString();
    2422      textBoxValueTo.Text = VM.Item.Range.Last().ToString();
     23      */
    2524    }
    26 
    27     private object Parse(string s) {
    28       if (isDouble) {
    29         if (s == "-1,79769313486232E+308") return double.MinValue;
    30         if (s == "1,79769313486232E+308") return double.MaxValue;
    31         return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture);
    32       }
    33       return int.Parse(s);
    34     }
     25    /*
     26    protected abstract object Parse(string s);
    3527
    3628    private void SetValue() {
     
    5951      numericRangeControl1.VM = VM;
    6052    }
     53    */
    6154  }
    6255}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.Designer.cs

    r17405 r17410  
    9292      this.Name = "JsonItemValidValuesControl";
    9393      this.Size = new System.Drawing.Size(500, 290);
    94       this.Load += new System.EventHandler(this.JsonItemValidValuesControl_Load);
    9594      this.Controls.SetChildIndex(this.groupBoxRange, 0);
    9695      this.Controls.SetChildIndex(this.comboBoxValues, 0);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValidValuesControl.cs

    r17405 r17410  
    1111namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    1212  public partial class JsonItemValidValuesControl : JsonItemBaseControl {
    13    
    1413
    15     public JsonItemValidValuesControl(JsonItemVM vm) : base(vm) {
     14    public JsonItemValidValuesControl(StringValueVM vm) : base(vm) {
    1615      InitializeComponent();
     16      /*
    1717      foreach (var i in VM.Item.Range) {
    1818        AddOption((string)i);
     
    2020          comboBoxValues.SelectedItem = (string)i;
    2121        }
    22       }
    23 
     22      }*/
    2423    }
    25 
     24    /*
    2625    private void AddOption(string opt) {
    2726      AddComboOption(opt);
     
    7271
    7372    }
     73    */
    7474  }
    7575}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.Designer.cs

    r17405 r17410  
    2626      this.textBoxValue = new System.Windows.Forms.TextBox();
    2727      this.label2 = new System.Windows.Forms.Label();
    28       this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration.Shared.NumericRangeControl();
     28      this.numericRangeControl1 = new HeuristicLab.JsonInterface.OptimizerIntegration.NumericRangeControl();
    2929      this.SuspendLayout();
    3030      //
     
    3737      this.textBoxValue.Size = new System.Drawing.Size(404, 20);
    3838      this.textBoxValue.TabIndex = 14;
    39       this.textBoxValue.Leave += new System.EventHandler(this.textBoxValue_Leave);
    4039      //
    4140      // label2
     
    5655      this.numericRangeControl1.TabIndex = 16;
    5756      this.numericRangeControl1.VM = null;
    58       this.numericRangeControl1.Load += new System.EventHandler(this.numericRangeControl1_Load);
    5957      //
    6058      // JsonItemValueControl
     
    7977    private System.Windows.Forms.TextBox textBoxValue;
    8078    private System.Windows.Forms.Label label2;
    81     private Shared.NumericRangeControl numericRangeControl1;
     79    private NumericRangeControl numericRangeControl1;
    8280  }
    8381}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface.OptimizerIntegration/Views/JsonItemValueControl.cs

    r17405 r17410  
    1111
    1212namespace HeuristicLab.JsonInterface.OptimizerIntegration {
    13   public partial class JsonItemValueControl : JsonItemBaseControl {
    14     bool isDouble = false;
    15     object[] range = new object[2];
    1613
    17     public JsonItemValueControl(JsonItemVM vm, bool isDouble) : base(vm) {
    18       InitializeComponent();
    19       this.isDouble = isDouble;
    20       textBoxValue.Text = VM.Item.Value.ToString();
    21       range[0] = VM.Item.Range.First();
    22       range[1] = VM.Item.Range.Last();
     14  public class JsonItemIntValueControl : JsonItemValueControl {
     15
     16    public JsonItemIntValueControl(SingleValueVM<int> vm) : base(vm) { }
     17
     18  }
     19
     20  public class JsonItemDoubleValueControl : JsonItemValueControl {
     21    private SingleValueVM<double> VM { get; set; }
     22
     23    public JsonItemDoubleValueControl(SingleValueVM<double> vm) : base(vm) {
     24      VM = vm;
    2325    }
    2426
    25     private object Parse(string s) {
    26       if (isDouble) {
    27         return double.Parse(s.Replace(",", "."), NumberStyles.Any, CultureInfo.InvariantCulture);
    28       }
    29       return int.Parse(s);
     27  }
     28
     29  public abstract partial class JsonItemValueControl : JsonItemBaseControl {
     30
     31    public JsonItemValueControl(JsonItemVMBase vm) : base(vm) {
     32      InitializeComponent();
    3033    }
    3134
    32 
    33     private void textBoxValue_Leave(object sender, EventArgs e) {
    34       if (!string.IsNullOrWhiteSpace(textBoxValue.Text))
    35         VM.Item.Value = Parse(textBoxValue.Text);
    36     }
    37 
    38     private void numericRangeControl1_Load(object sender, EventArgs e) {
    39       numericRangeControl1.IsDouble = isDouble;
    40       numericRangeControl1.VM = VM;
    41     }
    4235  }
    4336}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/BaseConverter.cs

    r17407 r17410  
    3434      TypeCode typeCode = Type.GetTypeCode(t);
    3535
     36
    3637      if (t.IsEqualTo(typeof(PercentValue)))
    3738        return 1.0d;
     39
     40      if(t == typeof(IntValue)) {
     41        return int.MaxValue;
     42      }
    3843
    3944      switch (typeCode) {
     
    5964        return 0.0d;
    6065
     66      if (t == typeof(IntValue)) {
     67        return int.MinValue;
     68      }
     69
    6170      switch (typeCode) {
    6271        case TypeCode.Int16: return short.MinValue;
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ConstrainedValueParameterConverter.cs

    r17407 r17410  
    1313
    1414    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
     15      StringJsonItem cdata = data as StringJsonItem;
    1516      IParameter parameter = item as IParameter;
    1617      foreach (var x in GetValidValues(parameter))
    17         if(x.ToString() == CastValue<string>(data.Value))
     18        if(x.ToString() == CastValue<string>(cdata.Value))
    1819          parameter.ActualValue = x;
    1920
    20       if (parameter.ActualValue is IParameterizedItem && data.Children != null) {
    21         foreach(var param in data.Children) {
     21      if (parameter.ActualValue is IParameterizedItem && cdata.Children != null) {
     22        foreach(var param in cdata.Children) {
    2223          if(param.Name == parameter.ActualValue.ItemName)
    2324            root.Inject(parameter.ActualValue, param, root);
     
    2930      IParameter parameter = value as IParameter;
    3031
    31       IJsonItem item = new JsonItem() {
     32      IJsonItem item = new StringJsonItem() {
    3233        Name = parameter.Name,
    3334        Value = parameter.ActualValue?.ToString(),
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/EnumTypeConverter.cs

    r17407 r17410  
    1515      ((dynamic)item).Value = Enum.Parse(
    1616        item.GetType().GenericTypeArguments.First(),
    17         CastValue<string>(data.Value));
     17        ((StringJsonItem)data).Value);
    1818   
    1919    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
    2020      object val = ((dynamic)value).Value;
    2121      Type enumType = val.GetType();
    22       return new JsonItem() {
     22      return new StringJsonItem() {
    2323        Name = value.ItemName,
    2424        Value = Enum.GetName(enumType, val),
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/MultiCheckedOperatorConverter.cs

    r17407 r17410  
    2424      dynamic val = value as dynamic;
    2525      foreach (var op in val.Operators) {
    26         item.AddChilds(new JsonItem() {
     26        item.AddChilds(new BoolJsonItem() {
    2727          Name = op.Name,
    2828          Value = val.Operators.ItemChecked(op),
    29           Range = new object[] { false, true }
     29          Range = new bool[] { false, true }
    3030        });
    3131      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ParameterizedItemConverter.cs

    r17407 r17410  
    1616      if(data.Children != null) {
    1717        foreach (var sp in data.Children)
    18           if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param))
     18          if (pItem.Parameters.TryGetValue(sp.Name, out IParameter param) && param != null)
    1919            root.Inject(param, sp, root);
    2020      }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/StringValueConverter.cs

    r17407 r17410  
    1313
    1414    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
    15       ((StringValue)item).Value = CastValue<string>(data.Value);
     15      ((StringValue)item).Value = ((StringJsonItem)data).Value;
    1616
    1717    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
    18       new JsonItem() {
     18      new StringJsonItem() {
    1919        Name = value.ItemName,
    2020        Value = ((StringValue)value).Value
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueParameterConverter.cs

    r17407 r17410  
    3131          if (tmp.Name == "[OverridableParamName]") {
    3232            tmp.Name = parameter.Name;
    33             JsonItem.Merge(item as JsonItem, tmp as JsonItem);
     33            item = tmp;
     34            //JsonItem.Merge(item as JsonItem, tmp as JsonItem);
    3435          } else
    3536            item.AddChilds(tmp);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueRangeConverter.cs

    r17407 r17410  
    1111namespace HeuristicLab.JsonInterface {
    1212
    13   public class IntRangeConverter : ValueRangeConverter<IntRange, IntValue, int> {
     13  public class IntRangeConverter : BaseConverter {
    1414    public override int Priority => 1;
    1515    public override Type ConvertableType => typeof(IntRange);
    16   }
    17   public class DoubleRangeConverter : ValueRangeConverter<DoubleRange, DoubleValue, double> {
    18     public override int Priority => 1;
    19     public override Type ConvertableType => typeof(DoubleRange);
    20   }
    21 
    22   public abstract class ValueRangeConverter<RangeType, T, TType> : BaseConverter
    23     where RangeType : StringConvertibleValueTuple<T, T>
    24     where T : ValueTypeValue<TType>, IDeepCloneable, IStringConvertibleValue
    25     where TType : struct {
    26 
    27     private const BindingFlags Flags = BindingFlags.NonPublic | BindingFlags.Instance;
    2816
    2917    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
    30       object[] arr = (object[])data.Value;
    31       Tuple<T,T> tuple = new Tuple<T,T>(Instantiate<T>(arr[0]), Instantiate<T>(arr[1]));
    32       var field = item.GetType().GetField("values", Flags);
    33       field.SetValue(tuple, item);
     18      IntRange range = item as IntRange;
     19      IntArrayJsonItem cdata = data as IntArrayJsonItem;
     20      range.Start = cdata.Value[0];
     21      range.End = cdata.Value[1];
    3422    }
    3523
    3624    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
    37       var field = value.GetType().GetField("values", Flags);
    38       Tuple<T, T> tuple = (Tuple<T, T>)field.GetValue(value);
    39       return new JsonItem() {
     25      IntRange range = value as IntRange;
     26      return new IntArrayJsonItem() {
    4027        Name = "[OverridableParamName]",
    41         Value = new object[] { tuple.Item1.Value, tuple.Item2.Value },
    42         Range = new object[] { GetMinValue(typeof(TType)), GetMaxValue(typeof(TType)) }
     28        Value = new int[] { range.Start, range.End },
     29        Range = new int[] { int.MinValue, int.MaxValue }
    4330      };
    4431    }
    45      
     32  }
     33
     34  public class DoubleRangeConverter : BaseConverter {
     35    public override int Priority => 1;
     36    public override Type ConvertableType => typeof(DoubleRange);
     37
     38    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
     39      DoubleRange range = item as DoubleRange;
     40      DoubleArrayJsonItem cdata = data as DoubleArrayJsonItem;
     41      range.Start = cdata.Value[0];
     42      range.End = cdata.Value[1];
     43    }
     44
     45    public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
     46      DoubleRange range = value as DoubleRange;
     47      return new DoubleArrayJsonItem() {
     48        Name = "[OverridableParamName]",
     49        Value = new double[] { range.Start, range.End },
     50        Range = new double[] { double.MinValue, double.MaxValue }
     51      };
     52    }
    4653  }
    4754}
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Converters/ValueTypeValueConverter.cs

    r17407 r17410  
    99namespace HeuristicLab.JsonInterface {
    1010
    11   public class IntValueConverter : ValueTypeValueConverter<IntValue, int> {
     11  public class IntValueConverter : BaseConverter {
    1212    public override int Priority => 1;
    1313    public override Type ConvertableType => typeof(IntValue);
     14
     15    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
     16      ((IntValue)item).Value = ((IntJsonItem)data).Value;
     17
     18    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
     19      new IntJsonItem() {
     20        Name = "[OverridableParamName]",
     21        Value = ((IntValue)value).Value,
     22        Range = new int[] { int.MinValue, int.MaxValue }
     23      };
    1424  }
    1525
    16   public class DoubleValueConverter : ValueTypeValueConverter<DoubleValue, double> {
     26  public class DoubleValueConverter : BaseConverter {
    1727    public override int Priority => 1;
    1828    public override Type ConvertableType => typeof(DoubleValue);
     29
     30    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
     31      ((DoubleValue)item).Value = ((DoubleJsonItem)data).Value;
     32
     33    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
     34      new DoubleJsonItem() {
     35        Name = "[OverridableParamName]",
     36        Value = ((DoubleValue)value).Value,
     37        Range = new double[] { double.MinValue, double.MaxValue }
     38      };
    1939  }
    2040
    21   public class PercentValueConverter : ValueTypeValueConverter<PercentValue, double> {
     41  public class PercentValueConverter : BaseConverter {
    2242    public override int Priority => 2;
    2343    public override Type ConvertableType => typeof(PercentValue);
     44
     45    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
     46      ((PercentValue)item).Value = ((DoubleJsonItem)data).Value;
     47
     48    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
     49      new DoubleJsonItem() {
     50        Name = "[OverridableParamName]",
     51        Value = ((PercentValue)value).Value,
     52        Range = new double[] { double.MinValue, double.MaxValue }
     53      };
    2454  }
    2555
    26   public class BoolValueConverter : ValueTypeValueConverter<BoolValue, bool> {
     56  public class BoolValueConverter : BaseConverter {
    2757    public override int Priority => 1;
    2858    public override Type ConvertableType => typeof(BoolValue);
     59
     60    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
     61      ((BoolValue)item).Value = ((BoolJsonItem)data).Value;
     62
     63    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
     64      new BoolJsonItem() {
     65        Name = "[OverridableParamName]",
     66        Value = ((BoolValue)value).Value,
     67        Range = new bool[] { false, true }
     68      };
    2969  }
    3070
    31   public class DateTimeValueConverter : ValueTypeValueConverter<DateTimeValue, DateTime> {
     71  public class DateTimeValueConverter : BaseConverter {
    3272    public override int Priority => 1;
    3373    public override Type ConvertableType => typeof(DateTimeValue);
    34   }
    35 
    36   public abstract class ValueTypeValueConverter<ValueType, T> : BaseConverter
    37     where ValueType : ValueTypeValue<T>
    38     where T : struct {
    3974
    4075    public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
    41       ((ValueType)item).Value = CastValue<T>(data.Value);
     76      ((DateTimeValue)item).Value = ((DateTimeJsonItem)data).Value;
    4277
    4378    public override IJsonItem Extract(IItem value, IJsonItemConverter root) =>
    44       new JsonItem() {
     79      new DateTimeJsonItem() {
    4580        Name = "[OverridableParamName]",
    46         Value = ((ValueType)value).Value,
    47         Range = new object[] { GetMinValue(typeof(T)), GetMaxValue(typeof(T)) }
     81        Value = ((DateTimeValue)value).Value,
     82        Range = new DateTime[] { DateTime.MinValue, DateTime.MaxValue }
    4883      };
    4984  }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/HeuristicLab.JsonInterface.csproj

    r17408 r17410  
    6868    <Compile Include="Interfaces\IJsonItem.cs" />
    6969    <Compile Include="Interfaces\IJsonItemValidator.cs" />
     70    <Compile Include="Models\GenericJsonItem.cs" />
    7071    <Compile Include="Models\JsonItem.cs" />
     72    <Compile Include="Models\JsonItems.cs" />
    7173    <Compile Include="Models\ResultItem.cs" />
    7274    <Compile Include="Models\UnsupportedJsonItem.cs" />
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JCGenerator.cs

    r17406 r17410  
    1515  /// </summary>
    1616  public class JCGenerator {
    17     private JObject Template { get; set; }
     17    private JObject Template { get; set; } = JObject.Parse(Constants.Template);
    1818    private JArray JArrayItems { get; set; }
    1919    private IList<IJsonItem> JsonItems { get; set; }
     
    2424      // data container
    2525      JArrayItems = new JArray();
     26      JArray ResultItems = new JArray();
    2627      JsonItems = new List<IJsonItem>();
    2728
     
    3536      AddIItem(optimizer);
    3637      // save the JArray with JsonItems (= IParameterizedItems)
     38
     39      JArrayItems = new JArray();
     40      foreach (var item in JsonItems) {
     41        if (item is ResultItem)
     42          ResultItems.Add(Serialize(item));
     43        else
     44          JArrayItems.Add(Serialize(item));
     45      }
    3746      Template[Constants.Parameters] = JArrayItems;
     47      Template[Constants.ActivatedResults] = ResultItems;
    3848      // serialize template and return string
    3949      return SingleLineArrayJsonWriter.Serialize(Template);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItemConverter.cs

    r17406 r17410  
    5252   
    5353    public void Inject(IItem item, IJsonItem data, IJsonItemConverter root) {
    54       if(!Cache.ContainsKey(item.GetHashCode())) {
     54      if(item != null && !Cache.ContainsKey(item.GetHashCode())) {
    5555        IJsonItemConverter converter = GetConverter(item.GetType());
    5656        if(converter != null) converter.Inject(item, data, root);
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonTemplateInstantiator.cs

    r17406 r17410  
    2222      public JArray Config { get; set; }
    2323      public IDictionary<string, IJsonItem> Objects { get; set; }
     24      public IOptimizer Optimizer { get; set; }
    2425    }
    2526
     
    4748      ProtoBufSerializer serializer = new ProtoBufSerializer();
    4849      IOptimizer optimizer = (IOptimizer)serializer.Deserialize(hLFileLocation);
     50      instData.Optimizer = optimizer;
    4951
    5052      // collect all parameterizedItems from template
     
    6567
    6668    #region Helper
     69
     70    private static object GetValueFromJObject(JObject obj) {
     71      object val = obj[nameof(IJsonItem.Value)]?.ToObject<object>();
     72      if (val is JContainer jContainer) // for resolving array values
     73        val = jContainer.ToObject<object[]>();
     74
     75      return val;
     76    }
     77
    6778    private static void CollectParameterizedItems(InstData instData) {
     79      //JCGenerator generator = new JCGenerator();
     80      //IEnumerable<IJsonItem> items = generator.FetchJsonItems(instData.Optimizer);
     81      IJsonItem root = JsonItemConverter.Extract(instData.Optimizer);
     82      instData.Objects.Add(root.Path, root);
     83
     84      foreach (JObject obj in instData.Template[Constants.Parameters]) {
     85        string[] pathParts = obj.Property("Path").Value.ToString().Split('.');
     86        IJsonItem tmp = root;
     87        IJsonItem old = null;
     88        for(int i = 1; i < pathParts.Length; ++i) {
     89          foreach(var c in tmp.Children) {
     90            if (c.Name == pathParts[i])
     91              tmp = c;
     92          }
     93          if (old == tmp)
     94            throw new Exception($"Invalid path '{string.Join(".", pathParts)}'");
     95          else old = tmp;
     96        }
     97        tmp.Value = GetValueFromJObject(obj);
     98        tmp.Range = obj[nameof(IJsonItem.Range)]?.ToObject<object[]>();
     99        tmp.ActualName = obj[nameof(IJsonItem.ActualName)]?.ToString();
     100        instData.Objects.Add(tmp.Path, tmp);
     101      }
     102
     103
     104      /*
    68105      foreach (JObject item in instData.Template[Constants.Parameters]) {
    69106        string[] pathParts = item.Property("Path").Value.ToString().Split('.');
     
    89126        parent.AddChilds(data);
    90127        instData.Objects.Add(data.Path, data);
    91       }
     128      }*/
    92129    }
    93130   
     
    95132      foreach (JObject obj in instData.Config) {
    96133        // build item from config object
    97         IJsonItem item = JsonItem.BuildJsonItem(obj);
     134        //IJsonItem item = JsonItem.BuildJsonItem(obj);
     135        string path = obj.Property("Path").Value.ToString();
    98136        // override default value
    99         if (instData.Objects.TryGetValue(item.Path, out IJsonItem param)) {
    100           param.Value = item.Value;
     137        if (instData.Objects.TryGetValue(path, out IJsonItem param)) {
     138          param.Value = GetValueFromJObject(obj);
    101139          // override ActualName (for LookupParameters)
    102140          if (param.ActualName != null)
    103             param.ActualName = item.ActualName;
    104         } else throw new InvalidDataException($"No parameter with path='{item.Path}' defined!");
     141            param.ActualName = obj[nameof(IJsonItem.ActualName)]?.ToString();
     142        } else throw new InvalidDataException($"No parameter with path='{path}' defined!");
    105143      }
    106144    }
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/JsonItem.cs

    r17408 r17410  
    152152    }
    153153    #endregion
    154 
    155     #region BuildJsonItemMethods
    156     public static IJsonItem BuildJsonItem(JObject obj) {
    157       object val = obj[nameof(Value)]?.ToObject<object>();
    158       if (val is JContainer jContainer) // for resolving array values
    159         val = jContainer.ToObject<object[]>();
    160        
    161       return new JsonItem() {
    162         Name = obj[nameof(Name)]?.ToString(),
    163         Value = val,
    164         Range = obj[nameof(Range)]?.ToObject<object[]>(),
    165         ActualName = obj[nameof(ActualName)]?.ToString()
    166       };
    167     }
    168     #endregion
    169154  }
    170155}
  • branches/3026_IntegrationIntoSymSpace/Heuristiclab.ConfigStarter/Program.cs

    r17394 r17410  
    4545      alg.Problem = tsp;
    4646
    47       File.WriteAllText(@"C:\Workspace\Template.json", JCGenerator.GenerateTemplate(alg));
     47      JCGenerator generator = new JCGenerator();
     48
     49      //File.WriteAllText(@"C:\Workspace\Template.json", generator.GenerateTemplate(alg));
    4850      JsonTemplateInstantiator.Instantiate(@"C:\Workspace\Template.json");
    4951      /*
Note: See TracChangeset for help on using the changeset viewer.