#region License Information /* HeuristicLab * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Core.Networks.Views; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; using HeuristicLab.Optimization; using HeuristicLab.PluginInfrastructure; using System; using System.Windows.Forms; namespace HeuristicLab.Networks.Views { [View("AlgorithmNode View")] [Content(typeof(AlgorithmNode), true)] [Content(typeof(IAlgorithmNode), false)] public partial class AlgorithmNodeView : NetworkItemView { protected TypeSelectorDialog typeSelectorDialog; public new IAlgorithmNode Content { get { return (IAlgorithmNode)base.Content; } set { base.Content = value; } } public AlgorithmNodeView() { InitializeComponent(); } protected override void Dispose(bool disposing) { if (disposing) { if (typeSelectorDialog != null) typeSelectorDialog.Dispose(); if (components != null) components.Dispose(); } base.Dispose(disposing); } protected override void DeregisterContentEvents() { Content.AlgorithmChanged -= Content_AlgorithmChanged; base.DeregisterContentEvents(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.AlgorithmChanged += Content_AlgorithmChanged; } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) { portCollectionView.Content = null; algorithmViewHost.Content = null; runCollectionView.Content = null; } else { portCollectionView.Content = Content.Ports; algorithmViewHost.ViewType = null; algorithmViewHost.Content = Content.Algorithm; runCollectionView.Content = Content.Runs; } } protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); portCollectionView.Enabled = Content != null && !ReadOnly; setAlgorithmButton.Enabled = Content != null && !ReadOnly; clearAlgorithmButton.Enabled = Content != null && Content.Algorithm != null && !ReadOnly; algorithmPanel.Enabled = Content != null; runCollectionView.Enabled = Content != null && !ReadOnly; } protected virtual void Content_AlgorithmChanged(object sender, System.EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_AlgorithmChanged), sender, e); else { clearAlgorithmButton.Enabled = Content.Algorithm != null && !ReadOnly; algorithmViewHost.ViewType = null; algorithmViewHost.Content = Content.Algorithm; } } protected virtual void setAlgorithmButton_Click(object sender, EventArgs e) { if (typeSelectorDialog == null) { typeSelectorDialog = new TypeSelectorDialog(); typeSelectorDialog.Caption = "Select Algorithm"; typeSelectorDialog.TypeSelector.Configure(typeof(IAlgorithm), false, true); } if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) { try { Content.Algorithm = (IAlgorithm)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType(); } catch (Exception ex) { ErrorHandling.ShowErrorDialog(this, ex); } } } protected virtual void clearAlgorithmButton_Click(object sender, EventArgs e) { Content.Algorithm = null; } protected virtual void algorithmPanel_DragEnterOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IAlgorithm)) { if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy; else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move; else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link; } } protected virtual void algorithmPanel_DragDrop(object sender, DragEventArgs e) { if (e.Effect != DragDropEffects.None) { IAlgorithm alg = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IAlgorithm; if (e.Effect.HasFlag(DragDropEffects.Copy)) alg = (IAlgorithm)alg.Clone(); Content.Algorithm = alg; } } } }