[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;
|
---|
[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 | }
|
---|