Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/06/17 20:51:26 (7 years ago)
Author:
bburlacu
Message:

#1772: Merge trunk changes, add a couple of convenience parameters to the SchemaCreator.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.Designer.cs

    r14312 r15351  
    5959      this.symbolicExpressionTreeChart.Name = "functionTreeChart";
    6060      this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(407, 367);
    61       this.symbolicExpressionTreeChart.Spacing = 5;
    6261      this.symbolicExpressionTreeChart.TabIndex = 0;
    6362      this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font(FontFamily.GenericSerif, 8F);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs

    r10649 r15351  
    6060      SecondWalk(layoutRoot, -layoutRoot.Prelim);
    6161      NormalizeCoordinates(layoutNodeMap.Values);
    62       if (height != 0 && width != 0) {
     62      if (width > 0 && height > 0) {
    6363        FitToBounds(width, height, layoutNodeMap.Values);
    6464        Center(width, height, layoutNodeMap.Values);
     
    178178        if (ymax < y) ymax = y;
    179179      }
    180       return new RectangleF(xmin, ymin, xmax + minHorizontalSpacing + NodeWidth, ymax + minVerticalSpacing + NodeHeight);
     180      return new RectangleF(xmin, ymin, xmax + NodeWidth, ymax + NodeHeight);
    181181    }
    182182
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.Designer.cs

    r14312 r15351  
    7070      this.symbolicExpressionTreeChart.Name = "allowedChildSymbolsControl";
    7171      this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(645, 386);
    72       this.symbolicExpressionTreeChart.Spacing = 5;
    7372      this.symbolicExpressionTreeChart.SuspendRepaint = false;
    7473      this.symbolicExpressionTreeChart.TabIndex = 0;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r14312 r15351  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3737    private ILayoutEngine<ISymbolicExpressionTreeNode> layoutEngine;
    3838
    39     private const int preferredNodeWidth = 70;
    40     private const int preferredNodeHeight = 46;
    41     private int minHorizontalDistance = 30;
    42     private int minVerticalDistance = 30;
    43 
    4439    public SymbolicExpressionTreeChart() {
    4540      InitializeComponent();
    4641      this.image = new Bitmap(Width, Height);
    4742      this.stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
    48       this.spacing = 5;
    4943      this.lineColor = Color.Black;
    5044      this.backgroundColor = Color.White;
     
    5549
    5650      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) {
    57         NodeWidth = preferredNodeWidth,
    58         NodeHeight = preferredNodeHeight,
    59         HorizontalSpacing = minHorizontalDistance,
    60         VerticalSpacing = minVerticalDistance
     51        NodeWidth = PreferredNodeWidth,
     52        NodeHeight = PreferredNodeHeight,
     53        HorizontalSpacing = MinimumHorizontalDistance,
     54        VerticalSpacing = MinimumVerticalDistance
    6155      };
    6256      reingoldTilfordToolStripMenuItem.Checked = true;
     
    6963
    7064    #region Public properties
    71     private int spacing;
    72     public int Spacing {
    73       get { return this.spacing; }
    74       set {
    75         this.spacing = value;
    76         this.Repaint();
     65    private int preferredNodeWidth = 70;
     66    public int PreferredNodeWidth {
     67      get { return preferredNodeWidth; }
     68      set {
     69        preferredNodeWidth = value;
     70        Repaint();
     71      }
     72    }
     73
     74    private int preferredNodeHeight = 46;
     75    public int PreferredNodeHeight {
     76      get { return preferredNodeHeight; }
     77      set {
     78        preferredNodeHeight = value;
     79        Repaint();
     80      }
     81    }
     82
     83    private int minHorizontalDistance = 30;
     84    public int MinimumHorizontalDistance {
     85      get { return minHorizontalDistance; }
     86      set {
     87        minHorizontalDistance = value;
     88        Repaint();
     89      }
     90    }
     91
     92    private int minVerticalDistance = 30;
     93    public int MinimumVerticalDistance {
     94      get { return minVerticalDistance; }
     95      set {
     96        minVerticalDistance = value;
     97        Repaint();
     98      }
     99    }
     100
     101    private int minHorizontalPadding = 20;
     102    public int MinimumHorizontalPadding {
     103      get { return minHorizontalPadding; }
     104      set {
     105        minHorizontalPadding = value;
     106        Repaint();
     107      }
     108    }
     109
     110    private int minVerticalPadding = 20;
     111    public int MinimumVerticalPadding {
     112      get { return minVerticalPadding; }
     113      set {
     114        minVerticalPadding = value;
     115        Repaint();
    77116      }
    78117    }
     
    186225        graphics.Clear(backgroundColor);
    187226        if (tree != null) {
    188           DrawFunctionTree(graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
     227          DrawFunctionTree(graphics, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance);
    189228        }
    190229      }
     
    287326        actualRoot = tree.Root.GetSubtree(0);
    288327      }
    289 
    290       var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width, Height).ToList();
     328      var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width - MinimumHorizontalPadding, Height - MinimumVerticalPadding).ToList();
     329      // add the padding
     330      foreach (var vn in visualNodes) {
     331        vn.X += MinimumHorizontalPadding / 2;
     332        vn.Y += MinimumVerticalPadding / 2;
     333      }
     334
    291335      visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x);
    292336      visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>();
     
    322366    }
    323367
     368    private Action<Brush, int, int, int, int> fill;
     369    private Action<Pen, int, int, int, int> draw;
    324370    protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) {
    325371      graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1));
     
    329375      using (var nodeLinePen = new Pen(visualTreeNode.LineColor))
    330376      using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) {
    331         //draw terminal node
    332         if (node.SubtreeCount == 0) {
    333           graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    334           graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
     377        var x = visualTreeNode.X;
     378        var y = visualTreeNode.Y;
     379        var w = visualTreeNode.Width - 1;  // allow 1px for the drawing of the line
     380        var h = visualTreeNode.Height - 1; // allow 1px for the drawing of the line
     381        // draw leaf nodes as rectangles and internal nodes as ellipses
     382        if (node.SubtreeCount > 0) {
     383          fill = graphics.FillEllipse; draw = graphics.DrawEllipse;
    335384        } else {
    336           graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    337           graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    338         }
     385          fill = graphics.FillRectangle; draw = graphics.DrawRectangle;
     386        }
     387        fill(nodeFillBrush, x, y, w, h);
     388        draw(nodeLinePen, x, y, w, h);
    339389        //draw name of symbol
    340         var text = ShortLabel(node);
    341         graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat);
     390        graphics.DrawString(node.ToString(), textFont, textBrush, new RectangleF(x, y, w, h), stringFormat);
    342391      }
    343392    }
     
    368417      Image bitmap = new Bitmap(Width, Height);
    369418      using (var g = Graphics.FromImage(bitmap)) {
    370         DrawFunctionTree(g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance, false);
     419        DrawFunctionTree(g, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance, false);
    371420      }
    372421      bitmap.Save(filename);
     
    378427        using (Metafile file = new Metafile(filename, g.GetHdc())) {
    379428          using (Graphics emfFile = Graphics.FromImage(file)) {
    380             DrawFunctionTree(emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance, false);
     429            DrawFunctionTree(emfFile, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance, false);
    381430          }
    382431        }
     
    399448
    400449    private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) {
    401       minHorizontalDistance = 30;
    402       minVerticalDistance = 30;
    403450      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) {
    404         NodeWidth = preferredNodeWidth,
    405         NodeHeight = preferredNodeHeight,
    406         HorizontalSpacing = minHorizontalDistance,
    407         VerticalSpacing = minVerticalDistance
     451        NodeWidth = PreferredNodeWidth,
     452        NodeHeight = PreferredNodeHeight,
     453        HorizontalSpacing = MinimumHorizontalDistance,
     454        VerticalSpacing = MinimumVerticalDistance
    408455      };
    409456      reingoldTilfordToolStripMenuItem.Checked = true;
     
    413460
    414461    private void boxesToolStripMenuItem_Click(object sender, EventArgs e) {
    415       minHorizontalDistance = 5;
    416       minVerticalDistance = 5;
    417462      layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()) {
    418         NodeWidth = preferredNodeWidth,
    419         NodeHeight = preferredNodeHeight,
    420         HorizontalSpacing = minHorizontalDistance,
    421         VerticalSpacing = minVerticalDistance
     463        NodeWidth = PreferredNodeWidth,
     464        NodeHeight = PreferredNodeHeight,
     465        HorizontalSpacing = MinimumHorizontalDistance,
     466        VerticalSpacing = MinimumVerticalDistance
    422467      };
    423468      reingoldTilfordToolStripMenuItem.Checked = false;
Note: See TracChangeset for help on using the changeset viewer.