1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Forms;
|
---|
6 | using HeuristicLab.Collections;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Data;
|
---|
9 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
11 | using HeuristicLab.MainForm;
|
---|
12 | using HeuristicLab.MainForm.WindowsForms;
|
---|
13 |
|
---|
14 | namespace 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 | infoLabel.Text = "";
|
---|
27 | treeChart.SymbolicExpressionTreeNodeClicked += SymbolicExpressionTreeNodeClicked;
|
---|
28 |
|
---|
29 | }
|
---|
30 |
|
---|
31 | private void SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
|
---|
32 | var visualTreeNode = sender as VisualTreeNode<ISymbolicExpressionTreeNode>;
|
---|
33 | if(visualTreeNode != null) {
|
---|
34 | var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode;
|
---|
35 | if(Content.SubFunctions.TryGetValue(subFunctionTreeNode.Name, out SubFunction subFunction))
|
---|
36 | viewHost.Content = subFunction;
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected override void OnContentChanged() {
|
---|
41 | base.OnContentChanged();
|
---|
42 | if (Content == null) return;
|
---|
43 | expressionInput.Text = Content.Template;
|
---|
44 | linearScalingCheckBox.Checked = Content.ApplyLinearScaling;
|
---|
45 | PaintTree();
|
---|
46 | infoLabel.Text = "";
|
---|
47 | }
|
---|
48 |
|
---|
49 | private void ParseButtonClick(object sender, EventArgs e) {
|
---|
50 | Parse();
|
---|
51 | }
|
---|
52 |
|
---|
53 | private void ExpressionInputTextChanged(object sender, EventArgs e) {
|
---|
54 | infoLabel.Text = "Unparsed changes! Press parse button to save changes.";
|
---|
55 | infoLabel.ForeColor = Color.DarkOrange;
|
---|
56 | }
|
---|
57 |
|
---|
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 | }
|
---|
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 | }
|
---|
96 | }
|
---|
97 | }
|
---|