Changeset 13551 for branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs
- Timestamp:
- 01/19/16 08:49:23 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs
r13485 r13551 30 30 using HeuristicLab.MainForm; 31 31 using HeuristicLab.Optimization; 32 using HeuristicLab. PluginInfrastructure;32 using HeuristicLab.Optimization.Views; 33 33 34 34 namespace HeuristicLab.OptimizationExpertSystem.Views { … … 47 47 public ExpertSystemView() { 48 48 InitializeComponent(); 49 // brings progress panel to front (it is not visible by default, but obstructs other elements in designer) 50 this.Controls.SetChildIndex(this.progressPanel, 0); 51 algorithmStartButton.Text = string.Empty; 52 algorithmStartButton.Image = VSImageLibrary.Play; 49 53 refreshMapButton.Text = string.Empty; 50 54 refreshMapButton.Image = VSImageLibrary.Refresh; … … 60 64 61 65 protected override void DeregisterContentEvents() { 62 Content.PropertyChanged -= Content _PropertyChanged;66 Content.PropertyChanged -= ContentOnPropertyChanged; 63 67 Content.SuggestedInstances.CollectionReset -= SuggestedInstancesOnChanged; 64 68 Content.SuggestedInstances.ItemsAdded -= SuggestedInstancesOnChanged; … … 66 70 Content.SuggestedInstances.ItemsRemoved -= SuggestedInstancesOnChanged; 67 71 Content.SuggestedInstances.ItemsReplaced -= SuggestedInstancesOnChanged; 72 if (Content.Problem != null) Content.Problem.ProblemChanged -= ContentOnProblemChanged; 68 73 base.DeregisterContentEvents(); 69 74 } 70 75 protected override void RegisterContentEvents() { 71 76 base.RegisterContentEvents(); 72 Content.PropertyChanged += Content _PropertyChanged;77 Content.PropertyChanged += ContentOnPropertyChanged; 73 78 Content.SuggestedInstances.CollectionReset += SuggestedInstancesOnChanged; 74 79 Content.SuggestedInstances.ItemsAdded += SuggestedInstancesOnChanged; … … 76 81 Content.SuggestedInstances.ItemsRemoved += SuggestedInstancesOnChanged; 77 82 Content.SuggestedInstances.ItemsReplaced += SuggestedInstancesOnChanged; 83 if (Content.Problem != null) Content.Problem.ProblemChanged += ContentOnProblemChanged; 78 84 } 79 85 … … 89 95 algorithmViewHost.Content = null; 90 96 runsView.Content = null; 91 algorithmInstancesViewHost.Content = null;97 kbViewHost.Content = null; 92 98 problemInstancesView.Content = null; 93 99 } else { … … 95 101 problemViewHost.Content = Content.Problem; 96 102 runsView.Content = Content.Runs; 97 algorithmInstancesViewHost.Content = Content.AlgorithmInstances; 103 kbViewHost.ViewType = typeof(RunCollectionRLDView); 104 kbViewHost.Content = Content.KnowledgeBase; 98 105 problemInstancesView.Content = Content.ProblemInstances; 99 106 } … … 105 112 base.SetEnabledStateOfControls(); 106 113 maxEvaluationsTextBox.Enabled = Content != null && !ReadOnly && !Locked; 107 newProblemButton.Enabled = Content != null && !ReadOnly && !Locked; 108 openProblemButton.Enabled = Content != null && !ReadOnly && !Locked; 109 problemViewHost.Enabled = Content != null && !ReadOnly && !Locked; 110 suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked; 114 problemViewHost.Enabled = Content != null && !ReadOnly && !Locked && !okbDownloadInProgress; 115 suggestedInstancesComboBox.Enabled = Content != null && !ReadOnly && !Locked && !okbDownloadInProgress; 116 algorithmStartButton.Enabled = Content != null && !ReadOnly && !Locked && suggestedInstancesComboBox.SelectedIndex >= 0; 111 117 algorithmViewHost.Enabled = Content != null && !ReadOnly && !Locked; 112 118 runsView.Enabled = Content != null; 113 algorithmInstancesViewHost.Enabled = Content != null && !okbDownloadInProgress; 119 kbViewHost.Enabled = Content != null && !okbDownloadInProgress; 120 problemInstancesView.Enabled = Content != null && !okbDownloadInProgress; 114 121 refreshMapButton.Enabled = Content != null; 115 okbDownloadButton.Enabled = Content != null && Content.Problem != null && !ReadOnly && !Locked && !okbDownloadInProgress;122 okbDownloadButton.Enabled = Content != null && Content.Problem != null && Content.Problem.ProblemId >= 0 && !ReadOnly && !Locked && !okbDownloadInProgress; 116 123 } 117 124 … … 134 141 #region Event Handlers 135 142 #region Content events 136 private void Content_PropertyChanged(object sender, PropertyChangedEventArgs e) { 143 private void ContentOnProblemChanged(object sender, EventArgs eventArgs) { 144 UpdateSuggestedInstancesCombobox(); 145 SetEnabledStateOfControls(); 146 } 147 148 private void ContentOnPropertyChanged(object sender, PropertyChangedEventArgs e) { 137 149 if (InvokeRequired) { 138 Invoke((Action<object, PropertyChangedEventArgs>)Content _PropertyChanged, sender, e);150 Invoke((Action<object, PropertyChangedEventArgs>)ContentOnPropertyChanged, sender, e); 139 151 return; 140 152 } … … 142 154 try { 143 155 switch (e.PropertyName) { 144 case " AlgorithmInstances": algorithmInstancesViewHost.Content = Content.AlgorithmInstances; break;156 case "KnowledgeBase": kbViewHost.Content = Content.KnowledgeBase; break; 145 157 case "MaximumEvaluations": maxEvaluationsTextBox.Text = Content.MaximumEvaluations.ToString(); break; 146 case "Problem": problemViewHost.Content = Content.Problem; break; 158 case "Problem": 159 problemViewHost.Content = Content.Problem; 160 Content.Problem.ProblemChanged += ContentOnProblemChanged; 161 break; 147 162 case "ProblemInstances": problemInstancesView.Content = Content.ProblemInstances; break; 148 163 } … … 172 187 errorProvider.SetError(maxEvaluationsTextBox, null); 173 188 } 174 }175 176 private void newProblemButton_Click(object sender, EventArgs e) {177 if (problemTypeSelectorDialog == null) {178 problemTypeSelectorDialog = new TypeSelectorDialog { Caption = "Select Problem" };179 problemTypeSelectorDialog.TypeSelector.Caption = "Available Problems";180 problemTypeSelectorDialog.TypeSelector.Configure(typeof(ISingleObjectiveHeuristicOptimizationProblem)181 , showNotInstantiableTypes: false, showGenericTypes: false);182 }183 if (problemTypeSelectorDialog.ShowDialog(this) == DialogResult.OK) {184 try {185 Content.Problem = (ISingleObjectiveHeuristicOptimizationProblem)problemTypeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();186 } catch (Exception ex) {187 ErrorHandling.ShowErrorDialog(this, ex);188 }189 }190 }191 192 private void openProblemButton_Click(object sender, EventArgs e) {193 openFileDialog.Title = "Open Problem";194 if (openFileDialog.ShowDialog(this) == DialogResult.OK) {195 newProblemButton.Enabled = openProblemButton.Enabled = false;196 problemViewHost.Enabled = false;197 198 ContentManager.LoadAsync(openFileDialog.FileName, delegate(IStorableContent content, Exception error) {199 try {200 if (error != null) throw error;201 var problem = content as ISingleObjectiveHeuristicOptimizationProblem;202 if (problem == null) {203 var algorithm = content as IAlgorithm;204 if (algorithm == null || !(algorithm.Problem is ISingleObjectiveHeuristicOptimizationProblem))205 MessageBox.Show(this, "The selected file is not a problem, nor an algorithm with a problem.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);206 else Content.Problem = (ISingleObjectiveHeuristicOptimizationProblem)algorithm.Problem;207 } else208 Content.Problem = problem;209 } catch (Exception ex) {210 ErrorHandling.ShowErrorDialog(this, ex);211 } finally {212 Invoke(new Action(delegate() {213 problemViewHost.Enabled = true;214 newProblemButton.Enabled = openProblemButton.Enabled = true;215 }));216 }217 });218 }219 }220 221 private void problemTabPage_DragEnterOver(object sender, DragEventArgs e) {222 e.Effect = DragDropEffects.None;223 var prob = e.Data.GetData(Constants.DragDropDataFormat) as ISingleObjectiveHeuristicOptimizationProblem;224 if (!ReadOnly && prob != null) {225 if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key226 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key227 else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;228 else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;229 else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;230 }231 }232 233 private void problemTabPage_DragDrop(object sender, DragEventArgs e) {234 if (e.Effect != DragDropEffects.None) {235 var prob = e.Data.GetData(Constants.DragDropDataFormat) as ISingleObjectiveHeuristicOptimizationProblem;236 if (e.Effect.HasFlag(DragDropEffects.Copy)) prob = (ISingleObjectiveHeuristicOptimizationProblem)prob.Clone();237 Content.Problem = prob;238 }239 }240 241 private void suggestedInstancesComboBox_SelectedIndexChanged(object sender, EventArgs e) {242 if (SuppressEvents) return;243 if (InvokeRequired) { Invoke((Action<object, EventArgs>)suggestedInstancesComboBox_SelectedIndexChanged, sender, e); return; }244 if (suggestedInstancesComboBox.SelectedIndex >= 0)245 algorithmViewHost.Content = (IAlgorithm)suggestedInstancesComboBox.SelectedItem;246 else algorithmViewHost.Content = null;247 189 } 248 190 #endregion … … 290 232 291 233 private void okbDownloadButton_Click(object sender, EventArgs e) { 234 if (Content.Problem.ProblemId < 0) { 235 MessageBox.Show("Please select a problem instance first."); 236 return; 237 } 292 238 var progress = new Progress(); 293 239 progress.ProgressStateChanged += OkbDownloadProgressOnStateChanged; … … 307 253 } 308 254 } 255 256 private void algorithmStartButton_Click(object sender, EventArgs e) { 257 var selectedInstance = (IAlgorithm)suggestedInstancesComboBox.SelectedItem; 258 var clone = (IAlgorithm)selectedInstance.Clone(); 259 clone.Prepare(true); 260 clone.Start(); 261 algorithmViewHost.Content = clone.Results; 262 } 309 263 } 310 264 }
Note: See TracChangeset
for help on using the changeset viewer.