1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2019 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.IO;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 | using HeuristicLab.MainForm.WindowsForms;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
29 | [View("Mathematical Representation")]
|
---|
30 | [Content(typeof(ISymbolicDataAnalysisModel))]
|
---|
31 | public partial class SymbolicDataAnalysisModelMathView : AsynchronousContentView {
|
---|
32 | protected readonly SymbolicDataAnalysisExpressionLatexFormatter Formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
|
---|
33 | public SymbolicDataAnalysisModelMathView()
|
---|
34 | : base() {
|
---|
35 | InitializeComponent();
|
---|
36 | webBrowser.ScrollBarsEnabled = true;
|
---|
37 | webBrowser.ScriptErrorsSuppressed = false;
|
---|
38 |
|
---|
39 | // update for the first time after page has loaded
|
---|
40 | webBrowser.DocumentCompleted += (sender, args) => RefreshHtmlPage();
|
---|
41 |
|
---|
42 | string hlDir = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory);
|
---|
43 | webBrowser.Navigate("file://" + Path.Combine(hlDir, "displayModelFrame.html"));
|
---|
44 | }
|
---|
45 |
|
---|
46 | public new ISymbolicDataAnalysisModel Content {
|
---|
47 | get { return (ISymbolicDataAnalysisModel)base.Content; }
|
---|
48 | set { base.Content = value; }
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void OnContentChanged() {
|
---|
52 | base.OnContentChanged();
|
---|
53 | RefreshHtmlPage();
|
---|
54 | }
|
---|
55 |
|
---|
56 | private void RefreshHtmlPage() {
|
---|
57 | // only update if the page has loaded already
|
---|
58 | if (webBrowser.Document == null || webBrowser.Document.Body == null) return;
|
---|
59 |
|
---|
60 | if (Content != null) {
|
---|
61 | HtmlElement newElement = webBrowser.Document.GetElementById("model");
|
---|
62 | newElement.InnerText = GetFormattedTree();
|
---|
63 | webBrowser.Document.InvokeScript("refreshModel");
|
---|
64 | } else {
|
---|
65 | HtmlElement newElement = webBrowser.Document.GetElementById("model");
|
---|
66 | newElement.InnerText = string.Empty;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | protected virtual string GetFormattedTree() {
|
---|
71 | return Formatter.Format(Content.SymbolicExpressionTree);
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|