[18099] | 1 | using System;
|
---|
[18063] | 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Drawing;
|
---|
[18075] | 4 | using System.Linq;
|
---|
[18063] | 5 | using System.Text;
|
---|
| 6 | using System.Windows.Forms;
|
---|
| 7 | using HeuristicLab.Collections;
|
---|
| 8 | using HeuristicLab.Core;
|
---|
| 9 | using HeuristicLab.Data;
|
---|
| 10 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[18067] | 11 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
[18063] | 12 | using HeuristicLab.MainForm;
|
---|
| 13 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 14 |
|
---|
| 15 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
| 16 |
|
---|
| 17 | [View("StructureTemplate View")]
|
---|
| 18 | [Content(typeof(StructureTemplate), true)]
|
---|
| 19 | public partial class StructureTemplateView : AsynchronousContentView {
|
---|
| 20 | public new StructureTemplate Content {
|
---|
| 21 | get => (StructureTemplate)base.Content;
|
---|
| 22 | set => base.Content = value;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public StructureTemplateView() {
|
---|
| 26 | InitializeComponent();
|
---|
[18068] | 27 | infoLabel.Text = "";
|
---|
[18075] | 28 | this.Resize += StructureTemplateViewResize;
|
---|
[18099] | 29 | splitContainer.SplitterMoved += SplitContainerSplitterMoved;
|
---|
[18068] | 30 | treeChart.SymbolicExpressionTreeNodeClicked += SymbolicExpressionTreeNodeClicked;
|
---|
| 31 |
|
---|
[18063] | 32 | }
|
---|
| 33 |
|
---|
[18099] | 34 | private void SplitContainerSplitterMoved(object sender, EventArgs e) {
|
---|
| 35 | PaintTree();
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[18075] | 38 | private void StructureTemplateViewResize(object sender, EventArgs e) {
|
---|
| 39 | PaintTree();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
[18068] | 42 | private void SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
|
---|
[18067] | 43 | var visualTreeNode = sender as VisualTreeNode<ISymbolicExpressionTreeNode>;
|
---|
| 44 | if(visualTreeNode != null) {
|
---|
| 45 | var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode;
|
---|
[18151] | 46 | var selectedSubFunction = Content.SubFunctions.Where(x => x.Name == subFunctionTreeNode.Name).FirstOrDefault();
|
---|
| 47 | if(subFunctionTreeNode != null && selectedSubFunction != null)
|
---|
| 48 | viewHost.Content = selectedSubFunction;
|
---|
[18067] | 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[18065] | 52 | protected override void OnContentChanged() {
|
---|
| 53 | base.OnContentChanged();
|
---|
| 54 | if (Content == null) return;
|
---|
| 55 | expressionInput.Text = Content.Template;
|
---|
[18099] | 56 | linearScalingCheckBox.Checked = Content.ApplyLinearScaling;
|
---|
[18068] | 57 | PaintTree();
|
---|
| 58 | infoLabel.Text = "";
|
---|
[18065] | 59 | }
|
---|
| 60 |
|
---|
[18068] | 61 | private void ParseButtonClick(object sender, EventArgs e) {
|
---|
[18069] | 62 | Parse();
|
---|
[18063] | 63 | }
|
---|
| 64 |
|
---|
[18068] | 65 | private void ExpressionInputTextChanged(object sender, EventArgs e) {
|
---|
| 66 | infoLabel.Text = "Unparsed changes! Press parse button to save changes.";
|
---|
| 67 | infoLabel.ForeColor = Color.DarkOrange;
|
---|
[18063] | 68 | }
|
---|
| 69 |
|
---|
[18068] | 70 | private void PaintTree() {
|
---|
| 71 | if(Content != null && Content.Tree != null) {
|
---|
| 72 | treeChart.Tree = Content.Tree;
|
---|
| 73 | foreach (var n in Content.Tree.IterateNodesPrefix()) {
|
---|
| 74 | if (n.Symbol is SubFunctionSymbol) {
|
---|
| 75 | var visualNode = treeChart.GetVisualSymbolicExpressionTreeNode(n);
|
---|
| 76 | visualNode.FillColor = Color.LightCyan;
|
---|
| 77 | visualNode.LineColor = Color.SlateGray;
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | treeChart.RepaintNodes();
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
[18069] | 83 |
|
---|
| 84 | private void ExpressionInputKeyUp(object sender, KeyEventArgs e) {
|
---|
| 85 | if (e.KeyCode == Keys.Enter)
|
---|
| 86 | Parse();
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | private void Parse() {
|
---|
[18073] | 90 | viewHost.Content = null; // reset active detail view
|
---|
[18069] | 91 | if (!string.IsNullOrEmpty(expressionInput.Text)) {
|
---|
| 92 | try {
|
---|
| 93 | Content.Template = expressionInput.Text;
|
---|
| 94 | PaintTree();
|
---|
| 95 | infoLabel.Text = "Template structure successfully parsed.";
|
---|
| 96 | infoLabel.ForeColor = Color.DarkGreen;
|
---|
[18075] | 97 | } catch (AggregateException ex) {
|
---|
| 98 | infoLabel.Text = string.Join("\n", ex.InnerExceptions.Select(x => x.Message));
|
---|
| 99 | infoLabel.ForeColor = Color.DarkRed;
|
---|
[18069] | 100 | } catch (Exception ex) {
|
---|
| 101 | infoLabel.Text = ex.Message;
|
---|
| 102 | infoLabel.ForeColor = Color.DarkRed;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | private void LinearScalingCheckBoxCheckStateChanged(object sender, EventArgs e) {
|
---|
| 108 | Content.ApplyLinearScaling = linearScalingCheckBox.Checked;
|
---|
| 109 | PaintTree();
|
---|
| 110 | }
|
---|
[18134] | 111 |
|
---|
| 112 | private void helpButton_DoubleClick(object sender, EventArgs e) {
|
---|
| 113 | using (InfoBox dialog = new InfoBox("Help for structure template",
|
---|
| 114 | "HeuristicLab.Problems.DataAnalysis.Symbolic.Views.Resources.structureTemplateHelp.rtf",
|
---|
| 115 | this)) {
|
---|
| 116 | dialog.ShowDialog(this);
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
[18063] | 119 | }
|
---|
| 120 | }
|
---|