Changeset 10524 for branches/HeuristicLab.EvolutionTracking
- Timestamp:
- 02/28/14 15:21:02 (11 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking
- Files:
-
- 3 deleted
- 14 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding merged: 10520,10522-10523
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views merged: 10520
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj
r10514 r10524 174 174 </ItemGroup> 175 175 <ItemGroup> 176 <Compile Include="Formatters\SymbolicExpressionTreeLatexFormatter.cs" /> 177 <Compile Include="LayoutEngines\BoxesLayoutEngine.cs" /> 178 <Compile Include="LayoutEngines\ILayoutEngine.cs" /> 179 <Compile Include="LayoutEngines\LayoutNode.cs" /> 180 <Compile Include="LayoutEngines\ReingoldTilfordLayoutEngine.cs" /> 176 181 <Compile Include="Plugin.cs" /> 177 182 <Compile Include="SymbolicExpressionGrammarAllowedChildSymbolsControl.cs"> … … 225 230 <DependentUpon>SymbolicExpressionView.cs</DependentUpon> 226 231 </Compile> 227 <Compile Include="Visual SymbolicExpressionTreeNode.cs" />228 <Compile Include="Visual SymbolicExpressionTreeNodeConnection.cs" />232 <Compile Include="VisualTreeNode.cs" /> 233 <Compile Include="VisualTreeNodeConnection.cs" /> 229 234 </ItemGroup> 230 235 <ItemGroup> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionGrammarAllowedChildSymbolsControl.cs
r9456 r10524 29 29 using HeuristicLab.PluginInfrastructure; 30 30 31 using VisualSymbolicExpressionTreeNode = HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.VisualTreeNode<HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ISymbolicExpressionTreeNode>; 32 31 33 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { 32 34 public sealed partial class SymbolicExpressionGrammarAllowedChildSymbolsControl : UserControl { … … 162 164 163 165 VisualSymbolicExpressionTreeNode clickedNode = (VisualSymbolicExpressionTreeNode)sender; 164 var selectedNode = clickedNode. SymbolicExpressionTreeNode;166 var selectedNode = clickedNode.Content; 165 167 if (selectedNode.SubtreeCount == 0) { 166 168 if (!selectedSymbolicExpressionTreeNodes.Contains(selectedNode)) … … 207 209 var visualNode = symbolicExpressionTreeChart.FindVisualSymbolicExpressionTreeNodeAt(coordinates.X, coordinates.Y); 208 210 if (visualNode != null) { 209 var node = visualNode. SymbolicExpressionTreeNode;211 var node = visualNode.Content; 210 212 var root = symbolicExpressionTreeChart.Tree.Root; 211 213 if (node == root || node.Parent == root) e.Effect = DragDropEffects.Copy; … … 223 225 var symbols = data as IEnumerable<ISymbol>; 224 226 225 if (node. SymbolicExpressionTreeNode== root) {227 if (node.Content == root) { 226 228 if (symbol != null) 227 229 Grammar.AddAllowedChildSymbol(root.Symbol, symbol); … … 229 231 foreach (var s in symbols) Grammar.AddAllowedChildSymbol(root.Symbol, s); 230 232 } else { 231 int argumentIndex = root.IndexOfSubtree(node. SymbolicExpressionTreeNode);233 int argumentIndex = root.IndexOfSubtree(node.Content); 232 234 if (symbol != null) 233 235 Grammar.AddAllowedChildSymbol(root.Symbol, symbol, argumentIndex); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs
r10501 r10524 49 49 this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); 50 50 this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 51 this.exportPgfLaTeXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 52 this.layoutEngineToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 53 this.reingoldTilfordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 54 this.boxesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 51 55 this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); 52 this.exportPgfLaTeXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();53 56 this.contextMenuStrip.SuspendLayout(); 54 57 this.SuspendLayout(); … … 58 61 this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 59 62 this.saveImageToolStripMenuItem, 60 this.exportPgfLaTeXToolStripMenuItem}); 63 this.exportPgfLaTeXToolStripMenuItem, 64 this.layoutEngineToolStripMenuItem}); 61 65 this.contextMenuStrip.Name = "contextMenuStrip"; 62 66 this.contextMenuStrip.Size = new System.Drawing.Size(166, 70); … … 65 69 // 66 70 this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem"; 67 this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(1 52, 22);71 this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 68 72 this.saveImageToolStripMenuItem.Text = "Save Image"; 69 73 this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click); 70 //71 // saveFileDialog72 //73 this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|EMF (*.emf)|*.emf";74 74 // 75 75 // exportPgfLaTeXToolStripMenuItem … … 79 79 this.exportPgfLaTeXToolStripMenuItem.Text = "Export Pgf/LaTeX"; 80 80 this.exportPgfLaTeXToolStripMenuItem.Click += new System.EventHandler(this.exportLatexToolStripMenuItem_Click); 81 // 82 // layoutEngineToolStripMenuItem 83 // 84 this.layoutEngineToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 85 this.reingoldTilfordToolStripMenuItem, 86 this.boxesToolStripMenuItem}); 87 this.layoutEngineToolStripMenuItem.Name = "layoutEngineToolStripMenuItem"; 88 this.layoutEngineToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 89 this.layoutEngineToolStripMenuItem.Text = "Layout Engine:"; 90 // 91 // reingoldTilfordToolStripMenuItem 92 // 93 this.reingoldTilfordToolStripMenuItem.Name = "reingoldTilfordToolStripMenuItem"; 94 this.reingoldTilfordToolStripMenuItem.Size = new System.Drawing.Size(161, 22); 95 this.reingoldTilfordToolStripMenuItem.Text = "Reingold-Tilford"; 96 this.reingoldTilfordToolStripMenuItem.Click += new System.EventHandler(this.reingoldTilfordToolStripMenuItem_Click); 97 // 98 // boxesToolStripMenuItem 99 // 100 this.boxesToolStripMenuItem.Name = "boxesToolStripMenuItem"; 101 this.boxesToolStripMenuItem.Size = new System.Drawing.Size(161, 22); 102 this.boxesToolStripMenuItem.Text = "Boxes"; 103 this.boxesToolStripMenuItem.Click += new System.EventHandler(this.boxesToolStripMenuItem_Click); 104 // 105 // saveFileDialog 106 // 107 this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|EMF (*.emf)|*.emf"; 81 108 // 82 109 // SymbolicExpressionTreeChart … … 103 130 protected System.Windows.Forms.SaveFileDialog saveFileDialog; 104 131 private System.Windows.Forms.ToolStripMenuItem exportPgfLaTeXToolStripMenuItem; 132 private System.Windows.Forms.ToolStripMenuItem layoutEngineToolStripMenuItem; 133 private System.Windows.Forms.ToolStripMenuItem reingoldTilfordToolStripMenuItem; 134 private System.Windows.Forms.ToolStripMenuItem boxesToolStripMenuItem; 105 135 } 106 136 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r10501 r10524 33 33 private Image image; 34 34 private readonly StringFormat stringFormat; 35 private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes; 36 private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines; 37 private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> layoutEngine; 38 private readonly SymbolicExpressionTreeLayoutAdapter layoutAdapter; 35 private Dictionary<ISymbolicExpressionTreeNode, VisualTreeNode<ISymbolicExpressionTreeNode>> visualTreeNodes; 36 private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection> visualLines; 37 private ILayoutEngine<ISymbolicExpressionTreeNode> layoutEngine; 39 38 40 39 private const int preferredNodeWidth = 70; 41 40 private const int preferredNodeHeight = 46; 42 private const int minHorizontalDistance = 20; 43 private const int minVerticalDistance = 20; 44 41 private const int minHorizontalDistance = 30; 42 private const int minVerticalDistance = 30; 45 43 46 44 public SymbolicExpressionTreeChart() { … … 52 50 this.backgroundColor = Color.White; 53 51 this.textFont = new Font(FontFamily.GenericSansSerif, 12); 54 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(); 55 layoutAdapter = new SymbolicExpressionTreeLayoutAdapter(); 52 // layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> { 53 layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> { 54 NodeWidth = preferredNodeWidth, 55 NodeHeight = preferredNodeHeight, 56 HorizontalSpacing = minHorizontalDistance, 57 VerticalSpacing = minVerticalDistance 58 }; 56 59 } 57 60 58 61 public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree) 59 62 : this() { 60 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>();61 layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();62 63 this.Tree = tree; 63 64 } … … 105 106 set { 106 107 tree = value; 107 visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode>();108 visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection>();109 108 if (tree != null) { 110 IEnumerable<ISymbolicExpressionTreeNode> nodes; 111 if (tree.Root.SubtreeCount == 1) nodes = tree.Root.GetSubtree(0).IterateNodesPrefix(); 112 else nodes = tree.Root.IterateNodesPrefix(); 113 foreach (ISymbolicExpressionTreeNode node in nodes) { 114 visualTreeNodes[node] = new VisualSymbolicExpressionTreeNode(node); 115 if (node.Parent != null) visualLines[Tuple.Create(node.Parent, node)] = new VisualSymbolicExpressionTreeNodeConnection(); 116 } 117 } 118 Repaint(); 109 Repaint(); 110 } 119 111 } 120 112 } … … 160 152 } 161 153 162 public void RepaintNode(Visual SymbolicExpressionTreeNodevisualNode) {154 public void RepaintNode(VisualTreeNode<ISymbolicExpressionTreeNode> visualNode) { 163 155 if (!suspendRepaint) { 164 156 using (var graphics = Graphics.FromImage(image)) { … … 182 174 } 183 175 184 public Visual SymbolicExpressionTreeNodeGetVisualSymbolicExpressionTreeNode(ISymbolicExpressionTreeNode symbolicExpressionTreeNode) {176 public VisualTreeNode<ISymbolicExpressionTreeNode> GetVisualSymbolicExpressionTreeNode(ISymbolicExpressionTreeNode symbolicExpressionTreeNode) { 185 177 if (visualTreeNodes.ContainsKey(symbolicExpressionTreeNode)) 186 178 return visualTreeNodes[symbolicExpressionTreeNode]; … … 188 180 } 189 181 190 public Visual SymbolicExpressionTreeNodeConnection GetVisualSymbolicExpressionTreeNodeConnection(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) {182 public VisualTreeNodeConnection GetVisualSymbolicExpressionTreeNodeConnection(ISymbolicExpressionTreeNode parent, ISymbolicExpressionTreeNode child) { 191 183 if (child.Parent != parent) throw new ArgumentException(); 192 184 var key = Tuple.Create(parent, child); 193 Visual SymbolicExpressionTreeNodeConnection connection = null;185 VisualTreeNodeConnection connection = null; 194 186 visualLines.TryGetValue(key, out connection); 195 187 return connection; … … 205 197 206 198 protected virtual void SymbolicExpressionTreeChart_MouseClick(object sender, MouseEventArgs e) { 207 VisualSymbolicExpressionTreeNodevisualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);199 var visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); 208 200 if (visualTreeNode != null) { 209 201 OnSymbolicExpressionTreeNodeClicked(visualTreeNode, e); … … 219 211 220 212 protected virtual void SymbolicExpressionTreeChart_MouseDoubleClick(object sender, MouseEventArgs e) { 221 Visual SymbolicExpressionTreeNodevisualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);213 VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); 222 214 if (visualTreeNode != null) 223 215 OnSymbolicExpressionTreeNodeDoubleClicked(visualTreeNode, e); … … 231 223 } 232 224 233 private Visual SymbolicExpressionTreeNodedraggedSymbolicExpressionTree;225 private VisualTreeNode<ISymbolicExpressionTreeNode> draggedSymbolicExpressionTree; 234 226 private MouseButtons dragButtons; 235 227 private void SymbolicExpressionTreeChart_MouseDown(object sender, MouseEventArgs e) { … … 243 235 244 236 private void SymbolicExpressionTreeChart_MouseMove(object sender, MouseEventArgs e) { 245 Visual SymbolicExpressionTreeNodevisualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y);237 VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode = FindVisualSymbolicExpressionTreeNodeAt(e.X, e.Y); 246 238 if (draggedSymbolicExpressionTree != null && 247 239 draggedSymbolicExpressionTree != visualTreeNode) { … … 258 250 } 259 251 260 public Visual SymbolicExpressionTreeNodeFindVisualSymbolicExpressionTreeNodeAt(int x, int y) {252 public VisualTreeNode<ISymbolicExpressionTreeNode> FindVisualSymbolicExpressionTreeNodeAt(int x, int y) { 261 253 foreach (var visualTreeNode in visualTreeNodes.Values) { 262 254 if (x >= visualTreeNode.X && x <= visualTreeNode.X + visualTreeNode.Width && … … 269 261 270 262 #region methods for painting the symbolic expression tree 271 private void DrawFunctionTree(ISymbolicExpressionTree symbolicExpressionTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) { 272 var layoutNodes = layoutAdapter.Convert(symbolicExpressionTree).ToList(); 273 if (symbolicExpressionTree.Root.SubtreeCount == 1) layoutNodes.RemoveAt(0); 274 layoutEngine.Reset(); 275 layoutEngine.Root = layoutNodes[0]; 276 layoutEngine.AddNodes(layoutNodes); 277 layoutEngine.MinHorizontalSpacing = (preferredWidth + minHDistance); 278 layoutEngine.MinVerticalSpacing = (preferredHeight + minVDistance); 279 layoutEngine.CalculateLayout(); 280 var bounds = layoutEngine.Bounds(); 281 282 double verticalScalingFactor = 1.0; 283 double layoutHeight = (bounds.Height + preferredHeight); 284 if (this.Height < layoutHeight) 285 verticalScalingFactor = this.Height / layoutHeight; 286 287 double horizontalScalingFactor = 1.0; 288 double layoutWidth = (bounds.Width + preferredWidth); 289 if (this.Width < layoutWidth) 290 horizontalScalingFactor = this.Width / layoutWidth; 291 292 double horizontalOffset; 293 if (this.Width > layoutWidth) 294 horizontalOffset = (this.Width - layoutWidth) / 2.0; 295 else 296 horizontalOffset = preferredWidth / 2.0; 297 298 var levels = layoutNodes.GroupBy(n => n.Level, n => n).ToList(); 299 for (int i = levels.Count - 1; i >= 0; --i) { 300 var nodes = levels[i].ToList(); 301 302 double minSpacing = double.MaxValue; 303 if (nodes.Count > 1) { 304 for (int j = 1; j < nodes.Count() - 1; ++j) { 305 var distance = nodes[j].X - nodes[j - 1].X; // guaranteed to be > 0 306 if (minSpacing > distance) minSpacing = distance; 307 } 308 } 309 minSpacing *= horizontalScalingFactor; 310 311 int minWidth = (int)Math.Round(preferredWidth * horizontalScalingFactor); 312 int width = (int)Math.Min(minSpacing, preferredWidth) - 2; // leave some pixels so that node margins don't overlap 313 314 foreach (var layoutNode in nodes) { 315 var visualNode = visualTreeNodes[layoutNode.Content]; 316 visualNode.Width = width; 317 visualNode.Height = (int)Math.Round(preferredHeight * verticalScalingFactor); 318 visualNode.X = (int)Math.Round((layoutNode.X + horizontalOffset) * horizontalScalingFactor + (minWidth - width) / 2.0); 319 visualNode.Y = (int)Math.Round(layoutNode.Y * verticalScalingFactor); 320 DrawTreeNode(graphics, visualNode); 321 } 322 } 323 // draw node connections 324 foreach (var visualNode in visualTreeNodes.Values) { 325 var node = visualNode.SymbolicExpressionTreeNode; 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; 270 layoutEngine.Initialize(actualRoot, n => n.Subtrees, n => n.GetLength(), n => n.GetDepth()); 271 layoutEngine.CalculateLayout(Width, Height); 272 273 var visualNodes = layoutEngine.GetVisualNodes().ToList(); 274 visualTreeNodes = visualNodes.ToDictionary(x => x.Content, x => x); 275 visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualTreeNodeConnection>(); 276 foreach (var node in visualNodes.Select(n => n.Content)) { 277 foreach (var subtree in node.Subtrees) { 278 visualLines.Add(new Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(node, subtree), new VisualTreeNodeConnection()); 279 } 280 } 281 // draw nodes and connections 282 foreach (var visualNode in visualNodes) { 283 DrawTreeNode(visualNode); 284 var node = visualNode.Content; 326 285 foreach (var subtree in node.Subtrees) { 327 286 var visualLine = GetVisualSymbolicExpressionTreeNodeConnection(node, subtree); … … 338 297 } 339 298 340 protected void DrawTreeNode(Visual SymbolicExpressionTreeNodevisualTreeNode) {299 protected void DrawTreeNode(VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) { 341 300 using (var graphics = Graphics.FromImage(image)) { 342 301 graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; … … 346 305 } 347 306 348 protected void DrawTreeNode(Graphics graphics, Visual SymbolicExpressionTreeNodevisualTreeNode) {307 protected void DrawTreeNode(Graphics graphics, VisualTreeNode<ISymbolicExpressionTreeNode> visualTreeNode) { 349 308 graphics.Clip = new Region(new Rectangle(visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width + 1, visualTreeNode.Height + 1)); 350 309 graphics.Clear(backgroundColor); 351 var node = visualTreeNode. SymbolicExpressionTreeNode;310 var node = visualTreeNode.Content; 352 311 using (var textBrush = new SolidBrush(visualTreeNode.TextColor)) 353 312 using (var nodeLinePen = new Pen(visualTreeNode.LineColor)) … … 408 367 } 409 368 #endregion 369 370 private void reingoldTilfordToolStripMenuItem_Click(object sender, EventArgs e) { 371 layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> { 372 NodeWidth = preferredNodeWidth, 373 NodeHeight = preferredNodeHeight, 374 HorizontalSpacing = minHorizontalDistance, 375 VerticalSpacing = minVerticalDistance 376 }; 377 Repaint(); 378 } 379 380 private void boxesToolStripMenuItem_Click(object sender, EventArgs e) { 381 layoutEngine = new BoxesLayoutEngine<ISymbolicExpressionTreeNode> { 382 NodeWidth = preferredNodeWidth, 383 NodeHeight = preferredNodeHeight, 384 HorizontalSpacing = minHorizontalDistance, 385 VerticalSpacing = minVerticalDistance 386 }; 387 Repaint(); 388 } 410 389 } 411 390 } -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeTile.cs
r10517 r10524 24 24 using System.Linq; 25 25 using HeuristicLab.Visualization; 26 using HeuristicLab.Visualization.Primitives; 26 27 using Rectangle = HeuristicLab.Visualization.Rectangle; 27 28 28 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { … … 40 41 41 42 public ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> LayoutEngine { get; set; } 42 public SymbolicExpressionTreeLayoutAdapter LayoutAdapter { get; set; }43 43 public SymbolicExpressionTreeTile(IChart chart) : base(chart) { } 44 44 public SymbolicExpressionTreeTile(IChart chart, ISymbolicExpressionTree tree) … … 50 50 private void GeneratePrimitives(double preferredNodeWidth, double preferredNodeHeight) { 51 51 Clear(); 52 var layoutNodes = LayoutAdapter.Convert(SymbolicExpressionTree).ToList(); 53 layoutNodes.RemoveAt(0); 54 LayoutEngine.Root = layoutNodes[0]; 52 LayoutEngine.Initialize(SymbolicExpressionTree.Root, node => node.Subtrees); 55 53 LayoutEngine.CalculateLayout(); 56 54 57 var primitivesMap = new Dictionary< LayoutNode<ISymbolicExpressionTreeNode>, IPrimitive>(); // both Ellipse and Rectangle are derived from the RectangularPrimitiveBase55 var primitivesMap = new Dictionary<ISymbolicExpressionTreeNode, IPrimitive>(); // both Ellipse and Rectangle are derived from the RectangularPrimitiveBase 58 56 var font = new Font(FontFamily.GenericSansSerif, 10, GraphicsUnit.Pixel); 59 57 60 foreach (var node in layoutNodes) { 61 var lowerLeft = new PointD(node.X, node.Y); 62 var upperRight = new PointD(node.X + preferredNodeWidth, node.Y + preferredNodeHeight); 58 var visualNodes = LayoutEngine.GetVisualNodes().ToList(); 59 var visualNodeMap = visualNodes.ToDictionary(x => x.Content, x => x); 63 60 61 foreach (var visualNode in visualNodes) { 62 var lowerLeft = new PointD(visualNode.X, visualNode.Y); 63 var upperRight = new PointD(visualNode.X + preferredNodeWidth, visualNode.Y + preferredNodeHeight); 64 var node = visualNode.Content; 64 65 RectangularPrimitiveBase rectangularPrimitive; 65 if (node. IsLeaf) {66 rectangularPrimitive = new LabeledRectangle(Chart, lowerLeft, upperRight) { Font = font, Text = node.Content.ToString() };66 if (node.SubtreeCount == 0) { 67 rectangularPrimitive = new Rectangle(Chart, lowerLeft, upperRight) { Font = font, Text = visualNode.Content.ToString() }; 67 68 } else { 68 rectangularPrimitive = new LabeledEllipse(Chart, lowerLeft, upperRight) { Font = font, Text = node.Content.ToString() };69 rectangularPrimitive = new Ellipse(Chart, lowerLeft, upperRight) { Font = font, Text = visualNode.Content.ToString() }; 69 70 } 70 71 … … 73 74 } 74 75 75 foreach (var node in layoutNodes.Where(n => n.Children != null)) { 76 foreach (var child in node.Children) { 76 foreach (var node in visualNodes.Where(n => n.Content.SubtreeCount > 0)) { 77 var parent = node.Content; 78 foreach (var child in parent.Subtrees.Select(x => visualNodeMap[x])) { 77 79 var start = new PointD(node.X + preferredNodeWidth / 2, node.Y + preferredNodeHeight); 78 80 var end = new PointD(child.X + preferredNodeWidth / 2, child.Y); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r10514 r10524 187 187 <Compile Include="Formatters\SymbolicExpressionTreeGraphvizFormatter.cs" /> 188 188 <Compile Include="Formatters\SymbolicExpressionTreeHierarchicalFormatter.cs" /> 189 <Compile Include="Formatters\SymbolicExpressionTreeLatexFormatter.cs" />190 <Compile Include="Interfaces\ILayoutAdapter.cs" />191 189 <Compile Include="Interfaces\IReadOnlySymbol.cs" /> 192 190 <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" /> … … 210 208 <Compile Include="Interfaces\ISymbolicExpressionTreeStringFormatter.cs" /> 211 209 <Compile Include="Interfaces\Operators\ISymbolicExpressionTreeSizeConstraintOperator.cs" /> 212 <Compile Include="LayoutEngines\LayoutNode.cs" />213 <Compile Include="LayoutEngines\ReingoldTilfordLayoutEngine.cs" />214 <Compile Include="LayoutEngines\SymbolicExpressionTreeLayoutAdapter.cs" />215 210 <Compile Include="Manipulators\ChangeNodeTypeManipulation.cs" /> 216 211 <Compile Include="Interfaces\Operators\ISymbolicExpressionTreeManipulator.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views merged: 10521-10522
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r10501 r10524 97 97 98 98 private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { 99 var visualNode = (Visual SymbolicExpressionTreeNode)sender;100 var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode. SymbolicExpressionTreeNode;99 var visualNode = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; 100 var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.Content; 101 101 if (symbExprTreeNode == null) return; 102 102 var tree = Content.Model.SymbolicExpressionTree; … … 126 126 double max = impacts.Max(); 127 127 double min = impacts.Min(); 128 foreach ( ISymbolicExpressionTreeNodetreeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) {129 Visual SymbolicExpressionTreeNodevisualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);128 foreach (var treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { 129 VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 130 130 131 131 if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) { -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs
r9456 r10524 33 33 internal sealed partial class InteractiveSymbolicExpressionTreeChart : SymbolicExpressionTreeChart { 34 34 private ISymbolicExpressionTreeNode tempNode; // node in clipboard (to be cut/copy/pasted etc) 35 private Visual SymbolicExpressionTreeNodecurrSelected; // currently selected node35 private VisualTreeNode<ISymbolicExpressionTreeNode> currSelected; // currently selected node 36 36 private enum EditOp { NoOp, CopySubtree, CutSubtree } 37 37 private EditOp lastOp = EditOp.NoOp; … … 65 65 pasteToolStripMenuItem.Visible = false; 66 66 } else { 67 var node = currSelected. SymbolicExpressionTreeNode;67 var node = currSelected.Content; 68 68 insertNodeToolStripMenuItem.Visible = true; 69 69 changeNodeToolStripMenuItem.Visible = true; … … 77 77 pasteToolStripMenuItem.Enabled = tempNode != null && insertNodeToolStripMenuItem.Enabled 78 78 && !(lastOp == EditOp.CutSubtree 79 && tempNode.IterateNodesBreadth().Contains(currSelected. SymbolicExpressionTreeNode));79 && tempNode.IterateNodesBreadth().Contains(currSelected.Content)); 80 80 } 81 81 } 82 82 83 83 protected override void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { 84 currSelected = (Visual SymbolicExpressionTreeNode)sender; ;84 currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; ; 85 85 if (currSelected != null) { 86 86 currSelected.LineColor = Color.FromArgb(130, currSelected.LineColor); … … 104 104 105 105 private void insertNodeToolStripMenuItem_Click(object sender, EventArgs e) { 106 if (currSelected == null || currSelected. SymbolicExpressionTreeNodeis SymbolicExpressionTreeTerminalNode) return;107 var parent = currSelected. SymbolicExpressionTreeNode;106 if (currSelected == null || currSelected.Content is SymbolicExpressionTreeTerminalNode) return; 107 var parent = currSelected.Content; 108 108 109 109 using (var dialog = new InsertNodeDialog()) { … … 138 138 if (currSelected == null) return; 139 139 140 var node = (ISymbolicExpressionTreeNode)currSelected. SymbolicExpressionTreeNode.Clone();141 var originalNode = currSelected. SymbolicExpressionTreeNode;140 var node = (ISymbolicExpressionTreeNode)currSelected.Content.Clone(); 141 var originalNode = currSelected.Content; 142 142 143 143 ISymbolicExpressionTreeNode newNode = null; … … 180 180 } 181 181 } 182 tempNode = currSelected. SymbolicExpressionTreeNode;182 tempNode = currSelected.Content; 183 183 foreach (var node in tempNode.IterateNodesPostfix()) { 184 184 var visualNode = GetVisualSymbolicExpressionTreeNode(node); … … 194 194 } 195 195 private void removeNodeToolStripMenuItem_Click(object sender, EventArgs e) { 196 var node = currSelected. SymbolicExpressionTreeNode;196 var node = currSelected.Content; 197 197 if (node == tempNode) tempNode = null; 198 198 ModifyTree(Tree, node.Parent, node, null, removeSubtree: false); … … 200 200 } 201 201 private void removeSubtreeToolStripMenuItem_Click(object sender, EventArgs e) { 202 var node = currSelected. SymbolicExpressionTreeNode;202 var node = currSelected.Content; 203 203 if (node.IterateNodesPostfix().Contains(tempNode)) tempNode = null; 204 204 ModifyTree(Tree, node.Parent, node, null, removeSubtree: true); … … 209 209 if (!(lastOp == EditOp.CopySubtree || lastOp == EditOp.CutSubtree)) return; 210 210 // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node 211 var node = currSelected. SymbolicExpressionTreeNode;211 var node = currSelected.Content; 212 212 if (node is ConstantTreeNode || node is VariableTreeNode) return; 213 213 // check if the currently selected node can accept the copied node as a child -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisExpressionLineageExplorerView.cs
r10517 r10524 15 15 public partial class SymbolicDataAnalysisExpressionLineageExplorerView : AsynchronousContentView { 16 16 private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionTreeNodeLayoutEngine; 17 private readonly SymbolicExpressionTreeLayoutAdapter symbolicExpressionTreeLayoutAdapter;18 17 19 18 private readonly Dictionary<TreeNode, ISymbolicExpressionTree> treeMap; … … 32 31 InitializeComponent(); 33 32 symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> { 34 MinHorizontalSpacing = MinHorizontalSpacing + PreferredNodeWidth, 35 MinVerticalSpacing = MinVerticalSpacing + PreferredNodeHeight 33 HorizontalSpacing = MinHorizontalSpacing, 34 VerticalSpacing = MinVerticalSpacing, 35 NodeWidth = PreferredNodeWidth, 36 NodeHeight = PreferredNodeHeight 36 37 }; 37 symbolicExpressionTreeLayoutAdapter = new SymbolicExpressionTreeLayoutAdapter();38 38 treeMap = new Dictionary<TreeNode, ISymbolicExpressionTree>(); 39 39 double width = lineageExplorerChart.PreferredSize.Width; … … 74 74 var chart = lineageExplorerChart.Chart; 75 75 var tile = new SymbolicExpressionTreeTile(chart) { 76 LayoutAdapter = symbolicExpressionTreeLayoutAdapter,77 76 LayoutEngine = symbolicExpressionTreeNodeLayoutEngine, 78 77 PreferredNodeWidth = PreferredNodeWidth, -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TextualSymbolicDataAnalysisModelView.designer.cs
r9456 r10524 48 48 this.SuspendLayout(); 49 49 // 50 // expressionTreeView50 // symbolicExpressionTreeView 51 51 // 52 52 this.symbolicExpressionTreeView.AllowDrop = true; … … 54 54 this.symbolicExpressionTreeView.Content = null; 55 55 this.symbolicExpressionTreeView.Dock = System.Windows.Forms.DockStyle.Fill; 56 this.symbolicExpressionTreeView.Font = new System.Drawing.Font("Consolas", 8.25F); 56 57 this.symbolicExpressionTreeView.Location = new System.Drawing.Point(0, 0); 57 this.symbolicExpressionTreeView.Name = " expressionTreeView";58 this.symbolicExpressionTreeView.Name = "symbolicExpressionTreeView"; 58 59 this.symbolicExpressionTreeView.ReadOnly = false; 59 60 this.symbolicExpressionTreeView.Size = new System.Drawing.Size(352, 413); 60 61 this.symbolicExpressionTreeView.TabIndex = 0; 61 62 // 62 // SymbolicExpressionModelView63 // TextualSymbolicDataAnalysisModelView 63 64 // 64 65 this.AllowDrop = true; 65 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);66 66 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 67 67 this.Controls.Add(this.symbolicExpressionTreeView); 68 this.Name = " SymbolicExpressionModelView";68 this.Name = "TextualSymbolicDataAnalysisModelView"; 69 69 this.Size = new System.Drawing.Size(352, 413); 70 70 this.ResumeLayout(false);
Note: See TracChangeset
for help on using the changeset viewer.