Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Programmable/ProgrammableOperatorView.cs @ 2

Last change on this file since 2 was 2, checked in by swagner, 16 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 5.4 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30
31namespace HeuristicLab.Operators.Programmable {
32  public partial class ProgrammableOperatorView : ViewBase {
33    public ProgrammableOperator ProgrammableOperator {
34      get { return (ProgrammableOperator)Item; }
35      set { base.Item = value; }
36    }
37
38    public ProgrammableOperatorView() {
39      InitializeComponent();
40    }
41    public ProgrammableOperatorView(ProgrammableOperator programmableOperator)
42      : this() {
43      ProgrammableOperator = programmableOperator;
44    }
45
46    protected override void RemoveItemEvents() {
47      operatorBaseVariableInfosView.Operator = null;
48      operatorBaseVariablesView.Operator = null;
49      constrainedItemBaseView.ConstrainedItem = null;
50      ProgrammableOperator.CodeChanged -= new EventHandler(ProgrammableOperator_CodeChanged);
51      ProgrammableOperator.DescriptionChanged -= new EventHandler(ProgrammableOperator_DescriptionChanged);
52      base.RemoveItemEvents();
53    }
54
55    protected override void AddItemEvents() {
56      base.AddItemEvents();
57      operatorBaseVariableInfosView.Operator = ProgrammableOperator;
58      operatorBaseVariablesView.Operator = ProgrammableOperator;
59      constrainedItemBaseView.ConstrainedItem = ProgrammableOperator;
60      ProgrammableOperator.CodeChanged += new EventHandler(ProgrammableOperator_CodeChanged);
61      ProgrammableOperator.DescriptionChanged += new EventHandler(ProgrammableOperator_DescriptionChanged);
62    }
63
64    protected override void UpdateControls() {
65      base.UpdateControls();
66      if (ProgrammableOperator == null) {
67        codeTextBox.Text = "";
68        codeTextBox.Enabled = false;
69        addVariableInfoButton.Enabled = false;
70        removeVariableInfoButton.Enabled = false;
71        descriptionTextBox.Text = "";
72        descriptionTextBox.Enabled = false;
73      } else {
74        codeTextBox.Text = ProgrammableOperator.Code;
75        codeTextBox.Enabled = true;
76        addVariableInfoButton.Enabled = true;
77        removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
78        descriptionTextBox.Text = ProgrammableOperator.Description;
79        descriptionTextBox.Enabled = true;
80      }
81    }
82
83    private void operatorBaseVariableInfosView_SelectedVariableInfosChanged(object sender, EventArgs e) {
84      removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
85    }
86
87    #region Validated Events
88    private void codeTextBox_Validated(object sender, EventArgs e) {
89      ProgrammableOperator.Code = codeTextBox.Text;
90    }
91    private void descriptionTextBox_Validated(object sender, EventArgs e) {
92      ProgrammableOperator.SetDescription(descriptionTextBox.Text);
93    }
94    #endregion
95
96    #region Click Events
97    private void compileButton_Click(object sender, EventArgs e) {
98      try {
99        ProgrammableOperator.Compile();
100        MessageBox.Show("Compilation successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
101      }
102      catch (Exception ex) {
103        Auxiliary.ShowErrorMessageBox(ex);
104      }
105    }
106    private void addVariableInfoButton_Click(object sender, EventArgs e) {
107      AddVariableInfoDialog dialog = new AddVariableInfoDialog();
108      if (dialog.ShowDialog(this) == DialogResult.OK) {
109        if (ProgrammableOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null)
110          Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
111        else
112          ProgrammableOperator.AddVariableInfo(dialog.VariableInfo);
113      }
114      dialog.Dispose();
115    }
116    private void removeVariableInfoButton_Click(object sender, EventArgs e) {
117      IVariableInfo[] selected = new IVariableInfo[operatorBaseVariableInfosView.SelectedVariableInfos.Count];
118      operatorBaseVariableInfosView.SelectedVariableInfos.CopyTo(selected, 0);
119      for (int i = 0; i < selected.Length; i++)
120        ProgrammableOperator.RemoveVariableInfo(selected[i].FormalName);
121    }
122    #endregion
123
124    #region ProgrammableOperator Events
125    private void ProgrammableOperator_CodeChanged(object sender, EventArgs e) {
126      codeTextBox.Text = ProgrammableOperator.Code;
127    }
128    private void ProgrammableOperator_DescriptionChanged(object sender, EventArgs e) {
129      descriptionTextBox.Text = ProgrammableOperator.Description;
130    }
131    #endregion
132  }
133}
Note: See TracBrowser for help on using the repository browser.