Changeset 15351 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Timestamp:
- 09/06/17 20:51:26 (7 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.Designer.cs
r14312 r15351 59 59 this.symbolicExpressionTreeChart.Name = "functionTreeChart"; 60 60 this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(407, 367); 61 this.symbolicExpressionTreeChart.Spacing = 5;62 61 this.symbolicExpressionTreeChart.TabIndex = 0; 63 62 this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font(FontFamily.GenericSerif, 8F); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs
r10649 r15351 60 60 SecondWalk(layoutRoot, -layoutRoot.Prelim); 61 61 NormalizeCoordinates(layoutNodeMap.Values); 62 if ( height != 0 && width !=0) {62 if (width > 0 && height > 0) { 63 63 FitToBounds(width, height, layoutNodeMap.Values); 64 64 Center(width, height, layoutNodeMap.Values); … … 178 178 if (ymax < y) ymax = y; 179 179 } 180 return new RectangleF(xmin, ymin, xmax + minHorizontalSpacing + NodeWidth, ymax + minVerticalSpacing+ NodeHeight);180 return new RectangleF(xmin, ymin, xmax + NodeWidth, ymax + NodeHeight); 181 181 } 182 182 -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.Designer.cs
r14312 r15351 70 70 this.symbolicExpressionTreeChart.Name = "allowedChildSymbolsControl"; 71 71 this.symbolicExpressionTreeChart.Size = new System.Drawing.Size(645, 386); 72 this.symbolicExpressionTreeChart.Spacing = 5;73 72 this.symbolicExpressionTreeChart.SuspendRepaint = false; 74 73 this.symbolicExpressionTreeChart.TabIndex = 0; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r14312 r15351 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 37 37 private ILayoutEngine<ISymbolicExpressionTreeNode> layoutEngine; 38 38 39 private const int preferredNodeWidth = 70;40 private const int preferredNodeHeight = 46;41 private int minHorizontalDistance = 30;42 private int minVerticalDistance = 30;43 44 39 public SymbolicExpressionTreeChart() { 45 40 InitializeComponent(); 46 41 this.image = new Bitmap(Width, Height); 47 42 this.stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; 48 this.spacing = 5;49 43 this.lineColor = Color.Black; 50 44 this.backgroundColor = Color.White; … … 55 49 56 50 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) { 57 NodeWidth = preferredNodeWidth,58 NodeHeight = preferredNodeHeight,59 HorizontalSpacing = minHorizontalDistance,60 VerticalSpacing = minVerticalDistance51 NodeWidth = PreferredNodeWidth, 52 NodeHeight = PreferredNodeHeight, 53 HorizontalSpacing = MinimumHorizontalDistance, 54 VerticalSpacing = MinimumVerticalDistance 61 55 }; 62 56 reingoldTilfordToolStripMenuItem.Checked = true; … … 69 63 70 64 #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(); 77 116 } 78 117 } … … 186 225 graphics.Clear(backgroundColor); 187 226 if (tree != null) { 188 DrawFunctionTree(graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);227 DrawFunctionTree(graphics, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance); 189 228 } 190 229 } … … 287 326 actualRoot = tree.Root.GetSubtree(0); 288 327 } 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 291 335 visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x); 292 336 visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>(); … … 322 366 } 323 367 368 private Action<Brush, int, int, int, int> fill; 369 private Action<Pen, int, int, int, int> draw; 324 370 protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) { 325 371 graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1)); … … 329 375 using (var nodeLinePen = new Pen(visualTreeNode.LineColor)) 330 376 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; 335 384 } 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); 339 389 //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); 342 391 } 343 392 } … … 368 417 Image bitmap = new Bitmap(Width, Height); 369 418 using (var g = Graphics.FromImage(bitmap)) { 370 DrawFunctionTree(g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance, false);419 DrawFunctionTree(g, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance, false); 371 420 } 372 421 bitmap.Save(filename); … … 378 427 using (Metafile file = new Metafile(filename, g.GetHdc())) { 379 428 using (Graphics emfFile = Graphics.FromImage(file)) { 380 DrawFunctionTree(emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance, false);429 DrawFunctionTree(emfFile, PreferredNodeWidth, PreferredNodeHeight, MinimumHorizontalDistance, MinimumVerticalDistance, false); 381 430 } 382 431 } … … 399 448 400 449 private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) { 401 minHorizontalDistance = 30;402 minVerticalDistance = 30;403 450 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees) { 404 NodeWidth = preferredNodeWidth,405 NodeHeight = preferredNodeHeight,406 HorizontalSpacing = minHorizontalDistance,407 VerticalSpacing = minVerticalDistance451 NodeWidth = PreferredNodeWidth, 452 NodeHeight = PreferredNodeHeight, 453 HorizontalSpacing = MinimumHorizontalDistance, 454 VerticalSpacing = MinimumVerticalDistance 408 455 }; 409 456 reingoldTilfordToolStripMenuItem.Checked = true; … … 413 460 414 461 private void boxesToolStripMenuItem_Click(object sender, EventArgs e) { 415 minHorizontalDistance = 5;416 minVerticalDistance = 5;417 462 layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()) { 418 NodeWidth = preferredNodeWidth,419 NodeHeight = preferredNodeHeight,420 HorizontalSpacing = minHorizontalDistance,421 VerticalSpacing = minVerticalDistance463 NodeWidth = PreferredNodeWidth, 464 NodeHeight = PreferredNodeHeight, 465 HorizontalSpacing = MinimumHorizontalDistance, 466 VerticalSpacing = MinimumVerticalDistance 422 467 }; 423 468 reingoldTilfordToolStripMenuItem.Checked = false;
Note: See TracChangeset
for help on using the changeset viewer.