bool TXsheet::setCell(int row, int col, const TXshCell &cell) { if (row < 0 || col < 0) return false; bool wasColumnEmpty = isColumnEmpty(col); TXshCellColumn *cellColumn; if (!cell.isEmpty()) { TXshLevel *level = cell.m_level.getPointer(); assert(level); int levelType = level->getType(); TXshColumn::ColumnType type = TXshColumn::eLevelType; if (levelType == SND_XSHLEVEL) type = TXshColumn::eSoundType; else if (levelType == SND_TXT_XSHLEVEL) type = TXshColumn::eSoundTextType; else if (levelType == PLT_XSHLEVEL) type = TXshColumn::ePaletteType; else if (levelType == ZERARYFX_XSHLEVEL) type = TXshColumn::eZeraryFxType; else if (levelType == MESH_XSHLEVEL) type = TXshColumn::eMeshType; cellColumn = touchColumn(col, type)->getCellColumn(); } else { TXshColumn *column = getColumn(col); cellColumn = column ? column->getCellColumn() : 0; } if (!cellColumn || cellColumn->isLocked()) return false; cellColumn->setXsheet(this); if (!cellColumn->setCell(row, cell)) { if (wasColumnEmpty) { removeColumn(col); insertColumn(col); } return false; } TFx *fx = cellColumn->getFx(); if (wasColumnEmpty && fx && fx->getOutputConnectionCount() == 0 && cellColumn->getPaletteColumn() == 0) getFxDag()->addToXsheet(fx); if (cell.isEmpty()) updateFrameCount(); else if (row >= m_imp->m_frameCount) m_imp->m_frameCount = row + 1; TNotifier::instance()->notify(TXsheetChange()); return true; }
void FilmstripFrames::onFrameSwitched() { // no. interferische con lo shift-click per la selezione. // m_selection->selectNone(); TApp *app = TApp::instance(); TFrameHandle *fh = app->getCurrentFrame(); TFrameId fid; if (fh->isEditingLevel()) fid = fh->getFid(); else { TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); int col = app->getCurrentColumn()->getColumnIndex(); int row = fh->getFrame(); if (row < 0 || col < 0) return; TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; fid = cell.getFrameId(); } int index = fid2index(fid); if (index >= 0) { exponeFrame(index); // clear selection and select only the destination frame select(index, ONLY_SELECT); } update(); }
bool changeFrameSkippingHolds(QKeyEvent *e) { if ((e->modifiers() & Qt::ShiftModifier) == 0 || e->key() != Qt::Key_Down && e->key() != Qt::Key_Up) return false; TApp *app = TApp::instance(); TFrameHandle *fh = app->getCurrentFrame(); if (!fh->isEditingScene()) return false; int row = fh->getFrame(); int col = app->getCurrentColumn()->getColumnIndex(); TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); if (e->key() == Qt::Key_Down) { if (cell.isEmpty()) { int r0, r1; if (xsh->getCellRange(col, r0, r1)) { while (row <= r1 && xsh->getCell(row, col).isEmpty()) row++; if (xsh->getCell(row, col).isEmpty()) return false; } else return false; } else { while (xsh->getCell(row, col) == cell) row++; } } else { // Key_Up while (row >= 0 && xsh->getCell(row, col) == cell) row--; if (row < 0) return false; cell = xsh->getCell(row, col); while (row > 0 && xsh->getCell(row - 1, col) == cell) row--; } fh->setFrame(row); return true; }
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 TXsheet::decreaseStepCells(int r0, int c0, int &r1, int c1) { int c, size = r1 - r0 + 1; QList<int> ends; for (c = c0; c <= c1; c++) { int r = r0, i = 0, rEnd = r1; while (r <= rEnd) { TXshCell cell = getCell(r, c); if (!cell.isEmpty()) { r++; bool removed = false; while (cell == getCell(r, c) && r <= rEnd) { if (!removed) { removed = true; removeCells(r, c); rEnd--; } else r++; } } else r++; i++; } ends.append(rEnd); } if (ends.isEmpty()) return; // controllo se devo cambiare la selezione bool allDecreaseIsEqual = true; for (c = 0; c < ends.size() - 1 && allDecreaseIsEqual; c++) allDecreaseIsEqual = allDecreaseIsEqual && ends[c] == ends[c + 1]; if (allDecreaseIsEqual) r1 = ends[0]; }
bool ColumnCmd::canResequence(int index) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshColumn *column = xsh->getColumn(index); if (!column) return false; TXshLevelColumn *lcolumn = column->getLevelColumn(); if (!lcolumn) return false; int r0 = 0, r1 = -1; if (lcolumn->getRange(r0, r1) == 0) return false; assert(r0 <= r1); TXshCell cell = lcolumn->getCell(r0); assert(!cell.isEmpty()); TXshLevel *xl = cell.m_level->getChildLevel(); if (!xl) return false; for (int r = r0 + 1; r <= r1; r++) { cell = lcolumn->getCell(r); if (cell.isEmpty()) continue; if (cell.m_level.getPointer() != xl) return false; } return true; }
void PaletteViewerPanel::onCurrentButtonToggled(bool isCurrent) { if (isActive() == isCurrent) return; TApp *app = TApp::instance(); TPaletteHandle *ph = app->getPaletteController()->getCurrentLevelPalette(); // Se sono sulla palette del livello corrente e le palette e' vuota non // consento di bloccare il pannello. if (isActive() && !ph->getPalette()) { m_isCurrentButton->setPressed(true); return; } setActive(isCurrent); m_paletteViewer->enableSaveAction(isCurrent); // Cambio il livello corrente if (isCurrent) { std::set<TXshSimpleLevel *> levels; TXsheet *xsheet = app->getCurrentXsheet()->getXsheet(); int row, column; findPaletteLevels(levels, row, column, m_paletteHandle->getPalette(), xsheet); // Se non trovo livelli riferiti alla palette setto il palette viewer alla // palette del livello corrente. if (levels.empty()) { m_paletteViewer->setPaletteHandle(ph); update(); return; } TXshSimpleLevel *level = *levels.begin(); // Se sto editando l'xsheet devo settare come corrente anche la colonna e il // frame. if (app->getCurrentFrame()->isEditingScene()) { int currentColumn = app->getCurrentColumn()->getColumnIndex(); if (currentColumn != column) app->getCurrentColumn()->setColumnIndex(column); int currentRow = app->getCurrentFrame()->getFrameIndex(); TXshCell cell = xsheet->getCell(currentRow, column); if (cell.isEmpty() || cell.getSimpleLevel() != level) app->getCurrentFrame()->setFrameIndex(row); TCellSelection *selection = dynamic_cast<TCellSelection *>( app->getCurrentSelection()->getSelection()); if (selection) selection->selectNone(); } app->getCurrentLevel()->setLevel(level); m_paletteViewer->setPaletteHandle(ph); } else { m_paletteHandle->setPalette(ph->getPalette()); m_paletteViewer->setPaletteHandle(m_paletteHandle); } update(); }
void ShiftTraceTool::drawControlRect() { if (m_ghostIndex < 0 || m_ghostIndex > 1) return; int row = m_row[m_ghostIndex]; if (row < 0) return; int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; TImageP img = cell.getImage(false); if (!img) return; TRectD box; if (TRasterImageP ri = img) { TRasterP ras = ri->getRaster(); box = (convert(ras->getBounds()) - ras->getCenterD()) * ri->getSubsampling(); } else if (TToonzImageP ti = img) { TRasterP ras = ti->getRaster(); box = (convert(ras->getBounds()) - ras->getCenterD()) * ti->getSubsampling(); } else if (TVectorImageP vi = img) { box = vi->getBBox(); } else { return; } glPushMatrix(); tglMultMatrix(getGhostAff()); TPixel32 color; color = m_highlightedGadget == TranslateGadget ? TPixel32(200, 100, 100) : TPixel32(120, 120, 120); tglColor(color); glBegin(GL_LINE_STRIP); glVertex2d(box.x0, box.y0); glVertex2d(box.x1, box.y0); glVertex2d(box.x1, box.y1); glVertex2d(box.x0, box.y1); glVertex2d(box.x0, box.y0); glEnd(); color = m_highlightedGadget == 2000 ? TPixel32(200, 100, 100) : TPixel32::White; double r = 4 * sqrt(tglGetPixelSize2()); drawDot(box.getP00(), r, color); drawDot(box.getP01(), r, color); drawDot(box.getP10(), r, color); drawDot(box.getP11(), r, color); if (m_curveStatus == NoCurve) { color = m_highlightedGadget == 2001 ? TPixel32(200, 100, 100) : TPixel32::White; TPointD c = m_center[m_ghostIndex]; drawDot(c, r, color); } glPopMatrix(); }
ResequenceUndo(int col, int count) : m_index(col), m_r0(0), m_newFramesCount(count) { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(col, r0, r1); m_r0 = r0; assert(r0 <= r1); if (r0 > r1) return; for (int r = r0; r <= r1; r++) { TXshCell cell = xsh->getCell(r, col); assert(cell.isEmpty() || cell.m_level->getChildLevel()); m_oldFrames.push_back(cell.m_frameId); } }
bool TXshZeraryFxColumn::setCell(int row, const TXshCell &cell) { if (cell.isEmpty()) return false; TXshCell newCell = cell; //Sto settando delle celle in una colonna nuova, devo settare anche l'effetto. if (isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0) { newCell = TXshCell(m_zeraryFxLevel, cell.getFrameId()); TXshZeraryFxLevel *fxLevel = cell.m_level->getZeraryFxLevel(); TXshZeraryFxColumn *fxColumn = fxLevel->getColumn(); m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx()); } return TXshCellColumn::setCell(row, newCell); }
TFrameId TTool::getCurrentFid() const { if (!m_application) return TFrameId(); TFrameHandle *fh = m_application->getCurrentFrame(); if (fh->isEditingLevel()) return fh->getFid(); int row = m_application->getCurrentFrame()->getFrame(); int col = m_application->getCurrentColumn()->getColumnIndex(); TXshCell cell = m_application->getCurrentXsheet()->getXsheet()->getCell(row, col); if (cell.isEmpty()) return TFrameId::NO_FRAME; return cell.getFrameId(); }
void ShiftTraceTool::updateData() { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int row = TApp::instance()->getCurrentFrame()->getFrame(); int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXshCell cell = xsh->getCell(row, col); m_box = TRectD(); for (int i = 0; i < 2; i++) m_row[i] = -1; m_dpiAff = TAffine(); // we must find the prev (m_row[0]) and next (m_row[1]) reference images // (either might not exist) // see also stage.cpp, StageBuilder::addCellWithOnionSkin if (cell.isEmpty()) { // current cell is empty. search for the prev ref img int r = row - 1; while (r >= 0 && xsh->getCell(r, col).getSimpleLevel() == 0) r--; if (r >= 0) m_row[0] = r; // else prev drawing doesn't exist : nothing to do } else { // current cell is not empty // search for prev ref img TXshSimpleLevel *sl = cell.getSimpleLevel(); int r = row - 1; if (r >= 0) { TXshCell otherCell = xsh->getCell(r, col); if (otherCell.getSimpleLevel() == sl) { // find the span start while (r - 1 >= 0 && xsh->getCell(r - 1, col) == otherCell) r--; m_row[0] = r; } } // search for next ref img r = row + 1; while (xsh->getCell(r, col) == cell) r++; // first cell after the current span has the same level if (xsh->getCell(r, col).getSimpleLevel() == sl) m_row[1] = r; } updateBox(); }
void redo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(m_index, r0, r1); assert(r0 <= r1); if (r0 > r1) return; TXshCell cell = xsh->getCell(r0, m_index); assert(!cell.isEmpty()); assert(cell.m_level->getChildLevel()); xsh->clearCells(r0, m_index, r1 - r0 + 1); for (int i = 0; i < m_newFramesCount; i++) { cell.m_frameId = TFrameId(i + 1); xsh->setCell(m_r0 + i, m_index, cell); } TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void TXshMeshColumn::saveData(TOStream &os) { os.child("status") << getStatusWord(); if (getOpacity() < 255) os.child("camerastand_opacity") << (int)getOpacity(); int r0, r1; if (getRange(r0, r1)) { os.openChild("cells"); { for (int r = r0; r <= r1; ++r) { TXshCell cell = getCell(r); if (cell.isEmpty()) continue; TFrameId fid = cell.m_frameId; int n = 1, inc = 0, dr = fid.getNumber(); // If fid has no letter save more than one cell and its increment - // otherwise save just one cell if (r < r1 && fid.getLetter() == 0) { TXshCell cell2 = getCell(r + 1); TFrameId fid2 = cell2.m_frameId; if (cell2.m_level.getPointer() == cell.m_level.getPointer() && fid2.getLetter() == 0) { inc = cell2.m_frameId.getNumber() - dr; for (++n;; ++n) { if (r + n > r1) break; cell2 = getCell(r + n); TFrameId fid2 = cell2.m_frameId; if (cell2.m_level.getPointer() != cell.m_level.getPointer() || fid2.getLetter() != 0) break; if (fid2.getNumber() != dr + n * inc) break; } } } os.child("cell") << r << n << cell.m_level.getPointer() << fid.expand() << inc; r += n - 1; } } os.closeChild(); } }
void undo() const override { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int r0, r1; xsh->getCellRange(m_index, r0, r1); assert(r0 <= r1); if (r0 > r1) return; TXshCell cell = xsh->getCell(r0, m_index); assert(!cell.isEmpty()); assert(cell.m_level->getChildLevel()); xsh->clearCells(r0, m_index, r1 - r0 + 1); for (int i = 0; i < (int)m_oldFrames.size(); i++) { TFrameId fid = m_oldFrames[i]; if (fid != TFrameId::EMPTY_FRAME) { cell.m_frameId = fid; xsh->setCell(m_r0 + i, m_index, cell); } } TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }
void TXsheet::getUsedLevels(set<TXshLevel *> &levels) const { set<const TXsheet *> visitedXshs; vector<const TXsheet *> todoXshs; visitedXshs.insert(this); todoXshs.push_back(this); while (!todoXshs.empty()) { const TXsheet *xsh = todoXshs.back(); todoXshs.pop_back(); int c0 = 0, c1 = xsh->getColumnCount() - 1; for (int c = c0; c <= c1; ++c) { TXshColumnP column = const_cast<TXsheet *>(xsh)->getColumn(c); if (!column) continue; TXshCellColumn *cellColumn = column->getCellColumn(); if (!cellColumn) continue; int r0, r1; if (!cellColumn->getRange(r0, r1)) continue; TXshLevel *level = 0; for (int r = r0; r <= r1; r++) { TXshCell cell = cellColumn->getCell(r); if (cell.isEmpty() || !cell.m_level) continue; if (level != cell.m_level.getPointer()) { level = cell.m_level.getPointer(); levels.insert(level); if (level->getChildLevel()) { TXsheet *childXsh = level->getChildLevel()->getXsheet(); if (visitedXshs.count(childXsh) == 0) { visitedXshs.insert(childXsh); todoXshs.push_back(childXsh); } } } } } } }
void execute() { TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int row = TApp::instance()->getCurrentFrame()->getFrame(); int col = TApp::instance()->getCurrentColumn()->getColumnIndex(); TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) return; for (--row; row >= 0 && xsh->getCell(row, col) == cell; --row) // Get *last* cell in previous uniform ; // cell block if (row >= 0 && !xsh->getCell(row, col).isEmpty()) { cell = xsh->getCell(row, col); while (row > 0 && xsh->getCell(row - 1, col) == cell) // Get *first* cell in current uniform --row; // cell block TApp::instance()->getCurrentFrame()->setFrame(row); } }
bool TXshMeshColumn::canSetCell(const TXshCell &cell) const { TXshSimpleLevel *sl = cell.getSimpleLevel(); return cell.isEmpty() || (sl && sl->getType() == MESH_XSHLEVEL); }
void execute() override { TColumnSelection *selection = dynamic_cast<TColumnSelection *>(TSelection::getCurrent()); if (!selection) { DVGui::warning( tr("It is not possible to merge tlv columns because no column was " "selected.")); return; } std::set<int> indices = selection->getIndices(); if (indices.size() < 2) { DVGui::warning( tr("It is not possible to merge tlv columns because at least two " "columns have to be selected.")); return; } std::set<int>::iterator it = indices.begin(); int destColumn = *it; TCellSelection::Range cells; cells.m_c0 = cells.m_c1 = destColumn; TXshColumn *column = TApp::instance()->getCurrentXsheet()->getXsheet()->getColumn( destColumn); column->getRange(cells.m_r0, cells.m_r1); // column->getLevelColumn() TFilePath newLevelPath; TXshCell c = TApp::instance()->getCurrentXsheet()->getXsheet()->getCell( cells.m_r0, destColumn); if (!c.isEmpty() && c.getSimpleLevel()) newLevelPath = c.getSimpleLevel()->getPath(); if (MergeCmappedDialog(newLevelPath).exec() != QDialog::Accepted) return; it = indices.begin(); for (; it != indices.end(); ++it) if (!checkColumnValidity(*it)) return; DVGui::ProgressDialog progress(tr("Merging Tlv Levels..."), QString(), 0, indices.size() - 1, TApp::instance()->getMainWindow()); progress.setWindowModality(Qt::WindowModal); progress.setWindowTitle(tr("Merging Tlv Levels...")); progress.setValue(0); progress.show(); QCoreApplication::instance()->processEvents(); TUndoManager::manager()->beginBlock(); cloneColumn(cells, newLevelPath); it = indices.begin(); ++it; for (int count = 0; it != indices.end();) { int index = *it; it++; mergeCmapped(destColumn, index - count, it == indices.end() ? QString::fromStdWString(newLevelPath.getWideString()) : "", false); ColumnCmd::deleteColumn(index - count); progress.setValue(++count); QCoreApplication::instance()->processEvents(); } TUndoManager::manager()->endBlock(); 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(); }
int TApp::getCurrentImageType() { /*-- 現在のセルの種類に関係無く、Splineを選択中はベクタを編集できるようにする * --*/ if (getCurrentObject()->isSpline()) return TImage::VECTOR; TXshSimpleLevel *sl = 0; if (getCurrentFrame()->isEditingScene()) { int row = getCurrentFrame()->getFrame(); int col = getCurrentColumn()->getColumnIndex(); if (col < 0) #ifdef LINETEST return TImage::RASTER; #else { int levelType = Preferences::instance()->getDefLevelType(); return (levelType == PLI_XSHLEVEL) ? TImage::VECTOR : // RASTER image type includes both TZI_XSHLEVEL (levelType == TZP_XSHLEVEL) ? TImage::TOONZ_RASTER : TImage::RASTER; // and OVL_XSHLEVEL level types } #endif TXsheet *xsh = getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(row, col); if (cell.isEmpty()) { int r0, r1; xsh->getCellRange(col, r0, r1); if (0 <= r0 && r0 <= r1) { /*-- Columnに格納されている一番上のLevelのTypeに合わせる--*/ cell = xsh->getCell(r0, col); } else /*-- Columnが空の場合 --*/ { #ifdef LINETEST return TImage::RASTER; #else int levelType = Preferences::instance()->getDefLevelType(); return (levelType == PLI_XSHLEVEL) ? TImage::VECTOR : (levelType == TZP_XSHLEVEL) ? TImage::TOONZ_RASTER : TImage::RASTER; #endif } } sl = cell.getSimpleLevel(); } else if (getCurrentFrame()->isEditingLevel()) sl = getCurrentLevel()->getSimpleLevel(); if (sl) { switch (sl->getType()) { case TZP_XSHLEVEL: return TImage::TOONZ_RASTER; case OVL_XSHLEVEL: return TImage::RASTER; case PLI_XSHLEVEL: default: return TImage::VECTOR; case MESH_XSHLEVEL: return TImage::MESH; } } return TImage::VECTOR; }
bool LevelCreatePopup::apply() { TApp *app = TApp::instance(); int row = app->getCurrentFrame()->getFrame(); int col = app->getCurrentColumn()->getColumnIndex(); int i, j; ToonzScene *scene = app->getCurrentScene()->getScene(); TXsheet *xsh = scene->getXsheet(); bool validColumn = true; if (xsh->getColumn(col)) validColumn = xsh->getColumn(col)->getColumnType() == TXshColumn::eLevelType; int from = (int)m_fromFld->getValue(); int to = (int)m_toFld->getValue(); int inc = (int)m_incFld->getValue(); int step = (int)m_stepFld->getValue(); double w = m_widthFld->getValue(); double h = m_heightFld->getValue(); double dpi = m_dpiFld->getValue(); int xres = std::max(tround(w * dpi), 1); int yres = std::max(tround(h * dpi), 1); int lType = getLevelType(); std::wstring levelName = m_nameFld->text().toStdWString(); // tolgo i blanks prima e dopo i = levelName.find_first_not_of(L' '); if (i == (int)std::wstring::npos) levelName = L""; else { int j = levelName.find_last_not_of(L' '); assert(j != (int)std::wstring::npos); levelName = levelName.substr(i, j - i + 1); } if (levelName.empty()) { error(tr("No level name specified: please choose a valid level name")); return false; } if (from > to) { error(tr("Invalid frame range")); return false; } if (inc <= 0) { error(tr("Invalid increment value")); return false; } if (step <= 0) { error(tr("Invalid step value")); return false; } int numFrames = step * (((to - from) / inc) + 1); if (scene->getLevelSet()->getLevel(levelName)) { error( tr("The level name specified is already used: please choose a " "different level name")); m_nameFld->selectAll(); return false; } TFilePath parentDir(m_pathFld->getPath().toStdWString()); TFilePath fp = scene->getDefaultLevelPath(lType, levelName).withParentDir(parentDir); TFilePath actualFp = scene->decodeFilePath(fp); if (TSystem::doesExistFileOrLevel(actualFp)) { error( tr("The level name specified is already used: please choose a " "different level name")); m_nameFld->selectAll(); return false; } parentDir = scene->decodeFilePath(parentDir); if (!TFileStatus(parentDir).doesExist()) { QString question; /*question = "Folder " +toQString(parentDir) + " doesn't exist.\nDo you want to create it?";*/ question = tr("Folder %1 doesn't exist.\nDo you want to create it?") .arg(toQString(parentDir)); int ret = DVGui::MsgBox(question, QObject::tr("Yes"), QObject::tr("No")); if (ret == 0 || ret == 2) return false; try { TSystem::mkDir(parentDir); DvDirModel::instance()->refreshFolder(parentDir.getParentDir()); } catch (...) { error(tr("Unable to create") + toQString(parentDir)); return false; } } TXshLevel *level = scene->createNewLevel(lType, levelName, TDimension(), 0, fp); TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(level); assert(sl); sl->setPath(fp, true); if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) { sl->getProperties()->setDpiPolicy(LevelProperties::DP_ImageDpi); sl->getProperties()->setDpi(dpi); sl->getProperties()->setImageDpi(TPointD(dpi, dpi)); sl->getProperties()->setImageRes(TDimension(xres, yres)); } /*-- これからLevelを配置しようとしているセルが空いているかどうかのチェック * --*/ bool areColumnsShifted = false; TXshCell cell = xsh->getCell(row, col); bool isInRange = true; for (i = row; i < row + numFrames; i++) { if (!cell.isEmpty()) { isInRange = false; break; } cell = xsh->getCell(i, col); } if (!validColumn) { isInRange = false; } /*-- 別のLevelに占有されていた場合、Columnを1つ右に移動 --*/ if (!isInRange) { col += 1; TApp::instance()->getCurrentColumn()->setColumnIndex(col); areColumnsShifted = true; xsh->insertColumn(col); } CreateLevelUndo *undo = new CreateLevelUndo(row, col, numFrames, step, areColumnsShifted); TUndoManager::manager()->add(undo); for (i = from; i <= to; i += inc) { TFrameId fid(i); TXshCell cell(sl, fid); if (lType == PLI_XSHLEVEL) sl->setFrame(fid, new TVectorImage()); else if (lType == TZP_XSHLEVEL) { TRasterCM32P raster(xres, yres); raster->fill(TPixelCM32()); TToonzImageP ti(raster, TRect()); ti->setDpi(dpi, dpi); sl->setFrame(fid, ti); ti->setSavebox(TRect(0, 0, xres - 1, yres - 1)); } else if (lType == OVL_XSHLEVEL) { TRaster32P raster(xres, yres); raster->clear(); TRasterImageP ri(raster); ri->setDpi(dpi, dpi); sl->setFrame(fid, ri); } for (j = 0; j < step; j++) xsh->setCell(row++, col, cell); } if (lType == TZP_XSHLEVEL || lType == OVL_XSHLEVEL) { sl->save(fp); DvDirModel::instance()->refreshFolder(fp.getParentDir()); } undo->onAdd(sl); app->getCurrentScene()->notifySceneChanged(); app->getCurrentScene()->notifyCastChange(); app->getCurrentXsheet()->notifyXsheetChanged(); // Cambia l'immagine corrente ma non cambiano ne' il frame ne' la colonna // corrente // (entrambi notificano il cambiamento dell'immagine al tool). // devo verfificare che sia settato il tool giusto. app->getCurrentTool()->onImageChanged( (TImage::Type)app->getCurrentImageType()); return true; }
bool VectorizerPopup::apply() { std::set<TXshLevel *> levels; ToonzScene *scene = m_sceneHandle->getScene(); if (!scene) { assert(scene); return false; } TSceneProperties *sceneProp = scene->getProperties(); if (!sceneProp) return false; VectorizerParameters *vectorizerParameters = sceneProp->getVectorizerParameters(); if (!vectorizerParameters) return false; int r0 = 0; int c0 = 0; int r1 = 0; int c1 = 0; bool isCellSelection = getSelectedLevels(levels, r0, c0, r1, c1); if (levels.empty()) { error(tr("The current selection is invalid.")); return false; } //Initialize Progress bar m_progressDialog = new DVGui::ProgressDialog("", "Cancel", 0, 1); m_progressDialog->setWindowFlags(Qt::Dialog | Qt::WindowTitleHint); //Don't show ? and X buttons m_progressDialog->setWindowTitle(QString("Convert To Vector...")); m_progressDialog->setAttribute(Qt::WA_DeleteOnClose); m_progressDialog->setWindowModality(Qt::WindowModal); //No user interaction is allowed during vectorization m_progressDialog->setFixedSize(200, 100); //Initialize vectorizer m_vectorizer = new Vectorizer; m_vectorizer->setParameters(*vectorizerParameters); connect(m_vectorizer, SIGNAL(frameName(QString)), this, SLOT(onFrameName(QString)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(frameDone(int)), this, SLOT(onFrameDone(int)), Qt::QueuedConnection); connect(m_vectorizer, SIGNAL(partialDone(int, int)), this, SLOT(onPartialDone(int, int)), Qt::QueuedConnection); //We DON'T want the progress bar to be hidden at cancel press - since its modal //behavior prevents the user to interfere with a possibly still active vectorization. disconnect(m_progressDialog, SIGNAL(canceled()), m_progressDialog, SLOT(onCancel())); //We first inform the vectorizer of a cancel press; bool ret = connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SLOT(cancel())); //which eventually transmits the command to vectorization core, allowing full-time cancels ret = ret && connect(m_progressDialog, SIGNAL(canceled()), m_vectorizer, SIGNAL(transmitCancel())); //Only after the vectorizer has terminated its process - or got cancelled, we are allowed //to proceed here. ret = ret && connect(m_vectorizer, SIGNAL(finished()), this, SLOT(onFinished()), Qt::QueuedConnection); assert(ret); int newIndexColumn = c1 + 1; std::set<TXshLevel *>::iterator it = levels.begin(); for (it; it != levels.end(); it++) { TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(*it); if (!sl || !sl->getSimpleLevel() || !isLevelToConvert(sl)) { QString levelName = tr(toString(sl->getName()).c_str()); QString errorMsg = tr("Cannot convert to vector the current selection.") + levelName; error(errorMsg); continue; } std::vector<TFrameId> fids; if (isCellSelection) getSelectedFids(fids, sl, r0, c0, r1, c1); else sl->getFids(fids); assert(fids.size() > 0); close(); // Re-initialize progress Bar m_progressDialog->setMaximum(fids.size() * 100); m_progressDialog->setValue(0); m_currFrame = 0; // Re-initialize vectorizer m_vectorizer->setLevel(sl); m_vectorizer->setFids(fids); // Start vectorizing m_vectorizer->start(); m_progressDialog->show(); // Wait the vectorizer... while (!l_quitLoop) QCoreApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents); l_quitLoop = false; // Assign output X-sheet cells TXshSimpleLevel *vl = m_vectorizer->getVectorizedLevel(); if (isCellSelection && vl) { TXsheet *xsheet = TApp::instance()->getCurrentXsheet()->getXsheet(); xsheet->insertColumn(newIndexColumn); int r, c; for (c = c0; c <= c1; c++) { for (r = r0; r <= r1; r++) { TXshCell cell = xsheet->getCell(r, c); TXshSimpleLevel *level = (!cell.isEmpty()) ? cell.getSimpleLevel() : 0; if (level != sl) continue; TFrameId curFid = cell.getFrameId(); std::vector<TFrameId> newFids; vl->getFids(newFids); std::vector<TFrameId>::iterator it1 = newFids.begin(); for (it1; it1 != newFids.end(); it1++) { TFrameId id = *it1; if (id.getNumber() == curFid.getNumber() || // Hanno stesso numero di frame (id.getNumber() == 1 && curFid.getNumber() == -2)) // La vecchia cella non ha numero di frame xsheet->setCell(r, newIndexColumn, TXshCell(vl, id)); } } } newIndexColumn += 1; } else if (vl) { std::vector<TFrameId> gomi; scene->getXsheet()->exposeLevel(0, scene->getXsheet()->getFirstFreeColumnIndex(), vl, gomi); } if (m_vectorizer->isCanceled()) break; } m_progressDialog->close(); delete m_vectorizer; TApp::instance()->getCurrentScene()->notifyCastChange(); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); return true; }
bool TXshZeraryFxColumn::canSetCell(const TXshCell &cell) const { return cell.isEmpty() || cell.m_level->getZeraryFxLevel() != 0; }
const OnionSkinMask &osm = sb->m_onionSkinMask; return level == sb->m_xsheetLevel && osm.isEnabled() && !osm.isEmpty() && (osm.isWholeScene() || col == sb->m_currentColumnIndex || locals::hasOnionSkinnedMeshParent(sb, xsh, col)); } }; // locals if (m_onionSkinMask.isShiftTraceEnabled() && col == m_currentColumnIndex) { TXshCell cell = xsh->getCell(row, col); int r = row - 1; // r,col can be a hold. find its starting point for (; r - 1 >= 0 && xsh->getCell(r - 1, col) == cell; r--) ; if (cell.isEmpty()) r--; if (r >= 0 && (cell.getSimpleLevel() == 0 || xsh->getCell(r, col).getSimpleLevel() == cell.getSimpleLevel())) { m_shiftTraceGhostId = FIRST_GHOST; addCell(players, scene, xsh, r, col, level); } TXshCell otherCell; if (cell.getSimpleLevel() != 0) { for (r = row + 1; (otherCell = xsh->getCell(r, col)) == cell; r++) ; if (cell.getSimpleLevel() == 0 || otherCell.getSimpleLevel() == cell.getSimpleLevel()) {
void ComboViewerPanel::changeWindowTitle() { TApp *app = TApp::instance(); ToonzScene *scene = app->getCurrentScene()->getScene(); if (!scene) return; int frame = app->getCurrentFrame()->getFrame(); // put the titlebar texts in this string QString name; // if the frame type is "scene editing" if (app->getCurrentFrame()->isEditingScene()) { QString sceneName = QString::fromStdWString(scene->getSceneName()); if (sceneName.isEmpty()) sceneName = tr("Untitled"); if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString(" *"); name = tr("Scene: ") + sceneName; if (frame >= 0) name = name + tr(" :: Frame: ") + tr(std::to_string(frame + 1).c_str()); int col = app->getCurrentColumn()->getColumnIndex(); if (col < 0) { setWindowTitle(name); return; } TXsheet *xsh = app->getCurrentXsheet()->getXsheet(); TXshCell cell = xsh->getCell(frame, col); if (cell.isEmpty()) { setWindowTitle(name); return; } assert(cell.m_level.getPointer()); TFilePath fp(cell.m_level->getName()); QString imageName = QString::fromStdWString(fp.withFrame(cell.m_frameId).getWideString()); name = name + tr(" :: Level: ") + imageName; if (m_sceneViewer->isPreviewEnabled()) { name = name + " :: Zoom : " + QString::number((int)(100.0 * sqrt(m_sceneViewer->getViewMatrix().det()) * m_sceneViewer->getDpiFactor())) + "%"; } // If the current level exists and some option is set in the preference, // set the zoom value to the current level's dpi else if (Preferences::instance() ->isActualPixelViewOnSceneEditingModeEnabled() && TApp::instance()->getCurrentLevel()->getSimpleLevel() && !CleanupPreviewCheck::instance() ->isEnabled() // cleanup preview must be OFF && !CameraTestCheck::instance() ->isEnabled()) // camera test mode must be OFF neither { name = name + " :: Zoom : " + QString::number((int)(100.0 * sqrt(m_sceneViewer->getViewMatrix().det()) * m_sceneViewer->getDpiFactor())) + "%"; } } // if the frame type is "level editing" else { TXshLevel *level = app->getCurrentLevel()->getLevel(); if (level) { TFilePath fp(level->getName()); QString imageName = QString::fromStdWString( fp.withFrame(app->getCurrentFrame()->getFid()).getWideString()); name = name + tr("Level: ") + imageName; name = name + " :: Zoom : " + QString::number((int)(100.0 * sqrt(m_sceneViewer->getViewMatrix().det()) * m_sceneViewer->getDpiFactor())) + "%"; } } setWindowTitle(name); }