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;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Operators {
|
---|
32 | /// <summary>
|
---|
33 | /// The visual representation of a <see cref="CombinedOperator"/>.
|
---|
34 | /// </summary>
|
---|
35 | public partial class CombinedOperatorView : ViewBase {
|
---|
36 | /// <summary>
|
---|
37 | /// Gets or sets the combined operator to display.
|
---|
38 | /// </summary>
|
---|
39 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
40 | /// No own data storage present.</remarks>
|
---|
41 | public CombinedOperator CombinedOperator {
|
---|
42 | get { return (CombinedOperator)Item; }
|
---|
43 | set { base.Item = value; }
|
---|
44 | }
|
---|
45 |
|
---|
46 | /// <summary>
|
---|
47 | /// Removes the eventhandlers in all children and from the underlying <see cref="CombinedOperator"/>.
|
---|
48 | /// </summary>
|
---|
49 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
50 | protected override void RemoveItemEvents() {
|
---|
51 | operatorGraphView.OperatorGraph = null;
|
---|
52 | operatorBaseVariableInfosView.Operator = null;
|
---|
53 | operatorBaseVariablesView.Operator = null;
|
---|
54 | constrainedItemBaseView.ConstrainedItem = null;
|
---|
55 | CombinedOperator.DescriptionChanged -= new EventHandler(CombinedOperator_DescriptionChanged);
|
---|
56 | base.RemoveItemEvents();
|
---|
57 | }
|
---|
58 |
|
---|
59 | /// <summary>
|
---|
60 | /// Adds event handlers in all children and to the underlying <see cref="CombinedOperator"/>.
|
---|
61 | /// </summary>
|
---|
62 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
63 | protected override void AddItemEvents() {
|
---|
64 | base.AddItemEvents();
|
---|
65 | operatorGraphView.OperatorGraph = CombinedOperator.OperatorGraph;
|
---|
66 | operatorBaseVariableInfosView.Operator = CombinedOperator;
|
---|
67 | operatorBaseVariablesView.Operator = CombinedOperator;
|
---|
68 | constrainedItemBaseView.ConstrainedItem = CombinedOperator;
|
---|
69 | CombinedOperator.DescriptionChanged += new EventHandler(CombinedOperator_DescriptionChanged);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /// <summary>
|
---|
73 | /// Initializes a new instance of <see cref="CombinedOperatorView"/>.
|
---|
74 | /// </summary>
|
---|
75 | public CombinedOperatorView() {
|
---|
76 | InitializeComponent();
|
---|
77 | }
|
---|
78 | /// <summary>
|
---|
79 | /// Initializes a new instance of <see cref="CombinedOperatorView"/> with the specified
|
---|
80 | /// <paramref name="combinedOperator"/>.
|
---|
81 | /// </summary>
|
---|
82 | /// <param name="combinedOperator">The combined operator to display.</param>
|
---|
83 | public CombinedOperatorView(CombinedOperator combinedOperator)
|
---|
84 | : this() {
|
---|
85 | CombinedOperator = combinedOperator;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /// <summary>
|
---|
89 | /// Updates all controls with the latest data of the model.
|
---|
90 | /// </summary>
|
---|
91 | protected override void UpdateControls() {
|
---|
92 | base.UpdateControls();
|
---|
93 | if (CombinedOperator == null) {
|
---|
94 | descriptionTextBox.Text = "";
|
---|
95 | descriptionTextBox.Enabled = false;
|
---|
96 | } else {
|
---|
97 | descriptionTextBox.Text = CombinedOperator.Description;
|
---|
98 | descriptionTextBox.Enabled = true;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | private void CombinedOperator_DescriptionChanged(object sender, EventArgs e) {
|
---|
103 | descriptionTextBox.Text = CombinedOperator.Description;
|
---|
104 | }
|
---|
105 | private void descriptionTextBox_Validated(object sender, EventArgs e) {
|
---|
106 | CombinedOperator.SetDescription(descriptionTextBox.Text);
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void operatorBaseVariableInfosView_SelectedVariableInfosChanged(object sender, EventArgs e) {
|
---|
110 | removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
|
---|
111 | }
|
---|
112 |
|
---|
113 | #region Click Events
|
---|
114 | private void addVariableInfoButton_Click(object sender, EventArgs e) {
|
---|
115 | AddVariableInfoDialog dialog = new AddVariableInfoDialog();
|
---|
116 | if (dialog.ShowDialog(this) == DialogResult.OK) {
|
---|
117 | if (CombinedOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null)
|
---|
118 | Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
|
---|
119 | else
|
---|
120 | CombinedOperator.AddVariableInfo(dialog.VariableInfo);
|
---|
121 | }
|
---|
122 | dialog.Dispose();
|
---|
123 | }
|
---|
124 | private void removeVariableInfoButton_Click(object sender, EventArgs e) {
|
---|
125 | IVariableInfo[] selected = new IVariableInfo[operatorBaseVariableInfosView.SelectedVariableInfos.Count];
|
---|
126 | operatorBaseVariableInfosView.SelectedVariableInfos.CopyTo(selected, 0);
|
---|
127 | for (int i = 0; i < selected.Length; i++)
|
---|
128 | CombinedOperator.RemoveVariableInfo(selected[i].FormalName);
|
---|
129 | }
|
---|
130 | #endregion
|
---|
131 | }
|
---|
132 | }
|
---|