Safely exit after finishing command line exporting

master
Jeremy HU 2022-10-13 00:24:45 +11:00
parent bb2734ba33
commit 873e6423bb
4 changed files with 102 additions and 10 deletions

View File

@ -706,13 +706,15 @@ DocumentWindow::DocumentWindow()
void DocumentWindow::updateInprogressIndicator() void DocumentWindow::updateInprogressIndicator()
{ {
if (m_document->isMeshGenerating() || bool inprogress = m_document->isMeshGenerating() ||
m_document->isPostProcessing() || m_document->isPostProcessing() ||
m_document->isTextureGenerating()) { m_document->isTextureGenerating() ||
m_inprogressIndicator->showSpinner(true); nullptr != m_componentPreviewImagesGenerator ||
} else { nullptr != m_componentPreviewImagesDecorator;
m_inprogressIndicator->showSpinner(false); if (inprogress == m_inprogressIndicator->isSpinning())
} return;
m_inprogressIndicator->showSpinner(inprogress);
emit workingStatusChanged(inprogress);
} }
void DocumentWindow::toggleRotation() void DocumentWindow::toggleRotation()
@ -1211,6 +1213,8 @@ void DocumentWindow::generateComponentPreviewImages()
connect(m_componentPreviewImagesGenerator, &MeshPreviewImagesGenerator::finished, thread, &QThread::quit); connect(m_componentPreviewImagesGenerator, &MeshPreviewImagesGenerator::finished, thread, &QThread::quit);
connect(thread, &QThread::finished, thread, &QThread::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start(); thread->start();
updateInprogressIndicator();
} }
void DocumentWindow::componentPreviewImagesReady() void DocumentWindow::componentPreviewImagesReady()
@ -1230,6 +1234,8 @@ void DocumentWindow::componentPreviewImagesReady()
if (m_isComponentPreviewImagesObsolete) if (m_isComponentPreviewImagesObsolete)
generateComponentPreviewImages(); generateComponentPreviewImages();
else
updateInprogressIndicator();
} }
void DocumentWindow::decorateComponentPreviewImages() void DocumentWindow::decorateComponentPreviewImages()
@ -1263,6 +1269,8 @@ void DocumentWindow::decorateComponentPreviewImages()
connect(m_componentPreviewImagesDecorator.get(), &ComponentPreviewImagesDecorator::finished, thread, &QThread::quit); connect(m_componentPreviewImagesDecorator.get(), &ComponentPreviewImagesDecorator::finished, thread, &QThread::quit);
connect(thread, &QThread::finished, thread, &QThread::deleteLater); connect(thread, &QThread::finished, thread, &QThread::deleteLater);
thread->start(); thread->start();
updateInprogressIndicator();
} }
void DocumentWindow::componentPreviewImageDecorationsReady() void DocumentWindow::componentPreviewImageDecorationsReady()
@ -1280,6 +1288,8 @@ void DocumentWindow::componentPreviewImageDecorationsReady()
if (m_isComponentPreviewImageDecorationsObsolete) if (m_isComponentPreviewImageDecorationsObsolete)
decorateComponentPreviewImages(); decorateComponentPreviewImages();
else
updateInprogressIndicator();
} }
ModelWidget *DocumentWindow::modelWidget() ModelWidget *DocumentWindow::modelWidget()
@ -1394,4 +1404,9 @@ void DocumentWindow::updateRecentFileActions()
QString DocumentWindow::strippedName(const QString &fullFileName) QString DocumentWindow::strippedName(const QString &fullFileName)
{ {
return QFileInfo(fullFileName).fileName(); return QFileInfo(fullFileName).fileName();
} }
bool DocumentWindow::isWorking()
{
return nullptr == m_inprogressIndicator || m_inprogressIndicator->isSpinning();
}

View File

@ -30,11 +30,13 @@ signals:
void initialized(); void initialized();
void uninialized(); void uninialized();
void waitingExportFinished(const QString &filename, bool isSuccessful); void waitingExportFinished(const QString &filename, bool isSuccessful);
void workingStatusChanged(bool isWorking);
public: public:
DocumentWindow(); DocumentWindow();
~DocumentWindow(); ~DocumentWindow();
Document *document(); Document *document();
ModelWidget *modelWidget(); ModelWidget *modelWidget();
bool isWorking();
static DocumentWindow *createDocumentWindow(); static DocumentWindow *createDocumentWindow();
static const std::map<DocumentWindow *, dust3d::Uuid> &documentWindows(); static const std::map<DocumentWindow *, dust3d::Uuid> &documentWindows();
static void showAcknowlegements(); static void showAcknowlegements();

