Skip to content

Commit

Permalink
save and load workflows on hub instead of in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aumuell authored and MDjur committed Feb 17, 2023
1 parent 52b3aac commit 6773400
Show file tree
Hide file tree
Showing 21 changed files with 397 additions and 66 deletions.
15 changes: 13 additions & 2 deletions app/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->actionNew, SIGNAL(triggered()), SIGNAL(newDataFlow()));
ui->actionNew->setShortcut(QKeySequence::StandardKey::New);
connect(ui->actionOpen, SIGNAL(triggered()), SIGNAL(loadDataFlow()));
connect(ui->actionOpen, &QAction::triggered, [this]() { emit loadDataFlowOnHub(); });
ui->actionOpen->setShortcut(QKeySequence::StandardKey::Open);
connect(ui->actionOpenOnGui, SIGNAL(triggered()), SIGNAL(loadDataFlowOnGui()));
connect(ui->actionOpenOnHub, SIGNAL(triggered()), SIGNAL(loadDataFlowOnHub()));
connect(ui->actionSave, SIGNAL(triggered()), SIGNAL(saveDataFlow()));
ui->actionSave->setShortcut(QKeySequence::StandardKey::Save);
connect(ui->actionSave_As, SIGNAL(triggered()), SIGNAL(saveDataFlowAs()));
ui->actionSave_As->setShortcut(QKeySequence::StandardKey::SaveAs);
connect(ui->actionSaveOnGui, SIGNAL(triggered()), SIGNAL(saveDataFlowOnGui()));
connect(ui->actionSaveOnHub, SIGNAL(triggered()), SIGNAL(saveDataFlowOnHub()));
ui->actionSaveOnHub->setShortcut(QKeySequence::StandardKey::SaveAs);
connect(ui->actionExecute, SIGNAL(triggered()), SIGNAL(executeDataFlow()));
ui->actionExecute->setShortcut(QKeySequence::StandardKey::Refresh);
connect(ui->actionConnect, SIGNAL(triggered()), SIGNAL(connectVistle()));
Expand Down Expand Up @@ -105,6 +109,13 @@ MainWindow::MainWindow(QWidget *parent)
ui->modulesDock->raise();
ui->modulesDock->setFocus();

#ifndef HAVE_PYTHON
ui->actionSaveOnGui->setEnabled(false);
ui->actionSaveOnGui->setVisible(false);
ui->actionOpenOnGui->setEnabled(false);
ui->actionOpenOnGui->setVisible(false);
#endif

readSettings();

if (menuBar())
Expand Down
5 changes: 4 additions & 1 deletion app/gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ public slots:
void quitRequested(bool &allowed);
void newDataFlow();
void loadDataFlow();
void loadDataFlowOnGui();
void loadDataFlowOnHub();
void saveDataFlow();
void saveDataFlowAs();
void saveDataFlowOnGui();
void saveDataFlowOnHub();
void executeDataFlow();
void connectVistle();
void showSessionUrl();
Expand Down
44 changes: 39 additions & 5 deletions app/gui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@
<string>Fi&amp;le</string>
</property>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionOpenOnGui"/>
<addaction name="actionOpenOnHub"/>
<addaction name="actionSave"/>
<addaction name="actionSave_As"/>
<addaction name="actionSaveOnGui"/>
<addaction name="actionSaveOnHub"/>
<addaction name="separator"/>
<addaction name="actionShow_Session_URL"/>
<addaction name="actionCopy_Session_URL"/>
Expand Down Expand Up @@ -357,12 +359,12 @@
<string>&amp;Undo</string>
</property>
</action>
<action name="actionSave_As">
<action name="actionSaveOnGui">
<property name="text">
<string>Sa&amp;ve As...</string>
<string>Sa&amp;ve Locally...</string>
</property>
<property name="toolTip">
<string>Save workflow as a new file</string>
<string>Save workflow as a new file on GUI</string>
</property>
</action>
<action name="actionSettings">
Expand Down Expand Up @@ -516,6 +518,38 @@
<string>snap modules to positions aligning ports</string>
</property>
</action>
<action name="actionSaveOnHub">
<property name="text">
<string>Sa&amp;ve On Hub...</string>
</property>
<property name="toolTip">
<string>Save workflow as a new file on hub</string>
</property>
</action>
<action name="actionOpenOnHub">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/icons/open.svg</normaloff>:/icons/open.svg</iconset>
</property>
<property name="text">
<string>&amp;Open On Hub...</string>
</property>
<property name="toolTip">
<string>Open existing workflow on hub</string>
</property>
</action>
<action name="actionOpenOnGui">
<property name="icon">
<iconset resource="gui.qrc">
<normaloff>:/icons/open.svg</normaloff>:/icons/open.svg</iconset>
</property>
<property name="text">
<string>&amp;Open Locally...</string>
</property>
<property name="toolTip">
<string>Open existing workflow on GUI</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
6 changes: 3 additions & 3 deletions app/gui/modifieddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ ModifiedDialog::ModifiedDialog(const QString &reason, QWidget *parent): QMessage

