Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2740


Ignore:
Timestamp:
02/03/10 04:43:06 (14 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
Location:
trunk/sources
Files:
7 added
6 deleted
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IOperatorParameter.cs

    r2715 r2740  
    2727namespace HeuristicLab.Core {
    2828  public interface IOperatorParameter : IParameter {
    29     string ActualName { get; set; }
    3029    IOperator Value { get; set; }
    3130
    32     event EventHandler ActualNameChanged;
    3331    event EventHandler ValueChanged;
    3432  }
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IParameter.cs

    r2687 r2740  
    2929  public interface IParameter : INamedItem {
    3030    Type DataType { get; }
    31 
    32     IItem GetValue(ExecutionContext context);
     31    ExecutionContext ExecutionContext { get; set; }
    3332  }
    3433}
  • trunk/sources/HeuristicLab.Operators/3.3/CombinedOperator.cs

    r2727 r2740  
    3636  [Item("CombinedOperator", "An operator which contains an operator graph.")]
    3737  [Creatable("Test")]
    38   public sealed class CombinedOperator : StandardOperator, IOperator {
     38  public sealed class CombinedOperator : SingleSuccessorOperator, IOperator {
    3939    public override Image ItemImage {
    4040      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Module; }
     
    6868    }
    6969
    70     public override ExecutionContextCollection Apply(ExecutionContext context) {
    71       ExecutionContextCollection next = base.Apply(context);
     70    public override ExecutionContextCollection Apply() {
     71      ExecutionContextCollection next = base.Apply();
    7272      if (operatorGraph.InitialOperator != null)
    73         next.Insert(0, new ExecutionContext(context, operatorGraph.InitialOperator, context.Scope));
     73        next.Insert(0, new ExecutionContext(ExecutionContext, operatorGraph.InitialOperator, ExecutionContext.Scope));
    7474      return next;
    7575    }
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r2715 r2740  
    3535  [EmptyStorableClass]
    3636  [Creatable("Test")]
    37   public sealed class Counter : StandardOperator {
     37  public sealed class Counter : SingleSuccessorOperator {
    3838    public ItemParameter<IntData> Value {
    3939      get { return (ItemParameter<IntData>)Parameters["Value"]; }
     
    4949    }
    5050
    51     public override ExecutionContextCollection Apply(ExecutionContext context) {
    52       IntData value = (IntData)Value.GetValue(context);
    53       IntData increment = (IntData)Increment.GetValue(context);
     51    public override ExecutionContextCollection Apply() {
     52      IntData value = (IntData)Value.Value;
     53      IntData increment = (IntData)Increment.Value;
    5454      value.Value += increment.Value;
    55       return base.Apply(context);
     55      return base.Apply();
    5656    }
    5757  }
  • trunk/sources/HeuristicLab.Operators/3.3/EmptyOperator.cs

    r2684 r2740  
    3434  [Creatable("Test")]
    3535  [EmptyStorableClass]
    36   public sealed class EmptyOperator : StandardOperator {
     36  public sealed class EmptyOperator : SingleSuccessorOperator {
    3737    public EmptyOperator()
    3838      : base() {
  • trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r2714 r2740  
    8686  <ItemGroup>
    8787    <Compile Include="CombinedOperator.cs" />
     88    <Compile Include="MultipleSuccessorsOperator.cs" />
    8889    <Compile Include="Counter.cs" />
    8990    <Compile Include="EmptyOperator.cs">
     
    9495    <Compile Include="Properties\AssemblyInfo.cs" />
    9596    <Compile Include="SequentialProcessor.cs" />
    96     <Compile Include="StandardOperator.cs" />
     97    <Compile Include="SingleSuccessorOperator.cs" />
    9798  </ItemGroup>
    9899  <ItemGroup>
  • trunk/sources/HeuristicLab.Operators/3.3/Operator.cs

    r2684 r2740  
    8484    }
    8585
     86    [Storable]
     87    private ExecutionContext executionContext;
     88    protected ExecutionContext ExecutionContext {
     89      get { return executionContext; }
     90    }
     91
    8692    /// <summary>
    8793    /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and
     
    107113      clone.canceled = canceled;
    108114      clone.breakpoint = breakpoint;
     115      clone.executionContext = (ExecutionContext)cloner.Clone(executionContext);
    109116      return clone;
    110117    }
     
    112119    /// <inheritdoc/>
    113120    public virtual ExecutionContextCollection Execute(ExecutionContext context) {
    114       canceled = false;
    115       ExecutionContextCollection next = Apply(context);
    116       OnExecuted();
    117       return next;
     121      try {
     122        canceled = false;
     123        executionContext = context;
     124        foreach (IParameter param in Parameters)
     125          param.ExecutionContext = context;
     126        ExecutionContextCollection next = Apply();
     127        OnExecuted();
     128        return next;
     129      }
     130      finally {
     131        foreach (IParameter param in Parameters)
     132          param.ExecutionContext = null;
     133        context = null;
     134      }
    118135    }
    119136    /// <inheritdoc/>
     
    127144    /// <param name="scope">The scope where to execute the operator</param>
    128145    /// <returns><c>null</c>.</returns>
    129     public virtual ExecutionContextCollection Apply(ExecutionContext context) {
     146    public virtual ExecutionContextCollection Apply() {
    130147      return new ExecutionContextCollection();
    131148    }
  • trunk/sources/HeuristicLab.Operators/3.3/SequentialProcessor.cs

    r2684 r2740  
    3636  [Creatable("Test")]
    3737  [EmptyStorableClass]
    38   public sealed class SequentialProcessor : Operator, IOperator {
    39     public new ParameterCollection Parameters {
    40       get {
    41         return base.Parameters;
    42       }
    43     }
    44     IObservableKeyedCollection<string, IParameter> IOperator.Parameters {
    45       get { return Parameters; }
    46     }
    47 
     38  public sealed class SequentialProcessor : MultipleSuccessorsOperator {
    4839    public SequentialProcessor()
    4940      : base() {
    5041    }
    5142
    52     public override ExecutionContextCollection Apply(ExecutionContext context) {
     43    public override ExecutionContextCollection Apply() {
    5344      ExecutionContextCollection next = new ExecutionContextCollection();
    54       foreach (IParameter param in Parameters) {
    55         IOperatorParameter opParam = param as IOperatorParameter;
    56         if (opParam != null) {
    57           IOperator op = (IOperator)opParam.GetValue(context);
    58           if (op != null) next.Add(new ExecutionContext(context.Parent, op, context.Scope));
    59         }
    60       }
     45      for (int i = 0; i < Successors.Count; i++)
     46        next.Add(new ExecutionContext(ExecutionContext.Parent, Successors[i], ExecutionContext.Scope));
    6147      return next;
    6248    }
  • trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs

    r2739 r2740  
    3232  /// A base class for operators which have only one successor.
    3333  /// </summary>
    34   [Item("StandardOperator", "A base class for operators which have only one successor.")]
     34  [Item("SingleSuccessorOperator", "A base class for operators which have only one successor.")]
    3535  [Creatable("Test")]
    3636  [EmptyStorableClass]
    37   public abstract class StandardOperator : Operator {
    38     public OperatorParameter Successor {
     37  public abstract class SingleSuccessorOperator : Operator {
     38    protected OperatorParameter SuccessorParameter {
    3939      get { return (OperatorParameter)Parameters["Successor"]; }
    4040    }
    41 
    42     public StandardOperator()
    43       : base() {
    44       Parameters.Add(new OperatorParameter("Successor", "Operator which is executed next"));
     41    public IOperator Successor {
     42      get { return SuccessorParameter.Value; }
     43      set { SuccessorParameter.Value = value; }
    4544    }
    4645
    47     public override ExecutionContextCollection Apply(ExecutionContext context) {
    48       IOperator successor = (IOperator)Successor.GetValue(context);
    49       if (successor != null)
    50         return new ExecutionContextCollection(new ExecutionContext(context.Parent, successor, context.Scope));
     46    public SingleSuccessorOperator()
     47      : base() {
     48      Parameters.Add(new OperatorParameter("Successor", "Operator which is executed next."));
     49    }
     50
     51    public override ExecutionContextCollection Apply() {
     52      if (Successor != null)
     53        return new ExecutionContextCollection(new ExecutionContext(ExecutionContext.Parent, Successor, ExecutionContext.Scope));
    5154      else
    5255        return new ExecutionContextCollection();
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

    r2714 r2740  
    5151  </ItemGroup>
    5252  <ItemGroup>
     53    <Compile Include="SubScopesItemParameterView.cs">
     54      <SubType>UserControl</SubType>
     55    </Compile>
     56    <Compile Include="SubScopesItemParameterView.Designer.cs">
     57      <DependentUpon>SubScopesItemParameterView.cs</DependentUpon>
     58    </Compile>
     59    <Compile Include="OperatorParameterView.cs">
     60      <SubType>UserControl</SubType>
     61    </Compile>
     62    <Compile Include="OperatorParameterView.Designer.cs">
     63      <DependentUpon>OperatorParameterView.cs</DependentUpon>
     64    </Compile>
    5365    <Compile Include="HeuristicLabParametersViewsPlugin.cs" />
    5466    <Compile Include="ItemParameterView.cs">
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ItemParameterView.Designer.cs

    r2715 r2740  
    4747    private void InitializeComponent() {
    4848      this.components = new System.ComponentModel.Container();
    49       this.valueGroupBox = new System.Windows.Forms.GroupBox();
    50       this.valuePanel = new System.Windows.Forms.Panel();
     49      this.localValueGroupBox = new System.Windows.Forms.GroupBox();
     50      this.localValuePanel = new System.Windows.Forms.Panel();
    5151      this.viewHost = new HeuristicLab.Core.Views.ViewHost();
    52       this.clearValueButton = new System.Windows.Forms.Button();
    53       this.setValueButton = new System.Windows.Forms.Button();
     52      this.clearLocalValueButton = new System.Windows.Forms.Button();
     53      this.setLocalValueButton = new System.Windows.Forms.Button();
    5454      this.actualNameTextBox = new System.Windows.Forms.TextBox();
    5555      this.actualNameLabel = new System.Windows.Forms.Label();
    5656      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5757      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    58       this.valueGroupBox.SuspendLayout();
    59       this.valuePanel.SuspendLayout();
     58      this.localValueGroupBox.SuspendLayout();
     59      this.localValuePanel.SuspendLayout();
    6060      this.SuspendLayout();
    6161      //
     
    8989      this.descriptionTextBox.TabIndex = 5;
    9090      //
    91       // valueGroupBox
    92       //
    93       this.valueGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     91      // localValueGroupBox
     92      //
     93      this.localValueGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    9494                  | System.Windows.Forms.AnchorStyles.Left)
    9595                  | System.Windows.Forms.AnchorStyles.Right)));
    96       this.valueGroupBox.Controls.Add(this.valuePanel);
    97       this.valueGroupBox.Controls.Add(this.clearValueButton);
    98       this.valueGroupBox.Controls.Add(this.setValueButton);
    99       this.valueGroupBox.Location = new System.Drawing.Point(0, 146);
    100       this.valueGroupBox.Name = "valueGroupBox";
    101       this.valueGroupBox.Size = new System.Drawing.Size(386, 169);
    102       this.valueGroupBox.TabIndex = 10;
    103       this.valueGroupBox.TabStop = false;
    104       this.valueGroupBox.Text = "&Value:";
    105       //
    106       // valuePanel
    107       //
    108       this.valuePanel.AllowDrop = true;
    109       this.valuePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     96      this.localValueGroupBox.Controls.Add(this.localValuePanel);
     97      this.localValueGroupBox.Controls.Add(this.clearLocalValueButton);
     98      this.localValueGroupBox.Controls.Add(this.setLocalValueButton);
     99      this.localValueGroupBox.Location = new System.Drawing.Point(0, 146);
     100      this.localValueGroupBox.Name = "localValueGroupBox";
     101      this.localValueGroupBox.Size = new System.Drawing.Size(386, 169);
     102      this.localValueGroupBox.TabIndex = 10;
     103      this.localValueGroupBox.TabStop = false;
     104      this.localValueGroupBox.Text = "Local &Value:";
     105      //
     106      // localValuePanel
     107      //
     108      this.localValuePanel.AllowDrop = true;
     109      this.localValuePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    110110                  | System.Windows.Forms.AnchorStyles.Left)
    111111                  | System.Windows.Forms.AnchorStyles.Right)));
    112       this.valuePanel.Controls.Add(this.viewHost);
    113       this.valuePanel.Location = new System.Drawing.Point(6, 48);
    114       this.valuePanel.Name = "valuePanel";
    115       this.valuePanel.Size = new System.Drawing.Size(374, 115);
    116       this.valuePanel.TabIndex = 0;
    117       this.valuePanel.DragOver += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragEnterOver);
    118       this.valuePanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragDrop);
    119       this.valuePanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragEnterOver);
     112      this.localValuePanel.Controls.Add(this.viewHost);
     113      this.localValuePanel.Location = new System.Drawing.Point(6, 48);
     114      this.localValuePanel.Name = "localValuePanel";
     115      this.localValuePanel.Size = new System.Drawing.Size(374, 115);
     116      this.localValuePanel.TabIndex = 0;
     117      this.localValuePanel.DragOver += new System.Windows.Forms.DragEventHandler(this.localValuePanel_DragEnterOver);
     118      this.localValuePanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.localValuePanel_DragDrop);
     119      this.localValuePanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.localValuePanel_DragEnterOver);
    120120      //
    121121      // viewHost
    122122      //
     123      this.viewHost.Content = null;
    123124      this.viewHost.Dock = System.Windows.Forms.DockStyle.Fill;
    124125      this.viewHost.Location = new System.Drawing.Point(0, 0);
    125126      this.viewHost.Name = "viewHost";
    126       this.viewHost.Content = null;
    127127      this.viewHost.Size = new System.Drawing.Size(374, 115);
    128128      this.viewHost.TabIndex = 0;
    129129      //
    130       // clearValueButton
    131       //
    132       this.clearValueButton.Enabled = false;
    133       this.clearValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;
    134       this.clearValueButton.Location = new System.Drawing.Point(35, 19);
    135       this.clearValueButton.Name = "clearValueButton";
    136       this.clearValueButton.Size = new System.Drawing.Size(23, 23);
    137       this.clearValueButton.TabIndex = 9;
    138       this.toolTip.SetToolTip(this.clearValueButton, "Clear Value");
    139       this.clearValueButton.UseVisualStyleBackColor = true;
    140       this.clearValueButton.Click += new System.EventHandler(this.clearValueButton_Click);
    141       //
    142       // setValueButton
    143       //
    144       this.setValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;
    145       this.setValueButton.Location = new System.Drawing.Point(6, 19);
    146       this.setValueButton.Name = "setValueButton";
    147       this.setValueButton.Size = new System.Drawing.Size(23, 23);
    148       this.setValueButton.TabIndex = 8;
    149       this.toolTip.SetToolTip(this.setValueButton, "Set Value");
    150       this.setValueButton.UseVisualStyleBackColor = true;
    151       this.setValueButton.Click += new System.EventHandler(this.setValueButton_Click);
     130      // clearLocalValueButton
     131      //
     132      this.clearLocalValueButton.Enabled = false;
     133      this.clearLocalValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;
     134      this.clearLocalValueButton.Location = new System.Drawing.Point(35, 19);
     135      this.clearLocalValueButton.Name = "clearLocalValueButton";
     136      this.clearLocalValueButton.Size = new System.Drawing.Size(23, 23);
     137      this.clearLocalValueButton.TabIndex = 9;
     138      this.toolTip.SetToolTip(this.clearLocalValueButton, "Clear Value");
     139      this.clearLocalValueButton.UseVisualStyleBackColor = true;
     140      this.clearLocalValueButton.Click += new System.EventHandler(this.clearLocalValueButton_Click);
     141      //
     142      // setLocalValueButton
     143      //
     144      this.setLocalValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;
     145      this.setLocalValueButton.Location = new System.Drawing.Point(6, 19);
     146      this.setLocalValueButton.Name = "setLocalValueButton";
     147      this.setLocalValueButton.Size = new System.Drawing.Size(23, 23);
     148      this.setLocalValueButton.TabIndex = 8;
     149      this.toolTip.SetToolTip(this.setLocalValueButton, "Set Value");
     150      this.setLocalValueButton.UseVisualStyleBackColor = true;
     151      this.setLocalValueButton.Click += new System.EventHandler(this.setLocalValueButton_Click);
    152152      //
    153153      // actualNameTextBox
     
    174174      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    175175      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    176       this.Controls.Add(this.valueGroupBox);
     176      this.Controls.Add(this.localValueGroupBox);
    177177      this.Controls.Add(this.actualNameTextBox);
    178178      this.Controls.Add(this.actualNameLabel);
     
    187187      this.Controls.SetChildIndex(this.actualNameTextBox, 0);
    188188      this.Controls.SetChildIndex(this.nameLabel, 0);
    189       this.Controls.SetChildIndex(this.valueGroupBox, 0);
     189      this.Controls.SetChildIndex(this.localValueGroupBox, 0);
    190190      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    191       this.valueGroupBox.ResumeLayout(false);
    192       this.valuePanel.ResumeLayout(false);
     191      this.localValueGroupBox.ResumeLayout(false);
     192      this.localValuePanel.ResumeLayout(false);
    193193      this.ResumeLayout(false);
    194194      this.PerformLayout();
     
    198198    #endregion
    199199
    200     protected System.Windows.Forms.GroupBox valueGroupBox;
     200    protected System.Windows.Forms.GroupBox localValueGroupBox;
    201201    protected System.Windows.Forms.TextBox actualNameTextBox;
    202202    protected System.Windows.Forms.Label actualNameLabel;
    203     protected System.Windows.Forms.Panel valuePanel;
     203    protected System.Windows.Forms.Panel localValuePanel;
    204204    protected HeuristicLab.Core.Views.ViewHost viewHost;
    205     protected System.Windows.Forms.Button setValueButton;
     205    protected System.Windows.Forms.Button setLocalValueButton;
    206206    protected System.Windows.Forms.ToolTip toolTip;
    207     protected System.Windows.Forms.Button clearValueButton;
     207    protected System.Windows.Forms.Button clearLocalValueButton;
    208208  }
    209209}
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ItemParameterView.cs

    r2727 r2740  
    5454    public ItemParameterView() {
    5555      InitializeComponent();
    56       Caption = "Parameter";
     56      Caption = "ItemParameter";
    5757    }
    5858    /// <summary>
     
    7272    protected override void DeregisterContentEvents() {
    7373      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
    74       Content.ValueChanged -= new EventHandler(Content_ValueChanged);
     74      Content.LocalValueChanged -= new EventHandler(Content_LocalValueChanged);
    7575      base.DeregisterContentEvents();
    7676    }
     
    8383      base.RegisterContentEvents();
    8484      Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
    85       Content.ValueChanged += new EventHandler(Content_ValueChanged);
     85      Content.LocalValueChanged += new EventHandler(Content_LocalValueChanged);
    8686    }
    8787
     
    8989      base.OnContentChanged();
    9090      if (Content == null) {
    91         Caption = "Parameter";
     91        Caption = "ItemParameter";
    9292        actualNameTextBox.Text = "-";
    9393        actualNameTextBox.Enabled = false;
    94         setValueButton.Enabled = false;
    95         clearValueButton.Enabled = false;
    96         valueGroupBox.Enabled = false;
     94        setLocalValueButton.Enabled = false;
     95        clearLocalValueButton.Enabled = false;
     96        localValueGroupBox.Enabled = false;
    9797        viewHost.Content = null;
    9898      } else {
    9999        Caption = Content.Name + " (" + Content.GetType().Name + ")";
    100100        actualNameTextBox.Text = Content.ActualName;
    101         actualNameTextBox.Enabled = Content.Value == null;
    102         setValueButton.Enabled = Content.Value == null;
    103         clearValueButton.Enabled = Content.Value != null;
    104         valueGroupBox.Enabled = true;
    105         viewHost.Content = Content.Value;
     101        actualNameTextBox.Enabled = Content.LocalValue == null;
     102        setLocalValueButton.Enabled = Content.LocalValue == null;
     103        clearLocalValueButton.Enabled = Content.LocalValue != null;
     104        localValueGroupBox.Enabled = true;
     105        viewHost.Content = Content.LocalValue;
    106106      }
    107107    }
     
    113113        actualNameTextBox.Text = Content.ActualName;
    114114    }
    115     protected virtual void Content_ValueChanged(object sender, EventArgs e) {
     115    protected virtual void Content_LocalValueChanged(object sender, EventArgs e) {
    116116      if (InvokeRequired)
    117         Invoke(new EventHandler(Content_ValueChanged), sender, e);
     117        Invoke(new EventHandler(Content_LocalValueChanged), sender, e);
    118118      else {
    119         actualNameTextBox.Enabled = Content.Value == null;
    120         setValueButton.Enabled = Content.Value == null;
    121         clearValueButton.Enabled = Content.Value != null;
    122         viewHost.Content = Content.Value;
     119        actualNameTextBox.Enabled = Content.LocalValue == null;
     120        setLocalValueButton.Enabled = Content.LocalValue == null;
     121        clearLocalValueButton.Enabled = Content.LocalValue != null;
     122        viewHost.Content = Content.LocalValue;
    123123      }
    124124    }
     
    127127      Content.ActualName = actualNameTextBox.Text;
    128128    }
    129     protected virtual void setValueButton_Click(object sender, EventArgs e) {
     129    protected virtual void setLocalValueButton_Click(object sender, EventArgs e) {
    130130      if (typeSelectorDialog == null) {
    131131        typeSelectorDialog = new TypeSelectorDialog();
    132         typeSelectorDialog.Caption = "Select Value Type";
     132        typeSelectorDialog.Caption = "Select Local Value Type";
    133133      }
    134134      typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false);
    135135      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
    136         Content.Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     136        Content.LocalValue = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    137137    }
    138     protected virtual void clearValueButton_Click(object sender, EventArgs e) {
    139       Content.Value = null;
     138    protected virtual void clearLocalValueButton_Click(object sender, EventArgs e) {
     139      Content.LocalValue = null;
    140140    }
    141     protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
     141    protected virtual void localValuePanel_DragEnterOver(object sender, DragEventArgs e) {
    142142      e.Effect = DragDropEffects.None;
    143143      Type type = e.Data.GetData("Type") as Type;
     
    150150      }
    151151    }
    152     protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
     152    protected virtual void localValuePanel_DragDrop(object sender, DragEventArgs e) {
    153153      if (e.Effect != DragDropEffects.None) {
    154154        T item = e.Data.GetData("Value") as T;
    155155        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    156         Content.Value = item;
     156        Content.LocalValue = item;
    157157      }
    158158    }
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r2714 r2740  
    4949  </ItemGroup>
    5050  <ItemGroup>
     51    <Compile Include="SubScopesItemParameter.cs" />
     52    <Compile Include="ScopeParameter.cs" />
    5153    <Compile Include="HeuristicLabParametersPlugin.cs" />
    5254    <Compile Include="ItemParameter.cs" />
  • trunk/sources/HeuristicLab.Parameters/3.3/ItemParameter.cs

    r2715 r2740  
    2929namespace HeuristicLab.Parameters {
    3030  /// <summary>
    31   /// Represents a parameter.
     31  /// A generic parameter which represents an instance of type T.
    3232  /// </summary>
    3333  [Item("ItemParameter<T>", "A generic parameter which represents an instance of type T.")]
     
    4646    }
    4747
    48     private T value;
     48    private T localValue;
    4949    [Storable]
    50     public T Value {
    51       get { return this.value; }
     50    public T LocalValue {
     51      get { return this.localValue; }
    5252      set {
    53         if (value != this.value) {
     53        if (value != this.localValue) {
    5454          if ((value != null) && (!DataType.IsInstanceOfType(value))) throw new ArgumentException("Static value does not match data type of parameter");
    55           if (this.value != null) this.value.Changed -= new ChangedEventHandler(Value_Changed);
    56           this.value = value;
    57           if (this.value != null) this.value.Changed += new ChangedEventHandler(Value_Changed);
    58           OnValueChanged();
     55          if (this.localValue != null) this.localValue.Changed -= new ChangedEventHandler(LocalValue_Changed);
     56          this.localValue = value;
     57          if (this.localValue != null) this.localValue.Changed += new ChangedEventHandler(LocalValue_Changed);
     58          OnLocalValueChanged();
    5959        }
    6060      }
     61    }
     62
     63    public T Value {
     64      get { return GetValue(); }
     65      set { SetValue(value); }
    6166    }
    6267
     
    6469      : base("Anonymous", null, typeof(T)) {
    6570      actualName = Name;
    66       Value = null;
     71      LocalValue = null;
    6772    }
    6873    public ItemParameter(string name, string description)
    6974      : base(name, description, typeof(T)) {
    70       this.actualName = Name;
    71       this.Value = null;
     75      actualName = Name;
     76      LocalValue = null;
    7277    }
    73     public ItemParameter(string name, string description, T value)
     78    public ItemParameter(string name, string description, T localValue)
    7479      : base(name, description, typeof(T)) {
    75       this.actualName = Name;
    76       this.Value = value;
     80      actualName = Name;
     81      LocalValue = localValue;
    7782    }
    7883
    79     public override IItem GetValue(ExecutionContext context) {
     84    public override IDeepCloneable Clone(Cloner cloner) {
     85      ItemParameter<T> clone = (ItemParameter<T>)base.Clone(cloner);
     86      clone.actualName = actualName;
     87      clone.LocalValue = (T)cloner.Clone(localValue);
     88      return clone;
     89    }
     90
     91    public override string ToString() {
     92      return string.Format("{0}: {1} ({2})", Name, LocalValue != null ? LocalValue.ToString() : ActualName, DataType.Name);
     93    }
     94
     95    protected ItemParameter<T> GetParameter(out string name) {
    8096      ItemParameter<T> param = this;
    81       ExecutionContext current = context;
    82       string actualName = null;
     97      ExecutionContext current = ExecutionContext;
     98      name = param.Name;
    8399      while (param != null) {
    84         if (param.Value != null) return param.Value;
    85         actualName = param.ActualName;
     100        if (param.LocalValue != null) return param;
     101        name = param.ActualName;
    86102        current = current.Parent;
    87         while ((current != null) && !current.Operator.Parameters.ContainsKey(actualName))
     103        while ((current != null) && !current.Operator.Parameters.ContainsKey(name))
    88104          current = current.Parent;
    89105        if (current != null)
     
    92108          param = null;
    93109      }
    94 
    95       IScope scope = context.Scope;
    96       while ((scope != null) && !scope.Variables.ContainsKey(actualName))
     110      return null;
     111    }
     112    protected IVariable GetVariable(string name) {
     113      IScope scope = ExecutionContext.Scope;
     114      while ((scope != null) && !scope.Variables.ContainsKey(name))
    97115        scope = scope.Parent;
    98       return scope != null ? scope.Variables[actualName].Value : null;
     116      return scope != null ? scope.Variables[actualName] : null;
    99117    }
    100 
    101     public override IDeepCloneable Clone(Cloner cloner) {
    102       ItemParameter<T> clone = (ItemParameter<T>)base.Clone(cloner);
    103       clone.actualName = actualName;
    104       clone.Value = (T)cloner.Clone(value);
    105       return clone;
     118    protected virtual T GetValue() {
     119      string name;
     120      // try to get local value from context stack
     121      ItemParameter<T> param = GetParameter(out name);
     122      if (param != null) return param.Value;
     123      else {
     124        // try to get variable from scope
     125        IVariable var = GetVariable(name);
     126        if (var != null) return (T)var.Value;
     127      }
     128      return null;
    106129    }
    107 
    108     public override string ToString() {
    109       return string.Format("{0}: {1} ({2})", Name, Value != null ? Value.ToString() : ActualName, DataType.Name);
     130    protected virtual void SetValue(T value) {
     131      string name;
     132      // try to get local value from context stack
     133      ItemParameter<T> param = GetParameter(out name);
     134      if (param != null) param.Value = value;
     135      else {
     136        // try to get variable from scope
     137        IVariable var = GetVariable(name);
     138        if (var != null) var.Value = value;
     139        else ExecutionContext.Scope.Variables.Add(new Variable(name, value));
     140      }
    110141    }
    111142
     
    116147      OnChanged();
    117148    }
    118     public event EventHandler ValueChanged;
    119     private void OnValueChanged() {
    120       if (ValueChanged != null)
    121         ValueChanged(this, new EventArgs());
     149    public event EventHandler LocalValueChanged;
     150    private void OnLocalValueChanged() {
     151      if (LocalValueChanged != null)
     152        LocalValueChanged(this, new EventArgs());
    122153      OnChanged();
    123154    }
    124 
    125     private void Value_Changed(object sender, ChangedEventArgs e) {
     155    private void LocalValue_Changed(object sender, ChangedEventArgs e) {
    126156      OnChanged(e);
    127157    }
  • trunk/sources/HeuristicLab.Parameters/3.3/OperatorParameter.cs

    r2714 r2740  
    2929namespace HeuristicLab.Parameters {
    3030  /// <summary>
    31   /// Represents a parameter.
     31  /// A parameter which represents an operator.
    3232  /// </summary>
    3333  [Item("OperatorParameter", "A parameter which represents an operator.")]
    34   [EmptyStorableClass]
    3534  [Creatable("Test")]
    36   public class OperatorParameter : ItemParameter<IOperator>, IOperatorParameter {
     35  public class OperatorParameter : Parameter, IOperatorParameter {
     36    private IOperator value;
     37    [Storable]
     38    public IOperator Value {
     39      get { return this.value; }
     40      set {
     41        if (value != this.value) {
     42          if (this.value != null) this.value.Changed -= new ChangedEventHandler(Value_Changed);
     43          this.value = value;
     44          if (this.value != null) this.value.Changed += new ChangedEventHandler(Value_Changed);
     45          OnValueChanged();
     46        }
     47      }
     48    }
     49
    3750    public OperatorParameter()
    38       : base("Anonymous", null) {
     51      : base("Anonymous", null, typeof(IOperator)) {
    3952    }
    4053    public OperatorParameter(string name, string description)
    41       : base(name, description) {
     54      : base(name, description, typeof(IOperator)) {
    4255    }
    4356    public OperatorParameter(string name, string description, IOperator value)
    44       : base(name, description, value) {
     57      : base(name, description, typeof(IOperator)) {
     58      Value = value;
     59    }
     60
     61    public override IDeepCloneable Clone(Cloner cloner) {
     62      OperatorParameter clone = (OperatorParameter)base.Clone(cloner);
     63      clone.Value = (IOperator)cloner.Clone(value);
     64      return clone;
     65    }
     66
     67    public override string ToString() {
     68      return string.Format("{0}: {1} ({2})", Name, Value != null ? Value.ToString() : "null", DataType.Name);
     69    }
     70
     71    public event EventHandler ValueChanged;
     72    private void OnValueChanged() {
     73      if (ValueChanged != null)
     74        ValueChanged(this, new EventArgs());
     75      OnChanged();
     76    }
     77    private void Value_Changed(object sender, ChangedEventArgs e) {
     78      OnChanged(e);
    4579    }
    4680  }
  • trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs

    r2714 r2740  
    2929namespace HeuristicLab.Parameters {
    3030  /// <summary>
    31   /// Represents a parameter.
     31  /// A base class for parameters.
    3232  /// </summary>
    3333  [Item("Parameter", "A base class for parameters.")]
     
    4545      get { return dataType; }
    4646    }
     47    [Storable]
     48    private ExecutionContext executionContext;
     49    public ExecutionContext ExecutionContext {
     50      get { return executionContext; }
     51      set { executionContext = value; }
     52    }
    4753
    4854    protected Parameter()
     
    5662    }
    5763
    58     public abstract IItem GetValue(ExecutionContext context);
    59 
    6064    public override IDeepCloneable Clone(Cloner cloner) {
    6165      Parameter clone = (Parameter)base.Clone(cloner);
    6266      clone.dataType = dataType;
     67      clone.executionContext = (ExecutionContext)cloner.Clone(executionContext);
    6368      return clone;
    6469    }
Note: See TracChangeset for help on using the changeset viewer.