Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2845


Ignore:
Timestamp:
02/20/10 20:04:08 (15 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameterized items
Location:
trunk/sources
Files:
5 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Common/3.2/EventArgs.cs

    r2790 r2845  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    2623
    2724namespace HeuristicLab.Common {
  • trunk/sources/HeuristicLab.Core.Views/3.3/HeuristicLab.Core.Views-3.3.csproj

    r2834 r2845  
    7070  <ItemGroup>
    7171    <None Include="HeuristicLabCoreViewsPlugin.cs.frame" />
     72    <Compile Include="OperatorTreeView.cs">
     73      <SubType>UserControl</SubType>
     74    </Compile>
     75    <Compile Include="OperatorTreeView.Designer.cs">
     76      <DependentUpon>OperatorTreeView.cs</DependentUpon>
     77    </Compile>
     78    <Compile Include="ParameterizedNamedItemView.cs">
     79      <SubType>UserControl</SubType>
     80    </Compile>
     81    <Compile Include="ParameterizedNamedItemView.Designer.cs">
     82      <DependentUpon>ParameterizedNamedItemView.cs</DependentUpon>
     83    </Compile>
    7284    <Compile Include="ValueParameterCollectionView.cs">
    7385      <SubType>UserControl</SubType>
     
    124136    <Compile Include="OperatorsSidebar.Designer.cs">
    125137      <DependentUpon>OperatorsSidebar.cs</DependentUpon>
    126     </Compile>
    127     <Compile Include="OperatorTreeView.cs">
    128       <SubType>UserControl</SubType>
    129     </Compile>
    130     <Compile Include="OperatorTreeView.Designer.cs">
    131       <DependentUpon>OperatorTreeView.cs</DependentUpon>
    132138    </Compile>
    133139    <Compile Include="TypeSelectorDialog.cs">
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2834 r2845  
    104104    <Compile Include="ChangedEventArgs.cs" />
    105105    <None Include="HeuristicLabCorePlugin.cs.frame" />
     106    <Compile Include="Interfaces\IParameterizedNamedItem.cs" />
    106107    <Compile Include="Interfaces\IParameterizedItem.cs" />
    107108    <Compile Include="Interfaces\IAtomicOperation.cs" />
     
    109110    <Compile Include="Interfaces\IOperation.cs" />
    110111    <Compile Include="OperationCollection.cs" />
     112    <Compile Include="ParameterizedNamedItem.cs" />
    111113    <Compile Include="ValueParameterCollection.cs" />
    112114    <Compile Include="Interfaces\IValueLookupParameter.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperator.cs

    r2834 r2845  
    2727  /// a basic instruction of an algorithm.
    2828  /// </summary>
    29   public interface IOperator : INamedItem, IParameterizedItem {
     29  public interface IOperator : IParameterizedNamedItem {
    3030    /// <summary>
    3131    /// Gets or sets a boolean value whether the engine should stop here during the run.
  • trunk/sources/HeuristicLab.Operators.Views/3.3/OperatorView.Designer.cs

    r2805 r2845  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.parameterCollectionView = new HeuristicLab.Core.Views.ParameterCollectionView();
     47      this.breakpointLabel = new System.Windows.Forms.Label();
     48      this.breakpointCheckBox = new System.Windows.Forms.CheckBox();
    4849      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4950      this.SuspendLayout();
     51      //
     52      // parameterCollectionView
     53      //
     54      this.parameterCollectionView.Location = new System.Drawing.Point(0, 139);
     55      this.parameterCollectionView.Size = new System.Drawing.Size(490, 214);
     56      this.parameterCollectionView.TabIndex = 6;
    5057      //
    5158      // nameTextBox
     
    5360      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    5461      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
    55       this.nameTextBox.Size = new System.Drawing.Size(418, 20);
    5662      //
    57       // descriptionTextBox
     63      // breakpointLabel
    5864      //
    59       this.descriptionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    60                   | System.Windows.Forms.AnchorStyles.Right)));
    61       this.descriptionTextBox.Size = new System.Drawing.Size(418, 87);
     65      this.breakpointLabel.AutoSize = true;
     66      this.breakpointLabel.Location = new System.Drawing.Point(3, 120);
     67      this.breakpointLabel.Name = "breakpointLabel";
     68      this.breakpointLabel.Size = new System.Drawing.Size(61, 13);
     69      this.breakpointLabel.TabIndex = 4;
     70      this.breakpointLabel.Text = "&Breakpoint:";
    6271      //
    63       // parameterCollectionView
     72      // breakpointCheckBox
    6473      //
    65       this.parameterCollectionView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    66                   | System.Windows.Forms.AnchorStyles.Left)
    67                   | System.Windows.Forms.AnchorStyles.Right)));
    68       this.parameterCollectionView.Caption = "ParameterCollection";
    69       this.parameterCollectionView.Location = new System.Drawing.Point(0, 119);
    70       this.parameterCollectionView.Name = "parameterCollectionView";
    71       this.parameterCollectionView.Size = new System.Drawing.Size(490, 234);
    72       this.parameterCollectionView.TabIndex = 4;
     74      this.breakpointCheckBox.AutoSize = true;
     75      this.breakpointCheckBox.Location = new System.Drawing.Point(72, 119);
     76      this.breakpointCheckBox.Name = "breakpointCheckBox";
     77      this.breakpointCheckBox.Size = new System.Drawing.Size(15, 14);
     78      this.breakpointCheckBox.TabIndex = 5;
     79      this.breakpointCheckBox.UseVisualStyleBackColor = true;
     80      this.breakpointCheckBox.CheckedChanged += new System.EventHandler(this.breakpointCheckBox_CheckedChanged);
    7381      //
    7482      // OperatorView
     
    7684      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    7785      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    78       this.Controls.Add(this.parameterCollectionView);
     86      this.Controls.Add(this.breakpointLabel);
     87      this.Controls.Add(this.breakpointCheckBox);
    7988      this.Name = "OperatorView";
    80       this.Size = new System.Drawing.Size(490, 353);
     89      this.Controls.SetChildIndex(this.breakpointCheckBox, 0);
     90      this.Controls.SetChildIndex(this.breakpointLabel, 0);
    8191      this.Controls.SetChildIndex(this.nameTextBox, 0);
    8292      this.Controls.SetChildIndex(this.nameLabel, 0);
     
    92102    #endregion
    93103
    94     protected HeuristicLab.Core.Views.ParameterCollectionView parameterCollectionView;
     104    private System.Windows.Forms.Label breakpointLabel;
     105    private System.Windows.Forms.CheckBox breakpointCheckBox;
    95106
    96107  }
  • trunk/sources/HeuristicLab.Operators.Views/3.3/OperatorView.cs

    r2805 r2845  
    2323using HeuristicLab.Core.Views;
    2424using HeuristicLab.MainForm;
     25using System;
    2526
    2627namespace HeuristicLab.Operators.Views {
     
    3031  [Content(typeof(Operator), true)]
    3132  [Content(typeof(IOperator), false)]
    32   public partial class OperatorView : NamedItemView {
     33  public partial class OperatorView : ParameterizedNamedItemView {
    3334    public new IOperator Content {
    3435      get { return (IOperator)base.Content; }
     
    5152    }
    5253
     54    /// <summary>
     55    /// Removes the eventhandlers from the underlying <see cref="IOperatorGraph"/>.
     56    /// </summary>
     57    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
     58    protected override void DeregisterContentEvents() {
     59      Content.BreakpointChanged -= new EventHandler(Content_BreakpointChanged);
     60      base.DeregisterContentEvents();
     61    }
     62
     63    /// <summary>
     64    /// Adds eventhandlers to the underlying <see cref="IOperatorGraph"/>.
     65    /// </summary>
     66    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
     67    protected override void RegisterContentEvents() {
     68      base.RegisterContentEvents();
     69      Content.BreakpointChanged += new EventHandler(Content_BreakpointChanged);
     70    }
     71
    5372    protected override void OnContentChanged() {
    5473      base.OnContentChanged();
    5574      if (Content == null) {
    56         parameterCollectionView.Content = null;
     75        breakpointCheckBox.Checked = false;
     76        breakpointCheckBox.Enabled = false;
    5777      } else {
    58         parameterCollectionView.Content = ((IOperator)Content).Parameters;
     78        breakpointCheckBox.Checked = Content.Breakpoint;
    5979      }
     80    }
     81
     82    private void Content_BreakpointChanged(object sender, EventArgs e) {
     83      if (InvokeRequired)
     84        Invoke(new EventHandler(Content_DescriptionChanged), sender, e);
     85      else
     86        breakpointCheckBox.Checked = Content.Breakpoint;
     87    }
     88
     89    private void breakpointCheckBox_CheckedChanged(object sender, System.EventArgs e) {
     90      if (Content != null) Content.Breakpoint = breakpointCheckBox.Checked;
    6091    }
    6192  }
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r2834 r2845  
    2222using System;
    2323using System.Drawing;
    24 using HeuristicLab.Collections;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3130  /// </summary>
    3231  [Item("Operator", "Base class for operators.")]
    33   public abstract class Operator : NamedItem, IOperator {
     32  public abstract class Operator : ParameterizedNamedItem, IOperator {
    3433    public override Image ItemImage {
    3534      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Method; }
     
    3736    public override bool CanChangeDescription {
    3837      get { return false; }
    39     }
    40 
    41     private ParameterCollection parameters;
    42     [Storable]
    43     protected ParameterCollection Parameters {
    44       get { return parameters;}
    45       private set {
    46         if (parameters != null) parameters.Changed -= new ChangedEventHandler(Parameters_Changed);
    47         parameters = value;
    48         readOnlyParameters = null;
    49         if (parameters != null) parameters.Changed += new ChangedEventHandler(Parameters_Changed);
    50       }
    51     }
    52     private ReadOnlyObservableKeyedCollection<string, IParameter> readOnlyParameters;
    53     IObservableKeyedCollection<string, IParameter> IParameterizedItem.Parameters {
    54       get {
    55         if (readOnlyParameters == null) readOnlyParameters = parameters.AsReadOnly();
    56         return readOnlyParameters;
    57       }
    5838    }
    5939
     
    10383    /// the canceled flag to <c>false</c> and the name of the operator to the type name.
    10484    /// </summary>
    105     protected Operator() {
    106       Name = ItemName;
    107       Parameters = new ParameterCollection();
    108       readOnlyParameters = null;
     85    protected Operator()
     86      : base() {
     87      canceled = false;
     88      breakpoint = false;
     89    }
     90    protected Operator(string name)
     91      : base(name) {
     92      canceled = false;
     93      breakpoint = false;
     94    }
     95    protected Operator(string name, ParameterCollection parameters)
     96      : base(name, parameters) {
     97      canceled = false;
     98      breakpoint = false;
     99    }
     100    protected Operator(string name, string description)
     101      : base(name, description) {
     102      canceled = false;
     103      breakpoint = false;
     104    }
     105    protected Operator(string name, string description, ParameterCollection parameters)
     106      : base(name, description, parameters) {
    109107      canceled = false;
    110108      breakpoint = false;
     
    119117    public override IDeepCloneable Clone(Cloner cloner) {
    120118      Operator clone = (Operator)base.Clone(cloner);
    121       clone.Parameters = (ParameterCollection)cloner.Clone(parameters);
    122119      clone.canceled = canceled;
    123120      clone.breakpoint = breakpoint;
     
    178175      }
    179176    }
    180 
    181     private void Parameters_Changed(object sender, ChangedEventArgs e) {
    182       OnChanged(e);
    183     }
    184177  }
    185178}
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r2834 r2845  
    5151  <ItemGroup>
    5252    <None Include="HeuristicLabOptimizationPlugin.cs.frame" />
     53    <Compile Include="IAlgorithm.cs" />
    5354    <Compile Include="HeuristicLabOptimizationPlugin.cs" />
    5455    <Compile Include="IProblem.cs" />
     
    6869      <Project>{0E27A536-1C4A-4624-A65E-DC4F4F23E3E1}</Project>
    6970      <Name>HeuristicLab.Common.Resources-3.2</Name>
     71    </ProjectReference>
     72    <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj">
     73      <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project>
     74      <Name>HeuristicLab.Common-3.2</Name>
    7075    </ProjectReference>
    7176    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLabOptimizationPlugin.cs.frame

    r2834 r2845  
    2929  [PluginFile("HeuristicLab.Optimization-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Collections", "3.3")]
     31  [PluginDependency("HeuristicLab.Common", "3.2")]
    3132  [PluginDependency("HeuristicLab.Common.Resources", "3.2")]
    3233  [PluginDependency("HeuristicLab.Core", "3.3")]
  • trunk/sources/HeuristicLab.Optimization/3.3/IProblem.cs

    r2834 r2845  
    2626  /// Interface to represent a problem.
    2727  /// </summary>
    28   public interface IProblem : INamedItem, IParameterizedItem { }
     28  public interface IProblem : IParameterizedNamedItem { }
    2929}
  • trunk/sources/HeuristicLab.Optimization/3.3/Problem.cs

    r2834 r2845  
    2121
    2222using System.Drawing;
    23 using HeuristicLab.Collections;
    2423using HeuristicLab.Core;
    25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2624
    2725namespace HeuristicLab.Optimization {
     
    3028  /// </summary>
    3129  [Item("Problem", "Base class for problems.")]
    32   public abstract class Problem : NamedItem, IProblem {
     30  public abstract class Problem : ParameterizedNamedItem, IProblem {
    3331    public override Image ItemImage {
    3432      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Type; }
    3533    }
    3634
    37     private ParameterCollection parameters;
    38     [Storable]
    39     protected ParameterCollection Parameters {
    40       get { return parameters;}
    41       private set {
    42         if (parameters != null) parameters.Changed -= new ChangedEventHandler(Parameters_Changed);
    43         parameters = value;
    44         readOnlyParameters = null;
    45         if (parameters != null) parameters.Changed += new ChangedEventHandler(Parameters_Changed);
    46       }
    47     }
    48     private ReadOnlyObservableKeyedCollection<string, IParameter> readOnlyParameters;
    49     IObservableKeyedCollection<string, IParameter> IParameterizedItem.Parameters {
    50       get {
    51         if (readOnlyParameters == null) readOnlyParameters = parameters.AsReadOnly();
    52         return readOnlyParameters;
    53       }
    54     }
    55 
    56     protected Problem() {
    57       Name = ItemName;
    58       Parameters = new ParameterCollection();
    59       readOnlyParameters = null;
    60     }
    61 
    62     public override IDeepCloneable Clone(Cloner cloner) {
    63       Problem clone = (Problem)base.Clone(cloner);
    64       clone.Parameters = (ParameterCollection)cloner.Clone(parameters);
    65       return clone;
    66     }
    67 
    68     private void Parameters_Changed(object sender, ChangedEventArgs e) {
    69       OnChanged(e);
    70     }
     35    protected Problem() : base() { }
     36    protected Problem(string name) : base(name) { }
     37    protected Problem(string name, ParameterCollection parameters) : base(name, parameters) { }
     38    protected Problem(string name, string description) : base(name, description) { }
     39    protected Problem(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { }
    7140  }
    7241}
Note: See TracChangeset for help on using the changeset viewer.