Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6415


Ignore:
Timestamp:
06/15/11 23:02:01 (13 years ago)
Author:
mkommend
Message:

#1479: Merged trunk changes, refactored grammar editor and added copy functionality.

Location:
branches/GP.Grammar.Editor
Files:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj

    r6403 r6415  
    110110  </ItemGroup>
    111111  <ItemGroup>
     112    <Compile Include="SymbolicExpressionGrammarAllowedChildSymbolsControl.cs">
     113      <SubType>UserControl</SubType>
     114    </Compile>
     115    <Compile Include="SymbolicExpressionGrammarAllowedChildSymbolsControl.Designer.cs">
     116      <DependentUpon>SymbolicExpressionGrammarAllowedChildSymbolsControl.cs</DependentUpon>
     117    </Compile>
    112118    <Compile Include="SymbolicExpressionGrammarEditorView.cs">
    113119      <SubType>UserControl</SubType>
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs

    r6403 r6415  
    2828      this.grpSymbols = new System.Windows.Forms.GroupBox();
    2929      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
     30      this.copyButton = new System.Windows.Forms.Button();
    3031      this.showDetailsCheckBox = new System.Windows.Forms.CheckBox();
    3132      this.removeButton = new System.Windows.Forms.Button();
    3233      this.addButton = new System.Windows.Forms.Button();
    33       this.symbolsTreeView = new System.Windows.Forms.TreeView();
     34      this.symbolsTreeView = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.CheckBoxTreeView();
    3435      this.imageList = new System.Windows.Forms.ImageList(this.components);
    3536      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
    36       this.allowedChildSymbolsControl = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
     37      this.allowedChildSymbolsControl = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionGrammarAllowedChildSymbolsControl();
     38      this.symbolDetailsGroupBox = new System.Windows.Forms.GroupBox();
    3739      this.symbolDetailsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    3840      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     
    4648      this.splitContainer2.Panel2.SuspendLayout();
    4749      this.splitContainer2.SuspendLayout();
     50      this.symbolDetailsGroupBox.SuspendLayout();
    4851      this.SuspendLayout();
    4952      //
     
    7982      // splitContainer1.Panel1
    8083      //
     84      this.splitContainer1.Panel1.Controls.Add(this.copyButton);
    8185      this.splitContainer1.Panel1.Controls.Add(this.showDetailsCheckBox);
    8286      this.splitContainer1.Panel1.Controls.Add(this.removeButton);
     
    9195      this.splitContainer1.TabIndex = 0;
    9296      //
     97      // copyButton
     98      //
     99      this.copyButton.Enabled = false;
     100      this.copyButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Copy;
     101      this.copyButton.Location = new System.Drawing.Point(33, 3);
     102      this.copyButton.Name = "copyButton";
     103      this.copyButton.Size = new System.Drawing.Size(24, 24);
     104      this.copyButton.TabIndex = 8;
     105      this.toolTip.SetToolTip(this.copyButton, "Copy Symbol");
     106      this.copyButton.UseVisualStyleBackColor = true;
     107      this.copyButton.Click += new System.EventHandler(this.copyButton_Click);
     108      //
    93109      // showDetailsCheckBox
    94110      //
     
    97113      this.showDetailsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
    98114      this.showDetailsCheckBox.Image = HeuristicLab.Common.Resources.VSImageLibrary.Properties;
    99       this.showDetailsCheckBox.Location = new System.Drawing.Point(63, 3);
     115      this.showDetailsCheckBox.Location = new System.Drawing.Point(93, 3);
    100116      this.showDetailsCheckBox.Name = "showDetailsCheckBox";
    101117      this.showDetailsCheckBox.Size = new System.Drawing.Size(24, 24);
     
    109125      this.removeButton.Enabled = false;
    110126      this.removeButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Remove;
    111       this.removeButton.Location = new System.Drawing.Point(33, 3);
     127      this.removeButton.Location = new System.Drawing.Point(63, 3);
    112128      this.removeButton.Name = "removeButton";
    113129      this.removeButton.Size = new System.Drawing.Size(24, 24);
    114130      this.removeButton.TabIndex = 6;
    115       this.toolTip.SetToolTip(this.removeButton, "Remove");
     131      this.toolTip.SetToolTip(this.removeButton, "Remove Symbol");
    116132      this.removeButton.UseVisualStyleBackColor = true;
    117133      this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
     
    124140      this.addButton.Size = new System.Drawing.Size(24, 24);
    125141      this.addButton.TabIndex = 5;
    126       this.toolTip.SetToolTip(this.addButton, "Add");
     142      this.toolTip.SetToolTip(this.addButton, "Add Symbol");
    127143      this.addButton.UseVisualStyleBackColor = true;
    128144      this.addButton.Click += new System.EventHandler(this.addButton_Click);
     
    130146      // symbolsTreeView
    131147      //
     148      this.symbolsTreeView.AllowDrop = true;
    132149      this.symbolsTreeView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    133150            | System.Windows.Forms.AnchorStyles.Left)
    134151            | System.Windows.Forms.AnchorStyles.Right)));
    135152      this.symbolsTreeView.CheckBoxes = true;
     153      this.symbolsTreeView.HideSelection = false;
    136154      this.symbolsTreeView.ImageIndex = 0;
    137155      this.symbolsTreeView.ImageList = this.imageList;
     
    144162      this.symbolsTreeView.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.symbolsTreeView_ItemDrag);
    145163      this.symbolsTreeView.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.symbolsTreeView_AfterSelect);
     164      this.symbolsTreeView.DragDrop += new System.Windows.Forms.DragEventHandler(this.symbolsTreeView_DragDrop);
     165      this.symbolsTreeView.DragEnter += new System.Windows.Forms.DragEventHandler(this.symbolsTreeView_DragEnter);
     166      this.symbolsTreeView.DragOver += new System.Windows.Forms.DragEventHandler(this.symbolsTreeView_DragOver);
    146167      //
    147168      // imageList
     
    164185      // splitContainer2.Panel2
    165186      //
    166       this.splitContainer2.Panel2.Controls.Add(this.symbolDetailsViewHost);
     187      this.splitContainer2.Panel2.Controls.Add(this.symbolDetailsGroupBox);
    167188      this.splitContainer2.Size = new System.Drawing.Size(568, 359);
    168189      this.splitContainer2.SplitterDistance = 165;
     
    172193      //
    173194      this.allowedChildSymbolsControl.AllowDrop = true;
    174       this.allowedChildSymbolsControl.BackgroundColor = System.Drawing.Color.White;
    175195      this.allowedChildSymbolsControl.Dock = System.Windows.Forms.DockStyle.Fill;
    176       this.allowedChildSymbolsControl.LineColor = System.Drawing.Color.Black;
     196      this.allowedChildSymbolsControl.Grammar = null;
    177197      this.allowedChildSymbolsControl.Location = new System.Drawing.Point(0, 0);
    178198      this.allowedChildSymbolsControl.Name = "allowedChildSymbolsControl";
    179199      this.allowedChildSymbolsControl.Size = new System.Drawing.Size(568, 165);
    180       this.allowedChildSymbolsControl.Spacing = 5;
     200      this.allowedChildSymbolsControl.Symbol = null;
    181201      this.allowedChildSymbolsControl.TabIndex = 0;
    182       this.allowedChildSymbolsControl.TextFont = new System.Drawing.Font("Times New Roman", 8F);
    183       this.allowedChildSymbolsControl.Tree = null;
    184       this.allowedChildSymbolsControl.SymbolicExpressionTreeNodeClicked += new System.Windows.Forms.MouseEventHandler(this.symbolicExpressionTreeChart_SymbolicExpressionTreeNodeClicked);
    185       this.allowedChildSymbolsControl.DragDrop += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragDrop);
    186       this.allowedChildSymbolsControl.DragEnter += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragEnter);
    187       this.allowedChildSymbolsControl.DragOver += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragOver);
    188       this.allowedChildSymbolsControl.Paint += new System.Windows.Forms.PaintEventHandler(this.allowedChildSymbolsControl_Paint);
    189       this.allowedChildSymbolsControl.KeyDown += new System.Windows.Forms.KeyEventHandler(this.symbolicExpressionTreeChart_KeyDown);
    190       this.allowedChildSymbolsControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.allowedChildSymbolsControl_MouseDown);
     202      //
     203      // symbolDetailsGroupBox
     204      //
     205      this.symbolDetailsGroupBox.Controls.Add(this.symbolDetailsViewHost);
     206      this.symbolDetailsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     207      this.symbolDetailsGroupBox.Location = new System.Drawing.Point(0, 0);
     208      this.symbolDetailsGroupBox.Name = "symbolDetailsGroupBox";
     209      this.symbolDetailsGroupBox.Size = new System.Drawing.Size(568, 190);
     210      this.symbolDetailsGroupBox.TabIndex = 1;
     211      this.symbolDetailsGroupBox.TabStop = false;
     212      this.symbolDetailsGroupBox.Text = "Symbol Details";
    191213      //
    192214      // symbolDetailsViewHost
     
    196218      this.symbolDetailsViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
    197219      this.symbolDetailsViewHost.Enabled = false;
    198       this.symbolDetailsViewHost.Location = new System.Drawing.Point(0, 0);
     220      this.symbolDetailsViewHost.Location = new System.Drawing.Point(3, 16);
    199221      this.symbolDetailsViewHost.Name = "symbolDetailsViewHost";
    200222      this.symbolDetailsViewHost.ReadOnly = false;
    201       this.symbolDetailsViewHost.Size = new System.Drawing.Size(568, 190);
    202       this.symbolDetailsViewHost.TabIndex = 0;
     223      this.symbolDetailsViewHost.Size = new System.Drawing.Size(562, 171);
     224      this.symbolDetailsViewHost.TabIndex = 1;
    203225      this.symbolDetailsViewHost.ViewsLabelVisible = true;
    204226      this.symbolDetailsViewHost.ViewType = null;
     
    225247      ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
    226248      this.splitContainer2.ResumeLayout(false);
     249      this.symbolDetailsGroupBox.ResumeLayout(false);
    227250      this.ResumeLayout(false);
    228251      this.PerformLayout();
     
    233256    private System.Windows.Forms.GroupBox grpSymbols;
    234257    private System.Windows.Forms.SplitContainer splitContainer1;
    235     private System.Windows.Forms.TreeView symbolsTreeView;
     258    private CheckBoxTreeView symbolsTreeView;
    236259    private System.Windows.Forms.SplitContainer splitContainer2;
    237     private SymbolicExpressionTreeChart allowedChildSymbolsControl;
    238     private MainForm.WindowsForms.ViewHost symbolDetailsViewHost;
    239260    private System.Windows.Forms.ImageList imageList;
    240261    protected System.Windows.Forms.CheckBox showDetailsCheckBox;
    241262    protected System.Windows.Forms.Button removeButton;
    242263    protected System.Windows.Forms.Button addButton;
     264    private System.Windows.Forms.GroupBox symbolDetailsGroupBox;
     265    private MainForm.WindowsForms.ViewHost symbolDetailsViewHost;
     266    protected System.Windows.Forms.Button copyButton;
     267    private SymbolicExpressionGrammarAllowedChildSymbolsControl allowedChildSymbolsControl;
    243268  }
    244269}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r6409 r6415  
    2525using System.Linq;
    2626using System.Windows.Forms;
    27 using HeuristicLab.Collections;
    2827using HeuristicLab.Common;
    2928using HeuristicLab.Core.Views;
     
    3534  [Content(typeof(ISymbolicExpressionGrammar), false)]
    3635  public partial class SymbolicExpressionGrammarEditorView : NamedItemView {
    37     private ObservableList<ISymbolicExpressionTreeNode> selectedSymbolicExpressionTreeNodes;
    38 
    3936    public SymbolicExpressionGrammarEditorView() {
    4037      InitializeComponent();
    41       selectedSymbolicExpressionTreeNodes = new ObservableList<ISymbolicExpressionTreeNode>();
    4238    }
    4339
     
    5652      get { return (ISymbolicExpressionGrammar)base.Content; }
    5753      set { base.Content = value; }
     54    }
     55
     56    protected override void SetEnabledStateOfControls() {
     57      base.SetEnabledStateOfControls();
     58      addButton.Enabled = Content != null;
     59      removeButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
     60      copyButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
     61    }
     62
     63    protected override void OnContentChanged() {
     64      base.OnContentChanged();
     65      if (Content != null) {
     66        symbolsTreeView.Nodes.Clear();
     67        UpdateSymbolsTreeView();
     68        symbolsTreeView.ExpandAll();
     69        allowedChildSymbolsControl.Grammar = Content;
     70        allowedChildSymbolsControl.Symbol = null;
     71        symbolDetailsViewHost.Content = null;
     72      } else {
     73        symbolsTreeView.Nodes.Clear();
     74        allowedChildSymbolsControl.Grammar = null;
     75        symbolDetailsViewHost.Content = null;
     76      }
    5877    }
    5978
     
    7998        symbol = (ISymbol)symbolsTreeView.SelectedNode.Tag;
    8099
    81       RebuildSymbolsTreeView();
     100      allowedChildSymbolsControl.Grammar = Content;
     101
     102      UpdateSymbolsTreeView();
    82103      if (symbol != null && Content.ContainsSymbol(symbol)) {
    83         BuildAllowedChildSymbolsTree(symbol);
     104        allowedChildSymbolsControl.Symbol = symbol;
    84105        symbolDetailsViewHost.Content = symbol;
    85106        symbolsTreeView.SelectedNode = IterateSymbolTreeNodes().Where(n => n.Tag == symbol).ToList().FirstOrDefault();
     
    88109    #endregion
    89110
    90     protected override void SetEnabledStateOfControls() {
    91       base.SetEnabledStateOfControls();
    92     }
    93 
    94     protected override void OnContentChanged() {
    95       base.OnContentChanged();
    96       if (Content != null) {
    97         RebuildSymbolsTreeView();
    98         allowedChildSymbolsControl.Tree = null;
    99         symbolDetailsViewHost.Content = null;
    100       } else {
    101         symbolsTreeView.Nodes.Clear();
    102         allowedChildSymbolsControl.Tree = null;
    103         symbolDetailsViewHost.Content = null;
    104       }
     111    private void UpdateSymbolsTreeView() {
     112      var symbols = Content.Symbols.ToList();
     113      foreach (var treeNode in IterateSymbolTreeNodes().ToList()) {
     114        var symbol = treeNode.Tag as ISymbol;
     115        if (!symbols.Contains(symbol))
     116          treeNode.Remove();
     117      }
     118
     119      var groupSymbols = symbols.OfType<GroupSymbol>().ToList();
     120      var topLevelSymbols = Content.Symbols.Where(s => !groupSymbols.Any(g => g.Symbols.Contains(s)));
     121      AddChildTreeNodes(symbolsTreeView.Nodes, topLevelSymbols);
     122
     123      RebuildImageList();
    105124    }
    106125
    107126    private void AddChildTreeNodes(TreeNodeCollection collection, IEnumerable<ISymbol> symbols) {
    108127      foreach (ISymbol symbol in symbols) {
    109         var node = new TreeNode();
    110         node.Name = symbol.Name;
    111         node.Text = symbol.Name;
    112         node.Tag = symbol;
    113         node.Checked = symbol.Enabled;
    114         collection.Add(node);
     128        TreeNode node = collection.Cast<TreeNode>().Where(n => n.Tag == symbol).FirstOrDefault();
     129        if (node == null) {
     130          node = new TreeNode();
     131          node.Name = symbol.Name;
     132          node.Text = symbol.Name;
     133          node.Tag = symbol;
     134          node.Checked = symbol.Enabled;
     135          collection.Add(node);
     136        }
    115137        var groupSymbol = symbol as GroupSymbol;
    116138        if (groupSymbol != null) AddChildTreeNodes(node.Nodes, groupSymbol.Symbols);
     
    122144        var symbol = (ISymbol)e.Node.Tag;
    123145        symbolDetailsViewHost.Content = symbol;
    124         selectedSymbolicExpressionTreeNodes.Clear();
    125         BuildAllowedChildSymbolsTree(symbol);
     146        allowedChildSymbolsControl.Symbol = symbol;
    126147      }
    127148      removeButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
     149      copyButton.Enabled = symbolsTreeView.SelectedNode != null && !(symbolsTreeView.SelectedNode.Tag is IReadOnlySymbol);
    128150    }
    129151
    130152    private void symbolsTreeView_AfterCheck(object sender, TreeViewEventArgs e) {
    131153      if (e.Action != TreeViewAction.Unknown) {
    132         DeregisterContentEvents();
     154        Content.StartGrammarManipulation();
     155        allowedChildSymbolsControl.Symbol = null;
    133156        var symbol = (ISymbol)e.Node.Tag;
    134157        symbol.Enabled = e.Node.Checked;
     
    138161        if (symbolsTreeView.SelectedNode != null) {
    139162          symbol = (ISymbol)symbolsTreeView.SelectedNode.Tag;
    140           selectedSymbolicExpressionTreeNodes.Clear();
    141           BuildAllowedChildSymbolsTree(symbol);
    142         }
    143         RegisterContentEvents();
    144       }
    145     }
    146 
    147     private void RebuildSymbolsTreeView() {
    148       symbolsTreeView.Nodes.Clear();
    149       var symbols = Content.Symbols.ToList();
    150       var groupSymbols = symbols.OfType<GroupSymbol>().ToList();
    151       var topLevelSymbols = Content.Symbols.Where(s => !groupSymbols.Any(g => g.Symbols.Contains(s)));
    152       AddChildTreeNodes(symbolsTreeView.Nodes, topLevelSymbols);
    153 
    154       RebuildImageList();
    155       symbolsTreeView.ExpandAll();
    156     }
    157 
    158     private void BuildAllowedChildSymbolsTree(ISymbol symbol) {
    159       var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(symbol));
    160 
    161       allowedChildSymbolsControl.SuspendRepaint = true;
    162       if (Content.GetMaximumSubtreeCount(symbol) > 0) {
    163         for (int i = 0; i < Content.GetMaximumSubtreeCount(symbol); i++) {
    164           var node = new DummySymbol("Subtree " + i).CreateTreeNode();
    165           foreach (var childSymbol in Content.GetAllowedChildSymbols(symbol, i)) {
    166             node.AddSubtree(new SymbolicExpressionTreeNode(childSymbol));
    167           }
    168           tree.Root.AddSubtree(node);
    169         }
    170       }
    171       allowedChildSymbolsControl.Tree = tree;
    172 
    173       foreach (var subtreeNode in tree.Root.Subtrees) {
    174         foreach (var allowedChildNode in subtreeNode.Subtrees) {
    175           var visualLine = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNodeConnection(subtreeNode, allowedChildNode);
    176           visualLine.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
    177         }
    178       }
    179 
    180       for (int i = Content.GetMinimumSubtreeCount(symbol); i < Content.GetMaximumSubtreeCount(symbol); i++) {
    181         var subtreeNode = tree.Root.GetSubtree(i);
    182         var visualTreeNode = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNode(subtreeNode);
    183         visualTreeNode.TextColor = Color.Gray;
    184         visualTreeNode.LineColor = Color.LightGray;
    185 
    186         var visualLine = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNodeConnection(tree.Root, subtreeNode);
    187         visualLine.LineColor = Color.LightGray;
    188 
    189         foreach (var allowedChildNode in subtreeNode.Subtrees) {
    190           visualTreeNode = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNode(allowedChildNode);
    191           visualTreeNode.TextColor = Color.Gray;
    192           visualTreeNode.LineColor = Color.LightGray;
    193 
    194           visualLine = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNodeConnection(subtreeNode, allowedChildNode);
    195           visualLine.LineColor = Color.LightGray;
    196         }
    197       }
    198 
    199       allowedChildSymbolsControl.SuspendRepaint = false;
    200       allowedChildSymbolsControl.Repaint();
    201       UpdateSelectedSymbolicExpressionTreeNodes();
    202     }
    203 
    204     private void symbolicExpressionTreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
    205       if ((Control.ModifierKeys & Keys.Control) == 0)
    206         selectedSymbolicExpressionTreeNodes.Clear();
    207 
    208       VisualSymbolicExpressionTreeNode clickedNode = (VisualSymbolicExpressionTreeNode)sender;
    209       var selectedNode = clickedNode.SymbolicExpressionTreeNode;
    210       if (selectedNode.SubtreeCount == 0) {
    211         if (!selectedSymbolicExpressionTreeNodes.Contains(selectedNode))
    212           selectedSymbolicExpressionTreeNodes.Add(selectedNode);
    213         else
    214           selectedSymbolicExpressionTreeNodes.Remove(selectedNode);
    215       }
    216 
    217       UpdateSelectedSymbolicExpressionTreeNodes();
    218     }
    219 
    220     private void symbolicExpressionTreeChart_KeyDown(object sender, KeyEventArgs e) {
    221       if (e.KeyCode == Keys.Delete) {
    222         DeregisterContentEvents();
    223         var root = allowedChildSymbolsControl.Tree.Root;
    224         foreach (var node in selectedSymbolicExpressionTreeNodes) {
    225           int argIndex = root.IndexOfSubtree(node.Parent);
    226           Content.RemoveAllowedChildSymbol(root.Symbol, node.Symbol, argIndex);
    227         }
    228         RegisterContentEvents();
    229         selectedSymbolicExpressionTreeNodes.Clear();
    230         BuildAllowedChildSymbolsTree(root.Symbol);
    231       }
    232     }
    233 
     163          allowedChildSymbolsControl.Symbol = symbol;
     164        }
     165        Content.FinishedGrammarManipulation();
     166      }
     167    }
     168
     169    #region drag & drop operations
     170    private GroupSymbol parentOfDraggedSymbol;
    234171    private void symbolsTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
    235172      if (!Locked) {
    236         DataObject data = new DataObject();
    237         data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, ((TreeNode)e.Item).Tag);
    238         DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    239       }
    240     }
     173        var treeNode = e.Item as TreeNode;
     174        if (treeNode.Parent != null) parentOfDraggedSymbol = treeNode.Parent.Tag as GroupSymbol;
     175        var data = new DataObject();
     176        data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, treeNode.Tag);
     177        validDragOperation = true;
     178        DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Move);
     179      }
     180    }
     181
    241182
    242183    private bool validDragOperation;
    243     private void symbolicExpressionTreeChart_DragEnter(object sender, DragEventArgs e) {
     184    private void symbolsTreeView_DragEnter(object sender, DragEventArgs e) {
    244185      validDragOperation = false;
     186      if (Content == null) return;
     187
    245188      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    246189      var symbol = data as ISymbol;
    247       var symbols = data as IEnumerable<ISymbol>;
    248       if (symbol != null && !(symbol is IReadOnlySymbol) && Content.ContainsSymbol(symbol)) validDragOperation = true;
    249       else if (symbols != null && symbols.All(s => !(symbol is IReadOnlySymbol) && Content.ContainsSymbol(s))) validDragOperation = true;
    250     }
    251 
    252     private void symbolicExpressionTreeChart_DragOver(object sender, DragEventArgs e) {
     190      if (symbol != null && !(symbol is IReadOnlySymbol)) validDragOperation = true;
     191    }
     192    private void symbolsTreeView_DragOver(object sender, DragEventArgs e) {
    253193      e.Effect = DragDropEffects.None;
    254194      if (validDragOperation) {
    255         Point coordinates = allowedChildSymbolsControl.PointToClient(new Point(e.X, e.Y));
    256         var visualNode = allowedChildSymbolsControl.FindVisualSymbolicExpressionTreeNodeAt(coordinates.X, coordinates.Y);
    257         if (visualNode != null) {
    258           var node = visualNode.SymbolicExpressionTreeNode;
    259           var root = allowedChildSymbolsControl.Tree.Root;
    260           if (root.Symbol is ProgramRootSymbol) return;
    261           if (node == root || node.Parent == root) e.Effect = DragDropEffects.Copy;
    262         }
    263       }
    264     }
    265 
    266     private void symbolicExpressionTreeChart_DragDrop(object sender, DragEventArgs e) {
    267       Point coordinates = allowedChildSymbolsControl.PointToClient(new Point(e.X, e.Y));
    268       var node = allowedChildSymbolsControl.FindVisualSymbolicExpressionTreeNodeAt(coordinates.X, coordinates.Y);
    269       var root = allowedChildSymbolsControl.Tree.Root;
    270 
    271       var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
    272       var symbol = data as ISymbol;
    273       var symbols = data as IEnumerable<ISymbol>;
    274 
    275       DeregisterContentEvents();
    276       if (node.SymbolicExpressionTreeNode == root) {
    277         if (symbol != null)
    278           Content.AddAllowedChildSymbol(root.Symbol, symbol);
    279         else if (symbols != null)
    280           foreach (var s in symbols) Content.AddAllowedChildSymbol(root.Symbol, s);
    281       } else {
    282         int argumentIndex = root.IndexOfSubtree(node.SymbolicExpressionTreeNode);
    283         if (symbol != null)
    284           Content.AddAllowedChildSymbol(root.Symbol, symbol, argumentIndex);
    285         else if (symbols != null)
    286           foreach (var s in symbols) Content.AddAllowedChildSymbol(root.Symbol, s, argumentIndex);
    287       }
    288       RegisterContentEvents();
    289       BuildAllowedChildSymbolsTree(root.Symbol);
    290     }
    291 
    292     private void UpdateSelectedSymbolicExpressionTreeNodes() {
    293       foreach (var node in allowedChildSymbolsControl.Tree.IterateNodesPrefix()) {
    294         var visualNode = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNode(node);
    295         if (!selectedSymbolicExpressionTreeNodes.Contains(node)) visualNode.FillColor = Color.White;
    296         else visualNode.FillColor = Color.LightSteelBlue;
    297 
    298       }
    299       allowedChildSymbolsControl.Repaint();
    300     }
    301 
    302     private RectangleF increaseMinimumSubtreeCountRectangle;
    303     private RectangleF decreaseMinimumSubtreeCountRectangle;
    304     private RectangleF increaseMaximumSubtreeCountRectangle;
    305     private RectangleF decreaseMaximumSubtreeCountRectangle;
    306     private void allowedChildSymbolsControl_Paint(object sender, PaintEventArgs e) {
    307       increaseMinimumSubtreeCountRectangle = RectangleF.Empty;
    308       decreaseMinimumSubtreeCountRectangle = RectangleF.Empty;
    309       increaseMaximumSubtreeCountRectangle = RectangleF.Empty;
    310       decreaseMaximumSubtreeCountRectangle = RectangleF.Empty;
    311 
    312       if (Content == null) return;
    313       if (allowedChildSymbolsControl.Tree == null) return;
    314 
    315       var rootNode = allowedChildSymbolsControl.Tree.Root;
    316       var visualRootNode = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNode(rootNode);
    317       var graphics = e.Graphics;
    318 
    319       if (rootNode.Symbol is IReadOnlySymbol) return;
    320       if (rootNode.Symbol.MinimumArity == rootNode.Symbol.MaximumArity) return;
    321 
    322       using (Pen pen = new Pen(Color.Black)) {
    323         using (Font font = new Font("Times New Roman", 8)) {
    324           var stringFormat = new StringFormat();
    325           stringFormat.Alignment = StringAlignment.Center;
    326           stringFormat.LineAlignment = StringAlignment.Center;
    327           int spacing = 5;
    328           int size = (visualRootNode.Height - spacing * 3) / 2;
    329 
    330           increaseMinimumSubtreeCountRectangle = new RectangleF(visualRootNode.X - spacing - size, visualRootNode.Y + spacing, size, size);
    331           decreaseMinimumSubtreeCountRectangle = new RectangleF(visualRootNode.X - spacing - size, visualRootNode.Y + size + 2 * spacing, size, size);
    332           increaseMaximumSubtreeCountRectangle = new RectangleF(visualRootNode.X + visualRootNode.Width + spacing, visualRootNode.Y + spacing, size, size);
    333           decreaseMaximumSubtreeCountRectangle = new RectangleF(visualRootNode.X + visualRootNode.Width + spacing, visualRootNode.Y + size + 2 * spacing, size, size);
    334 
    335           pen.Color = Content.GetMaximumSubtreeCount(rootNode.Symbol) == Content.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
    336           graphics.DrawString("+", font, pen.Brush, increaseMinimumSubtreeCountRectangle, stringFormat);
    337           graphics.DrawRectangle(pen, Rectangle.Round(increaseMinimumSubtreeCountRectangle));
    338           if (pen.Color == Color.LightGray) increaseMinimumSubtreeCountRectangle = RectangleF.Empty;
    339 
    340           pen.Color = Content.GetMinimumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MinimumArity ? Color.LightGray : Color.Black;
    341           graphics.DrawString("-", font, pen.Brush, decreaseMinimumSubtreeCountRectangle, stringFormat);
    342           graphics.DrawRectangle(pen, Rectangle.Round(decreaseMinimumSubtreeCountRectangle));
    343           if (pen.Color == Color.LightGray) decreaseMinimumSubtreeCountRectangle = RectangleF.Empty;
    344 
    345           pen.Color = Content.GetMaximumSubtreeCount(rootNode.Symbol) == rootNode.Symbol.MaximumArity ? Color.LightGray : Color.Black;
    346           graphics.DrawRectangle(pen, Rectangle.Round(increaseMaximumSubtreeCountRectangle));
    347           graphics.DrawString("+", font, pen.Brush, increaseMaximumSubtreeCountRectangle, stringFormat);
    348           if (pen.Color == Color.LightGray) increaseMaximumSubtreeCountRectangle = RectangleF.Empty;
    349 
    350           pen.Color = Content.GetMaximumSubtreeCount(rootNode.Symbol) == Content.GetMinimumSubtreeCount(rootNode.Symbol) ? Color.LightGray : Color.Black;
    351           graphics.DrawRectangle(pen, Rectangle.Round(decreaseMaximumSubtreeCountRectangle));
    352           graphics.DrawString("-", font, pen.Brush, decreaseMaximumSubtreeCountRectangle, stringFormat);
    353           if (pen.Color == Color.LightGray) decreaseMaximumSubtreeCountRectangle = RectangleF.Empty;
    354         }
    355       }
    356     }
    357 
     195        GroupSymbol groupSymbol = null;
     196        Point mouse = symbolsTreeView.PointToClient(new Point(e.X, e.Y));
     197        TreeNode node = symbolsTreeView.GetNodeAt(mouse);
     198        if (node != null) groupSymbol = node.Tag as GroupSymbol;
     199        if (node != null && groupSymbol == null) groupSymbol = node.Parent.Tag as GroupSymbol;
     200        var symbol = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
     201        if (symbol == groupSymbol) return;
     202
     203        if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
     204      }
     205    }
     206    private void symbolsTreeView_DragDrop(object sender, DragEventArgs e) {
     207      var symbol = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as ISymbol;
     208
     209      GroupSymbol groupSymbol = null;
     210      Point mouse = symbolsTreeView.PointToClient(new Point(e.X, e.Y));
     211      TreeNode node = symbolsTreeView.GetNodeAt(mouse);
     212      if (node != null) groupSymbol = node.Tag as GroupSymbol;
     213      if (node != null && groupSymbol == null) groupSymbol = node.Parent.Tag as GroupSymbol;
     214
     215      Content.StartGrammarManipulation();
     216      Cloner cloner = new Cloner();
     217      var clonedSymbol = cloner.Clone(symbol);
     218      ChangeDuplicateSymbolNames(clonedSymbol);
     219
     220      if (groupSymbol != null) groupSymbol.SymbolsCollection.Add(clonedSymbol);
     221      else Content.AddSymbol(clonedSymbol);
     222
     223      UpdateGrammerConstraintsForClonedSymbol(symbol, cloner);
     224      Content.FinishedGrammarManipulation();
     225    }
     226    #endregion
     227
     228    #region button events
    358229    private TypeSelectorDialog typeSelectorDialog;
    359230    private void addButton_Click(object sender, EventArgs e) {
     
    367238        try {
    368239          ISymbol symbol = (ISymbol)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    369           var originalSymbolName = symbol.Name;
    370           int i = 1;
    371           while (Content.ContainsSymbol(symbol)) {
    372             symbol.Name = originalSymbolName + i;
    373             i++;
    374           }
     240          ChangeDuplicateSymbolNames(symbol);
    375241
    376242          var selectedNode = symbolsTreeView.SelectedNode;
    377           GroupSymbol groupSymbol = null;
    378           while (selectedNode != null) {
    379             groupSymbol = selectedNode.Tag as GroupSymbol;
    380             if (groupSymbol != null && Content.ContainsSymbol(groupSymbol)) break;
    381             selectedNode = selectedNode.Parent;
    382           }
    383 
    384           if (groupSymbol != null && Content.ContainsSymbol(groupSymbol)) groupSymbol.SymbolsCollection.Add(symbol);
     243          GroupSymbol groupSymbol = selectedNode.Tag as GroupSymbol;
     244          if (groupSymbol == null && selectedNode.Parent != null) groupSymbol = selectedNode.Parent.Tag as GroupSymbol;
     245
     246          if (groupSymbol != null) groupSymbol.SymbolsCollection.Add(symbol);
    385247          else Content.AddSymbol(symbol);
    386248        }
     
    391253    }
    392254
     255    private void copyButton_Click(object sender, EventArgs e) {
     256      var symbol = symbolsTreeView.SelectedNode.Tag as ISymbol;
     257      if (symbol != null && !(symbol is IReadOnlySymbol)) {
     258        allowedChildSymbolsControl.Symbol = null;
     259        symbolDetailsViewHost.Content = null;
     260
     261        Content.StartGrammarManipulation();
     262        Cloner cloner = new Cloner();
     263        var clonedSymbol = cloner.Clone(symbol);
     264        ChangeDuplicateSymbolNames(clonedSymbol);
     265
     266        GroupSymbol groupSymbol = null;
     267        if (symbolsTreeView.SelectedNode.Parent != null) groupSymbol = symbolsTreeView.SelectedNode.Parent.Tag as GroupSymbol;
     268
     269        if (groupSymbol != null) groupSymbol.SymbolsCollection.Add(clonedSymbol);
     270        else Content.AddSymbol(clonedSymbol);
     271
     272        UpdateGrammerConstraintsForClonedSymbol(symbol, cloner);
     273        Content.FinishedGrammarManipulation();
     274      }
     275    }
     276
    393277    private void removeButton_Click(object sender, EventArgs e) {
    394278      var symbol = symbolsTreeView.SelectedNode.Tag as ISymbol;
    395       if (symbol != null && !(symbol is IReadOnlySymbol))
     279      if (symbol != null && !(symbol is IReadOnlySymbol)) {
    396280        Content.RemoveSymbol(symbol);
    397       removeButton.Enabled = false;
    398       allowedChildSymbolsControl.Tree = null;
    399       symbolDetailsViewHost.Content = null;
     281        allowedChildSymbolsControl.Symbol = null;
     282        symbolDetailsViewHost.Content = null;
     283      }
    400284    }
    401285
     
    403287      splitContainer1.Panel2Collapsed = !showDetailsCheckBox.Checked;
    404288    }
     289    #endregion
    405290
    406291    #region helpers
     292    private void UpdateGrammerConstraintsForClonedSymbol(ISymbol symbol, Cloner cloner) {
     293      foreach (var s in symbol.Flatten().Where(x => !(x is GroupSymbol))) {
     294        if (!cloner.ClonedObjectRegistered(s)) throw new InvalidOperationException();
     295        var clone = cloner.Clone(s);
     296        Content.SetSubtreeCount(clone, Content.GetMinimumSubtreeCount(s), Content.GetMaximumSubtreeCount(s));
     297        foreach (var childSymbol in Content.GetAllowedChildSymbols(s)) {
     298          var newChildSymbol = childSymbol;
     299          if (cloner.ClonedObjectRegistered(childSymbol)) newChildSymbol = cloner.Clone(childSymbol);
     300          Content.AddAllowedChildSymbol(clone, newChildSymbol);
     301        }
     302        for (int i = 0; i < Content.GetMaximumSubtreeCount(s); i++) {
     303          foreach (var childSymbol in Content.GetAllowedChildSymbols(s, i)) {
     304            var newChildSymbol = childSymbol;
     305            if (cloner.ClonedObjectRegistered(childSymbol)) newChildSymbol = cloner.Clone(childSymbol);
     306            Content.AddAllowedChildSymbol(clone, newChildSymbol, i);
     307          }
     308        }
     309      }
     310    }
     311
     312
     313    private void ChangeDuplicateSymbolNames(ISymbol symbol) {
     314      foreach (var s in symbol.Flatten()) {
     315        var originalSymbolName = s.Name;
     316        int i = 1;
     317        while (Content.ContainsSymbol(s)) {
     318          s.Name = originalSymbolName + i;
     319          i++;
     320        }
     321      }
     322    }
     323
    407324    private IEnumerable<TreeNode> IterateSymbolTreeNodes(TreeNode node = null) {
    408325      TreeNodeCollection nodes;
     
    428345    }
    429346    #endregion
    430 
    431     private void allowedChildSymbolsControl_MouseDown(object sender, MouseEventArgs e) {
    432       if (Content == null) return;
    433       if (allowedChildSymbolsControl.Tree == null) return;
    434 
    435       var pointF = new PointF(e.X, e.Y);
    436       var rootSymbol = allowedChildSymbolsControl.Tree.Root.Symbol;
    437       int minimumSubtreeCount = Content.GetMinimumSubtreeCount(rootSymbol);
    438       int maximumSubtreecount = Content.GetMaximumSubtreeCount(rootSymbol);
    439 
    440       bool changed = true;
    441       DeregisterContentEvents();
    442       if (increaseMinimumSubtreeCountRectangle.Contains(pointF))
    443         Content.SetSubtreeCount(rootSymbol, minimumSubtreeCount + 1, maximumSubtreecount);
    444       else if (decreaseMinimumSubtreeCountRectangle.Contains(pointF))
    445         Content.SetSubtreeCount(rootSymbol, minimumSubtreeCount - 1, maximumSubtreecount);
    446       else if (increaseMaximumSubtreeCountRectangle.Contains(pointF))
    447         Content.SetSubtreeCount(rootSymbol, minimumSubtreeCount, maximumSubtreecount + 1);
    448       else if (decreaseMaximumSubtreeCountRectangle.Contains(pointF))
    449         Content.SetSubtreeCount(rootSymbol, minimumSubtreeCount, maximumSubtreecount - 1);
    450       else
    451         changed = false;
    452 
    453       if (changed) BuildAllowedChildSymbolsTree(rootSymbol);
    454       RegisterContentEvents();
    455     }
    456347  }
    457348
    458   [NonDiscoverableType]
    459   internal class DummySymbol : Symbol {
    460     private const int minimumArity = 1;
    461     private const int maximumArity = byte.MaxValue;
    462 
    463     public override int MinimumArity {
    464       get { return minimumArity; }
    465     }
    466     public override int MaximumArity {
    467       get { return maximumArity; }
    468     }
    469 
    470     public DummySymbol(DummySymbol original, Cloner cloner) : base(original, cloner) { }
    471     public DummySymbol(string name) : base(name, "DummySymbol for views") { }
    472     public override IDeepCloneable Clone(Cloner cloner) { return new DummySymbol(this, cloner); }
     349  //this class is necessary to prevent double clicks which do not fire the checkbox checked event
     350  internal class CheckBoxTreeView : TreeView {
     351    protected override void WndProc(ref Message m) {
     352      // Suppress WM_LBUTTONDBLCLK
     353      if (m.Msg == 0x203) { m.Result = IntPtr.Zero; } else base.WndProc(ref m);
     354    }
    473355  }
    474356}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionGrammar.cs

    r6284 r6415  
    4545
    4646    void SetSubtreeCount(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount);
     47
     48    void StartGrammarManipulation();
     49    void FinishedGrammarManipulation();
    4750  }
    4851}
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammar.cs

    r6284 r6415  
    198198      base.SetSubtreeCount(symbol, minimumSubtreeCount, maximumSubtreeCount);
    199199    }
     200
     201    private bool suppressEvents = false;
     202    void ISymbolicExpressionGrammar.StartGrammarManipulation() {
     203      suppressEvents = true;
     204    }
     205    void ISymbolicExpressionGrammar.FinishedGrammarManipulation() {
     206      suppressEvents = false;
     207      OnChanged();
     208    }
     209
     210    protected override void OnChanged() {
     211      if (!suppressEvents) base.OnChanged();
     212    }
    200213    #endregion
    201214  }
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6409 r6415  
    6464    #endregion
    6565
    66     protected bool suppressEvents;
     66    private bool suppressEvents;
    6767    protected Dictionary<string, ISymbol> symbols;
    6868    protected Dictionary<string, Tuple<int, int>> symbolSubtreeCount;
  • branches/GP.Grammar.Editor/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/GP.Grammar.Editor/HeuristicLab.PluginInfrastructure/3.3/Advanced/DeploymentService/ServiceClients.cs

    r4722 r6415  
    22// <auto-generated>
    33//     This code was generated by a tool.
    4 //     Runtime Version:4.0.30319.1
     4//     Runtime Version:4.0.30319.225
    55//
    66//     Changes to this file may cause incorrect behavior and will be lost if
     
    99//------------------------------------------------------------------------------
    1010
    11 namespace HeuristicLab.PluginInfrastructure.Advanced.DeploymentService {
    12 
    13 
    14   [System.Diagnostics.DebuggerStepThroughAttribute()]
     11namespace HeuristicLab.PluginInfrastructure.Advanced.DeploymentService
     12{
     13    using System.Runtime.Serialization;
     14   
     15   
     16    [System.Diagnostics.DebuggerStepThroughAttribute()]
    1517    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
    1618    [System.Runtime.Serialization.DataContractAttribute(Name="PluginDescription", Namespace="http://schemas.datacontract.org/2004/07/HeuristicLab.Services.Deployment", IsReference=true)]
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs

    r6387 r6415  
    5151    protected override void UpdateModel(ISymbolicExpressionTree tree) {
    5252      Content.Model = new SymbolicDiscriminantFunctionClassificationModel(tree, Content.Model.Interpreter);
    53       Content.SetClassDistibutionCutPointThresholds();
    5453    }
    5554
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolution.cs

    r5809 r6415  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    29 using HeuristicLab.Parameters;
     25using HeuristicLab.Optimization;
    3026using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    32 using System;
    3327
    3428namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    6963      Add(new Result(ModelLengthResultName, "Length of the symbolic classification model.", new IntValue()));
    7064      Add(new Result(ModelDepthResultName, "Depth of the symbolic classification model.", new IntValue()));
    71       RecalculateResults();
     65      CalculateResults();
    7266    }
    7367
     
    7670    }
    7771
    78     protected override void OnModelChanged(EventArgs e) {
    79       base.OnModelChanged(e);
    80       RecalculateResults();
     72    protected override void RecalculateResults() {
     73      base.RecalculateResults();
     74      CalculateResults();
    8175    }
    8276
    83     private new void RecalculateResults() {
     77    private void CalculateResults() {
    8478      ModelLength = Model.SymbolicExpressionTree.Length;
    8579      ModelDepth = Model.SymbolicExpressionTree.Depth;
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationSolution.cs

    r5975 r6415  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    6766      Add(new Result(ModelLengthResultName, "Length of the symbolic classification model.", new IntValue()));
    6867      Add(new Result(ModelDepthResultName, "Depth of the symbolic classification model.", new IntValue()));
    69       RecalculateResults();
     68      CalculateResults();
    7069    }
    7170
     
    7473    }
    7574
    76     protected override void OnModelChanged(EventArgs e) {
    77       base.OnModelChanged(e);
    78       RecalculateResults();
     75    protected override void RecalculateResults() {
     76      base.RecalculateResults();
     77      CalculateResults();
    7978    }
    8079
    81     private new void RecalculateResults() {
     80    private void CalculateResults() {
    8281      ModelLength = Model.SymbolicExpressionTree.Length;
    8382      ModelDepth = Model.SymbolicExpressionTree.Depth;
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r6387 r6415  
    2020#endregion
    2121
    22 using System;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    6362      Add(new Result(ModelLengthResultName, "Length of the symbolic regression model.", new IntValue()));
    6463      Add(new Result(ModelDepthResultName, "Depth of the symbolic regression model.", new IntValue()));
    65       RecalculateResults();
     64      CalculateResults();
    6665    }
    6766
     
    7069    }
    7170
    72     protected override void OnModelChanged(EventArgs e) {
    73       RecalculateResults();
    74       base.OnModelChanged(e);
     71    protected override void RecalculateResults() {
     72      base.RecalculateResults();
     73      CalculateResults();
    7574    }
    7675
    77     protected new void RecalculateResults() {
     76    private void CalculateResults() {
    7877      ModelLength = Model.SymbolicExpressionTree.Length;
    7978      ModelDepth = Model.SymbolicExpressionTree.Depth;
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.cs

    r6236 r6415  
    8080    protected override void OnContentChanged() {
    8181      base.OnContentChanged();
    82       variableNamesView.Content.Clear();
    8382      UpdateControl();
    8483    }
     
    105104    private void variableNames_Changed(object sender, CollectionItemsChangedEventArgs<StringValue> args) {
    106105      if (Content != null) {
    107         Content.Changed -= new EventHandler(Content_Changed);
     106        DeregisterContentEvents();
    108107        Content.VariableNames = variableNamesView.Content.CheckedItems.Select(x => x.Value).ToList();
    109         Content.Changed += new EventHandler(Content_Changed);
     108        RegisterContentEvents();
    110109      }
    111110    }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionEstimatedClassValuesView.cs

    r6255 r6415  
    8686        StringMatrix matrix = null;
    8787        if (Content != null) {
    88           string[,] values = new string[Content.ProblemData.Dataset.Rows, 5];
     88          string[,] values = new string[Content.ProblemData.Dataset.Rows, 4];
    8989
    9090          double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs

    r6184 r6415  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    6665      Add(new Result(TrainingAccuracyResultName, "Accuracy of the model on the training partition (percentage of correctly classified instances).", new PercentValue()));
    6766      Add(new Result(TestAccuracyResultName, "Accuracy of the model on the test partition (percentage of correctly classified instances).", new PercentValue()));
    68       RecalculateResults();
     67      CalculateResults();
    6968    }
    7069
     
    7372    }
    7473
    75     protected override void OnProblemDataChanged(EventArgs e) {
    76       base.OnProblemDataChanged(e);
    77       RecalculateResults();
     74    protected override void RecalculateResults() {
     75      CalculateResults();
    7876    }
    7977
    80     protected override void OnModelChanged(EventArgs e) {
    81       base.OnModelChanged(e);
    82       RecalculateResults();
    83     }
    84 
    85     protected void RecalculateResults() {
     78    private void CalculateResults() {
    8679      double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values
    8780      IEnumerable<double> originalTrainingClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs

    r5942 r6415  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827using HeuristicLab.Data;
    2928using HeuristicLab.Optimization;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis {
     
    8989      Add(new Result(TrainingRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the training partition", new DoubleValue()));
    9090      Add(new Result(TestRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue()));
     91      SetAccuracyMaximizingThresholds();
     92
     93      //mkommend: important to recalculate accuracy because during the calculation before no thresholds were present     
     94      base.RecalculateResults();
     95      CalculateResults();
    9196      RegisterEventHandler();
    92       SetAccuracyMaximizingThresholds();
    93       RecalculateResults();
    9497    }
    9598
     
    99102    }
    100103
    101     protected new void RecalculateResults() {
     104    protected override void OnModelChanged(EventArgs e) {
     105      DeregisterEventHandler();
     106      SetAccuracyMaximizingThresholds();
     107      RegisterEventHandler();
     108      base.OnModelChanged(e);
     109    }
     110
     111    protected override void RecalculateResults() {
     112      base.RecalculateResults();
     113      CalculateResults();
     114    }
     115
     116    private void CalculateResults() {
    102117      double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
    103118      IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
     
    119134    private void RegisterEventHandler() {
    120135      Model.ThresholdsChanged += new EventHandler(Model_ThresholdsChanged);
     136    }
     137    private void DeregisterEventHandler() {
     138      Model.ThresholdsChanged -= new EventHandler(Model_ThresholdsChanged);
    121139    }
    122140    private void Model_ThresholdsChanged(object sender, EventArgs e) {
     
    142160    }
    143161
    144     protected override void OnModelChanged(EventArgs e) {
    145       base.OnModelChanged(e);
    146       SetAccuracyMaximizingThresholds();
    147       RecalculateResults();
    148     }
    149 
    150     protected override void OnProblemDataChanged(EventArgs e) {
    151       base.OnProblemDataChanged(e);
    152       SetAccuracyMaximizingThresholds();
    153       RecalculateResults();
    154     }
    155162    protected virtual void OnModelThresholdsChanged(EventArgs e) {
    156       base.OnModelChanged(e);
    157163      RecalculateResults();
    158164    }
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Clustering/ClusteringSolution.cs

    r6184 r6415  
    4545    }
    4646
     47    protected override void RecalculateResults() {
     48    }
     49
    4750    #region IClusteringSolution Members
    4851
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs

    r5914 r6415  
    8686    }
    8787
     88    protected abstract void RecalculateResults();
     89
    8890    private void ProblemData_Changed(object sender, EventArgs e) {
    8991      OnProblemDataChanged(e);
     
    9294    public event EventHandler ModelChanged;
    9395    protected virtual void OnModelChanged(EventArgs e) {
     96      RecalculateResults();
    9497      var listeners = ModelChanged;
    9598      if (listeners != null) listeners(this, e);
     
    98101    public event EventHandler ProblemDataChanged;
    99102    protected virtual void OnProblemDataChanged(EventArgs e) {
     103      RecalculateResults();
    100104      var listeners = ProblemDataChanged;
    101105      if (listeners != null) listeners(this, e);
  • branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs

    r6387 r6415  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
     
    110109      Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
    111110
    112       RecalculateResults();
     111      CalculateResults();
    113112    }
    114113
     
    117116    }
    118117
    119     protected override void OnProblemDataChanged(EventArgs e) {
    120       RecalculateResults();
    121       base.OnProblemDataChanged(e);
    122     }
    123     protected override void OnModelChanged(EventArgs e) {
    124       RecalculateResults();
    125       base.OnModelChanged(e);
     118    protected override void RecalculateResults() {
     119      CalculateResults();
    126120    }
    127121
    128     protected void RecalculateResults() {
     122    private void CalculateResults() {
    129123      double[] estimatedTrainingValues = EstimatedTrainingValues.ToArray(); // cache values
    130124      IEnumerable<double> originalTrainingValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes);
Note: See TracChangeset for help on using the changeset viewer.