[8715] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8715] | 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;
|
---|
[13414] | 23 | using System.Threading.Tasks;
|
---|
[8715] | 24 | using System.Windows.Forms;
|
---|
| 25 | using HeuristicLab.MainForm;
|
---|
| 26 | using HeuristicLab.Problems.DataAnalysis;
|
---|
[15912] | 27 | using HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab;
|
---|
| 28 | using HeuristicLab.Problems.Instances.DataAnalysis.Views.Regression.Matlab;
|
---|
[8715] | 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.Instances.DataAnalysis.Views {
|
---|
| 31 | [View("Regression InstanceProvider View")]
|
---|
[10000] | 32 | [Content(typeof(RegressionInstanceProvider), IsDefaultView = true)]
|
---|
| 33 | public partial class RegressionInstanceProviderView : DataAnalysisInstanceProviderView<IRegressionProblemData> {
|
---|
| 34 |
|
---|
| 35 | public new RegressionInstanceProvider Content {
|
---|
| 36 | get { return (RegressionInstanceProvider)base.Content; }
|
---|
[8715] | 37 | set { base.Content = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[10000] | 40 | public RegressionInstanceProviderView() {
|
---|
[8715] | 41 | InitializeComponent();
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | protected override void importButton_Click(object sender, EventArgs e) {
|
---|
[15912] | 45 | if (Content is RegressionMatlabInstanceProvider) {
|
---|
| 46 | ImportMatlabData();
|
---|
| 47 | } else {
|
---|
| 48 | ImportCSVData();
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | private void ImportCSVData() {
|
---|
[15185] | 53 | var importTypeDialog = new RegressionImportDialog();
|
---|
[10000] | 54 | if (importTypeDialog.ShowDialog() == DialogResult.OK) {
|
---|
| 55 | IRegressionProblemData instance = null;
|
---|
[13414] | 56 |
|
---|
| 57 | Task.Factory.StartNew(() => {
|
---|
| 58 | var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
|
---|
| 59 | // lock active view and show progress bar
|
---|
| 60 | IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
|
---|
| 61 |
|
---|
| 62 | try {
|
---|
[14286] | 63 | var progress = mainForm.AddOperationProgressToContent(activeView.Content,
|
---|
| 64 | "Loading problem instance.");
|
---|
[13414] | 65 |
|
---|
[14286] | 66 | Content.ProgressChanged +=
|
---|
| 67 | (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
|
---|
[13414] | 68 |
|
---|
[14286] | 69 | instance = Content.ImportData(importTypeDialog.Path, importTypeDialog.ImportType,
|
---|
| 70 | importTypeDialog.CSVFormat);
|
---|
[14298] | 71 | } catch (Exception ex) {
|
---|
[13414] | 72 | ErrorWhileParsing(ex);
|
---|
[14286] | 73 | return;
|
---|
| 74 | } finally {
|
---|
[13414] | 75 | mainForm.RemoveOperationProgressFromContent(activeView.Content);
|
---|
| 76 | }
|
---|
[14286] | 77 |
|
---|
[13414] | 78 | try {
|
---|
| 79 | GenericConsumer.Load(instance);
|
---|
[14298] | 80 | } catch (Exception ex) {
|
---|
[13414] | 81 | ErrorWhileLoading(ex, importTypeDialog.Path);
|
---|
| 82 | } finally {
|
---|
[13441] | 83 | Invoke((Action)(() => instancesComboBox.SelectedIndex = -1));
|
---|
[13414] | 84 | }
|
---|
| 85 | });
|
---|
[8715] | 86 | }
|
---|
| 87 | }
|
---|
[15912] | 88 |
|
---|
| 89 |
|
---|
| 90 | private void ImportMatlabData() {
|
---|
| 91 | var importTypeDialog = new RegressionMatlabImportDialog();
|
---|
| 92 | if (importTypeDialog.ShowDialog() == DialogResult.OK) {
|
---|
| 93 | IRegressionProblemData instance = null;
|
---|
| 94 |
|
---|
| 95 | Task.Factory.StartNew(() => {
|
---|
| 96 | var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
|
---|
| 97 | // lock active view and show progress bar
|
---|
| 98 | IContentView activeView = (IContentView)MainFormManager.MainForm.ActiveView;
|
---|
| 99 |
|
---|
| 100 | try {
|
---|
| 101 | var progress = mainForm.AddOperationProgressToContent(activeView.Content,
|
---|
| 102 | "Loading problem instance.");
|
---|
| 103 |
|
---|
| 104 | Content.ProgressChanged +=
|
---|
| 105 | (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };
|
---|
| 106 |
|
---|
| 107 | instance = (Content as RegressionMatlabInstanceProvider).ImportData(importTypeDialog.Path, importTypeDialog.ImportType, importTypeDialog.SelectedVariables);
|
---|
| 108 | } catch (Exception ex) {
|
---|
| 109 | ErrorWhileParsing(ex);
|
---|
| 110 | return;
|
---|
| 111 | } finally {
|
---|
| 112 | mainForm.RemoveOperationProgressFromContent(activeView.Content);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | try {
|
---|
| 116 | GenericConsumer.Load(instance);
|
---|
| 117 | } catch (Exception ex) {
|
---|
| 118 | ErrorWhileLoading(ex, importTypeDialog.Path);
|
---|
| 119 | } finally {
|
---|
| 120 | Invoke((Action)(() => instancesComboBox.SelectedIndex = -1));
|
---|
| 121 | }
|
---|
| 122 | });
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
[8715] | 125 | }
|
---|
| 126 | }
|
---|