Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10561 for trunk/sources


Ignore:
Timestamp:
03/06/14 15:07:05 (11 years ago)
Author:
bburlacu
Message:

#2076: Updated the way the layout is used in the SymbolicExpressionTreeChart; updated simplifier view accordingly.

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs

    r10520 r10561  
    131131    }
    132132
     133    public IEnumerable<T> GetContentNodes() {
     134      return nodeMap.Keys;
     135    }
     136
    133137    public IEnumerable<VisualTreeNode<T>> GetVisualNodes() {
    134138      return nodeMap.Values;
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs

    r10520 r10561  
    2222    Func<T, int> GetDepth { get; set; }
    2323
     24    IEnumerable<T> GetContentNodes();
    2425    IEnumerable<VisualTreeNode<T>> GetVisualNodes();
    2526    Dictionary<T, PointF> GetCoordinates();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs

    r10531 r10561  
    6363        Expand(node);
    6464      }
     65    }
     66
     67    public IEnumerable<T> GetContentNodes() {
     68      return nodeMap.Keys;
    6569    }
    6670
     
    191195        // reset layout-related parameters
    192196        layoutNode.Reset();
     197        // reset the width and height since they might have been affected by scaling
     198        layoutNode.Width = NodeWidth;
     199        layoutNode.Height = NodeHeight;
    193200      }
    194201    }
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs

    r10520 r10561  
    105105
    106106      var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(Symbol));
    107       symbolicExpressionTreeChart.SuspendRepaint = true;
    108107      if (Grammar.GetMaximumSubtreeCount(Symbol) > 0) {
    109108        for (int i = 0; i < Grammar.GetMaximumSubtreeCount(Symbol); i++) {
     
    118117      }
    119118      symbolicExpressionTreeChart.Tree = tree;
    120 
     119      symbolicExpressionTreeChart.SuspendRepaint = true;
    121120      foreach (var subtreeNode in tree.Root.Subtrees) {
    122121        foreach (var allowedChildNode in subtreeNode.Subtrees) {
     
    144143        }
    145144      }
    146 
    147145      symbolicExpressionTreeChart.SuspendRepaint = false;
    148146      UpdateSelectedSymbolicExpressionTreeNodes();
     
    155153        else visualNode.FillColor = Color.LightSteelBlue;
    156154      }
    157       symbolicExpressionTreeChart.Repaint();
     155      symbolicExpressionTreeChart.RepaintNodes();
    158156    }
    159157
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r10531 r10561  
    5858    }
    5959
     60    private ILayoutEngine<ISymbolicExpressionTreeNode> TreeLayoutEngine {
     61      get { return layoutEngine; }
     62      set {
     63        layoutEngine = value;
     64        InitializeLayout();
     65        Repaint();
     66      }
     67    }
     68
    6069    public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree)
    6170      : this() {
     
    128137      if (this.Width <= 1 || this.Height <= 1)
    129138        this.image = new Bitmap(1, 1);
    130       else
     139      else {
    131140        this.image = new Bitmap(Width, Height);
     141      }
    132142      this.Repaint();
     143    }
     144
     145    public event EventHandler Repainted;//expose this event to notify the parent control that the tree was repainted
     146    protected virtual void OnRepaint(object sender, EventArgs e) {
     147      var repainted = Repainted;
     148      if (repainted != null) {
     149        repainted(sender, e);
     150      }
    133151    }
    134152
     
    137155        this.GenerateImage();
    138156        this.Refresh();
     157        OnRepaint(this, EventArgs.Empty);
    139158      }
    140159    }
     
    147166          foreach (var visualNode in visualTreeNodes.Values) {
    148167            DrawTreeNode(graphics, visualNode);
     168            if (visualNode.Content.SubtreeCount > 0) {
     169              foreach (var visualSubtree in visualNode.Content.Subtrees.Select(s => visualTreeNodes[s])) {
     170                DrawLine(graphics, visualNode, visualSubtree);
     171              }
     172            }
    149173          }
    150174        }
     
    170194        graphics.Clear(backgroundColor);
    171195        if (tree != null) {
    172           DrawFunctionTree(tree, graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
     196          DrawFunctionTree(graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
    173197        }
    174198      }
     
    236260
    237261    private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) {
    238 
    239262      VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    240263      if (draggedSymbolicExpressionTree != null &&
     
    262285    #endregion
    263286
     287    #region initialize the layout
    264288    private void InitializeLayout() {
    265       var actualRoot = tree.Root.SubtreeCount == 1 ? tree.Root.GetSubtree(0) : tree.Root;
     289      var actualRoot = tree.Root;
     290      if (actualRoot.Symbol is ProgramRootSymbol && actualRoot.SubtreeCount == 1) {
     291        actualRoot = tree.Root.GetSubtree(0);
     292      }
    266293      layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth());
    267294      layoutEngine.CalculateLayout(this.Width, this.Height);
     295      UpdateDictionaries();
     296    }
     297
     298    private void UpdateDictionaries() {
    268299      var visualNodes = layoutEngine.GetVisualNodes().ToList();
    269300      //populate the visual nodes and visual connections dictionaries
     
    276307      }
    277308    }
    278 
     309    #endregion
    279310    #region methods for painting the symbolic expression tree
    280     private void DrawFunctionTree(ISymbolicExpressionTree symbExprTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
     311    private void DrawFunctionTree(Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
    281312      //we assume here that the layout has already been initialized when the symbolic expression tree was changed
    282313      //recalculate layout according to new node widths and spacing
     
    286317      layoutEngine.VerticalSpacing = minVDistance;
    287318      layoutEngine.CalculateLayout(Width, Height);
     319      UpdateDictionaries();//this will reset the visual nodes, therefore colors will be reset to default values
    288320      var visualNodes = visualTreeNodes.Values;
    289321      //draw nodes and connections
     
    333365      }
    334366    }
     367
     368    protected void DrawLine(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> startNode, VisualTreeNode<ISymbolicExpressionTreeNode> endNode) {
     369      var origin = new Point(startNode.X + startNode.Width / 2, startNode.Y + startNode.Height);
     370      var target = new Point(endNode.X + endNode.Width / 2, endNode.Y);
     371      graphics.Clip = new Region(new Rectangle(Math.Min(origin.X, target.X), origin.Y, Math.Max(origin.X, target.X), target.Y));
     372      var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(startNode.Content, endNode.Content);
     373      using (var linePen = new Pen(visualLine.LineColor)) {
     374        linePen.DashStyle = visualLine.DashStyle;
     375        graphics.DrawLine(linePen, origin, target);
     376      }
     377    }
    335378    #endregion
    336379    #region save image
     
    348391      Image image = new Bitmap(Width, Height);
    349392      using (Graphics g = Graphics.FromImage(image)) {
    350         DrawFunctionTree(tree, g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
     393        DrawFunctionTree(g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
    351394      }
    352395      image.Save(filename);
     
    358401        using (Metafile file = new Metafile(filename, g.GetHdc())) {
    359402          using (Graphics emfFile = Graphics.FromImage(file)) {
    360             DrawFunctionTree(tree, emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
     403            DrawFunctionTree(emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
    361404          }
    362405        }
     
    377420
    378421    private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) {
    379       layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
     422      TreeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
    380423        NodeWidth = preferredNodeWidth,
    381424        NodeHeight = preferredNodeHeight,
     
    383426        VerticalSpacing = minVerticalDistance
    384427      };
    385       InitializeLayout();
    386       Repaint();
    387428    }
    388429
    389430    private void boxesToolStripMenuItem_Click(object sender, EventArgs e) {
    390       layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
     431      TreeLayoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
    391432        NodeWidth = preferredNodeWidth,
    392433        NodeHeight = preferredNodeHeight,
     
    394435        VerticalSpacing = minVerticalDistance
    395436      };
    396       InitializeLayout();
    397       Repaint();
    398437    }
    399438  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs

    r10521 r10561  
    218218            if (tempNode.IterateNodesBreadth().Contains(node))
    219219              throw new ArgumentException();// cannot cut/paste a node into itself
    220             ModifyTree(Tree, tempNode.Parent, tempNode, null); //remove node from its original parent     
     220            ModifyTree(Tree, tempNode.Parent, tempNode, null); //remove node from its original parent
    221221            ModifyTree(Tree, node, null, tempNode); //insert it as a child to the new parent
    222222            break;
Note: See TracChangeset for help on using the changeset viewer.