[18063] | 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;
|
---|
[18067] | 10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
[18063] | 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();
|
---|
[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 | }
|
---|