Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/14 10:51:38 (11 years ago)
Author:
bburlacu
Message:

#2076: SymbolicExpressionTreeChart: initialize layout when the tree node is changed, not when the tree draw method is called.

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4
Files:
2 edited

Legend:

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

    r10520 r10531  
    7272        Y = (int)Math.Round(x.Y)
    7373      });
     74    }
     75
     76    public IEnumerable<LayoutNode<T>> GetLayoutNodes() {
     77      return nodeMap.Values;
    7478    }
    7579
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r10520 r10531  
    5050      this.backgroundColor = Color.White;
    5151      this.textFont = new Font(FontFamily.GenericSansSerif, 12);
    52       //      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
    53       layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {
     52      layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {
    5453        NodeWidth = preferredNodeWidth,
    5554        NodeHeight = preferredNodeHeight,
     
    107106        tree = value;
    108107        if (tree != null) {
     108          //the layout engine needs to be initialized here so that the visualNodes and the visualLines dictionaries are populated
     109          InitializeLayout();
    109110          Repaint();
    110111        }
     
    235236
    236237    private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) {
     238
    237239      VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);
    238240      if (draggedSymbolicExpressionTree != null &&
     
    260262    #endregion
    261263
    262     #region methods for painting the symbolic expression tree
    263     private void DrawFunctionTree(ISymbolicExpressionTree symbExprTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
    264       var root = symbExprTree.Root;
    265       var actualRoot = root.SubtreeCount == 1 ? root.GetSubtree(0) : root;
    266       layoutEngine.NodeWidth = preferredWidth;
    267       layoutEngine.NodeHeight = preferredHeight;
    268       layoutEngine.HorizontalSpacing = minHDistance;
    269       layoutEngine.VerticalSpacing = minVDistance;
     264    private void InitializeLayout() {
     265      var actualRoot = tree.Root.SubtreeCount == 1 ? tree.Root.GetSubtree(0) : tree.Root;
    270266      layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth());
    271       layoutEngine.CalculateLayout(Width, Height);
    272 
     267      layoutEngine.CalculateLayout(this.Width, this.Height);
    273268      var visualNodes = layoutEngine.GetVisualNodes().ToList();
     269      //populate the visual nodes and visual connections dictionaries
    274270      visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x);
    275271      visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>();
     
    279275        }
    280276      }
    281       // draw nodes and connections
     277    }
     278
     279    #region methods for painting the symbolic expression tree
     280    private void DrawFunctionTree(ISymbolicExpressionTree symbExprTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
     281      //we assume here that the layout has already been initialized when the symbolic expression tree was changed
     282      //recalculate layout according to new node widths and spacing
     283      layoutEngine.NodeWidth = preferredWidth;
     284      layoutEngine.NodeHeight = preferredHeight;
     285      layoutEngine.HorizontalSpacing = minHDistance;
     286      layoutEngine.VerticalSpacing = minVDistance;
     287      layoutEngine.CalculateLayout(Width, Height);
     288      var visualNodes = visualTreeNodes.Values;
     289      //draw nodes and connections
    282290      foreach (var visualNode in visualNodes) {
    283291        DrawTreeNode(visualNode);
     
    375383        VerticalSpacing = minVerticalDistance
    376384      };
     385      InitializeLayout();
    377386      Repaint();
    378387    }
     
    385394        VerticalSpacing = minVerticalDistance
    386395      };
     396      InitializeLayout();
    387397      Repaint();
    388398    }
Note: See TracChangeset for help on using the changeset viewer.