1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Windows.Forms;
|
---|
4 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
7 | public partial class InsertNodeDialog : Form {
|
---|
8 | public InsertNodeDialog() {
|
---|
9 | InitializeComponent();
|
---|
10 | }
|
---|
11 |
|
---|
12 | public void SetAllowedSymbols(IEnumerable<ISymbol> symbols) {
|
---|
13 | allowedSymbolsCombo.Items.Clear();
|
---|
14 | foreach (var s in symbols) allowedSymbolsCombo.Items.Add(s);
|
---|
15 | allowedSymbolsCombo.SelectedIndex = 0;
|
---|
16 | }
|
---|
17 |
|
---|
18 | public ISymbol SelectedSymbol() {
|
---|
19 | return (ISymbol)allowedSymbolsCombo.SelectedItem;
|
---|
20 | }
|
---|
21 |
|
---|
22 | private void allowedSymbolsCombo_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
23 | return; // not sure what to do yet
|
---|
24 | var combo = (ComboBox)sender;
|
---|
25 | var symbol = combo.Items[combo.SelectedIndex];
|
---|
26 | if (symbol is Constant) {
|
---|
27 | // add controls to the dialog for changing the constant value
|
---|
28 | variableNameLabel.Visible = false;
|
---|
29 | variableNamesCombo.Visible = false;
|
---|
30 | variableWeightLabel.Visible = false;
|
---|
31 | variableWeightTextBox.Visible = false;
|
---|
32 | constantValueLabel.Visible = true;
|
---|
33 | constantValueTextBox.Visible = true;
|
---|
34 | } else if (symbol is Variable) {
|
---|
35 | var variable = (Variable)symbol;
|
---|
36 | foreach (var name in variable.VariableNames) variableNamesCombo.Items.Add(name);
|
---|
37 | variableNamesCombo.SelectedIndex = 0;
|
---|
38 | variableNameLabel.Visible = true;
|
---|
39 | variableNamesCombo.Visible = true;
|
---|
40 | variableWeightLabel.Visible = true;
|
---|
41 | variableWeightTextBox.Visible = true;
|
---|
42 | constantValueLabel.Visible = false;
|
---|
43 | constantValueTextBox.Visible = false;
|
---|
44 | // add controls to the dialog for changing the variable name or weight
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | private void childControl_KeyDown(object sender, KeyEventArgs e) {
|
---|
49 | insertNodeDialog_KeyDown(sender, e);
|
---|
50 | }
|
---|
51 |
|
---|
52 | private void insertNodeDialog_KeyDown(object sender, KeyEventArgs e) {
|
---|
53 | if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return) {
|
---|
54 | if (ValidateChildren()) {
|
---|
55 | DialogValidated(this, e);
|
---|
56 | Close();
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public event EventHandler DialogValidated;
|
---|
62 | }
|
---|
63 | }
|
---|