2 #include "ui_bulkconversiondialog.h" 10 QSharedPointer<VespucciWorkspace> ws) :
17 ui->filenameListWidget->setSelectionMode(QAbstractItemView::MultiSelection);
20 new QShortcut(QKeySequence(Qt::Key_Delete), ui->filenameListWidget);
21 connect(shortcut, SIGNAL(activated()),
this, SLOT(DeleteItem()));
30 void BulkConversionDialog::on_browsePushButton_clicked()
32 QStringList filename_list =
33 QFileDialog::getOpenFileNames(
this,
35 workspace_->directory(),
36 "Text (*.txt *.csv);;" 37 "Binary(*.arma *.bin *.dat)");
38 ui->filenameListWidget->addItems(filename_list);
41 void BulkConversionDialog::DeleteItem()
43 QList<QListWidgetItem*> items = ui->filenameListWidget->selectedItems();
44 for (
auto item: items)
45 ui->filenameListWidget->removeItemWidget(item);
48 void BulkConversionDialog::on_buttonBox_accepted()
52 ui->filenameListWidget->selectAll();
53 QList<QListWidgetItem *> items = ui->filenameListWidget->selectedItems();
54 vector<string> infile_names;
56 for (
auto item: items)
57 infile_names.push_back(item->text().toStdString());
59 string outfile_path = ui->targetLineEdit->text().toStdString();
61 arma::file_type outtype;
63 switch (ui->inputComboBox->currentIndex()){
76 switch (ui->outputComboBox->currentIndex()){
78 outtype = arma::arma_binary;
81 outtype = arma::csv_ascii;
84 outtype = arma::raw_ascii;
86 vector<string> skipped = SaveFiles(infile_names, outfile_path, intype, outtype);
89 report_dialog->
setLabel(
"Import or export failed for the following files:");
90 for (
auto& skipped_name : skipped)
92 report_dialog->show();
96 vector<string> BulkConversionDialog::SaveFiles(vector<string> infile_names,
string outfile_path, BulkConversionDialog::infile_type intype, arma::file_type outtype,
bool swap_spatial)
const 100 vector<string> skipped_files;
102 typedef vector<string>::iterator strvec_it;
105 bool comma_decimals =
false;
108 for(strvec_it it = infile_names.begin(); it!=infile_names.end(); ++it){
120 skipped_files.push_back(*it);
121 infile_names.erase(it);
126 QFileInfo(QString::fromStdString(*it)).baseName().toStdString();
127 WriteFile(outtype, outfilename, spectra, abscissa, x, y);
132 for(strvec_it it = infile_names.begin(); it!=infile_names.end(); ++it){
144 skipped_files.push_back(*it);
145 infile_names.erase(it);
150 QFileInfo(QString::fromStdString(*it)).baseName().toStdString();
152 WriteFile(outtype, outfilename, spectra, abscissa, x, y);
156 for (strvec_it it = infile_names.begin(); it != infile_names.end(); ++it){
157 QSharedPointer<VespucciDataset> dataset(
new VespucciDataset(QString::fromStdString(*it), workspace_->main_window(), workspace_));
158 ok = dataset->ConstructorCancelled();
160 skipped_files.push_back(*it);
161 infile_names.erase(it);
166 QFileInfo(QString::fromStdString(*it)).fileName().toStdString();
167 WriteFile(outtype, outfilename, dataset->spectra(), dataset->abscissa(), dataset->x(), dataset->y());
169 case oldbinary:
default:
170 for(strvec_it it = infile_names.begin(); it!=infile_names.end(); ++it){
176 skipped_files.push_back(*it);
177 infile_names.erase(it);
182 QFileInfo(QString::fromStdString(*it)).fileName().toStdString();
183 WriteFile(outtype, outfilename, spectra, abscissa, x, y);
186 return skipped_files;
189 const QString BulkConversionDialog::GetSep(
const QString &filename)
const 191 QFile inputfile(filename);
192 inputfile.open(QIODevice::ReadOnly);
193 QTextStream inputstream(&inputfile);
194 QString line = inputstream.readLine();
198 bool has_tab = -1 != line.indexOf(
"\t");
199 bool has_comma = -1 != line.indexOf(
",");
200 bool has_space = -1 !=line.indexOf(
" ");
204 if(has_tab){
return "\t";}
205 else if(has_space){
return " ";}
206 else if(has_comma) {
return ",";}
211 void BulkConversionDialog::WriteFile(
const arma::file_type &type,
212 const string filename,
213 const arma::mat &spectra,
214 const arma::vec &abscissa,
216 const arma::vec &y)
const 219 case csv_ascii:
case raw_ascii:
223 SaveHDF5(filename, spectra, abscissa, x, y);
224 case arma_binary:
default:
229 void BulkConversionDialog::on_BrowsePushButton_clicked()
231 QString path = QFileDialog::getExistingDirectory(
this,
"Select Folder",
232 workspace_->directory());
233 ui->targetLineEdit->setText(path);
236 bool BulkConversionDialog::SaveHDF5(
string filename,
243 workspace_->main_window(),
244 workspace_->directory_ptr());
245 dataset.
SetData(spectra, abscissa, x, y);
246 return dataset.Save(QString::fromStdString(filename));
VESPUCCI_EXPORT bool CheckFileValidity(QString filename, bool &comma_decimals)
TextImport::CheckFileValidity.
VESPUCCI_EXPORT bool ImportVespucciBinary(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y)
void SetData(const mat &spectra, const vec &wavelength, const vec &x, const vec &y)
VespucciDataset::SetData.
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.
VESPUCCI_EXPORT bool SaveOldVespucciBinary(std::string filename, const arma::mat &spectra, const arma::vec &x, const arma::vec &y, const arma::vec &abscissa)
Vespucci::SaveVespucciBinary.
void appendPlainText(const QString &text)
BulkConversionDialog(MainWindow *parent, QSharedPointer< VespucciWorkspace > ws)
VESPUCCI_EXPORT bool ImportWideText(std::string filename, arma::mat &spectra, arma::vec &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportWideText.
void setLabel(const QString &new_label)
The MainWindow class The main window of the program, this is where the user performs most operations...
VESPUCCI_EXPORT bool SaveText(std::string basename, const arma::mat &spectra, const arma::vec &x, const arma::vec &y, const arma::vec &abscissa, arma::file_type type)
VESPUCCI_EXPORT bool ImportLongText(std::string filename, arma::mat &spectra, arma::mat &abscissa, arma::vec &x, arma::vec &y, bool swap_spatial)
TextImport::ImportLongText.