- Timestamp:
- 06/06/09 02:09:35 (15 years ago)
- Location:
- branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2
- Files:
-
- 1 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ComparatorBase.cs
r1530 r2027 36 36 /// </summary> 37 37 protected ComparatorBase() { 38 Add VariableInfo(new VariableInfo("LeftSide", "Variable on the left side of the comparison", typeof(IItem), VariableKind.In));39 Add VariableInfo(new VariableInfo("RightSide", "Variable on the right side of the comparison", typeof(IItem), VariableKind.In));40 Add VariableInfo(new VariableInfo("Result", "Result of the comparison", typeof(BoolData), VariableKind.Out | VariableKind.New));38 AddParameter(new Parameter("LeftSide", "Variable on the left side of the comparison", typeof(IItem), ParameterType.In)); 39 AddParameter(new Parameter("RightSide", "Variable on the right side of the comparison", typeof(IItem), ParameterType.In)); 40 AddParameter(new Parameter("Result", "Result of the comparison", typeof(BoolData), ParameterType.Out)); 41 41 } 42 42 … … 50 50 /// <param name="scope">The scope where to apply the compare operation.</param> 51 51 /// <returns><c>null</c>.</returns> 52 public override IOperation Apply(IScope scope) { 53 BoolData result = GetVariableValue<BoolData>("Result", scope, false, false); 52 public override IOperation Apply(IEnvironment env, IScope scope) { 53 string resultName = env.TranslateName("Result"); 54 BoolData result = scope.GetVariableValue<BoolData>(resultName, false, false); 54 55 if (result == null) { 55 56 result = new BoolData(true); 56 IVariableInfo info = GetVariableInfo("Result"); 57 if (info.Local) 58 AddVariable(new Variable(info.ActualName, result)); 59 else 60 scope.AddVariable(new Variable(scope.TranslateName(info.FormalName), result)); 57 scope.AddVariable(new Variable(resultName, result)); 61 58 } 62 IItem leftSide = GetVariableValue<IItem>("LeftSide", scope, true);59 IItem leftSide = scope.GetVariableValue<IItem>(env.TranslateName("LeftSide"), true); 63 60 if (!(leftSide is IComparable)) throw new InvalidOperationException("Comparator: Left side needs to be of type IComparable"); 64 61 IComparable left = (IComparable)leftSide; 65 IItem rightSide = GetVariableValue<IItem>("RightSide", scope, true);62 IItem rightSide = scope.GetVariableValue<IItem>(env.TranslateName("RightSide"), true); 66 63 result.Data = Compare(left, rightSide); 67 64 return null; -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ConditionalBranch.cs
r1530 r2027 45 45 public ConditionalBranch() 46 46 : base() { 47 Add VariableInfo(new VariableInfo("Condition", "A boolean variable that decides the branch", typeof(BoolData), VariableKind.In));47 AddParameter(new Parameter("Condition", "A boolean variable that decides the branch", typeof(BoolData), ParameterType.In)); 48 48 } 49 49 … … 56 56 /// <returns>A new <see cref="AtomicOperation"/> with either operator 1 or operator 2 applied 57 57 /// to the given <paramref name="scope"/> or <c>null</c>.</returns> 58 public override IOperation Apply(IScope scope) { 59 BoolData resultData = GetVariableValue<BoolData>("Condition", scope, true); 60 bool result = resultData.Data; 58 public override IOperation Apply(IEnvironment env, IScope scope) { 59 bool result = scope.GetVariableValue<BoolData>(env.TranslateName("Condition"), true).Data; 61 60 62 61 if ((result) && (SubOperators.Count > 0) && (SubOperators[0] != null)) 63 return new AtomicOperation(SubOperators[0], scope);62 return new AtomicOperation(SubOperators[0], env, scope); 64 63 else if ((!result) && (SubOperators.Count > 1) && (SubOperators[1] != null)) 65 return new AtomicOperation(SubOperators[1], scope);64 return new AtomicOperation(SubOperators[1], env, scope); 66 65 return null; 67 66 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/Counter.cs
r1530 r2027 43 43 public Counter() 44 44 : base() { 45 Add VariableInfo(new VariableInfo("Value", "Counter value", typeof(IntData), VariableKind.In | VariableKind.Out));45 AddParameter(new Parameter("Value", "Counter value", typeof(IntData), ParameterType.InOut)); 46 46 } 47 47 … … 51 51 /// <param name="scope">The scope whose variable should be incremented.</param> 52 52 /// <returns><c>null</c>.</returns> 53 public override IOperation Apply(I Scope scope) {54 IntData value = GetVariableValue<IntData>("Value", scope, true);53 public override IOperation Apply(IEnvironment env, IScope scope) { 54 IntData value = scope.GetVariableValue<IntData>(env.TranslateName("Value"), true); 55 55 value.Data++; 56 56 return null; -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/DoubleCounter.cs
r1530 r2027 44 44 public DoubleCounter() 45 45 : base() { 46 Add VariableInfo(new VariableInfo("Value", "Counter value", typeof(DoubleData), VariableKind.In | VariableKind.Out));47 Add VariableInfo(new VariableInfo("Interval", "Interval value", typeof(DoubleData), VariableKind.In));46 AddParameter(new Parameter("Value", "Counter value", typeof(DoubleData), ParameterType.InOut)); 47 AddParameter(new Parameter("Interval", "Interval value", typeof(DoubleData), ParameterType.In)); 48 48 } 49 49 … … 53 53 /// <param name="scope">The scope whose variable should be incremented.</param> 54 54 /// <returns><c>null</c>.</returns> 55 public override IOperation Apply(I Scope scope) {56 DoubleData value = GetVariableValue<DoubleData>("Value", scope, true);57 double interval = GetVariableValue<DoubleData>("Interval", scope, true).Data;55 public override IOperation Apply(IEnvironment env, IScope scope) { 56 DoubleData value = scope.GetVariableValue<DoubleData>(env.TranslateName("Value"), true); 57 double interval = scope.GetVariableValue<DoubleData>(env.TranslateName("Interval"), true).Data; 58 58 value.Data += interval; 59 59 return null; -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/EmptyOperator.cs
r1530 r2027 47 47 /// <param name="scope">The scope to apply the operator on.</param> 48 48 /// <returns><c>null</c>.</returns> 49 public override IOperation Apply(I Scope scope) {49 public override IOperation Apply(IEnvironment environment, IScope scope) { 50 50 return null; 51 51 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/HeuristicLab.Operators-3.2.csproj
r1534 r2027 81 81 </ItemGroup> 82 82 <ItemGroup> 83 <Compile Include=" AddVariableInfoDialog.cs">84 <SubType> Form</SubType>83 <Compile Include="ComparatorBase.cs"> 84 <SubType>Code</SubType> 85 85 </Compile> 86 <Compile Include="AddVariableInfoDialog.Designer.cs">87 <DependentUpon>AddVariableInfoDialog.cs</DependentUpon>88 </Compile>89 <Compile Include="CombinedOperator.cs" />90 <Compile Include="CombinedOperatorView.cs">91 <SubType>UserControl</SubType>92 </Compile>93 <Compile Include="CombinedOperatorView.Designer.cs">94 <DependentUpon>CombinedOperatorView.cs</DependentUpon>95 </Compile>96 <Compile Include="ComparatorBase.cs" />97 86 <Compile Include="ConditionalBranch.cs"> 98 87 <SubType>Code</SubType> 99 88 </Compile> 100 <Compile Include="DelegatingOperator.cs" /> 101 <Compile Include="DoubleCounter.cs" /> 102 <Compile Include="ScopeCleaner.cs" /> 103 <Compile Include="StochasticMultiBranch.cs" /> 104 <Compile Include="SubScopesMixer.cs" /> 105 <Compile Include="DataCollector.cs" /> 106 <Compile Include="EqualToComparator.cs" /> 107 <Compile Include="GreaterOrEqualThanComparator.cs" /> 108 <Compile Include="GreaterThanComparator.cs" /> 109 <Compile Include="LessOrEqualThanComparator.cs" /> 110 <Compile Include="LessThanComparator.cs" /> 111 <Compile Include="OperatorExtractor.cs" /> 112 <Compile Include="ParallelProcessor.cs" /> 113 <Compile Include="EmptyOperator.cs" /> 114 <Compile Include="SequentialProcessor.cs" /> 115 <Compile Include="SingleObjectiveEvaluatorBase.cs" /> 116 <Compile Include="Sorter.cs" /> 117 <Compile Include="StochasticBranch.cs" /> 118 <Compile Include="SubScopesRemover.cs" /> 119 <Compile Include="UnequalToComparator.cs" /> 120 <Compile Include="UniformSequentialSubScopesProcessor.cs" /> 121 <Compile Include="UniformParallelSubScopesProcessor.cs" /> 122 <Compile Include="ParallelSubScopesProcessor.cs" /> 123 <Compile Include="SequentialSubScopesProcessor.cs" /> 124 <Compile Include="SubScopesCreater.cs" /> 125 <Compile Include="Counter.cs" /> 89 <Compile Include="Counter.cs"> 90 <SubType>Code</SubType> 91 </Compile> 92 <Compile Include="DoubleCounter.cs"> 93 <SubType>Code</SubType> 94 </Compile> 95 <Compile Include="EmptyOperator.cs"> 96 <SubType>Code</SubType> 97 </Compile> 98 <Compile Include="EqualToComparator.cs"> 99 <SubType>Code</SubType> 100 </Compile> 101 <Compile Include="GreaterOrEqualThanComparator.cs"> 102 <SubType>Code</SubType> 103 </Compile> 104 <Compile Include="GreaterThanComparator.cs"> 105 <SubType>Code</SubType> 106 </Compile> 126 107 <Compile Include="HeuristicLabOperatorsPlugin.cs" /> 108 <Compile Include="LessOrEqualThanComparator.cs"> 109 <SubType>Code</SubType> 110 </Compile> 111 <Compile Include="LessThanComparator.cs"> 112 <SubType>Code</SubType> 113 </Compile> 114 <Compile Include="ParallelProcessor.cs"> 115 <SubType>Code</SubType> 116 </Compile> 117 <Compile Include="ParallelSubScopesProcessor.cs"> 118 <SubType>Code</SubType> 119 </Compile> 127 120 <Compile Include="Properties\AssemblyInfo.cs" /> 128 <Compile Include="VariableInjector.cs" /> 121 <Compile Include="SequentialProcessor.cs"> 122 <SubType>Code</SubType> 123 </Compile> 124 <Compile Include="SequentialSubScopesProcessor.cs"> 125 <SubType>Code</SubType> 126 </Compile> 127 <Compile Include="SubScopesCreater.cs"> 128 <SubType>Code</SubType> 129 </Compile> 130 <Compile Include="UnequalToComparator.cs"> 131 <SubType>Code</SubType> 132 </Compile> 133 <Compile Include="UniformParallelSubScopesProcessor.cs"> 134 <SubType>Code</SubType> 135 </Compile> 136 <Compile Include="UniformSequentialSubScopesProcessor.cs"> 137 <SubType>Code</SubType> 138 </Compile> 139 <Compile Include="VariableInjector.cs"> 140 <SubType>Code</SubType> 141 </Compile> 129 142 <Compile Include="VariableInjectorView.cs"> 130 143 <SubType>UserControl</SubType> … … 135 148 </ItemGroup> 136 149 <ItemGroup> 137 <ProjectReference Include="..\..\HeuristicLab.Constraints\3.2\HeuristicLab.Constraints-3.2.csproj">138 <Project>{FCD62C6F-4793-4593-AE9A-0BDCA256EE99}</Project>139 <Name>HeuristicLab.Constraints-3.2</Name>140 </ProjectReference>141 150 <ProjectReference Include="..\..\HeuristicLab.Core\3.2\HeuristicLab.Core-3.2.csproj"> 142 151 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> … … 157 166 </ItemGroup> 158 167 <ItemGroup> 159 <EmbeddedResource Include="AddVariableInfoDialog.resx"> 160 <DependentUpon>AddVariableInfoDialog.cs</DependentUpon> 161 <SubType>Designer</SubType> 162 </EmbeddedResource> 163 <EmbeddedResource Include="CombinedOperatorView.resx"> 164 <DependentUpon>CombinedOperatorView.cs</DependentUpon> 165 <SubType>Designer</SubType> 168 <EmbeddedResource Include="VariableInjectorView.resx"> 169 <DependentUpon>VariableInjectorView.cs</DependentUpon> 166 170 </EmbeddedResource> 167 171 </ItemGroup> -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/HeuristicLabOperatorsPlugin.cs
r1927 r2027 31 31 [ClassInfo(Name = "HeuristicLab.Operators-3.2")] 32 32 [PluginFile(Filename = "HeuristicLab.Operators-3.2.dll", Filetype = PluginFileType.Assembly)] 33 [Dependency(Dependency = "HeuristicLab.Constraints-3.2")]34 33 [Dependency(Dependency = "HeuristicLab.Core-3.2")] 35 34 [Dependency(Dependency = "HeuristicLab.Data-3.2")] -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ParallelProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied 43 43 /// to the given <paramref name="scope"/> with the <c>ExecuteInParallel</c> set to <c>true</c>.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 next.ExecuteInParallel = true; 47 47 for (int i = 0; i < SubOperators.Count; i++) 48 next.AddOperation(new AtomicOperation(SubOperators[i], scope));48 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope)); 49 49 return next; 50 50 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/ParallelSubScopesProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied 43 43 /// on the <c>i</c>th sub scope, the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 next.ExecuteInParallel = true; 47 47 for (int i = 0; i < scope.SubScopes.Count; i++) 48 next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i]));48 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope.SubScopes[i])); 49 49 return next; 50 50 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SequentialProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>n</c> operators applied 43 43 /// to the given <paramref name="scope"/>.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 for (int i = 0; i < SubOperators.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[i], scope));47 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope)); 48 48 return next; 49 49 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SequentialSubScopesProcessor.cs
r1530 r2027 42 42 /// <returns>A new <see cref="CompositeOperation"/> with the <c>i</c>th operator applied 43 43 /// on the <c>i</c>th sub scope.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 for (int i = 0; i < scope.SubScopes.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[i], scope.SubScopes[i]));47 next.AddOperation(new AtomicOperation(SubOperators[i], env, scope.SubScopes[i])); 48 48 return next; 49 49 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/SubScopesCreater.cs
r1530 r2027 41 41 public SubScopesCreater() 42 42 : base() { 43 Add VariableInfo(new VariableInfo("SubScopes", "Number of sub-scopes", typeof(IntData), VariableKind.In));43 AddParameter(new Parameter("SubScopes", "Number of sub-scopes", typeof(IntData), ParameterType.In)); 44 44 } 45 45 … … 49 49 /// <param name="scope">The scope where to create the sub scopes.</param> 50 50 /// <returns><c>null</c>.</returns> 51 public override IOperation Apply(I Scope scope) {52 IntData count = GetVariableValue<IntData>("SubScopes", scope, true);51 public override IOperation Apply(IEnvironment env, IScope scope) { 52 IntData count = scope.GetVariableValue<IntData>(env.TranslateName("SubScopes"), true); 53 53 54 54 for (int i = 0; i < count.Data; i++) -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/UniformParallelSubScopesProcessor.cs
r1530 r2027 43 43 /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes and 44 44 /// the <c>ExecuteInParallel</c> flag set to <c>true</c>.</returns> 45 public override IOperation Apply(I Scope scope) {45 public override IOperation Apply(IEnvironment env, IScope scope) { 46 46 CompositeOperation next = new CompositeOperation(); 47 47 next.ExecuteInParallel = true; 48 48 for (int i = 0; i < scope.SubScopes.Count; i++) 49 next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));49 next.AddOperation(new AtomicOperation(SubOperators[0], env, scope.SubScopes[i])); 50 50 return next; 51 51 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/UniformSequentialSubScopesProcessor.cs
r1530 r2027 42 42 /// <param name="scope">The scope on whose sub scopes the operator is applied.</param> 43 43 /// <returns>A new <see cref="CompositeOperation"/> with one operator and all sub scopes.</returns> 44 public override IOperation Apply(I Scope scope) {44 public override IOperation Apply(IEnvironment env, IScope scope) { 45 45 CompositeOperation next = new CompositeOperation(); 46 46 for (int i = 0; i < scope.SubScopes.Count; i++) 47 next.AddOperation(new AtomicOperation(SubOperators[0], scope.SubScopes[i]));47 next.AddOperation(new AtomicOperation(SubOperators[0], env, scope.SubScopes[i])); 48 48 return next; 49 49 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjector.cs
r1530 r2027 30 30 /// Class to inject local variables into the scope. 31 31 /// </summary> 32 public class VariableInjector : OperatorBase { 33 private Dictionary<IVariable, IVariableInfo> variableVariableInfoTable; 34 private Dictionary<IVariableInfo, IVariable> variableInfoVariableTable; 32 public class VariableInjector : OperatorBase, IVariablesContainer { 33 private Dictionary<string, IVariable> myVariables; 34 /// <summary> 35 /// Gets a collection of all variables of the current operator. 36 /// </summary> 37 public virtual ICollection<IVariable> Variables { 38 get { return myVariables.Values; } 39 } 35 40 36 41 /// <inheritdoc select="summary"/> 37 42 public override string Description { 38 get { return @"TODO\r\nOperator description still missing ..."; } 43 get { return @"Injects new variable into a scope."; } 44 } 45 46 /// <summary> 47 /// Overrides the Parameters property so that a parameter is returned for each injected variable. 48 /// </summary> 49 public override ICollection<IParameter> Parameters { 50 get { 51 List<IParameter> parameters = new List<IParameter>(); 52 foreach (IVariable variable in Variables) 53 parameters.Add(new Parameter(variable.Name, "Injected variable.", variable.Value.GetType(), ParameterType.Out)); 54 return parameters; 55 } 39 56 } 40 57 … … 44 61 public VariableInjector() 45 62 : base() { 46 variableVariableInfoTable = new Dictionary<IVariable, IVariableInfo>(); 47 variableInfoVariableTable = new Dictionary<IVariableInfo, IVariable>(); 63 myVariables = new Dictionary<string, IVariable>(); 48 64 } 49 65 … … 56 72 /// <returns>The cloned object as <see cref="VariableInjector"/>.</returns> 57 73 public override object Clone(IDictionary<Guid, object> clonedObjects) { 58 VariableInjector clone = new VariableInjector(); 59 clonedObjects.Add(Guid, clone); 60 clone.Name = Name; 74 VariableInjector clone = (VariableInjector)base.Clone(clonedObjects); 61 75 foreach (IVariable variable in Variables) 62 76 clone.AddVariable((IVariable)Auxiliary.Clone(variable, clonedObjects)); … … 65 79 66 80 /// <summary> 67 /// Adds the specified <paramref name="variable"/> to the current instance to get injected.68 /// </summary>69 /// <param name="variable">The variable to add.</param>70 /// <remarks>Calls private method <see cref="CreateVariableInfo"/> and <see cref="OperatorBase.AddVariable"/>71 /// of base class <see cref="OperatorBase"/>.</remarks>72 public override void AddVariable(IVariable variable) {73 base.AddVariable(variable);74 CreateVariableInfo(variable);75 }76 77 /// <summary>78 /// Removes a variable with the specified <paramref name="name"/> from the current injector.79 /// </summary>80 /// <remarks>Calls private method <see cref="DeleteVariableInfo"/> and <see cref="OperatorBase.RemoveVariable"/>81 /// of base class <see cref="OperatorBase"/>.</remarks>82 /// <param name="name">The name of the </param>83 public override void RemoveVariable(string name) {84 DeleteVariableInfo(name);85 base.RemoveVariable(name);86 }87 88 /// <summary>89 81 /// Adds the specified variables to the given <paramref name="scope"/> (and removes them first, 90 82 /// if they already exist in the current scope). … … 92 84 /// <param name="scope">The scope where to inject the variables.</param> 93 85 /// <returns><c>null</c>.</returns> 94 public override IOperation Apply(I Scope scope) {86 public override IOperation Apply(IEnvironment env, IScope scope) { 95 87 foreach (IVariable variable in Variables) { 96 88 if (scope.GetVariable(variable.Name) != null) … … 109 101 } 110 102 111 private void CreateVariableInfo(IVariable variable) { 112 IVariableInfo info = new VariableInfo(Guid.NewGuid().ToString(), "Injected variable", variable.Value.GetType(), VariableKind.New); 113 info.ActualName = variable.Name; 114 AddVariableInfo(info); 115 variableVariableInfoTable.Add(variable, info); 116 variableInfoVariableTable.Add(info, variable); 117 info.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged); 103 /// <summary> 104 /// Gets a variable with the given <paramref name="name"/>. 105 /// </summary> 106 /// <param name="name">The name of the variable.</param> 107 /// <returns>The variable with the specified name.</returns> 108 public virtual IVariable GetVariable(string name) { 109 IVariable variable; 110 if (myVariables.TryGetValue(name, out variable)) 111 return variable; 112 else 113 return null; 114 } 115 /// <summary> 116 /// Adds the specified <paramref name="variable"/> to the current instance. 117 /// </summary> 118 /// <param name="variable">The variable to add.</param> 119 public virtual void AddVariable(IVariable variable) { 120 myVariables.Add(variable.Name, variable); 121 variable.NameChanging += new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 118 122 variable.NameChanged += new EventHandler(Variable_NameChanged); 119 } 120 private void DeleteVariableInfo(string name) { 121 IVariable variable = GetVariable(name); 122 if (variable != null) { 123 IVariableInfo info = variableVariableInfoTable[variable]; 124 RemoveVariableInfo(info.FormalName); 125 variableVariableInfoTable.Remove(variable); 126 variableInfoVariableTable.Remove(info); 127 info.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged); 123 OnVariableAdded(variable); 124 } 125 /// <summary> 126 /// Deletes the variable with the specified <paramref name="name"/>. 127 /// </summary> 128 /// <param name="name">The name of the variable to delete.</param> 129 public virtual void RemoveVariable(string name) { 130 IVariable variable; 131 if (myVariables.TryGetValue(name, out variable)) { 132 variable.NameChanging -= new EventHandler<NameChangingEventArgs>(Variable_NameChanging); 128 133 variable.NameChanged -= new EventHandler(Variable_NameChanged); 129 } 130 } 131 132 #region VariableInfo and Variable Events 133 private void VariableInfo_ActualNameChanged(object sender, EventArgs e) { 134 IVariableInfo info = (IVariableInfo)sender; 135 IVariable variable = variableInfoVariableTable[info]; 136 variable.Name = info.ActualName; 134 myVariables.Remove(name); 135 OnVariableRemoved(variable); 136 } 137 } 138 private void Variable_NameChanging(object sender, NameChangingEventArgs e) { 139 e.Cancel = myVariables.ContainsKey(e.Name); 137 140 } 138 141 private void Variable_NameChanged(object sender, EventArgs e) { 139 142 IVariable variable = (IVariable)sender; 140 IVariableInfo info = variableVariableInfoTable[variable]; 141 info.ActualName = variable.Name; 142 } 143 #endregion 143 string oldName = null; 144 foreach (KeyValuePair<string, IVariable> element in myVariables) { 145 if (element.Value == variable) 146 oldName = element.Key; 147 } 148 myVariables.Remove(oldName); 149 myVariables.Add(variable.Name, variable); 150 } 151 152 /// <summary> 153 /// Occurs when a variable has been added. 154 /// </summary> 155 public event EventHandler<VariableEventArgs> VariableAdded; 156 /// <summary> 157 /// Fires a new <c>VariableAdded</c> event. 158 /// </summary> 159 /// <param name="variable">The variable that has been added.</param> 160 protected virtual void OnVariableAdded(IVariable variable) { 161 if (VariableAdded != null) 162 VariableAdded(this, new VariableEventArgs(variable)); 163 } 164 /// <summary> 165 /// Occurs when a variable has been deleted. 166 /// </summary> 167 public event EventHandler<VariableEventArgs> VariableRemoved; 168 /// <summary> 169 /// Fires a new <c>VariableRemoved</c> event. 170 /// </summary> 171 /// <param name="variable">The variable that has been removed</param> 172 protected virtual void OnVariableRemoved(IVariable variable) { 173 if (VariableRemoved != null) 174 VariableRemoved(this, new VariableEventArgs(variable)); 175 } 144 176 145 177 #region Persistence Methods 146 178 /// <summary> 147 179 /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>. 148 /// <note type="caution"> Variable infos are not persisted!</note> 149 /// </summary> 150 /// <remarks>Calls <see cref="OperatorBase.GetXmlNode"/> of base class <see cref="OperatorBase"/>.</remarks> 180 /// </summary> 181 /// <remarks> 182 /// Calls <see cref="OperatorBase.GetXmlNode"/> of base class <see cref="OperatorBase"/>. 183 /// <br/>A quick overview how the single elements of the current instance are saved: 184 /// <list type="bullet"> 185 /// <item> 186 /// <term>Variables: </term> 187 /// <description>Saved as child node with tag name <c>Variables</c>. All variables are themselves 188 /// saved as child nodes.</description> 189 /// </item> 190 /// </list> 191 /// </remarks> 151 192 /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param> 152 193 /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param> 153 194 /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param> 154 195 /// <returns>The saved <see cref="XmlNode"/>.</returns> 155 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {196 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 156 197 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 157 // variable infos should not be persisted 158 XmlNode infosNode = node.SelectSingleNode("VariableInfos"); 159 infosNode.RemoveAll(); 198 XmlNode variablesNode = document.CreateNode(XmlNodeType.Element, "Variables", null); 199 foreach (IVariable variable in myVariables.Values) 200 variablesNode.AppendChild(PersistenceManager.Persist(variable, document, persistedObjects)); 201 node.AppendChild(variablesNode); 160 202 return node; 203 } 204 /// <summary> 205 /// Loads the persisted variable injector from the specified <paramref name="node"/>. 206 /// </summary> 207 /// <remarks>Calls <see cref="OperatorBase.Populate"/> of base class 208 /// <see cref="OperatorBase"/>. 209 /// For informations how the different elements must be saved please see <see cref="GetXmlNode"/>.</remarks> 210 /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param> 211 /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param> 212 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 213 base.Populate(node, restoredObjects); 214 XmlNode variablesNode = node.SelectSingleNode("Variables"); 215 foreach (XmlNode variableNode in variablesNode.ChildNodes) 216 AddVariable((IVariable)PersistenceManager.Restore(variableNode, restoredObjects)); 161 217 } 162 218 #endregion -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjectorView.Designer.cs
r1530 r2027 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 components = new System.ComponentModel.Container(); 47 this.variablesTabPage = new System.Windows.Forms.TabPage(); 48 this.variablesContainerView = new HeuristicLab.Core.VariablesContainerView(); 49 this.tabControl.SuspendLayout(); 50 this.parametersTabPage.SuspendLayout(); 51 this.variablesTabPage.SuspendLayout(); 52 this.SuspendLayout(); 53 // 54 // tabControl 55 // 56 this.tabControl.Controls.Add(this.variablesTabPage); 57 this.tabControl.Controls.SetChildIndex(this.parametersTabPage, 0); 58 this.tabControl.Controls.SetChildIndex(this.variablesTabPage, 0); 59 // 60 // variablesTabPage 61 // 62 this.variablesTabPage.Controls.Add(this.variablesContainerView); 63 this.variablesTabPage.Location = new System.Drawing.Point(4, 22); 64 this.variablesTabPage.Name = "variablesTabPage"; 65 this.variablesTabPage.Padding = new System.Windows.Forms.Padding(3); 66 this.variablesTabPage.Size = new System.Drawing.Size(415, 307); 67 this.variablesTabPage.TabIndex = 4; 68 this.variablesTabPage.Text = "Variables"; 69 this.variablesTabPage.UseVisualStyleBackColor = true; 70 // 71 // variablesContainerView 72 // 73 this.variablesContainerView.Caption = "Variables Container"; 74 this.variablesContainerView.Dock = System.Windows.Forms.DockStyle.Fill; 75 this.variablesContainerView.Location = new System.Drawing.Point(3, 3); 76 this.variablesContainerView.Name = "variablesContainerView"; 77 this.variablesContainerView.Size = new System.Drawing.Size(409, 301); 78 this.variablesContainerView.TabIndex = 0; 79 this.variablesContainerView.VariablesContainer = null; 80 // 81 // VariableInjectorView 82 // 83 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 48 84 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 85 this.Name = "VariableInjectorView"; 86 this.tabControl.ResumeLayout(false); 87 this.parametersTabPage.ResumeLayout(false); 88 this.variablesTabPage.ResumeLayout(false); 89 this.ResumeLayout(false); 90 49 91 } 50 92 51 93 #endregion 94 95 private System.Windows.Forms.TabPage variablesTabPage; 96 private HeuristicLab.Core.VariablesContainerView variablesContainerView; 52 97 } 53 98 } -
branches/Operator Architecture Refactoring/HeuristicLab.Operators/3.2/VariableInjectorView.cs
r1530 r2027 60 60 VariableInjector = variableInjector; 61 61 } 62 63 /// <summary> 64 /// Removes event handlers in all children. 65 /// </summary> 66 protected override void RemoveItemEvents() { 67 variablesContainerView.VariablesContainer = null; 68 base.RemoveItemEvents(); 69 } 70 /// <summary> 71 /// Adds event handlers in all children. 72 /// </summary> 73 protected override void AddItemEvents() { 74 base.AddItemEvents(); 75 variablesContainerView.VariablesContainer = VariableInjector; 76 } 77 62 78 } 63 79 }
Note: See TracChangeset
for help on using the changeset viewer.