[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
[51] | 30 | using HeuristicLab.Operators;
|
---|
[2] | 31 |
|
---|
| 32 | namespace HeuristicLab.Operators.Programmable {
|
---|
| 33 | public partial class ProgrammableOperatorView : ViewBase {
|
---|
| 34 | public ProgrammableOperator ProgrammableOperator {
|
---|
| 35 | get { return (ProgrammableOperator)Item; }
|
---|
| 36 | set { base.Item = value; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public ProgrammableOperatorView() {
|
---|
| 40 | InitializeComponent();
|
---|
| 41 | }
|
---|
| 42 | public ProgrammableOperatorView(ProgrammableOperator programmableOperator)
|
---|
| 43 | : this() {
|
---|
| 44 | ProgrammableOperator = programmableOperator;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | protected override void RemoveItemEvents() {
|
---|
| 48 | operatorBaseVariableInfosView.Operator = null;
|
---|
| 49 | operatorBaseVariablesView.Operator = null;
|
---|
| 50 | constrainedItemBaseView.ConstrainedItem = null;
|
---|
| 51 | ProgrammableOperator.CodeChanged -= new EventHandler(ProgrammableOperator_CodeChanged);
|
---|
| 52 | ProgrammableOperator.DescriptionChanged -= new EventHandler(ProgrammableOperator_DescriptionChanged);
|
---|
| 53 | base.RemoveItemEvents();
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void AddItemEvents() {
|
---|
| 57 | base.AddItemEvents();
|
---|
| 58 | operatorBaseVariableInfosView.Operator = ProgrammableOperator;
|
---|
| 59 | operatorBaseVariablesView.Operator = ProgrammableOperator;
|
---|
| 60 | constrainedItemBaseView.ConstrainedItem = ProgrammableOperator;
|
---|
| 61 | ProgrammableOperator.CodeChanged += new EventHandler(ProgrammableOperator_CodeChanged);
|
---|
| 62 | ProgrammableOperator.DescriptionChanged += new EventHandler(ProgrammableOperator_DescriptionChanged);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | protected override void UpdateControls() {
|
---|
| 66 | base.UpdateControls();
|
---|
| 67 | if (ProgrammableOperator == null) {
|
---|
| 68 | codeTextBox.Text = "";
|
---|
| 69 | codeTextBox.Enabled = false;
|
---|
| 70 | addVariableInfoButton.Enabled = false;
|
---|
| 71 | removeVariableInfoButton.Enabled = false;
|
---|
| 72 | descriptionTextBox.Text = "";
|
---|
| 73 | descriptionTextBox.Enabled = false;
|
---|
| 74 | } else {
|
---|
| 75 | codeTextBox.Text = ProgrammableOperator.Code;
|
---|
| 76 | codeTextBox.Enabled = true;
|
---|
| 77 | addVariableInfoButton.Enabled = true;
|
---|
| 78 | removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
|
---|
| 79 | descriptionTextBox.Text = ProgrammableOperator.Description;
|
---|
| 80 | descriptionTextBox.Enabled = true;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | private void operatorBaseVariableInfosView_SelectedVariableInfosChanged(object sender, EventArgs e) {
|
---|
| 85 | removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | #region Validated Events
|
---|
| 89 | private void codeTextBox_Validated(object sender, EventArgs e) {
|
---|
| 90 | ProgrammableOperator.Code = codeTextBox.Text;
|
---|
| 91 | }
|
---|
| 92 | private void descriptionTextBox_Validated(object sender, EventArgs e) {
|
---|
| 93 | ProgrammableOperator.SetDescription(descriptionTextBox.Text);
|
---|
| 94 | }
|
---|
| 95 | #endregion
|
---|
| 96 |
|
---|
| 97 | #region Click Events
|
---|
| 98 | private void compileButton_Click(object sender, EventArgs e) {
|
---|
| 99 | try {
|
---|
| 100 | ProgrammableOperator.Compile();
|
---|
| 101 | MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
---|
| 102 | }
|
---|
| 103 | catch (Exception ex) {
|
---|
| 104 | Auxiliary.ShowErrorMessageBox(ex);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | private void addVariableInfoButton_Click(object sender, EventArgs e) {
|
---|
| 108 | AddVariableInfoDialog dialog = new AddVariableInfoDialog();
|
---|
| 109 | if (dialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 110 | if (ProgrammableOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null)
|
---|
| 111 | Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
|
---|
| 112 | else
|
---|
| 113 | ProgrammableOperator.AddVariableInfo(dialog.VariableInfo);
|
---|
| 114 | }
|
---|
| 115 | dialog.Dispose();
|
---|
| 116 | }
|
---|
| 117 | private void removeVariableInfoButton_Click(object sender, EventArgs e) {
|
---|
| 118 | IVariableInfo[] selected = new IVariableInfo[operatorBaseVariableInfosView.SelectedVariableInfos.Count];
|
---|
| 119 | operatorBaseVariableInfosView.SelectedVariableInfos.CopyTo(selected, 0);
|
---|
| 120 | for (int i = 0; i < selected.Length; i++)
|
---|
| 121 | ProgrammableOperator.RemoveVariableInfo(selected[i].FormalName);
|
---|
| 122 | }
|
---|
| 123 | #endregion
|
---|
| 124 |
|
---|
| 125 | #region ProgrammableOperator Events
|
---|
| 126 | private void ProgrammableOperator_CodeChanged(object sender, EventArgs e) {
|
---|
| 127 | codeTextBox.Text = ProgrammableOperator.Code;
|
---|
| 128 | }
|
---|
| 129 | private void ProgrammableOperator_DescriptionChanged(object sender, EventArgs e) {
|
---|
| 130 | descriptionTextBox.Text = ProgrammableOperator.Description;
|
---|
| 131 | }
|
---|
| 132 | #endregion
|
---|
| 133 | }
|
---|
| 134 | }
|
---|