void ExportScenePopup::onExport()
{
	QApplication::setOverrideCursor(Qt::WaitCursor);
	TProjectManager *pm = TProjectManager::instance();
	TFilePath oldProjectPath = pm->getCurrentProjectPath();
	TFilePath projectPath;
	if (!m_createNewProject) {
		DvDirModelFileFolderNode *node = (DvDirModelFileFolderNode *)m_projectTreeView->getCurrentNode();
		if (!node || !pm->isProject(node->getPath())) {
			QApplication::restoreOverrideCursor();
			MsgBox(WARNING, tr("The folder you selected is not a project."));
			return;
		}
		projectPath = pm->projectFolderToProjectPath(node->getPath());
		assert(projectPath != TFilePath());
	} else //Create project
	{
		projectPath = createNewProject();
		if (projectPath == TFilePath()) {
			QApplication::restoreOverrideCursor();
			return;
		}
	}
	pm->setCurrentProjectPath(projectPath);

	std::vector<TFilePath> newScenes;
	int i;
	for (i = 0; i < m_scenes.size(); i++) {
		TFilePath newScenePath = importScene(m_scenes[i]);
		if (newScenePath == TFilePath())
			continue;
		newScenes.push_back(newScenePath);
	}
	pm->setCurrentProjectPath(oldProjectPath);
	if (newScenes.empty()) {
		QApplication::restoreOverrideCursor();
		MsgBox(WARNING, tr("There was an error exporting the scene."));
		return;
	}
	for (i = 0; i < newScenes.size(); i++)
		collectAssets(newScenes[i]);

	QApplication::restoreOverrideCursor();
	accept();
}
TFilePath ExportScenePopup::createNewProject()
{
	TProjectManager *pm = TProjectManager::instance();
	TFilePath projectName(m_newProjectName->text().toStdWString());
	if (projectName == TFilePath()) {
		MsgBox(WARNING, tr("The project name cannot be empty or contain any of the following characters:(new line)   \\ / : * ? \"  |"));
		return TFilePath();
	}
	if (projectName.isAbsolute()) {
		// bad project name
		MsgBox(WARNING, tr("The project name cannot be empty or contain any of the following characters:(new line)   \\ / : * ? \"  |"));
		return TFilePath();
	}
	if (pm->getProjectPathByName(projectName) != TFilePath()) {
		// project already exists
		MsgBox(WARNING, tr("The project name you specified is already used."));
		return TFilePath();
	}

	TFilePath currentProjectRoot;
	DvDirModelFileFolderNode *node = dynamic_cast<DvDirModelFileFolderNode *>(m_projectTreeView->getCurrentNode());
	if (node)
		currentProjectRoot = node->getPath();
	else
		currentProjectRoot = pm->getCurrentProjectRoot();
	TFilePath projectFolder = currentProjectRoot + projectName;
	TFilePath projectPath = pm->projectFolderToProjectPath(projectFolder);
	TProject *project = new TProject();

	TProjectP currentProject = pm->getCurrentProject();
	assert(currentProject);
	int i;
	for (i = 0; i < (int)currentProject->getFolderCount(); i++)
		project->setFolder(currentProject->getFolderName(i), currentProject->getFolder(i));
	project->save(projectPath);
	DvDirModel::instance()->refreshFolder(currentProjectRoot);

	return projectPath;
}
예제 #3
0
void ProjectCreatePopup::createProject() {
  if (!IoCmd::saveSceneIfNeeded(QObject::tr("Create project"))) return;

#ifdef LINETEST
  TnzCamera *camera = TnzCamera::instance();
  if (camera->isCameraConnected()) camera->cameraDisconnect();
#endif

  QFileInfo fi(m_nameFld->text());

  if (!isValidFileName(fi.baseName())) {
    error(
        tr("Project Name cannot be empty or contain any of the following "
           "characters:\n \\ / : * ? \" < > |"));
    return;
  }

  TProjectManager *pm   = TProjectManager::instance();
  TFilePath projectName = TFilePath(m_nameFld->text().toStdWString());
  if (projectName == TFilePath()) {
    return;
  }

  if (projectName.isAbsolute()) {
    error(tr("Bad project name: '%1' looks like an absolute file path")
              .arg(m_nameFld->text()));
    return;
  }

  if (pm->getProjectPathByName(projectName) != TFilePath()) {
    error(tr("Project '%1' already exists").arg(m_nameFld->text()));
    // project already exists
    return;
  }

  TFilePath currentProjectRoot;
  DvDirModelFileFolderNode *node =
      dynamic_cast<DvDirModelFileFolderNode *>(m_treeView->getCurrentNode());
  if (node)
    currentProjectRoot = node->getPath();
  else
    currentProjectRoot = pm->getCurrentProjectRoot();

  TFilePath projectFolder = currentProjectRoot + projectName;
  TFilePath projectPath   = pm->projectFolderToProjectPath(projectFolder);
  TProject *project       = new TProject();
  updateProjectFromFields(project);
  TProjectP currentProject = pm->getCurrentProject();
  project->setSceneProperties(currentProject->getSceneProperties());
  try {
    bool isSaved = project->save(projectPath);
    if (!isSaved)
      DVGui::error(tr("It is not possible to create the %1 project.")
                       .arg(toQString(projectPath)));
  } catch (TSystemException se) {
    DVGui::warning(QString::fromStdWString(se.getMessage()));
    return;
  }
  pm->setCurrentProjectPath(projectPath);
  IoCmd::newScene();
  DvDirModel::instance()->refreshFolder(projectFolder.getParentDir());
  accept();
}