- Timestamp:
- 01/20/10 05:04:31 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/EngineBaseView.cs
r2546 r2655 43 43 /// </summary> 44 44 /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks> 45 public IEngine Engine {46 get { return ( IEngine)Item; }45 public EngineBase Engine { 46 get { return (EngineBase)Item; } 47 47 set { base.Item = value; } 48 48 } … … 54 54 InitializeComponent(); 55 55 } 56 public EngineBaseView(EngineBase engine) 57 : this() { 58 Engine = engine; 59 } 56 60 57 61 /// <summary> … … 59 63 /// </summary> 60 64 /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks> 61 protected override void RemoveItemEvents() { 65 protected override void DeregisterObjectEvents() { 66 Engine.OperatorGraphChanged -= new EventHandler(Engine_OperatorGraphChanged); 62 67 Engine.Initialized -= new EventHandler(Engine_Initialized); 68 Engine.Started -= new EventHandler(Engine_Started); 69 Engine.Stopped -= new EventHandler(Engine_Stopped); 70 Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged); 63 71 Engine.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 64 Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged); 65 Engine.Finished -= new EventHandler(Engine_Finished); 66 operatorGraphView.OperatorGraph = null; 67 scopeView.Scope = null; 68 base.RemoveItemEvents(); 72 base.DeregisterObjectEvents(); 69 73 } 74 70 75 /// <summary> 71 76 /// Adds event handlers to the underlying <see cref="IEngine"/>. 72 77 /// </summary> 73 78 /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks> 74 protected override void AddItemEvents() { 75 base.AddItemEvents(); 79 protected override void RegisterObjectEvents() { 80 base.RegisterObjectEvents(); 81 Engine.OperatorGraphChanged += new EventHandler(Engine_OperatorGraphChanged); 76 82 Engine.Initialized += new EventHandler(Engine_Initialized); 83 Engine.Started += new EventHandler(Engine_Started); 84 Engine.Stopped += new EventHandler(Engine_Stopped); 85 Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged); 77 86 Engine.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred); 78 Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged);79 Engine.Finished += new EventHandler(Engine_Finished);80 operatorGraphView.OperatorGraph = Engine.OperatorGraph;81 scopeView.Scope = Engine.GlobalScope;82 87 } 83 88 … … 86 91 /// </summary> 87 92 /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks> 88 protected override void UpdateControls() {89 base. UpdateControls();90 abortButton.Enabled = false;93 protected override void OnObjectChanged() { 94 base.OnObjectChanged(); 95 stopButton.Enabled = false; 91 96 if (Engine == null) { 92 executeButton.Enabled = false; 97 operatorGraphView.Enabled = false; 98 scopeView.Enabled = false; 99 startButton.Enabled = false; 93 100 resetButton.Enabled = false; 94 101 executionTimeTextBox.Enabled = false; 95 102 } else { 96 executeButton.Enabled = true; 103 operatorGraphView.OperatorGraph = Engine.OperatorGraph; 104 scopeView.Scope = Engine.GlobalScope; 105 startButton.Enabled = !Engine.Finished; 97 106 resetButton.Enabled = true; 98 executionTimeCounter = 0;99 107 executionTimeTextBox.Text = Engine.ExecutionTime.ToString(); 100 108 executionTimeTextBox.Enabled = true; … … 103 111 104 112 #region Engine Events 113 private void Engine_OperatorGraphChanged(object sender, EventArgs e) { 114 if (InvokeRequired) 115 Invoke(new EventHandler(Engine_OperatorGraphChanged), sender, e); 116 else 117 operatorGraphView.OperatorGraph = Engine.OperatorGraph; 118 } 105 119 private void Engine_Initialized(object sender, EventArgs e) { 106 Refresh(); 120 if (InvokeRequired) 121 Invoke(new EventHandler(Engine_Initialized), sender, e); 122 else { 123 operatorGraphView.Enabled = true; 124 scopeView.Enabled = true; 125 startButton.Enabled = !Engine.Finished; 126 stopButton.Enabled = false; 127 resetButton.Enabled = true; 128 executionTimeTextBox.Text = Engine.ExecutionTime.ToString(); 129 } 107 130 } 108 private delegate void OnExceptionEventDelegate(object sender, EventArgs<Exception> e);109 private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {131 private void Engine_Started(object sender, EventArgs e) { 132 executionTimeCounter = 0; 110 133 if (InvokeRequired) 111 Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e); 112 else 113 Auxiliary.ShowErrorMessageBox(e.Value); 134 Invoke(new EventHandler(Engine_Started), sender, e); 135 else { 136 operatorGraphView.Enabled = false; 137 scopeView.Enabled = false; 138 startButton.Enabled = false; 139 stopButton.Enabled = true; 140 resetButton.Enabled = false; 141 executionTimeTextBox.Text = Engine.ExecutionTime.ToString(); 142 } 143 } 144 private void Engine_Stopped(object sender, EventArgs e) { 145 if (InvokeRequired) 146 Invoke(new EventHandler(Engine_Stopped), sender, e); 147 else { 148 operatorGraphView.Enabled = true; 149 scopeView.Enabled = true; 150 startButton.Enabled = !Engine.Finished; 151 stopButton.Enabled = false; 152 resetButton.Enabled = true; 153 executionTimeTextBox.Text = Engine.ExecutionTime.ToString(); 154 } 114 155 } 115 156 private void Engine_ExecutionTimeChanged(object sender, EventArgs e) { 116 157 executionTimeCounter++; 117 if (executionTimeCounter == 1000) 118 UpdateExecutionTimeTextBox(); 119 } 120 private void Engine_Finished(object sender, EventArgs e) { 121 UpdateExecutionTimeTextBox(); 122 if (globalScopeGroupBox.Controls.Count > 0) { 123 ScopeView scopeEditor = (ScopeView)globalScopeGroupBox.Controls[0]; 124 if (!scopeEditor.AutomaticUpdating) 125 scopeEditor.Refresh(); 126 } 127 EnableDisableControls(); 128 } 129 private void UpdateExecutionTimeTextBox() { 130 if (InvokeRequired) 131 Invoke(new MethodInvoker(UpdateExecutionTimeTextBox)); 132 else { 158 if ((executionTimeCounter == 1000) || !Engine.Running) { 133 159 executionTimeCounter = 0; 134 executionTimeTextBox.Text = Engine.ExecutionTime.ToString(); 160 if (InvokeRequired) 161 Invoke(new EventHandler(Engine_ExecutionTimeChanged), sender, e); 162 else 163 executionTimeTextBox.Text = Engine.ExecutionTime.ToString(); 135 164 } 136 165 } 137 private void En ableDisableControls() {166 private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) { 138 167 if (InvokeRequired) 139 Invoke(new MethodInvoker(EnableDisableControls)); 140 else { 141 executeButton.Enabled = true; 142 abortButton.Enabled = false; 143 resetButton.Enabled = true; 144 operatorGraphGroupBox.Enabled = true; 145 globalScopeGroupBox.Enabled = true; 146 } 168 Invoke(new EventHandler<EventArgs<Exception>>(Engine_ExceptionOccurred), sender, e); 169 else 170 Auxiliary.ShowErrorMessageBox(e.Value); 147 171 } 148 172 #endregion 149 173 150 174 #region Button events 151 private void executeButton_Click(object sender, EventArgs e) { 152 executeButton.Enabled = false; 153 abortButton.Enabled = true; 154 resetButton.Enabled = false; 155 operatorGraphGroupBox.Enabled = false; 156 globalScopeGroupBox.Enabled = false; 157 Engine.Execute(); 175 private void startButton_Click(object sender, EventArgs e) { 176 Engine.Start(); 158 177 } 159 private void abortButton_Click(object sender, EventArgs e) {160 Engine. Abort();178 private void stopButton_Click(object sender, EventArgs e) { 179 Engine.Stop(); 161 180 } 162 181 private void resetButton_Click(object sender, EventArgs e) { 163 Engine.Reset(); 164 UpdateExecutionTimeTextBox(); 165 if (globalScopeGroupBox.Controls.Count > 0) { 166 ScopeView scopeEditor = (ScopeView)globalScopeGroupBox.Controls[0]; 167 if (!scopeEditor.AutomaticUpdating) 168 scopeEditor.Refresh(); 169 } 182 Engine.Initialize(); 170 183 } 171 184 #endregion
Note: See TracChangeset
for help on using the changeset viewer.