OpenToonz - An open-source full-featured 2D animation creation software
C
Support Exporting Lonely Scene
Abel You2cc2723ddd16
diff --git a/toonz/sources/toonz/exportscenepopup.cpp b/toonz/sources/toonz/exportscenepopup.cppindex b85c0dfed..b5305c655 100644--- a/toonz/sources/toonz/exportscenepopup.cpp+++ b/toonz/sources/toonz/exportscenepopup.cpp@@ -13,7 +13,10 @@// TnzLib includes#include "toonz/tproject.h"#include "toonz/toonzscene.h"+#include "toonz/levelset.h"#include "toonz/sceneresources.h"+#include "toonz/txshlevel.h"+#include "toonz/txshsimplelevel.h"// TnzCore includes#include "tsystem.h"@@ -30,6 +33,8 @@#include <QMainWindow>#include <QStandardPaths>+#include <vector>+using namespace DVGui;TFilePath getStdDocumentsPath() {@@ -42,8 +47,7 @@ TFilePath getStdDocumentsPath() {namespace {//-------------------------------------------------------------------------TFilePath importScene(TFilePath scenePath) {- ToonzScene scene;+TFilePath loadSceneToProject(TFilePath scenePath, ToonzScene &scene) {bool ret;try {ret = IoCmd::loadScene(scene, scenePath, true);@@ -68,7 +72,6 @@ TFilePath importScene(TFilePath scenePath) {}TFilePath path = scene.getScenePath();- scene.save(scene.getScenePath());DvDirModel::instance()->refreshFolder(TProjectManager::instance()->getCurrentProjectPath().getParentDir());return path;@@ -76,20 +79,29 @@ TFilePath importScene(TFilePath scenePath) {//-------------------------------------------------------------------------int collectAssets(TFilePath scenePath) {- ToonzScene scene;- scene.load(scenePath);+int collectAssets(ToonzScene &scene) {ResourceCollector collector(&scene);SceneResources resources(&scene, scene.getXsheet());resources.accept(&collector);int count = collector.getCollectedResourceCount();- if (count > 0) {- scene.save(scenePath);- }return count;}//------------------------------------------------------------------------++void decodeLevelsPath(ToonzScene& scene) {+ std::vector<TXshLevel*> levels;+ scene.getLevelSet()->listLevels(levels);+ for (auto level : levels) {+ TXshSimpleLevel *sl = level->getSimpleLevel();+ if (!sl)continue;+ TFilePath orinPath = sl->getPath();+ if (!orinPath.isAbsolute()){+ TFilePath absolutePath = scene.decodeFilePath(orinPath);+ sl->setPath(absolutePath);+ }+ }+}} // namespace//------------------------------------------------------------------------@@ -516,7 +528,7 @@ void ExportSceneTreeView::focusInEvent(QFocusEvent *event) {ExportScenePopup::ExportScenePopup(std::vector<TFilePath> scenes): Dialog(TApp::instance()->getMainWindow(), true, false, "ExportScene"), m_scenes(scenes)- , m_createNewProject(false) {+ , m_mode(0) {setWindowTitle(tr("Export Scene"));bool ret = true;@@ -567,21 +579,42 @@ ExportScenePopup::ExportScenePopup(std::vector<TFilePath> scenes)newProjectLayout->setColumnStretch(1, 5);newProjectLayout->addWidget(m_newProjectName, 1, 1, 1, 1, Qt::AlignLeft);- m_pathFieldLabel = new QLabel(tr("Create In:"), this);+ m_newProPathFieldLabel = new QLabel(tr("Create In:"), this);m_projectLocationFld =new DVGui::FileField(this, getStdDocumentsPath().getQString());ret = ret && connect(m_projectLocationFld->getField(), SIGNAL(focusIn()),this, SLOT(onProjectNameFocusIn()));- newProjectLayout->addWidget(m_pathFieldLabel, 2, 0,+ newProjectLayout->addWidget(m_newProPathFieldLabel, 2, 0,Qt::AlignRight | Qt::AlignVCenter);newProjectLayout->addWidget(m_projectLocationFld, 2, 1);newProjectWidget->setLayout(newProjectLayout);layout->addWidget(newProjectWidget);+ // Export as Lonely Scene+ QWidget* lonelyProjectWidget = new QWidget(this);+ QGridLayout* lonelyProjectLayout = new QGridLayout(lonelyProjectWidget);++ m_lonelyModeButton =+ new QRadioButton(tr("Export as Standalone Scene"), lonelyProjectWidget);+ group->addButton(m_lonelyModeButton, 2);+ lonelyProjectLayout->addWidget(m_lonelyModeButton, 0, 0, 1, 2);++ m_lonelyModePathLabel = new QLabel(tr("Export To:"), lonelyProjectWidget);+ lonelyProjectLayout->addWidget(m_lonelyModePathLabel, 1, 0, Qt::AlignRight | Qt::AlignVCenter);++ m_lonelyModePathFld =+ new DVGui::FileField(lonelyProjectWidget, getStdDocumentsPath().getQString());+ ret = ret && connect(m_lonelyModePathFld->getField(), SIGNAL(focusIn()),+ this, SLOT(onLonelyModeFocusIn()));+ lonelyProjectLayout->addWidget(m_lonelyModePathFld, 1, 1);++ lonelyProjectWidget->setLayout(lonelyProjectLayout);+ layout->addWidget(lonelyProjectWidget);+ret = ret &&- connect(group, SIGNAL(buttonClicked(int)), this, SLOT(switchMode(int)));+ connect(group, SIGNAL(buttonClicked(int)), this, SLOT(switchMode(int)));addLayout(layout, false);@@ -595,23 +628,17 @@ ExportScenePopup::ExportScenePopup(std::vector<TFilePath> scenes)switchMode(0);// updateCommandLabel();-++ adjustSize();assert(ret);}//-----------------------------------------------------------------------------void ExportScenePopup::switchMode(int id) {- if (id == 0) // choose Existing Project- {- m_createNewProject = false;+ assert(id < 3);+ m_mode = id;// m_projectTreeView->setEnabled(true);- } else // create new project- {- assert(id == 1);- m_createNewProject = true;- // m_projectTreeView->setEnabled(false);- }}//-----------------------------------------------------------------------------@@ -628,6 +655,12 @@ void ExportScenePopup::onProjectNameFocusIn() {switchMode(1);}+void ExportScenePopup::onLonelyModeFocusIn()+{+ m_lonelyModeButton->setChecked(true);+ switchMode(2);+}+//-----------------------------------------------------------------------------void ExportScenePopup::onExport() {@@ -635,40 +668,56 @@ void ExportScenePopup::onExport() {TProjectManager *pm = TProjectManager::instance();TFilePath oldProjectPath = pm->getCurrentProjectPath();TFilePath projectPath;- if (!m_createNewProject) {- DvDirModelFileFolderNode *node =- (DvDirModelFileFolderNode *)m_projectTreeView->getCurrentNode();- if (!node || !pm->isProject(node->getPath())) {- QApplication::restoreOverrideCursor();- DVGui::warning(tr("The folder you selected is not a project."));- return;- }- projectPath = pm->projectFolderToProjectPath(node->getPath());- assert(projectPath != TFilePath());- } else // Create project- {- projectPath = createNewProject();- if (projectPath == TFilePath()) {- QApplication::restoreOverrideCursor();- return;- }+ if (m_mode == 0) {// Export to Existing Project+ DvDirModelFileFolderNode* node =+ (DvDirModelFileFolderNode*)m_projectTreeView->getCurrentNode();+ if (!node || node->getNodeType() == "Root" || !pm->isProject(node->getPath())) {+ QApplication::restoreOverrideCursor();+ DVGui::warning(tr("The folder you selected is not a project."));+ return;+ }+ projectPath = pm->projectFolderToProjectPath(node->getPath());+ assert(projectPath != TFilePath());+ }+ else if (m_mode == 1) {// Create New Project+ projectPath = createNewProject();+ if (projectPath == TFilePath()) {+ QApplication::restoreOverrideCursor();+ return;+ }}+ else // Export as Lonely Scene+ projectPath = TFilePath(); pm->getSandboxProjectPath();+pm->setCurrentProjectPath(projectPath);- std::vector<TFilePath> newScenes;int i;+ QString label("Exporting Scenes");+ QString cancel("Cancel");+ ProgressDialog progressBar(label, cancel, 0, m_scenes.size(), this);+ progressBar.show();for (i = 0; i < m_scenes.size(); i++) {- TFilePath newScenePath = importScene(m_scenes[i]);- if (newScenePath == TFilePath()) continue;- newScenes.push_back(newScenePath);+ ToonzScene scene;+ TFilePath newScenePath = loadSceneToProject(m_scenes[i], scene);+ if (m_mode == 2)decodeLevelsPath(scene);+ if (newScenePath == TFilePath()) {+ DVGui::warning(tr("There was an error exporting the scene."));+ continue;+ };+ progressBar.setValue(i);+ label = QString("Exporting ") ++ QString::fromStdString(newScenePath.getName());+ if (m_mode == 2) {+ QString path = m_lonelyModePathFld->getPath();+ TFilePath newSceneFolder = TFilePath(path) + newScenePath.getName();+ TSystem::mkDir(newSceneFolder);+ newScenePath = newSceneFolder + m_scenes[i].withoutParentDir();+ scene.setScenePath(newScenePath);+ };+ int count = collectAssets(scene);+ scene.save(newScenePath);}pm->setCurrentProjectPath(oldProjectPath);- if (newScenes.empty()) {- QApplication::restoreOverrideCursor();- DVGui::warning(tr("There was an error exporting the scene."));- return;- }- for (i = 0; i < newScenes.size(); i++) collectAssets(newScenes[i]);QApplication::restoreOverrideCursor();accept();diff --git a/toonz/sources/toonz/exportscenepopup.h b/toonz/sources/toonz/exportscenepopup.hindex 580efd2d5..466d615c4 100644--- a/toonz/sources/toonz/exportscenepopup.h+++ b/toonz/sources/toonz/exportscenepopup.h@@ -164,10 +164,15 @@ class ExportScenePopup final : public DVGui::Dialog {QRadioButton *m_newProjectButton;QRadioButton *m_chooseProjectButton;- QLabel *m_pathFieldLabel;+ QLabel *m_newProPathFieldLabel;DVGui::FileField *m_projectLocationFld;++ // 0,1,2+ UINT m_mode;- bool m_createNewProject;+ QRadioButton *m_lonelyModeButton;+ QLabel *m_lonelyModePathLabel;+ DVGui::FileField *m_lonelyModePathFld;public:ExportScenePopup(std::vector<TFilePath> scenes);@@ -181,6 +186,7 @@ protected slots:void switchMode(int id);void onProjectTreeViweFocusIn();void onProjectNameFocusIn();+ void onLonelyModeFocusIn();void onExport();protected: