Safely exit after finishing command line exporting
parent
bb2734ba33
commit
873e6423bb
|
@ -706,13 +706,15 @@ DocumentWindow::DocumentWindow()
|
|||
|
||||
void DocumentWindow::updateInprogressIndicator()
|
||||
{
|
||||
if (m_document->isMeshGenerating() ||
|
||||
bool inprogress = m_document->isMeshGenerating() ||
|
||||
m_document->isPostProcessing() ||
|
||||
m_document->isTextureGenerating()) {
|
||||
m_inprogressIndicator->showSpinner(true);
|
||||
} else {
|
||||
m_inprogressIndicator->showSpinner(false);
|
||||
}
|
||||
m_document->isTextureGenerating() ||
|
||||
nullptr != m_componentPreviewImagesGenerator ||
|
||||
nullptr != m_componentPreviewImagesDecorator;
|
||||
if (inprogress == m_inprogressIndicator->isSpinning())
|
||||
return;
|
||||
m_inprogressIndicator->showSpinner(inprogress);
|
||||
emit workingStatusChanged(inprogress);
|
||||
}
|
||||
|
||||
void DocumentWindow::toggleRotation()
|
||||
|
@ -1211,6 +1213,8 @@ void DocumentWindow::generateComponentPreviewImages()
|
|||
connect(m_componentPreviewImagesGenerator, &MeshPreviewImagesGenerator::finished, thread, &QThread::quit);
|
||||
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
||||
thread->start();
|
||||
|
||||
updateInprogressIndicator();
|
||||
}
|
||||
|
||||
void DocumentWindow::componentPreviewImagesReady()
|
||||
|
@ -1230,6 +1234,8 @@ void DocumentWindow::componentPreviewImagesReady()
|
|||
|
||||
if (m_isComponentPreviewImagesObsolete)
|
||||
generateComponentPreviewImages();
|
||||
else
|
||||
updateInprogressIndicator();
|
||||
}
|
||||
|
||||
void DocumentWindow::decorateComponentPreviewImages()
|
||||
|
@ -1263,6 +1269,8 @@ void DocumentWindow::decorateComponentPreviewImages()
|
|||
connect(m_componentPreviewImagesDecorator.get(), &ComponentPreviewImagesDecorator::finished, thread, &QThread::quit);
|
||||
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
||||
thread->start();
|
||||
|
||||
updateInprogressIndicator();
|
||||
}
|
||||
|
||||
void DocumentWindow::componentPreviewImageDecorationsReady()
|
||||
|
@ -1280,6 +1288,8 @@ void DocumentWindow::componentPreviewImageDecorationsReady()
|
|||
|
||||
if (m_isComponentPreviewImageDecorationsObsolete)
|
||||
decorateComponentPreviewImages();
|
||||
else
|
||||
updateInprogressIndicator();
|
||||
}
|
||||
|
||||
ModelWidget *DocumentWindow::modelWidget()
|
||||
|
@ -1395,3 +1405,8 @@ QString DocumentWindow::strippedName(const QString &fullFileName)
|
|||
{
|
||||
return QFileInfo(fullFileName).fileName();
|
||||
}
|
||||
|
||||
bool DocumentWindow::isWorking()
|
||||
{
|
||||
return nullptr == m_inprogressIndicator || m_inprogressIndicator->isSpinning();
|
||||
}
|
||||
|
|
|
@ -30,11 +30,13 @@ signals:
|
|||
void initialized();
|
||||
void uninialized();
|
||||
void waitingExportFinished(const QString &filename, bool isSuccessful);
|
||||
void workingStatusChanged(bool isWorking);
|
||||
public:
|
||||
DocumentWindow();
|
||||
~DocumentWindow();
|
||||
Document *document();
|
||||
ModelWidget *modelWidget();
|
||||
bool isWorking();
|
||||
static DocumentWindow *createDocumentWindow();
|
||||
static const std::map<DocumentWindow *, dust3d::Uuid> &documentWindows();
|
||||
static void showAcknowlegements();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include "document_window.h"
|
||||
#include "document.h"
|
||||
#include "theme.h"
|
||||
#include "version.h"
|
||||
|
||||
|
@ -25,7 +26,81 @@ int main(int argc, char *argv[])
|
|||
//freopen("dust3d.log", "w", stdout);
|
||||
//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();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
const std::vector<std::vector<dust3d::Vector3>> &triangleVertexNormals,
|
||||
const dust3d::Color &color=dust3d::Color::createWhite(),
|
||||
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);
|
||||
ModelMesh(dust3d::Object &object);
|
||||
ModelMesh(ModelOpenGLVertex *triangleVertices, int vertexNum);
|
||||
|
|
Loading…
Reference in New Issue