[591] | 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;
|
---|
[584] | 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 |
|
---|
| 31 | using HeuristicLab.PluginInfrastructure;
|
---|
| 32 | using HeuristicLab.Core;
|
---|
| 33 | using HeuristicLab.Data;
|
---|
| 34 |
|
---|
| 35 | namespace HeuristicLab.SimOpt {
|
---|
| 36 | public partial class SimOptProblemInjectorView : ViewBase {
|
---|
| 37 | public SimOptProblemInjector SimOptProblemInjector {
|
---|
| 38 | get { return (SimOptProblemInjector)base.Item; }
|
---|
| 39 | set { base.Item = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public SimOptProblemInjectorView() {
|
---|
| 43 | InitializeComponent();
|
---|
| 44 | UpdateDataTypeTreeView();
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | public SimOptProblemInjectorView(SimOptProblemInjector simOptProblemInjector)
|
---|
| 48 | : this() {
|
---|
| 49 | SimOptProblemInjector = simOptProblemInjector;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void UpdateControls() {
|
---|
| 53 | base.UpdateControls();
|
---|
| 54 | if (SimOptProblemInjector == null) {
|
---|
| 55 | geneNameStringDataView.Enabled = false;
|
---|
| 56 | geneNameStringDataView.StringData = null;
|
---|
| 57 | objectParameterDataView.Enabled = false;
|
---|
| 58 | objectParameterDataView.ConstrainedItemList = null;
|
---|
| 59 | maximizationBoolDataView.Enabled = false;
|
---|
| 60 | maximizationBoolDataView.BoolData = null;
|
---|
| 61 | } else {
|
---|
| 62 | objectParameterDataView.ConstrainedItemList = SimOptProblemInjector.Parameters;
|
---|
| 63 | objectParameterDataView.Enabled = true;
|
---|
| 64 | geneNameStringDataView.StringData = SimOptProblemInjector.GeneName;
|
---|
| 65 | geneNameStringDataView.Enabled = true;
|
---|
| 66 | maximizationBoolDataView.BoolData = SimOptProblemInjector.Maximization;
|
---|
| 67 | maximizationBoolDataView.Enabled = true;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | private void UpdateDataTypeTreeView() {
|
---|
| 72 | dataTypeTreeView.Nodes.Clear();
|
---|
[2591] | 73 | foreach (IPluginDescription plugin in ApplicationManager.Manager.Plugins) {
|
---|
[584] | 74 | TreeNode pluginNode = new TreeNode(plugin.Name);
|
---|
| 75 | pluginNode.Tag = null;
|
---|
| 76 |
|
---|
[2591] | 77 | foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(IObjectData), plugin)) {
|
---|
[584] | 78 | if (!type.IsAbstract) {
|
---|
| 79 | TreeNode itemNode = new TreeNode();
|
---|
| 80 | itemNode.Text = type.Name;
|
---|
| 81 | itemNode.Tag = type;
|
---|
| 82 | pluginNode.Nodes.Add(itemNode);
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | if (pluginNode.Nodes.Count > 0) {
|
---|
| 86 | dataTypeTreeView.Nodes.Add(pluginNode);
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 | if (dataTypeTreeView.Nodes.Count == 0) {
|
---|
| 90 | dataTypeTreeView.Enabled = false;
|
---|
| 91 | dataTypeTreeView.Nodes.Add(new TreeNode("No item types available"));
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | private void dataTypeTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
| 96 | DoDragDrop(e.Item, DragDropEffects.Copy);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | private void objectParameterDataView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 100 | TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));
|
---|
| 101 | IVariable var = new Variable();
|
---|
| 102 | var.Name = "Unnamed";
|
---|
| 103 | var.Value = (IItem)Activator.CreateInstance((Type)node.Tag);
|
---|
| 104 | ICollection<IConstraint> tmp;
|
---|
| 105 | objectParameterDataView.ConstrainedItemList.TryAdd(var, out tmp);
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | private void objectParameterDataView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 109 | e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | }
|
---|