Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicDataAnalysisModelMathView.cs @ 17507

Last change on this file since 17507 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 2.8 KB
RevLine 
[7446]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[7446]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;
[8110]23using System.IO;
[7446]24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
29  [View("Mathematical Representation")]
[8110]30  [Content(typeof(ISymbolicDataAnalysisModel))]
[14255]31  public partial class SymbolicDataAnalysisModelMathView : AsynchronousContentView {
32    protected readonly SymbolicDataAnalysisExpressionLatexFormatter Formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
33    public SymbolicDataAnalysisModelMathView()
[7446]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);
[8110]43      webBrowser.Navigate("file://" + Path.Combine(hlDir, "displayModelFrame.html"));
[7446]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");
[14255]62        newElement.InnerText = GetFormattedTree();
[13984]63        webBrowser.Document.InvokeScript("refreshModel");
[7446]64      } else {
65        HtmlElement newElement = webBrowser.Document.GetElementById("model");
66        newElement.InnerText = string.Empty;
67      }
68    }
[14255]69
70    protected virtual string GetFormattedTree() {
71      return Formatter.Format(Content.SymbolicExpressionTree);
72    }
[7446]73  }
74}
Note: See TracBrowser for help on using the repository browser.