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.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.Core;
|
---|
31 | using System.Diagnostics;
|
---|
32 | using HeuristicLab.Data;
|
---|
33 | using HeuristicLab.Operators;
|
---|
34 | using HeuristicLab.Random;
|
---|
35 | using HeuristicLab.Functions;
|
---|
36 |
|
---|
37 | namespace HeuristicLab.StructureIdentification {
|
---|
38 | public partial class GPOperatorLibraryEditor : EditorBase {
|
---|
39 | public IOperatorLibrary OperatorLibrary {
|
---|
40 | get { return (IOperatorLibrary)Item; }
|
---|
41 | set { base.Item = value; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public GPOperatorLibraryEditor(GPOperatorLibrary library)
|
---|
45 | : base() {
|
---|
46 | InitializeComponent();
|
---|
47 | OperatorLibrary = library;
|
---|
48 | operatorLibraryEditor.OperatorLibrary = library;
|
---|
49 |
|
---|
50 | library.GPOperatorGroup.OperatorAdded += new EventHandler(GPOperatorLibraryView_OperatorAdded);
|
---|
51 | library.GPOperatorGroup.OperatorRemoved += new EventHandler(GPOperatorGroup_OperatorRemoved);
|
---|
52 |
|
---|
53 | mutationVariableView.Enabled = false;
|
---|
54 | initVariableView.Enabled = false;
|
---|
55 |
|
---|
56 | foreach(IOperator op in library.Group.Operators) {
|
---|
57 | if(op.GetVariable(FunctionBase.MANIPULATION) != null) {
|
---|
58 | ListViewItem item = new ListViewItem();
|
---|
59 | item.Text = op.Name;
|
---|
60 | item.Name = op.Name;
|
---|
61 | item.Tag = op;
|
---|
62 | mutationListView.Items.Add(item);
|
---|
63 | }
|
---|
64 | if(op.GetVariable(FunctionBase.INITIALIZATION) != null) {
|
---|
65 | ListViewItem item = new ListViewItem();
|
---|
66 | item.Name = op.Name;
|
---|
67 | item.Text = op.Name;
|
---|
68 | item.Tag = op;
|
---|
69 | initListView.Items.Add(item);
|
---|
70 | }
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | private void GPOperatorLibraryView_OperatorAdded(object sender, EventArgs e) {
|
---|
76 | IOperator op = ((OperatorEventArgs)e).op;
|
---|
77 | if(op.GetVariable(FunctionBase.MANIPULATION) != null) {
|
---|
78 | ListViewItem operatorMutationItem = new ListViewItem();
|
---|
79 | operatorMutationItem.Name = op.Name;
|
---|
80 | operatorMutationItem.Text = op.Name;
|
---|
81 | operatorMutationItem.Tag = op;
|
---|
82 | mutationListView.Items.Add(operatorMutationItem);
|
---|
83 | }
|
---|
84 |
|
---|
85 | if(op.GetVariable(FunctionBase.INITIALIZATION) != null) {
|
---|
86 | ListViewItem operatorInitItem = new ListViewItem();
|
---|
87 | operatorInitItem.Name = op.Name;
|
---|
88 | operatorInitItem.Text = op.Name;
|
---|
89 | operatorInitItem.Tag = op;
|
---|
90 | initListView.Items.Add(operatorInitItem);
|
---|
91 | }
|
---|
92 |
|
---|
93 | op.NameChanged += new EventHandler(op_NameChanged);
|
---|
94 | Refresh();
|
---|
95 | }
|
---|
96 |
|
---|
97 | private void op_NameChanged(object sender, EventArgs e) {
|
---|
98 | IOperator srcOp = (IOperator)sender;
|
---|
99 | foreach(ListViewItem item in mutationListView.Items) {
|
---|
100 | if(item.Tag == srcOp) {
|
---|
101 | item.Name = srcOp.Name;
|
---|
102 | item.Text = srcOp.Name;
|
---|
103 | break;
|
---|
104 | }
|
---|
105 | }
|
---|
106 | foreach(ListViewItem item in initListView.Items) {
|
---|
107 | if(item.Tag == srcOp) {
|
---|
108 | item.Name = srcOp.Name;
|
---|
109 | item.Text = srcOp.Name;
|
---|
110 | break;
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | private void GPOperatorGroup_OperatorRemoved(object sender, EventArgs e) {
|
---|
117 | IOperator op = ((OperatorEventArgs)e).op;
|
---|
118 |
|
---|
119 | foreach(ListViewItem item in mutationListView.Items) {
|
---|
120 | if(item.Tag == op) {
|
---|
121 | mutationListView.Items.Remove(item);
|
---|
122 | break;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | foreach(ListViewItem item in initListView.Items) {
|
---|
127 | if(item.Tag == op) {
|
---|
128 | initListView.Items.Remove(item);
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | private void mutationListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
135 | if(mutationListView.SelectedItems.Count>0 && mutationListView.SelectedItems[0].Tag != null) {
|
---|
136 | IVariable variable = ((IOperator)mutationListView.SelectedItems[0].Tag).GetVariable(FunctionBase.MANIPULATION);
|
---|
137 | mutationVariableView.Enabled = true;
|
---|
138 | mutationVariableView.Variable = variable;
|
---|
139 | } else {
|
---|
140 | mutationVariableView.Enabled = false;
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | private void initListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
145 | if(initListView.SelectedItems.Count>0 && initListView.SelectedItems[0].Tag != null) {
|
---|
146 | IVariable variable = ((IOperator)initListView.SelectedItems[0].Tag).GetVariable(FunctionBase.INITIALIZATION);
|
---|
147 | initVariableView.Enabled = true;
|
---|
148 | initVariableView.Variable = variable;
|
---|
149 | } else {
|
---|
150 | initVariableView.Enabled = false;
|
---|
151 | }
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|