Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ChangeDatasetOfRegressionModel/HeuristicLab.Problems.DataAnalysis.Views/3.4/Solution Views/RegressionSolutionView.cs @ 7468

Last change on this file since 7468 was 7468, checked in by mkommend, 12 years ago

#1758: Minor code improvements (variable naming, return conditions)

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Windows.Forms;
27using HeuristicLab.Core;
28using HeuristicLab.MainForm;
29using HeuristicLab.Persistence.Default.Xml;
30using HeuristicLab.PluginInfrastructure;
31
32namespace HeuristicLab.Problems.DataAnalysis.Views {
33  [View("RegressionSolution View")]
34  [Content(typeof(RegressionSolutionBase), false)]
35  public partial class RegressionSolutionView : DataAnalysisSolutionView {
36    public RegressionSolutionView() {
37      InitializeComponent();
38    }
39
40    public new RegressionSolutionBase Content {
41      get { return (RegressionSolutionBase)base.Content; }
42      set { base.Content = value; }
43    }
44
45    protected override void SetEnabledStateOfControls() {
46      base.SetEnabledStateOfControls();
47      importButton.Enabled = !Locked && !ReadOnly && Content != null;
48    }
49
50    #region drag and drop
51    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
52      validDragOperation = false;
53      if (ReadOnly) return;
54
55      var dropData = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
56      if (dropData is RegressionProblemData) validDragOperation = true;
57      else if (dropData is IValueParameter) {
58        var param = (IValueParameter)dropData;
59        if (param.Value is RegressionProblemData) validDragOperation = true;
60      }
61    }
62    #endregion
63
64    private void importButton_Click(object sender, EventArgs e) {
65      if (openFileDialog.ShowDialog(this) != DialogResult.OK) return;
66
67      object hlFile = null;
68      try {
69        hlFile = XmlParser.Deserialize(openFileDialog.FileName);
70      }
71      catch (Exception ex) {
72        ErrorHandling.ShowErrorDialog(this, ex);
73        return;
74      }
75
76      IRegressionProblemData problemData = null;
77      if (hlFile is IRegressionProblemData) {
78        problemData = (IRegressionProblemData)hlFile;
79      } else if (hlFile is IRegressionProblem) {
80        problemData = ((IRegressionProblem)hlFile).ProblemData;
81      } else if (hlFile is IRegressionSolution) {
82        problemData = ((IRegressionSolution)hlFile).ProblemData;
83      }
84
85      if (problemData == null) {
86        ErrorHandling.ShowErrorDialog(this,
87          new NullReferenceException("The problem data is null." + Environment.NewLine
88                                   + "The .hl-file is no RegressionProblemData or RegressionProblem."));
89        return;
90      }
91
92      StringBuilder message = new StringBuilder();
93      if (!problemData.TargetVariable.Equals(Content.ProblemData.TargetVariable))
94        message.AppendLine("The target variables are not matching. Old target variable: '"
95                         + Content.ProblemData.TargetVariable
96                         + "'. New targetvariable: '" + problemData.TargetVariable + "'");
97
98      List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
99      foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
100        if (!variables.Contains(item.Value.Value))
101          message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
102      }
103
104      if (message.Length != 0)
105        ErrorHandling.ShowErrorDialog(this, new Exception(message.ToString()));
106      else
107        Content.ProblemData = problemData;
108
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.