OpenToonz - An open-source full-featured 2D animation creation software
C
Refactor Assets Import Process & Image Sequence Renaming
Abel Youeb30b087dd68
diff --git a/toonz/sources/common/tsystem/tsystem.cpp b/toonz/sources/common/tsystem/tsystem.cppindex 634c86c9a..3b79d7c06 100644--- a/toonz/sources/common/tsystem/tsystem.cpp+++ b/toonz/sources/common/tsystem/tsystem.cpp@@ -853,11 +853,11 @@ void TSystem::copyFileOrLevel_throw(const TFilePath &dst,//--------------------------------------------------------------bool TSystem::renameImageSequence(const TFilePathSet &files,- const TFilePath &levelPath,- int prefixLength) {+ const TFilePath &levelPath,+ int prefixLength) {std::string levelBaseName = levelPath.withoutParentDir().getName();-- //TSystem::readDirectory(levelPath.getParentDir(), false);+ assert(files.begin()->isAbsolute() && levelPath.isAbsolute());+ // TSystem::readDirectory(levelPath.getParentDir(), false);std::wstring wstr;TFilePath dst;@@ -868,10 +868,12 @@ bool TSystem::renameImageSequence(const TFilePathSet &files,wstr = wstr.substr(prefixLength);elsewstr.clear();- dst = file.withName(levelBaseName).withFrame(TFrameId(TFrameId(wstr).expand()));++ dst = file.getParentDir() +(levelBaseName + "." + TFrameId(wstr).expand()+ + file.getDottedType());try {TSystem::renameFile(dst, file);- } catch (...){+ } catch (...) {return false;}}diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.hindex f57738cda..1aa2b8209 100644--- a/toonz/sources/include/toonz/preferences.h+++ b/toonz/sources/include/toonz/preferences.h@@ -248,6 +248,7 @@ public:// Loading tabint getDefaultImportPolicy() { return getIntValue(importPolicy); }+ int getDefaultRenamePolicy() { return getIntValue(renamePolicy); }bool isAutoExposeEnabled() const { return getBoolValue(autoExposeEnabled); }bool isSubsceneFolderEnabled() const {return getBoolValue(subsceneFolderEnabled);diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cppindex bf54ea192..afa459907 100644--- a/toonz/sources/toonz/filebrowserpopup.cpp+++ b/toonz/sources/toonz/filebrowserpopup.cpp@@ -1210,9 +1210,11 @@ bool LoadLevelPopup::execute() {args.row0 = m_posFrom->text().toInt() - 1;args.frameCount = m_posTo->text().toInt() - m_posFrom->text().toInt() + 1;-- if ((int)getCurrentFIdsSet().size() != 0)- args.frameIdsSet.push_back(*getCurrentFIdsSet().begin());++ std::list<std::vector<TFrameId>> fidsSet = getCurrentFIdsSet();+ if (!fidsSet.empty()) {+ args.resourceDatas[0].m_frameIdSet = std::move(fidsSet.front());+ }else if (m_notExistLabel->isVisible()) {TFrameId firstLoadingFId = m_fromFrame->getValue();@@ -1229,7 +1231,7 @@ bool LoadLevelPopup::execute() {}if (!lastLoadingFId.getLetter().isEmpty())tmp_fids.push_back(lastLoadingFId);- args.frameIdsSet.push_back(tmp_fids);+ args.resourceDatas[0].m_frameIdSet = std::move(tmp_fids);}TFrameId xFrom = m_xFrom->getValue();@@ -1265,12 +1267,13 @@ bool LoadLevelPopup::execute() {args.resourceDatas.push_back(*it);std::list<std::vector<TFrameId>> fIdsSet = getCurrentFIdsSet();- if (fIdsSet.size() > 0) {- std::list<std::vector<TFrameId>>::const_iterator fIdIt;- for (fIdIt = fIdsSet.begin(); fIdIt != fIdsSet.end(); ++fIdIt)- args.frameIdsSet.insert(args.frameIdsSet.begin(), *fIdIt);+ auto fIdIt = fIdsSet.begin();+ auto rdIt = args.resourceDatas.begin();+ while (fIdIt != fIdsSet.end() && rdIt != args.resourceDatas.end()) {+ rdIt->m_frameIdSet = std::move(*fIdIt);+ ++fIdIt;+ ++rdIt;}-args.cachingBehavior = IoCmd::LoadResourceArguments::CacheRasterBehavior(m_rasterCacheBehaviorComboBox->currentData().toInt());diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cppindex af80a1443..71c87a67e 100644--- a/toonz/sources/toonz/iocommand.cpp+++ b/toonz/sources/toonz/iocommand.cpp@@ -1524,8 +1524,7 @@ bool IoCmd::saveScene(const TFilePath &path, int flags) {}// Must wait for current save to finish, just in case- while (TApp::instance()->isSaveInProgress())- ;+ while (TApp::instance()->isSaveInProgress());TApp::instance()->setSaveInProgress(true);try {@@ -1792,8 +1791,7 @@ void IoCmd::saveNonSceneFiles() {ToonzScene *scene = app->getCurrentScene()->getScene();SceneResources resources(scene, 0);// Must wait for current save to finish, just in case- while (TApp::instance()->isSaveInProgress())- ;+ while (TApp::instance()->isSaveInProgress());TApp::instance()->setSaveInProgress(true);resources.save(scene->getScenePath());@@ -1915,7 +1913,7 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,// if the .xml doesn't exist, load scene as standalone scene// belongs to sandbox projectTProjectManager *pm = TProjectManager::instance();- auto sceneProject = pm->loadSceneProject(scenePath);+ auto sceneProject = pm->loadSceneProject(scenePath);if (!sceneProject) {QString msg;msg = QObject::tr(@@ -2081,7 +2079,7 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,int ret =DVGui::MsgBox(question, turnOffPixelAnswer, resizeSceneAnswer, 0);if (ret == 0) {- } // do nothing+ } // do nothingelse if (ret == 1) { // Turn off pixels only modePreferences::instance()->setValue(pixelsOnly, false);app->getCurrentScene()->notifyPixelUnitSelected(false);@@ -2416,84 +2414,6 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,static bool isDir(const LoadResourceArguments::ResourceData &rd) {return QFileInfo(rd.m_path.getQString()).isDir();}-- // call when loading levels- static bool matchSequencePattern(const TFilePath &path) {- QRegularExpression pattern(- R"(- ^ # Match the start of the string- .*? # Optional prefix- \d+ # allow aFilePrefix<number>.ext,ignore if less than 10 and no padding- \. # Match a dot (.)- (png|jpg|jpeg|bmp|tga|tiff) # Image extensions- $ # Match the end of the string-)",- QRegularExpression::CaseInsensitiveOption |- QRegularExpression::ExtendedPatternSyntaxOption);- return pattern.match(QString::fromStdString(path.getLevelName()))- .hasMatch();- };-- static bool checkRenamePolicy(const TFilePath &path) {- // TODO: Check the Preference Policy- switch (Preferences::instance()->getIntValue(renamePolicy)) {- case 0:- break;- case 1:- return true;- case 2:- return false;- }- QString label =- QObject::tr(- "OpenToonz uses an underscore (_) or dot (.) as a frame "- "separator.\n"- "Would you like to add a separator to the image sequence?\n"- "\n%1 (and similar files)")- .arg(path.getQString());- QString checkBoxLabel = QObject::tr("Always do this action.");- QStringList buttons;- buttons << QObject::tr("Yes")- << QObject::tr("No, treat as single frame.");- DVGui::MessageAndCheckboxDialog *renameDialog =- DVGui::createMsgandCheckbox(DVGui::QUESTION, label, checkBoxLabel,- buttons, 1, Qt::Unchecked);- int ret = renameDialog->exec();- int checked = renameDialog->getChecked();- if (checked) {- Preferences::instance()->setValue(renamePolicy, ret);- TApp::instance()->getCurrentScene()->notifyImportPolicyChanged(ret);- }- return ret == 1;- };-- static bool isSharingSameParam(const TFilePath &path1,- const TFilePath &path2) {- std::wstring str1 = path1.getWideName(); // base name- std::wstring str2 = path2.getWideName();-- str1.erase(std::remove_if(str1.begin(), str1.end(), ::iswdigit),- str1.end());- str2.erase(std::remove_if(str2.begin(), str2.end(), ::iswdigit),- str2.end());-- return str1 == str2;- }-- static TFilePath getLevelPath(TFilePath path) {- std::wstring levelBaseName = path.getWideName();-- int i = levelBaseName.size();- while (i > 0 && std::iswdigit(levelBaseName[i - 1])) {- --i;- }- levelBaseName = levelBaseName.substr(0, i);-- if (!levelBaseName.size())- levelBaseName = path.getParentDir().getWideName();- return path.withName(levelBaseName).withFrame();- }-}; // localsif (args.resourceDatas.empty()) return 0;@@ -2544,21 +2464,24 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,std::vector<TFilePath> paths;int all = 0; // Turn on to allow all duplicate+ std::vector<LoadResourceArguments::ResourceData> rds;//Resources to be loaded- // Loop for all the resources to load+ // Loop for all the resources to import (Include subScene)for (int r = 0; r < rCount; ++r) {if (importDialog.aborted()) break;- QString origName =- args.resourceDatas[r].m_path.withoutParentDir().getQString();-LoadResourceArguments::ResourceData rd(args.resourceDatas[r]);- TFilePath &path = rd.m_path;+ TFilePath& path = rd.m_path;+ QString origName = path.withoutParentDir().getQString();- if (!rd.m_path.isLevelName())+ if (!path.isLevelName())path = TFilePath(path.getLevelNameW()).withParentDir(path.getParentDir());- if (std::find(paths.begin(), paths.end(), path) != paths.end()) {+ // duplicate check+ auto isDuplicate = [&rd](const IoCmd::LoadResourceArguments::ResourceData& existingRd) {+ return existingRd.m_path == rd.m_path;+ };+ if (std::find_if(rds.begin(), rds.end(), isDuplicate) != rds.end()) {if (!all) {QString question =QObject::tr(@@ -2566,11 +2489,11 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,"xsheet.\n\nAllow duplicate?").arg(origName).arg(QString::fromStdString(path.getName()));- QString Yes = QObject::tr("Allow");+ QString Yes = QObject::tr("Allow");QString YesAll = QObject::tr("Allow All Dups");- QString No = QObject::tr("No");- QString NoAll = QObject::tr("No to All Dups");- int ret = DVGui::MsgBox(question, Yes, YesAll, No, NoAll, 0);+ QString No = QObject::tr("No");+ QString NoAll = QObject::tr("No to All Dups");+ int ret = DVGui::MsgBox(question, Yes, YesAll, No, NoAll, 0);switch (ret) {case 2:all = 1; // YesAll@@ -2581,17 +2504,17 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,case 3:continue;}- } else if (all == 2)+ }+ else if (all == 2)continue;}- paths.push_back(path);if (progressDialog) {if (progressDialog->wasCanceled())break;else {progressDialog->setLabelText(- DVGui::ProgressDialog::tr("Loading \"%1\"...")+ DVGui::ProgressDialog::tr("Importing \"%1\"...").arg(path.getQString()));progressDialog->setValue(r);@@ -2610,8 +2533,7 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,if (ret == ResourceImportDialog::A_CANCEL) break;}- // for the scene file- TXshLevel *xl = 0;+ // SCENE FILEif (isScene) {TFilePath oldDstFolder = importDialog.getDstFolder();TFilePath dstFolder = (Preferences::instance()->isSubsceneFolderEnabled())@@ -2623,7 +2545,7 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,// load the scene as subXsheettry {- xl = loadChildLevel(scene, path, row0, col0, importDialog);+ auto xl = loadChildLevel(scene, path, row0, col0, importDialog);if (dstFolder != TFilePath())app->getCurrentScene()->notifyCastFolderAdded(scene->getLevelSet()->getDefaultFolder() + dstFolder);@@ -2634,8 +2556,7 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,// register the loaded level to argsargs.loadedLevels.push_back(xl);app->getCurrentXsheet()->notifyXsheetSoundChanged();- } catch (...) {- }+ } catch (...){}importDialog.setIsLastResource(isLastResource);importDialog.setDstFolder(oldDstFolder);@@ -2644,99 +2565,48 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,continue;}- // for single level files- else if (path.getSepChar().isNull()) {- // for single frame- if (rCount == 1) {+ // LEVEL FILE+ else {try {path = importDialog.process(scene, 0, path);- } catch (std::string msg) {- error(QString::fromStdString(msg));- continue;- }- }- // for sequence- else if (locals::matchSequencePattern(path) &&- locals::checkRenamePolicy(path)) {- TFilePathSet files;- TFilePath backup = scene->codeFilePath(path);- TFilePath levelPath = locals::getLevelPath(path);- progressDialog->setLabelText(- QString("Loading \"%1\"...")- .arg(levelPath.withFrame().getQString()));- // Check for Existing Level- if (TSystem::doesExistFileOrLevel(levelPath)) {- OverwriteDialog dialog;- levelPath.withName(dialog.execute(scene, levelPath, false));-- switch (dialog.getChoice()) {- case OverwriteDialog::KEEP_OLD:- while (r < rCount) {- path = args.resourceDatas[r].m_path;- if (backup.getParentDir() != path.getParentDir()) break;- if (!locals::isSharingSameParam(backup, path)) break;- ++r;- }- --r;- continue;-- case OverwriteDialog::OVERWRITE :- TSystem::removeFileOrLevel(levelPath);- default :- break;- }}- // Load or Import the files- while (r < rCount) {- path = args.resourceDatas[r].m_path;- progressDialog->setValue(r);- try {- path = importDialog.process(scene, 0, path);- } catch (std::string msg) {+ catch (std::string msg) {error(QString::fromStdString(msg));continue;}if (importDialog.aborted()) break;- // and Same parent folder- if ((backup.getParentDir() != path.getParentDir()) ||- (!locals::isSharingSameParam(backup, path))) {- --r;- break;- }- files.push_back(path);- ++r;- }- if (importDialog.aborted()) break;- if(TSystem::renameImageSequence(- files, levelPath,- backup.getWideName().substr(0,- backup.getWideName().find_last_not_of(L"0123456789") + 1)- .size())) {- QCoreApplication::processEvents();- path = levelPath;- } else {- // Failed to rename Files- DVGui::warning(QString("Failed to rename files!"));- break;}+ rd.m_path = path;+ rds.push_back(rd);}- }- // for other level files++ if(args.renamePolicy != LoadResourceArguments::RenamePolicy::NEVER)+ renameResources(rds);+++ if (progressDialog)+ progressDialog->setMaximum(rds.size());+ // LOAD IMPORTED FILE+ for (int i = 0; i < rds.size(); ++i) {+ TXshLevel* xl = 0;+ TFilePath path = rds[i].m_path;++ if (progressDialog) {+ if (progressDialog->wasCanceled())+ break;else {- try {- path = importDialog.process(scene, 0, path);- // path = scene->decodeFilePath(codedPath);- } catch (std::string msg) {- error(QString::fromStdString(msg));- continue;- }+ progressDialog->setLabelText(+ DVGui::ProgressDialog::tr("Loading \"%1\"...")+ .arg(path.getQString()));+ progressDialog->setValue(i);- if (importDialog.aborted()) break;+ QCoreApplication::processEvents();+ }}-+ // LOAD PSD FILEif (path.getType() == "psd") {- static PsdSettingsPopup *popup = 0;+ static PsdSettingsPopup* popup = 0;if (!popup) {popup = new PsdSettingsPopup();}@@ -2750,33 +2620,26 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,if (updateRecentFile)RecentFiles::instance()->addFilePath(toQString(scene->decodeFilePath(path)), RecentFiles::Level);- } else {- // reuse TFrameIds retrieved by FileBrowser- std::vector<TFrameId> fIds;- if ((int)args.frameIdsSet.size() > r) // if there is fIds to be reused- {- fIds = args.frameIdsSet[r];+ continue;}-+ // LOAD OTHER FILEtry {+ // reuse TFrameIds retrieved by FileBrowser, m_frameIdSetxl = ::loadResource(- scene, rd, args.castFolder, row0, col0, row1, col1, args.expose,-#if (__cplusplus > 199711L)- std::move(fIds),-#else- fIds,-#endif+ scene, rds[i], args.castFolder, row0, col0, row1, col1, args.expose,+ rds[i].m_frameIdSet,args.xFrom, args.xTo, args.levelName, args.step, args.inc,args.frameCount, args.doesFileActuallyExist);if (updateRecentFile) {RecentFiles::instance()->addFilePath(toQString(scene->decodeFilePath(path)), RecentFiles::Level);}- } catch (TException &e) {+ } catch (TException& e) {error(QString::fromStdWString(e.getMessage()));}+// if load success- if (xl) {+ if (!xl)continue;isSoundLevel = isSoundLevel || xl->getType() == SND_XSHLEVEL;// register the loaded level to argsargs.loadedLevels.push_back(xl);@@ -2785,7 +2648,7 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,// load the image data of all frames to cache at the beginningif (args.cachingBehavior != LoadResourceArguments::ON_DEMAND) {- TXshSimpleLevel *simpleLevel = xl->getSimpleLevel();+ TXshSimpleLevel* simpleLevel = xl->getSimpleLevel();if (simpleLevel && (simpleLevel->getType() == TZP_XSHLEVEL ||simpleLevel->getType() == OVL_XSHLEVEL)) {bool cacheImagesAsWell =@@ -2795,8 +2658,6 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,}}}- }- }if (loadedCount) app->getCurrentFrame()->setFrameIndex(row0);@@ -2921,6 +2782,252 @@ bool IoCmd::importLipSync(TFilePath levelPath, QList<TFrameId> frameList,return true;}+void IoCmd::renameResources(std::vector<LoadResourceArguments::ResourceData>& rds, bool askUser) {+ struct locals {+ // call when loading levels+ static bool matchSequencePattern(const TFilePath& path) {+ QRegularExpression pattern(+ R"(+ ^ # Match the start of the string+ .*? # Optional prefix+ \d+ # allow aFilePrefix<number>.ext+ \. # Match a dot (.)+ (png|jpg|jpeg|bmp|tga|tiff) # Image extensions+ $ # Match the end of the string+)",+QRegularExpression::CaseInsensitiveOption |+QRegularExpression::ExtendedPatternSyntaxOption);+ return pattern.match(QString::fromStdString(path.getLevelName()))+ .hasMatch();+ };++ static bool checkRenamePolicy(const TFilePath& path) {+ switch (Preferences::instance()->getIntValue(renamePolicy)) {+ case 0:+ break;+ case 1:+ return true;+ case 2:+ return false;+ }+ QString label =+ QObject::tr(+ "Image sequence detected, but the filenames are missing a separator: \n"+ "OpenToonz requires a separator (such as an underscore (_) or dot (.) \n"+ "between the name and the frame number to recognize sequences properly.\n"+ "Example: A0001.png → A.0001.png\n"+ "\nWould you like OpenToonz to automatically add a dot to fix the sequence format?\n"+ "\n%1 (and similar files)")+ .arg(path.getQString());++ QString checkBoxLabel = QObject::tr("Always do this action.");++ QStringList buttons;+ buttons << QObject::tr("Yes, add dot")+ << QObject::tr("No, treat as single frame");++ DVGui::MessageAndCheckboxDialog* renameDialog =+ DVGui::createMsgandCheckbox(DVGui::QUESTION, label, checkBoxLabel,+ buttons, 1, Qt::Unchecked);+ int ret = renameDialog->exec();+ int checked = renameDialog->getChecked();+ if (checked) {+ Preferences::instance()->setValue(renamePolicy, ret);+ TApp::instance()->getCurrentScene()->notifyImportPolicyChanged(ret);+ }+ return ret == 1;+ };++ static bool isSharingSameParam(const TFilePath& path1,+ const TFilePath& path2) {+ std::wstring str1 = path1.getWideName(); // base name+ std::wstring str2 = path2.getWideName();++ str1.erase(std::remove_if(str1.begin(), str1.end(), ::iswdigit),+ str1.end());+ str2.erase(std::remove_if(str2.begin(), str2.end(), ::iswdigit),+ str2.end());++ return str1 == str2;+ }++ static TFilePath getLevelPath(TFilePath path) {+ std::wstring levelBaseName = path.getWideName();++ int i = levelBaseName.size();+ while (i > 0 && std::iswdigit(levelBaseName[i - 1])) {+ --i;+ }+ levelBaseName = levelBaseName.substr(0, i);++ if (!levelBaseName.size())+ levelBaseName = path.getParentDir().getWideName();+ return path.withName(levelBaseName).withFrame();+ }+ }; // locals++ TApp* app = TApp::instance();+ ToonzScene* scene = app->getCurrentScene()->getScene();+ for (auto rd = rds.begin(); rd != rds.end();++rd) {+ TFilePath& path = rd->m_path;+ if (!locals::matchSequencePattern(path))continue;+ if (askUser &&+ !locals::checkRenamePolicy(path)) continue;+ TFilePath levelPath = scene->decodeFilePath(locals::getLevelPath(path));+ bool keepOld = false;+ if (TSystem::doesExistFileOrLevel(levelPath)) {+ OverwriteDialog dialog;+ levelPath = levelPath.withName(dialog.execute(scene, levelPath, false));+ if (dialog.getChoice() == OverwriteDialog::OVERWRITE)+ TSystem::removeFileOrLevel(levelPath);+ else if (dialog.getChoice() == OverwriteDialog::KEEP_OLD)+ keepOld = true;+ }+ TFilePath ¤tPath = rd->m_path;+ TFilePathSet files;+ files.push_back(scene->decodeFilePath(currentPath));+ auto nextRd = rd;+ nextRd++;+ for (; nextRd != rds.end();) {+ if ((currentPath.getParentDir() == nextRd->m_path.getParentDir()) &&+ (locals::isSharingSameParam(currentPath, nextRd->m_path))) {+ if(!keepOld)files.push_back(scene->decodeFilePath(nextRd->m_path));+ nextRd = rds.erase(nextRd);+ }+ else break;+ }+ if (keepOld) {+ currentPath = levelPath; continue;+ }+ if (files.empty())continue;+ if (TSystem::renameImageSequence(+ files, levelPath,+ currentPath.getWideName().substr(0,+ currentPath.getWideName().find_last_not_of(L"0123456789") + 1)+ .size())) {+ QCoreApplication::processEvents();+ currentPath = levelPath;+ } else {+ // Failed to rename Files+ DVGui::warning(QString("Failed to rename files!\n%1").arg(rd->m_path.getQString()));+ break;+ }+ }+}++// Use double value DPI as policy+// 0:Image DPI , -1:CameraDPI , other:value of dpi+void IoCmd::convertNAARaster2TLV(std::vector<LoadResourceArguments::ResourceData>& rds,+ bool askUser, double dpi, bool appendPalette) {+ struct locals {+ static bool checkConvertPolicy(const TFilePath& path) {+ switch (Preferences::instance()->getIntValue(convertPolicy)) {+ case 0:+ break; // Ask every time+ case 1:+ return true; // Always convert+ case 2:+ return false; // Never convert+ }++ QString label = QObject::tr(+ "%1\n\nis an image sequence that can be converted into a TLV format "+ "\nWould you like to convert it?")+ .arg(path.getQString());++ QString checkBoxLabel = QObject::tr("Always do this action.");+ QStringList buttons;+ buttons << QObject::tr("Yes") << QObject::tr("No, use as is");++ DVGui::MessageAndCheckboxDialog* convertDialog =+ DVGui::createMsgandCheckbox(DVGui::QUESTION, label, checkBoxLabel,+ buttons, 1, Qt::Unchecked);++ int ret = convertDialog->exec();+ int checked = convertDialog->getChecked();++ if (checked) {+ Preferences::instance()->setValue(convertPolicy, ret);+ TApp::instance()->getCurrentScene()->notifyImportPolicyChanged(ret);+ }++ return ret == 1;+ }++ static bool getRange(const TFilePath& path, int& from, int& to, TFilePath &first) {+ TLevelP levelTmp;+ TLevelReaderP lrTmp = TLevelReaderP(path);+ if (lrTmp) {+ levelTmp = lrTmp->loadInfo();+ TLevel::Table* t = levelTmp->getTable();+ if (!t->empty()) {+ TFrameId start = t->begin()->first;+ TFrameId end = t->rbegin()->first;+ if (start.getNumber() >= 0 && end.getNumber() >= 0) {+ from = start.getNumber();+ to = end.getNumber();+ first = lrTmp->getFrameReader(start)->getFilePath();+ return true;+ }+ }+ }+ return false;+ }+ };//Locals++ static const QStringList rasterExts = {+ "png", "jpg", "jpeg", "bmp", "tga" };+ TApp* app = TApp::instance();+ ToonzScene* scene = app->getCurrentScene()->getScene();+ for (auto &rd : rds) {+ TFilePath& path = rd.m_path;+ if (path.getDots() == ".." && rasterExts.contains(QString::fromStdString(path.getType()).toLower())) {+ if (!path.isAbsolute()) path = scene->decodeFilePath(path);+ TFilePath dstPath = path.getParentDir() + TFilePath(path.getName()).withType("tlv");+ int from, to;+ TFilePath first;+ if (!locals::getRange(path, from, to, first)) continue;+ if (ImageUtils::isAAImage(first))continue;+ if (askUser && !locals::checkConvertPolicy(path))continue;+ if (TSystem::doesExistFileOrLevel(dstPath)) {+ OverwriteDialog dialog;+ dstPath = dstPath.withName(dialog.execute(scene, dstPath, false));++ switch (dialog.getChoice()) {+ case OverwriteDialog::RENAME:+ case OverwriteDialog::KEEP_OLD:+ continue;+ case OverwriteDialog::OVERWRITE:+ TSystem::removeFileOrLevel(dstPath);+ TSystem::removeFileOrLevel(dstPath.withType("tpl"));+ break;+ default:+ continue;+ }+ }+ Convert2Tlv converter(path, TFilePath(), dstPath.getParentDir(), QString::fromStdWString(dstPath.getWideName())+ , from, to, false, TFilePath(), 20, 0, 50, false, true, scene->getCurrentCamera()->getDpi().x);+ std::string e;+ converter.init(e);+ if (!e.empty()) {+ DVGui::warning(QString("Failed to Convert\n%1").arg(path.getQString()));+ continue;+ }+ int count = converter.getFramesToConvertCount();+ if (count) {+ IoCmd::ConvertingPopup convertingPopup(+ TApp::instance()->getMainWindow(),+ path.getQString());+ convertingPopup.show();+ for (int i = 0; i < count; ++i)converter.convertNext(e);+ convertingPopup.hide();+ if (TSystem::doesExistFileOrLevel(dstPath))+ path = scene->codeFilePath(dstPath);+ }+ }+ }+}+//===========================================================================// If the scene will be saved in the different folder, check out the scene// cast.diff --git a/toonz/sources/toonz/iocommand.h b/toonz/sources/toonz/iocommand.hindex f4f69ef2b..4f566b96d 100644--- a/toonz/sources/toonz/iocommand.h+++ b/toonz/sources/toonz/iocommand.h@@ -85,6 +85,9 @@ struct LoadResourceArguments {{TFilePath m_path; //!< Path of the resource to be loaded.+ // reuse TFrameIds retrieved by FileBrowser+ std::vector<TFrameId> m_frameIdSet;+boost::optional<LevelOptions>m_options; //!< User-defined properties to be applied as a level.@@ -101,6 +104,11 @@ struct LoadResourceArguments {LOAD, //!< Resources are loaded from their original paths.};+ enum class RenamePolicy {+ ASK_USER,+ RENAME,+ NEVER,+ };public:std::vector<ResourceData>resourceDatas; //!< [\p In/Out] Data identifying a single resource.@@ -122,6 +130,7 @@ public:ImportPolicy importPolicy; //!< [\p In] Policy adopted for resources//! external to current scene.+ RenamePolicy renamePolicy;bool expose; //!< [\p In] Whether resources must be exposed in the//! xsheet.@@ -151,6 +160,8 @@ public:, col1(-1), importPolicy(static_cast<ImportPolicy>(Preferences::instance()->getDefaultImportPolicy()))+ , renamePolicy(static_cast<RenamePolicy>(+ Preferences::instance()->getDefaultRenamePolicy())), expose(Preferences::instance()->isAutoExposeEnabled()), xFrom(-1), xTo(-1)@@ -234,6 +245,9 @@ int loadResourceFolders(//! access and finalization.); //!< Loads the specified folders in current xsheet.//! \return The actually loaded levels count.++void renameResources(std::vector<LoadResourceArguments::ResourceData>& rds,+ bool askUser = true);bool exposeLevel(TXshSimpleLevel *sl, int row, int col, bool insert = false,bool overWrite = false);bool exposeLevel(TXshSimpleLevel *sl, int row, int col,diff --git a/toonz/sources/toonz/rasterizecommand.cpp b/toonz/sources/toonz/rasterizecommand.cppindex b0d39043b..876763ccf 100644--- a/toonz/sources/toonz/rasterizecommand.cpp+++ b/toonz/sources/toonz/rasterizecommand.cpp@@ -215,7 +215,7 @@ namespace {while (popup.isVisible() || popup.isConverting())QCoreApplication::processEvents(QEventLoop::AllEvents |QEventLoop::WaitForMoreEvents);- path = popup.getConvetedPath(path);+ path = popup.getConvertedPath(path);if (path.isEmpty()) return false;out->setPath(path);out->load();