Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3136

  • added linear scaling support for structure template parameter
File size: 3.2 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;
[18069]44      linearScalingCheckBox.Checked = Content.ApplyLinearScaling;
[18068]45      PaintTree();
46      infoLabel.Text = "";
[18065]47    }
48
[18068]49    private void ParseButtonClick(object sender, EventArgs e) {
[18069]50      Parse();
[18063]51    }
52
[18068]53    private void ExpressionInputTextChanged(object sender, EventArgs e) {
54      infoLabel.Text = "Unparsed changes! Press parse button to save changes.";
55      infoLabel.ForeColor = Color.DarkOrange;
[18063]56    }
57
[18068]58
59    private void PaintTree() {
60      if(Content != null && Content.Tree != null) {
61        treeChart.Tree = Content.Tree;
62        foreach (var n in Content.Tree.IterateNodesPrefix()) {
63          if (n.Symbol is SubFunctionSymbol) {
64            var visualNode = treeChart.GetVisualSymbolicExpressionTreeNode(n);
65            visualNode.FillColor = Color.LightCyan;
66            visualNode.LineColor = Color.SlateGray;
67          }
68        }
69        treeChart.RepaintNodes();
70      }
71    }
[18069]72
73    private void ExpressionInputKeyUp(object sender, KeyEventArgs e) {
74      if (e.KeyCode == Keys.Enter)
75        Parse();
76    }
77
78    private void Parse() {
79      if (!string.IsNullOrEmpty(expressionInput.Text)) {
80        try {
81          Content.Template = expressionInput.Text;
82          PaintTree();
83          infoLabel.Text = "Template structure successfully parsed.";
84          infoLabel.ForeColor = Color.DarkGreen;
85        } catch (Exception ex) {
86          infoLabel.Text = ex.Message;
87          infoLabel.ForeColor = Color.DarkRed;
88        }
89      }
90    }
91
92    private void LinearScalingCheckBoxCheckStateChanged(object sender, EventArgs e) {
93      Content.ApplyLinearScaling = linearScalingCheckBox.Checked;
94      PaintTree();
95    }
[18063]96  }
97}
Note: See TracBrowser for help on using the repository browser.