setWindowTitle(QString("%1").arg(reason));

setText("The data flow network has been modified.");
setText("The workflow has been modified.");
if (reason == "Open") {
setInformativeText("You will lose your changes, if you load another data flow network without saving.");
setInformativeText("You will lose your changes, if you load another workflow without saving.");
} else if (reason == "New") {
setInformativeText("You will lose your changes, if you clear the data flow network without saving.");
setInformativeText("You will lose your changes, if you clear the workflow without saving.");
} else if (reason == "Quit") {
setInformativeText("You will lose your changes, if you quit without saving.");
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/gui/modifieddialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</rect>
</property>
<property name="windowTitle">
<string>Clear Data Flow Network?</string>
<string>Clear Workflow?</string>
</property>
<property name="modal">
<bool>true</bool>
Expand All @@ -23,7 +23,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>The data flow network was modified. Do you want to replace it?</string>
<string>The workflow was modified. Do you want to replace it?</string>
</property>
<property name="wordWrap">
<bool>true</bool>
Expand Down
121 changes: 101 additions & 20 deletions app/gui/uicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "uicontroller.h"
#include "vistleconsole.h"
#include <vistle/util/directory.h>
#include "remotefilebrowser/remotefiledialog.h"
#include "remotefilebrowser/vistlefileinfogatherer.h"
#include "remotefilebrowser/remotefilesystemmodel.h"

#include <thread>

Expand Down Expand Up @@ -77,7 +80,7 @@ UiController::UiController(int argc, char *argv[], QObject *parent): QObject(par
m_mainWindow->enableConnectButton(false);
}

setCurrentFile(QString::fromStdString(m_ui->state().loadedWorkflowFile()));
setCurrentFile(QString::fromStdString(m_ui->state().loadedWorkflowFile()), m_ui->state().workflowLoader());

///\todo declare the scene pointer in the header, then de-allocate in the destructor.
m_scene = new DataFlowNetwork(m_vistleConnection.get(), m_mainWindow, m_mainWindow->dataFlowView());
Expand All @@ -88,9 +91,11 @@ UiController::UiController(int argc, char *argv[], QObject *parent): QObject(par

connect(m_mainWindow, SIGNAL(quitRequested(bool &)), SLOT(quitRequested(bool &)));
connect(m_mainWindow, SIGNAL(newDataFlow()), SLOT(clearDataFlowNetwork()));
connect(m_mainWindow, SIGNAL(loadDataFlow()), SLOT(loadDataFlowNetwork()));
connect(m_mainWindow, SIGNAL(loadDataFlowOnGui()), SLOT(loadDataFlowNetworkOnGui()));
connect(m_mainWindow, SIGNAL(loadDataFlowOnHub()), SLOT(loadDataFlowNetworkOnHub()));
connect(m_mainWindow, SIGNAL(saveDataFlow()), SLOT(saveDataFlowNetwork()));
connect(m_mainWindow, SIGNAL(saveDataFlowAs()), SLOT(saveDataFlowNetworkAs()));
connect(m_mainWindow, SIGNAL(saveDataFlowOnGui()), SLOT(saveDataFlowNetworkOnGui()));
connect(m_mainWindow, SIGNAL(saveDataFlowOnHub()), SLOT(saveDataFlowNetworkOnHub()));
connect(m_mainWindow, SIGNAL(executeDataFlow()), SLOT(executeDataFlowNetwork()));
connect(m_mainWindow, SIGNAL(connectVistle()), SLOT(connectVistle()));
connect(m_mainWindow, SIGNAL(showSessionUrl()), SLOT(showConnectionInfo()));
Expand All @@ -112,7 +117,7 @@ UiController::UiController(int argc, char *argv[], QObject *parent): QObject(par
connect(m_scene, SIGNAL(selectionChanged()), SLOT(moduleSelectionChanged()));

connect(&m_observer, SIGNAL(quit_s()), qApp, SLOT(quit()));
connect(&m_observer, SIGNAL(loadedWorkflowChanged_s(QString)), SLOT(setCurrentFile(QString)));
connect(&m_observer, SIGNAL(loadedWorkflowChanged_s(QString, int)), SLOT(setCurrentFile(QString, int)));
connect(&m_observer, SIGNAL(sessionUrlChanged_s(QString)), SLOT(setSessionUrl(QString)));
connect(&m_observer, SIGNAL(info_s(QString, int)), m_mainWindow->console(), SLOT(appendInfo(QString, int)));
connect(&m_observer, SIGNAL(modified(bool)), m_mainWindow, SLOT(setModified(bool)));
Expand Down Expand Up @@ -257,10 +262,11 @@ void UiController::quitRequested(bool &allowed)

bool UiController::checkModified(const QString &reason)
{
//std::cerr << "modification count: " << m_observer->modificationCount() << std::endl;
if (m_observer.modificationCount() == 0 && !m_modified)
return true;

std::cerr << "modified: " << m_modified << ", modification count: " << m_observer.modificationCount() << std::endl;

ModifiedDialog d(reason, m_mainWindow);

int res = d.exec();
Expand All @@ -279,16 +285,16 @@ void UiController::clearDataFlowNetwork()

m_vistleConnection->resetDataFlowNetwork();
m_observer.resetModificationCount();
setCurrentFile(QString());
setCurrentFile(QString(), m_currentFileOnHub);
}

void UiController::loadDataFlowNetwork()
void UiController::loadDataFlowNetworkOnGui()
{
if (!checkModified("Open"))
return;

QString dir = m_currentFile.isEmpty() ? QDir::currentPath() : m_currentFile;
QString filename = QFileDialog::getOpenFileName(m_mainWindow, tr("Open Data Flow Network"), dir,
QString filename = QFileDialog::getOpenFileName(m_mainWindow, tr("Open Workflow"), dir,
tr("Vistle files (*.vsl);;Python files (*.py);;All files (*)"));

if (filename.isEmpty())
Expand All @@ -301,33 +307,75 @@ void UiController::loadDataFlowNetwork()
vistle::PythonInterface::the().exec_file(filename.toStdString());
#endif

setCurrentFile(filename);
setCurrentFile(filename, vistle::message::Id::UI);
m_observer.resetModificationCount();
}

void UiController::saveDataFlowNetwork(const QString &filename)
void UiController::loadDataFlowNetworkOnHub()
{
if (!checkModified("Open"))
return;

auto fig = new VistleFileInfoGatherer(m_ui.get(), vistle::message::Id::MasterHub);
auto model = new RemoteFileSystemModel(fig);
auto browser = new RemoteFileDialog(model);
browser->setAttribute(Qt::WA_DeleteOnClose);
browser->selectFile(m_currentFile.isEmpty() ? "." : m_currentFile);
browser->setFileMode(RemoteFileDialog::ExistingFile);
browser->setAcceptMode(RemoteFileDialog::AcceptOpen);
QStringList filters{"Vistle files (*.vsl)", "Python files (*.py)", "All files (*)"};
browser->setNameFilters(filters);
browser->setWindowTitle("Open Workflow");

connect(browser, &QDialog::accepted, [this, browser]() {
const auto &files = browser->selectedFiles();
if (!files.empty()) {
QString filename = files[0];
qDebug() << "open" << filename;
vistle::message::LoadWorkflow load(filename.toStdString());
m_ui->sendMessage(load);
m_currentFileOnHub = vistle::message::Id::MasterHub;
}
});

browser->show();
}

void UiController::saveDataFlowNetwork(const QString &filename, int hubId)
{
if (filename.isEmpty()) {
if (!m_currentFile.isEmpty())
saveDataFlowNetwork(m_currentFile);
else
saveDataFlowNetworkAs();
} else {
if (!m_currentFile.isEmpty()) {
saveDataFlowNetwork(m_currentFile, m_currentFileOnHub);
} else {
if (m_currentFileOnHub == vistle::message::Id::UI)
saveDataFlowNetworkOnGui();
else
saveDataFlowNetworkOnHub();
}
return;
}

if (hubId == vistle::message::Id::UI) {
std::cerr << "writing to " << filename.toStdString() << std::endl;
setCurrentFile(filename);
std::string cmd = "save(\"";
cmd += filename.toStdString();
cmd += "\")";
#ifdef HAVE_PYTHON
vistle::PythonInterface::the().exec(cmd);
#endif
m_observer.resetModificationCount();
#endif
setCurrentFile(filename, hubId);
} else if (vistle::message::Id::isHub(hubId)) {
vistle::message::SaveWorkflow save(filename.toStdString());
save.setDestId(hubId);
m_ui->sendMessage(save);
setCurrentFile(filename, hubId);
}
}

void UiController::saveDataFlowNetworkAs(const QString &filename)
void UiController::saveDataFlowNetworkOnGui(const QString &filename)
{
QString newFile = QFileDialog::getSaveFileName(m_mainWindow, tr("Save Data Flow Network"),
QString newFile = QFileDialog::getSaveFileName(m_mainWindow, tr("Save Workflow"),
filename.isEmpty() ? QDir::currentPath() : filename,
tr("Vistle files (*.vsl);;Python files (*.py);;All files (*)"));

Expand All @@ -336,6 +384,37 @@ void UiController::saveDataFlowNetworkAs(const QString &filename)
}
}

void UiController::saveDataFlowNetworkOnHub(const QString &pathname)
{
auto m_fig = new VistleFileInfoGatherer(m_ui.get(), vistle::message::Id::MasterHub);
auto model = new RemoteFileSystemModel(m_fig);
auto browser = new RemoteFileDialog(model);
browser->setAttribute(Qt::WA_DeleteOnClose);
if (pathname.isEmpty() && m_currentFileOnHub != vistle::message::Id::UI)
browser->selectFile(m_currentFile);
else
browser->selectFile(pathname);
browser->setFileMode(RemoteFileDialog::AnyFile);
browser->setAcceptMode(RemoteFileDialog::AcceptSave);
QStringList filters{"Vistle files (*.vsl)", "Python files (*.py)", "All files (*)"};
browser->setNameFilters(filters);
browser->setWindowTitle("Save Workflow");

connect(browser, &QDialog::accepted, [this, browser]() {
const auto &files = browser->selectedFiles();
if (!files.empty()) {
QString filename = files[0];
qDebug() << "save" << filename;
vistle::message::SaveWorkflow save(filename.toStdString());
m_ui->sendMessage(save);
m_currentFile = filename;
m_currentFileOnHub = vistle::message::Id::MasterHub;
}
});

browser->show();
}

void UiController::executeDataFlowNetwork()
{
m_vistleConnection->executeSources();
Expand Down Expand Up @@ -444,10 +523,12 @@ void UiController::statusUpdated(int id, QString text, int prio)
}
}

void UiController::setCurrentFile(QString file)
void UiController::setCurrentFile(QString file, int loaderId)
{
m_currentFile = file;
m_currentFileOnHub = loaderId;
m_mainWindow->setFilename(m_currentFile);
qDebug() << "current" << m_currentFile << loaderId;
}

void UiController::setSessionUrl(QString url)
Expand Down
11 changes: 7 additions & 4 deletions app/gui/uicontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ private slots:
void setModified(bool mod);
bool checkModified(const QString &reason);
void clearDataFlowNetwork();
void loadDataFlowNetwork();
void saveDataFlowNetwork(const QString &filename = QString());
void saveDataFlowNetworkAs(const QString &filename = QString());
void loadDataFlowNetworkOnGui();
void loadDataFlowNetworkOnHub();
void saveDataFlowNetwork(const QString &filename = QString(), int hubId = vistle::message::Id::Invalid);
void saveDataFlowNetworkOnGui(const QString &filename = QString());
void saveDataFlowNetworkOnHub(const QString &filename = QString());
void executeDataFlowNetwork();
void connectVistle();

Expand All @@ -55,7 +57,7 @@ private slots:
void parameterValueChanged(int moduleId, QString parameterName);

void statusUpdated(int id, QString text, int prio);
void setCurrentFile(QString file);
void setCurrentFile(QString file, int loaderId);
void setSessionUrl(QString url);

void showConnectionInfo();
Expand All @@ -79,6 +81,7 @@ private slots:
MainWindow *m_mainWindow = nullptr;

QString m_currentFile;
int m_currentFileOnHub = vistle::message::Id::Invalid;
bool m_modified = false;
std::string m_pythonDir;

Expand Down
Loading

0 comments on commit 6773400

Please sign in to comment.