Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1227


Ignore:
Timestamp:
02/25/09 11:50:52 (15 years ago)
Author:
gkronber
Message:

merged fix for #472 (Export of HL3 function trees to HL2 import format (copy-to-clipboard) doesn't work) r1226 from CEDMA refactoring branch to trunk.

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/ModelAnalyzerExporter.cs

    r656 r1227  
    4848    public string Export(IFunctionTree tree) {
    4949      string result = ExportFunction(tree.Function, tree);
    50       result += "(\n";
     50      if(tree.SubTrees.Count>0)
     51        result += "(\n";
    5152      foreach(IFunctionTree subTree in tree.SubTrees) {
    5253        result += Export(subTree);
  • trunk/sources/HeuristicLab.GP/FunctionView.cs

    r656 r1227  
    5151      representationsMenu.Text = "Tree representation";
    5252      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;
    6356        else mi.Checked = false;
    6457        mi.Tag = generator;
     
    8376      DiscoveryService discoveryService = new DiscoveryService();
    8477      IFunctionTreeExporter[] exporters = discoveryService.GetInstances<IFunctionTreeExporter>();
    85       foreach(IFunctionTreeExporter exporter in exporters) {
     78      foreach (IFunctionTreeExporter exporter in exporters) {
    8679        string result;
    8780        // 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);
    9483        // try to export the whole tree
    95         if(exporter.TryExport(functionTree, out result)) {
     84        if (exporter.TryExport(functionTree, out result)) {
    9685          // if it worked enable the context-menu item
    9786          item.Enabled = true;
     
    10493      funTreeView.Nodes.Add(rootNode);
    10594
    106       foreach(IFunctionTree subTree in functionTree.SubTrees) {
     95      foreach (IFunctionTree subTree in functionTree.SubTrees) {
    10796        CreateTree(rootNode, subTree);
    10897      }
    10998      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      };
    110117    }
    111118
     
    117124      node.ContextMenu = treeNodeContextMenu;
    118125      rootNode.Nodes.Add(node);
    119       foreach(IFunctionTree subTree in functionTree.SubTrees) {
     126      foreach (IFunctionTree subTree in functionTree.SubTrees) {
    120127        CreateTree(node, subTree);
    121128      }
     
    127134      templateTextBox.Clear();
    128135      editButton.Enabled = false;
    129       if(funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) {
     136      if (funTreeView.SelectedNode != null && funTreeView.SelectedNode.Tag != null) {
    130137        IFunctionTree selectedBranch = (IFunctionTree)funTreeView.SelectedNode.Tag;
    131138        UpdateVariablesList(selectedBranch);
     
    137144
    138145    private void UpdateVariablesList(IFunctionTree functionTree) {
    139       foreach(IVariable variable in functionTree.LocalVariables) {
     146      foreach (IVariable variable in functionTree.LocalVariables) {
    140147        variablesListBox.Items.Add(variable.Name);
    141148      }
     
    144151    private void variablesListBox_SelectedIndexChanged(object sender, EventArgs e) {
    145152      // in case we had an event-handler registered for a different variable => unregister the event-handler
    146       if(selectedVariable != null) {
     153      if (selectedVariable != null) {
    147154        selectedVariable.Value.Changed -= new EventHandler(selectedVariable_ValueChanged);
    148155      }
    149       if(variablesListBox.SelectedItem != null) {
     156      if (variablesListBox.SelectedItem != null) {
    150157        string selectedVariableName = (string)variablesListBox.SelectedItem;
    151158        selectedVariable = selectedBranch.GetLocalVariable(selectedVariableName);
     
    162169
    163170    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) {
    165172        TreeNode node = funTreeView.SelectedNode;
    166173        node.Text = nameGenerator.GetName(functionTree);
     
    173180
    174181    private void funTreeView_MouseUp(object sender, MouseEventArgs e) {
    175       if(e.Button == MouseButtons.Right) {
     182      if (e.Button == MouseButtons.Right) {
    176183        // Select the clicked node
    177184        funTreeView.SelectedNode = funTreeView.GetNodeAt(e.X, e.Y);
Note: See TracChangeset for help on using the changeset viewer.