From 9c8ea6bb837a469adeb38d7dd934d188494e8d32 Mon Sep 17 00:00:00 2001 From: huxingyi Date: Fri, 16 Oct 2020 19:36:04 +0930 Subject: [PATCH] Support xml file as input document for command line --- .travis.yml | 23 ++++---- appveyor.yml | 2 +- src/documentwindow.cpp | 120 +++++++++++++++++++++++------------------ src/main.cpp | 2 +- 4 files changed, 81 insertions(+), 66 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce38e841..2cf6927c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,18 +8,17 @@ language: cpp matrix: include: - - if: tag IS present - - os: linux - dist: xenial - sudo: required - compiler: gcc - addons: - apt: - sources: - - ubuntu-toolchain-r-test - - os: osx - compiler: clang - osx_image: xcode9.3 + - os: linux + dist: xenial + sudo: required + compiler: gcc + addons: + apt: + sources: + - ubuntu-toolchain-r-test + - os: osx + compiler: clang + osx_image: xcode9.3 install: - if [[ $TRAVIS_BRANCH != "ci" && $TRAVIS_TAG == "" ]]; then echo "Not branch ci and no tag, cancel build"; fi diff --git a/appveyor.yml b/appveyor.yml index c03fc8b3..58b97b02 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ os: Visual Studio 2017 -skip_non_tags: true +skip_non_tags: false environment: matrix: diff --git a/src/documentwindow.cpp b/src/documentwindow.cpp index c0d5a456..5e539165 100644 --- a/src/documentwindow.cpp +++ b/src/documentwindow.cpp @@ -1663,74 +1663,87 @@ void DocumentWindow::createPartSnapshotForFillMesh(const QUuid &fillMeshFileId, void DocumentWindow::openPathAs(const QString &path, const QString &asName) { QApplication::setOverrideCursor(Qt::WaitCursor); - Ds3FileReader ds3Reader(path); - + m_document->clearHistories(); m_document->resetScript(); m_document->reset(); m_document->saveSnapshot(); - for (int i = 0; i < ds3Reader.items().size(); ++i) { - Ds3ReaderItem item = ds3Reader.items().at(i); - if (item.type == "asset") { - if (item.name.startsWith("images/")) { - QString filename = item.name.split("/")[1]; - QString imageIdString = filename.split(".")[0]; - QUuid imageId = QUuid(imageIdString); - if (!imageId.isNull()) { + if (path.endsWith(".xml")) { + QFile file(path); + file.open(QIODevice::ReadOnly); + QXmlStreamReader stream(&file); + + Snapshot snapshot; + loadSkeletonFromXmlStream(&snapshot, stream); + m_document->fromSnapshot(snapshot); + m_document->saveSnapshot(); + } else { + Ds3FileReader ds3Reader(path); + + for (int i = 0; i < ds3Reader.items().size(); ++i) { + Ds3ReaderItem item = ds3Reader.items().at(i); + if (item.type == "asset") { + if (item.name.startsWith("images/")) { + QString filename = item.name.split("/")[1]; + QString imageIdString = filename.split(".")[0]; + QUuid imageId = QUuid(imageIdString); + if (!imageId.isNull()) { + QByteArray data; + ds3Reader.loadItem(item.name, &data); + QImage image = QImage::fromData(data, "PNG"); + (void)ImageForever::add(&image, imageId); + } + } else if (item.name.startsWith("files/")) { + QString filename = item.name.split("/")[1]; + QString fileIdString = filename.split(".")[0]; + QUuid fileId = QUuid(fileIdString); + if (!fileId.isNull()) { + QByteArray data; + ds3Reader.loadItem(item.name, &data); + (void)FileForever::add(item.name, data, fileId); + } + } + } + } + + for (int i = 0; i < ds3Reader.items().size(); ++i) { + Ds3ReaderItem item = ds3Reader.items().at(i); + if (item.type == "model") { + QByteArray data; + ds3Reader.loadItem(item.name, &data); + QXmlStreamReader stream(data); + Snapshot snapshot; + loadSkeletonFromXmlStream(&snapshot, stream); + m_document->fromSnapshot(snapshot); + m_document->saveSnapshot(); + } else if (item.type == "asset") { + if (item.name == "canvas.png") { QByteArray data; ds3Reader.loadItem(item.name, &data); QImage image = QImage::fromData(data, "PNG"); - (void)ImageForever::add(&image, imageId); + m_document->updateTurnaround(image); } - } else if (item.name.startsWith("files/")) { - QString filename = item.name.split("/")[1]; - QString fileIdString = filename.split(".")[0]; - QUuid fileId = QUuid(fileIdString); - if (!fileId.isNull()) { + } else if (item.type == "script") { + if (item.name == "model.js") { + QByteArray script; + ds3Reader.loadItem(item.name, &script); + m_document->initScript(QString::fromUtf8(script.constData())); + } + } else if (item.type == "variable") { + if (item.name == "variables.xml") { QByteArray data; ds3Reader.loadItem(item.name, &data); - (void)FileForever::add(item.name, data, fileId); + QXmlStreamReader stream(data); + std::map> variables; + loadVariablesFromXmlStream(&variables, stream); + for (const auto &it: variables) + m_document->updateVariable(it.first, it.second); } } } } - for (int i = 0; i < ds3Reader.items().size(); ++i) { - Ds3ReaderItem item = ds3Reader.items().at(i); - if (item.type == "model") { - QByteArray data; - ds3Reader.loadItem(item.name, &data); - QXmlStreamReader stream(data); - Snapshot snapshot; - loadSkeletonFromXmlStream(&snapshot, stream); - m_document->fromSnapshot(snapshot); - m_document->saveSnapshot(); - } else if (item.type == "asset") { - if (item.name == "canvas.png") { - QByteArray data; - ds3Reader.loadItem(item.name, &data); - QImage image = QImage::fromData(data, "PNG"); - m_document->updateTurnaround(image); - } - } else if (item.type == "script") { - if (item.name == "model.js") { - QByteArray script; - ds3Reader.loadItem(item.name, &script); - m_document->initScript(QString::fromUtf8(script.constData())); - } - } else if (item.type == "variable") { - if (item.name == "variables.xml") { - QByteArray data; - ds3Reader.loadItem(item.name, &data); - QXmlStreamReader stream(data); - std::map> variables; - loadVariablesFromXmlStream(&variables, stream); - for (const auto &it: variables) - m_document->updateVariable(it.first, it.second); - } - } - } QApplication::restoreOverrideCursor(); setCurrentFilename(asName); @@ -2122,6 +2135,9 @@ void DocumentWindow::checkExportWaitingList() } else if (filename.endsWith(".glb")) { exportGlbToFilename(filename); emit waitingExportFinished(filename, isSuccessful); + } else if (filename.endsWith(".png")) { + exportImageToFilename(filename); + emit waitingExportFinished(filename, isSuccessful); } else { emit waitingExportFinished(filename, false); } diff --git a/src/main.cpp b/src/main.cpp index e43e67fa..546e69c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,7 +79,7 @@ int main(int argc, char ** argv) continue; } QString arg = argv[i]; - if (arg.endsWith(".ds3")) { + if (arg.endsWith(".ds3") || arg.endsWith(".xml")) { openFileList.append(arg); continue; }