- Timestamp:
- 06/28/17 22:10:45 (7 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13501,13503,13511,13513,13534-13535,13540,13550,13552,13593,13666
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
r14186 r15081 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 } 76 77 private void CalculatorListOnChanged(object sender, EventArgs e) { 78 SetEnabledStateOfControls(); 40 79 } 41 80 … … 65 104 parameterCollectionView.Content = Content.Parameters; 66 105 } 106 UpdateCharacteristicCalculators(); 67 107 } 68 108 … … 73 113 refreshButton.Enabled = (Content != null) && !ReadOnly && !Locked; 74 114 parameterCollectionView.Enabled = Content != null; 115 characteristicsMatrixView.Enabled = Content != null; 116 downloadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked; 117 uploadCharacteristicsButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly 118 && characteristicsMatrixView.Content != null && characteristicsMatrixView.Content.Rows > 0; 119 calculateButton.Enabled = Content != null && Content.ProblemId != -1 && !Locked && !ReadOnly && calculatorList.CheckedItems.Any(); 75 120 } 76 121 … … 79 124 RunCreationClient.Instance.Refreshed -= new EventHandler(RunCreationClient_Refreshed); 80 125 base.OnClosed(e); 126 } 127 128 private void UpdateCharacteristicCalculators() { 129 calculatorList.Clear(); 130 if (Content == null || Content.ProblemId == -1) return; 131 var problem = Content.CloneProblem(); 132 var calculators = ApplicationManager.Manager.GetInstances<ICharacteristicCalculator>().ToList(); 133 foreach (var calc in calculators) { 134 calc.Problem = problem; 135 if (!calc.CanCalculate()) continue; 136 calculatorList.Add(calc, true); 137 } 81 138 } 82 139 … … 103 160 if (InvokeRequired) 104 161 Invoke(new EventHandler(Content_ProblemChanged), sender, e); 105 else 162 else { 106 163 OnContentChanged(); 164 SetEnabledStateOfControls(); 165 } 107 166 } 108 167 #endregion … … 123 182 } 124 183 } 184 private void downloadCharacteristicsButton_Click(object sender, EventArgs e) { 185 var values = RunCreationClient.GetCharacteristicValues(Content.ProblemId).ToList(); 186 var content = new StringMatrix(values.Count, 3); 187 for (var i = 0; i < values.Count; i++) { 188 content[i, 0] = values[i].Name; 189 content[i, 1] = values[i].GetValue(); 190 content[i, 2] = values[i].GetType().Name; 191 } 192 characteristicsMatrixView.Content = content; 193 SetEnabledStateOfControls(); 194 } 195 private void uploadCharacteristicsButton_Click(object sender, EventArgs e) { 196 var matrix = characteristicsMatrixView.Content as StringMatrix; 197 if (matrix == null) return; 198 var values = new List<Value>(matrix.Rows); 199 for (var i = 0; i < matrix.Rows; i++) { 200 var name = matrix[i, 0]; 201 var strValue = matrix[i, 1]; 202 var type = matrix[i, 2]; 203 values.Add(Value.Create(name, strValue, type)); 204 } 205 try { 206 RunCreationClient.SetCharacteristicValues(Content.ProblemId, values); 207 } catch (Exception ex) { ErrorHandling.ShowErrorDialog(ex); } 208 } 209 private void calculateButton_Click(object sender, EventArgs e) { 210 var calculators = calculatorList.CheckedItems.Select(x => x.Value).Where(x => x.CanCalculate()).ToList(); 211 if (calculators.Count == 0) return; 212 213 var results = new Dictionary<string, Value>(); 214 foreach (var calc in calculators) { 215 foreach (var result in calc.Calculate()) 216 results[result.Name] = RunCreationClient.Instance.ConvertToValue(result.Value, result.Name); 217 } 218 var matrix = (characteristicsMatrixView.Content as StringMatrix) ?? (new StringMatrix(results.Count, 3)); 219 for (var i = 0; i < matrix.Rows; i++) { 220 Value r; 221 if (results.TryGetValue(matrix[i, 0], out r)) { 222 matrix[i, 1] = r.GetValue(); 223 matrix[i, 2] = r.GetType().Name; 224 results.Remove(matrix[i, 0]); 225 } 226 } 227 if (results.Count == 0) return; 228 var resultsList = results.ToList(); 229 var counter = resultsList.Count - 1; 230 for (var i = 0; i < matrix.Rows; i++) { 231 if (string.IsNullOrEmpty(matrix[i, 0])) { 232 matrix[i, 0] = resultsList[counter].Key; 233 matrix[i, 1] = resultsList[counter].Value.GetValue(); 234 matrix[i, 2] = resultsList[counter].Value.GetType().Name; 235 resultsList.RemoveAt(counter); 236 counter--; 237 if (counter < 0) return; 238 } 239 } 240 if (counter >= 0) { 241 ((IStringConvertibleMatrix)matrix).Rows += counter + 1; 242 for (var i = matrix.Rows - 1; counter >= 0; i--) { 243 matrix[i, 0] = resultsList[0].Key; 244 matrix[i, 1] = resultsList[0].Value.GetValue(); 245 matrix[i, 2] = resultsList[0].Value.GetType().Name; 246 resultsList.RemoveAt(0); 247 counter--; 248 } 249 } 250 characteristicsMatrixView.Content = matrix; 251 SetEnabledStateOfControls(); 252 } 125 253 #endregion 126 254 … … 132 260 } 133 261 #endregion 262 134 263 } 135 264 }
Note: See TracChangeset
for help on using the changeset viewer.