[592] | 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;
|
---|
[583] | 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();
|
---|
| 73 | DiscoveryService discoveryService = new DiscoveryService();
|
---|
| 74 | foreach (PluginInfo plugin in discoveryService.Plugins) {
|
---|
| 75 | TreeNode pluginNode = new TreeNode(plugin.Name);
|
---|
| 76 | pluginNode.Tag = null;
|
---|
| 77 |
|
---|
| 78 | Type[] types = discoveryService.GetTypes(typeof(IObjectData), plugin);
|
---|
| 79 | foreach (Type type in types) {
|
---|
| 80 | if (!type.IsAbstract) {
|
---|
| 81 | TreeNode itemNode = new TreeNode();
|
---|
| 82 | itemNode.Text = type.Name;
|
---|
| 83 | itemNode.Tag = type;
|
---|
| 84 | pluginNode.Nodes.Add(itemNode);
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | if (pluginNode.Nodes.Count > 0) {
|
---|
| 88 | dataTypeTreeView.Nodes.Add(pluginNode);
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 | if (dataTypeTreeView.Nodes.Count == 0) {
|
---|
| 92 | dataTypeTreeView.Enabled = false;
|
---|
| 93 | dataTypeTreeView.Nodes.Add(new TreeNode("No item types available"));
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | private void dataTypeTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
| 98 | DoDragDrop(e.Item, DragDropEffects.Copy);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | private void objectParameterDataView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 102 | TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));
|
---|
| 103 | IVariable var = new Variable();
|
---|
| 104 | var.Name = "Unnamed";
|
---|
| 105 | var.Value = (IItem)Activator.CreateInstance((Type)node.Tag);
|
---|
| 106 | ICollection<IConstraint> tmp;
|
---|
| 107 | objectParameterDataView.ConstrainedItemList.TryAdd(var, out tmp);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | private void objectParameterDataView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 111 | e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | }
|
---|