1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 HeuristicLab.Core.Views;
|
---|
23 | using HeuristicLab.MainForm;
|
---|
24 | using HeuristicLab.PluginInfrastructure;
|
---|
25 | using System;
|
---|
26 | using System.Windows.Forms;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Optimization.Networks.Views {
|
---|
29 | [View("Algorithm Node View")]
|
---|
30 | [Content(typeof(AlgorithmNode), true)]
|
---|
31 | [Content(typeof(IAlgorithmNode), false)]
|
---|
32 | public partial class AlgorithmNodeView : NodeView {
|
---|
33 | protected TypeSelectorDialog typeSelectorDialog;
|
---|
34 |
|
---|
35 | public new IAlgorithmNode Content {
|
---|
36 | get { return (IAlgorithmNode)base.Content; }
|
---|
37 | set { base.Content = value; }
|
---|
38 | }
|
---|
39 |
|
---|
40 | public AlgorithmNodeView() {
|
---|
41 | InitializeComponent();
|
---|
42 | }
|
---|
43 |
|
---|
44 | protected override void Dispose(bool disposing) {
|
---|
45 | if (disposing) {
|
---|
46 | if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
|
---|
47 | if (components != null) components.Dispose();
|
---|
48 | }
|
---|
49 | base.Dispose(disposing);
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected override void DeregisterContentEvents() {
|
---|
53 | Content.AlgorithmChanged -= Content_AlgorithmChanged;
|
---|
54 | base.DeregisterContentEvents();
|
---|
55 | }
|
---|
56 | protected override void RegisterContentEvents() {
|
---|
57 | base.RegisterContentEvents();
|
---|
58 | Content.AlgorithmChanged += Content_AlgorithmChanged;
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override void OnContentChanged() {
|
---|
62 | base.OnContentChanged();
|
---|
63 | if (Content == null) {
|
---|
64 | portCollectionView.Content = null;
|
---|
65 | algorithmViewHost.Content = null;
|
---|
66 | } else {
|
---|
67 | portCollectionView.Content = Content.Ports;
|
---|
68 | algorithmViewHost.ViewType = null;
|
---|
69 | algorithmViewHost.Content = Content.Algorithm;
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | protected override void SetEnabledStateOfControls() {
|
---|
74 | base.SetEnabledStateOfControls();
|
---|
75 | portCollectionView.Enabled = Content != null;
|
---|
76 | setAlgorithmButton.Enabled = Content != null && !ReadOnly;
|
---|
77 | clearAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !ReadOnly;
|
---|
78 | algorithmPanel.Enabled = Content != null;
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected virtual void Content_AlgorithmChanged(object sender, System.EventArgs e) {
|
---|
82 | if (InvokeRequired)
|
---|
83 | Invoke(new EventHandler(Content_AlgorithmChanged), sender, e);
|
---|
84 | else {
|
---|
85 | clearAlgorithmButton.Enabled = Content.Algorithm != null && !ReadOnly;
|
---|
86 | algorithmViewHost.ViewType = null;
|
---|
87 | algorithmViewHost.Content = Content.Algorithm;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected virtual void setAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
92 | if (typeSelectorDialog == null) {
|
---|
93 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
94 | typeSelectorDialog.Caption = "Select Algorithm";
|
---|
95 | typeSelectorDialog.TypeSelector.Configure(typeof(IAlgorithm), false, true);
|
---|
96 | }
|
---|
97 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
98 | try {
|
---|
99 | Content.Algorithm = (IAlgorithm)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
|
---|
100 | }
|
---|
101 | catch (Exception ex) {
|
---|
102 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 | protected virtual void clearAlgorithmButton_Click(object sender, EventArgs e) {
|
---|
107 | Content.Algorithm = null;
|
---|
108 | }
|
---|
109 | protected virtual void algorithmPanel_DragEnterOver(object sender, DragEventArgs e) {
|
---|
110 | e.Effect = DragDropEffects.None;
|
---|
111 | if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IAlgorithm)) {
|
---|
112 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
113 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
114 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
115 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
|
---|
116 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
|
---|
117 | }
|
---|
118 |
|
---|
119 | }
|
---|
120 | protected virtual void algorithmPanel_DragDrop(object sender, DragEventArgs e) {
|
---|
121 | if (e.Effect != DragDropEffects.None) {
|
---|
122 | IAlgorithm alg = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IAlgorithm;
|
---|
123 | if (e.Effect.HasFlag(DragDropEffects.Copy)) alg = (IAlgorithm)alg.Clone();
|
---|
124 | Content.Algorithm = alg;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|