OpenToonz - An open-source full-featured 2D animation creation software
C
fix xdts io
shun-iwasawa23910493a185
diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cppindex 9e127c7e0..2a48aeb2d 100644--- a/toonz/sources/toonz/filebrowserpopup.cpp+++ b/toonz/sources/toonz/filebrowserpopup.cpp@@ -2258,13 +2258,15 @@ void BrowserPopupController::openPopup(QStringList filters,m_browserPopup->initFolder(TFilePath(lastSelectedPath.toStdWString()));m_browserPopup->setFileMode(isDirectoryOnly);+ Qt::WindowFlags flags = m_browserPopup->windowFlags();+ bool parentSet = false;if (parentWidget) {for (QWidget *pwidget : QApplication::topLevelWidgets()) {if (pwidget->isWindow() && pwidget->isVisible() &&pwidget->isAncestorOf(parentWidget)) {- Qt::WindowFlags flags = m_browserPopup->windowFlags();m_browserPopup->setParent(pwidget);m_browserPopup->setWindowFlags(flags);+ parentSet = true;break;}}@@ -2277,6 +2279,13 @@ void BrowserPopupController::openPopup(QStringList filters,m_isExecute = true;elsem_isExecute = false;++ // set back the parent to the main window in order to prevent to be+ // deleted along with the parent widget+ if (parentSet) {+ m_browserPopup->setParent(TApp::instance()->getMainWindow());+ m_browserPopup->setWindowFlags(flags);+ }}// codePath is set to true by defaultdiff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cppindex 7e056ed37..9ca73415d 100644--- a/toonz/sources/toonz/iocommand.cpp+++ b/toonz/sources/toonz/iocommand.cpp@@ -1917,6 +1917,7 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,scene->getProperties()->getFieldGuideAspectRatio());IconGenerator::instance()->invalidateSceneIcon();DvDirModel::instance()->refreshFolder(scenePath.getParentDir());+ // set dirty for xdts files since converted tnz is not yet savedTApp::instance()->getCurrentScene()->setDirtyFlag(isXdts);History::instance()->addItem(scenePath);if (updateRecentFile)diff --git a/toonz/sources/toonz/xdtsimportpopup.cpp b/toonz/sources/toonz/xdtsimportpopup.cppindex 40f149e5a..acc7d1ba1 100644--- a/toonz/sources/toonz/xdtsimportpopup.cpp+++ b/toonz/sources/toonz/xdtsimportpopup.cpp@@ -65,7 +65,7 @@ XDTSImportPopup::XDTSImportPopup(QStringList levelNames, ToonzScene* scene,connect(loadButton, SIGNAL(clicked()), this, SLOT(accept()));connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));- addButtonBarWidget(cancelButton, loadButton);+ addButtonBarWidget(loadButton, cancelButton);updateSuggestions(scenePath.getQString());}@@ -75,8 +75,17 @@ XDTSImportPopup::XDTSImportPopup(QStringList levelNames, ToonzScene* scene,void XDTSImportPopup::onPathChanged() {FileField* fileField = dynamic_cast<FileField*>(sender());if (!fileField) return;+ QString levelName = m_fields.key(fileField);// make the field non-suggestive- m_pathSuggestedLevels.removeAll(m_fields.key(fileField));+ m_pathSuggestedLevels.removeAll(levelName);++ // if the path is specified under the sub-folder with the same name as the+ // level, then try to make suggestions from the parent folder of it+ TFilePath fp =+ m_scene->decodeFilePath(TFilePath(fileField->getPath())).getParentDir();+ if (QDir(fp.getQString()).dirName() == levelName)+ updateSuggestions(fp.getQString());+updateSuggestions(fileField->getPath());}@@ -119,15 +128,39 @@ void XDTSImportPopup::updateSuggestions(const QString samplePath) {if (fileField->getPath().isEmpty() ||m_pathSuggestedLevels.contains(levelName)) {// input suggestion if there is a file with the same level name+ bool found = false;for (TFilePath path : pathSet) {if (path.getName() == levelName.toStdString()) {TFilePath codedPath = m_scene->codeFilePath(path);fileField->setPath(codedPath.getQString());if (!m_pathSuggestedLevels.contains(levelName))m_pathSuggestedLevels.append(levelName);+ found = true;break;}}+ // Not found in the current folder.+ // Then check if there is a sub-folder with the same name as the level+ // (like foo/A/A.tlv), as CSP exports levels like that.+ if (!found && suggestFolder.cd(levelName)) {+ TFilePathSet subPathSet;+ try {+ TSystem::readDirectory(subPathSet, suggestFolder, true);+ } catch (...) {+ return;+ }+ for (TFilePath path : subPathSet) {+ if (path.getName() == levelName.toStdString()) {+ TFilePath codedPath = m_scene->codeFilePath(path);+ fileField->setPath(codedPath.getQString());+ if (!m_pathSuggestedLevels.contains(levelName))+ m_pathSuggestedLevels.append(levelName);+ break;+ }+ }+ // back to parent folder+ suggestFolder.cdUp();+ }}++fieldsItr;}diff --git a/toonz/sources/toonz/xdtsio.cpp b/toonz/sources/toonz/xdtsio.cppindex 71f8caf56..b89cd595e 100644--- a/toonz/sources/toonz/xdtsio.cpp+++ b/toonz/sources/toonz/xdtsio.cpp@@ -10,6 +10,9 @@#include "toonz/txsheethandle.h"#include "toonz/tscenehandle.h"#include "toonz/preferences.h"+#include "toonz/sceneproperties.h"+#include "toonz/tstageobject.h"+#include "toutputproperties.h"#include "toonzqt/menubarcommand.h"#include "toonzqt/gutil.h"@@ -135,12 +138,19 @@ QVector<int> XdtsFieldTrackItem::getCellNumberTrack() const {qSort(frameCellNumbers.begin(), frameCellNumbers.end(), frameLessThan);QVector<int> cells;- int currentFrame = 0;+ int currentFrame = 0;+ int initialNumber = 0;for (QPair<int, int> &frameCellNumber : frameCellNumbers) {while (currentFrame < frameCellNumber.first) {- cells.append((cells.isEmpty()) ? 0 : cells.last());+ cells.append((cells.isEmpty()) ? initialNumber : cells.last());currentFrame++;}+ // CSP may export negative frame data (although it is not allowed in XDTS+ // format specification) so handle such case.+ if (frameCellNumber.first < 0) {+ initialNumber = frameCellNumber.second;+ continue;+ }// ignore sheet symbols for nowint cellNumber = frameCellNumber.second;if (cellNumber == -1)@@ -417,6 +427,8 @@ bool XdtsIo::loadXdtsScene(ToonzScene *scene, const TFilePath &scenePath) {scene->setProject(sceneProject.getPointer());std::string sceneFileName = scenePath.getName() + ".tnz";scene->setScenePath(scenePath.getParentDir() + sceneFileName);+ // set the current scene here in order to use $scenefolder node properly+ // in the file browser which opens from XDTSImportPopupTApp::instance()->getCurrentScene()->setScene(scene);XDTSImportPopup popup(levelNames, scene, scenePath);@@ -468,9 +480,24 @@ bool XdtsIo::loadXdtsScene(ToonzScene *scene, const TFilePath &scenePath) {for (; row < duration; row++)xsh->setCell(row, column, TXshCell(level, TFrameId(lastFid)));}++ TStageObject *pegbar =+ xsh->getStageObject(TStageObjectId::ColumnId(column));+ if (pegbar) pegbar->setName(levelName.toStdString());}xsh->updateFrameCount();+ // if the duration is shorter than frame count, then set it both in+ // preview range and output range.+ if (duration < xsh->getFrameCount()) {+ scene->getProperties()->getPreviewProperties()->setRange(0, duration - 1,+ 1);+ scene->getProperties()->getOutputProperties()->setRange(0, duration - 1, 1);+ }++ // emit signal here for updating the frame slider range of flip console+ TApp::instance()->getCurrentScene()->notifySceneChanged();+return true;}