Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Views/3.4/ProblemDataView.cs @ 10217

Last change on this file since 10217 was 10217, checked in by tsteinre, 10 years ago
  • implemented parent hopping to find the Problem or Algorithm.
File size: 5.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Linq;
24using System.Text;
25using System.Windows.Forms;
26using HeuristicLab.Core;
27using HeuristicLab.Core.Views;
28using HeuristicLab.Data;
29using HeuristicLab.DataPreprocessing;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32using HeuristicLab.Optimization.Views;
33
34namespace HeuristicLab.Problems.DataAnalysis.Views {
35  [View("Problem Data View")]
36  [Content(typeof(DataAnalysisProblemData), true)]
37  public partial class ProblemDataView : ParameterizedNamedItemView {
38
39    public new DataAnalysisProblemData Content {
40      get { return (DataAnalysisProblemData)base.Content; }
41      set { base.Content = value; }
42    }
43
44    public ProblemDataView() {
45      InitializeComponent();
46    }
47
48    protected void FeatureCorrelationButton_Click(object sender, System.EventArgs e) {
49      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(FeatureCorrelationView).IsAssignableFrom(t));
50      MainFormManager.MainForm.ShowContent(Content, viewType);
51    }
52
53    protected void parameterCollectionView_DragDrop(object sender, DragEventArgs e) {
54      if (e.Effect != DragDropEffects.None) {
55        var stringValueList = (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IFixedValueParameter).Value as ICheckedItemList<StringValue>;
56        SetInputVariables(stringValueList);
57      }
58    }
59
60    private void SetInputVariables(ICheckedItemList<StringValue> stringValueList) {
61      var inputVariables = Content.InputVariables;
62      var stringValues = stringValueList.Select(x => x.Value);
63      var notContainedVariables = inputVariables.Where(x => !stringValues.Contains(x.Value));
64
65      if (notContainedVariables.Count() != 0) {
66        StringBuilder strBuilder = new StringBuilder();
67        foreach (var variable in notContainedVariables) {
68          strBuilder.Append(variable.Value + ", ");
69        }
70        strBuilder.Remove(strBuilder.Length - 2, 2);
71        MessageBox.Show(String.Format("There was an error while changing the input variables. The following input " +
72          "variables have not been contained {0}", strBuilder.ToString()), "Error while changing the input variables",
73          MessageBoxButtons.OK, MessageBoxIcon.Warning);
74      } else {
75        var checkedItems = stringValueList.CheckedItems.Select(x => x.Value.Value);
76        var setChecked = inputVariables.Where(x => checkedItems.Contains(x.Value));
77        foreach (var variable in inputVariables) {
78          if (setChecked.Contains(variable) && !inputVariables.ItemChecked(variable)) {
79            inputVariables.SetItemCheckedState(variable, true);
80          } else if (!setChecked.Contains(variable) && inputVariables.ItemChecked(variable)) {
81            inputVariables.SetItemCheckedState(variable, false);
82          }
83        }
84      }
85    }
86
87    protected void parameterCollectionView_DragEnterOver(object sender, DragEventArgs e) {
88      e.Effect = DragDropEffects.None;
89      if (ReadOnly)
90        return;
91      if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) == null)
92        return;
93
94      var parameter = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IFixedValueParameter;
95      if (parameter == null)
96        return;
97
98      var stringValueList = parameter.Value as ICheckedItemList<StringValue>;
99      if (stringValueList == null)
100        return;
101
102      e.Effect = e.AllowedEffect;
103    }
104
105    private void DataPreprocessingButton_Click(object sender, EventArgs e) {
106      // IItem i = GetAlgorithmOrProblemContent();
107      Type viewType = MainFormManager.GetViewTypes(this.Content.GetType(), true).FirstOrDefault(t => typeof(DataPreprocessingView).IsAssignableFrom(t));
108      MainFormManager.MainForm.ShowContent(Content, viewType);
109    }
110
111    private IItem GetAlgorithmOrProblemContent() {
112      Control a = this;
113      IItem i = null;
114      do {
115        a = a.Parent;
116      } while (a != null && !(a is ProblemView));
117
118      if (a is ProblemView) {
119        i = ((ProblemView)a).Content;
120      }
121
122      do {
123        a = a.Parent;
124      } while (a != null && !(a is AlgorithmView));
125
126      if (a is AlgorithmView) {
127        i = ((AlgorithmView)a).Content;
128      }
129
130      return i;
131
132      //AlgorithmView algV = a as AlgorithmView;
133      //var clone = (IContent)algV.Content.Clone(new Cloner());
134      //MainFormManager.MainForm.ShowContent(clone);
135
136    }
137  }
138}
Note: See TracBrowser for help on using the repository browser.