#region License Information /* HeuristicLab * Copyright (C) 2002-2016 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 System; using System.Windows.Forms; using HeuristicLab.MainForm; using HeuristicLab.Optimization; using HeuristicLab.Optimization.Views; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.GoalSeeking { [View("GoalSeekingOptimizer View", "")] [Content(typeof(GoalSeekingOptimizer), true)] public partial class GoalSeekingOptimizerView : IOptimizerView { public GoalSeekingOptimizerView() { InitializeComponent(); Content = new GoalSeekingOptimizer(); } public new GoalSeekingOptimizer Content { get { return (GoalSeekingOptimizer)base.Content; } set { base.Content = value; } } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) return; if (Content.Optimizer != null) algorithmViewHost.Content = Content.Optimizer; if (Content.Problem != null) problemViewHost.Content = Content.Problem; if (Content.ProblemData != null) dataViewHost.Content = Content.ProblemData; if (Content.Results != null) resultsViewHost.Content = Content.Results; } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.AlgorithmChanged += (o, e) => { algorithmViewHost.Content = Content.Optimizer; }; Content.ProblemChanged += (o, e) => { problemViewHost.Content = Content.Problem; }; Content.ProblemDataChanged += (o, e) => { dataViewHost.Content = Content.ProblemData; }; Content.ResultsChanged += (o, e) => { resultsViewHost.Content = Content.Results; }; } protected override void DeregisterContentEvents() { base.DeregisterContentEvents(); } #region event handlers private void problemTab_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) { try { Content.Problem = (IGoalSeekingProblem)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); problemViewHost.Content = Content.Problem; } catch (Exception ex) { MessageBox.Show(ex.Message, "Set problem", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void problemTab_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return; var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); if (data is IGoalSeekingProblem) e.Effect = DragDropEffects.Copy; } private void algorithmTab_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) { try { Content.Optimizer = (IAlgorithm)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); algorithmViewHost.Content = Content.Optimizer; } catch (Exception ex) { MessageBox.Show(ex.Message, "Set algorithm", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void algorithmTab_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return; var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); if (data is IAlgorithm) e.Effect = DragDropEffects.Copy; } #endregion private void dataTab_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) { try { Content.ProblemData = (IRegressionProblemData)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); dataViewHost.Content = Content.ProblemData; } catch (Exception ex) { // provide some information to the user MessageBox.Show(ex.Message, "Set problem data", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } private void dataTab_DragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.None; if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return; var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat); if (data is IRegressionProblemData) e.Effect = DragDropEffects.Copy; } } }