Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/03/10 03:14:37 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on engines and algorithms
Location:
trunk/sources/HeuristicLab.Core.Views/3.3
Files:
5 edited

Legend:

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

    r2818 r2916  
    5555    /// <param name="ex">The exception to format.</param>
    5656    /// <returns>The formated message.</returns>
    57     private static string BuildErrorMessage(Exception ex) {
     57    public static string BuildErrorMessage(Exception ex) {
     58      string nl = Environment.NewLine;
    5859      StringBuilder sb = new StringBuilder();
    59       sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     60      sb.Append("Sorry, but something went wrong!" + nl + ex.Message + nl + ex.StackTrace);
    6061
    6162      while (ex.InnerException != null) {
    6263        ex = ex.InnerException;
    63         sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
     64        sb.Append(nl + "-----" + nl + ex.Message + nl + ex.StackTrace);
    6465      }
    6566      return sb.ToString();
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.Designer.cs

    r2834 r2916  
    3333    protected override void Dispose(bool disposing) {
    3434      if (disposing) {
    35         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    3635        if (components != null) components.Dispose();
    3736      }
     
    4948      this.executionTimeTextBox = new System.Windows.Forms.TextBox();
    5049      this.executionTimeLabel = new System.Windows.Forms.Label();
    51       this.scopeView = new HeuristicLab.Core.Views.ScopeView();
    52       this.resetButton = new System.Windows.Forms.Button();
    5350      this.stopButton = new System.Windows.Forms.Button();
    5451      this.startButton = new System.Windows.Forms.Button();
    5552      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    56       this.newOperatorGraphButton = new System.Windows.Forms.Button();
    57       this.openOperatorGraphButton = new System.Windows.Forms.Button();
    58       this.saveOperatorGraphButton = new System.Windows.Forms.Button();
    59       this.tabControl = new System.Windows.Forms.TabControl();
    60       this.operatorGraphTabPage = new System.Windows.Forms.TabPage();
    61       this.operatorGraphViewHost = new HeuristicLab.Core.Views.ViewHost();
    62       this.globalScopeTabPage = new System.Windows.Forms.TabPage();
    63       this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
    64       this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
    65       this.tabControl.SuspendLayout();
    66       this.operatorGraphTabPage.SuspendLayout();
    67       this.globalScopeTabPage.SuspendLayout();
     53      this.logTextBox = new System.Windows.Forms.TextBox();
    6854      this.SuspendLayout();
    6955      //
     
    8672      this.executionTimeLabel.TabIndex = 4;
    8773      this.executionTimeLabel.Text = "&Execution Time:";
    88       //
    89       // scopeView
    90       //
    91       this.scopeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    92                   | System.Windows.Forms.AnchorStyles.Left)
    93                   | System.Windows.Forms.AnchorStyles.Right)));
    94       this.scopeView.Caption = "Scope";
    95       this.scopeView.Content = null;
    96       this.scopeView.Location = new System.Drawing.Point(6, 6);
    97       this.scopeView.Name = "scopeView";
    98       this.scopeView.Size = new System.Drawing.Size(782, 572);
    99       this.scopeView.TabIndex = 0;
    100       //
    101       // resetButton
    102       //
    103       this.resetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    104       this.resetButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Restart;
    105       this.resetButton.Location = new System.Drawing.Point(60, 616);
    106       this.resetButton.Name = "resetButton";
    107       this.resetButton.Size = new System.Drawing.Size(24, 24);
    108       this.resetButton.TabIndex = 3;
    109       this.toolTip.SetToolTip(this.resetButton, "Reset Engine");
    110       this.resetButton.UseVisualStyleBackColor = true;
    111       this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
    11274      //
    11375      // stopButton
     
    13698      this.startButton.Click += new System.EventHandler(this.startButton_Click);
    13799      //
    138       // newOperatorGraphButton
     100      // logTextBox
    139101      //
    140       this.newOperatorGraphButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.NewDocument;
    141       this.newOperatorGraphButton.Location = new System.Drawing.Point(6, 6);
    142       this.newOperatorGraphButton.Name = "newOperatorGraphButton";
    143       this.newOperatorGraphButton.Size = new System.Drawing.Size(24, 24);
    144       this.newOperatorGraphButton.TabIndex = 0;
    145       this.toolTip.SetToolTip(this.newOperatorGraphButton, "Create New Operator Graph");
    146       this.newOperatorGraphButton.UseVisualStyleBackColor = true;
    147       this.newOperatorGraphButton.Click += new System.EventHandler(this.newOperatorGraphButton_Click);
    148       //
    149       // openOperatorGraphButton
    150       //
    151       this.openOperatorGraphButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Open;
    152       this.openOperatorGraphButton.Location = new System.Drawing.Point(36, 6);
    153       this.openOperatorGraphButton.Name = "openOperatorGraphButton";
    154       this.openOperatorGraphButton.Size = new System.Drawing.Size(24, 24);
    155       this.openOperatorGraphButton.TabIndex = 1;
    156       this.toolTip.SetToolTip(this.openOperatorGraphButton, "Open Operator Graph");
    157       this.openOperatorGraphButton.UseVisualStyleBackColor = true;
    158       this.openOperatorGraphButton.Click += new System.EventHandler(this.openOperatorGraphButton_Click);
    159       //
    160       // saveOperatorGraphButton
    161       //
    162       this.saveOperatorGraphButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Save;
    163       this.saveOperatorGraphButton.Location = new System.Drawing.Point(66, 6);
    164       this.saveOperatorGraphButton.Name = "saveOperatorGraphButton";
    165       this.saveOperatorGraphButton.Size = new System.Drawing.Size(24, 24);
    166       this.saveOperatorGraphButton.TabIndex = 2;
    167       this.toolTip.SetToolTip(this.saveOperatorGraphButton, "Save Operator Graph");
    168       this.saveOperatorGraphButton.UseVisualStyleBackColor = true;
    169       this.saveOperatorGraphButton.Click += new System.EventHandler(this.saveOperatorGraphButton_Click);
    170       //
    171       // tabControl
    172       //
    173       this.tabControl.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     102      this.logTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    174103                  | System.Windows.Forms.AnchorStyles.Left)
    175104                  | System.Windows.Forms.AnchorStyles.Right)));
    176       this.tabControl.Controls.Add(this.operatorGraphTabPage);
    177       this.tabControl.Controls.Add(this.globalScopeTabPage);
    178       this.tabControl.Location = new System.Drawing.Point(0, 0);
    179       this.tabControl.Name = "tabControl";
    180       this.tabControl.SelectedIndex = 0;
    181       this.tabControl.Size = new System.Drawing.Size(802, 610);
    182       this.tabControl.TabIndex = 3;
    183       //
    184       // operatorGraphTabPage
    185       //
    186       this.operatorGraphTabPage.Controls.Add(this.operatorGraphViewHost);
    187       this.operatorGraphTabPage.Controls.Add(this.saveOperatorGraphButton);
    188       this.operatorGraphTabPage.Controls.Add(this.openOperatorGraphButton);
    189       this.operatorGraphTabPage.Controls.Add(this.newOperatorGraphButton);
    190       this.operatorGraphTabPage.Location = new System.Drawing.Point(4, 22);
    191       this.operatorGraphTabPage.Name = "operatorGraphTabPage";
    192       this.operatorGraphTabPage.Padding = new System.Windows.Forms.Padding(3);
    193       this.operatorGraphTabPage.Size = new System.Drawing.Size(794, 584);
    194       this.operatorGraphTabPage.TabIndex = 0;
    195       this.operatorGraphTabPage.Text = "Operator Graph";
    196       this.operatorGraphTabPage.UseVisualStyleBackColor = true;
    197       //
    198       // operatorGraphViewHost
    199       //
    200       this.operatorGraphViewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    201                   | System.Windows.Forms.AnchorStyles.Left)
    202                   | System.Windows.Forms.AnchorStyles.Right)));
    203       this.operatorGraphViewHost.Content = null;
    204       this.operatorGraphViewHost.Location = new System.Drawing.Point(6, 36);
    205       this.operatorGraphViewHost.Name = "operatorGraphViewHost";
    206       this.operatorGraphViewHost.Size = new System.Drawing.Size(782, 542);
    207       this.operatorGraphViewHost.TabIndex = 3;
    208       this.operatorGraphViewHost.ViewType = null;
    209       //
    210       // globalScopeTabPage
    211       //
    212       this.globalScopeTabPage.Controls.Add(this.scopeView);
    213       this.globalScopeTabPage.Location = new System.Drawing.Point(4, 22);
    214       this.globalScopeTabPage.Name = "globalScopeTabPage";
    215       this.globalScopeTabPage.Padding = new System.Windows.Forms.Padding(3);
    216       this.globalScopeTabPage.Size = new System.Drawing.Size(794, 584);
    217       this.globalScopeTabPage.TabIndex = 1;
    218       this.globalScopeTabPage.Text = "Global Scope";
    219       this.globalScopeTabPage.UseVisualStyleBackColor = true;
    220       //
    221       // openFileDialog
    222       //
    223       this.openFileDialog.DefaultExt = "hl";
    224       this.openFileDialog.FileName = "Item";
    225       this.openFileDialog.Filter = "HeuristicLab Files|*.hl|All Files|*.*";
    226       this.openFileDialog.Title = "Open File";
    227       //
    228       // saveFileDialog
    229       //
    230       this.saveFileDialog.DefaultExt = "hl";
    231       this.saveFileDialog.FileName = "Item";
    232       this.saveFileDialog.Filter = "Uncompressed HeuristicLab Files|*.hl|HeuristicLab Files|*.hl|All Files|*.*";
    233       this.saveFileDialog.FilterIndex = 2;
    234       this.saveFileDialog.Title = "Save File";
     105      this.logTextBox.Location = new System.Drawing.Point(0, 0);
     106      this.logTextBox.Multiline = true;
     107      this.logTextBox.Name = "logTextBox";
     108      this.logTextBox.ReadOnly = true;
     109      this.logTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
     110      this.logTextBox.Size = new System.Drawing.Size(802, 610);
     111      this.logTextBox.TabIndex = 6;
     112      this.logTextBox.WordWrap = false;
    235113      //
    236114      // EngineView
     
    238116      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    239117      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    240       this.Controls.Add(this.tabControl);
     118      this.Controls.Add(this.logTextBox);
    241119      this.Controls.Add(this.executionTimeTextBox);
    242120      this.Controls.Add(this.stopButton);
    243121      this.Controls.Add(this.executionTimeLabel);
    244       this.Controls.Add(this.resetButton);
    245122      this.Controls.Add(this.startButton);
    246123      this.Name = "EngineView";
    247124      this.Size = new System.Drawing.Size(802, 640);
    248       this.tabControl.ResumeLayout(false);
    249       this.operatorGraphTabPage.ResumeLayout(false);
    250       this.globalScopeTabPage.ResumeLayout(false);
    251125      this.ResumeLayout(false);
    252126      this.PerformLayout();
     
    258132    protected System.Windows.Forms.TextBox executionTimeTextBox;
    259133    protected System.Windows.Forms.Label executionTimeLabel;
    260     protected System.Windows.Forms.Button resetButton;
    261134    protected System.Windows.Forms.Button stopButton;
    262135    protected System.Windows.Forms.Button startButton;
    263     protected HeuristicLab.Core.Views.ScopeView scopeView;
    264136    protected System.Windows.Forms.ToolTip toolTip;
    265     protected System.Windows.Forms.TabControl tabControl;
    266     protected System.Windows.Forms.TabPage globalScopeTabPage;
    267     protected System.Windows.Forms.OpenFileDialog openFileDialog;
    268     protected System.Windows.Forms.SaveFileDialog saveFileDialog;
    269     protected System.Windows.Forms.TabPage operatorGraphTabPage;
    270     protected System.Windows.Forms.Button saveOperatorGraphButton;
    271     protected System.Windows.Forms.Button openOperatorGraphButton;
    272     protected System.Windows.Forms.Button newOperatorGraphButton;
    273     protected ViewHost operatorGraphViewHost;
     137    protected System.Windows.Forms.TextBox logTextBox;
    274138
    275139  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs

    r2834 r2916  
    2121
    2222using System;
    23 using System.Windows.Forms;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.MainForm;
    26 using HeuristicLab.Persistence.Default.Xml;
    2725
    2826namespace HeuristicLab.Core.Views {
     
    3331  [Content(typeof(IEngine), false)]
    3432  public partial class EngineView : ItemView {
    35     protected TypeSelectorDialog typeSelectorDialog;
    3633    private int executionTimeCounter;
    3734
     
    6158    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
    6259    protected override void DeregisterContentEvents() {
    63       Content.OperatorGraphChanged -= new EventHandler(Content_OperatorGraphChanged);
    6460      Content.Prepared -= new EventHandler(Content_Prepared);
    6561      Content.Started -= new EventHandler(Content_Started);
     
    7672    protected override void RegisterContentEvents() {
    7773      base.RegisterContentEvents();
    78       Content.OperatorGraphChanged += new EventHandler(Content_OperatorGraphChanged);
    7974      Content.Prepared += new EventHandler(Content_Prepared);
    8075      Content.Started += new EventHandler(Content_Started);
     
    9186      base.OnContentChanged();
    9287      stopButton.Enabled = false;
     88      logTextBox.Clear();
    9389      if (Content == null) {
    94         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
    95         operatorGraphViewHost.Enabled = false;
    96         scopeView.Enabled = false;
    97         startButton.Enabled = resetButton.Enabled = false;
     90        logTextBox.Enabled = false;
     91        startButton.Enabled = false;
    9892        executionTimeTextBox.Enabled = false;
    9993      } else {
    100         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
    101         operatorGraphViewHost.Content = Content.OperatorGraph;
    102         operatorGraphViewHost.Enabled = true;
    103         scopeView.Content = Content.GlobalScope;
    104         scopeView.Enabled = true;
     94        logTextBox.Enabled = true;
    10595        startButton.Enabled = !Content.Finished;
    106         resetButton.Enabled = true;
    10796        UpdateExecutionTimeTextBox();
    10897        executionTimeTextBox.Enabled = true;
     
    111100
    112101    #region Content Events
    113     protected virtual void Content_OperatorGraphChanged(object sender, EventArgs e) {
    114       if (InvokeRequired)
    115         Invoke(new EventHandler(Content_OperatorGraphChanged), sender, e);
    116       else
    117         operatorGraphViewHost.Content = Content.OperatorGraph;
    118     }
    119102    protected virtual void Content_Prepared(object sender, EventArgs e) {
    120103      if (InvokeRequired)
    121104        Invoke(new EventHandler(Content_Prepared), sender, e);
    122105      else {
    123         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
    124         operatorGraphViewHost.Enabled = true;
    125         scopeView.Enabled = true;
    126106        startButton.Enabled = !Content.Finished;
    127107        stopButton.Enabled = false;
    128         resetButton.Enabled = true;
    129108        UpdateExecutionTimeTextBox();
     109        logTextBox.Clear();
     110        Log("Engine prepared");
    130111      }
    131112    }
     
    135116        Invoke(new EventHandler(Content_Started), sender, e);
    136117      else {
    137         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = false;
    138         operatorGraphViewHost.Enabled = false;
    139         scopeView.Enabled = false;
    140118        startButton.Enabled = false;
    141119        stopButton.Enabled = true;
    142         resetButton.Enabled = false;
    143120        UpdateExecutionTimeTextBox();
     121        Log("Engine started");
    144122      }
    145123    }
     
    148126        Invoke(new EventHandler(Content_Stopped), sender, e);
    149127      else {
    150         newOperatorGraphButton.Enabled = openOperatorGraphButton.Enabled = saveOperatorGraphButton.Enabled = true;
    151         operatorGraphViewHost.Enabled = true;
    152         scopeView.Enabled = true;
    153128        startButton.Enabled = !Content.Finished;
    154129        stopButton.Enabled = false;
    155         resetButton.Enabled = true;
    156130        UpdateExecutionTimeTextBox();
     131        if (Content.Finished) Log("Engine finished");
     132        else Log("Engine stopped");
    157133      }
    158134    }
     
    168144        Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);
    169145      else
    170         Auxiliary.ShowErrorMessageBox(e.Value);
     146        Log(Auxiliary.BuildErrorMessage(e.Value));
    171147    }
    172148    #endregion
    173149
    174150    #region Button events
    175     protected void newOperatorGraphButton_Click(object sender, EventArgs e) {
    176       Content.OperatorGraph = new OperatorGraph();
    177     }
    178     protected void openOperatorGraphButton_Click(object sender, EventArgs e) {
    179       openFileDialog.Title = "Open Operator Graph";
    180       if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
    181         OperatorGraph operatorGraph = null;
    182         try {
    183           operatorGraph = XmlParser.Deserialize(openFileDialog.FileName) as OperatorGraph;
    184         }
    185         catch (Exception ex) {
    186           Auxiliary.ShowErrorMessageBox(ex);
    187         }
    188         if (operatorGraph == null)
    189           MessageBox.Show(this, "Selected file does not contain an operator graph.", "Invalid File", MessageBoxButtons.OK, MessageBoxIcon.Error);
    190         else
    191           Content.OperatorGraph = operatorGraph;
    192       }
    193     }
    194     protected void saveOperatorGraphButton_Click(object sender, EventArgs e) {
    195       saveFileDialog.Title = "Save Operator Graph";
    196       if (saveFileDialog.ShowDialog(this) == DialogResult.OK) {
    197         try {
    198           if (saveFileDialog.FilterIndex == 1)
    199             XmlGenerator.Serialize(Content.OperatorGraph, saveFileDialog.FileName, 0);
    200           else
    201             XmlGenerator.Serialize(Content.OperatorGraph, saveFileDialog.FileName, 9);
    202         }
    203         catch (Exception ex) {
    204           Auxiliary.ShowErrorMessageBox(ex);
    205         }
    206       }
    207     }
    208151    protected virtual void startButton_Click(object sender, EventArgs e) {
    209152      Content.Start();
     
    211154    protected virtual void stopButton_Click(object sender, EventArgs e) {
    212155      Content.Stop();
    213     }
    214     protected virtual void resetButton_Click(object sender, EventArgs e) {
    215       Content.Prepare();
    216156    }
    217157    #endregion
     
    224164        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    225165    }
     166    protected virtual void Log(string message) {
     167      if (InvokeRequired)
     168        Invoke(new Action<string>(Log), message);
     169      else {
     170        message = DateTime.Now.ToString() + "\t" + message;
     171        string[] newLines = message.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
     172        string[] lines = new string[logTextBox.Lines.Length + newLines.Length];
     173        logTextBox.Lines.CopyTo(lines, 0);
     174        newLines.CopyTo(lines, logTextBox.Lines.Length);
     175        logTextBox.Lines = lines;
     176      }
     177    }
    226178    #endregion
    227179  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/NamedItemView.cs

    r2870 r2916  
    9292
    9393    protected virtual void nameTextBox_Validating(object sender, CancelEventArgs e) {
    94       if (Content.CanChangeName) {
     94      if ((Content != null) && (Content.CanChangeName)) {
    9595        Content.Name = nameTextBox.Text;
    9696
  • trunk/sources/HeuristicLab.Core.Views/3.3/ViewHost.Designer.cs

    r2841 r2916  
    8282      this.viewsLabel.Size = new System.Drawing.Size(16, 16);
    8383      this.viewsLabel.TabIndex = 0;
    84       this.toolTip.SetToolTip(this.viewsLabel, "Double-click to open a new window of the current view.\r\nRight-click to change current view.");
     84      this.toolTip.SetToolTip(this.viewsLabel, "Double-click to open a new window of the current view." + System.Environment.NewLine + "Right-click to change current view.");
    8585      this.viewsLabel.DoubleClick += new System.EventHandler(this.viewsLabel_DoubleClick);
    8686      //
Note: See TracChangeset for help on using the changeset viewer.