Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/10 05:04:31 (15 years ago)
Author:
swagner
Message:

Committing first results of the refactoring of HeuristicLab.Core and related plugins (#95)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineBaseView.cs

    r2546 r2655  
    4343    /// </summary>
    4444    /// <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; }
    4747      set { base.Item = value; }
    4848    }
     
    5454      InitializeComponent();
    5555    }
     56    public EngineBaseView(EngineBase engine)
     57      : this() {
     58      Engine = engine;
     59    }
    5660
    5761    /// <summary>
     
    5963    /// </summary>
    6064    /// <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);
    6267      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);
    6371      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();
    6973    }
     74
    7075    /// <summary>
    7176    /// Adds event handlers to the underlying <see cref="IEngine"/>.
    7277    /// </summary>
    7378    /// <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);
    7682      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);
    7786      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;
    8287    }
    8388
     
    8691    /// </summary>
    8792    /// <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;
    9196      if (Engine == null) {
    92         executeButton.Enabled = false;
     97        operatorGraphView.Enabled = false;
     98        scopeView.Enabled = false;
     99        startButton.Enabled = false;
    93100        resetButton.Enabled = false;
    94101        executionTimeTextBox.Enabled = false;
    95102      } else {
    96         executeButton.Enabled = true;
     103        operatorGraphView.OperatorGraph = Engine.OperatorGraph;
     104        scopeView.Scope = Engine.GlobalScope;
     105        startButton.Enabled = !Engine.Finished;
    97106        resetButton.Enabled = true;
    98         executionTimeCounter = 0;
    99107        executionTimeTextBox.Text = Engine.ExecutionTime.ToString();
    100108        executionTimeTextBox.Enabled = true;
     
    103111
    104112    #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    }
    105119    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      }
    107130    }
    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;
    110133      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      }
    114155    }
    115156    private void Engine_ExecutionTimeChanged(object sender, EventArgs e) {
    116157      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) {
    133159        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();
    135164      }
    136165    }
    137     private void EnableDisableControls() {
     166    private void Engine_ExceptionOccurred(object sender, EventArgs<Exception> e) {
    138167      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);
    147171    }
    148172    #endregion
    149173
    150174    #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();
    158177    }
    159     private void abortButton_Click(object sender, EventArgs e) {
    160       Engine.Abort();
     178    private void stopButton_Click(object sender, EventArgs e) {
     179      Engine.Stop();
    161180    }
    162181    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();
    170183    }
    171184    #endregion
Note: See TracChangeset for help on using the changeset viewer.