Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.SimOpt/SimOptProblemInjectorView.cs @ 10709

Last change on this file since 10709 was 592, checked in by abeham, 16 years ago

Put the GPL license in the files from the communication framework and simulation optimization project (branch 3.1)

File size: 4.1 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30
31using HeuristicLab.PluginInfrastructure;
32using HeuristicLab.Core;
33using HeuristicLab.Data;
34
35namespace 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}
Note: See TracBrowser for help on using the repository browser.