- Timestamp:
- 02/03/10 04:43:06 (15 years ago)
- 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 27 27 namespace HeuristicLab.Core { 28 28 public interface IOperatorParameter : IParameter { 29 string ActualName { get; set; }30 29 IOperator Value { get; set; } 31 30 32 event EventHandler ActualNameChanged;33 31 event EventHandler ValueChanged; 34 32 } -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IParameter.cs
r2687 r2740 29 29 public interface IParameter : INamedItem { 30 30 Type DataType { get; } 31 32 IItem GetValue(ExecutionContext context); 31 ExecutionContext ExecutionContext { get; set; } 33 32 } 34 33 } -
trunk/sources/HeuristicLab.Operators/3.3/CombinedOperator.cs
r2727 r2740 36 36 [Item("CombinedOperator", "An operator which contains an operator graph.")] 37 37 [Creatable("Test")] 38 public sealed class CombinedOperator : S tandardOperator, IOperator {38 public sealed class CombinedOperator : SingleSuccessorOperator, IOperator { 39 39 public override Image ItemImage { 40 40 get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Module; } … … 68 68 } 69 69 70 public override ExecutionContextCollection Apply( ExecutionContext context) {71 ExecutionContextCollection next = base.Apply( context);70 public override ExecutionContextCollection Apply() { 71 ExecutionContextCollection next = base.Apply(); 72 72 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)); 74 74 return next; 75 75 } -
trunk/sources/HeuristicLab.Operators/3.3/Counter.cs
r2715 r2740 35 35 [EmptyStorableClass] 36 36 [Creatable("Test")] 37 public sealed class Counter : S tandardOperator {37 public sealed class Counter : SingleSuccessorOperator { 38 38 public ItemParameter<IntData> Value { 39 39 get { return (ItemParameter<IntData>)Parameters["Value"]; } … … 49 49 } 50 50 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; 54 54 value.Value += increment.Value; 55 return base.Apply( context);55 return base.Apply(); 56 56 } 57 57 } -
trunk/sources/HeuristicLab.Operators/3.3/EmptyOperator.cs
r2684 r2740 34 34 [Creatable("Test")] 35 35 [EmptyStorableClass] 36 public sealed class EmptyOperator : S tandardOperator {36 public sealed class EmptyOperator : SingleSuccessorOperator { 37 37 public EmptyOperator() 38 38 : base() { -
trunk/sources/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj
r2714 r2740 86 86 <ItemGroup> 87 87 <Compile Include="CombinedOperator.cs" /> 88 <Compile Include="MultipleSuccessorsOperator.cs" /> 88 89 <Compile Include="Counter.cs" /> 89 90 <Compile Include="EmptyOperator.cs"> … … 94 95 <Compile Include="Properties\AssemblyInfo.cs" /> 95 96 <Compile Include="SequentialProcessor.cs" /> 96 <Compile Include="S tandardOperator.cs" />97 <Compile Include="SingleSuccessorOperator.cs" /> 97 98 </ItemGroup> 98 99 <ItemGroup> -
trunk/sources/HeuristicLab.Operators/3.3/Operator.cs
r2684 r2740 84 84 } 85 85 86 [Storable] 87 private ExecutionContext executionContext; 88 protected ExecutionContext ExecutionContext { 89 get { return executionContext; } 90 } 91 86 92 /// <summary> 87 93 /// Initializes a new instance of <see cref="OperatorBase"/> setting the breakpoint flag and … … 107 113 clone.canceled = canceled; 108 114 clone.breakpoint = breakpoint; 115 clone.executionContext = (ExecutionContext)cloner.Clone(executionContext); 109 116 return clone; 110 117 } … … 112 119 /// <inheritdoc/> 113 120 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 } 118 135 } 119 136 /// <inheritdoc/> … … 127 144 /// <param name="scope">The scope where to execute the operator</param> 128 145 /// <returns><c>null</c>.</returns> 129 public virtual ExecutionContextCollection Apply( ExecutionContext context) {146 public virtual ExecutionContextCollection Apply() { 130 147 return new ExecutionContextCollection(); 131 148 } -
trunk/sources/HeuristicLab.Operators/3.3/SequentialProcessor.cs
r2684 r2740 36 36 [Creatable("Test")] 37 37 [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 { 48 39 public SequentialProcessor() 49 40 : base() { 50 41 } 51 42 52 public override ExecutionContextCollection Apply( ExecutionContext context) {43 public override ExecutionContextCollection Apply() { 53 44 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)); 61 47 return next; 62 48 } -
trunk/sources/HeuristicLab.Operators/3.3/SingleSuccessorOperator.cs
r2739 r2740 32 32 /// A base class for operators which have only one successor. 33 33 /// </summary> 34 [Item("S tandardOperator", "A base class for operators which have only one successor.")]34 [Item("SingleSuccessorOperator", "A base class for operators which have only one successor.")] 35 35 [Creatable("Test")] 36 36 [EmptyStorableClass] 37 public abstract class S tandardOperator : Operator {38 p ublic OperatorParameter Successor {37 public abstract class SingleSuccessorOperator : Operator { 38 protected OperatorParameter SuccessorParameter { 39 39 get { return (OperatorParameter)Parameters["Successor"]; } 40 40 } 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; } 45 44 } 46 45 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)); 51 54 else 52 55 return new ExecutionContextCollection(); -
trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj
r2714 r2740 51 51 </ItemGroup> 52 52 <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> 53 65 <Compile Include="HeuristicLabParametersViewsPlugin.cs" /> 54 66 <Compile Include="ItemParameterView.cs"> -
trunk/sources/HeuristicLab.Parameters.Views/3.3/ItemParameterView.Designer.cs
r2715 r2740 47 47 private void InitializeComponent() { 48 48 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(); 51 51 this.viewHost = new HeuristicLab.Core.Views.ViewHost(); 52 this.clear ValueButton = new System.Windows.Forms.Button();53 this.set ValueButton = new System.Windows.Forms.Button();52 this.clearLocalValueButton = new System.Windows.Forms.Button(); 53 this.setLocalValueButton = new System.Windows.Forms.Button(); 54 54 this.actualNameTextBox = new System.Windows.Forms.TextBox(); 55 55 this.actualNameLabel = new System.Windows.Forms.Label(); 56 56 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 57 57 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 58 this. valueGroupBox.SuspendLayout();59 this. valuePanel.SuspendLayout();58 this.localValueGroupBox.SuspendLayout(); 59 this.localValuePanel.SuspendLayout(); 60 60 this.SuspendLayout(); 61 61 // … … 89 89 this.descriptionTextBox.TabIndex = 5; 90 90 // 91 // valueGroupBox92 // 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) 94 94 | System.Windows.Forms.AnchorStyles.Left) 95 95 | 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 // valuePanel107 // 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) 110 110 | System.Windows.Forms.AnchorStyles.Left) 111 111 | 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); 120 120 // 121 121 // viewHost 122 122 // 123 this.viewHost.Content = null; 123 124 this.viewHost.Dock = System.Windows.Forms.DockStyle.Fill; 124 125 this.viewHost.Location = new System.Drawing.Point(0, 0); 125 126 this.viewHost.Name = "viewHost"; 126 this.viewHost.Content = null;127 127 this.viewHost.Size = new System.Drawing.Size(374, 115); 128 128 this.viewHost.TabIndex = 0; 129 129 // 130 // clear ValueButton131 // 132 this.clear ValueButton.Enabled = false;133 this.clear ValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;134 this.clear ValueButton.Location = new System.Drawing.Point(35, 19);135 this.clear ValueButton.Name = "clearValueButton";136 this.clear ValueButton.Size = new System.Drawing.Size(23, 23);137 this.clear ValueButton.TabIndex = 9;138 this.toolTip.SetToolTip(this.clear ValueButton, "Clear Value");139 this.clear ValueButton.UseVisualStyleBackColor = true;140 this.clear ValueButton.Click += new System.EventHandler(this.clearValueButton_Click);141 // 142 // set ValueButton143 // 144 this.set ValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;145 this.set ValueButton.Location = new System.Drawing.Point(6, 19);146 this.set ValueButton.Name = "setValueButton";147 this.set ValueButton.Size = new System.Drawing.Size(23, 23);148 this.set ValueButton.TabIndex = 8;149 this.toolTip.SetToolTip(this.set ValueButton, "Set Value");150 this.set ValueButton.UseVisualStyleBackColor = true;151 this.set ValueButton.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); 152 152 // 153 153 // actualNameTextBox … … 174 174 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 175 175 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 176 this.Controls.Add(this. valueGroupBox);176 this.Controls.Add(this.localValueGroupBox); 177 177 this.Controls.Add(this.actualNameTextBox); 178 178 this.Controls.Add(this.actualNameLabel); … … 187 187 this.Controls.SetChildIndex(this.actualNameTextBox, 0); 188 188 this.Controls.SetChildIndex(this.nameLabel, 0); 189 this.Controls.SetChildIndex(this. valueGroupBox, 0);189 this.Controls.SetChildIndex(this.localValueGroupBox, 0); 190 190 ((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); 193 193 this.ResumeLayout(false); 194 194 this.PerformLayout(); … … 198 198 #endregion 199 199 200 protected System.Windows.Forms.GroupBox valueGroupBox;200 protected System.Windows.Forms.GroupBox localValueGroupBox; 201 201 protected System.Windows.Forms.TextBox actualNameTextBox; 202 202 protected System.Windows.Forms.Label actualNameLabel; 203 protected System.Windows.Forms.Panel valuePanel;203 protected System.Windows.Forms.Panel localValuePanel; 204 204 protected HeuristicLab.Core.Views.ViewHost viewHost; 205 protected System.Windows.Forms.Button set ValueButton;205 protected System.Windows.Forms.Button setLocalValueButton; 206 206 protected System.Windows.Forms.ToolTip toolTip; 207 protected System.Windows.Forms.Button clear ValueButton;207 protected System.Windows.Forms.Button clearLocalValueButton; 208 208 } 209 209 } -
trunk/sources/HeuristicLab.Parameters.Views/3.3/ItemParameterView.cs
r2727 r2740 54 54 public ItemParameterView() { 55 55 InitializeComponent(); 56 Caption = " Parameter";56 Caption = "ItemParameter"; 57 57 } 58 58 /// <summary> … … 72 72 protected override void DeregisterContentEvents() { 73 73 Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged); 74 Content. ValueChanged -= new EventHandler(Content_ValueChanged);74 Content.LocalValueChanged -= new EventHandler(Content_LocalValueChanged); 75 75 base.DeregisterContentEvents(); 76 76 } … … 83 83 base.RegisterContentEvents(); 84 84 Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged); 85 Content. ValueChanged += new EventHandler(Content_ValueChanged);85 Content.LocalValueChanged += new EventHandler(Content_LocalValueChanged); 86 86 } 87 87 … … 89 89 base.OnContentChanged(); 90 90 if (Content == null) { 91 Caption = " Parameter";91 Caption = "ItemParameter"; 92 92 actualNameTextBox.Text = "-"; 93 93 actualNameTextBox.Enabled = false; 94 set ValueButton.Enabled = false;95 clear ValueButton.Enabled = false;96 valueGroupBox.Enabled = false;94 setLocalValueButton.Enabled = false; 95 clearLocalValueButton.Enabled = false; 96 localValueGroupBox.Enabled = false; 97 97 viewHost.Content = null; 98 98 } else { 99 99 Caption = Content.Name + " (" + Content.GetType().Name + ")"; 100 100 actualNameTextBox.Text = Content.ActualName; 101 actualNameTextBox.Enabled = Content. Value == null;102 set ValueButton.Enabled = Content.Value == null;103 clear ValueButton.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; 106 106 } 107 107 } … … 113 113 actualNameTextBox.Text = Content.ActualName; 114 114 } 115 protected virtual void Content_ ValueChanged(object sender, EventArgs e) {115 protected virtual void Content_LocalValueChanged(object sender, EventArgs e) { 116 116 if (InvokeRequired) 117 Invoke(new EventHandler(Content_ ValueChanged), sender, e);117 Invoke(new EventHandler(Content_LocalValueChanged), sender, e); 118 118 else { 119 actualNameTextBox.Enabled = Content. Value == null;120 set ValueButton.Enabled = Content.Value == null;121 clear ValueButton.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; 123 123 } 124 124 } … … 127 127 Content.ActualName = actualNameTextBox.Text; 128 128 } 129 protected virtual void set ValueButton_Click(object sender, EventArgs e) {129 protected virtual void setLocalValueButton_Click(object sender, EventArgs e) { 130 130 if (typeSelectorDialog == null) { 131 131 typeSelectorDialog = new TypeSelectorDialog(); 132 typeSelectorDialog.Caption = "Select Value Type";132 typeSelectorDialog.Caption = "Select Local Value Type"; 133 133 } 134 134 typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false); 135 135 if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) 136 Content. Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();136 Content.LocalValue = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); 137 137 } 138 protected virtual void clear ValueButton_Click(object sender, EventArgs e) {139 Content. Value = null;138 protected virtual void clearLocalValueButton_Click(object sender, EventArgs e) { 139 Content.LocalValue = null; 140 140 } 141 protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {141 protected virtual void localValuePanel_DragEnterOver(object sender, DragEventArgs e) { 142 142 e.Effect = DragDropEffects.None; 143 143 Type type = e.Data.GetData("Type") as Type; … … 150 150 } 151 151 } 152 protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {152 protected virtual void localValuePanel_DragDrop(object sender, DragEventArgs e) { 153 153 if (e.Effect != DragDropEffects.None) { 154 154 T item = e.Data.GetData("Value") as T; 155 155 if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone(); 156 Content. Value = item;156 Content.LocalValue = item; 157 157 } 158 158 } -
trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj
r2714 r2740 49 49 </ItemGroup> 50 50 <ItemGroup> 51 <Compile Include="SubScopesItemParameter.cs" /> 52 <Compile Include="ScopeParameter.cs" /> 51 53 <Compile Include="HeuristicLabParametersPlugin.cs" /> 52 54 <Compile Include="ItemParameter.cs" /> -
trunk/sources/HeuristicLab.Parameters/3.3/ItemParameter.cs
r2715 r2740 29 29 namespace HeuristicLab.Parameters { 30 30 /// <summary> 31 /// Represents a parameter.31 /// A generic parameter which represents an instance of type T. 32 32 /// </summary> 33 33 [Item("ItemParameter<T>", "A generic parameter which represents an instance of type T.")] … … 46 46 } 47 47 48 private T value;48 private T localValue; 49 49 [Storable] 50 public T Value {51 get { return this. value; }50 public T LocalValue { 51 get { return this.localValue; } 52 52 set { 53 if (value != this. value) {53 if (value != this.localValue) { 54 54 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 On ValueChanged();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(); 59 59 } 60 60 } 61 } 62 63 public T Value { 64 get { return GetValue(); } 65 set { SetValue(value); } 61 66 } 62 67 … … 64 69 : base("Anonymous", null, typeof(T)) { 65 70 actualName = Name; 66 Value = null;71 LocalValue = null; 67 72 } 68 73 public ItemParameter(string name, string description) 69 74 : base(name, description, typeof(T)) { 70 this.actualName = Name;71 this.Value = null;75 actualName = Name; 76 LocalValue = null; 72 77 } 73 public ItemParameter(string name, string description, T value)78 public ItemParameter(string name, string description, T localValue) 74 79 : base(name, description, typeof(T)) { 75 this.actualName = Name;76 this.Value = value;80 actualName = Name; 81 LocalValue = localValue; 77 82 } 78 83 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) { 80 96 ItemParameter<T> param = this; 81 ExecutionContext current = context;82 string actualName = null;97 ExecutionContext current = ExecutionContext; 98 name = param.Name; 83 99 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; 86 102 current = current.Parent; 87 while ((current != null) && !current.Operator.Parameters.ContainsKey( actualName))103 while ((current != null) && !current.Operator.Parameters.ContainsKey(name)) 88 104 current = current.Parent; 89 105 if (current != null) … … 92 108 param = null; 93 109 } 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)) 97 115 scope = scope.Parent; 98 return scope != null ? scope.Variables[actualName] .Value: null;116 return scope != null ? scope.Variables[actualName] : null; 99 117 } 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; 106 129 } 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 } 110 141 } 111 142 … … 116 147 OnChanged(); 117 148 } 118 public event EventHandler ValueChanged;119 private void On ValueChanged() {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()); 122 153 OnChanged(); 123 154 } 124 125 private void Value_Changed(object sender, ChangedEventArgs e) { 155 private void LocalValue_Changed(object sender, ChangedEventArgs e) { 126 156 OnChanged(e); 127 157 } -
trunk/sources/HeuristicLab.Parameters/3.3/OperatorParameter.cs
r2714 r2740 29 29 namespace HeuristicLab.Parameters { 30 30 /// <summary> 31 /// Represents a parameter.31 /// A parameter which represents an operator. 32 32 /// </summary> 33 33 [Item("OperatorParameter", "A parameter which represents an operator.")] 34 [EmptyStorableClass]35 34 [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 37 50 public OperatorParameter() 38 : base("Anonymous", null ) {51 : base("Anonymous", null, typeof(IOperator)) { 39 52 } 40 53 public OperatorParameter(string name, string description) 41 : base(name, description ) {54 : base(name, description, typeof(IOperator)) { 42 55 } 43 56 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); 45 79 } 46 80 } -
trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs
r2714 r2740 29 29 namespace HeuristicLab.Parameters { 30 30 /// <summary> 31 /// Represents a parameter.31 /// A base class for parameters. 32 32 /// </summary> 33 33 [Item("Parameter", "A base class for parameters.")] … … 45 45 get { return dataType; } 46 46 } 47 [Storable] 48 private ExecutionContext executionContext; 49 public ExecutionContext ExecutionContext { 50 get { return executionContext; } 51 set { executionContext = value; } 52 } 47 53 48 54 protected Parameter() … … 56 62 } 57 63 58 public abstract IItem GetValue(ExecutionContext context);59 60 64 public override IDeepCloneable Clone(Cloner cloner) { 61 65 Parameter clone = (Parameter)base.Clone(cloner); 62 66 clone.dataType = dataType; 67 clone.executionContext = (ExecutionContext)cloner.Clone(executionContext); 63 68 return clone; 64 69 }
Note: See TracChangeset
for help on using the changeset viewer.