Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/07/16 23:12:22 (9 years ago)
Author:
abeham
Message:

#2457:

  • Changed ICharacteristicCalculator interface
  • Updated OKB Problem view
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs

    r13552 r13593  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Windows.Forms;
    2622using HeuristicLab.Common.Resources;
    2723using HeuristicLab.Core.Views;
     
    3026using HeuristicLab.Optimization;
    3127using HeuristicLab.PluginInfrastructure;
     28using System;
     29using System.Collections.Generic;
     30using System.Linq;
     31using System.Windows.Forms;
    3232
    3333namespace HeuristicLab.Clients.OKB.RunCreation {
     
    9191      uploadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly
    9292        && characteristicsMatrixView.Content != null && characteristicsMatrixView.Content.Rows > 0;
    93       calculateButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly && calculatorListView.CheckedItems.Count > 0;
     93      calculateButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly;
    9494    }
    9595
     
    105105      if (Content == null || Content.ProblemId == -1) return;
    106106      var problem = Content.CloneProblem();
    107       var calculators = ApplicationManager.Manager.GetInstances<ICharacteristicCalculator>().Where(x => x.CanCalculate(problem)).ToList();
     107      var calculators = ApplicationManager.Manager.GetInstances<ICharacteristicCalculator>().ToList();
    108108      try {
    109109        calculatorListView.BeginUpdate();
    110110        foreach (var calc in calculators) {
     111          calc.Problem = problem;
    111112          var group = calculatorListView.Groups.Add(calc.Name, calc.Name);
    112113          group.Tag = calc;
    113           foreach (var c in calc.Characteristics) {
    114             var item = calculatorListView.Items.Add(c, c);
    115             item.Group = group;
    116             item.Checked = true;
    117           }
     114
     115          var paramItem = calculatorListView.Items.Add(calc.Name + ".Parameters", "Parameters");
     116          paramItem.Group = group;
     117          paramItem.Tag = "param";
     118
     119          var charactItem = calculatorListView.Items.Add(calc.Name + ".Characteristics", "Characteristics");
     120          charactItem.Group = group;
     121          charactItem.Tag = "chara";
    118122        }
    119123      } finally { calculatorListView.EndUpdate(); }
     
    189193      } catch (Exception ex) { ErrorHandling.ShowErrorDialog(ex); }
    190194    }
     195    private void calculatorListView_SelectedIndexChanged(object sender, EventArgs e) {
     196      if (InvokeRequired) {
     197        Invoke((Action<object, EventArgs>)calculatorListView_SelectedIndexChanged, sender, e);
     198        return;
     199      }
     200      if (calculatorListView.SelectedIndices.Count == 0) calculatorViewHost.Content = null;
     201      else {
     202        var item = calculatorListView.SelectedItems[0];
     203        if ((string)item.Tag == "param") {
     204          calculatorViewHost.Content = ((ICharacteristicCalculator)item.Group.Tag);
     205        } else if ((string)item.Tag == "chara") {
     206          calculatorViewHost.Content = ((ICharacteristicCalculator)item.Group.Tag).Characteristics;
     207        }
     208      }
     209    }
    191210    private void calculateButton_Click(object sender, EventArgs e) {
    192       var characteristics = calculatorListView.CheckedItems.OfType<ListViewItem>().GroupBy(x => x.Group).ToList();
    193       if (characteristics.Count == 0) return;
    194       var problem = Content.CloneProblem();
     211      var calculators = calculatorListView.Groups.OfType<ListViewGroup>()
     212                                                     .Select(x => (ICharacteristicCalculator)x.Tag)
     213                                                     .Where(x => x.Characteristics.CheckedItems.Any()
     214                                                              && x.CanCalculate()).ToList();
     215      if (calculators.Count == 0) return;
     216
    195217      var results = new Dictionary<string, Value>();
    196       foreach (var c in characteristics) {
    197         var calc = (ICharacteristicCalculator)c.Key.Tag;
    198         foreach (var result in calc.Calculate(problem, c.Select(x => x.Text).ToArray()))
    199           results[result.Key] = RunCreationClient.Instance.ConvertToValue(result.Value, result.Key);
     218      foreach (var calc in calculators) {
     219        foreach (var result in calc.Calculate())
     220          results[result.Name] = RunCreationClient.Instance.ConvertToValue(result.Value, result.Name);
    200221      }
    201222      var matrix = (characteristicsMatrixView.Content as StringMatrix) ?? (new StringMatrix(results.Count, 3));
     
    231252        }
    232253      }
    233       SetEnabledStateOfControls();
    234     }
    235     private void calculatorListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
     254      characteristicsMatrixView.Content = matrix;
    236255      SetEnabledStateOfControls();
    237256    }
Note: See TracChangeset for help on using the changeset viewer.