Changeset 13593 for trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
- Timestamp:
- 02/07/16 23:12:22 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
r13552 r13593 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.Linq;25 using System.Windows.Forms;26 22 using HeuristicLab.Common.Resources; 27 23 using HeuristicLab.Core.Views; … … 30 26 using HeuristicLab.Optimization; 31 27 using HeuristicLab.PluginInfrastructure; 28 using System; 29 using System.Collections.Generic; 30 using System.Linq; 31 using System.Windows.Forms; 32 32 33 33 namespace HeuristicLab.Clients.OKB.RunCreation { … … 91 91 uploadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly 92 92 && 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; 94 94 } 95 95 … … 105 105 if (Content == null || Content.ProblemId == -1) return; 106 106 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(); 108 108 try { 109 109 calculatorListView.BeginUpdate(); 110 110 foreach (var calc in calculators) { 111 calc.Problem = problem; 111 112 var group = calculatorListView.Groups.Add(calc.Name, calc.Name); 112 113 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"; 118 122 } 119 123 } finally { calculatorListView.EndUpdate(); } … … 189 193 } catch (Exception ex) { ErrorHandling.ShowErrorDialog(ex); } 190 194 } 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 } 191 210 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 195 217 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); 200 221 } 201 222 var matrix = (characteristicsMatrixView.Content as StringMatrix) ?? (new StringMatrix(results.Count, 3)); … … 231 252 } 232 253 } 233 SetEnabledStateOfControls(); 234 } 235 private void calculatorListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 254 characteristicsMatrixView.Content = matrix; 236 255 SetEnabledStateOfControls(); 237 256 }
Note: See TracChangeset
for help on using the changeset viewer.