Changeset 16692 for branches/2521_ProblemRefactoring/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
- Timestamp:
- 03/18/19 17:24:30 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2521_ProblemRefactoring/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
r12012 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using HeuristicLab.Common.Resources; 23 using HeuristicLab.Core; 24 using HeuristicLab.Core.Views; 25 using HeuristicLab.Data; 26 using HeuristicLab.MainForm; 27 using HeuristicLab.Optimization; 28 using HeuristicLab.PluginInfrastructure; 22 29 using System; 30 using System.Collections.Generic; 31 using System.Drawing; 23 32 using System.Linq; 24 33 using System.Windows.Forms; 25 using HeuristicLab.Core.Views;26 using HeuristicLab.MainForm;27 34 28 35 namespace HeuristicLab.Clients.OKB.RunCreation { … … 31 38 [Content(typeof(MultiObjectiveOKBProblem), true)] 32 39 public sealed partial class OKBProblemView : NamedItemView { 40 private readonly CheckedItemList<ICharacteristicCalculator> calculatorList; 41 33 42 public new OKBProblem Content { 34 43 get { return (OKBProblem)base.Content; } … … 38 47 public OKBProblemView() { 39 48 InitializeComponent(); 49 var calculatorListView = new CheckedItemListView<ICharacteristicCalculator>() { 50 Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top, 51 Location = new Point(flaSplitContainer.Padding.Left, calculateButton.Location.Y + calculateButton.Height + calculateButton.Padding.Bottom + 3), 52 }; 53 calculatorListView.Size = new Size(flaSplitContainer.Panel1.Size.Width - flaSplitContainer.Panel1.Padding.Horizontal, 54 flaSplitContainer.Panel1.Height - calculatorListView.Location.Y - flaSplitContainer.Panel1.Padding.Bottom); 55 calculatorList = new CheckedItemList<ICharacteristicCalculator>(); 56 calculatorList.ItemsAdded += CalculatorListOnChanged; 57 calculatorList.ItemsRemoved += CalculatorListOnChanged; 58 calculatorList.ItemsReplaced += CalculatorListOnChanged; 59 calculatorList.CollectionReset += CalculatorListOnChanged; 60 calculatorList.CheckedItemsChanged += CalculatorListOnChanged; 61 62 calculatorListView.Content = calculatorList.AsReadOnly(); 63 64 flaSplitContainer.Panel1.Controls.Add(calculatorListView); 65 calculateButton.Text = string.Empty; 66 calculateButton.Image = VSImageLibrary.Play; 67 refreshButton.Text = string.Empty; 68 refreshButton.Image = VSImageLibrary.Refresh; 69 cloneProblemButton.Text = string.Empty; 70 cloneProblemButton.Image = VSImageLibrary.Clone; 71 downloadCharacteristicsButton.Text = string.Empty; 72 downloadCharacteristicsButton.Image = VSImageLibrary.Refresh; 73 uploadCharacteristicsButton.Text = string.Empty; 74 uploadCharacteristicsButton.Image = VSImageLibrary.PublishToWeb; 75 refreshSolutionsButton.Text = string.Empty; 76 refreshSolutionsButton.Image = VSImageLibrary.Refresh; 77 uploadSolutionsButton.Text = string.Empty; 78 uploadSolutionsButton.Image = VSImageLibrary.PublishToWeb; 79 } 80 81 private void CalculatorListOnChanged(object sender, EventArgs e) { 82 SetEnabledStateOfControls(); 40 83 } 41 84 … … 54 97 base.RegisterContentEvents(); 55 98 Content.ProblemChanged += new EventHandler(Content_ProblemChanged); 99 Content.Solutions.ItemsAdded += SolutionsOnChanged; 100 Content.Solutions.ItemsReplaced += SolutionsOnChanged; 101 Content.Solutions.ItemsRemoved += SolutionsOnChanged; 102 Content.Solutions.CollectionReset += SolutionsOnChanged; 103 } 104 105 private void SolutionsOnChanged(object sender, EventArgs e) { 106 if (InvokeRequired) { Invoke((Action<object, EventArgs>)SolutionsOnChanged, sender, e); return; } 107 SetEnabledStateOfControls(); 56 108 } 57 109 … … 61 113 problemComboBox.SelectedIndex = -1; 62 114 parameterCollectionView.Content = null; 115 solutionsViewHost.Content = null; 63 116 } else { 64 117 problemComboBox.SelectedItem = RunCreationClient.Instance.Problems.FirstOrDefault(x => x.Id == Content.ProblemId); 65 118 parameterCollectionView.Content = Content.Parameters; 66 } 119 solutionsViewHost.Content = Content.Solutions; 120 } 121 UpdateCharacteristicCalculators(); 67 122 } 68 123 … … 73 128 refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked; 74 129 parameterCollectionView.Enabled = Content != null; 130 characteristicsMatrixView.Enabled = Content != null; 131 downloadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked; 132 uploadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly 133 && characteristicsMatrixView.Content != null && characteristicsMatrixView.Content.Rows > 0; 134 calculateButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly && calculatorList.CheckedItems.Any(); 135 refreshSolutionsButton.Enabled = Content != null && !ReadOnly && !Locked && Content.ProblemId != -1; 136 uploadSolutionsButton.Enabled = Content != null && !ReadOnly && !Locked && Content.ProblemId != -1 && Content.Solutions.Any(x => x.SolutionId == -1); 75 137 } 76 138 … … 79 141 RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed); 80 142 base.OnClosed(e); 143 } 144 145 private void UpdateCharacteristicCalculators() { 146 calculatorList.Clear(); 147 if (Content == null || Content.ProblemId == -1) return; 148 var problem = Content.CloneProblem(); 149 var calculators = ApplicationManager.Manager.GetInstances<ICharacteristicCalculator>().ToList(); 150 foreach (var calc in calculators) { 151 calc.Problem = problem; 152 if (!calc.CanCalculate()) continue; 153 calculatorList.Add(calc, true); 154 } 81 155 } 82 156 … … 103 177 if (InvokeRequired) 104 178 Invoke(new EventHandler(Content_ProblemChanged), sender, e); 105 else 179 else { 106 180 OnContentChanged(); 181 SetEnabledStateOfControls(); 182 } 107 183 } 108 184 #endregion … … 123 199 } 124 200 } 201 private void downloadCharacteristicsButton_Click(object sender, EventArgs e) { 202 var values = RunCreationClient.Instance.GetCharacteristicValues(Content.ProblemId).ToList(); 203 var content = new StringMatrix(values.Count, 3); 204 for (var i = 0; i < values.Count; i++) { 205 content[i, 0] = values[i].Name; 206 content[i, 1] = values[i].GetValue(); 207 content[i, 2] = values[i].GetType().Name; 208 } 209 characteristicsMatrixView.Content = content; 210 SetEnabledStateOfControls(); 211 } 212 private void uploadCharacteristicsButton_Click(object sender, EventArgs e) { 213 var matrix = characteristicsMatrixView.Content as StringMatrix; 214 if (matrix == null) return; 215 var values = new List<Value>(matrix.Rows); 216 for (var i = 0; i < matrix.Rows; i++) { 217 var name = matrix[i, 0]; 218 var strValue = matrix[i, 1]; 219 var type = matrix[i, 2]; 220 values.Add(Value.Create(name, strValue, type)); 221 } 222 try { 223 RunCreationClient.Instance.SetCharacteristicValues(Content.ProblemId, values); 224 } catch (Exception ex) { ErrorHandling.ShowErrorDialog(ex); } 225 } 226 private void calculateButton_Click(object sender, EventArgs e) { 227 var calculators = calculatorList.CheckedItems.Select(x => x.Value).Where(x => x.CanCalculate()).ToList(); 228 if (calculators.Count == 0) return; 229 230 var results = new Dictionary<string, Value>(); 231 foreach (var calc in calculators) { 232 foreach (var result in calc.Calculate()) 233 results[result.Name] = RunCreationClient.Instance.ConvertToValue(result.Value, result.Name); 234 } 235 var matrix = (characteristicsMatrixView.Content as StringMatrix) ?? (new StringMatrix(results.Count, 3)); 236 try { 237 for (var i = 0; i < matrix.Rows; i++) { 238 Value r; 239 if (results.TryGetValue(matrix[i, 0], out r)) { 240 matrix[i, 1] = r.GetValue(); 241 matrix[i, 2] = r.GetType().Name; 242 results.Remove(matrix[i, 0]); 243 } 244 } 245 if (results.Count == 0) return; 246 var resultsList = results.ToList(); 247 var counter = resultsList.Count - 1; 248 for (var i = 0; i < matrix.Rows; i++) { 249 if (string.IsNullOrEmpty(matrix[i, 0])) { 250 matrix[i, 0] = resultsList[counter].Key; 251 matrix[i, 1] = resultsList[counter].Value.GetValue(); 252 matrix[i, 2] = resultsList[counter].Value.GetType().Name; 253 resultsList.RemoveAt(counter); 254 counter--; 255 if (counter < 0) return; 256 } 257 } 258 if (counter >= 0) { 259 ((IStringConvertibleMatrix)matrix).Rows += counter + 1; 260 for (var i = matrix.Rows - 1; counter >= 0; i--) { 261 matrix[i, 0] = resultsList[0].Key; 262 matrix[i, 1] = resultsList[0].Value.GetValue(); 263 matrix[i, 2] = resultsList[0].Value.GetType().Name; 264 resultsList.RemoveAt(0); 265 counter--; 266 } 267 } 268 } finally { 269 characteristicsMatrixView.Content = matrix; 270 SetEnabledStateOfControls(); 271 } 272 } 125 273 #endregion 126 274 … … 132 280 } 133 281 #endregion 282 283 private void refreshSolutionsButton_Click(object sender, EventArgs e) { 284 Content.RefreshSolutions(); 285 } 286 287 private void uploadSolutionsButton_Click(object sender, EventArgs e) { 288 foreach (var solution in Content.Solutions.Where(x => x.SolutionId == -1)) 289 solution.Upload(); 290 SetEnabledStateOfControls(); 291 } 292 134 293 } 135 294 }
Note: See TracChangeset
for help on using the changeset viewer.