예제 #1
0
	void onDeliver()
	{
		if (m_error) {
			m_error = false;
			MsgBox(DVGui::CRITICAL, QObject::tr("There was an error saving frames for the %1 level.").arg(QString::fromStdWString(m_fp.withoutParentDir().getWideString())));
		}

		bool isPreview = (m_fp.getType() == "noext");

		TImageCache::instance()->remove(toString(m_fp.getWideString() + L".0"));
		TNotifier::instance()->notify(TSceneNameChange());

		if (Preferences::instance()->isGeneratedMovieViewEnabled()) {
			if (!isPreview && (Preferences::instance()->isDefaultViewerEnabled()) &&
				(m_fp.getType() == "mov" || m_fp.getType() == "avi" || m_fp.getType() == "3gp")) {
				QString name = QString::fromStdString(m_fp.getName());
				int index;
				if ((index = name.indexOf("#RENDERID")) != -1) //!quite ugly I know....
					m_fp = m_fp.withName(name.left(index).toStdWString());

				if (!TSystem::showDocument(m_fp)) {
					QString msg(QObject::tr("It is not possible to display the file %1: no player associated with its format").arg(QString::fromStdWString(m_fp.withoutParentDir().getWideString())));
					MsgBox(WARNING, msg);
				}

			}

			else {
				int r0, r1, step;
				TApp *app = TApp::instance();
				ToonzScene *scene = app->getCurrentScene()->getScene();
				TOutputProperties &outputSettings = isPreview ? *scene->getProperties()->getPreviewProperties() : *scene->getProperties()->getOutputProperties();
				outputSettings.getRange(r0, r1, step);
				const TRenderSettings rs = outputSettings.getRenderSettings();
				if (r0 == 0 && r1 == -1)
					r0 = 0, r1 = scene->getFrameCount() - 1;

				double timeStretchFactor = isPreview ? 1.0 : (double)outputSettings.getRenderSettings().m_timeStretchTo /
																 outputSettings.getRenderSettings().m_timeStretchFrom;

				r0 = tfloor(r0 * timeStretchFactor);
				r1 = tceil((r1 + 1) * timeStretchFactor) - 1;

				TXsheet::SoundProperties *prop = new TXsheet::SoundProperties();
				prop->m_frameRate = outputSettings.getFrameRate();
				TSoundTrack *snd = app->getCurrentXsheet()->getXsheet()->makeSound(prop);
				if (outputSettings.getRenderSettings().m_stereoscopic) {
					assert(!isPreview);
					::viewFile(m_fp.withName(m_fp.getName() + "_l"), r0 + 1, r1 + 1, step, isPreview ? rs.m_shrinkX : 1, snd, 0, false, true);
					::viewFile(m_fp.withName(m_fp.getName() + "_r"), r0 + 1, r1 + 1, step, isPreview ? rs.m_shrinkX : 1, snd, 0, false, true);
				} else
					::viewFile(m_fp, r0 + 1, r1 + 1, step, isPreview ? rs.m_shrinkX : 1, snd, 0, false, true);
			}
		}
	}
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;
  }
}
예제 #3
0
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();
}
예제 #4
0
void InsertFxPopup::loadMacro()
{
	TFilePath fp = m_presetFolder + TFilePath("macroFx");
	try {
		if (TFileStatus(fp).isDirectory()) {
			TFilePathSet macros = TSystem::readDirectory(fp);
			if (macros.empty())
				return;

			QTreeWidgetItem *macroFolder = new QTreeWidgetItem((QTreeWidget *)0, QStringList(tr("Macro")));
			macroFolder->setData(0, Qt::UserRole, QVariant(toQString(fp)));
			macroFolder->setIcon(0, m_folderIcon);
			m_fxTree->addTopLevelItem(macroFolder);
			for (TFilePathSet::iterator it = macros.begin(); it != macros.end(); ++it) {
				TFilePath macroPath = *it;
				QString name(macroPath.getName().c_str());
				QTreeWidgetItem *macroItem = new QTreeWidgetItem((QTreeWidget *)0, QStringList(name));
				macroItem->setData(0, Qt::UserRole, QVariant(toQString(macroPath)));
				macroItem->setIcon(0, m_fxIcon);
				macroFolder->addChild(macroItem);
			}
		}
	} catch (...) {
	}
}
예제 #5
0
bool InsertFxPopup::loadPreset(QTreeWidgetItem *item)
{
	QString str = item->data(0, Qt::UserRole).toString();
	TFilePath presetsFilepath(m_presetFolder + str.toStdWString());
	int i;
	for (i = item->childCount() - 1; i >= 0; i--)
		item->removeChild(item->child(i));
	if (TFileStatus(presetsFilepath).isDirectory()) {
		TFilePathSet presets = TSystem::readDirectory(presetsFilepath);
		if (!presets.empty()) {
			for (TFilePathSet::iterator it2 = presets.begin(); it2 != presets.end(); ++it2) {
				TFilePath presetPath = *it2;
				QString name(presetPath.getName().c_str());
				QTreeWidgetItem *presetItem = new QTreeWidgetItem((QTreeWidget *)0, QStringList(name));
				presetItem->setData(0, Qt::UserRole, QVariant(toQString(presetPath)));
				item->addChild(presetItem);
				presetItem->setIcon(0, m_fxIcon);
			}
		} else
			return false;
	} else
		return false;

	return true;
}
예제 #6
0
bool TFilePath::match(const TFilePath &fp) const
{
	return getParentDir() == fp.getParentDir() &&
		   getName() == fp.getName() &&
		   getFrame() == fp.getFrame() &&
		   getType() == fp.getType();
}
예제 #7
0
std::string ResourceImporter::extractPsdSuffix(TFilePath &path) {
  if (path.getType() != "psd") return "";
  std::string name = path.getName();
  int i            = name.find("#");
  if (i == std::string::npos) return "";
  std::string suffix = name.substr(i);
  path               = path.withName(name.substr(0, i));
  return suffix;
}
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);
}
예제 #9
0
void TSystem::copyDir(const TFilePath &dst, const TFilePath &src) {
  QFileInfoList fil = QDir(toQString(src)).entryInfoList();

  QDir::current().mkdir(toQString(dst));

  int i;
  for (i = 0; i < fil.size(); i++) {
    QFileInfo fi = fil.at(i);
    if (fi.fileName() == QString(".") || fi.fileName() == QString(".."))
      continue;
    if (fi.isDir()) {
      TFilePath srcDir = TFilePath(fi.filePath().toStdString());
      TFilePath dstDir = dst + srcDir.getName();
      copyDir(dstDir, srcDir);
    } else
      QFile::copy(fi.filePath(),
                  toQString(dst) + QString("\\") + fi.fileName());
  }
}
예제 #10
0
void TLevelSet::saveFolder(TOStream &os, TFilePath folder) {
  std::map<std::string, std::string> attr;
  attr["name"]                                   = folder.getName();
  if (folder == getDefaultFolder()) attr["type"] = "default";
  os.openChild("folder", attr);
  std::vector<TFilePath> folders;
  listFolders(folders, folder);
  if (!folders.empty()) {
    for (int i = 0; i < (int)folders.size(); i++) saveFolder(os, folders[i]);
  }
  std::vector<TXshLevel *> levels;
  listLevels(levels, folder);
  if (!levels.empty()) {
    os.openChild("levels");
    for (int i = 0; i < (int)levels.size(); i++)
      if (m_saveSet.empty() || m_saveSet.count(levels[i]) > 0) os << levels[i];
    os.closeChild();
  }
  os.closeChild();
}
예제 #11
0
void InsertFxPopup::removePreset()
{
	QTreeWidgetItem *item = m_fxTree->currentItem();
	QString itemRole = item->data(0, Qt::UserRole).toString();

	TFilePath path = TFilePath(itemRole.toStdWString());

	QString question = QString(tr("Are you sure you want to delete %1?").arg(path.getName().c_str()));
	int ret = DVGui::MsgBox(question, tr("Yes"), tr("No"), 1);
	if (ret == 2 || ret == 0)
		return;

	try {
		TSystem::deleteFile(path);
	} catch (...) {
		error(QString(tr("It is not possible to delete %1.").arg(toQString(path))));
		return;
	}
	m_fxTree->removeItemWidget(item, 0);
	delete item;
	TApp::instance()->getCurrentFx()->notifyFxPresetRemoved();
}
예제 #12
0
/*! 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;
}
예제 #13
0
TFilePath ResourceImporter::buildPsd(const TFilePath &basePath, const string &suffix)
{
	return basePath.withName(basePath.getName() + suffix);
}
예제 #14
0
TFilePath ResourceImporter::codePath(const TFilePath &oldPath, const TFilePath &newActualPath)
{
	return oldPath.withName(newActualPath.getName());
}
예제 #15
0
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 (...) {
			}
		}
	}
}
예제 #16
0
//------------------------------------------------------------
// 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!");
}
예제 #17
0
// Per adesso non appare
// Costruisce la stringa delle info della psd da caricare che comparirà nel
// popup:
// Path, Dimensioni, numero di livelli, ecc..
static void doPSDInfo(TFilePath psdpath, QTreeWidget *psdTree) {
  psdTree->clear();
  try {
    TPSDReader *psdreader = new TPSDReader(psdpath);

    TPSDHeaderInfo header = psdreader->getPSDHeaderInfo();
    int width             = header.cols;
    int height            = header.rows;
    int depth             = header.depth;
    int channels          = header.channels;
    int layersCount       = header.layersCount;
    QString filename =
        QString::fromStdString(psdpath.getName() + psdpath.getDottedType());
    QString parentDir =
        QString::fromStdWString(psdpath.getParentDir().getWideString());
    QString dimension = QString::number(width) + "x" + QString::number(height);
    QList<QTreeWidgetItem *> items;
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0, QStringList(QString("Filename: %1").arg(filename))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Parent dir: %1").arg(parentDir))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Dimension: %1").arg(dimension))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Depth: %1").arg(QString::number(depth)))));
    items.append(new QTreeWidgetItem(
        (QTreeWidget *)0,
        QStringList(QString("Channels: %1").arg(QString::number(channels)))));
    QTreeWidgetItem *layersItem = new QTreeWidgetItem((QTreeWidget *)0);
    int count                   = 0;
    QList<QTreeWidgetItem *> layersItemChildren;
    layersItemChildren.append(layersItem);
    int scavenge = 0;
    for (int i = layersCount - 1; i >= 0; i--) {
      TPSDLayerInfo *li = psdreader->getLayerInfo(i);
      int width         = li->right - li->left;
      int height        = li->bottom - li->top;
      QString layerName = li->name;
      if (strcmp(li->name, "</Layer group>") == 0 ||
          strcmp(li->name, "</Layer set>") == 0) {
        scavenge--;
      } else if (li->section > 0 && li->section <= 3) {
        QTreeWidgetItem *child = new QTreeWidgetItem((QTreeWidget *)0);
        child->setText(0, layerName);
        layersItemChildren[scavenge]->addChild(child);
        layersItemChildren.append(child);
        scavenge++;
      } else if (width > 0 && height > 0) {
        if (scavenge >= 0) {
          layersItemChildren[scavenge]->addChild(new QTreeWidgetItem(
              (QTreeWidget *)0, QStringList(QString("%1").arg(layerName))));
          count++;
        }
      }
    }
    QString layerItemText =
        "Layers: " +
        QString::number(count);  //+" ("+QString::number(layersCount)+")";
    layersItem->setText(0, layerItemText);
    items.append(layersItem);

    psdTree->insertTopLevelItems(0, items);
  } catch (TImageException &e) {
    error(QString::fromStdString(::to_string(e.getMessage())));
    return;
  }
}