source: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs @ 18065

Last change on this file since 18065 was 18065, checked in by dpiringe, 8 months ago

#3136

  • modified InfixExpressionParser to fully support SubFunctionSymbol
    • created a SubFunctionTreeNode to store the function arguments
  • modified StructureTemplateView to regenerate the content state
  • first implementation for the main tree build up logic
File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Text;
5using System.Windows.Forms;
6using HeuristicLab.Collections;
7using HeuristicLab.Core;
8using HeuristicLab.Data;
9using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
10using HeuristicLab.MainForm;
11using HeuristicLab.MainForm.WindowsForms;
12
13namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
14
15  [View("StructureTemplate View")]
16  [Content(typeof(StructureTemplate), true)]
17  public partial class StructureTemplateView : AsynchronousContentView {
18    public new StructureTemplate Content {
19      get => (StructureTemplate)base.Content;
20      set => base.Content = value;
21    }
22
23    public StructureTemplateView() {
24      InitializeComponent();
25      errorLabel.Text = "";
26    }
27
28    protected override void OnContentChanged() {
29      base.OnContentChanged();
30      if (Content == null) return;
31
32      expressionInput.Text = Content.Template;
33      symRegTreeChart.Content = Content.Tree;
34      subFunctionListView.Content = new ItemList<SubFunction>(Content.SubFunctions.Values).AsReadOnly();
35     
36      errorLabel.Text = "";
37     
38    }
39
40    private void parseButton_Click(object sender, EventArgs e) {
41      if(!string.IsNullOrEmpty(expressionInput.Text)) {
42        try {
43          Content.Template = expressionInput.Text;
44          symRegTreeChart.Content = Content.Tree;
45
46          var subFunctionList = new ItemList<SubFunction>();
47          foreach (var func in Content.SubFunctions.Values)
48            subFunctionList.Add(func);
49          subFunctionListView.Content = subFunctionList.AsReadOnly();
50
51          errorLabel.Text = "Template structure successfully parsed.";
52          errorLabel.ForeColor = Color.DarkGreen;
53        } catch (Exception ex) {
54          errorLabel.Text = ex.Message;
55          errorLabel.ForeColor = Color.DarkRed;
56        }
57      }
58    }
59
60    private void expressionInput_TextChanged(object sender, EventArgs e) {
61      errorLabel.Text = "Unparsed changes! Press parse button to save changes.";
62      errorLabel.ForeColor = Color.DarkOrange;
63    }
64
65  }
66}
Note: See TracBrowser for help on using the repository browser.