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;
}
예제 #2
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();
}