Skip to content

Commit 5de632c

Browse files
committed
Closes #1434
1 parent 43807b2 commit 5de632c

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

src/Core/ImportExport/GenericIEPlugin.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Copyright (c) 2015 Scientific Computing and Imaging Institute,
77
University of Utah.
88
9-
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
@@ -106,7 +106,7 @@ class IEPluginLegacyAdapter : public GenericIEPluginInterface<Data>
106106

107107
template <class Data>
108108
class PluginMap
109-
{
109+
{
110110
public:
111111
PluginMap() : lock_("IE plugin map"), pluginTable_(nullptr) {}
112112
Core::Thread::Mutex& getLock();
@@ -174,7 +174,7 @@ size_t PluginMap<Data>::numPlugins() const
174174
template <class Data>
175175
void GenericIEPluginManager<Data>::get_importer_list(std::vector<std::string>& results) const
176176
{
177-
if (0 == map_.numPlugins())
177+
if (0 == map_.numPlugins())
178178
{
179179
return;
180180
}
@@ -190,7 +190,7 @@ void GenericIEPluginManager<Data>::get_importer_list(std::vector<std::string>& r
190190
template <class Data>
191191
void GenericIEPluginManager<Data>::get_exporter_list(std::vector<std::string>& results) const
192192
{
193-
if (0 == map_.numPlugins())
193+
if (0 == map_.numPlugins())
194194
{
195195
return;
196196
}
@@ -338,24 +338,28 @@ SCISHARE std::string defaultImportTypeForFile(const GenericIEPluginManager<NrrdD
338338

339339
SCISHARE std::string fileTypeDescriptionFromDialogBoxFilter(const std::string& fileFilter);
340340

341+
template <class Data>
342+
std::string dialogBoxFilterFromFileTypeDescription(const GenericIEPluginManager<Data>& mgr, const std::string& name)
343+
{
344+
if (name.find("*") != std::string::npos) // user has set state variable with full filter string
345+
return name;
346+
std::ostringstream filter;
347+
auto pl = mgr.get_plugin(name);
348+
auto ext = pl ? pl->fileExtension() : std::string();
349+
filter << name << " (" << (!ext.empty() ? ext : "*.*") << ")";
350+
return filter.str();
351+
}
352+
341353
template <class Data>
342354
std::string printPluginDescriptionsForFilter(const GenericIEPluginManager<Data>& mgr, const std::string& defaultType, const std::vector<std::string>& pluginNames)
343355
{
344356
std::ostringstream types;
345357
types << defaultType;
346358

359+
// Qt dialog-specific formatting
347360
for (const auto& name : pluginNames)
348361
{
349-
auto pl = mgr.get_plugin(name);
350-
types << ";;" << name;
351-
if (!pl->fileExtension().empty())
352-
{
353-
types << " (" << pl->fileExtension() << ")";
354-
}
355-
else
356-
{
357-
types << " (*.*)";
358-
}
362+
types << ";;" << dialogBoxFilterFromFileTypeDescription(mgr, name);
359363
}
360364
return types.str();
361365
}
@@ -370,7 +374,7 @@ std::string makeGuiTypesListForImport(const GenericIEPluginManager<Data>& mgr)
370374
}
371375

372376
template <class Data>
373-
std::string defaultExportTypeForFile(const GenericIEPluginManager<Data>* mgr = 0)
377+
std::string defaultExportTypeForFile(const GenericIEPluginManager<Data>* mgr = nullptr)
374378
{
375379
return "";
376380
}

src/Core/ImportExport/Nrrd/NrrdIEPlugin.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Copyright (c) 2015 Scientific Computing and Imaging Institute,
77
University of Utah.
88
9-
9+
1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),
1212
to deal in the Software without restriction, including without limitation
@@ -85,7 +85,7 @@ std::string SCIRun::defaultExportTypeForFile(const GenericIEPluginManager<Matrix
8585
return "SCIRun Matrix Binary (*.mat);;SCIRun Matrix ASCII (*.mat)";
8686
}
8787

88-
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
88+
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
8989

9090
#include <Core/Thread/Mutex.h>
9191
#include <Core/Utils/Legacy/StringUtil.h>
@@ -168,7 +168,7 @@ NrrdIEPlugin::~NrrdIEPlugin()
168168
std::map<std::string, NrrdIEPlugin *>::iterator iter = matrix_plugin_table->find(pluginname);
169169
if (iter == matrix_plugin_table->end())
170170
{
171-
std::cerr << "WARNING: NrrdIEPlugin " << pluginname <<
171+
std::cerr << "WARNING: NrrdIEPlugin " << pluginname <<
172172
" not found in database for removal.\n";
173173
}
174174
else
@@ -235,7 +235,7 @@ NrrdIEPluginManager::get_exporter_list(std::vector<std::string> &results)
235235
nrrdIEPluginMutex.unlock();
236236
}
237237

238-
238+
239239
NrrdIEPlugin *
240240
NrrdIEPluginManager::get_plugin(const std::string &name)
241241
{
@@ -257,4 +257,4 @@ NrrdIEPluginManager::get_plugin(const std::string &name)
257257
} // End namespace SCIRun
258258

259259

260-
#endif
260+
#endif

src/Interface/Modules/DataIO/ReadFieldDialog.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
#include <Core/Algorithms/Base/AlgorithmVariableNames.h>
3232
#include <Dataflow/Network/ModuleStateInterface.h> //TODO: extract into intermediate
3333
#include <Core/ImportExport/GenericIEPlugin.h>
34+
#include <Core/ImportExport/Field/FieldIEPlugin.h>
3435
#include <iostream>
3536
#include <QFileDialog>
3637

38+
using namespace SCIRun;
3739
using namespace SCIRun::Gui;
3840
using namespace SCIRun::Dataflow::Networks;
3941
using namespace SCIRun::Core::Algorithms;
@@ -59,6 +61,8 @@ ReadFieldDialog::ReadFieldDialog(const std::string& name, ModuleStateHandle stat
5961
void ReadFieldDialog::pullSpecial()
6062
{
6163
fileNameLineEdit_->setText(QString::fromStdString(state_->getValue(Variables::Filename).toString()));
64+
static FieldIEPluginManager mgr;
65+
selectedFilter_ = QString::fromStdString(dialogBoxFilterFromFileTypeDescription(mgr, state_->getValue(Variables::FileTypeName).toString()));
6266
}
6367

6468
void ReadFieldDialog::pushFileNameToState()
@@ -74,7 +78,7 @@ void ReadFieldDialog::openFile()
7478
auto file = QFileDialog::getOpenFileName(this, "Open Field File", dialogDirectory(), typesQ, &selectedFilter_);
7579
if (file.length() > 0)
7680
{
77-
auto typeName = SCIRun::fileTypeDescriptionFromDialogBoxFilter(selectedFilter_.toStdString());
81+
auto typeName = fileTypeDescriptionFromDialogBoxFilter(selectedFilter_.toStdString());
7882
state_->setValue(Variables::FileTypeName, typeName);
7983
fileNameLineEdit_->setText(file);
8084
updateRecentFile(file);

src/Interface/Modules/DataIO/ReadMatrixClassicDialog.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
#include <Modules/DataIO/ReadMatrixClassic.h>
3232
#include <Dataflow/Network/ModuleStateInterface.h> //TODO: extract into intermediate
3333
#include <Core/ImportExport/GenericIEPlugin.h>
34+
#include <Core/ImportExport/Matrix/MatrixIEPlugin.h>
3435
#include <iostream>
3536
#include <QFileDialog>
3637

38+
using namespace SCIRun;
3739
using namespace SCIRun::Core::Algorithms;
3840
using namespace SCIRun::Gui;
3941
using namespace SCIRun::Dataflow::Networks;
@@ -60,7 +62,8 @@ ReadMatrixClassicDialog::ReadMatrixClassicDialog(const std::string& name, Module
6062
void ReadMatrixClassicDialog::pullSpecial()
6163
{
6264
fileNameLineEdit_->setText(QString::fromStdString(state_->getValue(Variables::Filename).toString()));
63-
selectedFilter_ = QString::fromStdString(state_->getValue(Variables::FileTypeName).toString());
65+
static MatrixIEPluginManager mgr;
66+
selectedFilter_ = QString::fromStdString(dialogBoxFilterFromFileTypeDescription(mgr, state_->getValue(Variables::FileTypeName).toString()));
6467
}
6568

6669
void ReadMatrixClassicDialog::pushFileNameToState()
@@ -75,7 +78,7 @@ void ReadMatrixClassicDialog::openFile()
7578
auto file = QFileDialog::getOpenFileName(this, "Open Matrix File", dialogDirectory(), typesQ, &selectedFilter_);
7679
if (file.length() > 0)
7780
{
78-
auto typeName = SCIRun::fileTypeDescriptionFromDialogBoxFilter(selectedFilter_.toStdString());
81+
auto typeName = fileTypeDescriptionFromDialogBoxFilter(selectedFilter_.toStdString());
7982
state_->setValue(Variables::FileTypeName, typeName);
8083
fileNameLineEdit_->setText(file);
8184
updateRecentFile(file);

0 commit comments

Comments
 (0)