Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/tools/DebuggerVisualizer/HeuristicLab.DebuggerVisualizers/SymbolicExpressionTreeVisualizer.cs @ 12515

Last change on this file since 12515 was 6374, checked in by mkommend, 14 years ago

#1549: Added first version of debugger visualizers

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Diagnostics;
24using System.IO;
25using System.Windows.Forms;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
28using HeuristicLab.Persistence.Default.Xml;
29using Microsoft.VisualStudio.DebuggerVisualizers;
30
31[assembly: DebuggerVisualizer(
32typeof(HeuristicLab.DebuggerVisualizers.SymbolicExpressionTreeVisualizer),
33typeof(HeuristicLab.DebuggerVisualizers.HeuristicLabVisualizerObjectSource),
34Target = typeof(HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.SymbolicExpressionTreeNode),
35Description = "Visual Symbolic Expression Tree Node Debugger")]
36
37namespace HeuristicLab.DebuggerVisualizers {
38  public class SymbolicExpressionTreeVisualizer : DialogDebuggerVisualizer {
39    public SymbolicExpressionTreeVisualizer() : base() { }
40
41    protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) {
42      if (windowService == null)
43        throw new ArgumentNullException("windowService");
44      if (objectProvider == null)
45        throw new ArgumentNullException("objectProvider");
46
47      ISymbolicExpressionTreeNode treeNode;
48      byte[] serializedObjectByteArray = objectProvider.GetObject() as byte[];
49      using (MemoryStream memStream = new MemoryStream(serializedObjectByteArray)) {
50        treeNode = XmlParser.Deserialize<ISymbolicExpressionTreeNode>(memStream);
51      }
52
53      using (Form displayForm = new Form()) {
54        var graphicalSymbolicExpressionTreeChart = new SymbolicExpressionTreeChart();
55        graphicalSymbolicExpressionTreeChart.Tree = new SymbolicExpressionTree(treeNode);
56        graphicalSymbolicExpressionTreeChart.Dock = DockStyle.Fill;
57
58        displayForm.Controls.Add(graphicalSymbolicExpressionTreeChart);
59        displayForm.Text = treeNode.ToString();
60
61        windowService.ShowDialog(displayForm);
62      }
63    }
64
65    public static void TestShowVisualizer(object objectToVisualize) {
66      VisualizerDevelopmentHost visualizerHost = new VisualizerDevelopmentHost(objectToVisualize, typeof(SymbolicExpressionTreeVisualizer), typeof(HeuristicLabVisualizerObjectSource));
67      visualizerHost.ShowVisualizer();
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.