void ColumnCmd::resequence(int index) { if (!canResequence(index)) return; TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshColumn *column = xsh->getColumn(index); assert(column); TXshLevelColumn *lcolumn = column->getLevelColumn(); assert(lcolumn); int r0 = 0, r1 = -1; lcolumn->getRange(r0, r1); assert(r0 <= r1); TXshCell cell = lcolumn->getCell(r0); assert(!cell.isEmpty()); TXshChildLevel *xl = cell.m_level->getChildLevel(); assert(xl); TXsheet *childXsh = xl->getXsheet(); int frameCount = childXsh->getFrameCount(); if (frameCount < 1) frameCount = 1; TUndoManager::manager()->add(new ResequenceUndo(index, frameCount)); lcolumn->clearCells(r0, r1 - r0 + 1); for (int i = 0; i < frameCount; i++) { cell.m_frameId = TFrameId(i + 1); lcolumn->setCell(r0 + i, cell); } xsh->updateFrameCount(); TApp::instance()->getCurrentScene()->setDirtyFlag(true); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void undo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); for (int i = 0; i < (int)m_oldFrames.size(); i++) { xsh->setCell(m_r0 + i, m_col, m_oldFrames[i]); } xsh->updateFrameCount(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void redo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(m_col, r0, r1); if (r0 <= r1) { xsh->clearCells(r0, m_col, r1 - r0 + 1); xsh->updateFrameCount(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); } }
void ColumnCmd::cloneChild(int index) { if (!canResequence(index)) return; /*-- カラムを取得 --*/ TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshColumn *column = xsh->getColumn(index); assert(column); // get the subxsheet to clone (childLevel, childXsh) /*-- SubXsheetレベルを取得 --*/ TXshLevelColumn *lcolumn = column->getLevelColumn(); assert(lcolumn); int r0 = 0, r1 = -1; lcolumn->getRange(r0, r1); assert(r0 <= r1); /*-- SubXsheetの一番頭のセル --*/ TXshCell cell = lcolumn->getCell(r0); assert(!cell.isEmpty()); /*- cell内に格納されているLevelを取得 -*/ TXshChildLevel *childLevel = cell.m_level->getChildLevel(); assert(childLevel); /*- SubXsheetのXsheetを取得 -*/ TXsheet *childXsh = childLevel->getXsheet(); // insert a new empty column /*- 隣に空きColumnをInsertしてCloneに備える -*/ int newColumnIndex = index + 1; xsh->insertColumn(newColumnIndex); // create a subxsheet (newChildLevel, newChildXsh) ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); ChildStack *childStack = scene->getChildStack(); TXshChildLevel *newChildLevel = childStack->createChild(0, newColumnIndex); TXsheet *newChildXsh = newChildLevel->getXsheet(); // copy columns. std::set<int> indices; for (int i = 0; i < childXsh->getColumnCount(); i++) indices.insert(i); StageObjectsData *data = new StageObjectsData(); data->storeColumns(indices, childXsh, 0); data->storeColumnFxs(indices, childXsh, 0); std::list<int> restoredSplineIds; data->restoreObjects(indices, restoredSplineIds, newChildXsh, StageObjectsData::eDoClone); delete data; cloneNotColumnLinkedFxsAndOutputsFx(childXsh, newChildXsh); cloneXsheetTStageObjectTree(childXsh, newChildXsh); /*--以下は、Clone SubXsheet するときに、SubXsheet内にある子SubXsheetをクローンする関数 クローンされた中にある子SubXsheetは、同じもので良いので、スキップする --*/ // cloneSubXsheets(newChildXsh); /*-- XSheetノードのFxSchematicでのDagNodePosを再現 FxやColumnノードの位置の再現は上のsetColumnで行っている --*/ newChildXsh->getFxDag()->getXsheetFx()->getAttributes()->setDagNodePos( childXsh->getFxDag()->getXsheetFx()->getAttributes()->getDagNodePos()); newChildXsh->updateFrameCount(); /*-- TXshChildLevel作成時にsetCellした1つ目のセルを消去 --*/ xsh->removeCells(0, newColumnIndex); /*-- CloneしたColumnのセル番号順を再現 --*/ for (int r = r0; r <= r1; r++) { TXshCell cell = lcolumn->getCell(r); if (cell.isEmpty()) continue; cell.m_level = newChildLevel; xsh->setCell(r, newColumnIndex, cell); } TStageObjectId currentObjectId = TApp::instance()->getCurrentObject()->getObjectId(); xsh->getStageObject(TStageObjectId::ColumnId(newColumnIndex)) ->setParent(xsh->getStageObjectParent(currentObjectId)); xsh->updateFrameCount(); TUndoManager::manager()->add( new CloneChildUndo(newChildLevel, newColumnIndex)); // notify changes TApp::instance()->getCurrentScene()->setDirtyFlag(true); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void LevelMoverTool::onCellChange(int row, int col) { TXsheet *xsh = getViewer()->getXsheet(); TPoint pos = TPoint(col, row) + m_grabOffset; if (pos.y < 0) pos.y = 0; if (pos.x < 0) return; if (pos == m_aimedPos) return; m_aimedPos = pos; TPoint delta = m_aimedPos - m_lastPos; m_validPos = canMoveColumns(pos); if (!m_validPos) return; CellsMover *cellsMover = m_undo->getCellsMover(); if (m_moved) cellsMover->undoMoveCells(); m_validPos = canMove(pos); if (m_validPos) { //---------------------- if (delta.x != 0 && (m_qualifiers & CellsMover::eMoveColumns)) { // spostamento di colonne int colCount = m_range.lx; bool emptySrc = true; for (int i = 0; i < colCount; i++) { TXshColumn *column = xsh->getColumn(m_lastPos.x + i); if (column && !column->isEmpty()) { emptySrc = false; break; } } bool lockedDst = false; bool emptyDst = true; for (int i = 0; i < colCount; i++) { if (!isTotallyEmptyColumn(pos.x + i)) emptyDst = false; TXshColumn *column = xsh->getColumn(pos.x + i); if (column && column->isLocked()) lockedDst = true; } if (emptySrc) { if (m_lastPos.x == m_startPos.x) m_undo->getCellsMover()->m_uffa |= 1; // first column(s) has/have been cleared cellsMover->emptyColumns(m_lastPos.x); } if (emptyDst && !lockedDst) { if (pos.x == m_startPos.x) m_undo->getCellsMover()->m_uffa &= ~1; // first column(s) has/have been restored else m_undo->getCellsMover()->m_uffa |= 2; // columns data have been copied on the current position cellsMover->restoreColumns(pos.x); } else { m_undo->getCellsMover()->m_uffa &= ~2; // no columns data have been copied on the current position } } //---------------------- m_lastPos = pos; cellsMover->setPos(pos.y, pos.x); cellsMover->saveCells(); cellsMover->moveCells(); m_moved = true; } else { cellsMover->moveCells(); } xsh->updateFrameCount(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); if (cellsMover->getColumnTypeFromCell(0) == TXshColumn::eSoundType) TApp::instance()->getCurrentXsheet()->notifyXsheetSoundChanged(); TRect selection(m_aimedPos, m_range); getViewer()->getCellSelection()->selectCells(selection.y0, selection.x0, selection.y1, selection.x1); }