Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/09/11 16:36:07 (13 years ago)
Author:
mkommend
Message:

#1479: Allowed modificiation of the subtree count in grammars and adapted SymbolicExpressionTreeChart to handle different styles for connection lines.

Location:
branches/GP.Grammar.Editor
Files:
1 added
8 edited

Legend:

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

    r6285 r6403  
    149149    </Compile>
    150150    <Compile Include="VisualSymbolicExpressionTreeNode.cs" />
     151    <Compile Include="VisualSymbolicExpressionTreeNodeConnection.cs" />
    151152  </ItemGroup>
    152153  <ItemGroup>
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.Designer.cs

    r6299 r6403  
    4747      this.initialFrequencyLabel = new System.Windows.Forms.Label();
    4848      this.initialFrequencyTextBox = new System.Windows.Forms.TextBox();
    49       this.checkBoxEnabled = new System.Windows.Forms.CheckBox();
     49      this.enabledCheckBox = new System.Windows.Forms.CheckBox();
     50      this.minimumArityLabel = new System.Windows.Forms.Label();
     51      this.maximumArityLabel = new System.Windows.Forms.Label();
     52      this.minimumArityTextBox = new System.Windows.Forms.TextBox();
     53      this.maximumArityTextBox = new System.Windows.Forms.TextBox();
    5054      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5155      this.SuspendLayout();
     
    8589      this.initialFrequencyTextBox.Validated += new System.EventHandler(this.initialFrequencyTextBox_Validated);
    8690      //
    87       // checkBoxEnabled
     91      // enabledCheckBox
    8892      //
    89       this.checkBoxEnabled.AutoSize = true;
    90       this.checkBoxEnabled.Location = new System.Drawing.Point(93, 52);
    91       this.checkBoxEnabled.Name = "checkBoxEnabled";
    92       this.checkBoxEnabled.Size = new System.Drawing.Size(65, 17);
    93       this.checkBoxEnabled.TabIndex = 5;
    94       this.checkBoxEnabled.Text = "Enabled";
    95       this.checkBoxEnabled.UseVisualStyleBackColor = true;
    96       this.checkBoxEnabled.CheckedChanged += new System.EventHandler(this.checkBoxEnabled_CheckedChanged);
     93      this.enabledCheckBox.AutoSize = true;
     94      this.enabledCheckBox.Location = new System.Drawing.Point(93, 104);
     95      this.enabledCheckBox.Name = "enabledCheckBox";
     96      this.enabledCheckBox.Size = new System.Drawing.Size(65, 17);
     97      this.enabledCheckBox.TabIndex = 5;
     98      this.enabledCheckBox.Text = "Enabled";
     99      this.enabledCheckBox.UseVisualStyleBackColor = true;
     100      this.enabledCheckBox.CheckedChanged += new System.EventHandler(this.checkBoxEnabled_CheckedChanged);
     101      //
     102      // minimumArityLabel
     103      //
     104      this.minimumArityLabel.AutoSize = true;
     105      this.minimumArityLabel.Location = new System.Drawing.Point(3, 55);
     106      this.minimumArityLabel.Name = "minimumArityLabel";
     107      this.minimumArityLabel.Size = new System.Drawing.Size(74, 13);
     108      this.minimumArityLabel.TabIndex = 8;
     109      this.minimumArityLabel.Text = "Minimum Arity:";
     110      this.toolTip.SetToolTip(this.minimumArityLabel, "Relative frequency of the symbol in randomly created trees");
     111      //
     112      // maximumArityLabel
     113      //
     114      this.maximumArityLabel.AutoSize = true;
     115      this.maximumArityLabel.Location = new System.Drawing.Point(3, 81);
     116      this.maximumArityLabel.Name = "maximumArityLabel";
     117      this.maximumArityLabel.Size = new System.Drawing.Size(74, 13);
     118      this.maximumArityLabel.TabIndex = 6;
     119      this.maximumArityLabel.Text = "Maximum Arity";
     120      this.toolTip.SetToolTip(this.maximumArityLabel, "Relative frequency of the symbol in randomly created trees");
     121      //
     122      // minimumArityTextBox
     123      //
     124      this.minimumArityTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     125            | System.Windows.Forms.AnchorStyles.Right)));
     126      this.errorProvider.SetIconAlignment(this.minimumArityTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
     127      this.minimumArityTextBox.Location = new System.Drawing.Point(93, 52);
     128      this.minimumArityTextBox.Name = "minimumArityTextBox";
     129      this.minimumArityTextBox.ReadOnly = true;
     130      this.minimumArityTextBox.Size = new System.Drawing.Size(227, 20);
     131      this.minimumArityTextBox.TabIndex = 9;
     132      //
     133      // maximumArityTextBox
     134      //
     135      this.maximumArityTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     136            | System.Windows.Forms.AnchorStyles.Right)));
     137      this.errorProvider.SetIconAlignment(this.maximumArityTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
     138      this.maximumArityTextBox.Location = new System.Drawing.Point(93, 78);
     139      this.maximumArityTextBox.Name = "maximumArityTextBox";
     140      this.maximumArityTextBox.ReadOnly = true;
     141      this.maximumArityTextBox.Size = new System.Drawing.Size(227, 20);
     142      this.maximumArityTextBox.TabIndex = 7;
    97143      //
    98144      // SymbolView
     
    100146      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    101147      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     148      this.Controls.Add(this.minimumArityTextBox);
     149      this.Controls.Add(this.minimumArityLabel);
     150      this.Controls.Add(this.maximumArityTextBox);
     151      this.Controls.Add(this.maximumArityLabel);
    102152      this.Controls.Add(this.initialFrequencyTextBox);
    103153      this.Controls.Add(this.initialFrequencyLabel);
    104       this.Controls.Add(this.checkBoxEnabled);
     154      this.Controls.Add(this.enabledCheckBox);
    105155      this.Name = "SymbolView";
    106       this.Size = new System.Drawing.Size(320, 75);
    107       this.Controls.SetChildIndex(this.checkBoxEnabled, 0);
     156      this.Size = new System.Drawing.Size(320, 123);
     157      this.Controls.SetChildIndex(this.enabledCheckBox, 0);
    108158      this.Controls.SetChildIndex(this.initialFrequencyLabel, 0);
    109159      this.Controls.SetChildIndex(this.initialFrequencyTextBox, 0);
     160      this.Controls.SetChildIndex(this.maximumArityLabel, 0);
     161      this.Controls.SetChildIndex(this.maximumArityTextBox, 0);
     162      this.Controls.SetChildIndex(this.minimumArityLabel, 0);
     163      this.Controls.SetChildIndex(this.minimumArityTextBox, 0);
    110164      this.Controls.SetChildIndex(this.infoLabel, 0);
    111165      this.Controls.SetChildIndex(this.nameLabel, 0);
     
    121175    protected System.Windows.Forms.Label initialFrequencyLabel;
    122176    protected System.Windows.Forms.TextBox initialFrequencyTextBox;
    123     private System.Windows.Forms.CheckBox checkBoxEnabled;
     177    private System.Windows.Forms.CheckBox enabledCheckBox;
     178    protected System.Windows.Forms.Label minimumArityLabel;
     179    protected System.Windows.Forms.Label maximumArityLabel;
     180    protected System.Windows.Forms.TextBox minimumArityTextBox;
     181    protected System.Windows.Forms.TextBox maximumArityTextBox;
    124182
    125183  }
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolView.cs

    r6337 r6403  
    5959      initialFrequencyTextBox.Enabled = Content != null || Locked;
    6060      initialFrequencyTextBox.ReadOnly = ReadOnly;
    61       checkBoxEnabled.Enabled = Content != null || Locked || ReadOnly;
     61      enabledCheckBox.Enabled = Content != null || Locked || ReadOnly;
    6262    }
    6363
     
    9797    private void checkBoxEnabled_CheckedChanged(object sender, EventArgs e) {
    9898      if (Content != null)
    99         Content.Enabled = checkBoxEnabled.Checked;
     99        Content.Enabled = enabledCheckBox.Checked;
    100100    }
    101101    #endregion
     
    105105      if (Content == null) {
    106106        initialFrequencyTextBox.Text = string.Empty;
    107         checkBoxEnabled.Checked = false;
     107        minimumArityTextBox.Text = string.Empty;
     108        maximumArityTextBox.Text = string.Empty;
     109        enabledCheckBox.Checked = false;
    108110      } else {
    109111        initialFrequencyTextBox.Text = Content.InitialFrequency.ToString();
    110         checkBoxEnabled.Checked = Content.Enabled;
     112        minimumArityTextBox.Text = Content.MinimumArity.ToString();
     113        maximumArityTextBox.Text = Content.MaximumArity.ToString();
     114        enabledCheckBox.Checked = Content.Enabled;
    111115      }
    112116      SetEnabledStateOfControls();
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.Designer.cs

    r6377 r6403  
    2828      this.grpSymbols = new System.Windows.Forms.GroupBox();
    2929      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
     30      this.showDetailsCheckBox = new System.Windows.Forms.CheckBox();
     31      this.removeButton = new System.Windows.Forms.Button();
     32      this.addButton = new System.Windows.Forms.Button();
    3033      this.symbolsTreeView = new System.Windows.Forms.TreeView();
    3134      this.imageList = new System.Windows.Forms.ImageList(this.components);
    3235      this.splitContainer2 = new System.Windows.Forms.SplitContainer();
     36      this.allowedChildSymbolsControl = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    3337      this.symbolDetailsViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    34       this.showDetailsCheckBox = new System.Windows.Forms.CheckBox();
    35       this.removeButton = new System.Windows.Forms.Button();
    36       this.addButton = new System.Windows.Forms.Button();
    37       this.allowedChildSymbolsControl = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    3838      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    3939      this.grpSymbols.SuspendLayout();
     
    9090      this.splitContainer1.SplitterDistance = 191;
    9191      this.splitContainer1.TabIndex = 0;
     92      //
     93      // showDetailsCheckBox
     94      //
     95      this.showDetailsCheckBox.Appearance = System.Windows.Forms.Appearance.Button;
     96      this.showDetailsCheckBox.Checked = true;
     97      this.showDetailsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
     98      this.showDetailsCheckBox.Image = HeuristicLab.Common.Resources.VSImageLibrary.Properties;
     99      this.showDetailsCheckBox.Location = new System.Drawing.Point(63, 3);
     100      this.showDetailsCheckBox.Name = "showDetailsCheckBox";
     101      this.showDetailsCheckBox.Size = new System.Drawing.Size(24, 24);
     102      this.showDetailsCheckBox.TabIndex = 7;
     103      this.toolTip.SetToolTip(this.showDetailsCheckBox, "Show/Hide Details");
     104      this.showDetailsCheckBox.UseVisualStyleBackColor = true;
     105      this.showDetailsCheckBox.CheckedChanged += new System.EventHandler(this.showDetailsCheckBox_CheckedChanged);
     106      //
     107      // removeButton
     108      //
     109      this.removeButton.Enabled = false;
     110      this.removeButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Remove;
     111      this.removeButton.Location = new System.Drawing.Point(33, 3);
     112      this.removeButton.Name = "removeButton";
     113      this.removeButton.Size = new System.Drawing.Size(24, 24);
     114      this.removeButton.TabIndex = 6;
     115      this.toolTip.SetToolTip(this.removeButton, "Remove");
     116      this.removeButton.UseVisualStyleBackColor = true;
     117      this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
     118      //
     119      // addButton
     120      //
     121      this.addButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Add;
     122      this.addButton.Location = new System.Drawing.Point(3, 3);
     123      this.addButton.Name = "addButton";
     124      this.addButton.Size = new System.Drawing.Size(24, 24);
     125      this.addButton.TabIndex = 5;
     126      this.toolTip.SetToolTip(this.addButton, "Add");
     127      this.addButton.UseVisualStyleBackColor = true;
     128      this.addButton.Click += new System.EventHandler(this.addButton_Click);
    92129      //
    93130      // symbolsTreeView
     
    132169      this.splitContainer2.TabIndex = 0;
    133170      //
    134       // symbolViewHost
    135       //
    136       this.symbolDetailsViewHost.Caption = "View";
    137       this.symbolDetailsViewHost.Content = null;
    138       this.symbolDetailsViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
    139       this.symbolDetailsViewHost.Enabled = false;
    140       this.symbolDetailsViewHost.Location = new System.Drawing.Point(0, 0);
    141       this.symbolDetailsViewHost.Name = "symbolViewHost";
    142       this.symbolDetailsViewHost.ReadOnly = false;
    143       this.symbolDetailsViewHost.Size = new System.Drawing.Size(568, 190);
    144       this.symbolDetailsViewHost.TabIndex = 0;
    145       this.symbolDetailsViewHost.ViewsLabelVisible = true;
    146       this.symbolDetailsViewHost.ViewType = null;
    147       //
    148       // showDetailsCheckBox
    149       //
    150       this.showDetailsCheckBox.Appearance = System.Windows.Forms.Appearance.Button;
    151       this.showDetailsCheckBox.Checked = true;
    152       this.showDetailsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;
    153       this.showDetailsCheckBox.Image = HeuristicLab.Common.Resources.VSImageLibrary.Properties;
    154       this.showDetailsCheckBox.Location = new System.Drawing.Point(63, 3);
    155       this.showDetailsCheckBox.Name = "showDetailsCheckBox";
    156       this.showDetailsCheckBox.Size = new System.Drawing.Size(24, 24);
    157       this.showDetailsCheckBox.TabIndex = 7;
    158       this.toolTip.SetToolTip(this.showDetailsCheckBox, "Show/Hide Details");
    159       this.showDetailsCheckBox.UseVisualStyleBackColor = true;
    160       this.showDetailsCheckBox.CheckedChanged += new System.EventHandler(this.showDetailsCheckBox_CheckedChanged);
    161       //
    162       // removeButton
    163       //
    164       this.removeButton.Enabled = false;
    165       this.removeButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Remove;
    166       this.removeButton.Location = new System.Drawing.Point(33, 3);
    167       this.removeButton.Name = "removeButton";
    168       this.removeButton.Size = new System.Drawing.Size(24, 24);
    169       this.removeButton.TabIndex = 6;
    170       this.toolTip.SetToolTip(this.removeButton, "Remove");
    171       this.removeButton.UseVisualStyleBackColor = true;
    172       this.removeButton.Click += new System.EventHandler(this.removeButton_Click);
    173       //
    174       // addButton
    175       //
    176       this.addButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Add;
    177       this.addButton.Location = new System.Drawing.Point(3, 3);
    178       this.addButton.Name = "addButton";
    179       this.addButton.Size = new System.Drawing.Size(24, 24);
    180       this.addButton.TabIndex = 5;
    181       this.toolTip.SetToolTip(this.addButton, "Add");
    182       this.addButton.UseVisualStyleBackColor = true;
    183       this.addButton.Click += new System.EventHandler(this.addButton_Click);
    184       //
    185       // symbolicExpressionTreeChart
     171      // allowedChildSymbolsControl
    186172      //
    187173      this.allowedChildSymbolsControl.AllowDrop = true;
     
    190176      this.allowedChildSymbolsControl.LineColor = System.Drawing.Color.Black;
    191177      this.allowedChildSymbolsControl.Location = new System.Drawing.Point(0, 0);
    192       this.allowedChildSymbolsControl.Name = "symbolicExpressionTreeChart";
     178      this.allowedChildSymbolsControl.Name = "allowedChildSymbolsControl";
    193179      this.allowedChildSymbolsControl.Size = new System.Drawing.Size(568, 165);
    194180      this.allowedChildSymbolsControl.Spacing = 5;
     
    200186      this.allowedChildSymbolsControl.DragEnter += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragEnter);
    201187      this.allowedChildSymbolsControl.DragOver += new System.Windows.Forms.DragEventHandler(this.symbolicExpressionTreeChart_DragOver);
     188      this.allowedChildSymbolsControl.Paint += new System.Windows.Forms.PaintEventHandler(this.allowedChildSymbolsControl_Paint);
    202189      this.allowedChildSymbolsControl.KeyDown += new System.Windows.Forms.KeyEventHandler(this.symbolicExpressionTreeChart_KeyDown);
     190      this.allowedChildSymbolsControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.allowedChildSymbolsControl_MouseDown);
     191      //
     192      // symbolDetailsViewHost
     193      //
     194      this.symbolDetailsViewHost.Caption = "View";
     195      this.symbolDetailsViewHost.Content = null;
     196      this.symbolDetailsViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
     197      this.symbolDetailsViewHost.Enabled = false;
     198      this.symbolDetailsViewHost.Location = new System.Drawing.Point(0, 0);
     199      this.symbolDetailsViewHost.Name = "symbolDetailsViewHost";
     200      this.symbolDetailsViewHost.ReadOnly = false;
     201      this.symbolDetailsViewHost.Size = new System.Drawing.Size(568, 190);
     202      this.symbolDetailsViewHost.TabIndex = 0;
     203      this.symbolDetailsViewHost.ViewsLabelVisible = true;
     204      this.symbolDetailsViewHost.ViewType = null;
    203205      //
    204206      // SymbolicExpressionGrammarEditorView
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarEditorView.cs

    r6387 r6403  
    159159      var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(symbol));
    160160
     161      allowedChildSymbolsControl.SuspendRepaint = true;
    161162      if (Content.GetMaximumSubtreeCount(symbol) > 0) {
    162163        for (int i = 0; i < Content.GetMaximumSubtreeCount(symbol); i++) {
     
    169170      }
    170171      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.Dash;
     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();
    171201      UpdateSelectedSymbolicExpressionTreeNodes();
    172202    }
     
    216246      var symbol = data as ISymbol;
    217247      var symbols = data as IEnumerable<ISymbol>;
    218       if (symbol != null && !(symbol is IReadOnlySymbol) && !Content.ContainsSymbol(symbol)) validDragOperation = true;
     248      if (symbol != null && !(symbol is IReadOnlySymbol) && Content.ContainsSymbol(symbol)) validDragOperation = true;
    219249      else if (symbols != null && symbols.All(s => !(symbol is IReadOnlySymbol) && Content.ContainsSymbol(s))) validDragOperation = true;
    220250    }
     
    263293      foreach (var node in allowedChildSymbolsControl.Tree.IterateNodesPrefix()) {
    264294        var visualNode = allowedChildSymbolsControl.GetVisualSymbolicExpressionTreeNode(node);
    265         if (!selectedSymbolicExpressionTreeNodes.Contains(node)) {
    266           visualNode.FillColor = Color.White;
    267           visualNode.LineColor = Color.Black;
    268         } else {
    269           visualNode.FillColor = Color.WhiteSmoke;
    270           visualNode.LineColor = Color.DarkOrange;
    271         }
     295        if (!selectedSymbolicExpressionTreeNodes.Contains(node)) visualNode.FillColor = Color.White;
     296        else visualNode.FillColor = Color.LightSteelBlue;
     297
    272298      }
    273299      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      }
    274356    }
    275357
     
    297379            groupSymbol = selectedNode.Tag as GroupSymbol;
    298380            if (groupSymbol != null && Content.ContainsSymbol(groupSymbol)) break;
     381            selectedNode = selectedNode.Parent;
    299382          }
    300383
     
    345428    }
    346429    #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    }
    347456  }
    348457
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r6387 r6403  
    3131    private StringFormat stringFormat;
    3232    private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
     33    private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines;
    3334
    3435    public SymbolicExpressionTreeChart() {
     
    9192        tree = value;
    9293        visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode>();
     94        visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection>();
    9395        if (tree != null) {
    94           foreach (SymbolicExpressionTreeNode node in tree.IterateNodesPrefix())
     96          foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
    9597            visualTreeNodes[node] = new VisualSymbolicExpressionTreeNode(node);
     98            if (node.Parent != null) visualLines[Tuple.Create(node.Parent, node)] = new VisualSymbolicExpressionTreeNodeConnection();
     99          }
    96100        }
    97101        Repaint();
     
    99103    }
    100104
     105    private bool suspendRepaint;
     106    public bool SuspendRepaint {
     107      get { return suspendRepaint; }
     108      set { suspendRepaint = value; }
     109    }
     110
    101111    protected override void OnPaint(PaintEventArgs e) {
     112      e.Graphics.DrawImage(image, 0, 0);
    102113      base.OnPaint(e);
    103       e.Graphics.DrawImage(image, 0, 0);
    104114    }
    105115    protected override void OnResize(EventArgs e) {
     
    113123
    114124    public void Repaint() {
    115       this.GenerateImage();
    116       this.Refresh();
     125      if (!suspendRepaint) {
     126        this.GenerateImage();
     127        this.Refresh();
     128      }
    117129    }
    118130
     
    133145        return visualTreeNodes[symbolicExpressionTreeNode];
    134146      return null;
     147    }
     148
     149    public VisualSymbolicExpressionTreeNodeConnection GetVisualSymbolicExpressionTreeNodeConnection(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) {
     150      if (child.Parent != parent) throw new ArgumentException();
     151      var key = Tuple.Create(parent, child);
     152      VisualSymbolicExpressionTreeNodeConnection connection = null;
     153      visualLines.TryGetValue(key, out connection);
     154      return connection;
    135155    }
    136156
     
    228248
    229249      SolidBrush textBrush = new SolidBrush(visualTreeNode.TextColor);
    230       Pen linePen = new Pen(this.lineColor);
    231250      Pen nodeLinePen = new Pen(visualTreeNode.LineColor);
    232251      SolidBrush nodeFillBrush = new SolidBrush(visualTreeNode.FillColor);
     
    275294
    276295      //draw connection line to parent node
    277       if (!connectionPoint.IsEmpty)
    278         graphics.DrawLine(linePen, connectionPoint, new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y));
     296      if (!connectionPoint.IsEmpty && node.Parent != null) {
     297        var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node.Parent, node);
     298        using (Pen linePen = new Pen(visualLine.LineColor)) {
     299          linePen.DashStyle = visualLine.DashStyle;
     300          graphics.DrawLine(linePen, connectionPoint, new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y));
     301        }
     302      }
    279303
    280304      //calculate areas for the subtrees according to their tree size and call drawFunctionTree
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/VisualSymbolicExpressionTreeNode.cs

    r5809 r6403  
    2323
    2424namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
    25   public class VisualSymbolicExpressionTreeNode {
     25  public class VisualSymbolicExpressionTreeNode : object {
    2626    private static readonly Color defaultLineColor = Color.Black;
    2727    private static readonly Color defaultTextColor = Color.Black;
  • branches/GP.Grammar.Editor/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r6387 r6403  
    143143    private void AddSymbolToDictionaries(ISymbol symbol) {
    144144      symbols.Add(symbol.Name, symbol);
    145       symbolSubtreeCount.Add(symbol.Name, Tuple.Create(symbol.MinimumArity, symbol.MaximumArity));
     145      symbolSubtreeCount.Add(symbol.Name, Tuple.Create(symbol.MinimumArity, symbol.MinimumArity));
    146146      RegisterSymbolEvents(symbol);
    147147    }
     
    332332
    333333    private void SetSubTreeCountInDictionaries(ISymbol symbol, int minimumSubtreeCount, int maximumSubtreeCount) {
    334       for (int i = GetMaximumSubtreeCount(symbol) - 1; i >= maximumSubtreeCount; i--) {
     334      for (int i = maximumSubtreeCount; i < GetMaximumSubtreeCount(symbol); i++) {
    335335        var key = Tuple.Create(symbol.Name, i);
    336336        allowedChildSymbolsPerIndex.Remove(key);
Note: See TracChangeset for help on using the changeset viewer.