-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2256 from cjh1/tiled-export
Add support for exporting dataset to Tiled
- Loading branch information
Showing
11 changed files
with
397 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* This source file is part of the Tomviz project, https://tomviz.org/. | ||
It is released under the 3-Clause BSD License, see "LICENSE". */ | ||
|
||
#include "DataBrokerSaveDialog.h" | ||
#include "DataBroker.h" | ||
#include "Utilities.h" | ||
|
||
#include "ui_DataBrokerSaveDialog.h" | ||
|
||
#include <QDateTime> | ||
#include <QDebug> | ||
#include <QProcessEnvironment> | ||
#include <QPushButton> | ||
#include <QTreeWidget> | ||
|
||
#include <pqSettings.h> | ||
|
||
namespace tomviz { | ||
|
||
DataBrokerSaveDialog::DataBrokerSaveDialog(DataBroker* dataBroker, | ||
QWidget* parent) | ||
: QDialog(parent), m_ui(new Ui::DataBrokerSaveDialog), | ||
m_dataBroker(dataBroker) | ||
{ | ||
m_ui->setupUi(this); | ||
|
||
setEnabledOkButton(false); | ||
|
||
connect(m_ui->nameLineEdit, &QLineEdit::textChanged, this, | ||
[this](const QString& name) { | ||
if (name.size() > 0) { | ||
m_name = name; | ||
setEnabledOkButton(true); | ||
} | ||
}); | ||
} | ||
|
||
DataBrokerSaveDialog::~DataBrokerSaveDialog() = default; | ||
|
||
void DataBrokerSaveDialog::setEnabledOkButton(bool enabled) | ||
{ | ||
auto okButton = m_ui->buttonBox->button(QDialogButtonBox::Ok); | ||
okButton->setEnabled(enabled); | ||
} | ||
|
||
QString DataBrokerSaveDialog::name() | ||
{ | ||
return m_name; | ||
} | ||
|
||
} // namespace tomviz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* This source file is part of the Tomviz project, https://tomviz.org/. | ||
It is released under the 3-Clause BSD License, see "LICENSE". */ | ||
|
||
#ifndef tomvizDataBrokerSaveDialog_h | ||
#define tomvizDataBrokerSaveDialog_h | ||
|
||
#include "ActiveObjects.h" | ||
|
||
#include <QDialog> | ||
|
||
#include <QDate> | ||
#include <QList> | ||
#include <QScopedPointer> | ||
#include <QVariantMap> | ||
|
||
namespace Ui { | ||
class DataBrokerSaveDialog; | ||
} | ||
|
||
class QTreeWidgetItem; | ||
|
||
namespace tomviz { | ||
|
||
class DataBroker; | ||
class ListResourceCall; | ||
|
||
class DataBrokerSaveDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit DataBrokerSaveDialog(DataBroker* dataBroker, | ||
QWidget* parent = nullptr); | ||
~DataBrokerSaveDialog() override; | ||
QString name(); | ||
|
||
private: | ||
Q_DISABLE_COPY(DataBrokerSaveDialog) | ||
QScopedPointer<Ui::DataBrokerSaveDialog> m_ui; | ||
DataBroker* m_dataBroker; | ||
|
||
void setEnabledOkButton(bool enable); | ||
|
||
QString m_name; | ||
}; | ||
} // namespace tomviz | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>DataBrokerSaveDialog</class> | ||
<widget class="QDialog" name="DataBrokerSaveDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>117</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Export to DataBroker</string> | ||
</property> | ||
<widget class="QDialogButtonBox" name="buttonBox"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>30</x> | ||
<y>70</y> | ||
<width>341</width> | ||
<height>32</height> | ||
</rect> | ||
</property> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="standardButtons"> | ||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
</property> | ||
</widget> | ||
<widget class="QWidget" name="formLayoutWidget"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>9</x> | ||
<y>9</y> | ||
<width>381</width> | ||
<height>51</height> | ||
</rect> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>Name to associate with data:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="1"> | ||
<widget class="QLineEdit" name="nameLineEdit"> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>accepted()</signal> | ||
<receiver>DataBrokerSaveDialog</receiver> | ||
<slot>accept()</slot> | ||
</connection> | ||
<connection> | ||
<sender>buttonBox</sender> | ||
<signal>rejected()</signal> | ||
<receiver>DataBrokerSaveDialog</receiver> | ||
<slot>reject()</slot> | ||
</connection> | ||
</connections> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* This source file is part of the Tomviz project, https://tomviz.org/. | ||
It is released under the 3-Clause BSD License, see "LICENSE". */ | ||
|
||
#include "DataBrokerSaveReaction.h" | ||
#include "DataBrokerSaveDialog.h" | ||
|
||
#include "ActiveObjects.h" | ||
#include "DataSource.h" | ||
#include "GenericHDF5Format.h" | ||
#include "LoadDataReaction.h" | ||
#include "Utilities.h" | ||
|
||
#include <vtkImageData.h> | ||
|
||
#include <QDebug> | ||
#include <QMessageBox> | ||
|
||
namespace tomviz { | ||
|
||
DataBrokerSaveReaction::DataBrokerSaveReaction(QAction* parentObject, | ||
MainWindow* mainWindow) | ||
: pqReaction(parentObject), m_mainWindow(mainWindow) | ||
{ | ||
QObject::connect( | ||
&ActiveObjects::instance(), | ||
QOverload<DataSource*>::of(&ActiveObjects::dataSourceChanged), this, | ||
[this](DataSource* dataSource) { | ||
parentAction()->setEnabled(dataSource != nullptr && | ||
m_dataBrokerInstalled); | ||
}); | ||
} | ||
|
||
DataBrokerSaveReaction::~DataBrokerSaveReaction() = default; | ||
|
||
void DataBrokerSaveReaction::onTriggered() | ||
{ | ||
saveData(); | ||
} | ||
|
||
void DataBrokerSaveReaction::setDataBrokerInstalled(bool installed) | ||
{ | ||
m_dataBrokerInstalled = installed; | ||
} | ||
|
||
void DataBrokerSaveReaction::saveData() | ||
{ | ||
auto dataBroker = new DataBroker(tomviz::mainWidget()); | ||
DataBrokerSaveDialog dialog(dataBroker, tomviz::mainWidget()); | ||
|
||
if (dialog.exec() == QDialog::Accepted) { | ||
auto name = dialog.name(); | ||
|
||
auto ds = ActiveObjects::instance().activeDataSource(); | ||
if (ds == nullptr) { | ||
qWarning() << "No active data source!"; | ||
return; | ||
} | ||
|
||
auto data = ds->imageData(); | ||
|
||
vtkNew<vtkImageData> permutedData; | ||
if (DataSource::hasTiltAngles(data)) { | ||
// No deep copies of data needed. Just re-label the axes. | ||
permutedData->ShallowCopy(data); | ||
relabelXAndZAxes(permutedData); | ||
} else { | ||
// Need to re-order to C ordering before writing | ||
GenericHDF5Format::reorderData(data, permutedData, | ||
ReorderMode::FortranToC); | ||
} | ||
|
||
tomviz::mainWidget()->setCursor(Qt::WaitCursor); | ||
auto call = dataBroker->saveData("fxi", name, data); | ||
connect( | ||
call, &SaveDataCall::complete, dataBroker, | ||
[dataBroker, this](const QString& id) { | ||
dataBroker->deleteLater(); | ||
tomviz::mainWidget()->unsetCursor(); | ||
QMessageBox messageBox( | ||
QMessageBox::Information, "tomviz", | ||
QString( | ||
"The active dataset was successfully exported to DataBroker: %1") | ||
.arg(id), | ||
QMessageBox::Ok, m_mainWindow); | ||
messageBox.exec(); | ||
}); | ||
|
||
connect(call, &DataBrokerCall::error, dataBroker, | ||
[dataBroker, this](const QString& errorMessage) { | ||
tomviz::mainWidget()->unsetCursor(); | ||
dataBroker->deleteLater(); | ||
QMessageBox messageBox( | ||
QMessageBox::Warning, "tomviz", | ||
QString("Error export data to DataBroker: %1. Please check " | ||
"message log for details.") | ||
.arg(errorMessage), | ||
QMessageBox::Ok, m_mainWindow); | ||
messageBox.exec(); | ||
}); | ||
} | ||
} | ||
|
||
} // namespace tomviz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* This source file is part of the Tomviz project, https://tomviz.org/. | ||
It is released under the 3-Clause BSD License, see "LICENSE". */ | ||
|
||
#ifndef tomvizDataBrokerSaveReaction_h | ||
#define tomvizDataBrokerSaveReaction_h | ||
|
||
#include <pqReaction.h> | ||
|
||
#include "DataBroker.h" | ||
#include "MainWindow.h" | ||
|
||
namespace tomviz { | ||
class DataSource; | ||
|
||
/// DataBrokerSaveReaction handles the "Export to DataBroker" action in | ||
/// tomviz. | ||
/// | ||
class DataBrokerSaveReaction : public pqReaction | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
DataBrokerSaveReaction(QAction* parentAction, MainWindow* mainWindow); | ||
~DataBrokerSaveReaction() override; | ||
|
||
void setDataBrokerInstalled(bool installed); | ||
void saveData(); | ||
|
||
protected: | ||
/// Called when the action is triggered. | ||
void onTriggered() override; | ||
|
||
bool m_dataBrokerInstalled = false; | ||
|
||
private: | ||
Q_DISABLE_COPY(DataBrokerSaveReaction) | ||
MainWindow* m_mainWindow; | ||
}; | ||
} // namespace tomviz | ||
|
||
#endif |
Oops, something went wrong.