[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();
|
---|
| 26 | errorLabel.Text = "";
|
---|
[18067] | 27 | treeChart.SymbolicExpressionTreeNodeClicked += TreeChart_SymbolicExpressionTreeNodeClicked;
|
---|
[18063] | 28 | }
|
---|
| 29 |
|
---|
[18067] | 30 | private void TreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
|
---|
| 31 | var visualTreeNode = sender as VisualTreeNode<ISymbolicExpressionTreeNode>;
|
---|
| 32 | if(visualTreeNode != null) {
|
---|
| 33 | var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode;
|
---|
| 34 | viewHost.Content = subFunctionTreeNode?.SubFunction;
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[18065] | 38 | protected override void OnContentChanged() {
|
---|
| 39 | base.OnContentChanged();
|
---|
| 40 | if (Content == null) return;
|
---|
| 41 |
|
---|
| 42 | expressionInput.Text = Content.Template;
|
---|
| 43 | symRegTreeChart.Content = Content.Tree;
|
---|
[18067] | 44 |
|
---|
| 45 | treeChart.Tree = Content.Tree;
|
---|
| 46 |
|
---|
[18065] | 47 | errorLabel.Text = "";
|
---|
| 48 |
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[18063] | 51 | private void parseButton_Click(object sender, EventArgs e) {
|
---|
| 52 | if(!string.IsNullOrEmpty(expressionInput.Text)) {
|
---|
| 53 | try {
|
---|
| 54 | Content.Template = expressionInput.Text;
|
---|
| 55 | symRegTreeChart.Content = Content.Tree;
|
---|
[18067] | 56 | treeChart.Tree = Content.Tree;
|
---|
[18063] | 57 |
|
---|
| 58 | errorLabel.Text = "Template structure successfully parsed.";
|
---|
| 59 | errorLabel.ForeColor = Color.DarkGreen;
|
---|
| 60 | } catch (Exception ex) {
|
---|
| 61 | errorLabel.Text = ex.Message;
|
---|
| 62 | errorLabel.ForeColor = Color.DarkRed;
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | private void expressionInput_TextChanged(object sender, EventArgs e) {
|
---|
| 68 | errorLabel.Text = "Unparsed changes! Press parse button to save changes.";
|
---|
| 69 | errorLabel.ForeColor = Color.DarkOrange;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | }
|
---|
| 73 | }
|
---|