Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2679_HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem.Views/3.4/GoalSeekingOptimizerView.cs @ 17915

Last change on this file since 17915 was 16901, checked in by bburlacu, 6 years ago

#2679: Update branch: framework version 4.6.1, use heal.attic for persistence, some minor refactoring.

File size: 5.3 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 HeuristicLab.MainForm;
23using HeuristicLab.Optimization;
24using HeuristicLab.Optimization.Views;
25using HeuristicLab.Problems.DataAnalysis;
26using System;
27using System.Windows.Forms;
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      if (Content.Results != null)
58        resultsViewHost.Content = Content.Results;
59    }
60
61    protected override void RegisterContentEvents() {
62      base.RegisterContentEvents();
63      Content.AlgorithmChanged += (o, e) => algorithmViewHost.Content = Content.Optimizer;
64      Content.ProblemChanged += (o, e) => problemViewHost.Content = Content.Problem;
65      Content.ProblemDataChanged += (o, e) => dataViewHost.Content = Content.ProblemData;
66      Content.ResultsChanged += (o, e) => resultsViewHost.Content = Content.Results;
67    }
68
69    protected override void DeregisterContentEvents() {
70      base.DeregisterContentEvents();
71    }
72
73    #region event handlers
74    private void problemTab_DragDrop(object sender, DragEventArgs e) {
75      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
76        try {
77          Content.Problem = (IGoalSeekingProblem)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
78          problemViewHost.Content = Content.Problem;
79        } catch (Exception ex) {
80          MessageBox.Show(ex.Message, "Set problem", MessageBoxButtons.OK, MessageBoxIcon.Error);
81        }
82      }
83    }
84
85    private void problemTab_DragEnter(object sender, DragEventArgs e) {
86      e.Effect = DragDropEffects.None;
87      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
88        return;
89
90      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
91
92      if (data is IGoalSeekingProblem)
93        e.Effect = DragDropEffects.Copy;
94    }
95
96    private void algorithmTab_DragDrop(object sender, DragEventArgs e) {
97      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
98        try {
99          Content.Optimizer = (IAlgorithm)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
100          algorithmViewHost.Content = Content.Optimizer;
101        } catch (Exception ex) {
102          MessageBox.Show(ex.Message, "Set algorithm", MessageBoxButtons.OK, MessageBoxIcon.Error);
103        }
104      }
105    }
106
107    private void algorithmTab_DragEnter(object sender, DragEventArgs e) {
108      e.Effect = DragDropEffects.None;
109      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
110        return;
111
112      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
113      if (data is IAlgorithm)
114        e.Effect = DragDropEffects.Copy;
115    }
116    #endregion
117
118    private void dataTab_DragDrop(object sender, DragEventArgs e) {
119      if (e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) {
120        try {
121          Content.ProblemData = (IRegressionProblemData)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
122          dataViewHost.Content = Content.ProblemData;
123        } catch (Exception ex) {
124          // provide some information to the user
125          MessageBox.Show(ex.Message, "Set problem data", MessageBoxButtons.OK, MessageBoxIcon.Error);
126        }
127      }
128    }
129
130    private void dataTab_DragEnter(object sender, DragEventArgs e) {
131      e.Effect = DragDropEffects.None;
132      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat))
133        return;
134
135      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
136      if (data is IRegressionProblemData)
137        e.Effect = DragDropEffects.Copy;
138    }
139  }
140}
Note: See TracBrowser for help on using the repository browser.