Support xml file as input document for command line

master
huxingyi 2020-10-16 19:36:04 +09:30
parent 3cff6ad52a
commit 9c8ea6bb83
4 changed files with 81 additions and 66 deletions

View File

@ -8,18 +8,17 @@ language: cpp
matrix: matrix:
include: include:
- if: tag IS present - os: linux
- os: linux dist: xenial
dist: xenial sudo: required
sudo: required compiler: gcc
compiler: gcc addons:
addons: apt:
apt: sources:
sources: - ubuntu-toolchain-r-test
- ubuntu-toolchain-r-test - os: osx
- os: osx compiler: clang
compiler: clang osx_image: xcode9.3
osx_image: xcode9.3
install: install:
- if [[ $TRAVIS_BRANCH != "ci" && $TRAVIS_TAG == "" ]]; then echo "Not branch ci and no tag, cancel build"; fi - if [[ $TRAVIS_BRANCH != "ci" && $TRAVIS_TAG == "" ]]; then echo "Not branch ci and no tag, cancel build"; fi

View File

@ -1,6 +1,6 @@
os: Visual Studio 2017 os: Visual Studio 2017
skip_non_tags: true skip_non_tags: false
environment: environment:
matrix: matrix:

View File

@ -1663,74 +1663,87 @@ void DocumentWindow::createPartSnapshotForFillMesh(const QUuid &fillMeshFileId,
void DocumentWindow::openPathAs(const QString &path, const QString &asName) void DocumentWindow::openPathAs(const QString &path, const QString &asName)
{ {
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
Ds3FileReader ds3Reader(path);
m_document->clearHistories(); m_document->clearHistories();
m_document->resetScript(); m_document->resetScript();
m_document->reset(); m_document->reset();
m_document->saveSnapshot(); m_document->saveSnapshot();
for (int i = 0; i < ds3Reader.items().size(); ++i) { if (path.endsWith(".xml")) {
Ds3ReaderItem item = ds3Reader.items().at(i); QFile file(path);
if (item.type == "asset") { file.open(QIODevice::ReadOnly);
if (item.name.startsWith("images/")) { QXmlStreamReader stream(&file);
QString filename = item.name.split("/")[1];
QString imageIdString = filename.split(".")[0]; Snapshot snapshot;
QUuid imageId = QUuid(imageIdString); loadSkeletonFromXmlStream(&snapshot, stream);
if (!imageId.isNull()) { 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; QByteArray data;
ds3Reader.loadItem(item.name, &data); ds3Reader.loadItem(item.name, &data);
QImage image = QImage::fromData(data, "PNG"); QImage image = QImage::fromData(data, "PNG");
(void)ImageForever::add(&image, imageId); m_document->updateTurnaround(image);
} }
} else if (item.name.startsWith("files/")) { } else if (item.type == "script") {
QString filename = item.name.split("/")[1]; if (item.name == "model.js") {
QString fileIdString = filename.split(".")[0]; QByteArray script;
QUuid fileId = QUuid(fileIdString); ds3Reader.loadItem(item.name, &script);
if (!fileId.isNull()) { m_document->initScript(QString::fromUtf8(script.constData()));
}
} else if (item.type == "variable") {
if (item.name == "variables.xml") {
QByteArray data; QByteArray data;
ds3Reader.loadItem(item.name, &data); ds3Reader.loadItem(item.name, &data);
(void)FileForever::add(item.name, data, fileId); QXmlStreamReader stream(data);
std::map<QString, std::map<QString, QString>> 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<QString, std::map<QString, QString>> variables;
loadVariablesFromXmlStream(&variables, stream);
for (const auto &it: variables)
m_document->updateVariable(it.first, it.second);
}
}
}
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
setCurrentFilename(asName); setCurrentFilename(asName);
@ -2122,6 +2135,9 @@ void DocumentWindow::checkExportWaitingList()
} else if (filename.endsWith(".glb")) { } else if (filename.endsWith(".glb")) {
exportGlbToFilename(filename); exportGlbToFilename(filename);
emit waitingExportFinished(filename, isSuccessful); emit waitingExportFinished(filename, isSuccessful);
} else if (filename.endsWith(".png")) {
exportImageToFilename(filename);
emit waitingExportFinished(filename, isSuccessful);
} else { } else {
emit waitingExportFinished(filename, false); emit waitingExportFinished(filename, false);
} }

View File

@ -79,7 +79,7 @@ int main(int argc, char ** argv)
continue; continue;
} }
QString arg = argv[i]; QString arg = argv[i];
if (arg.endsWith(".ds3")) { if (arg.endsWith(".ds3") || arg.endsWith(".xml")) {
openFileList.append(arg); openFileList.append(arg);
continue; continue;
} }