Vespucci  1.0.0
datasetimportdialog.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2014-2016 Wright State University - All Rights Reserved
3  Daniel P. Foose - Maintainer/Lead Developer
4 
5  This file is part of Vespucci.
6 
7  Vespucci 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  Vespucci 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 Vespucci. If not, see <http://www.gnu.org/licenses/>.
19 *******************************************************************************/
21 #include "ui_datasetimportdialog.h"
22 #include <QFileDialog>
25 
31 DatasetImportDialog::DatasetImportDialog(QWidget *parent, QSharedPointer<VespucciWorkspace> ws) :
32  QDialog(parent),
33  ui(new Ui::DatasetImportDialog)
34 {
35  ui->setupUi(this);
36  workspace_ = ws;
37  directory_ = ws->directory_ptr();
38  QString name = "Dataset" + QString::number(workspace_->dataset_loading_count());
39  ui->nameLineEdit->setText(name); //puts in default name
40 
41  QPushButton *ok_button = ui->buttonBox->button(QDialogButtonBox::Ok);
42  ok_button->setDisabled(true);
43 
44  ws->settings()->beginGroup("specdata");
45  QString abs_label = ws->settings()->value("absLabel").toString();
46  QString abs_units = ws->settings()->value("absUnits").toString();
47  QString ord_label = ws->settings()->value("ordLabel").toString();
48  QString ord_units = ws->settings()->value("ordUnits").toString();
49  ws->settings()->endGroup();
50 
51  ui->yDescriptionLineEdit->setText(ord_label);
52  ui->yUnitsLineEdit->setText(ord_units);
53  ui->xDescriptionLineEdit->setText(abs_label);
54  ui->xUnitsLineEdit->setText(abs_units);
55 
56  connect(ui->filenameLineEdit,
57  &QLineEdit::textChanged,
58  this,
60 }
61 
63 {
64  delete ui;
65 }
66 
67 void DatasetImportDialog::FilenameChanged(QString new_filename)
68 {
69  QFileInfo info(new_filename);
70  QString basename = info.completeBaseName();
71  QString dataset_name = basename;
72  int i = 1;
73  while (workspace_->dataset_names().contains(dataset_name))
74  dataset_name = basename + " (" + QString::number(i++) + ")";
75 
76  ui->nameLineEdit->setText(dataset_name);
77 }
78 
82 void DatasetImportDialog::on_browseButton_clicked()
83 {
84  QString filename;
85 
86  filename = QFileDialog::getOpenFileName(this, tr("Open Data File"),
87  workspace_->directory(),
88  tr("Text Files (*.txt);;"
89  "Vespucci Dataset Files (*.vds);;"));
90  ui->filenameLineEdit->setText(filename);
91 
92 }
93 
98 void DatasetImportDialog::on_buttonBox_accepted()
99 {
100  QString y_description = ui->yDescriptionLineEdit->text() + " (" + ui->yUnitsLineEdit->text() + ")";
101  QString x_description = ui->xDescriptionLineEdit->text() + " (" + ui->xUnitsLineEdit->text() + ")";
102 
103  QString name = ui->nameLineEdit->text();
104  QString filename = ui->filenameLineEdit->text();
105  QFileInfo file_info(filename);
106  QString extension = file_info.suffix();
107 
108  if (workspace_->dataset_names().contains(name)){
109  QMessageBox::warning(this, "Name Exists", "A dataset with this name already exists.");
110  return;
111  }
112 
113  std::string format;
114  const QString data_format_string = ui->dataFormatComboBox->currentText();
115  if (data_format_string == "Wide Text")
116  format = "WideTabDel";
117  else if (data_format_string == "Wide Text (CSV)")
118  format = "WideCSV";
119  else if (data_format_string == "Long Text")
120  format = "LongTabDel";
121  else if (data_format_string == "Long Text (CSV)")
122  format = "LongCSV";
123  else if (data_format_string == "Old Vespucci Dataset")
124  format = "OldVBinary";
125  else
126  return;
127 
128 
129 
130  if (data_format_string == "Old Vespucci Dataset"){
131  try{
132  mat spectra;
133  vec abscissa, x, y;
134  BinaryImport::ImportOldVespucciBinary(filename.toStdString(),
135  spectra,
136  abscissa,
137  x, y);
138  QSharedPointer<VespucciDataset> dataset(new VespucciDataset(name,
139  workspace_->main_window(),
140  workspace_->directory_ptr()));
141  dataset->SetData(spectra, abscissa, x, y);
142  if (!dataset->ConstructorCancelled()){
143  workspace_->AddDataset(dataset);
144  workspace_->set_directory(file_info.dir().absolutePath());
145  dataset.clear();
146  }
147  }catch(exception e){
148  workspace_->main_window()->DisplayExceptionWarning(e);
149  workspace_->RemoveDataset(name);
150  return;
151  }
152  close();
153  return;
154  }
155  bool swap = ui->swapCheckBox->isChecked();
156 
157  try{
158  QSharedPointer<VespucciDataset> dataset(new VespucciDataset(filename,
159  workspace_->main_window(),
160  directory_,
161  name,
162  x_description,
163  y_description,
164  swap,
165  format));
166  if (!dataset->ConstructorCancelled()){
167  workspace_->AddDataset(dataset);
168  workspace_->set_directory(file_info.dir().absolutePath());
169  dataset.clear();
170  }
171  }
172  catch(exception e){
173  workspace_->main_window()->DisplayExceptionWarning(e);
174  workspace_->RemoveDataset(name);
175  return;
176  }
177 
178  close();
179 }
180 
181 
182 
186 void DatasetImportDialog::on_buttonBox_rejected()
187 {
188  close();
189 }
190 
191 void DatasetImportDialog::on_filenameLineEdit_textChanged(const QString &arg1)
192 {
193  QFileInfo file_info(arg1);
194  QPushButton *ok_button = ui->buttonBox->button(QDialogButtonBox::Ok);
195 
196  if(file_info.exists()){
197  double file_size = file_info.size()/1048576;
198  QString file_size_string = QString::number(file_size, 'f', 3);
199  ui->fileSizeLabel->setText(file_size_string);
200  ok_button->setEnabled(true);
201  }
202 
203  else{
204  ui->fileSizeLabel->setText("File does not exist!");
205  ok_button->setDisabled(true);
206  }
207 }
Definition: ahcadialog.h:26
VESPUCCI_EXPORT bool ImportOldVespucciBinary(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y)
The VespucciDataset class This is the main class for dealing with hyperspectral data. This handles the import and export of spectra, and the creation of maps. Images are handled by the MapData class. This class is intended to be allocated on the heap inside of a smart pointer, there is no copy constructor.
The DatasetImportDialog class Dialog that allows the user to import files into the program...
DatasetImportDialog(QWidget *parent, QSharedPointer< VespucciWorkspace > ws)
DatasetImportDialog::DatasetImportDialog.
void FilenameChanged(QString new_filename)