Skip to content

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

C

Fix crash on exploding sub-xsheet (#305)

shun-iwasawa0a9e80ffa1d2
diff --git a/toonz/sources/toonz/subscenecommand.cpp b/toonz/sources/toonz/subscenecommand.cpp
index cd92d0765..9527fc038 100644
--- a/toonz/sources/toonz/subscenecommand.cpp
+++ b/toonz/sources/toonz/subscenecommand.cpp
@@ -520,7 +520,7 @@ TFx *explodeFxSubTree(TFx *innerFx, QMap<TFx *, QPair<TFx *, int>> &fxs, FxDag *
overFx->getInputPort(1)->setFx(root);
outerDag->removeFromXsheet(fx);
TPointD pos = root->getAttributes()->getDagNodePos();
- overFx->getAttributes()->setDagNodePos(TPointD(pos.x + 150, pos.y));
+ overFx->getAttributes()->setDagNodePos((pos == TConst::nowhere) ? TConst::nowhere : TPointD(pos.x + 150, pos.y));
root = overFx;
//e' brutto... mi serve solo per mettere gli over dentro il gruppo
fxs[overFx] = QPair<TFx *, int>(overFx, -1);
@@ -632,7 +632,11 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
}
obj->assignParams(params);
delete params;
- obj->setParent(parentId);
+ // a pegbar cannot be a child of column
+ if (parentId.isColumn())
+ obj->setParent(TStageObjectId::TableId);
+ else
+ obj->setParent(parentId);
//Put in the right StageObject group if needed
obj->removeFromAllGroup();
@@ -655,6 +659,7 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
//add colums;
FxDag *innerDag = subXsh->getFxDag();
FxDag *outerDag = xsh->getFxDag();
+ TStageObjectId tmpParentId = parentId;
set<int> indexes;
int i;
for (i = 0; i < subXsh->getColumnCount(); i++) {
@@ -665,6 +670,12 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
TFx *outerFx = outerColumn->getFx();
xsh->insertColumn(index, outerColumn);
+ // the above insertion operation may increment the parentId, in case that
+ // 1, the parent object is column, and
+ // 2, the parent column is placed on the right side of the inserted column
+ // ( i.e. index of the parent column is equal to or higher than "index")
+ if (onlyColumn && tmpParentId.isColumn() && tmpParentId.getIndex() >= index)
+ tmpParentId = TStageObjectId::ColumnId(tmpParentId.getIndex() + 1);
if (innerFx && outerFx) {
outerFx->getAttributes()->setDagNodePos(innerFx->getAttributes()->getDagNodePos());
@@ -701,7 +712,7 @@ set<int> explodeStageObjects(TXsheet *xsh, TXsheet *subXsh, int index, const TSt
}
if (onlyColumn)
- outerCol->setParent(parentId);
+ outerCol->setParent(tmpParentId);
//Put in the right StageObject group if needed
if (!objGroupData.m_groupIds.empty()) {
@@ -830,7 +841,7 @@ void explodeFxs(TXsheet *xsh, TXsheet *subXsh,
}
//cerco il punto medio tra tutti i nodi
- TPointD middlePoint;
+ TPointD middlePoint(0.0,0.0);
int fxsCount = 0;
QMap<TFx *, QPair<TFx *, int>>::iterator it;
@@ -849,6 +860,8 @@ void explodeFxs(TXsheet *xsh, TXsheet *subXsh,
}
if (fxsCount > 0)
middlePoint = TPointD(middlePoint.x / fxsCount, middlePoint.y / fxsCount);
+ else
+ middlePoint = TPointD(25000, 25000);//center of the scene
//faccio in modo che tutti i nodi estratti siano centrati in middlePoint
//Li metto poi in un gruppo
@@ -2472,6 +2485,12 @@ void SubsceneCmd::explode(int index)
// Remove column
xsh->removeColumn(index);
+ // The above removing operation may decrement the parentId, in case that
+ // 1, the parent object is column, and
+ // 2, the parent column is placed on the right side of the removed column
+ // ( i.e. index of the parent column is higher than "index")
+ if (parentId.isColumn() && parentId.getIndex() > index)
+ parentId = TStageObjectId::ColumnId(parentId.getIndex() - 1);
// Explode
set<int> newIndexes = ::explode(xsh, childLevel->getXsheet(), index, parentId,
diff --git a/toonz/sources/toonzqt/fxschematicnode.cpp b/toonz/sources/toonzqt/fxschematicnode.cpp
index 5e683525b..9967f2d71 100644
--- a/toonz/sources/toonzqt/fxschematicnode.cpp
+++ b/toonz/sources/toonzqt/fxschematicnode.cpp
@@ -3397,14 +3397,19 @@ void FxGroupNode::updateFxsDagPosition(const TPointD &pos) const
TPointD delta = pos - oldPos;
int i;
for (i = 0; i < m_groupedFxs.size(); i++) {
- m_groupedFxs[i]->getAttributes()->setDagNodePos(m_groupedFxs[i]->getAttributes()->getDagNodePos() + delta);
- TMacroFx *macro = dynamic_cast<TMacroFx *>(m_groupedFxs[i].getPointer());
- if (macro) {
- std::vector<TFxP> fxs = macro->getFxs();
- int i;
- for (i = 0; i < (int)fxs.size(); i++) {
- TPointD oldP = fxs[i]->getAttributes()->getDagNodePos();
- fxs[i]->getAttributes()->setDagNodePos(oldP + delta);
+ // If the node position is unidentified, then leave the placement of it to placeNode() function.
+ //if (m_groupedFxs[i]->getAttributes()->getDagNodePos() != TConst::nowhere)
+ {
+ m_groupedFxs[i]->getAttributes()->setDagNodePos(m_groupedFxs[i]->getAttributes()->getDagNodePos() + delta);
+ TMacroFx *macro = dynamic_cast<TMacroFx *>(m_groupedFxs[i].getPointer());
+ if (macro) {
+ std::vector<TFxP> fxs = macro->getFxs();
+ int i;
+ for (i = 0; i < (int)fxs.size(); i++) {
+ TPointD oldP = fxs[i]->getAttributes()->getDagNodePos();
+ //if (oldP != TConst::nowhere)
+ fxs[i]->getAttributes()->setDagNodePos(oldP + delta);
+ }
}
}
}
diff --git a/toonz/sources/toonzqt/fxschematicscene.cpp b/toonz/sources/toonzqt/fxschematicscene.cpp
index 863eb858a..af9c9c49f 100644
--- a/toonz/sources/toonzqt/fxschematicscene.cpp
+++ b/toonz/sources/toonzqt/fxschematicscene.cpp
@@ -1539,23 +1539,6 @@ TFx *FxSchematicScene::getCurrentFx()
void FxSchematicScene::mousePressEvent(QGraphicsSceneMouseEvent *me)
{
- // avoid clear of selection by middle-click
- if (me->button() != Qt::MidButton)
- SchematicScene::mousePressEvent(me);
-
- if (me->button() == Qt::RightButton) {
- QList<QGraphicsItem *> pointedItems = items(me->scenePos());
- for (int i = 0; i < pointedItems.size(); i++) {
- FxSchematicNode *sn = dynamic_cast<FxSchematicNode *>(pointedItems[i]);
- if (sn) {
- m_fxHandle->setFx(sn->getFx(), false);
- if (!m_selection->isSelected(sn->getFx()))
- m_selection->select(sn->getFx());
- m_selection->makeCurrent();
- }
- }
- }
-
QList<QGraphicsItem *> items = selectedItems();
#if QT_VERSION >= 0x050000
QGraphicsItem *item = itemAt(me->scenePos(), QTransform());
@@ -1564,25 +1547,17 @@ void FxSchematicScene::mousePressEvent(QGraphicsSceneMouseEvent *me)
#endif
FxSchematicPort *port = dynamic_cast<FxSchematicPort *>(item);
FxSchematicLink *link = dynamic_cast<FxSchematicLink *>(item);
-
+ SchematicScene::mousePressEvent(me);
+ onSelectionChanged();
if (me->button() == Qt::MidButton) {
int i;
for (i = 0; i < items.size(); i++)
items[i]->setSelected(true);
}
-
/*
- ここに入ったとき、
- ① 上記のSchematicScene::mousePressEvent(me)が呼ばれ
- ② 最上段にあるSchematicNode::mousePressEvent内でsetSelected(this)が呼ばれ
- ③ シグナルQGraphicsScene::selectionChanged()がエミットされ
- ④ スロットFxSchematticScene::onSelectionChanged()が呼ばれ
- その中で、いったんselectNone()され、その後選択ノードが追加される。
- ここにいたるまでにm_selectionが正しく更新される保障が無い。
- よって、選択Fx無しと勘違いして、FxSettingsが更新されないおそれがある。
- そこで、m_selection->isEmpty()では無く、QGraphicsScene::selectedItems()の個数で
- 直接判断することにする
- */
+ m_selection may not be updated here, so I use QGraphicsScene::selectedItems()
+ instead of m_selection->isEmpty() to check whether any node is selected or not.
+ */
if (selectedItems().isEmpty()) {
if (me->button() != Qt::MidButton && !item)
m_fxHandle->setFx(0, false);
diff --git a/toonz/sources/toonzqt/stageschematicnode.cpp b/toonz/sources/toonzqt/stageschematicnode.cpp
index 05ca5738d..105715d1d 100644
--- a/toonz/sources/toonzqt/stageschematicnode.cpp
+++ b/toonz/sources/toonzqt/stageschematicnode.cpp
@@ -6,6 +6,7 @@
#include "tconvert.h"
#include "tvectorimage.h"
#include "tundo.h"
+#include "tconst.h"
// TnzLib includes
#include "toonz/tstageobjectid.h"
@@ -2401,7 +2402,11 @@ void StageSchematicGroupNode::updateObjsDagPosition(const TPointD &pos) const
TPointD delta = pos - oldPos;
int i;
for (i = 0; i < m_groupedObj.size(); i++)
- m_groupedObj[i]->setDagNodePos(m_groupedObj[i]->getDagNodePos() + delta);
+ {
+ // If the node position is unidentified, then leave the placement of it to placeNode() function.
+ if (m_groupedObj[i]->getDagNodePos() != TConst::nowhere)
+ m_groupedObj[i]->setDagNodePos(m_groupedObj[i]->getDagNodePos() + delta);
+ }
}
//--------------------------------------------------------