Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 18068 was 18068, checked in by dpiringe, 3 years ago

#3136

  • modified the StructureTemplateView to enable colorful tree nodes of type SubFunctionTreeNode
  • refactored SubFunctionTreeNode, SubFunction and StructureTemplate
File size: 2.8 KB
RevLine 
[18063]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;
[18067]10using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
[18063]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();
[18068]26      infoLabel.Text = "";
27      treeChart.SymbolicExpressionTreeNodeClicked += SymbolicExpressionTreeNodeClicked;
28     
[18063]29    }
30
[18068]31    private void SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
[18067]32      var visualTreeNode = sender as VisualTreeNode<ISymbolicExpressionTreeNode>;
33      if(visualTreeNode != null) {
34        var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode;
[18068]35        if(Content.SubFunctions.TryGetValue(subFunctionTreeNode.Name, out SubFunction subFunction))
36          viewHost.Content = subFunction;
[18067]37      }
38    }
39
[18065]40    protected override void OnContentChanged() {
41      base.OnContentChanged();
42      if (Content == null) return;
43      expressionInput.Text = Content.Template;
[18068]44      PaintTree();
45      infoLabel.Text = "";
[18065]46    }
47
[18068]48    private void ParseButtonClick(object sender, EventArgs e) {
[18063]49      if(!string.IsNullOrEmpty(expressionInput.Text)) {
50        try {
51          Content.Template = expressionInput.Text;
[18068]52          PaintTree();
53          infoLabel.Text = "Template structure successfully parsed.";
54          infoLabel.ForeColor = Color.DarkGreen;
[18063]55        } catch (Exception ex) {
[18068]56          infoLabel.Text = ex.Message;
57          infoLabel.ForeColor = Color.DarkRed;
[18063]58        }
59      }
60    }
61
[18068]62    private void ExpressionInputTextChanged(object sender, EventArgs e) {
63      infoLabel.Text = "Unparsed changes! Press parse button to save changes.";
64      infoLabel.ForeColor = Color.DarkOrange;
[18063]65    }
66
[18068]67
68    private void PaintTree() {
69      if(Content != null && Content.Tree != null) {
70        treeChart.Tree = Content.Tree;
71        foreach (var n in Content.Tree.IterateNodesPrefix()) {
72          if (n.Symbol is SubFunctionSymbol) {
73            var visualNode = treeChart.GetVisualSymbolicExpressionTreeNode(n);
74            visualNode.FillColor = Color.LightCyan;
75            visualNode.LineColor = Color.SlateGray;
76          }
77        }
78        treeChart.RepaintNodes();
79      }
80    }
[18063]81  }
82}
Note: See TracBrowser for help on using the repository browser.