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

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

#3136

  • changed the StructureTemplateView -> nodes of type SubFunctionTreeNode are now clickable
    • still need to overhaul the UI elements
  • added a way to parse SubFunctionTreeNode with a unique name in InfixExpressionParser
File size: 2.4 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.Encodings.SymbolicExpressionTreeEncoding.Views;
11using HeuristicLab.MainForm;
12using HeuristicLab.MainForm.WindowsForms;
13
14namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
15
16  [View("StructureTemplate View")]
17  [Content(typeof(StructureTemplate), true)]
18  public partial class StructureTemplateView : AsynchronousContentView {
19    public new StructureTemplate Content {
20      get => (StructureTemplate)base.Content;
21      set => base.Content = value;
22    }
23
24    public StructureTemplateView() {
25      InitializeComponent();
26      errorLabel.Text = "";
27      treeChart.SymbolicExpressionTreeNodeClicked += TreeChart_SymbolicExpressionTreeNodeClicked;
28    }
29
30    private void TreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
31      var visualTreeNode = sender as VisualTreeNode<ISymbolicExpressionTreeNode>;
32      if(visualTreeNode != null) {
33        var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode;
34        viewHost.Content = subFunctionTreeNode?.SubFunction;
35      }
36    }
37
38    protected override void OnContentChanged() {
39      base.OnContentChanged();
40      if (Content == null) return;
41
42      expressionInput.Text = Content.Template;
43      symRegTreeChart.Content = Content.Tree;
44
45      treeChart.Tree = Content.Tree;
46
47      errorLabel.Text = "";
48     
49    }
50
51    private void parseButton_Click(object sender, EventArgs e) {
52      if(!string.IsNullOrEmpty(expressionInput.Text)) {
53        try {
54          Content.Template = expressionInput.Text;
55          symRegTreeChart.Content = Content.Tree;
56          treeChart.Tree = Content.Tree;
57
58          errorLabel.Text = "Template structure successfully parsed.";
59          errorLabel.ForeColor = Color.DarkGreen;
60        } catch (Exception ex) {
61          errorLabel.Text = ex.Message;
62          errorLabel.ForeColor = Color.DarkRed;
63        }
64      }
65    }
66
67    private void expressionInput_TextChanged(object sender, EventArgs e) {
68      errorLabel.Text = "Unparsed changes! Press parse button to save changes.";
69      errorLabel.ForeColor = Color.DarkOrange;
70    }
71
72  }
73}
Note: See TracBrowser for help on using the repository browser.