- Timestamp:
- 10/14/08 14:42:29 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GpPluginsRefactoringBranch/HeuristicLab.GP/FunctionView.cs
r645 r654 38 38 private IFunctionTree selectedBranch; 39 39 private IVariable selectedVariable; 40 private IFunctionTreeNameGenerator nameGenerator; 41 private IFunctionTreeNameGenerator[] allNameGenerators; 40 42 41 // private FunctionNameVisitor functionNameVisitor;42 43 public FunctionTreeView() { 44 nameGenerator = new DefaultFunctionTreeNameGenerator(); 43 45 InitializeComponent(); 44 // functionNameVisitor = new FunctionNameVisitor(); 46 47 DiscoveryService discoveryService = new DiscoveryService(); 48 allNameGenerators = discoveryService.GetInstances<IFunctionTreeNameGenerator>(); 49 50 foreach(IFunctionTreeNameGenerator generator in allNameGenerators) { 51 ToolStripButton button = new ToolStripButton(generator.Name, null, 52 delegate(object source, EventArgs args) { 53 this.nameGenerator = generator; 54 foreach(ToolStripButton otherButton in representationContextMenu.Items) otherButton.Checked = false; 55 ((ToolStripButton)source).Checked = true; 56 UpdateControls(); 57 }); 58 if(generator is DefaultFunctionTreeNameGenerator) button.Checked = true; 59 else button.Checked = false; 60 representationContextMenu.Items.Add(button); 61 } 45 62 } 46 63 … … 53 70 protected override void UpdateControls() { 54 71 funTreeView.Nodes.Clear(); 55 //functionNameVisitor.Visit(functionTree);56 72 TreeNode rootNode = new TreeNode(); 57 73 rootNode.Name = functionTree.Function.Name; 58 //rootNode.Text = functionNameVisitor.Name;74 rootNode.Text = nameGenerator.GetName(functionTree); 59 75 rootNode.Tag = functionTree; 76 treeNodeContextMenu.Items.Clear(); 77 DiscoveryService discoveryService = new DiscoveryService(); 78 IFunctionTreeExporter[] exporters = discoveryService.GetInstances<IFunctionTreeExporter>(); 79 if(exporters.Length>0) 80 treeNodeContextMenu.Items.Add(new ToolStripSeparator()); 81 foreach(IFunctionTreeExporter exporter in exporters) { 82 string result; 83 // register a menu item for the exporter 84 ToolStripItem item = new ToolStripButton("Copy to clip-board (" + exporter.Name + ")", null, 85 delegate(object source, EventArgs args) { 86 TreeNode node = funTreeView.SelectedNode; 87 if(node == null || node.Tag == null) return; 88 Clipboard.SetText(exporter.Export((IFunctionTree)node.Tag)); 89 }); 90 // try to export the whole tree 91 if(exporter.TryExport(functionTree, out result)) { 92 // if it worked enable the context-menu item 93 item.Enabled = true; 94 } else { 95 item.Enabled = false; 96 } 97 treeNodeContextMenu.Items.Add(item); 98 } 60 99 rootNode.ContextMenuStrip = treeNodeContextMenu; 61 100 funTreeView.Nodes.Add(rootNode); … … 69 108 private void CreateTree(TreeNode rootNode, IFunctionTree functionTree) { 70 109 TreeNode node = new TreeNode(); 71 // functionNameVisitor.Visit(functionTree);72 110 node.Name = functionTree.Function.Name; 73 // node.Text = functionNameVisitor.Name;111 node.Text = nameGenerator.GetName(functionTree); 74 112 node.Tag = functionTree; 75 113 node.ContextMenuStrip = treeNodeContextMenu; … … 88 126 IFunctionTree selectedBranch = (IFunctionTree)funTreeView.SelectedNode.Tag; 89 127 UpdateVariablesList(selectedBranch); 90 templateTextBox.Text = selectedBranch.Function.Name;128 templateTextBox.Text = nameGenerator.GetName(selectedBranch); 91 129 this.selectedBranch = selectedBranch; 92 130 editButton.Enabled = true; … … 122 160 if(funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) { 123 161 TreeNode node = funTreeView.SelectedNode; 124 // functionNameVisitor.Visit(selectedBranch); 125 // node.Text = functionNameVisitor.Name; 162 node.Text = nameGenerator.GetName(functionTree); 126 163 } 127 164 } … … 129 166 protected virtual void editButton_Click(object sender, EventArgs e) { 130 167 PluginManager.ControlManager.ShowControl(selectedBranch.Function.CreateView()); 131 }132 133 private void copyToClipboardMenuItem_Click(object sender, EventArgs e) {134 TreeNode node = funTreeView.SelectedNode;135 if(node == null || node.Tag == null) return;136 137 //ModelAnalyzerExporter visitor = new ModelAnalyzerExporter();138 //visitor.Visit((IFunctionTree)node.Tag);139 //Clipboard.SetText(visitor.ModelAnalyzerPrefix);140 }141 142 private void copyToClipboardSExpressionToolStripMenuItem_Click(object sender, EventArgs e) {143 TreeNode node = funTreeView.SelectedNode;144 if(node == null || node.Tag == null) return;145 146 //string sexp = ((IFunctionTree)node.Tag).ToString();147 //Clipboard.SetText(sexp);148 168 } 149 169 … … 154 174 } 155 175 } 156 157 //private class FunctionNameVisitor : IFunctionVisitor {158 // string name;159 // IFunctionTree currentBranch;160 161 // public string Name {162 // get { return name; }163 // }164 165 // public void Visit(IFunctionTree tree) {166 // currentBranch = tree;167 // tree.Function.Accept(this);168 // }169 170 // #region IFunctionVisitor Members171 // public void Visit(IFunction function) {172 // name = function.Name;173 // }174 175 // public void Visit(Addition addition) {176 // name = "+";177 // }178 179 // public void Visit(Constant constant) {180 // name = ((ConstrainedDoubleData)(currentBranch.GetLocalVariable(HeuristicLab.Functions.Constant.VALUE).Value)).Data + "";181 // }182 183 // public void Visit(Cosinus cosinus) {184 // name = "Sin";185 // }186 187 // public void Visit(Differential diff) {188 // string timeOffset = "";189 // int sampleOffset = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Differential.OFFSET).Value).Data;190 // int variableIndex = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Differential.INDEX).Value).Data;191 // double weight = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Differential.WEIGHT).Value).Data;192 // if(sampleOffset < 0) {193 // timeOffset = "(t" + sampleOffset + ")";194 // } else if(sampleOffset > 0) {195 // timeOffset = "(t+" + sampleOffset + ")";196 // } else {197 // timeOffset = "";198 // }199 // name = "Diff" + variableIndex + timeOffset + " * " + weight;200 // }201 202 // public void Visit(Division division) {203 // name = "/";204 // }205 206 // public void Visit(Exponential exponential) {207 // name = "Exp";208 // }209 210 // public void Visit(Logarithm logarithm) {211 // name = "Log";212 // }213 214 // public void Visit(Multiplication multiplication) {215 // name = "*";216 // }217 218 // public void Visit(Power power) {219 // name = "Pow";220 // }221 222 // public void Visit(Signum signum) {223 // name = "Sign";224 // }225 226 // public void Visit(Sinus sinus) {227 // name = "Sin";228 // }229 230 // public void Visit(Sqrt sqrt) {231 // name = "Sqrt";232 // }233 234 // public void Visit(Subtraction substraction) {235 // name = "-";236 // }237 238 // public void Visit(Tangens tangens) {239 // name = "Tan";240 // }241 242 // public void Visit(Variable variable) {243 // string timeOffset = "";244 // int sampleOffset = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.OFFSET).Value).Data;245 // int variableIndex = ((ConstrainedIntData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.INDEX).Value).Data;246 // double weight = ((ConstrainedDoubleData)currentBranch.GetLocalVariable(HeuristicLab.Functions.Variable.WEIGHT).Value).Data;247 // if(sampleOffset < 0) {248 // timeOffset = "(t" + sampleOffset + ")";249 // } else if(sampleOffset > 0) {250 // timeOffset = "(t+" + sampleOffset + ")";251 // } else {252 // timeOffset = "";253 // }254 // name = "Var" + variableIndex + timeOffset + " * " + weight;255 // }256 257 // public void Visit(And and) {258 // name = "And";259 // }260 261 // public void Visit(Average average) {262 // name = "Avg";263 // }264 265 // public void Visit(IfThenElse ifThenElse) {266 // name = "IFTE";267 // }268 269 // public void Visit(Not not) {270 // name = "Not";271 // }272 273 // public void Visit(Or or) {274 // name = "Or";275 // }276 277 // public void Visit(Xor xor) {278 // name = "Xor";279 // }280 281 // public void Visit(Equal equal) {282 // name = "eq?";283 // }284 285 // public void Visit(LessThan lessThan) {286 // name = "<";287 // }288 289 // public void Visit(GreaterThan greaterThan) {290 // name = ">";291 // }292 // #endregion293 //}294 176 } 295 177 }
Note: See TracChangeset
for help on using the changeset viewer.