Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Automatic Path Alias Priority by Scene Type (#6068)

Abel_You9a8b4ed6ff00
diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.h
index 6c7068c36..f57738cda 100644
--- a/toonz/sources/include/toonz/preferences.h
+++ b/toonz/sources/include/toonz/preferences.h
@@ -103,7 +103,8 @@ public:
enum PathAliasPriority {
ProjectFolderAliases = 0,
SceneFolderAlias,
- ProjectFolderOnly
+ ProjectFolderOnly,
+ AutoByScene
};
enum FunctionEditorToggle {
diff --git a/toonz/sources/include/toonz/toonzscene.h b/toonz/sources/include/toonz/toonzscene.h
index 40849bbe0..73e51f896 100644
--- a/toonz/sources/include/toonz/toonzscene.h
+++ b/toonz/sources/include/toonz/toonzscene.h
@@ -77,7 +77,7 @@ public:
bool isUntitled()
const; //!< Returns whether the scene path is empty, or the scene
//! is explicitly untitled. \sa Member function setUntitled().
-
+
TXsheet *getXsheet()
const; //!< Returns a pointer to the scene's \a current xsheet.
TXsheet *getTopXsheet() const; //!< Returns the \a topmost xsheet in the
@@ -261,9 +261,6 @@ If \b scene is in +scenes/name.tnz return name,
// if the path is codable with $scenefolder alias, replace it and return true
bool codeFilePathWithSceneFolder(TFilePath &path) const;
-
- // return false if the scene doesn't belong to any project
- bool isLonelyScene() const;
bool isLoading() { return m_isLoading; }
void setIsLoading(bool isLoading) { m_isLoading = isLoading; }
@@ -278,6 +275,9 @@ private:
TContentHistory *m_contentHistory;
bool m_isUntitled; //!< Whether the scene is untitled.
//! \sa The setUntitled() member function.
+ bool m_standAlone; //!< Whether the scene is stand-alone
+ //(not in a project folder with scenes.xml inside).
+
VersionNumber m_versionNumber; // last saved scene file version. Note that
// currently it is not match with OT version.
// TODO: Revise VersionNumber with OT version
diff --git a/toonz/sources/include/toonz/tproject.h b/toonz/sources/include/toonz/tproject.h
index f8a4e95fa..9377e26bc 100644
--- a/toonz/sources/include/toonz/tproject.h
+++ b/toonz/sources/include/toonz/tproject.h
@@ -150,7 +150,8 @@ public:
TFilePath getProjectPathByName(const TFilePath &projectName);
TFilePath getProjectPathByProjectFolder(const TFilePath &projectFolder);
- std::shared_ptr<TProject> loadSceneProject(const TFilePath &scenePath);
+ std::shared_ptr<TProject> loadSceneProject(const TFilePath &scenePath,
+ bool* sceneStandAlone = 0);
void getFolderNames(std::vector<std::string> &names);
void addListener(Listener *listener);
diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cpp
index 372db6269..af80a1443 100644
--- a/toonz/sources/toonz/iocommand.cpp
+++ b/toonz/sources/toonz/iocommand.cpp
@@ -1872,12 +1872,14 @@ bool IoCmd::loadScene(ToonzScene &scene, const TFilePath &scenePath,
bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
bool checkSaveOldScene) {
RenderingSuspender suspender;
-
+
+ // - Check if old Scene saved
if (checkSaveOldScene)
if (!saveSceneIfNeeded(QApplication::tr("Load Scene"))) return false;
+
+ // - Check if the scenePath is valid
assert(!path.isEmpty());
TFilePath scenePath = path;
- bool importScene = false;
bool isXdts = scenePath.getType() == "xdts";
if (scenePath.getType() == "") scenePath = scenePath.withType("tnz");
if (scenePath.getType() != "tnz" && !isXdts) {
@@ -1889,6 +1891,7 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
}
if (!TSystem::doesExistFileOrLevel(scenePath)) return false;
+ // - Check if a .tmp file exists
TFilePath scenePathTemp(scenePath.getWideString() +
QString(".tmp").toStdWString());
if (TSystem::doesExistFileOrLevel(scenePathTemp)) {
@@ -1908,6 +1911,9 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
TSystem::removeFileOrLevel(scenePathTemp);
}
+ // - Try find the project of the scene if scenes.xml exist
+ // if the .xml doesn't exist, load scene as standalone scene
+ // belongs to sandbox project
TProjectManager *pm = TProjectManager::instance();
auto sceneProject = pm->loadSceneProject(scenePath);
if (!sceneProject) {
@@ -1920,15 +1926,9 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
DVGui::warning(msg);
}
if (sceneProject && !sceneProject->isCurrent()) {
- QString currentProjectName = QString::fromStdWString(
- pm->getCurrentProject()->getName().getWideString());
QString sceneProjectName =
QString::fromStdWString(sceneProject->getName().getWideString());
- /*QString question = "The Scene '"
- + QString::fromStdWString(scenePath.getWideString())
-+ "' belongs to project '" + sceneProjectName + "'.\n"
-+ "What do you want to do?";*/
QString question =
QObject::tr(
"The Scene '%1' belongs to project '%2'.\nWhat do you want to do?")
@@ -1945,9 +1945,11 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
}
if (ret == 2)
pm->setCurrentProjectPath(sceneProject->getProjectPath());
- else
- importScene = true;
+ // else importScene = true;
+ // Import Scene Later because of difference of currentProject and sceneProject
}
+
+ // - Start to load scene
QApplication::setOverrideCursor(Qt::WaitCursor);
TApp *app = TApp::instance();
diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cpp
index 006210320..5b1e3a3fd 100644
--- a/toonz/sources/toonz/preferencespopup.cpp
+++ b/toonz/sources/toonz/preferencespopup.cpp
@@ -1434,7 +1434,9 @@ QList<ComboBoxItem> PreferencesPopup::getComboItemList(
{tr("Scene Folder Alias ($scenefolder)"),
Preferences::SceneFolderAlias},
{tr("Use Project Folder Aliases Only"),
- Preferences::ProjectFolderOnly}}},
+ Preferences::ProjectFolderOnly},
+ {tr("Automatic by Scene"),
+ Preferences::AutoByScene}}},
{linearUnits, // cameraUnits shares items with linearUnits
{{tr("cm"), "cm"},
{tr("mm"), "mm"},
@@ -1669,6 +1671,12 @@ QWidget* PreferencesPopup::createGeneralPage() {
"$scenefolder as well.");
pathAliasPriorityCB->setItemData(1, scenefolderTooltip, Qt::ToolTipRole);
pathAliasPriorityCB->setItemData(2, QString(" "), Qt::ToolTipRole);
+ QString autoBySceneToolTip =
+ tr("Automatically sets folder based on scene type:\n"
+ "Standalone -> $scenefolder\n"
+ "Project -> project folder aliases (+drawing...)");
+ pathAliasPriorityCB->setItemData(3, autoBySceneToolTip, Qt::ToolTipRole);
+
m_onEditedFuncMap.insert(autosaveEnabled,
&PreferencesPopup::onAutoSaveChanged);
@@ -1678,8 +1686,11 @@ QWidget* PreferencesPopup::createGeneralPage() {
&PreferencesPopup::onAutoSaveOptionsChanged);
m_onEditedFuncMap.insert(watchFileSystemEnabled,
&PreferencesPopup::onWatchFileSystemClicked);
+ m_onEditedFuncMap.insert(pathAliasPriority,
+ &PreferencesPopup::onPathAliasPriorityChanged);
bool ret = true;
+
ret = ret && connect(m_pref, SIGNAL(stopAutoSave()), this,
SLOT(onAutoSaveExternallyChanged()));
ret = ret && connect(m_pref, SIGNAL(startAutoSave()), this,
diff --git a/toonz/sources/toonzlib/toonzscene.cpp b/toonz/sources/toonzlib/toonzscene.cpp
index e56c4c43d..77aed63a9 100644
--- a/toonz/sources/toonzlib/toonzscene.cpp
+++ b/toonz/sources/toonzlib/toonzscene.cpp
@@ -328,7 +328,7 @@ std::shared_ptr<TProject> ToonzScene::getProject() const { return m_project; }
void ToonzScene::setScenePath(const TFilePath &fp, bool changeToTitled) {
m_scenePath = fp;
- if(changeToTitled)m_isUntitled = false;
+ if (changeToTitled) m_isUntitled = false;
}
//-----------------------------------------------------------------------------
@@ -385,14 +385,16 @@ int ToonzScene::loadFrameCount(const TFilePath &fp) {
void ToonzScene::loadNoResources(const TFilePath &fp) {
clear();
- TProjectManager *pm = TProjectManager::instance();
- auto sceneProject = pm->loadSceneProject(fp);
+ TProjectManager *pm = TProjectManager::instance();
+ bool sceneStandAlone = false;
+ auto sceneProject = pm->loadSceneProject(fp, &sceneStandAlone);
if (!sceneProject) return;
-
- setProject(sceneProject);
+ if (sceneStandAlone) m_standAlone = true;
loadTnzFile(fp);
getXsheet()->updateFrameCount();
+
+ setProject(sceneProject);
}
//-----------------------------------------------------------------------------
@@ -1275,7 +1277,6 @@ TFilePath ToonzScene::decodeFilePath(const TFilePath &path) const {
if (project) {
h = ::to_string(head.substr(1));
TFilePath f = project->getFolder(h);
- if (isLonelyScene()) return m_scenePath.getParentDir() + f + tail;
if (f != TFilePath()) s = f.getWideString();
}
}
@@ -1346,7 +1347,8 @@ TFilePath ToonzScene::codeFilePath(const TFilePath &path) const {
Preferences::PathAliasPriority priority =
Preferences::instance()->getPathAliasPriority();
- if (priority == Preferences::SceneFolderAlias &&
+ if ((priority == Preferences::SceneFolderAlias ||
+ (m_standAlone && priority == Preferences::AutoByScene)) &&
codeFilePathWithSceneFolder(fp)) {
return fp;
}
@@ -1380,11 +1382,6 @@ bool ToonzScene::codeFilePathWithSceneFolder(TFilePath &path) const {
return false;
}
-bool ToonzScene::isLonelyScene() const {
- TFilePath sceneFolderPath = getProject()->getFolder("scenes", true);
- return !sceneFolderPath.isAncestorOf(m_scenePath) && !isUntitled();
-}
-
//-----------------------------------------------------------------------------
TFilePath ToonzScene::getDefaultLevelPath(int levelType,
@@ -1413,14 +1410,13 @@ TFilePath ToonzScene::getDefaultLevelPath(int levelType,
levelPath = TFilePath(levelName + L"..png");
}
- // In case scene is loaded from outside
- if (!isUntitled() && Preferences::instance()->getPathAliasPriority() ==
- Preferences::SceneFolderAlias)
+ Preferences::PathAliasPriority priority =
+ Preferences::instance()->getPathAliasPriority();
+ if (!isUntitled() && (priority == Preferences::SceneFolderAlias ||
+ (m_standAlone && priority == Preferences::AutoByScene)))
return TFilePath("$scenefolder") + levelPath;
std::string folderName = getFolderName(levelType);
- if (!isUntitled() && isLonelyScene())
- return TFilePath("$scenefolder") + TFilePath(folderName) + levelPath;
if (project->getUseScenePath(folderName))
return TFilePath("+" + folderName) + getSavePath() + levelPath;
diff --git a/toonz/sources/toonzlib/tproject.cpp b/toonz/sources/toonzlib/tproject.cpp
index fab1bb376..660cb499a 100644
--- a/toonz/sources/toonzlib/tproject.cpp
+++ b/toonz/sources/toonzlib/tproject.cpp
@@ -1026,8 +1026,10 @@ std::shared_ptr<TProject> TProjectManager::getCurrentProject() {
Returns 0 if \b scenePath isn't a valid scene, or isn't saved in a valid
folder of a project root.
\note \b scenePath must be an absolute path.\n
- Creates a new TProject. The caller gets ownership.*/
-std::shared_ptr<TProject> TProjectManager::loadSceneProject(const TFilePath &scenePath) {
+ Creates a new TProject. The caller gets ownership.
+ Sets *sceneStandAlone to true if scenes.xml not found */
+std::shared_ptr<TProject> TProjectManager::loadSceneProject(const TFilePath &scenePath,
+ bool* sceneStandAlone) {
// cerca il file scenes.xml nella stessa directory della scena
// oppure in una
// directory superiore
@@ -1064,12 +1066,15 @@ std::shared_ptr<TProject> TProjectManager::loadSceneProject(const TFilePath &sce
TFilePath path = getProjectFile(projectPath);
projectPath = path;
-
} catch (...) {
+ throw TException("Error while reading scenes.xml");
}
if (projectPath == TFilePath()) return 0;
- } else
+ }
+ else {
+ if (sceneStandAlone) *sceneStandAlone = true;
projectPath = getSandboxProjectPath();
+ }
if (!TProject::isAProjectPath(projectPath)) {
// in Toonz 5.1 e precedenti era un project name
@@ -1082,7 +1087,6 @@ std::shared_ptr<TProject> TProjectManager::loadSceneProject(const TFilePath &sce
auto project = std::make_shared<TProject>();
project->load(projectPath);
-
return project;
}