Commit f65e0f28 authored by T.J. Corona's avatar T.J. Corona Committed by Kitware Robot

Merge topic 'updates-for-export'

16ac1211 Updates for export scripts
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Merge-request: !1333
parents 991505f6 16ac1211
......@@ -25,6 +25,7 @@
#include "smtk/extension/paraview/appcomponents/pqSMTKWrapper.h"
#include "smtk/extension/qt/qtOperationView.h"
#include "smtk/extension/qt/qtUIManager.h"
#include "smtk/io/Logger.h"
#include "smtk/operation/Manager.h"
#include "smtk/operation/operators/ImportPythonOperation.h"
......@@ -35,7 +36,9 @@
#include <QMenu>
#include <QMenuBar>
#include <QObject>
#include <QPushButton>
#include <QSharedPointer>
#include <QWindow>
pqExportSimulationReaction::pqExportSimulationReaction(QAction* parentObject)
: Superclass(parentObject)
......@@ -86,14 +89,24 @@ void pqExportSimulationReaction::exportSimulation()
// Set the input python operation file name
importPythonOp->parameters()->findFile("filename")->setValue(fname.toStdString());
// Execute the operation
auto result = importPythonOp->operate();
smtk::operation::Operation::Result result;
try
{
// Execute the operation
result = importPythonOp->operate();
}
catch (std::exception& e)
{
smtkErrorMacro(smtk::io::Logger::instance(), e.what());
return;
}
// Test the results for success
if (result->findInt("outcome")->value() !=
static_cast<int>(smtk::operation::Operation::Outcome::SUCCEEDED))
{
std::cerr << "\"import python operation\" operation failed\n";
smtkErrorMacro(
smtk::io::Logger::instance(), "\"import python operation\" operation failed\n");
return;
}
......@@ -117,9 +130,32 @@ void pqExportSimulationReaction::exportSimulation()
smtk::extension::qtOperationView* opView = dynamic_cast<smtk::extension::qtOperationView*>(
uiManager->setSMTKView(view, exportDialog.data()));
// Close the modal dialog when the operation is executed.
connect(opView, &smtk::extension::qtOperationView::operationRequested,
[=]() { exportDialog->done(QDialog::Accepted); });
// Alert the user if the operation fails. Close the dialog if the operation
// succeeds.
connect(opView, &smtk::extension::qtOperationView::operationExecuted,
[=](const smtk::operation::Operation::Result& result) {
if (result->findInt("outcome")->value() !=
static_cast<int>(smtk::operation::Operation::Outcome::SUCCEEDED))
{
QMessageBox msgBox;
msgBox.setStandardButtons(QMessageBox::Ok);
// Create a spacer so it doesn't look weird
QSpacerItem* horizontalSpacer =
new QSpacerItem(300, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.setText("Export failed. Please see output log for more details.");
QGridLayout* layout = (QGridLayout*)msgBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
msgBox.exec();
// Once the user has accepted that their export failed, they are
// free to try again without changing any options.
opView->onModifiedParameters();
}
else
{
exportDialog->done(QDialog::Accepted);
}
});
// Launch the modal dialog and wait for the operation to succeed.
exportDialog->exec();
......
......@@ -15,6 +15,7 @@
#include "smtk/attribute/Resource.h"
#include "smtk/extension/qt/qtAttribute.h"
#include "smtk/extension/qt/qtUIManager.h"
#include "smtk/io/Logger.h"
#include "smtk/operation/Operation.h"
#include "smtk/view/View.h"
......@@ -174,13 +175,14 @@ void qtOperationView::onOperate()
{
if ((!m_applied) && this->Internals->m_instancedView->isValid())
{
auto result = this->Internals->m_operator->operate();
smtk::operation::Operation::Result result = this->Internals->m_operator->operate();
emit this->operationRequested(this->Internals->m_operator);
emit this->operationExecuted(result);
if (this->Internals->m_applyButton)
{ // The button may disappear when a session is closed by an operator.
this->Internals->m_applyButton->setEnabled(false);
}
m_applied = true;
emit this->operationExecuted(result);
}
}
......@@ -100,7 +100,21 @@ public:
smtk::io::Logger& log() const override { PYBIND11_OVERLOAD(smtk::io::Logger&, Operation, log, ); }
Result operateInternal() override { PYBIND11_OVERLOAD_PURE(Result, Operation, operateInternal, ); }
Result operateInternal() override
{
// Python operations often raise exceptions. If they are uncaught, they
// become C++ exceptions. We convert these exceptions to a failed
// execution.
try
{
return this->operateInternalPy();
}
catch(std::exception& e)
{
this->log().addRecord(smtk::io::Logger::ERROR, e.what());
return this->createResult(smtk::operation::Operation::Outcome::FAILED);
}
}
void postProcessResult(Result& res) override
{ PYBIND11_OVERLOAD(void, Operation, postProcessResult, res); }
......@@ -119,6 +133,8 @@ private:
void setIndex(Index index) { m_index = index; }
void setTypeName(const std::string& typeName) { m_typeName = typeName; }
Result operateInternalPy() { PYBIND11_OVERLOAD_PURE(Result, Operation, operateInternal, ); }
pybind11::object m_object;
Index m_index;
std::string m_typeName;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment