From 4e48381d6b997dcd6c675ba94302ae861181cca8 Mon Sep 17 00:00:00 2001 From: pojienie Date: Jul 08 2020 11:06:04 +0000 Subject: fix undo data when pasting in group --- diff --git a/toonz/sources/common/tvectorimage/tvectorimage.cpp b/toonz/sources/common/tvectorimage/tvectorimage.cpp index ab7fd8a..1bd786b 100644 --- a/toonz/sources/common/tvectorimage/tvectorimage.cpp +++ b/toonz/sources/common/tvectorimage/tvectorimage.cpp @@ -1034,8 +1034,8 @@ bool TVectorImage::Imp::areWholeGroups(const std::vector &indexes) const { if (!m_strokes[indexes[i]]->m_groupId.isGrouped()) return false; for (j = 0; j < m_strokes.size(); j++) { int ret = areDifferentGroup(indexes[i], false, j, false); - if (ret == -1 || - (ret >= 1 && find(indexes.begin(), indexes.end(), j) == indexes.end())) + if (ret == -1 || (ret >= 1 && find(indexes.begin(), indexes.end(), j) == + indexes.end())) return false; } } @@ -1219,8 +1219,8 @@ VIStroke::VIStroke(const VIStroke &s, bool sameId) //----------------------------------------------------------------------------- -void TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, - bool sameStrokeId) { +int TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, + bool sameStrokeId) { QMutexLocker sl(m_imp->m_mutex); #ifdef _DEBUG @@ -1243,16 +1243,16 @@ void TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, // mettere comunque un test qui if (srcPlt) mergePalette(tarPlt, styleTable, srcPlt, usedStyles); - mergeImage(img, affine, styleTable, sameStrokeId); + return mergeImage(img, affine, styleTable, sameStrokeId); } //----------------------------------------------------------------------------- -void TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, - const std::map &styleTable, - bool sameStrokeId) { +int TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, + const std::map &styleTable, + bool sameStrokeId) { int imageSize = img->getStrokeCount(); - if (imageSize == 0) return; + if (imageSize == 0) return 0; QMutexLocker sl(m_imp->m_mutex); m_imp->m_computedAlmostOnce |= img->m_imp->m_computedAlmostOnce; @@ -1282,7 +1282,7 @@ void TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, } else { img->m_imp->m_strokes[i]->m_groupId = TGroupId(groupId, img->m_imp->m_strokes[i]->m_groupId); - } + } } } } @@ -1351,6 +1351,8 @@ void TVectorImage::mergeImage(const TVectorImageP &img, const TAffine &affine, #ifdef _DEBUG checkIntersections(); #endif + + return insertAt; } //----------------------------------------------------------------------------- @@ -2908,7 +2910,7 @@ void TVectorImage::Imp::regroupGhosts(std::vector &changedStrokes) { ((currGroupId.isGrouped(false) != 0 && m_strokes[i]->m_groupId == currGroupId) || (currGroupId.isGrouped(true) != 0 && - m_strokes[i]->m_groupId.isGrouped(true) != 0))) { + m_strokes[i]->m_groupId.isGrouped(true) != 0))) { if (m_strokes[i]->m_groupId != currGroupId) { m_strokes[i]->m_groupId = currGroupId; changedStrokes.push_back(i); diff --git a/toonz/sources/include/tvectorimage.h b/toonz/sources/include/tvectorimage.h index 49b211c..cb4c1c0 100644 --- a/toonz/sources/include/tvectorimage.h +++ b/toonz/sources/include/tvectorimage.h @@ -82,7 +82,7 @@ public: void validateRegions(bool state = false); //! Get valid regions flags /*! Call validateRegions() after region/stroke changes -*/ + */ bool areValidRegions(); //! Return a clone of image @@ -306,7 +306,7 @@ get the stroke nearest at point /*! if enabled, region edges are joined together when possible. for flash * render, should be disabled! -*/ + */ void enableMinimizeEdges(bool enabled); /*! Creates a new Image using the selected strokes. If removeFlag==true then removes selected strokes @@ -316,12 +316,12 @@ get the stroke nearest at point TVectorImageP splitSelected(bool removeFlag); //! Merge the image with the \b img. - void mergeImage(const TVectorImageP &img, const TAffine &affine, - bool sameStrokeId = true); + int mergeImage(const TVectorImageP &img, const TAffine &affine, + bool sameStrokeId = true); - void mergeImage(const TVectorImageP &img, const TAffine &affine, - const std::map &styleTable, - bool sameStrokeId = true); + int mergeImage(const TVectorImageP &img, const TAffine &affine, + const std::map &styleTable, + bool sameStrokeId = true); //! Merge the image with the vector of image \b images. void mergeImage(const std::vector &images); diff --git a/toonz/sources/toonzqt/strokesdata.cpp b/toonz/sources/toonzqt/strokesdata.cpp index 4fbd795..4e2577c 100644 --- a/toonz/sources/toonzqt/strokesdata.cpp +++ b/toonz/sources/toonzqt/strokesdata.cpp @@ -111,10 +111,15 @@ void StrokesData::getImage(TVectorImageP image, std::set &indices, TAffine offset = findOffset(srcImg, image); UINT oldImageSize = image->getStrokeCount(); - image->mergeImage(srcImg, offset, false); + int insertAt = image->mergeImage(srcImg, offset, false); UINT newImageSize = image->getStrokeCount(); indices.clear(); - for (UINT sI = oldImageSize; sI < newImageSize; sI++) indices.insert(sI); + + if (insertAt == 0) + for (UINT sI = oldImageSize; sI < newImageSize; sI++) indices.insert(sI); + else + for (UINT sI = oldImageSize; sI < newImageSize; sI++) + indices.insert(sI - oldImageSize + insertAt); } else { std::vector indicesToInsert(indices.begin(), indices.end()); if (indicesToInsert.empty()) return;