Changeset 10565 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
- Timestamp:
- 03/07/14 16:23:41 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r10561 r10565 27 27 using System.Linq; 28 28 using System.Windows.Forms; 29 using Point = System.Drawing.Point; 29 30 30 31 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { … … 50 50 this.backgroundColor = Color.White; 51 51 this.textFont = new Font(FontFamily.GenericSansSerif, 12); 52 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> { 52 53 visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualTreeNode<ISymbolicExpressionTreeNode>>(); 54 visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>(); 55 56 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) { 53 57 NodeWidth = preferredNodeWidth, 54 58 NodeHeight = preferredNodeHeight, … … 56 60 VerticalSpacing = minVerticalDistance 57 61 }; 58 } 59 60 private ILayoutEngine<ISymbolicExpressionTreeNode> TreeLayoutEngine { 61 get { return layoutEngine; } 62 set { 63 layoutEngine = value; 64 InitializeLayout(); 65 Repaint(); 66 } 67 } 62 reingoldTilfordToolStripMenuItem.Checked = true; 63 } 64 65 //private ILayoutEngine<ISymbolicExpressionTreeNode> TreeLayoutEngine { 66 // get { return layoutEngine; } 67 // set { 68 // layoutEngine = value; 69 // InitializeLayout(); 70 // Repaint(); 71 // } 72 //} 68 73 69 74 public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree) … … 114 119 set { 115 120 tree = value; 116 if (tree != null) { 117 //the layout engine needs to be initialized here so that the visualNodes and the visualLines dictionaries are populated 118 InitializeLayout(); 119 Repaint(); 120 } 121 Repaint(); 121 122 } 122 123 } … … 285 286 #endregion 286 287 287 #region initialize the layout 288 private void InitializeLayout() { 288 private void CalculateLayout(int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) { 289 layoutEngine.NodeWidth = preferredWidth; 290 layoutEngine.NodeHeight = preferredHeight; 291 layoutEngine.HorizontalSpacing = minHDistance; 292 layoutEngine.VerticalSpacing = minVDistance; 293 289 294 var actualRoot = tree.Root; 290 295 if (actualRoot.Symbol is ProgramRootSymbol && actualRoot.SubtreeCount == 1) { 291 296 actualRoot = tree.Root.GetSubtree(0); 292 297 } 293 layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()); 294 layoutEngine.CalculateLayout(this.Width, this.Height); 295 UpdateDictionaries(); 296 } 297 298 private void UpdateDictionaries() { 299 var visualNodes = layoutEngine.GetVisualNodes().ToList(); 300 //populate the visual nodes and visual connections dictionaries 298 299 var visualNodes = layoutEngine.CalculateLayout(actualRoot, Width, Height).ToList(); 301 300 visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x); 302 301 visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>(); … … 307 306 } 308 307 } 309 #endregion 308 310 309 #region methods for painting the symbolic expression tree 311 310 private void DrawFunctionTree(Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) { 312 //we assume here that the layout has already been initialized when the symbolic expression tree was changed 313 //recalculate layout according to new node widths and spacing 314 layoutEngine.NodeWidth = preferredWidth; 315 layoutEngine.NodeHeight = preferredHeight; 316 layoutEngine.HorizontalSpacing = minHDistance; 317 layoutEngine.VerticalSpacing = minVDistance; 318 layoutEngine.CalculateLayout(Width, Height); 319 UpdateDictionaries();//this will reset the visual nodes, therefore colors will be reset to default values 311 CalculateLayout(preferredWidth, preferredHeight, minHDistance, minVDistance); 320 312 var visualNodes = visualTreeNodes.Values; 321 313 //draw nodes and connections … … 420 412 421 413 private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) { 422 TreeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>{414 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) { 423 415 NodeWidth = preferredNodeWidth, 424 416 NodeHeight = preferredNodeHeight, … … 426 418 VerticalSpacing = minVerticalDistance 427 419 }; 420 reingoldTilfordToolStripMenuItem.Checked = true; 421 boxesToolStripMenuItem.Checked = false; 422 Repaint(); 428 423 } 429 424 430 425 private void boxesToolStripMenuItem_Click(object sender, EventArgs e) { 431 TreeLayoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode>{426 layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()) { 432 427 NodeWidth = preferredNodeWidth, 433 428 NodeHeight = preferredNodeHeight, … … 435 430 VerticalSpacing = minVerticalDistance 436 431 }; 432 reingoldTilfordToolStripMenuItem.Checked = false; 433 boxesToolStripMenuItem.Checked = true; 434 Repaint(); 437 435 } 438 436 }
Note: See TracChangeset
for help on using the changeset viewer.