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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using System.Windows.Forms;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.MainForm;
|
---|
29 | using HeuristicLab.Persistence.Default.Xml;
|
---|
30 | using HeuristicLab.PluginInfrastructure;
|
---|
31 |
|
---|
32 | namespace 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 | btnImport.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 btnImport_Click(object sender, System.EventArgs e) {
|
---|
65 | if (openFileDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
66 | object hlFile = null;
|
---|
67 | try {
|
---|
68 | hlFile = XmlParser.Deserialize(openFileDialog.FileName);
|
---|
69 | }
|
---|
70 | catch (Exception ex) {
|
---|
71 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
72 | }
|
---|
73 |
|
---|
74 | if (hlFile != null) {
|
---|
75 | IRegressionProblemData problemData = null;
|
---|
76 | if (hlFile is RegressionProblemData) {
|
---|
77 | problemData = (RegressionProblemData)hlFile;
|
---|
78 | } else if (hlFile is IRegressionProblem) {
|
---|
79 | problemData = ((IRegressionProblem)hlFile).ProblemData;
|
---|
80 | } else if (hlFile is IRegressionSolution) {
|
---|
81 | problemData = ((IRegressionSolution)hlFile).ProblemData;
|
---|
82 | }
|
---|
83 |
|
---|
84 | if (problemData == null) {
|
---|
85 | ErrorHandling.ShowErrorDialog(this,
|
---|
86 | new NullReferenceException("The problem data is null." + Environment.NewLine
|
---|
87 | + "The .hl-file is no RegressionProblemData or RegressionProblem."));
|
---|
88 | } else {
|
---|
89 | StringBuilder message = new StringBuilder();
|
---|
90 | if (!problemData.TargetVariable.Equals(Content.ProblemData.TargetVariable))
|
---|
91 | message.AppendLine("The target variables are not matching. Old target variable: '"
|
---|
92 | + Content.ProblemData.TargetVariable
|
---|
93 | + "'. New targetvariable: '" + problemData.TargetVariable + "'");
|
---|
94 |
|
---|
95 | List<string> variables = problemData.InputVariables.Select(x => x.Value).ToList();
|
---|
96 |
|
---|
97 | foreach (var item in Content.ProblemData.InputVariables.CheckedItems) {
|
---|
98 | if (!variables.Contains(item.Value.Value))
|
---|
99 | message.AppendLine("Input variable '" + item.Value.Value + "' is not in the new problem data.");
|
---|
100 | }
|
---|
101 |
|
---|
102 | if (message.Length != 0)
|
---|
103 | ErrorHandling.ShowErrorDialog(this, new Exception(message.ToString()));
|
---|
104 | else
|
---|
105 | Content.ProblemData = problemData;
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|