Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/MathSymbolicDataAnalysisModelView.cs @ 15428

Last change on this file since 15428 was 8110, checked in by gkronber, 12 years ago

#1773 switched back to the tree view as default for symbolic data analysis models instead of the math notation view.

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.IO;
24using System.Windows.Forms;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
29  [View("Mathematical Representation")]
30  [Content(typeof(ISymbolicDataAnalysisModel))]
31  public partial class MathSymbolicDataAnalysisModelView : AsynchronousContentView {
32    private SymbolicDataAnalysisExpressionLatexFormatter formatter = new SymbolicDataAnalysisExpressionLatexFormatter();
33    public MathSymbolicDataAnalysisModelView()
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 = formatter.Format(Content.SymbolicExpressionTree);
63      } else {
64        HtmlElement newElement = webBrowser.Document.GetElementById("model");
65        newElement.InnerText = string.Empty;
66      }
67      webBrowser.Document.InvokeScript("refreshModel");
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.