void execute() { TApp *app = TApp::instance(); ToonzScene *scene = app->getCurrentScene()->getScene(); TLevelSet *levelSet = scene->getLevelSet(); std::set<TXshLevel *> usedLevels; scene->getTopXsheet()->getUsedLevels(usedLevels); std::vector<TXshLevel *> unused; for (int i = 0; i < levelSet->getLevelCount(); i++) { TXshLevel *xl = levelSet->getLevel(i); if (usedLevels.count(xl) == 0) unused.push_back(xl); } if (unused.empty()) { DVGui::error(QObject::tr("No unused levels")); return; } else { TUndoManager *um = TUndoManager::manager(); um->beginBlock(); for (int i = 0; i < (int)unused.size(); i++) { TXshLevel *xl = unused[i]; um->add(new DeleteLevelUndo(xl)); scene->getLevelSet()->removeLevel(xl); } TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); TApp::instance()->getCurrentScene()->notifyCastChange(); um->endBlock(); } }
void StudioPaletteCmd::updateAllLinkedStyles(TPaletteHandle *paletteHandle, TXsheetHandle *xsheetHandle) { if (!xsheetHandle) return; TXsheet *xsheet = xsheetHandle->getXsheet(); if (!xsheet) return; ToonzScene *scene = xsheet->getScene(); if (!scene) return; // emit signal only if something changed bool somethingChanged = false; StudioPalette *sp = StudioPalette::instance(); TLevelSet *levelSet = scene->getLevelSet(); for (int i = 0; i < levelSet->getLevelCount(); i++) { TXshLevel *xl = levelSet->getLevel(i); TXshSimpleLevel *sl = xl ? xl->getSimpleLevel() : 0; if (!sl) continue; TPalette *palette = sl->getPalette(); if (palette) { somethingChanged = somethingChanged | sp->updateLinkedColors(palette); if (sl->getType() == TZP_XSHLEVEL) { std::vector<TFrameId> fids; sl->getFids(fids); std::vector<TFrameId>::iterator it; for (it = fids.begin(); it != fids.end(); ++it) { TFrameId fid = *it; std::string id = sl->getImageId(fid); } } } } if (!paletteHandle || !paletteHandle->getPalette()) return; if (somethingChanged) paletteHandle->notifyColorStyleChanged(); }
TXshSimpleLevel *Level::getLevel() const { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); TXshLevel *level = scene->getLevelSet()->getLevel(m_name.toStdWString()); TXshSimpleLevel *sl = dynamic_cast<TXshSimpleLevel *>(level); return sl; }
/*! update combo items when the contents of scene cast are changed */ void Filmstrip::updateChooseLevelComboItems() { // clear items m_chooseLevelCombo->clear(); m_levels.clear(); std::map<TXshSimpleLevel *, TFrameId> new_workingFrames; // correct and register items ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); if (scene) { std::vector<TXshLevel *> levels; scene->getLevelSet()->listLevels(levels); std::vector<TXshLevel *>::iterator it; for (it = levels.begin(); it != levels.end(); ++it) { // register only TLV and PLI TXshSimpleLevel *sl = (*it)->getSimpleLevel(); if (sl) { // register only used level in xsheet if (!scene->getTopXsheet()->isLevelUsed(sl)) continue; m_levels.push_back(sl); // create new m_workingFrames map with the new levelset TFrameId fId; std::map<TXshSimpleLevel *, TFrameId>::iterator WFit = m_workingFrames.find(sl); if (WFit != m_workingFrames.end()) fId = WFit->second; else fId = sl->getFirstFid(); new_workingFrames.insert(std::make_pair(sl, fId)); QString levelName = QString::fromStdWString(sl->getName()); if (sl->getProperties()->getDirtyFlag()) levelName += " *"; // append the current working frame number to the item name if (fId != sl->getFirstFid() && fId.getNumber() >= 0) levelName += QString(" [#") + QString::number(fId.getNumber()) + QString("]"); m_chooseLevelCombo->addItem(levelName); } } } m_chooseLevelCombo->addItem(tr("- No Current Level -")); // swap the list m_workingFrames.clear(); m_workingFrames = new_workingFrames; // synchronize the current index of combo to the current level updateCurrentLevelComboItem(); }
bool removeLevel(TXshLevel *level) { TApp *app = TApp::instance(); ToonzScene *scene = app->getCurrentScene()->getScene(); if (scene->getChildStack()->getTopXsheet()->isLevelUsed(level)) DVGui::error(QObject::tr("It is not possible to delete the used level %1.").arg(QString::fromStdWString(level->getName()))); //"E_CantDeleteUsedLevel_%1" else { TUndoManager *um = TUndoManager::manager(); um->add(new DeleteLevelUndo(level)); scene->getLevelSet()->removeLevel(level); } return true; }
QScriptValue getLevel(QScriptContext *ctx, QScriptEngine *eng) { QString levelName = ctx->argument(0).toString(); ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); TXshLevel *level = scene->getLevelSet()->getLevel(levelName.toStdWString()); if (!level) { level = scene->createNewLevel(PLI_XSHLEVEL, levelName.toStdWString()); levelName = QString::fromStdWString(level->getName()); } if (level->getSimpleLevel()) return eng->newQObject(new ScriptWrapper::Level(level->getSimpleLevel()), QScriptEngine::ScriptOwnership); else return QScriptValue(); }
void SceneResources::getResources() { ToonzScene *scene = m_scene; std::vector<TXshLevel *> levels; scene->getLevelSet()->listLevels(levels); std::vector<TXshLevel *>::iterator it; for (it = levels.begin(); it != levels.end(); ++it) { TXshSimpleLevel *sl = (*it)->getSimpleLevel(); if (sl) m_resources.push_back(new SceneLevel(scene, sl)); TXshPaletteLevel *pl = (*it)->getPaletteLevel(); if (pl) m_resources.push_back(new ScenePalette(scene, pl)); TXshSoundLevel *sdl = (*it)->getSoundLevel(); if (sdl) m_resources.push_back(new SceneSound(scene, sdl)); } }
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; }
void Vectorizer::setLevel(const TXshSimpleLevelP &level) { m_level = level; //Creo il livello pli TXshSimpleLevel *sl = m_level.getPointer(); if (!sl) return; int rowCount = sl->getFrameCount(); if (rowCount <= 0 || sl->isEmpty()) return; TXshLevel *xl; ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); // Build the new level name wstring levelName = sl->getName() + L"v"; { std::auto_ptr<NameBuilder> nameBuilder(NameBuilder::getBuilder(levelName)); for (;;) { levelName = nameBuilder->getNext(); if (scene->getLevelSet()->getLevel(levelName) == 0) break; } } TFilePath dstPath = sl->getPath().withName(levelName).withType("pli"); dstPath = scene->decodeFilePath(dstPath); bool overWrite = false; if (TSystem::doesExistFileOrLevel(dstPath)) { m_dialogShown = true; std::wstring name = m_dialog->execute(scene, dstPath, true); if (m_dialog->cancelPressed()) return; switch (m_dialog->getChoice()) { case OverwriteDialog::KEEP_OLD: { xl = scene->getLevelSet()->getLevel(levelName); if (!xl) xl = scene->loadLevel(dstPath); m_vLevel = xl->getSimpleLevel(); return; } CASE OverwriteDialog::OVERWRITE : overWrite = true; DEFAULT: levelName = name; } } xl = scene->createNewLevel(PLI_XSHLEVEL, levelName); TXshSimpleLevel *vl = xl->getSimpleLevel(); assert(vl); if (overWrite) { vl->setPath(scene->codeFilePath(dstPath)); vl->setName(levelName); } TPalette *palette = 0; if (sl->getType() == TZP_XSHLEVEL) palette = sl->getPalette(); palette = palette ? palette->clone() : new TPalette; palette->setPaletteName(vl->getName()); vl->setPalette(palette); m_vLevel = vl; }
void mergeColumns(int column, int mColumn, bool isRedo) { MergeColumnsSessionId++; TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet(); int start, end; xsh->getCellRange(column, start, end); if (start > end) return; vector<TXshCell> cell(end - start + 1); vector<TXshCell> mCell(end - start + 1); xsh->getCells(start, column, cell.size(), &(cell[0])); xsh->getCells(start, mColumn, cell.size(), &(mCell[0])); TXshColumn *col = xsh->getColumn(column); TXshColumn *mcol = xsh->getColumn(mColumn); vector<MatchlinePair> matchingLevels; std::set<TFrameId> alreadyDoneSet; TXshSimpleLevel *level = 0, *mLevel = 0; TXshLevelP xl; bool areRasters = false; std::map<TFrameId, QString> images; for (int i = 0; i < (int)cell.size(); i++) { if (cell[i].isEmpty() || mCell[i].isEmpty()) continue; if (!level) { level = cell[i].getSimpleLevel(); xl = cell[i].m_level; } else if (level != cell[i].getSimpleLevel()) { MsgBox(WARNING, QObject::tr("It is not possible to perform a merging involving more than one level per column.")); return; } if (!mLevel) mLevel = mCell[i].getSimpleLevel(); else if (mLevel != mCell[i].getSimpleLevel()) { MsgBox(WARNING, QObject::tr("It is not possible to perform a merging involving more than one level per column.")); return; } TImageP img = cell[i].getImage(true); TImageP match = mCell[i].getImage(false); TFrameId fid = cell[i].m_frameId; TFrameId mFid = mCell[i].m_frameId; if (!img || !match) continue; if (alreadyDoneSet.find(fid) == alreadyDoneSet.end()) { TRasterImageP timg = (TRasterImageP)img; TRasterImageP tmatch = (TRasterImageP)match; TVectorImageP vimg = (TVectorImageP)img; TVectorImageP vmatch = (TVectorImageP)match; if (timg) { if (!tmatch) { MsgBox(WARNING, QObject::tr("Only raster levels can be merged to a raster level.")); return; } areRasters = true; } else if (vimg) { if (!vmatch) { MsgBox(WARNING, QObject::tr("Only vector levels can be merged to a vector level.")); return; } } else { MsgBox(WARNING, QObject::tr("It is possible to merge only Toonz vector levels or standard raster levels.")); return; } QString id = "MergeColumnsUndo" + QString::number(MergeColumnsSessionId) + "-" + QString::number(fid.getNumber()); TImageCache::instance()->add(id, (timg) ? timg->cloneImage() : vimg->cloneImage()); images[fid] = id; TAffine imgAff, matchAff; getColumnPlacement(imgAff, xsh, start + i, column, false); getColumnPlacement(matchAff, xsh, start + i, mColumn, false); TAffine dpiAff = getDpiAffine(level, fid); TAffine mdpiAff = getDpiAffine(mLevel, mFid); matchingLevels.push_back(MatchlinePair(cell[i], imgAff * dpiAff, mCell[i], matchAff * mdpiAff)); alreadyDoneSet.insert(fid); } } if (matchingLevels.empty()) { MsgBox(WARNING, QObject::tr("It is possible to merge only Toonz vector levels or standard raster levels.")); return; } ToonzScene *sc = TApp::instance()->getCurrentScene()->getScene(); TXshSimpleLevel *simpleLevel = sc->getLevelSet()->getLevel(column)->getSimpleLevel(); if (!isRedo) TUndoManager::manager()->add(new MergeColumnsUndo(xl, MergeColumnsSessionId, column, level, images, mColumn, level->getPalette())); if (areRasters) { mergeRasterColumns(matchingLevels); for (int i = 0; i < (int)cell.size(); i++) //the saveboxes must be updated { if (cell[i].isEmpty() || mCell[i].isEmpty()) continue; if (!cell[i].getImage(false) || !mCell[i].getImage(false)) continue; ToolUtils::updateSaveBox(cell[i].getSimpleLevel(), cell[i].m_frameId); } } else mergeVectorColumns(matchingLevels); TXshLevel *sl = TApp::instance()->getCurrentScene()->getScene()->getLevelSet()->getLevel(column); vector<TFrameId> fidsss; sl->getFids(fidsss); invalidateIcons(sl, fidsss); sl->setDirtyFlag(true); level->setDirtyFlag(true); TApp::instance()->getCurrentXsheet()->notifyXsheetChanged(); }