Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/EngineBaseEditor.cs @ 142

Last change on this file since 142 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 5.2 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30
31namespace HeuristicLab.Core {
32  public partial class EngineBaseEditor : EditorBase {
33    private int executionTimeCounter;
34
35    public IEngine Engine {
36      get { return (IEngine)Item; }
37      set { base.Item = value; }
38    }
39
40    public EngineBaseEditor() {
41      InitializeComponent();
42    }
43
44    protected override void RemoveItemEvents() {
45      Engine.Initialized -= new EventHandler(Engine_Initialized);
46      Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
47      Engine.ExecutionTimeChanged -= new EventHandler(Engine_ExecutionTimeChanged);
48      Engine.Finished -= new EventHandler(Engine_Finished);
49      operatorGraphView.OperatorGraph = null;
50      scopeView.Scope = null;
51      base.RemoveItemEvents();
52    }
53    protected override void AddItemEvents() {
54      base.AddItemEvents();
55      Engine.Initialized += new EventHandler(Engine_Initialized);
56      Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
57      Engine.ExecutionTimeChanged += new EventHandler(Engine_ExecutionTimeChanged);
58      Engine.Finished += new EventHandler(Engine_Finished);
59      operatorGraphView.OperatorGraph = Engine.OperatorGraph;
60      scopeView.Scope = Engine.GlobalScope;
61    }
62
63    protected override void UpdateControls() {
64      base.UpdateControls();
65      abortButton.Enabled = false;
66      if (Engine == null) {
67        executeButton.Enabled = false;
68        resetButton.Enabled = false;
69        executionTimeTextBox.Enabled = false;
70      } else {
71        executeButton.Enabled = true;
72        resetButton.Enabled = true;
73        executionTimeCounter = 0;
74        executionTimeTextBox.Text = Engine.ExecutionTime.ToString();
75        executionTimeTextBox.Enabled = true;
76      }
77    }
78
79    #region Engine Events
80    private void Engine_Initialized(object sender, EventArgs e) {
81      Refresh();
82    }
83    private delegate void OnExceptionEventDelegate(object sender, ExceptionEventArgs e);
84    private void Engine_ExceptionOccurred(object sender, ExceptionEventArgs e) {
85      if (InvokeRequired)
86        Invoke(new OnExceptionEventDelegate(Engine_ExceptionOccurred), sender, e);
87      else
88        Auxiliary.ShowErrorMessageBox(e.Exception);
89    }
90    private void Engine_ExecutionTimeChanged(object sender, EventArgs e) {
91      executionTimeCounter++;
92      if (executionTimeCounter == 1000)
93        UpdateExecutionTimeTextBox();
94    }
95    private void Engine_Finished(object sender, EventArgs e) {
96      UpdateExecutionTimeTextBox();
97      if (globalScopeGroupBox.Controls.Count > 0) {
98        ScopeView scopeEditor = (ScopeView)globalScopeGroupBox.Controls[0];
99        if (!scopeEditor.AutomaticUpdating)
100          scopeEditor.Refresh();
101      }
102      EnableDisableControls();
103    }
104    private void UpdateExecutionTimeTextBox() {
105      if (InvokeRequired)
106        Invoke(new MethodInvoker(UpdateExecutionTimeTextBox));
107      else {
108        executionTimeCounter = 0;
109        executionTimeTextBox.Text = Engine.ExecutionTime.ToString();
110      }
111    }
112    private void EnableDisableControls() {
113      if (InvokeRequired)
114        Invoke(new MethodInvoker(EnableDisableControls));
115      else {
116        executeButton.Enabled = true;
117        abortButton.Enabled = false;
118        resetButton.Enabled = true;
119        operatorGraphGroupBox.Enabled = true;
120        globalScopeGroupBox.Enabled = true;
121      }
122    }
123    #endregion
124
125    #region Button events
126    private void executeButton_Click(object sender, EventArgs e) {
127      executeButton.Enabled = false;
128      abortButton.Enabled = true;
129      resetButton.Enabled = false;
130      operatorGraphGroupBox.Enabled = false;
131      globalScopeGroupBox.Enabled = false;
132      Engine.Execute();
133    }
134    private void abortButton_Click(object sender, EventArgs e) {
135      Engine.Abort();
136    }
137    private void resetButton_Click(object sender, EventArgs e) {
138      Engine.Reset();
139      UpdateExecutionTimeTextBox();
140      if (globalScopeGroupBox.Controls.Count > 0) {
141        ScopeView scopeEditor = (ScopeView)globalScopeGroupBox.Controls[0];
142        if (!scopeEditor.AutomaticUpdating)
143          scopeEditor.Refresh();
144      }
145    }
146    #endregion
147  }
148}
Note: See TracBrowser for help on using the repository browser.