Changeset 15417
- Timestamp:
- 10/11/17 10:00:34 (7 years ago)
- Location:
- branches/EnhancedProgress
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r15415 r15417 48 48 this.content = content; 49 49 50 UpdateButtonsState();51 if (content.Visible)ShowProgress();50 if (content.ProgressState != ProgressState.Finished) 51 ShowProgress(); 52 52 RegisterContentEvents(); 53 53 } 54 54 55 /// <summary>56 /// Clean up any resources being used.57 /// </summary>58 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>59 55 protected override void Dispose(bool disposing) { 60 56 DeregisterContentEvents(); … … 72 68 content.ProgressBarModeChanged += new EventHandler(Content_ProgressBarModeChanged); 73 69 content.ProgressValueChanged += new EventHandler(Content_ProgressValueChanged); 74 content.VisibleChanged += new EventHandler(Content_VisibleChanged);75 70 content.CanBeStoppedChanged += new EventHandler(Content_CanBeStoppedChanged); 76 71 content.CanBeCanceledChanged += new EventHandler(Content_CanBeCanceledChanged); … … 81 76 content.ProgressBarModeChanged -= new EventHandler(Content_ProgressBarModeChanged); 82 77 content.ProgressValueChanged -= new EventHandler(Content_ProgressValueChanged); 83 content.VisibleChanged -= new EventHandler(Content_VisibleChanged);84 78 content.CanBeStoppedChanged -= new EventHandler(Content_CanBeStoppedChanged); 85 79 content.CanBeCanceledChanged -= new EventHandler(Content_CanBeCanceledChanged); … … 102 96 } 103 97 104 private void Content_VisibleChanged(object sender, EventArgs e) { 105 if (content.Visible) 98 private void Content_CanBeStoppedChanged(object sender, EventArgs e) { 99 UpdateButtonsState(); 100 } 101 private void Content_CanBeCanceledChanged(object sender, EventArgs e) { 102 UpdateButtonsState(); 103 } 104 105 private void ShowProgress() { 106 if (control.InvokeRequired) { 107 control.Invoke((Action)ShowProgress); 108 return; 109 } 110 if (Parent != null) return; 111 112 int height = (content.CanBeStopped || content.CanBeCanceled) ? Height : collapsedControlHeight; 113 Left = (control.ClientRectangle.Width / 2) - (Width / 2); 114 Top = (control.ClientRectangle.Height / 2) - (height / 2); 115 Anchor = AnchorStyles.None; 116 117 UpdateProgressMessage(); 118 UpdateProgressValue(); 119 UpdateButtonsState(); 120 121 control.Enabled = false; 122 Parent = control.Parent; 123 BringToFront(); 124 Visible = true; 125 } 126 127 private void HideProgress() { 128 if (control.InvokeRequired) { 129 control.Invoke((Action)HideProgress); 130 return; 131 } 132 if (Parent == null) return; 133 134 Visible = false; 135 control.Enabled = true; 136 Parent = null; 137 } 138 139 private void UpdateProgressState() { 140 if (control.InvokeRequired) { 141 control.Invoke((Action)UpdateProgressState); 142 return; 143 } 144 145 if (content.ProgressState != ProgressState.Finished) 106 146 ShowProgress(); 107 147 else 108 148 HideProgress(); 109 }110 111 private void Content_CanBeStoppedChanged(object sender, EventArgs e) {112 UpdateButtonsState();113 }114 private void Content_CanBeCanceledChanged(object sender, EventArgs e) {115 UpdateButtonsState();116 }117 118 private void ShowProgress() {119 if (control.InvokeRequired) {120 control.Invoke((Action)ShowProgress);121 return;122 }123 124 int height = (content.CanBeStopped || content.CanBeCanceled) ? Height : collapsedControlHeight;125 126 Left = (control.ClientRectangle.Width / 2) - (Width / 2);127 Top = (control.ClientRectangle.Height / 2) - (height / 2);128 Anchor = AnchorStyles.None;129 130 control.Enabled = false;131 Parent = control.Parent;132 BringToFront();133 134 UpdateProgressValue();135 UpdateProgressMessage();136 UpdateButtonsState();137 Visible = true;138 }139 140 private void HideProgress() {141 if (control.InvokeRequired) {142 control.Invoke((Action)HideProgress);143 return;144 }145 146 control.Enabled = true;147 Parent = null;148 Visible = false;149 }150 151 private void UpdateProgressState() {152 if (control.InvokeRequired) {153 control.Invoke((Action)UpdateProgressState);154 return;155 }156 149 157 150 switch (content.ProgressState) { 158 151 case ProgressState.Started: 152 case ProgressState.Finished: 159 153 progressBar.SetState(ProgressBarState.Normal); 160 154 break; 161 case ProgressState.Finished: 162 HideProgress(); 163 progressBar.SetState(ProgressBarState.Normal); 164 break; 165 case ProgressState.Stopped: 155 case ProgressState.StopRequested: 166 156 progressBar.SetState(ProgressBarState.Warning); 167 157 break; 168 case ProgressState.Cancel ed:158 case ProgressState.CancelRequested: 169 159 progressBar.SetState(ProgressBarState.Error); 170 160 break; … … 211 201 212 202 stopButton.Visible = content.CanBeStopped; 213 stopButton.Enabled = content. ProgressState == ProgressState.Started && content.CanBeStopped;203 stopButton.Enabled = content.CanBeStopped && content.ProgressState == ProgressState.Started; 214 204 215 205 cancelButton.Visible = content.CanBeCanceled; 216 cancelButton.Enabled = content. ProgressState == ProgressState.Started && content.CanBeCanceled;206 cancelButton.Enabled = content.CanBeCanceled && content.ProgressState == ProgressState.Started; 217 207 218 208 if (content.CanBeStopped || content.CanBeCanceled) { -
branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.designer.cs
r15415 r15417 103 103 // stopButton 104 104 // 105 this.stopButton.Dock = System.Windows.Forms.DockStyle.Left;106 105 this.stopButton.Location = new System.Drawing.Point(193, 3); 107 106 this.stopButton.Name = "stopButton"; -
branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r15415 r15417 24 24 25 25 namespace HeuristicLab.MainForm { 26 public enum ProgressState { Started, Finished, Stop ped, Canceled }26 public enum ProgressState { Started, Finished, StopRequested, CancelRequested } 27 27 public enum ProgressBarMode { Continuous, Marquee } 28 28 … … 36 36 /// </summary> 37 37 double ProgressValue { get; set; } 38 bool Visible { get; set; }39 38 bool CanBeStopped { get; } 40 39 bool CanBeCanceled { get; } … … 56 55 event EventHandler ProgressBarModeChanged; 57 56 event EventHandler ProgressValueChanged; 58 event EventHandler VisibleChanged;59 57 event EventHandler CanBeStoppedChanged; 60 58 event EventHandler CanBeCanceledChanged; -
branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Progress.cs
r15415 r15417 70 70 } 71 71 72 private bool visible;73 public bool Visible {74 get { return visible; }75 set {76 if (visible != value) {77 visible = value;78 OnVisibleChanged();79 }80 }81 }82 83 72 private bool canBeStopped; 84 73 public bool CanBeStopped { … … 115 104 ProgressBarMode = ProgressBarMode.Marquee; 116 105 Message = message; 117 Visible = true;118 106 } 119 107 public void Start(string message, double progressValue) { … … 122 110 ProgressValue = progressValue; 123 111 Message = message; 124 Visible = true;125 112 } 126 113 … … 129 116 ProgressValue = 1.0; 130 117 ProgressState = ProgressState.Finished; 131 Visible = false;132 118 } 133 119 134 120 public void Stop() { 135 121 if (canBeStopped) { 136 ProgressState = ProgressState.Stop ped;122 ProgressState = ProgressState.StopRequested; 137 123 OnStopRequested(); 138 124 } else throw new NotSupportedException("This progress cannot be stopped."); … … 140 126 public void Cancel() { 141 127 if (canBeCanceled) { 142 ProgressState = ProgressState.Cancel ed;128 ProgressState = ProgressState.CancelRequested; 143 129 OnCancelRequested(); 144 130 } else throw new NotSupportedException("This progress cannot be canceled."); … … 170 156 } 171 157 172 public event EventHandler VisibleChanged;173 private void OnVisibleChanged() {174 var handler = VisibleChanged;175 if (handler != null) handler(this, EventArgs.Empty);176 }177 178 158 public event EventHandler CanBeStoppedChanged; 179 159 private void OnCanBeStoppedChanged() { -
branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r15415 r15417 40 40 private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator; 41 41 42 private readonly IProgress progress = new Progress() { CanBeCanceled = true, CanBeStopped = true };42 private readonly Progress progress = new Progress(); 43 43 44 44 private enum TreeState { Valid, Invalid } … … 184 184 185 185 progress.Start("Calculate Impact and Replacement Values ...", 0); 186 progress.CanBeStopped = true; 186 187 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 187 await Task.Delay(500); // wait for progressbar to finish animation 188 if (progress.ProgressState != ProgressState.StopRequested) 189 await Task.Delay(500); // wait for progressbar to finish animation 188 190 var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2); 189 191 foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) { … … 192 194 nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1); 193 195 progress.Finish(); 196 progress.CanBeStopped = false; 194 197 PaintNodeImpacts(); 195 198 } … … 198 201 var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>(); 199 202 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 203 if (progress.ProgressState == ProgressState.StopRequested) continue; 200 204 double impactValue, replacementValue, newQualityForImpactsCalculation; 201 205 impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
Note: See TracChangeset
for help on using the changeset viewer.