Changeset 1226 for branches/CEDMA-Refactoring-Ticket419
- Timestamp:
- 02/25/09 11:49:10 (16 years ago)
- Location:
- branches/CEDMA-Refactoring-Ticket419
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/ModelAnalyzerExporter.cs
r656 r1226 48 48 public string Export(IFunctionTree tree) { 49 49 string result = ExportFunction(tree.Function, tree); 50 result += "(\n"; 50 if(tree.SubTrees.Count>0) 51 result += "(\n"; 51 52 foreach(IFunctionTree subTree in tree.SubTrees) { 52 53 result += Export(subTree); -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP/FunctionView.cs
r656 r1226 51 51 representationsMenu.Text = "Tree representation"; 52 52 representationsMenu.Name = "Tree representation"; 53 foreach(IFunctionTreeNameGenerator generator in allNameGenerators) { 54 MenuItem mi = new MenuItem(generator.Name, 55 delegate(object source, EventArgs args) { 56 IFunctionTreeNameGenerator g = (IFunctionTreeNameGenerator)((MenuItem)source).Tag; 57 this.nameGenerator = g; 58 foreach(MenuItem otherMenuItem in representationsMenu.MenuItems) otherMenuItem.Checked = false; 59 ((MenuItem)source).Checked = true; 60 UpdateControls(); 61 }, Shortcut.None); 62 if(generator is DefaultFunctionTreeNameGenerator) mi.Checked = true; 53 foreach (IFunctionTreeNameGenerator generator in allNameGenerators) { 54 MenuItem mi = new MenuItem(generator.Name, MakeNameGeneratorDelegate(generator), Shortcut.None); 55 if (generator is DefaultFunctionTreeNameGenerator) mi.Checked = true; 63 56 else mi.Checked = false; 64 57 mi.Tag = generator; … … 83 76 DiscoveryService discoveryService = new DiscoveryService(); 84 77 IFunctionTreeExporter[] exporters = discoveryService.GetInstances<IFunctionTreeExporter>(); 85 foreach (IFunctionTreeExporter exporter in exporters) {78 foreach (IFunctionTreeExporter exporter in exporters) { 86 79 string result; 87 80 // register a menu item for the exporter 88 MenuItem item = new MenuItem("Copy to clip-board (" + exporter.Name + ")", 89 delegate(object source, EventArgs args) { 90 TreeNode node = funTreeView.SelectedNode; 91 if(node == null || node.Tag == null) return; 92 Clipboard.SetText(exporter.Export((IFunctionTree)node.Tag)); 93 }, Shortcut.None); 81 MenuItem item = new MenuItem("Copy to clip-board (" + exporter.Name + ")", 82 MakeExporterDelegate(exporter), Shortcut.None); 94 83 // try to export the whole tree 95 if (exporter.TryExport(functionTree, out result)) {84 if (exporter.TryExport(functionTree, out result)) { 96 85 // if it worked enable the context-menu item 97 86 item.Enabled = true; … … 104 93 funTreeView.Nodes.Add(rootNode); 105 94 106 foreach (IFunctionTree subTree in functionTree.SubTrees) {95 foreach (IFunctionTree subTree in functionTree.SubTrees) { 107 96 CreateTree(rootNode, subTree); 108 97 } 109 98 funTreeView.ExpandAll(); 99 } 100 101 private EventHandler MakeNameGeneratorDelegate(IFunctionTreeNameGenerator generator) { 102 return delegate(object source, EventArgs args) { 103 IFunctionTreeNameGenerator g = (IFunctionTreeNameGenerator)((MenuItem)source).Tag; 104 this.nameGenerator = g; 105 foreach (MenuItem otherMenuItem in representationsMenu.MenuItems) otherMenuItem.Checked = false; 106 ((MenuItem)source).Checked = true; 107 UpdateControls(); 108 }; 109 } 110 111 private EventHandler MakeExporterDelegate(IFunctionTreeExporter exporter) { 112 return delegate(object source, EventArgs args) { 113 TreeNode node = funTreeView.SelectedNode; 114 if (node == null || node.Tag == null) return; 115 Clipboard.SetText(exporter.Export((IFunctionTree)node.Tag)); 116 }; 110 117 } 111 118 … … 117 124 node.ContextMenu = treeNodeContextMenu; 118 125 rootNode.Nodes.Add(node); 119 foreach (IFunctionTree subTree in functionTree.SubTrees) {126 foreach (IFunctionTree subTree in functionTree.SubTrees) { 120 127 CreateTree(node, subTree); 121 128 } … … 127 134 templateTextBox.Clear(); 128 135 editButton.Enabled = false; 129 if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) {136 if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) { 130 137 IFunctionTree selectedBranch = (IFunctionTree)funTreeView.SelectedNode.Tag; 131 138 UpdateVariablesList(selectedBranch); … … 137 144 138 145 private void UpdateVariablesList(IFunctionTree functionTree) { 139 foreach (IVariable variable in functionTree.LocalVariables) {146 foreach (IVariable variable in functionTree.LocalVariables) { 140 147 variablesListBox.Items.Add(variable.Name); 141 148 } … … 144 151 private void variablesListBox_SelectedIndexChanged(object sender, EventArgs e) { 145 152 // in case we had an event-handler registered for a different variable => unregister the event-handler 146 if (selectedVariable != null) {153 if (selectedVariable != null) { 147 154 selectedVariable.Value.Changed -= new EventHandler(selectedVariable_ValueChanged); 148 155 } 149 if (variablesListBox.SelectedItem != null) {156 if (variablesListBox.SelectedItem != null) { 150 157 string selectedVariableName = (string)variablesListBox.SelectedItem; 151 158 selectedVariable = selectedBranch.GetLocalVariable(selectedVariableName); … … 162 169 163 170 void selectedVariable_ValueChanged(object sender, EventArgs e) { 164 if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) {171 if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) { 165 172 TreeNode node = funTreeView.SelectedNode; 166 173 node.Text = nameGenerator.GetName(functionTree); … … 173 180 174 181 private void funTreeView_MouseUp(object sender, MouseEventArgs e) { 175 if (e.Button == MouseButtons.Right) {182 if (e.Button == MouseButtons.Right) { 176 183 // Select the clicked node 177 184 funTreeView.SelectedNode = funTreeView.GetNodeAt(e.X, e.Y);
Note: See TracChangeset
for help on using the changeset viewer.