Changeset 10561
- Timestamp:
- 03/06/14 15:07:05 (11 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/BoxesLayoutEngine.cs
r10520 r10561 131 131 } 132 132 133 public IEnumerable<T> GetContentNodes() { 134 return nodeMap.Keys; 135 } 136 133 137 public IEnumerable<VisualTreeNode<T>> GetVisualNodes() { 134 138 return nodeMap.Values; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ILayoutEngine.cs
r10520 r10561 22 22 Func<T, int> GetDepth { get; set; } 23 23 24 IEnumerable<T> GetContentNodes(); 24 25 IEnumerable<VisualTreeNode<T>> GetVisualNodes(); 25 26 Dictionary<T, PointF> GetCoordinates(); -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/LayoutEngines/ReingoldTilfordLayoutEngine.cs
r10531 r10561 63 63 Expand(node); 64 64 } 65 } 66 67 public IEnumerable<T> GetContentNodes() { 68 return nodeMap.Keys; 65 69 } 66 70 … … 191 195 // reset layout-related parameters 192 196 layoutNode.Reset(); 197 // reset the width and height since they might have been affected by scaling 198 layoutNode.Width = NodeWidth; 199 layoutNode.Height = NodeHeight; 193 200 } 194 201 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs
r10520 r10561 105 105 106 106 var tree = new SymbolicExpressionTree(new SymbolicExpressionTreeNode(Symbol)); 107 symbolicExpressionTreeChart.SuspendRepaint = true;108 107 if (Grammar.GetMaximumSubtreeCount(Symbol) > 0) { 109 108 for (int i = 0; i < Grammar.GetMaximumSubtreeCount(Symbol); i++) { … … 118 117 } 119 118 symbolicExpressionTreeChart.Tree = tree; 120 119 symbolicExpressionTreeChart.SuspendRepaint = true; 121 120 foreach (var subtreeNode in tree.Root.Subtrees) { 122 121 foreach (var allowedChildNode in subtreeNode.Subtrees) { … … 144 143 } 145 144 } 146 147 145 symbolicExpressionTreeChart.SuspendRepaint = false; 148 146 UpdateSelectedSymbolicExpressionTreeNodes(); … … 155 153 else visualNode.FillColor = Color.LightSteelBlue; 156 154 } 157 symbolicExpressionTreeChart.Repaint ();155 symbolicExpressionTreeChart.RepaintNodes(); 158 156 } 159 157 -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r10531 r10561 58 58 } 59 59 60 private ILayoutEngine<ISymbolicExpressionTreeNode> TreeLayoutEngine { 61 get { return layoutEngine; } 62 set { 63 layoutEngine = value; 64 InitializeLayout(); 65 Repaint(); 66 } 67 } 68 60 69 public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree) 61 70 : this() { … … 128 137 if (this.Width <= 1 || this.Height <= 1) 129 138 this.image = new Bitmap(1, 1); 130 else 139 else { 131 140 this.image = new Bitmap(Width, Height); 141 } 132 142 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 } 133 151 } 134 152 … … 137 155 this.GenerateImage(); 138 156 this.Refresh(); 157 OnRepaint(this, EventArgs.Empty); 139 158 } 140 159 } … … 147 166 foreach (var visualNode in visualTreeNodes.Values) { 148 167 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 } 149 173 } 150 174 } … … 170 194 graphics.Clear(backgroundColor); 171 195 if (tree != null) { 172 DrawFunctionTree( tree,graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);196 DrawFunctionTree(graphics, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance); 173 197 } 174 198 } … … 236 260 237 261 private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) { 238 239 262 VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); 240 263 if (draggedSymbolicExpressionTree != null && … … 262 285 #endregion 263 286 287 #region initialize the layout 264 288 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 } 266 293 layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()); 267 294 layoutEngine.CalculateLayout(this.Width, this.Height); 295 UpdateDictionaries(); 296 } 297 298 private void UpdateDictionaries() { 268 299 var visualNodes = layoutEngine.GetVisualNodes().ToList(); 269 300 //populate the visual nodes and visual connections dictionaries … … 276 307 } 277 308 } 278 309 #endregion 279 310 #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) { 281 312 //we assume here that the layout has already been initialized when the symbolic expression tree was changed 282 313 //recalculate layout according to new node widths and spacing … … 286 317 layoutEngine.VerticalSpacing = minVDistance; 287 318 layoutEngine.CalculateLayout(Width, Height); 319 UpdateDictionaries();//this will reset the visual nodes, therefore colors will be reset to default values 288 320 var visualNodes = visualTreeNodes.Values; 289 321 //draw nodes and connections … … 333 365 } 334 366 } 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 } 335 378 #endregion 336 379 #region save image … … 348 391 Image image = new Bitmap(Width, Height); 349 392 using (Graphics g = Graphics.FromImage(image)) { 350 DrawFunctionTree( tree,g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);393 DrawFunctionTree(g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance); 351 394 } 352 395 image.Save(filename); … … 358 401 using (Metafile file = new Metafile(filename, g.GetHdc())) { 359 402 using (Graphics emfFile = Graphics.FromImage(file)) { 360 DrawFunctionTree( tree,emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);403 DrawFunctionTree(emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance); 361 404 } 362 405 } … … 377 420 378 421 private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) { 379 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> {422 TreeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> { 380 423 NodeWidth = preferredNodeWidth, 381 424 NodeHeight = preferredNodeHeight, … … 383 426 VerticalSpacing = minVerticalDistance 384 427 }; 385 InitializeLayout();386 Repaint();387 428 } 388 429 389 430 private void boxesToolStripMenuItem_Click(object sender, EventArgs e) { 390 layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> {431 TreeLayoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> { 391 432 NodeWidth = preferredNodeWidth, 392 433 NodeHeight = preferredNodeHeight, … … 394 435 VerticalSpacing = minVerticalDistance 395 436 }; 396 InitializeLayout();397 Repaint();398 437 } 399 438 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs
r10521 r10561 218 218 if (tempNode.IterateNodesBreadth().Contains(node)) 219 219 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 221 221 ModifyTree(Tree, node, null, tempNode); //insert it as a child to the new parent 222 222 break;
Note: See TracChangeset
for help on using the changeset viewer.