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