Changeset 2843 for trunk/sources/HeuristicLab.GP/3.3/FunctionView.cs
- Timestamp:
- 02/19/10 18:49:17 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP/3.3/FunctionView.cs
r2729 r2843 30 30 namespace HeuristicLab.GP { 31 31 public partial class FunctionView : ViewBase { 32 private Function function; 32 33 33 private const string ALL_SLOTS = "All"; 34 34 private string selectedSlot = ALL_SLOTS; 35 35 36 public FunctionView() { 36 public Function Function { 37 get { 38 return (Function)Item; 39 } 40 set { 41 Item = value; 42 } 43 } 44 45 public FunctionView() 46 : base() { 37 47 InitializeComponent(); 38 48 } 39 49 40 50 public FunctionView(Function function) 41 : this() {42 this.function = function;43 function.Changed += (sender, args) => UpdateControls();44 Refresh();51 : base() { 52 InitializeComponent(); 53 Function = function; 54 UpdateControls(); 45 55 } 46 56 47 57 protected override void UpdateControls() { 48 nameTextBox.Text = function.Name;49 minSubTreesTextBox.Text = function.MinSubTrees.ToString();50 maxSubTreesTextBox.Text = function.MaxSubTrees.ToString();51 ticketsTextBox.Text = function.Tickets.ToString();52 minTreeHeightTextBox.Text = function.MinTreeHeight.ToString();53 minTreeSizeTextBox.Text = function.MinTreeSize.ToString();54 if ( function.Initializer != null) {55 initializerTextBox.Text = function.Initializer.Name;58 nameTextBox.Text = Function.Name; 59 minSubTreesTextBox.Text = Function.MinSubTrees.ToString(); 60 maxSubTreesTextBox.Text = Function.MaxSubTrees.ToString(); 61 ticketsTextBox.Text = Function.Tickets.ToString(); 62 minTreeHeightTextBox.Text = Function.MinTreeHeight.ToString(); 63 minTreeSizeTextBox.Text = Function.MinTreeSize.ToString(); 64 if (Function.Initializer != null) { 65 initializerTextBox.Text = Function.Initializer.Name; 56 66 } else { 57 67 initializerTextBox.Enabled = false; 58 68 editInitializerButton.Enabled = false; 59 69 } 60 if ( function.Manipulator != null) {61 manipulatorTextBox.Text = function.Manipulator.Name;70 if (Function.Manipulator != null) { 71 manipulatorTextBox.Text = Function.Manipulator.Name; 62 72 } else { 63 73 manipulatorTextBox.Enabled = false; … … 67 77 argumentComboBox.Items.Clear(); 68 78 argumentComboBox.Items.Add(ALL_SLOTS); 69 for (int i = 0; i < function.MaxSubTrees; i++) {79 for (int i = 0; i < Function.MaxSubTrees; i++) { 70 80 argumentComboBox.Items.Add(i.ToString()); 71 81 } … … 75 85 76 86 private void UpdateAllowedSubFunctionsList() { 77 if ( function.MaxSubTrees > 0) {87 if (Function.MaxSubTrees > 0) { 78 88 subFunctionsListBox.Items.Clear(); 79 89 if (selectedSlot == ALL_SLOTS) { 80 IEnumerable<IFunction> functionSet = function.GetAllowedSubFunctions(0);81 for (int i = 1; i < function.MaxSubTrees; i++) {82 functionSet = functionSet.Intersect( function.GetAllowedSubFunctions(i));90 IEnumerable<IFunction> functionSet = Function.GetAllowedSubFunctions(0); 91 for (int i = 1; i < Function.MaxSubTrees; i++) { 92 functionSet = functionSet.Intersect(Function.GetAllowedSubFunctions(i)); 83 93 } 84 94 foreach (var subFun in functionSet) { … … 87 97 } else { 88 98 int slot = int.Parse(selectedSlot); 89 foreach (var subFun in function.GetAllowedSubFunctions(slot)) {99 foreach (var subFun in Function.GetAllowedSubFunctions(slot)) { 90 100 subFunctionsListBox.Items.Add(subFun); 91 101 } … … 100 110 string name = nameTextBox.Text; 101 111 if (!string.IsNullOrEmpty(name)) { 102 function.Name = name;112 Function.Name = name; 103 113 functionPropertiesErrorProvider.SetError(nameTextBox, string.Empty); 104 114 } else { … … 110 120 int minSubTrees; 111 121 if (int.TryParse(minSubTreesTextBox.Text, out minSubTrees) && minSubTrees >= 0) { 112 function.MinSubTrees = minSubTrees;122 Function.MinSubTrees = minSubTrees; 113 123 functionPropertiesErrorProvider.SetError(minSubTreesTextBox, string.Empty); 114 124 } else { … … 120 130 int maxSubTrees; 121 131 if (int.TryParse(maxSubTreesTextBox.Text, out maxSubTrees) && maxSubTrees >= 0) { 122 function.MaxSubTrees = maxSubTrees;132 Function.MaxSubTrees = maxSubTrees; 123 133 functionPropertiesErrorProvider.SetError(maxSubTreesTextBox, string.Empty); 124 134 } else { … … 130 140 double tickets; 131 141 if (double.TryParse(ticketsTextBox.Text, out tickets) && tickets >= 0) { 132 function.Tickets = tickets;142 Function.Tickets = tickets; 133 143 functionPropertiesErrorProvider.SetError(ticketsTextBox, string.Empty); 134 144 } else { … … 138 148 139 149 private void editInitializerButton_Click(object sender, EventArgs e) { 140 ControlManager.Manager.ShowControl( function.Initializer.CreateView());150 ControlManager.Manager.ShowControl(Function.Initializer.CreateView()); 141 151 } 142 152 143 153 private void editManipulatorButton_Click(object sender, EventArgs e) { 144 ControlManager.Manager.ShowControl( function.Manipulator.CreateView());154 ControlManager.Manager.ShowControl(Function.Manipulator.CreateView()); 145 155 } 146 156 … … 168 178 Cursor = Cursors.WaitCursor; 169 179 if (selectedSlot == ALL_SLOTS) { 170 for (int slot = 0; slot < function.MaxSubTrees; slot++)171 function.AddAllowedSubFunction(fun, slot);180 for (int slot = 0; slot < Function.MaxSubTrees; slot++) 181 Function.AddAllowedSubFunction(fun, slot); 172 182 } else { 173 183 int slot = int.Parse(selectedSlot); 174 function.AddAllowedSubFunction(fun, slot);184 Function.AddAllowedSubFunction(fun, slot); 175 185 } 176 186 } … … 188 198 if (selectedSlot == ALL_SLOTS) { 189 199 List<IFunction> removedSubFunctions = new List<IFunction>(subFunctionsListBox.SelectedItems.Cast<IFunction>()); 190 for (int slot = 0; slot < function.MaxSubTrees; slot++) {200 for (int slot = 0; slot < Function.MaxSubTrees; slot++) { 191 201 foreach (var subFun in removedSubFunctions) { 192 function.RemoveAllowedSubFunction((IFunction)subFun, slot);202 Function.RemoveAllowedSubFunction((IFunction)subFun, slot); 193 203 } 194 204 } … … 197 207 List<IFunction> removedSubFunctions = new List<IFunction>(subFunctionsListBox.SelectedItems.Cast<IFunction>()); 198 208 foreach (var subFun in removedSubFunctions) { 199 function.RemoveAllowedSubFunction(subFun, slot);209 Function.RemoveAllowedSubFunction(subFun, slot); 200 210 } 201 211 }
Note: See TracChangeset
for help on using the changeset viewer.