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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Text;
|
---|
28 | using System.Windows.Forms;
|
---|
29 | using HeuristicLab.Core;
|
---|
30 | using HeuristicLab.Common;
|
---|
31 | using HeuristicLab.MainForm;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Core.Views {
|
---|
34 | /// <summary>
|
---|
35 | /// Base class for editors of engines.
|
---|
36 | /// </summary>
|
---|
37 | [Content(typeof(Engine), true)]
|
---|
38 | [Content(typeof(IEngine), false)]
|
---|
39 | public partial class EngineView : ItemView {
|
---|
40 | private int executionTimeCounter;
|
---|
41 |
|
---|
42 | /// <summary>
|
---|
43 | /// Gets or sets the current engine.
|
---|
44 | /// </summary>
|
---|
45 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
46 | public new IEngine Content {
|
---|
47 | get { return (IEngine)base.Content; }
|
---|
48 | set { base.Content = value; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | /// <summary>
|
---|
52 | /// Initializes a new instance of <see cref="EngineBaseEditor"/>.
|
---|
53 | /// </summary>
|
---|
54 | public EngineView() {
|
---|
55 | InitializeComponent();
|
---|
56 | }
|
---|
57 | public EngineView(IEngine content)
|
---|
58 | : this() {
|
---|
59 | Content = content;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /// <summary>
|
---|
63 | /// Removes the event handlers from the underlying <see cref="IEngine"/>.
|
---|
64 | /// </summary>
|
---|
65 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
66 | protected override void DeregisterContentEvents() {
|
---|
67 | Content.OperatorGraphChanged -= new EventHandler(Content_OperatorGraphChanged);
|
---|
68 | Content.Initialized -= new EventHandler(Content_Initialized);
|
---|
69 | Content.Started -= new EventHandler(Content_Started);
|
---|
70 | Content.Stopped -= new EventHandler(Content_Stopped);
|
---|
71 | Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
|
---|
72 | Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
73 | base.DeregisterContentEvents();
|
---|
74 | }
|
---|
75 |
|
---|
76 | /// <summary>
|
---|
77 | /// Adds event handlers to the underlying <see cref="IEngine"/>.
|
---|
78 | /// </summary>
|
---|
79 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
80 | protected override void RegisterContentEvents() {
|
---|
81 | base.RegisterContentEvents();
|
---|
82 | Content.OperatorGraphChanged += new EventHandler(Content_OperatorGraphChanged);
|
---|
83 | Content.Initialized += new EventHandler(Content_Initialized);
|
---|
84 | Content.Started += new EventHandler(Content_Started);
|
---|
85 | Content.Stopped += new EventHandler(Content_Stopped);
|
---|
86 | Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
|
---|
87 | Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
|
---|
88 | }
|
---|
89 |
|
---|
90 | /// <summary>
|
---|
91 | /// Updates all controls with the latest data of the model.
|
---|
92 | /// </summary>
|
---|
93 | /// <remarks>Calls <see cref="EditorBase.UpdateControls"/> of base class <see cref="EditorBase"/>.</remarks>
|
---|
94 | protected override void OnContentChanged() {
|
---|
95 | base.OnContentChanged();
|
---|
96 | stopButton.Enabled = false;
|
---|
97 | if (Content == null) {
|
---|
98 | operatorGraphView.Enabled = false;
|
---|
99 | scopeView.Enabled = false;
|
---|
100 | startButton.Enabled = false;
|
---|
101 | resetButton.Enabled = false;
|
---|
102 | executionTimeTextBox.Enabled = false;
|
---|
103 | } else {
|
---|
104 | operatorGraphView.Content = Content.OperatorGraph;
|
---|
105 | scopeView.Content = Content.GlobalScope;
|
---|
106 | startButton.Enabled = !Content.Finished;
|
---|
107 | resetButton.Enabled = true;
|
---|
108 | UpdateExecutionTimeTextBox();
|
---|
109 | executionTimeTextBox.Enabled = true;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | #region Content Events
|
---|
114 | protected virtual void Content_OperatorGraphChanged(object sender, EventArgs e) {
|
---|
115 | if (InvokeRequired)
|
---|
116 | Invoke(new EventHandler(Content_OperatorGraphChanged), sender, e);
|
---|
117 | else
|
---|
118 | operatorGraphView.Content = Content.OperatorGraph;
|
---|
119 | }
|
---|
120 | protected virtual void Content_Initialized(object sender, EventArgs e) {
|
---|
121 | if (InvokeRequired)
|
---|
122 | Invoke(new EventHandler(Content_Initialized), sender, e);
|
---|
123 | else {
|
---|
124 | operatorGraphView.Enabled = true;
|
---|
125 | scopeView.Enabled = true;
|
---|
126 | startButton.Enabled = !Content.Finished;
|
---|
127 | stopButton.Enabled = false;
|
---|
128 | resetButton.Enabled = true;
|
---|
129 | UpdateExecutionTimeTextBox();
|
---|
130 | }
|
---|
131 | }
|
---|
132 | protected virtual void Content_Started(object sender, EventArgs e) {
|
---|
133 | executionTimeCounter = 0;
|
---|
134 | if (InvokeRequired)
|
---|
135 | Invoke(new EventHandler(Content_Started), sender, e);
|
---|
136 | else {
|
---|
137 | operatorGraphView.Enabled = false;
|
---|
138 | scopeView.Enabled = false;
|
---|
139 | startButton.Enabled = false;
|
---|
140 | stopButton.Enabled = true;
|
---|
141 | resetButton.Enabled = false;
|
---|
142 | UpdateExecutionTimeTextBox();
|
---|
143 | }
|
---|
144 | }
|
---|
145 | protected virtual void Content_Stopped(object sender, EventArgs e) {
|
---|
146 | if (InvokeRequired)
|
---|
147 | Invoke(new EventHandler(Content_Stopped), sender, e);
|
---|
148 | else {
|
---|
149 | operatorGraphView.Enabled = true;
|
---|
150 | scopeView.Enabled = true;
|
---|
151 | startButton.Enabled = !Content.Finished;
|
---|
152 | stopButton.Enabled = false;
|
---|
153 | resetButton.Enabled = true;
|
---|
154 | UpdateExecutionTimeTextBox();
|
---|
155 | }
|
---|
156 | }
|
---|
157 | protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
|
---|
158 | executionTimeCounter++;
|
---|
159 | if ((executionTimeCounter == 100) || !Content.Running) {
|
---|
160 | executionTimeCounter = 0;
|
---|
161 | UpdateExecutionTimeTextBox();
|
---|
162 | }
|
---|
163 | }
|
---|
164 | protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {
|
---|
165 | if (InvokeRequired)
|
---|
166 | Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
|
---|
167 | else
|
---|
168 | Auxiliary.ShowErrorMessageBox(e.Value);
|
---|
169 | }
|
---|
170 | #endregion
|
---|
171 |
|
---|
172 | #region Button events
|
---|
173 | protected virtual void startButton_Click(object sender, EventArgs e) {
|
---|
174 | Content.Start();
|
---|
175 | }
|
---|
176 | protected virtual void stopButton_Click(object sender, EventArgs e) {
|
---|
177 | Content.Stop();
|
---|
178 | }
|
---|
179 | protected virtual void resetButton_Click(object sender, EventArgs e) {
|
---|
180 | Content.Initialize();
|
---|
181 | }
|
---|
182 | #endregion
|
---|
183 |
|
---|
184 | #region Helpers
|
---|
185 | protected virtual void UpdateExecutionTimeTextBox() {
|
---|
186 | if (InvokeRequired)
|
---|
187 | Invoke(new Action(UpdateExecutionTimeTextBox));
|
---|
188 | else
|
---|
189 | executionTimeTextBox.Text = Content.ExecutionTime.ToString();
|
---|
190 | }
|
---|
191 | #endregion
|
---|
192 | }
|
---|
193 | }
|
---|