Changeset 13475 for branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs
- Timestamp:
- 12/16/15 17:04:35 (8 years ago)
- Location:
- branches/PerformanceComparison
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison
- Property svn:ignore
-
old new 2 2 *.suo 3 3 *.user 4 .git 5 .gitignore
-
- Property svn:ignore
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs
r12860 r13475 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.ComponentModel; 25 using System.IO; 26 using System.Linq; 24 27 using System.Windows.Forms; 28 using HeuristicLab.Clients.OKB.Administration; 29 using HeuristicLab.Clients.OKB.Query; 25 30 using HeuristicLab.Common; 31 using HeuristicLab.Common.Resources; 32 using HeuristicLab.Core; 26 33 using HeuristicLab.Core.Views; 27 34 using HeuristicLab.MainForm; 28 35 using HeuristicLab.Optimization; 36 using HeuristicLab.Persistence.Default.Xml; 29 37 using HeuristicLab.PluginInfrastructure; 30 38 … … 43 51 public ExpertSystemView() { 44 52 InitializeComponent(); 53 refreshMapButton.Text = string.Empty; 54 refreshMapButton.Image = VSImageLibrary.Refresh; 45 55 } 46 56 … … 83 93 runsView.Content = null; 84 94 algorithmInstancesViewHost.Content = null; 95 problemInstancesView.Content = null; 85 96 } else { 86 97 maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); … … 88 99 runsView.Content = Content.Runs; 89 100 algorithmInstancesViewHost.Content = Content.AlgorithmInstances; 101 problemInstancesView.Content = Content.ProblemInstances; 90 102 } 91 103 } finally { SuppressEvents = false; } … … 103 115 runsView.Enabled = Content != null; 104 116 algorithmInstancesViewHost.Enabled = Content != null; 117 refreshMapButton.Enabled = Content != null; 118 okbDownloadButton.Enabled = Content != null && Content.Problem != null && !ReadOnly && !Locked; 105 119 } 106 120 … … 131 145 try { 132 146 switch (e.PropertyName) { 147 case "AlgorithmInstances": algorithmInstancesViewHost.Content = Content.AlgorithmInstances; break; 133 148 case "MaximumEvaluations": maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); break; 134 149 case "Problem": problemViewHost.Content = Content.Problem; break; 150 case "ProblemInstances": problemInstancesView.Content = Content.ProblemInstances; break; 135 151 } 136 152 } finally { SuppressEvents = false; } 153 SetEnabledStateOfControls(); 137 154 } 138 155 … … 233 250 } 234 251 #endregion 252 253 private bool validDragOperation; 254 private void instancesDropPanel_DragEnter(object sender, DragEventArgs e) { 255 validDragOperation = false; 256 if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun)) { 257 validDragOperation = true; 258 } else if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) { 259 validDragOperation = true; 260 var items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 261 foreach (object item in items) 262 validDragOperation = validDragOperation && (item is IRun); 263 } 264 } 265 private void instancesDropPanel_DragOver(object sender, DragEventArgs e) { 266 e.Effect = DragDropEffects.None; 267 if (!validDragOperation) return; 268 if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key 269 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key 270 else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; 271 else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move; 272 else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link; 273 } 274 private void instancesDropPanel_DragDrop(object sender, DragEventArgs e) { 275 if (e.Effect == DragDropEffects.None) return; 276 if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun) { 277 var item = (IRun)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); 278 Content.ProblemInstances.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item); 279 } else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) { 280 var items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<IRun>(); 281 if (e.Effect.HasFlag(DragDropEffects.Copy)) { 282 var cloner = new Cloner(); 283 items = items.Select(x => cloner.Clone(x)); 284 } 285 Content.ProblemInstances.AddRange(items); 286 } 287 } 235 288 #endregion 289 290 private void refreshMapButton_Click(object sender, EventArgs e) { 291 Content.UpdateInstanceMap(); 292 } 293 294 private void okbDownloadButton_Click(object sender, EventArgs e) { 295 var queryClient = QueryClient.Instance; 296 queryClient.Refresh(); 297 298 var problemTypeFilter = (StringComparisonAvailableValuesFilter)queryClient.Filters.Single(x => x.Label == "Problem Data Type Name"); 299 problemTypeFilter.Value = Content.Problem.GetType().Name; 300 301 var runIds = queryClient.GetRunIds(problemTypeFilter).ToList(); 302 var count = queryClient.GetNumberOfRuns(problemTypeFilter); 303 if (count > 0) { 304 var list = new ItemList<IAlgorithm>(); 305 var adminClient = AdministrationClient.Instance; 306 adminClient.Refresh(); 307 var runs = queryClient.GetRuns(runIds, true).ToList(); 308 foreach (var rGroup in runs.GroupBy(x => x.Algorithm.Id)) { 309 var data = AdministrationClient.GetAlgorithmData(rGroup.Key); 310 if (data != null) { 311 using (var stream = new MemoryStream(data)) { 312 try { 313 var alg = (IAlgorithm)XmlParser.Deserialize<IContent>(stream); 314 alg.Runs.AddRange(rGroup.Select(x => queryClient.ConvertToOptimizationRun(x))); 315 list.Add(alg); 316 } catch (Exception) { } 317 stream.Close(); 318 } 319 } 320 } 321 Content.AlgorithmInstances = list; 322 } 323 } 236 324 } 237 325 }
Note: See TracChangeset
for help on using the changeset viewer.