View File

@ -4,6 +4,7 @@
#include <iostream> #include <iostream>
#include <cstdio> #include <cstdio>
#include "document_window.h" #include "document_window.h"
#include "document.h"
#include "theme.h" #include "theme.h"
#include "version.h" #include "version.h"
@ -25,7 +26,81 @@ int main(int argc, char *argv[])
//freopen("dust3d.log", "w", stdout); //freopen("dust3d.log", "w", stdout);
//setvbuf(stdout, 0, _IONBF, 0); //setvbuf(stdout, 0, _IONBF, 0);
DocumentWindow::createDocumentWindow(); DocumentWindow *firstWindow = DocumentWindow::createDocumentWindow();
QStringList openFileList;
QStringList waitingExportList;
for (int i = 1; i < argc; ++i) {
if ('-' == argv[i][0]) {
if (0 == strcmp(argv[i], "-output") ||
0 == strcmp(argv[i], "-o")) {
++i;
if (i < argc)
waitingExportList.append(argv[i]);
continue;
}
qDebug() << "Unknown option:" << argv[i];
continue;
}
QString arg = argv[i];
if (arg.endsWith(".ds3")) {
openFileList.append(arg);
continue;
}
}
int finishedExportFileNum = 0;
int totalExportFileNum = 0;
int succeedExportNum = 0;
int exitCode = -1;
std::vector<DocumentWindow *> windowList;
auto checkToSafelyExit = [&]() {
if (-1 == exitCode)
return;
for (int i = 0; i < openFileList.size(); ++i) {
if (windowList[i]->isWorking())
return;
}
app.exit(exitCode);
};
if (!openFileList.empty()) {
windowList.push_back(firstWindow);
for (int i = 1; i < openFileList.size(); ++i) {
windowList.push_back(DocumentWindow::createDocumentWindow());
}
if (!waitingExportList.empty() &&
openFileList.size() == 1) {
totalExportFileNum = openFileList.size() * waitingExportList.size();
for (int i = 0; i < openFileList.size(); ++i) {
QObject::connect(windowList[i], &DocumentWindow::workingStatusChanged, &app, checkToSafelyExit);
}
for (int i = 0; i < openFileList.size(); ++i) {
QObject::connect(windowList[i], &DocumentWindow::waitingExportFinished, &app, [&](const QString &filename, bool isSuccessful) {
qDebug() << "Export to" << filename << (isSuccessful ? "isSuccessful" : "failed");
++finishedExportFileNum;
if (isSuccessful)
++succeedExportNum;
if (finishedExportFileNum == totalExportFileNum) {
if (succeedExportNum == totalExportFileNum) {
exitCode = 0;
checkToSafelyExit();
return;
}
exitCode = 1;
checkToSafelyExit();
return;
}
});
}
for (int i = 0; i < openFileList.size(); ++i) {
QObject::connect(windowList[i]->document(), &Document::exportReady, windowList[i], &DocumentWindow::checkExportWaitingList);
windowList[i]->setExportWaitingList(waitingExportList);
}
}
for (int i = 0; i < openFileList.size(); ++i) {
windowList[i]->openPathAs(openFileList[i], openFileList[i]);
}
}
return app.exec(); return app.exec();
} }

View File

@ -18,7 +18,7 @@ public:
const std::vector<std::vector<dust3d::Vector3>> &triangleVertexNormals, const std::vector<std::vector<dust3d::Vector3>> &triangleVertexNormals,
const dust3d::Color &color=dust3d::Color::createWhite(), const dust3d::Color &color=dust3d::Color::createWhite(),
float metalness=0.0, float metalness=0.0,
float roughness=0.0, float roughness=1.0,
const std::vector<std::tuple<dust3d::Color, float/*metalness*/, float/*roughness*/>> *vertexProperties=nullptr); const std::vector<std::tuple<dust3d::Color, float/*metalness*/, float/*roughness*/>> *vertexProperties=nullptr);
ModelMesh(dust3d::Object &object); ModelMesh(dust3d::Object &object);
ModelMesh(ModelOpenGLVertex *triangleVertices, int vertexNum); ModelMesh(ModelOpenGLVertex *triangleVertices, int vertexNum);