1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Linq;
|
---|
7 | using System.Text;
|
---|
8 | using System.Windows.Forms;
|
---|
9 |
|
---|
10 | using HeuristicLab.PluginInfrastructure;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.Data;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.SimOpt {
|
---|
15 | public partial class SimOptProblemInjectorView : ViewBase {
|
---|
16 | public SimOptProblemInjector SimOptProblemInjector {
|
---|
17 | get { return (SimOptProblemInjector)base.Item; }
|
---|
18 | set { base.Item = value; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | public SimOptProblemInjectorView() {
|
---|
22 | InitializeComponent();
|
---|
23 | UpdateDataTypeTreeView();
|
---|
24 | }
|
---|
25 |
|
---|
26 | public SimOptProblemInjectorView(SimOptProblemInjector simOptProblemInjector)
|
---|
27 | : this() {
|
---|
28 | SimOptProblemInjector = simOptProblemInjector;
|
---|
29 | }
|
---|
30 |
|
---|
31 | protected override void UpdateControls() {
|
---|
32 | base.UpdateControls();
|
---|
33 | if (SimOptProblemInjector == null) {
|
---|
34 | geneNameStringDataView.Enabled = false;
|
---|
35 | geneNameStringDataView.StringData = null;
|
---|
36 | objectParameterDataView.Enabled = false;
|
---|
37 | objectParameterDataView.ConstrainedItemList = null;
|
---|
38 | maximizationBoolDataView.Enabled = false;
|
---|
39 | maximizationBoolDataView.BoolData = null;
|
---|
40 | } else {
|
---|
41 | objectParameterDataView.ConstrainedItemList = SimOptProblemInjector.Parameters;
|
---|
42 | objectParameterDataView.Enabled = true;
|
---|
43 | geneNameStringDataView.StringData = SimOptProblemInjector.GeneName;
|
---|
44 | geneNameStringDataView.Enabled = true;
|
---|
45 | maximizationBoolDataView.BoolData = SimOptProblemInjector.Maximization;
|
---|
46 | maximizationBoolDataView.Enabled = true;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | private void UpdateDataTypeTreeView() {
|
---|
51 | dataTypeTreeView.Nodes.Clear();
|
---|
52 | DiscoveryService discoveryService = new DiscoveryService();
|
---|
53 | foreach (PluginInfo plugin in discoveryService.Plugins) {
|
---|
54 | TreeNode pluginNode = new TreeNode(plugin.Name);
|
---|
55 | pluginNode.Tag = null;
|
---|
56 |
|
---|
57 | Type[] types = discoveryService.GetTypes(typeof(IObjectData), plugin);
|
---|
58 | foreach (Type type in types) {
|
---|
59 | if (!type.IsAbstract) {
|
---|
60 | TreeNode itemNode = new TreeNode();
|
---|
61 | itemNode.Text = type.Name;
|
---|
62 | itemNode.Tag = type;
|
---|
63 | pluginNode.Nodes.Add(itemNode);
|
---|
64 | }
|
---|
65 | }
|
---|
66 | if (pluginNode.Nodes.Count > 0) {
|
---|
67 | dataTypeTreeView.Nodes.Add(pluginNode);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | if (dataTypeTreeView.Nodes.Count == 0) {
|
---|
71 | dataTypeTreeView.Enabled = false;
|
---|
72 | dataTypeTreeView.Nodes.Add(new TreeNode("No item types available"));
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | private void dataTypeTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
77 | DoDragDrop(e.Item, DragDropEffects.Copy);
|
---|
78 | }
|
---|
79 |
|
---|
80 | private void objectParameterDataView_DragDrop(object sender, DragEventArgs e) {
|
---|
81 | TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));
|
---|
82 | IVariable var = new Variable();
|
---|
83 | var.Name = "Unnamed";
|
---|
84 | var.Value = (IItem)Activator.CreateInstance((Type)node.Tag);
|
---|
85 | ICollection<IConstraint> tmp;
|
---|
86 | objectParameterDataView.ConstrainedItemList.TryAdd(var, out tmp);
|
---|
87 | }
|
---|
88 |
|
---|
89 | private void objectParameterDataView_DragEnter(object sender, DragEventArgs e) {
|
---|
90 | e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|