source: branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem.Views/3.4/GoalSeekingOptimizerView.cs @ 14380

Last change on this file since 14380 was 14380, checked in by bburlacu, 4 years ago

#2679: Add GoalSeekingOptimizer and GoalSeekingOptimizerView.

File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Windows.Forms;
24using HeuristicLab.MainForm;
25using HeuristicLab.Optimization;
26using HeuristicLab.Optimization.Views;
27using HeuristicLab.Problems.DataAnalysis;
28
29namespace HeuristicLab.GoalSeeking {
30  [View("GoalSeekingOptimizer View", "")]
31  [Content(typeof(GoalSeekingOptimizer), true)]
32  public partial class GoalSeekingOptimizerView : IOptimizerView {
33    public GoalSeekingOptimizerView() {
34      InitializeComponent();
35      Content = new GoalSeekingOptimizer();
36    }
37
38    public new GoalSeekingOptimizer Content {
39      get { return (GoalSeekingOptimizer)base.Content; }
40      set { base.Content = value; }
41    }
42
43    protected override void OnContentChanged() {
44      base.OnContentChanged();
45      if (Content == null)
46        return;
47
48      if (Content.Optimizer != null)
49        algorithmViewHost.Content = Content.Optimizer;
50
51      if (Content.Problem != null)
52        problemViewHost.Content = Content.Problem;
53
54      if (Content.ProblemData != null)
55        dataViewHost.Content = Content.ProblemData;
56    }
57
58    protected override void RegisterContentEvents() {
59      base.RegisterContentEvents();
60      Content.AlgorithmChanged += (o, e) => { algorithmViewHost.Content = Content.Optimizer; };
61      Content.ProblemChanged += (o, e) => { problemViewHost.Content = Content.Problem; };
62      Content.ProblemDataChanged += (o, e) => { dataViewHost.Content = Content.ProblemData; };
63    }
64
65    protected override void DeregisterContentEvents() {
66      base.DeregisterContentEvents();
67    }
68
69    #region event handlers
70    private void problemTab_DragDrop(object sender, DragEventArgs e) {
71      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
72        try {
73          Content.Problem = (IGoalSeekingProblem)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
74          problemViewHost.Content = Content.Problem;
75        }
76        catch (Exception ex) {
77          MessageBox.Show(ex.Message, "Set problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
78        }
79      }
80    }
81
82    private void problemTab_DragEnter(object sender, DragEventArgs e) {
83      e.Effect = DragDropEffects.None;
84      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
85        return;
86
87      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
88
89      if (data is IGoalSeekingProblem)
90        e.Effect = DragDropEffects.Copy;
91    }
92
93    private void algorithmTab_DragDrop(object sender, DragEventArgs e) {
94      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
95        try {
96          Content.Optimizer = (IAlgorithm)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
97          algorithmViewHost.Content = Content.Optimizer;
98        }
99        catch (Exception ex) {
100          MessageBox.Show(ex.Message, "Set algorithm", MessageBoxButtons.OK, MessageBoxIcon.Error);
101        }
102      }
103    }
104
105    private void algorithmTab_DragEnter(object sender, DragEventArgs e) {
106      e.Effect = DragDropEffects.None;
107      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
108        return;
109
110      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
111      if (data is IAlgorithm)
112        e.Effect = DragDropEffects.Copy;
113    }
114    #endregion
115
116    private void dataTab_DragDrop(object sender, DragEventArgs e) {
117      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
118        try {
119          Content.ProblemData = (IRegressionProblemData)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
120          dataViewHost.Content = Content.ProblemData;
121        }
122        catch (Exception ex) {
123          // provide some information to the user
124          MessageBox.Show(ex.Message, "Set problem data", MessageBoxButtons.OK, MessageBoxIcon.Error);
125        }
126      }
127    }
128
129    private void dataTab_DragEnter(object sender, DragEventArgs e) {
130      e.Effect = DragDropEffects.None;
131      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
132        return;
133
134      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
135      if (data is IRegressionProblemData)
136        e.Effect = DragDropEffects.Copy;
137    }
138  }
139}
Note: See TracBrowser for help on using the repository browser.