OpenToonz - An open-source full-featured 2D animation creation software
C
Full subxsheet clone with independent levels
Ahl76572d59ac5fed
diff --git a/stuff/profiles/layouts/rooms/Default/menubar_template.xml b/stuff/profiles/layouts/rooms/Default/menubar_template.xmlindex f028afdff..f3e9b87ab 100644--- a/stuff/profiles/layouts/rooms/Default/menubar_template.xml+++ b/stuff/profiles/layouts/rooms/Default/menubar_template.xml@@ -164,6 +164,7 @@<command>MI_Collapse</command><command>MI_Resequence</command><command>MI_CloneChild</command>+ <command>MI_FullCloneChild</command><command>MI_ExplodeChild</command><command>MI_ToggleEditInPlace</command><separator/>diff --git a/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xml b/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xmlindex a71275ab5..3d509bec3 100644--- a/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xml+++ b/stuff/profiles/layouts/rooms/StudioGhibli/menubar_template.xml@@ -123,6 +123,7 @@<command>MI_Collapse</command><command>MI_Resequence</command><command>MI_CloneChild</command>+ <command>MI_FullCloneChild</command><command>MI_ExplodeChild</command><separator/><command>MI_ApplyMatchLines</command>diff --git a/stuff/profiles/layouts/rooms/StudioGhibli/room4_menubar.xml b/stuff/profiles/layouts/rooms/StudioGhibli/room4_menubar.xmlindex b268cecec..772ba1b0b 100644--- a/stuff/profiles/layouts/rooms/StudioGhibli/room4_menubar.xml+++ b/stuff/profiles/layouts/rooms/StudioGhibli/room4_menubar.xml@@ -23,6 +23,7 @@<command>MI_SaveSubxsheetAs</command><command>MI_LoadSubSceneFile</command><command>MI_CloneChild</command>+ <command>MI_FullCloneChild</command><command>MI_ExplodeChild</command><command>MI_ToggleEditInPlace</command></menu>diff --git a/toonz/sources/toonz/columncommand.cpp b/toonz/sources/toonz/columncommand.cppindex 2944c16c2..0d0a30f61 100644--- a/toonz/sources/toonz/columncommand.cpp+++ b/toonz/sources/toonz/columncommand.cpp@@ -31,7 +31,16 @@#include "toonz/txshzeraryfxcolumn.h"#include "toonz/txshlevelcolumn.h"#include "toonz/txshchildlevel.h"+#include "toonz/txshsimplelevel.h"+#include "toonz/txshpalettelevel.h"+#include "toonz/txshsoundlevel.h"+#include "toonz/txshlevel.h"#include "toonz/txshcell.h"+#include "toonz/txshleveltypes.h"+#include "toonz/levelset.h"+#include "toonz/hook.h"+#include "toonz/imagemanager.h"+#include "toonz/namebuilder.h"#include "toonz/childstack.h"#include "toonz/toonzscene.h"#include "toonz/tcamera.h"@@ -49,15 +58,25 @@// TnzCore includes#include "tstroke.h"#include "tundo.h"+#include "tpalette.h"+#include "tsystem.h"+#include "tfilepath.h"+#include "timage.h"+#include "tsound_io.h"#include "tools/toolhandle.h"// Qt includes#include <QApplication>#include <QClipboard>+#include <QCursor>#include <QSet>+#include <QStringList>+#include <map>#include <memory>+#include <set>+#include <vector>//*************************************************************************// Local Namespace stuff@@ -426,11 +445,149 @@ void resetColumns(//-----------------------------------------------------------------------------+std::wstring uniqueLevelName(ToonzScene *scene, const std::wstring &base) {+ std::unique_ptr<NameBuilder> nameBuilder(NameBuilder::getBuilder(base));+ for (;;) {+ const std::wstring name = nameBuilder->getNext();+ if (!scene->getLevelSet()->getLevel(name)) return name;+ }+}++//-----------------------------------------------------------------------------++TFilePath uniqueCodedPath(ToonzScene *scene, const TFilePath &srcPath,+ const std::wstring &levelName) {+ TFilePath decoded;+ if (srcPath.isEmpty())+ decoded = TFilePath(levelName);+ else {+ decoded = scene->decodeFilePath(srcPath);+ decoded = decoded.withName(levelName);+ }++ std::unique_ptr<NameBuilder> nameBuilder(+ NameBuilder::getBuilder(decoded.getWideName()));+ for (;;) {+ const std::wstring name = nameBuilder->getNext();+ TFilePath fp = decoded.withName(name);+ if (TSystem::doesExistFileOrLevel(fp)) continue;+ if (scene->getLevelSet()->getLevel(*scene, fp)) continue;+ return scene->codeFilePath(fp);+ }+}++//-----------------------------------------------------------------------------++// Formats that cannot be written (mp3, ogg...) are saved as wav+TFilePath uniqueSoundPath(ToonzScene *scene, const TFilePath &srcPath,+ const std::wstring &levelName) {+ TFilePath path = srcPath;+ if (!path.isEmpty()) {+ QStringList writableFormats;+ TSoundTrackWriter::getSupportedFormats(writableFormats);+ if (!writableFormats.contains(+ QString::fromStdString(path.getType()).toLower()))+ path = path.withType("wav");+ }+ return uniqueCodedPath(scene, path, levelName);+}++//-----------------------------------------------------------------------------++TXshSimpleLevel *cloneSimpleLevel(TXshSimpleLevel *srcSl) {+ if (!srcSl || srcSl->getPath().isUneditable()) return srcSl;++ ToonzScene *scene = srcSl->getScene();+ const int levelType = srcSl->getType();+ const std::wstring dstName =+ uniqueLevelName(scene, srcSl->getName() + L"_clone");++ TXshSimpleLevel *dstSl =+ scene->createNewLevel(levelType, dstName)->getSimpleLevel();+ if (!srcSl->getPath().isEmpty())+ dstSl->setPath(uniqueCodedPath(scene, srcSl->getPath(), dstSl->getName()));+ dstSl->clonePropertiesFrom(srcSl);+ *dstSl->getHookSet() = *srcSl->getHookSet();++ if (srcSl->getPalette() &&+ (levelType == TZP_XSHLEVEL || levelType == PLI_XSHLEVEL ||+ levelType == MESH_XSHLEVEL)) {+ dstSl->setPalette(srcSl->getPalette()->clone());+ dstSl->getPalette()->setDirtyFlag(true);+ }++ const std::vector<TFrameId> fids = srcSl->getFids();+ for (const TFrameId &fid : fids) {+ TImageP img = srcSl->getFullsampledFrame(fid, ImageManager::dontPutInCache);+ if (!img) continue;+ dstSl->setFrame(fid, img->cloneImage());+ }++ dstSl->setDirtyFlag(true);+ return dstSl;+}++//-----------------------------------------------------------------------------++TXshPaletteLevel *clonePaletteLevel(TXshPaletteLevel *srcPl) {+ if (!srcPl) return srcPl;++ ToonzScene *scene = srcPl->getScene();+ const std::wstring dstName =+ uniqueLevelName(scene, srcPl->getName() + L"_clone");+ TXshPaletteLevel *dstPl =+ scene->createNewLevel(PLT_XSHLEVEL, dstName)->getPaletteLevel();+ if (srcPl->getPalette()) {+ dstPl->setPalette(srcPl->getPalette()->clone());+ dstPl->getPalette()->setDirtyFlag(true);+ }+ dstPl->setPath(uniqueCodedPath(scene, srcPl->getPath(), dstName));+ return dstPl;+}++//-----------------------------------------------------------------------------++TXshSoundLevel *cloneSoundLevel(TXshSoundLevel *srcSl) {+ if (!srcSl) return srcSl;++ ToonzScene *scene = srcSl->getScene();+ const std::wstring dstName =+ uniqueLevelName(scene, srcSl->getName() + L"_clone");++ TXshSoundLevel *dstSl =+ srcSl->getSoundTrack() ? srcSl->clone() : new TXshSoundLevel();+ dstSl->setName(dstName);+ dstSl->setType(srcSl->getType());+ dstSl->setScene(scene);+ dstSl->setFrameRate(srcSl->getFrameRate());+ dstSl->computeValues();+ dstSl->setPath(uniqueSoundPath(scene, srcSl->getPath(), dstName));+ scene->getLevelSet()->insertLevel(dstSl);+ return dstSl;+}++//-----------------------------------------------------------------------------++TXshLevel *cloneUsedLevel(TXshLevel *srcLevel) {+ if (!srcLevel) return srcLevel;+ if (TXshSimpleLevel *sl = srcLevel->getSimpleLevel())+ return cloneSimpleLevel(sl);+ if (TXshPaletteLevel *pl = srcLevel->getPaletteLevel())+ return clonePaletteLevel(pl);+ if (TXshSoundLevel *snd = srcLevel->getSoundLevel())+ return cloneSoundLevel(snd);+ return srcLevel;+}++//-----------------------------------------------------------------------------+// Clones the TXshChildLevel, but NOT any further nested TXshChildLevel inside// it.TXshChildLevel *cloneChildLevel(TXshChildLevel *cl) {- TXshChildLevel *newLevel = new TXshChildLevel(cl->getName());- newLevel->setScene(cl->getScene());+ ToonzScene *scene = cl->getScene();+ const std::wstring name = uniqueLevelName(scene, cl->getName());+ TXshChildLevel *newLevel = new TXshChildLevel(name);+ newLevel->setScene(scene);TXsheet *childXsh = cl->getXsheet(), *newChildXsh = newLevel->getXsheet();@@ -441,62 +598,137 @@ TXshChildLevel *cloneChildLevel(TXshChildLevel *cl) {data->storeColumns(indices, childXsh, 0);data->storeColumnFxs(indices, childXsh, 0);std::list<int> restoredSplineIds;+ QMap<TStageObjectId, TStageObjectId> idTable;+ QMap<TFx *, TFx *> fxTable;data->restoreObjects(indices, restoredSplineIds, newChildXsh,- StageObjectsData::eDoClone);+ StageObjectsData::eDoClone, idTable, fxTable);delete data;- cloneNotColumnLinkedFxsAndOutputsFx(childXsh, newChildXsh);+ cloneNotColumnLinkedFxsAndOutputsFx(childXsh, newChildXsh, &fxTable);cloneXsheetTStageObjectTree(childXsh, newChildXsh);+ newChildXsh->getFxDag()->getXsheetFx()->getAttributes()->setDagNodePos(+ childXsh->getFxDag()->getXsheetFx()->getAttributes()->getDagNodePos());+ ExpressionReferenceManager::instance()->refreshXsheetRefInfo(newChildXsh);+ ExpressionReferenceManager::instance()->transferReference(+ childXsh, newChildXsh, idTable, fxTable);++ scene->getLevelSet()->insertLevel(newLevel);return newLevel;}//------------------------------------------------------------------------------void cloneSubXsheets(TXsheet *xsh) {- std::map<TXsheet *, TXshChildLevel *> visited;- std::set<TXsheet *> toVisit;+void remapNestedChildren(TXsheet *xsh,+ std::map<TXshChildLevel *, TXshChildLevel *> &childMap,+ std::vector<TXshLevelP> &inserted) {+ for (int i = 0; i < xsh->getColumnCount(); ++i) {+ TXshColumn *column = xsh->getColumn(i);+ if (!column) continue;+ TXshCellColumn *cc = column->getCellColumn();+ if (!cc) continue;++ int r0 = 0, r1 = -1;+ cc->getRange(r0, r1);+ if (cc->isEmpty() || r0 > r1) continue;++ for (int r = r0; r <= r1; ++r) {+ TXshCell cell = cc->getCell(r);+ if (cell.isEmpty() || !cell.m_level) continue;+ TXshChildLevel *srcChild = cell.m_level->getChildLevel();+ if (!srcChild) continue;++ TXshChildLevel *dstChild = 0;+ std::map<TXshChildLevel *, TXshChildLevel *>::iterator it =+ childMap.find(srcChild);+ if (it == childMap.end()) {+ dstChild = cloneChildLevel(srcChild);+ childMap[srcChild] = dstChild;+ inserted.push_back(dstChild);+ remapNestedChildren(dstChild->getXsheet(), childMap, inserted);+ } else+ dstChild = it->second;++ cell.m_level = dstChild;+ cc->setCell(r, cell);+ }+ }+}- toVisit.insert(xsh);+//------------------------------------------------------------------------------ while (!toVisit.empty()) {- xsh = *toVisit.begin();- toVisit.erase(xsh);+void collectXsheets(TXsheet *xsh, std::set<TXsheet *> &visited) {+ if (!visited.insert(xsh).second) return;- for (int i = 0; i < xsh->getColumnCount(); ++i) {- TXshColumn *column = xsh->getColumn(i);- if (!column) continue;+ for (int i = 0; i < xsh->getColumnCount(); ++i) {+ TXshColumn *column = xsh->getColumn(i);+ if (!column) continue;+ TXshCellColumn *cc = column->getCellColumn();+ if (!cc) continue;++ int r0 = 0, r1 = -1;+ cc->getRange(r0, r1);+ if (cc->isEmpty() || r0 > r1) continue;++ for (int r = r0; r <= r1; ++r) {+ const TXshCell cell = cc->getCell(r);+ if (cell.isEmpty() || !cell.m_level) continue;+ TXshChildLevel *child = cell.m_level->getChildLevel();+ if (child) collectXsheets(child->getXsheet(), visited);+ }+ }+}++//------------------------------------------------------------------------------ if (TXshCellColumn *cc = column->getCellColumn()) {- int r0 = 0, r1 = -1;- cc->getRange(r0, r1);- if (!cc->isEmpty() && r0 <= r1)- for (int r = r0; r <= r1; ++r) {- TXshCell cell = cc->getCell(r);- if (cell.m_level && cell.m_level->getChildLevel()) {- TXsheet *subxsh = cell.m_level->getChildLevel()->getXsheet();-- std::map<TXsheet *, TXshChildLevel *>::iterator it =- visited.find(subxsh);- if (it == visited.end()) {- it = visited- .insert(std::make_pair(- subxsh,- cloneChildLevel(cell.m_level->getChildLevel())))- .first;- toVisit.insert(subxsh);- }- assert(it != visited.end());-- cell.m_level = it->second;- cc->setCell(r, cell);- }- }+void remapAndCloneLevels(TXsheet *xsh,+ std::map<TXshLevel *, TXshLevelP> &levelMap,+ std::vector<TXshLevelP> &inserted) {+ for (int i = 0; i < xsh->getColumnCount(); ++i) {+ TXshColumn *column = xsh->getColumn(i);+ if (!column) continue;+ TXshCellColumn *cc = column->getCellColumn();+ if (!cc) continue;++ int r0 = 0, r1 = -1;+ cc->getRange(r0, r1);+ if (cc->isEmpty() || r0 > r1) continue;++ for (int r = r0; r <= r1; ++r) {+ TXshCell cell = cc->getCell(r);+ if (cell.isEmpty() || !cell.m_level) continue;+ if (cell.m_level->getChildLevel()) continue;++ TXshLevel *srcLevel = cell.m_level.getPointer();+ std::map<TXshLevel *, TXshLevelP>::iterator it = levelMap.find(srcLevel);+ if (it == levelMap.end()) {+ TXshLevel *dstLevel = cloneUsedLevel(srcLevel);+ levelMap[srcLevel] = dstLevel;+ if (dstLevel && dstLevel != srcLevel) inserted.push_back(dstLevel);+ it = levelMap.find(srcLevel);+ }++ if (it->second && it->second.getPointer() != srcLevel) {+ cell.m_level = it->second;+ cc->setCell(r, cell);}}}}+//-----------------------------------------------------------------------------++void fullCloneContents(TXsheet *clonedRoot, std::vector<TXshLevelP> &inserted) {+ std::map<TXshChildLevel *, TXshChildLevel *> childMap;+ remapNestedChildren(clonedRoot, childMap, inserted);++ std::set<TXsheet *> sheets;+ collectXsheets(clonedRoot, sheets);++ std::map<TXshLevel *, TXshLevelP> levelMap;+ for (TXsheet *xsh : sheets) remapAndCloneLevels(xsh, levelMap, inserted);+}+//=============================================================================// PasteColumnsUndo//-----------------------------------------------------------------------------@@ -1068,34 +1300,80 @@ void ColumnCmd::resequence(int index) {class CloneChildUndo final : public TUndo {TXshChildLevelP m_childLevel;int m_columnIndex;+ int m_r0;+ std::vector<TXshCell> m_cells;+ std::vector<TXshLevelP> m_clonedLevels;+ TStageObjectId m_parentId;+ bool m_fullClone;public:- CloneChildUndo(TXshChildLevel *childLevel, int columnIndex)- : m_childLevel(childLevel), m_columnIndex(columnIndex) {}+ CloneChildUndo(TXshChildLevel *childLevel, int columnIndex, int r0,+ const std::vector<TXshCell> &cells,+ const std::vector<TXshLevelP> &clonedLevels,+ TStageObjectId parentId, bool fullClone)+ : m_childLevel(childLevel)+ , m_columnIndex(columnIndex)+ , m_r0(r0)+ , m_cells(cells)+ , m_clonedLevels(clonedLevels)+ , m_parentId(parentId)+ , m_fullClone(fullClone) {}void undo() const override {- TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();+ TApp *app = TApp::instance();+ ToonzScene *scene = app->getCurrentScene()->getScene();+ TXsheet *xsh = app->getCurrentXsheet()->getXsheet();xsh->removeColumn(m_columnIndex);- TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();++ if (m_fullClone) {+ auto removeIfUnused = [scene](TXshLevel *level) {+ if (!level) return;+ if (!scene->getTopXsheet()->isLevelUsed(level))+ scene->getLevelSet()->removeLevel(level);+ };+ for (int i = (int)m_clonedLevels.size() - 1; i >= 0; --i)+ removeIfUnused(m_clonedLevels[i].getPointer());+ removeIfUnused(m_childLevel.getPointer());+ }++ app->getCurrentXsheet()->notifyXsheetChanged();+ if (m_fullClone) app->getCurrentScene()->notifyCastChange();}void redo() const override {- TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();+ TApp *app = TApp::instance();+ ToonzScene *scene = app->getCurrentScene()->getScene();+ TXsheet *xsh = app->getCurrentXsheet()->getXsheet();++ if (m_fullClone) {+ if (m_childLevel)+ scene->getLevelSet()->insertLevel(m_childLevel.getPointer());+ for (int i = 0; i < (int)m_clonedLevels.size(); ++i)+ scene->getLevelSet()->insertLevel(m_clonedLevels[i].getPointer());+ }+xsh->insertColumn(m_columnIndex);- int frameCount = m_childLevel->getXsheet()->getFrameCount();- if (frameCount < 1) frameCount = 1;- for (int r = 0; r < frameCount; r++)- xsh->setCell(r, m_columnIndex,- TXshCell(m_childLevel.getPointer(), TFrameId(r + 1)));- TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();+ for (int i = 0; i < (int)m_cells.size(); ++i) {+ if (m_cells[i].isEmpty()) continue;+ xsh->setCell(m_r0 + i, m_columnIndex, m_cells[i]);+ }+ if (m_parentId != TStageObjectId::NoneId)+ xsh->getStageObject(TStageObjectId::ColumnId(m_columnIndex))+ ->setParent(m_parentId);++ app->getCurrentXsheet()->notifyXsheetChanged();+ if (m_fullClone) app->getCurrentScene()->notifyCastChange();}int getSize() const override {- // bisognerebbe tener conto della dimensione del sottoxsheet- return sizeof(*this) + 100;+ return sizeof(*this) + (int)(m_cells.size() * sizeof(TXshCell) ++ m_clonedLevels.size() * sizeof(TXshLevelP));}QString getHistoryString() override {+ if (m_fullClone)+ return QObject::tr("Full Clone Sub-xsheet : Col%1")+ .arg(QString::number(m_columnIndex + 1));return QObject::tr("Clone Sub-xsheet : Col%1").arg(QString::number(m_columnIndex + 1));}@@ -1107,7 +1385,7 @@ public:// cloneChild//=============================================================================-void ColumnCmd::cloneChild(int index) {+void ColumnCmd::cloneChild(int index, bool fullClone) {if (!canResequence(index)) return;/*-- カラムを取得 --*/@@ -1131,6 +1409,8 @@ void ColumnCmd::cloneChild(int index) {/*- SubXsheetのXsheetを取得 -*/TXsheet *childXsh = childLevel->getXsheet();+ if (fullClone) QApplication::setOverrideCursor(Qt::WaitCursor);+// insert a new empty column/*- 隣に空きColumnをInsertしてCloneに備える -*/int newColumnIndex = index + 1;@@ -1162,6 +1442,9 @@ void ColumnCmd::cloneChild(int index) {クローンされた中にある子SubXsheetは、同じもので良いので、スキップする --*/// cloneSubXsheets(newChildXsh);+ std::vector<TXshLevelP> clonedLevels;+ if (fullClone) fullCloneContents(newChildXsh, clonedLevels);+/*-- XSheetノードのFxSchematicでのDagNodePosを再現FxやColumnノードの位置の再現は上のsetColumnで行っている--*/@@ -1177,26 +1460,36 @@ void ColumnCmd::cloneChild(int index) {/*-- TXshChildLevel作成時にsetCellした1つ目のセルを消去 --*/xsh->removeCells(0, newColumnIndex);/*-- CloneしたColumnのセル番号順を再現 --*/+ std::vector<TXshCell> clonedCells;for (int r = r0; r <= r1; r++) {- TXshCell cell = lcolumn->getCell(r);- if (cell.isEmpty()) continue;+ TXshCell srcCell = lcolumn->getCell(r);+ if (srcCell.isEmpty()) {+ clonedCells.push_back(TXshCell());+ continue;+ }- cell.m_level = newChildLevel;- xsh->setCell(r, newColumnIndex, cell);+ srcCell.m_level = newChildLevel;+ xsh->setCell(r, newColumnIndex, srcCell);+ clonedCells.push_back(srcCell);}TStageObjectId currentObjectId =TApp::instance()->getCurrentObject()->getObjectId();+ TStageObjectId parentId = xsh->getStageObjectParent(currentObjectId);xsh->getStageObject(TStageObjectId::ColumnId(newColumnIndex))- ->setParent(xsh->getStageObjectParent(currentObjectId));+ ->setParent(parentId);xsh->updateFrameCount();- TUndoManager::manager()->add(- new CloneChildUndo(newChildLevel, newColumnIndex));+ TUndoManager::manager()->add(new CloneChildUndo(newChildLevel, newColumnIndex,+ r0, clonedCells, clonedLevels,+ parentId, fullClone));// notify changesTApp::instance()->getCurrentScene()->setDirtyFlag(true);TApp::instance()->getCurrentXsheet()->notifyXsheetChanged();+ if (fullClone) TApp::instance()->getCurrentScene()->notifyCastChange();++ if (fullClone) QApplication::restoreOverrideCursor();}//=============================================================================diff --git a/toonz/sources/toonz/columncommand.h b/toonz/sources/toonz/columncommand.hindex 1526067fc..f99eb4224 100644--- a/toonz/sources/toonz/columncommand.h+++ b/toonz/sources/toonz/columncommand.h@@ -33,7 +33,7 @@ void copyColumn(int dstIndex, int srcIndex);void resequence(int index);bool canResequence(int index);-void cloneChild(int index);+void cloneChild(int index, bool fullClone = false);void clearCells(int index);//! Adds an undo object for converting layer to vector.diff --git a/toonz/sources/toonz/columnselection.cpp b/toonz/sources/toonz/columnselection.cppindex 40973571d..0b8ee11c4 100644--- a/toonz/sources/toonz/columnselection.cpp+++ b/toonz/sources/toonz/columnselection.cpp@@ -54,6 +54,7 @@ void TColumnSelection::enableCommands() {enableCommand(this, MI_ExplodeChild, &TColumnSelection::explodeChild);enableCommand(this, MI_Resequence, &TColumnSelection::resequence);enableCommand(this, MI_CloneChild, &TColumnSelection::cloneChild);+ enableCommand(this, MI_FullCloneChild, &TColumnSelection::fullCloneChild);enableCommand(this, MI_FoldColumns, &TColumnSelection::hideColumns);enableCommand(this, MI_Reframe1, &TColumnSelection::reframe1Cells);enableCommand(this, MI_Reframe2, &TColumnSelection::reframe2Cells);@@ -306,6 +307,12 @@ void TColumnSelection::cloneChild() {//-----------------------------------------------------------------------------+void TColumnSelection::fullCloneChild() {+ if (m_indices.size() == 1) ColumnCmd::cloneChild(*m_indices.begin(), true);+}++//-----------------------------------------------------------------------------+void TColumnSelection::hideColumns() {TApp* app = TApp::instance();for (auto o : Orientations::all()) {diff --git a/toonz/sources/toonz/columnselection.h b/toonz/sources/toonz/columnselection.hindex 865f4eaa1..896a957df 100644--- a/toonz/sources/toonz/columnselection.h+++ b/toonz/sources/toonz/columnselection.h@@ -45,6 +45,7 @@ public:void explodeChild();void resequence();void cloneChild();+ void fullCloneChild();void hideColumns();diff --git a/toonz/sources/toonz/icons/dark/actions/16x16/sub_full_clone.svg b/toonz/sources/toonz/icons/dark/actions/16x16/sub_full_clone.svgnew file mode 100644index 000000000..a4e6cddf6--- /dev/null+++ b/toonz/sources/toonz/icons/dark/actions/16x16/sub_full_clone.svg@@ -0,0 +1,14 @@+<?xml version="1.0" encoding="UTF-8" standalone="no"?>+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">+<svg width="100%" height="100%" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">+ <g id="sub_full_clone">+ <rect id="bg" x="0" y="0" width="16" height="16" style="fill:#878787;fill-opacity:0;"/>+ <rect x="0.5" y="0.5" width="15" height="15" style="fill:none;stroke:#000000;stroke-width:1.1px;stroke-opacity:0.85;"/>+ <g transform="translate(8,8) scale(0.8) translate(-8,-8)">+ <path d="M7,10l-6,0l0,1.001l6,-0l0,-1.001Zm-0,-3l-6,0l0,1.001l6,-0.001c0,-0.417 -0,-1 -0,-1Z" style="fill-opacity:0.5;"/>+ <path d="M3,4l4,0l0,10l-7,0l0,-7l3,0.001l0,-3.001Zm0,9l-2,0l0,-5l2,0l0,5Zm1,0l0,-8l3,0l0,8l-3,0Z"/>+ <path d="M7,1l8,0l0,14l-8,0l0,-14Zm3,6l-2,0l0,2l2,0l0,2l2,0l0,-2l2,0l0,-2l-2,0l0,-2l-2,0l0,2Z"/>+ </g>+ </g>+</svg>+\ No newline at end of filediff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cppindex cccd88c96..a0b938568 100644--- a/toonz/sources/toonz/mainwindow.cpp+++ b/toonz/sources/toonz/mainwindow.cpp@@ -2513,6 +2513,8 @@ void MainWindow::defineActions() {"resequence");createMenuXsheetAction(MI_CloneChild, QT_TR_NOOP("Clone Sub-Xsheet"), "","sub_clone");+ createMenuXsheetAction(MI_FullCloneChild, QT_TR_NOOP("Full Clone Sub-Xsheet"),+ "", "sub_full_clone");createMenuXsheetAction(MI_ApplyMatchLines,QT_TR_NOOP("&Apply Match Lines..."), "","apply_match_lines");diff --git a/toonz/sources/toonz/menubar.cpp b/toonz/sources/toonz/menubar.cppindex e3e41ed7c..73f2b7d21 100644--- a/toonz/sources/toonz/menubar.cpp+++ b/toonz/sources/toonz/menubar.cpp@@ -996,6 +996,7 @@ QMenuBar *StackedMenuBar::createXsheetMenuBar() {addMenuItem(subxsheetMenu, MI_SaveSubxsheetAs);addMenuItem(subxsheetMenu, MI_LoadSubSceneFile);addMenuItem(subxsheetMenu, MI_CloneChild);+ addMenuItem(subxsheetMenu, MI_FullCloneChild);addMenuItem(subxsheetMenu, MI_ExplodeChild);//----Levels Menu@@ -1420,6 +1421,7 @@ QMenuBar *StackedMenuBar::createFullMenuBar() {addMenuItem(xsheetMenu, MI_Collapse);addMenuItem(xsheetMenu, MI_Resequence);addMenuItem(xsheetMenu, MI_CloneChild);+ addMenuItem(xsheetMenu, MI_FullCloneChild);addMenuItem(xsheetMenu, MI_ExplodeChild);addMenuItem(xsheetMenu, MI_ToggleEditInPlace);xsheetMenu->addSeparator();diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.hindex 0c8eb006a..ebec470f1 100644--- a/toonz/sources/toonz/menubarcommandids.h+++ b/toonz/sources/toonz/menubarcommandids.h@@ -130,6 +130,7 @@#define MI_SaveSubxsheetAs "MI_SaveSubxsheetAs"#define MI_Resequence "MI_Resequence"#define MI_CloneChild "MI_CloneChild"+#define MI_FullCloneChild "MI_FullCloneChild"#define MI_ApplyMatchLines "MI_ApplyMatchLines"#define MI_MergeCmapped "MI_MergeCmapped"#define MI_MergeColumns "MI_MergeColumns"diff --git a/toonz/sources/toonz/toonz.qrc b/toonz/sources/toonz/toonz.qrcindex ca86fc1e0..0858720ac 100644--- a/toonz/sources/toonz/toonz.qrc+++ b/toonz/sources/toonz/toonz.qrc@@ -355,6 +355,7 @@<file>icons/dark/actions/16x16/fold_column.svg</file><file>icons/dark/actions/16x16/sub_edit_in_place.svg</file><file>icons/dark/actions/16x16/sub_clone.svg</file>+ <file>icons/dark/actions/16x16/sub_full_clone.svg</file><file>icons/dark/actions/16x16/duplicate.svg</file><file>icons/dark/actions/20x20/onionskin_toggle.svg</file><file>icons/dark/actions/16x16/insert_frame.svg</file>diff --git a/toonz/sources/toonz/xshcolumnviewer.cpp b/toonz/sources/toonz/xshcolumnviewer.cppindex 9a278a639..823a15c72 100644--- a/toonz/sources/toonz/xshcolumnviewer.cpp+++ b/toonz/sources/toonz/xshcolumnviewer.cpp@@ -3049,6 +3049,7 @@ void ColumnArea::contextMenuEvent(QContextMenuEvent *event) {if (cell.m_level && cell.m_level->getChildLevel()) {menu.addAction(cmdManager->getAction(MI_Resequence));menu.addAction(cmdManager->getAction(MI_CloneChild));+ menu.addAction(cmdManager->getAction(MI_FullCloneChild));menu.addAction(cmdManager->getAction(MI_ExplodeChild));}menu.addSeparator();diff --git a/toonz/sources/toonzlib/txshpalettelevel.cpp b/toonz/sources/toonzlib/txshpalettelevel.cppindex 13da70f8c..6064fb444 100644--- a/toonz/sources/toonzlib/txshpalettelevel.cpp+++ b/toonz/sources/toonzlib/txshpalettelevel.cpp@@ -100,15 +100,28 @@ void TXshPaletteLevel::load() {void TXshPaletteLevel::save() {TFilePath path = getScene()->decodeFilePath(m_path);- if (TSystem::doesExistFileOrLevel(path) && m_palette) {+ if (!m_palette) return;+ const bool exists = TSystem::doesExistFileOrLevel(path);+ // A new palette (e.g. a clone) has no file yet: create it when modified+ if (!exists && !m_palette->getDirtyFlag()) return;+ if (exists) {TFileStatus fs(path);if (!fs.isWritable()) {throw TSystemException(path, "The palette cannot be saved: it is a read only palette.");}- TOStream os(path);- os << m_palette;}+ TOStream os(path);+ if (!os) {+ throw TSystemException(+ path, "The palette cannot be saved: the file cannot be created.");+ }+ os << m_palette;+ if (!os.checkStatus()) {+ throw TSystemException(+ path, "The palette cannot be saved: the file cannot be written.");+ }+ m_palette->setDirtyFlag(false);}//-----------------------------------------------------------------------------