TFx *InsertFxPopup::createFx() { TApp *app = TApp::instance(); ToonzScene *scene = app->getCurrentScene()->getScene(); TXsheet *xsh = scene->getXsheet(); QTreeWidgetItem *item = m_fxTree->currentItem(); QString text = item->data(0, Qt::UserRole).toString(); if (text.isEmpty()) return 0; TFx *fx; TFilePath path = TFilePath(text.toStdWString()); if (TFileStatus(path).doesExist() && TFileStatus(path.getParentDir()).isDirectory()) { std::string folder = path.getParentDir().getName(); if (folder == "macroFx") //Devo caricare una macro fx = createMacroFxByPath(path); else //Verifico se devo caricare un preset { folder = path.getParentDir().getParentDir().getName(); if (folder == "presets") //Devo caricare un preset fx = createPresetFxByName(path); } } else fx = createFxByName(text.toStdString()); if (fx) return fx; else return 0; }
void InsertFxPopup::contextMenuEvent(QContextMenuEvent *event) { QTreeWidgetItem *item = m_fxTree->currentItem(); QString itemRole = item->data(0, Qt::UserRole).toString(); TFilePath path = TFilePath(itemRole.toStdWString()); if (TFileStatus(path).doesExist() && TFileStatus(path.getParentDir()).isDirectory()) { QMenu *menu = new QMenu(this); std::string folder = path.getParentDir().getName(); if (folder == "macroFx") //Menu' macro { QAction *remove = new QAction(tr("Remove Macro FX"), menu); connect(remove, SIGNAL(triggered()), this, SLOT(removePreset())); menu->addAction(remove); } else //Verifico se devo caricare un preset { folder = path.getParentDir().getParentDir().getName(); if (folder == "presets") //Menu' preset { QAction *remove = new QAction(tr("Remove Preset"), menu); connect(remove, SIGNAL(triggered()), this, SLOT(removePreset())); menu->addAction(remove); } } menu->exec(event->globalPos()); } }
bool TSystem::doesExistFileOrLevel(const TFilePath &fp) { if (TFileStatus(fp).doesExist()) return true; if (fp.isLevelName()) { const TFilePath &parentDir = fp.getParentDir(); if (!TFileStatus(parentDir).doesExist()) return false; TFilePathSet files; try { files = TSystem::readDirectory(parentDir, false, true, true); } catch (...) { } TFilePathSet::iterator it, end = files.end(); for (it = files.begin(); it != end; ++it) { if (it->getLevelNameW() == fp.getLevelNameW()) return true; } } else if (fp.getType() == "psd") { QString name(QString::fromStdWString(fp.getWideName())); name.append(QString::fromStdString(fp.getDottedType())); int sepPos = name.indexOf("#"); int dotPos = name.indexOf(".", sepPos); int removeChars = dotPos - sepPos; int doubleUnderscorePos = name.indexOf("__", sepPos); if (doubleUnderscorePos > 0) removeChars = doubleUnderscorePos - sepPos; name.remove(sepPos, removeChars); TFilePath psdpath(fp.getParentDir() + TFilePath(name.toStdWString())); if (TFileStatus(psdpath).doesExist()) return true; } return false; }
void PsdSettingsPopup::doPsdParser() { TFilePath psdpath = TApp::instance()->getCurrentScene()->getScene()->decodeFilePath(m_path); std::string mode = ""; switch (m_mode) { case FLAT: { break; } case FRAMES: { mode = "#frames"; std::string name = psdpath.getName() + "#1" + mode + psdpath.getDottedType(); psdpath = psdpath.getParentDir() + TFilePath(name); break; } case COLUMNS: { std::string name = psdpath.getName() + "#1" + psdpath.getDottedType(); psdpath = psdpath.getParentDir() + TFilePath(name); break; } case FOLDER: { mode = "#group"; std::string name = psdpath.getName() + "#1" + mode + psdpath.getDottedType(); psdpath = psdpath.getParentDir() + TFilePath(name); break; } default: { assert(false); return; } } try { m_psdparser = new TPSDParser(psdpath); m_psdLevelPaths.clear(); for (int i = 0; i < m_psdparser->getLevelsCount(); i++) { int layerId = m_psdparser->getLevelId(i); std::string name = m_path.getName(); if (layerId > 0 && m_mode != FRAMES) { if (m_levelNameType->currentIndex() == 0) // FileName#LevelName name += "#" + std::to_string(layerId); else // LevelName name += "##" + std::to_string(layerId); } if (mode != "") name += mode; name += m_path.getDottedType(); TFilePath psdpath = m_path.getParentDir() + TFilePath(name); m_psdLevelPaths.push_back(psdpath); } } catch (TImageException &e) { error(QString::fromStdString(::to_string(e.getMessage()))); return; } }
void TSystem::renameFileOrLevel_throw(const TFilePath &dst, const TFilePath &src, bool renamePalette) { if (renamePalette && ((src.getType() == "tlv") || (src.getType() == "tzp") || (src.getType() == "tzu"))) { // Special case: since renames cannot be 'grouped' in the UI, palettes are // automatically // renamed here if required const char *type = (src.getType() == "tlv") ? "tpl" : "plt"; TFilePath srcpltname(src.withNoFrame().withType(type)); TFilePath dstpltname(dst.withNoFrame().withType(type)); if (TSystem::doesExistFileOrLevel(src) && TSystem::doesExistFileOrLevel(srcpltname)) TSystem::renameFile(dstpltname, srcpltname, false); } if (src.isLevelName()) { TFilePathSet files; files = TSystem::readDirectory(src.getParentDir(), false); for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) { if (it->getLevelName() == src.getLevelName()) { TFilePath src1 = *it; TFilePath dst1 = dst.withFrame(it->getFrame()); TSystem::renameFile(dst1, src1); } } } else TSystem::renameFile(dst, src); }
void InsertFxPopup::updatePresets() { int i; for (i = 0; i < m_fxTree->topLevelItemCount(); i++) { QTreeWidgetItem *folder = m_fxTree->topLevelItem(i); TFilePath path = TFilePath(folder->data(0, Qt::UserRole).toString().toStdWString()); if (folder->text(0).toStdString() == "Plugins") { continue; } if (path.getName() == "macroFx") { int j; for (j = folder->childCount() - 1; j >= 0; j--) folder->removeChild(folder->child(j)); m_fxTree->removeItemWidget(folder, 0); delete folder; } else if (path.getParentDir().getName() == "macroFx") continue; else for (int i = 0; i < folder->childCount(); i++) { bool isPresetLoaded = loadPreset(folder->child(i)); if (isPresetLoaded) folder->child(i)->setIcon(0, m_presetIcon); else folder->child(i)->setIcon(0, m_fxIcon); } } loadMacro(); update(); }
void TPanelTitleBarButtonForSafeArea::getSafeAreaNameList( QList<QString> &nameList) { TFilePath fp = TEnv::getConfigDir(); QString currentSafeAreaName = QString::fromStdString(EnvSafeAreaName); std::string safeAreaFileName = "safearea.ini"; while (!TFileStatus(fp + safeAreaFileName).doesExist() && !fp.isRoot() && fp.getParentDir() != TFilePath()) fp = fp.getParentDir(); fp = fp + safeAreaFileName; if (TFileStatus(fp).doesExist()) { QSettings settings(toQString(fp), QSettings::IniFormat); // find the current safearea name from the list QStringList groups = settings.childGroups(); for (int g = 0; g < groups.size(); g++) { settings.beginGroup(groups.at(g)); nameList.push_back(settings.value("name", "").toString()); settings.endGroup(); } } }
bool TFilePath::match(const TFilePath &fp) const { return getParentDir() == fp.getParentDir() && getName() == fp.getName() && getFrame() == fp.getFrame() && getType() == fp.getType(); }
void RenderCommand::doRender(bool isPreview) { bool isWritable = true; bool isMultiFrame; /*-- 初期化処理。フレーム範囲の計算や、Renderの場合はOutputSettingsから保存先パスも作る --*/ if (!init(isPreview)) return; if (m_fp.getDots() == ".") { isMultiFrame = false; TFileStatus fs(m_fp); if (fs.doesExist()) isWritable = fs.isWritable(); } else { isMultiFrame = true; TFilePath dir = m_fp.getParentDir(); QDir qDir(QString::fromStdWString(dir.getWideString())); QString levelName = QRegExp::escape(QString::fromStdWString(m_fp.getWideName())); QString levelType = QString::fromStdString(m_fp.getType()); QString exp(levelName + ".[0-9]{1,4}." + levelType); QRegExp regExp(exp); QStringList list = qDir.entryList(QDir::Files); QStringList livelFrames = list.filter(regExp); int i; for (i = 0; i < livelFrames.size() && isWritable; i++) { TFilePath frame = dir + TFilePath(livelFrames[i].toStdWString()); if (frame.isEmpty() || !frame.isAbsolute()) continue; TFileStatus fs(frame); isWritable = fs.isWritable(); } } if (!isWritable) { string str = "It is not possible to write the output: the file"; str += isMultiFrame ? "s are read only." : " is read only."; MsgBox(WARNING, QString::fromStdString(str)); return; } ToonzScene *scene = 0; TCamera *camera = 0; try { /*-- Xsheetノードに繋がっている各ラインごとに計算するモード。 MultipleRender で Schematic Flows または Fx Schematic Terminal Nodes が選択されている場合 --*/ if (m_multimediaRender && m_fp.getType() != "swf") //swf is not currently supported on multimedia... multimediaRender(); else if (!isPreview && m_fp.getType() == "swf") flashRender(); else /*-- 通常のRendering --*/ rasterRender(isPreview); } catch (TException &e) { MsgBox(WARNING, QString::fromStdString(toString(e.getMessage()))); } catch (...) { MsgBox(WARNING, QObject::tr("It is not possible to complete the rendering.")); } }
inline static TFilePath getRelativePath(const TFilePath &file, const TFilePath &relTo) { QDir relToDir( QString::fromStdWString(relTo.getParentDir().getWideString())); QString relFileStr(relToDir.relativeFilePath( QString::fromStdWString(file.getWideString()))); return TFilePath(relFileStr.toStdWString()); }
inline static TFilePath getAbsolutePath(const TFilePath &file, const TFilePath &relTo) { QDir relToDir( QString::fromStdWString(relTo.getParentDir().getWideString())); QString absFileStr(relToDir.absoluteFilePath( QString::fromStdWString(file.getWideString()))); return TFilePath(absFileStr.toStdWString()); }
TFilePath CleanupParameters::getPath(ToonzScene *scene) const { if (m_path == TFilePath()) { int levelType = (m_lineProcessingMode != lpNone) ? TZP_XSHLEVEL : OVL_XSHLEVEL; TFilePath fp = scene->getDefaultLevelPath(levelType); return fp.getParentDir(); } else return scene->decodeSavePath(m_path); }
void StudioPaletteTreeViewer::dropEvent(QDropEvent *event) { TFilePath newPath = getItemPath(m_dropItem); resetDropItem(); if (newPath.isEmpty()) return; const QMimeData *mimeData = event->mimeData(); const PaletteData *paletteData = dynamic_cast<const PaletteData *>(mimeData); if (paletteData) { if (paletteData->hasOnlyPalette()) { TPalette *palette = paletteData->getPalette(); if (!palette) return; try { StudioPaletteCmd::createPalette( newPath, ::to_string(palette->getPaletteName()), palette); } catch (TException &e) { error("Can't create palette: " + QString(::to_string(e.getMessage()).c_str())); } catch (...) { error("Can't create palette"); } } return; } if (!mimeData->hasUrls() || mimeData->urls().size() == 0) return; QList<QUrl> urls = mimeData->urls(); TUndoManager::manager()->beginBlock(); int i; for (i = 0; i < urls.size(); i++) { QUrl url = urls[i]; TFilePath path = TFilePath(url.toLocalFile().toStdWString()); StudioPalette *studioPalette = StudioPalette::instance(); if (path == newPath || path.getParentDir() == newPath) continue; if (isInStudioPalette(path)) { TFilePath newPalettePath = newPath + TFilePath(path.getWideName() + ::to_wstring(path.getDottedType())); try { StudioPaletteCmd::movePalette(newPalettePath, path); } catch (TException &e) { error("Can't rename palette: " + QString(::to_string(e.getMessage()).c_str())); } catch (...) { error("Can't rename palette"); } } } TUndoManager::manager()->endBlock(); event->setDropAction(Qt::CopyAction); event->accept(); }
void TSystem::hideFile(const TFilePath &fp) { #ifdef _WIN32 if (!SetFileAttributesW(fp.getWideString().c_str(), FILE_ATTRIBUTE_HIDDEN)) throw TSystemException(fp, "can't hide file!"); #else // MACOSX, and others TSystem::renameFile(TFilePath(fp.getParentDir() + L"." + fp.getLevelNameW()), fp); #endif }
void PsdSettingsPopup::setPath(const TFilePath &path) { m_path = path; // doPSDInfo(path,m_psdTree); QString filename = QString::fromStdString(path.getName()); //+psdpath.getDottedType()); QString pathLbl = QString::fromStdWString(path.getParentDir().getWideString()); m_filename->setText(filename); m_parentDir->setText(pathLbl); }
Convert2Tlv::Convert2Tlv(const TFilePath &filepath1, const TFilePath &filepath2, const TFilePath &outFolder, const QString &outName, int from, int to, bool doAutoclose, const TFilePath &palettePath, int colorTolerance, int antialiasType, int antialiasValue, bool isUnpaintedFromNAA) : m_size(0, 0), m_level1(), m_levelIn1(), m_levelIn2(), m_levelOut(), m_autoclose(doAutoclose), m_premultiply(false), m_count(0), m_from(from), m_to(to), m_palettePath(palettePath), m_colorTolerance(colorTolerance), m_palette(0), m_antialiasType(antialiasType), m_antialiasValue(antialiasValue), m_isUnpaintedFromNAA(isUnpaintedFromNAA) { if (filepath1 != TFilePath()) { m_levelIn1 = filepath1.getParentDir() + filepath1.getLevelName(); if (outFolder != TFilePath()) m_levelOut = m_levelIn1.withParentDir(outFolder).withNoFrame().withType("tlv"); else m_levelOut = m_levelIn1.withNoFrame().withType("tlv"); //filePaths[0].getParentDir() + TFilePath(filePaths[0].getWideName() + L".tlv"); if (outName != "") m_levelOut = m_levelOut.withName(outName.toStdString()); } if (filepath2 != TFilePath()) m_levelIn2 = filepath2.getParentDir() + filepath2.getLevelName(); }
void StudioPaletteTreeViewer::onItemChanged(QTreeWidgetItem *item, int column) { if (item != currentItem() || isRootItem(item)) return; wstring name = item->text(column).toStdWString(); TFilePath oldPath = getCurrentFolderPath(); if (oldPath.isEmpty() || name.empty() || oldPath.getWideName() == name) return; TFilePath newPath(oldPath.getParentDir() + TFilePath(name + ::to_wstring(oldPath.getDottedType()))); try { StudioPaletteCmd::movePalette(newPath, oldPath); } catch (TException &e) { error(QString(::to_string(e.getMessage()).c_str())); item->setText(column, QString::fromStdWString(oldPath.getWideName())); } catch (...) { error("Can't rename file"); item->setText(column, QString::fromStdWString(oldPath.getWideName())); } refreshItem(getItem(oldPath.getParentDir())); setCurrentItem(getItem(newPath)); }
void TSystem::hideFileOrLevel_throw(const TFilePath &fp) { if (fp.isLevelName()) { TFilePathSet files; files = TSystem::readDirectory(fp.getParentDir(), false); TFilePathSet::iterator it, end = files.end(); for (it = files.begin(); it != end; ++it) { if (it->getLevelNameW() == fp.getLevelNameW()) TSystem::hideFile(*it); } } else TSystem::hideFile(fp); }
bool TSystem::touchParentDir(const TFilePath &fp) { TFilePath parentDir = fp.getParentDir(); TFileStatus fs(parentDir); if (fs.isDirectory()) return true; else if (fs.doesExist()) return false; try { mkDir(parentDir); } catch (...) { return false; } return true; }
/*! Create palette \b palette in folder \b folderName with name \b paletteName. If there are any problems send an error message. */ TFilePath StudioPaletteCmd::createPalette(const TFilePath &folderName, std::string paletteName, const TPalette *palette) { TFilePath palettePath; TFileStatus status(folderName); if (!status.isDirectory()) throw TException("Select a folder."); if (!status.doesExist()) { TSystem::mkDir(folderName); FolderListenerManager::instance()->notifyFolderChanged( folderName.getParentDir()); } palettePath = StudioPalette::instance()->createPalette(folderName, paletteName); if (palette) StudioPalette::instance()->setPalette(palettePath, palette, true); TUndoManager::manager()->add(new CreatePaletteUndo(palettePath)); return palettePath; }
void TSystem::copyFileOrLevel_throw(const TFilePath &dst, const TFilePath &src) { if (src.isLevelName()) { TFilePathSet files; files = TSystem::readDirectory(src.getParentDir(), false); TFilePathSet::iterator it, end = files.end(); for (it = files.begin(); it != end; ++it) { if (it->getLevelNameW() == src.getLevelNameW()) { TFilePath src1 = *it; TFilePath dst1 = dst.withFrame(it->getFrame()); TSystem::copyFile(dst1, src1); } } } else TSystem::copyFile(dst, src); }
void CasmSubmitPage::Data::loadCasm(const TFilePath &fp) { if (!TFileStatus(fp).doesExist()) { string msg = toString(fp.getWideString()) + "\n"; msg += "File not found\n"; msg += "Please verify that the path and file name are correct"; m_filepathTextField->setText(""); TMessage::error(msg); return; } Application::instance()->setCurrentFolder(fp.getParentDir()); string uncString = convertToUncString(fp); m_filepathTextField->setText(uncString); m_taskNameTextField->setText(TFilePath(uncString).getName()); #ifdef WIN32 int x = uncString.find("\\", 2); while (x != string::npos) { uncString.replace(x, 1, "/", 0, 1); x = uncString.find("\\", x + 1); } #endif TFilePath uncFilePath = TFilePath(uncString); CasmFileInfo casmFileInfo(uncFilePath); int start, end; bool interlaced; casmFileInfo.getFrameRange(start, end, interlaced); if (m_casmTask) delete m_casmTask; m_casmTask = new CasmTask; m_casmTask->m_casmFile = uncString; m_casmTask->m_start = start; m_casmTask->m_end = end; m_casmTask->m_step = 1; m_configPanel->setTask(m_casmTask); }
/*! Loads the project specified in \b projectPath.\n \b projectPath must be an absolute path. */ void TProject::load(const TFilePath &projectPath) { assert(isAProjectPath(projectPath)); TFilePath latestProjectPath = getLatestVersionProjectPath(projectPath); TFilePath inputProjectPath = searchProjectPath(projectPath.getParentDir()); TProjectManager *pm = TProjectManager::instance(); m_name = pm->projectPathToProjectName(latestProjectPath); m_path = latestProjectPath; m_folderNames.clear(); m_folders.clear(); m_useScenePathFlags.clear(); delete m_sprop; m_sprop = new TSceneProperties(); // Read the project TIStream is(inputProjectPath); if (!is) return; string tagName; if (!is.matchTag(tagName) || tagName != "project") return; while (is.matchTag(tagName)) { if (tagName == "folders") { while (is.matchTag(tagName)) { if (tagName == "folder") { string name = is.getTagAttribute("name"); TFilePath path(is.getTagAttribute("path")); setFolder(name, path); string useScenePath = is.getTagAttribute("useScenePath"); setUseScenePath(name, useScenePath == "yes"); } else throw TException("expected <folder>"); } is.matchEndTag(); } else if (tagName == "version") { int major, minor; is >> major >> minor; is.setVersion(VersionNumber(major, minor)); is.matchEndTag(); } else if (tagName == "sceneProperties") {
/*! Returns the index of the folder specified in the path \b folderDir. Returns -1 if \b folderDir isn't a folder of the project. */ int TProject::getFolderIndexFromPath(const TFilePath &folderDir) { TFilePath scenePath = decode(getFolder(Scenes)); bool sceneDependentScenePath = false; if (scenePath.getName().find("$scene") != string::npos) { scenePath = scenePath.getParentDir(); sceneDependentScenePath = true; } int folderIndex; for (folderIndex = 0; folderIndex < getFolderCount(); folderIndex++) if (isConstantFolder(folderIndex)) { TFilePath fp = decode(getFolder(folderIndex)); if (fp == folderDir) return folderIndex; } else { TFilePath fp = decode(getFolder(folderIndex)); wstring a = fp.getWideString(); wstring b = folderDir.getWideString(); int alen = a.length(); int blen = b.length(); int i = a.find(L"$scene"); assert(i != (int)wstring::npos); if (i == (int)wstring::npos) continue; int j = i + 1; while (j < alen && isalnum(a[j])) j++; // a.substr(i,j-i) == "$scenexxxx" int k = j + blen - alen; if (!(0 <= i && i < k && k <= blen)) continue; assert(i < blen); if (i > 0 && a.substr(0, i) != b.substr(0, i)) continue; if (k < blen && (j >= alen || a.substr(j) != b.substr(k))) continue; wstring v = b.substr(i, k - i); TFilePath scene(v + L".tnz"); if (sceneDependentScenePath) scene = scenePath + scene.getWideName() + scene; else scene = scenePath + scene; if (TFileStatus(scene).doesExist()) return folderIndex; } return -1; }
/* "Save In" フィールドのためのFileField。browseDirectoryを再実装して、フィールドが空欄のときは、 カレントレベル(Scan画像。TIF等)の入っているフォルダの1つ上をデフォルトフォルダにして開くようにしたい。 */ void CleanupSaveInField::browseDirectory() { if (!m_fileBrowseButton->hasFocus()) return; QString directory = QString(); if (!m_browserPopupController) return; /* ここで、m_lastSelectedPathが空のとき、カレントレベルがScan画像の場合、 そのファイルの入っているフォルダの1つ上のフォルダを初期フォルダにする */ QString initialFolder = m_lastSelectedPath; if (initialFolder.isEmpty()) { /*--- 親Widgetを取得する ---*/ CleanupSettingsPane *parentCSP = dynamic_cast<CleanupSettingsPane *>(parentWidget()); if (parentCSP) { TFilePath lastSelectedPath = parentCSP->getLastSelectedPath(); if (!lastSelectedPath.isEmpty()) { /*---- * 親Widgetのm_lastSelectedPathが、CLNファイルの見込み所在地なので、その1つ上のフォルダを初期フォルダにする。---*/ initialFolder = QString::fromStdWString( lastSelectedPath.getParentDir().getParentDir().getWideString()); } } } m_browserPopupController->openPopup(QStringList(), true, initialFolder); if (m_browserPopupController->isExecute()) directory = m_browserPopupController->getPath(); if (!directory.isEmpty()) { setPath(directory); m_lastSelectedPath = directory; emit pathChanged(); return; } }
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 RenderCommand::init(bool isPreview) { ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene(); TSceneProperties *sprop = scene->getProperties(); /*-- Preview/Renderに応じてそれぞれのSettingを取得 --*/ TOutputProperties &outputSettings = isPreview ? *sprop->getPreviewProperties() : *sprop->getOutputProperties(); outputSettings.getRange(m_r0, m_r1, m_step); /*-- シーン全体のレンダリングの場合、m_r1をScene長に設定 --*/ if (m_r0 == 0 && m_r1 == -1) { m_r0 = 0; m_r1 = scene->getFrameCount() - 1; } if (m_r0 < 0) m_r0 = 0; if (m_r1 >= scene->getFrameCount()) m_r1 = scene->getFrameCount() - 1; if (m_r1 < m_r0) { MsgBox(WARNING, QObject::tr("The command cannot be executed because the scene is empty.")); return false; // throw TException("empty scene"); // non so perche', ma termina il programma // nonostante il try all'inizio } // Initialize the preview case /*TRenderSettings rs = sprop->getPreviewProperties()->getRenderSettings(); TRenderSettings rso = sprop->getOutputProperties()->getRenderSettings(); rs.m_stereoscopic=true; rs.m_stereoscopicShift=0.05; rso.m_stereoscopic=true; rso.m_stereoscopicShift=0.05; sprop->getPreviewProperties()->setRenderSettings(rs); sprop->getOutputProperties()->setRenderSettings(rso);*/ if (isPreview) { /*-- PreviewではTimeStretchを考慮しないので、そのままフレーム値を格納してゆく --*/ m_numFrames = (int)(m_r1 - m_r0 + 1); m_r = m_r0; m_stepd = m_step; m_multimediaRender = 0; return true; } // Full render case // Read the output filepath TFilePath fp = outputSettings.getPath(); /*-- ファイル名が指定されていない場合は、シーン名を出力ファイル名にする --*/ if (fp.getWideName() == L"") fp = fp.withName(scene->getScenePath().getName()); /*-- ラスタ画像の場合、ファイル名にフレーム番号を追加 --*/ if (TFileType::getInfo(fp) == TFileType::RASTER_IMAGE || fp.getType() == "pct" || fp.getType() == "pic" || fp.getType() == "pict") //pct e' un formato"livello" (ha i settings di quicktime) ma fatto di diversi frames fp = fp.withFrame(TFrameId::EMPTY_FRAME); fp = scene->decodeFilePath(fp); if (!TFileStatus(fp.getParentDir()).doesExist()) { try { TFilePath parent = fp.getParentDir(); TSystem::mkDir(parent); DvDirModel::instance()->refreshFolder(parent.getParentDir()); } catch (TException &e) { MsgBox(WARNING, QObject::tr("It is not possible to create folder : %1").arg(QString::fromStdString(toString(e.getMessage())))); return false; } catch (...) { MsgBox(WARNING, QObject::tr("It is not possible to create a folder.")); return false; } } m_fp = fp; // Retrieve camera infos const TCamera *camera = isPreview ? scene->getCurrentPreviewCamera() : scene->getCurrentCamera(); TDimension cameraSize = camera->getRes(); TPointD cameraDpi = camera->getDpi(); // Retrieve render interval/step/times double stretchTo = (double)outputSettings.getRenderSettings().m_timeStretchTo; double stretchFrom = (double)outputSettings.getRenderSettings().m_timeStretchFrom; m_timeStretchFactor = stretchTo / stretchFrom; m_stepd = m_step / m_timeStretchFactor; int stretchedR0 = tfloor(m_r0 * m_timeStretchFactor); int stretchedR1 = tceil((m_r1 + 1) * m_timeStretchFactor) - 1; m_r = stretchedR0 / m_timeStretchFactor; m_numFrames = (stretchedR1 - stretchedR0) / m_step + 1; // Update the multimedia render switch m_multimediaRender = outputSettings.getMultimediaRendering(); return true; }
void SceneLevel::save() { TFilePath fp = m_oldPath; SceneResource::updatePath(fp); TFilePath actualFp = m_scene->decodeFilePath(fp); actualFp = restorePsdPath(actualFp); TFilePath oldActualPath = restorePsdPath(m_oldActualPath); assert(actualFp.getWideString() == L"" || actualFp.getWideString()[0] != L'+'); if (actualFp != oldActualPath || !TSystem::doesExistFileOrLevel(oldActualPath) || m_sl->getProperties()->getDirtyFlag() || (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag())) { try { TSystem::touchParentDir(actualFp); if (actualFp != oldActualPath && TSystem::doesExistFileOrLevel(oldActualPath) && m_sl->getProperties()->getDirtyFlag() == false && (!m_sl->getPalette() || (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag() == false))) { try { TXshSimpleLevel::copyFiles(actualFp, oldActualPath); } catch (...) { } //Must NOT KEEP FRAMES, it generate a level frames bind necessary to imageBuilder path refresh. m_sl->setPath(fp, false); } else { m_sl->save(actualFp, oldActualPath); if ((actualFp.getType() == "tlv" || actualFp.getType() == "pli") && actualFp != oldActualPath && m_oldRefImgPath != TFilePath()) { //Devo preoccuparmi dell'eventuale livello colormodel TFilePath actualRefImagPath = m_scene->decodeFilePath(m_oldRefImgPath); TFilePath actualRefImagPathTpl = actualRefImagPath.withType("tpl"); TFilePath oldRefImagPathTpl = m_oldActualRefImgPath.withType("tpl"); TSystem::copyFile(actualRefImagPath, m_oldActualRefImgPath); if (actualRefImagPath.getType() == "tlv") TSystem::copyFile(actualRefImagPathTpl, oldRefImagPathTpl); } if (actualFp.getType() == "tif" || actualFp.getType() == "tiff" || actualFp.getType() == "tga" || actualFp.getType() == "tzi") { TFilePath clnin = oldActualPath.withNoFrame().withType("cln"); if (TSystem::doesExistFileOrLevel(clnin)) TSystem::copyFile(actualFp.withNoFrame().withType("cln"), clnin); } } //Se il livello e' tlv verifico se esiste il corrispondente unpainted ed in caso affermativo lo copio. //Questo controllo viene fatto qui e non nella copia o nel salvataggio del livello perche' in generale //non si vuole che il livello unpainted venga copiato con il livello. if (actualFp.getType() == "tlv") { TFilePath oldUnpaintedLevelPath = oldActualPath.getParentDir() + TFilePath(oldActualPath.getName() + "-unpainted." + oldActualPath.getType()); TFilePath unpaintedLevelPath = actualFp.getParentDir() + TFilePath(actualFp.getName() + "-unpainted." + actualFp.getType()); if (TSystem::doesExistFileOrLevel(oldUnpaintedLevelPath) && !TSystem::doesExistFileOrLevel(unpaintedLevelPath)) TSystem::copyFile(unpaintedLevelPath, oldUnpaintedLevelPath); TFilePath oldUnpaintedPalettePath = oldUnpaintedLevelPath.withType("tpl"); TFilePath unpaintedPalettePath = unpaintedLevelPath.withType("tpl"); if (TSystem::doesExistFileOrLevel(oldUnpaintedPalettePath) && !TSystem::doesExistFileOrLevel(unpaintedPalettePath)) TSystem::copyFile(unpaintedPalettePath, oldUnpaintedPalettePath); } } catch (...) { } } fp = m_oldScannedPath; if (fp != TFilePath()) { SceneResource::updatePath(fp); actualFp = m_scene->decodeFilePath(fp); if (actualFp != m_oldActualScannedPath && TSystem::doesExistFileOrLevel(m_oldActualScannedPath)) { try { TSystem::touchParentDir(actualFp); TSystem::copyFileOrLevel_throw(actualFp, m_oldActualScannedPath); m_sl->clearFrames(); m_sl->load(); } catch (...) { } } } }
TFilePath TSystem::getBinDir() { TFilePath fp = TFilePath(QCoreApplication::applicationFilePath().toStdString()); return fp.getParentDir(); }
//------------------------------------------------------------ // gestire exception void TSystem::rmDir(const TFilePath &path) { if (!QDir(toQString(path.getParentDir())) .rmdir(QString::fromStdString(path.getName()))) throw TSystemException(path, "can't remove folder!"); }