Changeset 8986
- Timestamp:
- 12/03/12 13:02:13 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r8980 r8986 129 129 public void RepaintNodes() { 130 130 if (!suspendRepaint) { 131 var graphics = Graphics.FromImage(image); 132 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 133 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 134 foreach (var visualNode in visualTreeNodes.Values) { 135 DrawTreeNode(graphics, visualNode); 131 using (var graphics = Graphics.FromImage(image)) { 132 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 133 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 134 foreach (var visualNode in visualTreeNodes.Values) { 135 DrawTreeNode(graphics, visualNode); 136 } 136 137 } 137 138 this.Refresh(); … … 141 142 public void RepaintNode(VisualSymbolicExpressionTreeNode visualNode) { 142 143 if (!suspendRepaint) { 143 var graphics = Graphics.FromImage(image); 144 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 145 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 146 DrawTreeNode(graphics, visualNode); 144 using (var graphics = Graphics.FromImage(image)) { 145 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; 146 graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 147 DrawTreeNode(graphics, visualNode); 148 } 147 149 this.Refresh(); 148 150 } … … 268 270 int actualHeight = height - spacing; 269 271 270 SolidBrush textBrush = new SolidBrush(visualTreeNode.TextColor);271 Pen nodeLinePen = new Pen(visualTreeNode.LineColor);272 SolidBrush nodeFillBrush = new SolidBrush(visualTreeNode.FillColor);273 274 //calculate size of node275 if (actualWidth >= visualTreeNode.PreferredWidth && actualHeight >= visualTreeNode.PreferredHeight) {276 visualTreeNode.Width = visualTreeNode.PreferredWidth;277 visualTreeNode.Height = visualTreeNode.PreferredHeight;278 visualTreeNode.X = (int)center_x - visualTreeNode.Width / 2;279 visualTreeNode.Y = (int)center_y - visualTreeNode.Height / 2;280 }281 //width too small to draw in desired sized282 else if (actualWidth < visualTreeNode.PreferredWidth && actualHeight >= visualTreeNode.PreferredHeight) {283 visualTreeNode.Width = actualWidth;284 visualTreeNode.Height = visualTreeNode.PreferredHeight;285 visualTreeNode.X = x;286 visualTreeNode.Y = (int)center_y - visualTreeNode.Height / 2;287 }288 //height too small to draw in desired sized289 else if (actualWidth >= visualTreeNode.PreferredWidth && actualHeight < visualTreeNode.PreferredHeight) {290 visualTreeNode.Width = visualTreeNode.PreferredWidth;291 visualTreeNode.Height = actualHeight;292 visualTreeNode.X = (int)center_x - visualTreeNode.Width / 2;293 visualTreeNode.Y = y;294 }295 //width and height too small to draw in desired size296 else {297 visualTreeNode.Width = actualWidth;298 visualTreeNode.Height = actualHeight;299 visualTreeNode.X = x;300 visualTreeNode.Y = y;301 }302 303 //draw terminal node304 if (node.SubtreeCount == 0) {305 graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);306 graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);307 } else {308 graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);309 graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);310 }311 312 //draw name of symbol313 var text = node.ToString();314 graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat);315 316 //draw connection line to parent node317 if (!connectionPoint.IsEmpty && node.Parent != null) {318 var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node.Parent, node);319 using (Pen linePen = new Pen(visualLine.LineColor)) {320 linePen.DashStyle = visualLine.DashStyle;321 graphics.DrawLine(linePen, connectionPoint, new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y));322 }323 }324 325 //calculate areas for the subtrees according to their tree size and call drawFunctionTree326 Point connectFrom = new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y + visualTreeNode.Height);327 int[] xBoundaries = new int[node.SubtreeCount + 1];328 xBoundaries[0] = x;329 for (int i = 0; i < node.SubtreeCount; i++) {330 xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.GetSubtree(i).GetLength()) / (node.GetLength() - 1));331 DrawFunctionTree(node.GetSubtree(i), graphics, xBoundaries[i], y + height,332 xBoundaries[i + 1] - xBoundaries[i], height, connectFrom);272 using (var textBrush = new SolidBrush(visualTreeNode.TextColor)) 273 using (var nodeLinePen = new Pen(visualTreeNode.LineColor)) 274 using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) { 275 276 //calculate size of node 277 if (actualWidth >= visualTreeNode.PreferredWidth && actualHeight >= visualTreeNode.PreferredHeight) { 278 visualTreeNode.Width = visualTreeNode.PreferredWidth; 279 visualTreeNode.Height = visualTreeNode.PreferredHeight; 280 visualTreeNode.X = (int)center_x - visualTreeNode.Width / 2; 281 visualTreeNode.Y = (int)center_y - visualTreeNode.Height / 2; 282 } 283 //width too small to draw in desired sized 284 else if (actualWidth < visualTreeNode.PreferredWidth && actualHeight >= visualTreeNode.PreferredHeight) { 285 visualTreeNode.Width = actualWidth; 286 visualTreeNode.Height = visualTreeNode.PreferredHeight; 287 visualTreeNode.X = x; 288 visualTreeNode.Y = (int)center_y - visualTreeNode.Height / 2; 289 } 290 //height too small to draw in desired sized 291 else if (actualWidth >= visualTreeNode.PreferredWidth && actualHeight < visualTreeNode.PreferredHeight) { 292 visualTreeNode.Width = visualTreeNode.PreferredWidth; 293 visualTreeNode.Height = actualHeight; 294 visualTreeNode.X = (int)center_x - visualTreeNode.Width / 2; 295 visualTreeNode.Y = y; 296 } 297 //width and height too small to draw in desired size 298 else { 299 visualTreeNode.Width = actualWidth; 300 visualTreeNode.Height = actualHeight; 301 visualTreeNode.X = x; 302 visualTreeNode.Y = y; 303 } 304 305 //draw terminal node 306 if (node.SubtreeCount == 0) { 307 graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 308 graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 309 } else { 310 graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 311 graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 312 } 313 314 //draw name of symbol 315 var text = node.ToString(); 316 graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat); 317 318 //draw connection line to parent node 319 if (!connectionPoint.IsEmpty && node.Parent != null) { 320 var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node.Parent, node); 321 using (Pen linePen = new Pen(visualLine.LineColor)) { 322 linePen.DashStyle = visualLine.DashStyle; 323 graphics.DrawLine(linePen, connectionPoint, new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y)); 324 } 325 } 326 327 //calculate areas for the subtrees according to their tree size and call drawFunctionTree 328 Point connectFrom = new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y + visualTreeNode.Height); 329 int[] xBoundaries = new int[node.SubtreeCount + 1]; 330 xBoundaries[0] = x; 331 for (int i = 0; i < node.SubtreeCount; i++) { 332 xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.GetSubtree(i).GetLength()) / (node.GetLength() - 1)); 333 DrawFunctionTree(node.GetSubtree(i), graphics, xBoundaries[i], y + height, xBoundaries[i + 1] - xBoundaries[i], height, connectFrom); 334 } 333 335 } 334 336 } … … 346 348 graphics.Clear(backgroundColor); 347 349 var node = visualTreeNode.SymbolicExpressionTreeNode; 348 var textBrush = new SolidBrush(visualTreeNode.TextColor); 349 var nodeLinePen = new Pen(visualTreeNode.LineColor); 350 var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor); 351 //draw terminal node 352 if (node.SubtreeCount == 0) { 353 graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 354 graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 355 } else { 356 graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 357 graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 358 } 359 //draw name of symbol 360 var text = node.ToString(); 361 graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat); 350 using (var textBrush = new SolidBrush(visualTreeNode.TextColor)) 351 using (var nodeLinePen = new Pen(visualTreeNode.LineColor)) 352 using (var nodeFillBrush = new SolidBrush(visualTreeNode.FillColor)) { 353 //draw terminal node 354 if (node.SubtreeCount == 0) { 355 graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 356 graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 357 } else { 358 graphics.FillEllipse(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 359 graphics.DrawEllipse(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height); 360 } 361 //draw name of symbol 362 var text = node.ToString(); 363 graphics.DrawString(text, textFont, textBrush, new RectangleF(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height), stringFormat); 364 } 362 365 } 363 366 #endregion
Note: See TracChangeset
for help on using the changeset viewer.