[6374] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Diagnostics;
|
---|
| 24 | using System.IO;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
| 28 | using HeuristicLab.Persistence.Default.Xml;
|
---|
| 29 | using Microsoft.VisualStudio.DebuggerVisualizers;
|
---|
| 30 |
|
---|
| 31 | [assembly: DebuggerVisualizer(
|
---|
| 32 | typeof(HeuristicLab.DebuggerVisualizers.SymbolicExpressionTreeVisualizer),
|
---|
| 33 | typeof(HeuristicLab.DebuggerVisualizers.HeuristicLabVisualizerObjectSource),
|
---|
| 34 | Target = typeof(HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.SymbolicExpressionTreeNode),
|
---|
| 35 | Description = "Visual Symbolic Expression Tree Node Debugger")]
|
---|
| 36 |
|
---|
| 37 | namespace 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 | }
|
---|