Skip to content

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

C

Initial implementation to fix moving region spaces from vector undo.

Dennis Lamb2bdad3d6eca
diff --git a/toonz/sources/common/tvectorimage/tcomputeregions.cpp b/toonz/sources/common/tvectorimage/tcomputeregions.cpp
index 0c0acd302..8a9f12b8b 100644
--- a/toonz/sources/common/tvectorimage/tcomputeregions.cpp
+++ b/toonz/sources/common/tvectorimage/tcomputeregions.cpp
@@ -3371,7 +3371,7 @@ void TVectorImage::Imp::checkIntersections() {
#endif
//-----------------------------------------------------------------------------
-TStroke *TVectorImage::Imp::removeEndpoints(int strokeIndex) {
+TStroke *TVectorImage::Imp::removeEndpoints(int strokeIndex, double *offset=NULL) {
#ifdef _DEBUG
checkIntersections();
#endif
@@ -3399,6 +3399,10 @@ TStroke *TVectorImage::Imp::removeEndpoints(int strokeIndex) {
double offs = s->getLength(minW);
+ if (offset) {
+ *offset = offs;
+ }
+
TStroke s0, s1, final;
if (!areAlmostEqual(maxW, 1.0, 0.001)) {
@@ -3446,7 +3450,7 @@ TStroke *TVectorImage::Imp::removeEndpoints(int strokeIndex) {
//-----------------------------------------------------------------------------
-void TVectorImage::Imp::restoreEndpoints(int index, TStroke *oldStroke) {
+void TVectorImage::Imp::restoreEndpoints(int index, TStroke *oldStroke, double offs) {
#ifdef _DEBUG
checkIntersections();
#endif
@@ -3454,9 +3458,6 @@ void TVectorImage::Imp::restoreEndpoints(int index, TStroke *oldStroke) {
VIStroke *vs = m_strokes[index];
TStroke *s = vs->m_s;
- TPointD p = s->getPoint(0.0);
-
- double offs = oldStroke->getLength(oldStroke->getW(p));
vs->m_s = oldStroke;
diff --git a/toonz/sources/common/tvectorimage/tvectorimage.cpp b/toonz/sources/common/tvectorimage/tvectorimage.cpp
index 826182840..75c99042c 100644
--- a/toonz/sources/common/tvectorimage/tvectorimage.cpp
+++ b/toonz/sources/common/tvectorimage/tvectorimage.cpp
@@ -2025,12 +2025,12 @@ void TVectorImage::Imp::printStrokes(std::ofstream &os) {
//-----------------------------------------------------------------------------
-TStroke *TVectorImage::removeEndpoints(int strokeIndex) {
- return m_imp->removeEndpoints(strokeIndex);
+TStroke *TVectorImage::removeEndpoints(int strokeIndex, double *offset) {
+ return m_imp->removeEndpoints(strokeIndex, offset);
}
-void TVectorImage::restoreEndpoints(int index, TStroke *oldStroke) {
- m_imp->restoreEndpoints(index, oldStroke);
+void TVectorImage::restoreEndpoints(int index, TStroke *oldStroke, double offset) {
+ m_imp->restoreEndpoints(index, oldStroke, offset);
}
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/common/tvectorimage/tvectorimageP.h b/toonz/sources/common/tvectorimage/tvectorimageP.h
index 5a14c1508..8cbe0d7e1 100644
--- a/toonz/sources/common/tvectorimage/tvectorimageP.h
+++ b/toonz/sources/common/tvectorimage/tvectorimageP.h
@@ -186,8 +186,8 @@ public:
const std::vector<DoublePair> &sortedWRanges);
void moveStrokes(int fromIndex, int count, int moveBefore, bool regroup);
- TStroke *removeEndpoints(int strokeIndex);
- void restoreEndpoints(int index, TStroke *oldStroke);
+ TStroke *removeEndpoints(int strokeIndex, double *offset);
+ void restoreEndpoints(int index, TStroke *oldStroke, double offset);
int areDifferentGroup(UINT index1, bool isRegion1, UINT index2,
bool isRegion2) const;
diff --git a/toonz/sources/include/tools/strokeselection.h b/toonz/sources/include/tools/strokeselection.h
index bf50c683f..f34aea808 100644
--- a/toonz/sources/include/tools/strokeselection.h
+++ b/toonz/sources/include/tools/strokeselection.h
@@ -34,6 +34,16 @@ class TSceneHandle;
//=========================================================
+// Undo data structures
+
+struct UndoVectorData {
+ int index;
+ double offset;
+ TStroke *oldStroke;
+};
+
+//=========================================================
+
//****************************************************************************
// StrokeSelection declaration
//****************************************************************************
diff --git a/toonz/sources/include/tvectorimage.h b/toonz/sources/include/tvectorimage.h
index d7d6cd820..53416e506 100644
--- a/toonz/sources/include/tvectorimage.h
+++ b/toonz/sources/include/tvectorimage.h
@@ -361,12 +361,13 @@ get the stroke nearest at point
regions. only ending parts are removed.
If the entire stroke is not bounding any region, it is kept entitely.
it returns the original stroke (for undo)*/
- TStroke *removeEndpoints(int strokeIndex);
+
+ TStroke *removeEndpoints(int strokeIndex, double *offset=NULL);
/*! this method replaces the stroke at index with oldstroke. Oldstroke is
-supposed to contain
+ supposed to contain
existing stroke. this method is used for undoing removeEndpoints . */
- void restoreEndpoints(int index, TStroke *oldStroke);
+ void restoreEndpoints(int index, TStroke *oldStroke, double offset);
//! Set the autoclose tolerance to the specified value.
void setAutocloseTolerance(double val);
diff --git a/toonz/sources/tnztools/strokeselection.cpp b/toonz/sources/tnztools/strokeselection.cpp
index bebf83d08..10bdcb4e2 100644
--- a/toonz/sources/tnztools/strokeselection.cpp
+++ b/toonz/sources/tnztools/strokeselection.cpp
@@ -265,11 +265,11 @@ public:
class RemoveEndpointsUndo final : public TUndo {
TXshSimpleLevelP m_level;
TFrameId m_frameId;
- std::vector<std::pair<int, TStroke *>> m_strokes;
+ std::vector<UndoVectorData> m_strokes;
public:
RemoveEndpointsUndo(TXshSimpleLevel *level, const TFrameId &frameId,
- std::vector<std::pair<int, TStroke *>> strokes)
+ std::vector<UndoVectorData> strokes)
: m_level(level)
, m_frameId(frameId)
, m_strokes(strokes)
@@ -278,16 +278,16 @@ public:
~RemoveEndpointsUndo() {
int i;
- for (i = 0; i < (int)m_strokes.size(); i++) delete m_strokes[i].second;
+ for (i = 0; i < (int)m_strokes.size(); i++) delete m_strokes[i].oldStroke;
}
void undo() const override {
TVectorImageP vi = m_level->getFrame(m_frameId, true);
int i;
for (i = 0; i < (int)m_strokes.size(); i++) {
- TStroke *newS = new TStroke(*(m_strokes[i].second));
- newS->setId(m_strokes[i].second->getId());
- vi->restoreEndpoints(m_strokes[i].first, newS);
+ TStroke *newS = new TStroke(*(m_strokes[i].oldStroke));
+ newS->setId(m_strokes[i].oldStroke->getId());
+ vi->restoreEndpoints(m_strokes[i].index, newS, m_strokes[i].offset);
}
StrokeSelection *selection = dynamic_cast<StrokeSelection *>(
TTool::getApplication()->getCurrentSelection()->getSelection());
@@ -300,7 +300,7 @@ public:
int i;
TVectorImageP vi = m_level->getFrame(m_frameId, true);
for (i = 0; i < (int)m_strokes.size(); i++) {
- TStroke *s = vi->removeEndpoints(m_strokes[i].first);
+ TStroke *s = vi->removeEndpoints(m_strokes[i].index);
delete s;
// assert(s==m_strokes[i].second);
}
@@ -451,12 +451,19 @@ void StrokeSelection::removeEndpoints() {
return;
}
- std::vector<std::pair<int, TStroke *>> undoData;
+ std::vector<UndoVectorData> undoData;
m_vi->findRegions();
for (auto const &e : m_indexes) {
- TStroke *s = m_vi->removeEndpoints(e);
- if (s) undoData.push_back(std::pair<int, TStroke *>(e, s));
+ double offset;
+ TStroke *s = m_vi->removeEndpoints(e, &offset);
+ UndoVectorData undoStroke;
+
+ undoStroke.index = e;
+ undoStroke.oldStroke = s;
+ undoStroke.offset = offset;
+
+ if (s) undoData.push_back(undoStroke);
}
TTool *tool = TTool::getApplication()->getCurrentTool()->getTool();
TXshSimpleLevel *level =