예제 #1
0
void QmlProject::parseProject(RefreshOptions options)
{
    Core::MessageManager *messageManager = Core::ICore::messageManager();
    if (options & Files) {
        if (options & ProjectFile)
            delete m_projectItem.data();
        if (!m_projectItem) {
            Utils::FileReader reader;
            if (reader.fetch(m_fileName)) {
                QDeclarativeComponent *component = new QDeclarativeComponent(&m_engine, this);
                component->setData(reader.data(), QUrl::fromLocalFile(m_fileName));
                if (component->isReady()
                    && qobject_cast<QmlProjectItem*>(component->create())) {
                    m_projectItem = qobject_cast<QmlProjectItem*>(component->create());
                    connect(m_projectItem.data(), SIGNAL(qmlFilesChanged(QSet<QString>,QSet<QString>)),
                            this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));
                } else {
                    messageManager->printToOutputPane(tr("Error while loading project file %1.").arg(m_fileName), Core::MessageManager::NoModeSwitch);
                    messageManager->printToOutputPane(component->errorString(), Core::MessageManager::NoModeSwitch);
                }
            } else {
                messageManager->printToOutputPane(tr("QML project: %1").arg(reader.errorString()), Core::MessageManager::NoModeSwitch);
            }
        }
        if (m_projectItem) {
            m_projectItem.data()->setSourceDirectory(projectDir().path());
            m_modelManager->updateSourceFiles(m_projectItem.data()->files(), true);

            QString mainFilePath = m_projectItem.data()->mainFile();
            if (!mainFilePath.isEmpty()) {
                mainFilePath = projectDir().absoluteFilePath(mainFilePath);
                Utils::FileReader reader;
                QString errorMessage;
                if (!reader.fetch(mainFilePath, &errorMessage)) {
                    messageManager->printToOutputPane(
                                tr("Warning while loading project file %1.").arg(m_fileName),
                                Core::MessageManager::NoModeSwitch);
                    messageManager->printToOutputPane(errorMessage, Core::MessageManager::NoModeSwitch);
                } else {
                    m_defaultImport = detectImport(QString::fromUtf8(reader.data()));
                }
            }
        }
        m_rootNode->refresh();
    }

    if (options & Configuration) {
        // update configuration
    }

    if (options & Files)
        emit fileListChanged();
}
예제 #2
0
/*
  Add a filepath to this project's file list.
  It's path should be relative to the project directory.
*/
bool ProjectManager::addToProjectFile(QString projectPath, QString newFilePath, QString buildtype)
{
  bool retval = false;
  QDomDocument newProjectDoc;
  QDir projectDir(projectPath);
  QFile projectFile(projectDir.filePath(projectDir.dirName() + ".xml"));
  // read in the existing file, and add a node to the "files" section
  if(newProjectDoc.setContent(&projectFile))
  {
    projectFile.close();
    QDomElement newFileElement = newProjectDoc.createElement("file");
    newFileElement.setAttribute("type", buildtype);
    QDomText newFilePathElement = newProjectDoc.createTextNode(projectDir.relativeFilePath(newFilePath));
    newFileElement.appendChild(newFilePathElement);
    newProjectDoc.elementsByTagName("files").at(0).toElement().appendChild(newFileElement);
    
    // write our newly manipulated file
    if(projectFile.open(QIODevice::WriteOnly | QFile::Text)) // reopen as WriteOnly
    {
      projectFile.write(newProjectDoc.toByteArray(2));
      projectFile.close();
      retval = true;
    }
  }
  return retval;
}
예제 #3
0
/*
  Remove the file in the current project's project file.
  The file has already been removed from the filebrowser UI.
*/
void ProjectInfo::onRemoveFileRequest(QString filename)
{
  QFile projectFile(projectFilePath( ));
  QDir projectDir(mainWindow->currentProjectPath());
  if(projectManager.removeFromProjectFile(projectDir.path(), filename))
    mainWindow->removeFileFromProject(projectDir.filePath(filename));
}
예제 #4
0
/*
  Return the path of the project file
  for the current project.
*/
QString ProjectInfo::projectFilePath( )
{
	QDir projectDir(mainWindow->currentProjectPath());
	QString projectName = projectDir.dirName();
	// filename should not have spaces
	return projectDir.filePath(projectName.remove(" ") + ".xml"); 
}
예제 #5
0
bool Project::rename(const std::string& newName)
{
    if (isLoaded()) 
    {
        ofLogVerbose("Project::rename") << "renaming project \"" << getName() << "\" to \"" << newName + "\"";

        ofFile projectDir(getPath());

        std::string oldProjectName = getName();

        ofLogVerbose("Project::rename") << "project path: " << getPath() << " Renamed to: " << projectDir.getEnclosingDirectory() + newName;

        if (!projectDir.renameTo(projectDir.getEnclosingDirectory() + newName)) return false;

        _path = projectDir.getAbsolutePath();

        ofFile projectFile(projectDir.getAbsolutePath() + "/sketch/" + oldProjectName + "." + SKETCH_FILE_EXTENSION);


        // remove old executable
        ofDirectory bin;
        bin.listDir(projectDir.path() + "/bin");
        std::vector<ofFile> files = bin.getFiles();

        Poco::RegularExpression appExpression( oldProjectName + "(.exe|.app)*$", Poco::RegularExpression::RE_ANCHORED);

        for (unsigned int i = 0; i < files.size(); ++i)
        {
            std::string baseName = files[i].getBaseName();
            if (appExpression.match(baseName)) {
                files[i].remove(true);
                ofLogVerbose("Project::rename")
                    << "removed " << files[i].getFileName() << " from " << bin.getAbsolutePath() << endl;
            }
        }


        ofLogVerbose("Project::rename") << "projectDir path after rename: " << projectDir.getAbsolutePath();
        ofLogVerbose("Project::rename") << "projectFile path: " << projectFile.getAbsolutePath();

        if (!projectFile.renameTo(projectDir.getAbsolutePath() + "/sketch/" + newName + "." + SKETCH_FILE_EXTENSION)) return false;

        ofLogVerbose("Project::rename") << "projectFile path after rename: " << projectFile.getAbsolutePath();

        _data["projectFile"]["name"] = newName;

        _data["projectFile"]["fileName"] = newName + "." + SKETCH_FILE_EXTENSION;

        return true;
    }
    else
    {
        ofLogVerbose("Project::rename") << "Cannot rename project, it is not loaded.";
        return false;
    }

}
예제 #6
0
파일: prefs.cpp 프로젝트: KDE/lokalize
void SettingsController::reflectRelativePathsHack()
{
    //m_scriptsRelPrefWidget->clear();
    QStringList actionz(m_scriptsPrefWidget->items());
    QString projectDir(Project::instance()->projectDir());
    int i=actionz.size();
    while(--i>=0)
        actionz[i]=QDir(projectDir).relativeFilePath(actionz.at(i));
    m_scriptsRelPrefWidget->setItems(actionz);
}
예제 #7
0
/*
  Called when the "upload" action is triggered.
  Build the current project and upload the resulting .bin to the board.
*/
void MainWindow::onUpload( )
{
  if(currentProject.isEmpty())
    return statusBar()->showMessage( "Open a project to upload, or create a new one from the File menu.", 3500 );
  QDir projectDir(currentProject);
  projectDir.cd("build");
  projectDir.setNameFilters(QStringList() << "*.bin");
  QFileInfoList bins = projectDir.entryInfoList();
  if(bins.count())
    uploadFile(bins.first().filePath());
  else
    return statusBar()->showMessage( "Couldn't find the file to upload for this project.", 3500 );
}
예제 #8
0
bool ProjectManager::openProject(wxString projectPath)
{
   // Load Torque 6 DLL
   if ( mTorque6Library == NULL )
   {
#ifdef TORQUE_DEBUG
      mTorque6Library = openLibrary("Torque6_DEBUG");
#else
      mTorque6Library = openLibrary("Torque6");
#endif

      // Load Nessicary Functions
      mTorque6Init      = (initFunc)getLibraryFunc(mTorque6Library, "winInit");
      mTorque6Shutdown  = (shutdownFunc)getLibraryFunc(mTorque6Library, "winDestroy");
   }

   // If successful, initialize.
   if ( mTorque6Library && mTorque6Init && mTorque6Shutdown )
   {
      const char* argv[3];
      argv[0] = "Torque6Editor.exe";
      argv[1] = "-project";
      argv[2] = projectPath;

      mTorque6Init(3, argv, (HWND)mWindow->GetHWND());

      mProjectLoaded = true;
      mProjectPath = projectPath;
      wxDir projectDir(mProjectPath);
      mProjectName = projectDir.GetName();

      // Run a frame.
      Torque::Engine.mainLoop();

      // Editor Overlay
      Torque::Scene.pause();
      Torque::Debug.registerDebugMode("Editor", this);
      Torque::Debug.setDebugMode("Editor", true);

      // Editor Camera
      mEditorCamera.initialize(this);
      mRenderLayer4View = Torque::Graphics.getView("DeferredFinal", 1750, mEditorCamera.getRenderCamera());
      mEditorOverlayView = Torque::Graphics.getView("EditorOverlay", 6100, mEditorCamera.getRenderCamera());

      onProjectLoaded(mProjectName, projectPath);
      return true;
   }

   return false;
}
예제 #9
0
QString getResourceDir(const QString& projectName)
{
	QFileInfo fileInfo(projectName);
	QString subDirName = fileInfo.completeBaseName();
	QString dir = chineseTextUTF8ToQString(g_SystemContext._workContextDir + CONTEXT_DIR + RESOURCE);
	dir.append("/");
	dir.append(subDirName);
	dir.append("/");
	QDir projectDir(dir);
	projectDir.mkpath(dir);
	QString staticDir = dir;
	staticDir.append("staticmodel/");
	projectDir.mkpath(staticDir);
	return dir;
}
예제 #10
0
void Project::addLibrary(QSharedPointer<Library> library)
{
    if (not library.isNull())
    {
        QString folderName = library->getName();
        QDir dir(m_path);
        QString folderPath = QDir::cleanPath(dir.absoluteFilePath(folderName));
        QDir projectDir(folderPath);
        if (projectDir.exists())
        {
            library->withPath(folderPath);
            m_libraries.insert(folderName, library);
        }
    }
}
void GoProject::parseProject(RefreshOptions options)
{
    if (options & Files) {
        if (options & ProjectFile)
            delete m_projectItem.data();

        if (!m_projectItem) {
              QString errorMessage;
              m_projectItem = GoProjectFileFormat::parseProjectFile(m_fileName, &errorMessage);
              if (m_projectItem) {
                  connect(m_projectItem.data(), SIGNAL(filesChanged(QSet<QString>,QSet<QString>)),
                          this, SLOT(refreshFiles(QSet<QString>,QSet<QString>)));

              } else {
                  MessageManager::write(tr("Error while loading project file %1.").arg(m_fileName), MessageManager::NoModeSwitch);
                  MessageManager::write(errorMessage);
              }
        }
        if (m_projectItem) {
            m_projectItem.data()->setSourceDirectory(projectDir().path());
            m_modelManager->updateSourceFiles(m_projectItem.data()->files(), true);

            /*
            QString mainFilePath = m_projectItem.data()->mainFile();
            if (!mainFilePath.isEmpty()) {
                mainFilePath = projectDir().absoluteFilePath(mainFilePath);
                Utils::FileReader reader;
                QString errorMessage;
                if (!reader.fetch(mainFilePath, &errorMessage)) {
                    MessageManager::write(tr("Warning while loading project file %1.").arg(m_fileName));
                    MessageManager::write(errorMessage);
                } else {
                    m_defaultImport = detectImport(QString::fromUtf8(reader.data()));
                }
            }
            */
        }
        m_rootNode->refresh();
        updateConfigurations();
    }

    if (options & Configuration) {
        // update configuration
    }

    if (options & Files)
        emit fileListChanged();
}
예제 #12
0
/*
  Read the project's ProjectInfo from the project file
  and load them into the UI.
*/  
bool ProjectInfo::load()
{
  QString proj = mainWindow->currentProjectPath();
  if(proj.isEmpty())
    return false;
  QDir projectDir(proj);
	QString projectName = projectDir.dirName();
	setWindowTitle(projectName + " - Project Info");
	
	// read the ProjectInfo file
	QFile file(projectFilePath());
	if(file.open(QIODevice::ReadOnly|QFile::Text))
	{
		QDomDocument projectFile;
    if(projectFile.setContent(&file))
		{
			versionEdit->setText(projectFile.elementsByTagName("version").at(0).toElement().text());
			heapSizeEdit->setText(projectFile.elementsByTagName("heapsize").at(0).toElement().text());
			QString optlevel = projectFile.elementsByTagName("optlevel").at(0).toElement().text();
			optLevelBox->setCurrentIndex(optLevelBox->findText(optlevel));
			Qt::CheckState state = (projectFile.elementsByTagName("debuginfo").at(0).toElement().text() == "true") ? Qt::Checked : Qt::Unchecked;
			debugInfoCheckbox->setCheckState(state);
      
      state = (projectFile.elementsByTagName("include_osc").at(0).toElement().text() == "true") ? Qt::Checked : Qt::Unchecked;
			oscBox->setCheckState(state);
      
      state = (projectFile.elementsByTagName("include_usb").at(0).toElement().text() == "true") ? Qt::Checked : Qt::Unchecked;
			usbBox->setCheckState(state);
      
      state = (projectFile.elementsByTagName("include_network").at(0).toElement().text() == "true") ? Qt::Checked : Qt::Unchecked;
			networkBox->setCheckState(state);
      setNetworkSectionEnabled(state == Qt::Checked);
      
      networkMempoolEdit->setText(projectFile.elementsByTagName("network_mempool").at(0).toElement().text());
      udpSocketEdit->setText(projectFile.elementsByTagName("network_udp_sockets").at(0).toElement().text());
      tcpSocketEdit->setText(projectFile.elementsByTagName("network_tcp_sockets").at(0).toElement().text());
      tcpServerEdit->setText(projectFile.elementsByTagName("network_tcp_servers").at(0).toElement().text());
      
      loadFileBrowser( &projectDir, &projectFile);
		}
		file.close();
	}
	else
		return false;
  return true;
}
예제 #13
0
/*
  Open an existing project.
  Read the project file and load the appropriate files into the UI.
*/
void MainWindow::openProject(QString projectPath)
{
  QDir projectDir(projectPath);
  QString projectName = projectDir.dirName();
  if(!projectDir.exists())
    return statusBar()->showMessage( QString("Couldn't find %1.").arg(projectName), 3500 );

  QString pathname = projectName; // filename should not have spaces
  QFile projFile(projectDir.filePath(pathname + ".xml"));
  QDomDocument doc;
  if(doc.setContent(&projFile))
  {
    currentProject = projectPath;
    currentFileDropDown->clear();
    QDomNodeList allFiles = doc.elementsByTagName("files").at(0).childNodes();
    for(int i = 0; i < allFiles.count(); i++)
    {
      QFileInfo fi(allFiles.at(i).toElement().text());
      if(fi.fileName().isEmpty())
        continue;
      // load the file name into the file dropdown
      if(projectDir.exists(fi.fileName()))
      {
        if(QDir::isAbsolutePath(fi.filePath()))
          currentFileDropDown->addItem(fi.fileName(), fi.filePath());
        else
          currentFileDropDown->addItem(fi.fileName(), projectDir.filePath(fi.filePath()));
          
        // if this is the main project file, load it into the editor
        if(fi.baseName() == pathname)
        {
          editorLoadFile(projectDir.filePath(fi.filePath()));
          currentFileDropDown->setCurrentIndex(currentFileDropDown->findText(fi.fileName()));
        }
      }
    }
    setWindowTitle( projectName + "[*] - mcbuilder");
    updateRecentProjects(projectPath);
    builder->onProjectUpdated();
    projInfo->load();
    buildLog->clear();
	}
	else
    return statusBar()->showMessage( QString("Couldn't find main file for %1.").arg(projectName), 3500 );
}
예제 #14
0
QString CommandLineFrontend::buildDirectory(const QString &profileName) const
{
    QString buildDir = m_parser.projectBuildDirectory();
    if (buildDir.isEmpty()) {
        buildDir = Preferences(m_settings, profileName).defaultBuildDirectory();
        if (buildDir.isEmpty()) {
            qbsDebug() << "No project build directory given; using current directory.";
            buildDir = QDir::currentPath();
        } else {
            qbsDebug() << "No project build directory given; using directory from preferences.";
        }
    }

    QString projectName(QFileInfo(m_parser.projectFilePath()).baseName());
    buildDir.replace(BuildDirectoryOption::magicProjectString(), projectName);
    QString projectDir(QFileInfo(m_parser.projectFilePath()).path());
    buildDir.replace(BuildDirectoryOption::magicProjectDirString(), projectDir);
    if (!QFileInfo(buildDir).isAbsolute())
        buildDir = QDir::currentPath() + QLatin1Char('/') + buildDir;
    buildDir = QDir::cleanPath(buildDir);
    return buildDir;
}
예제 #15
0
void newProjectDialog::createProject()
{
	QMessageBox msgBox;
	bool err = false;

	if(ui->projectNameEdit->text().isEmpty())
	{
		msgBox.setText("Enter the name of the project");
		msgBox.exec();
		err = true;
	}
	else
		project.name = ui->projectNameEdit->text();

	project.mcu = mcuList.at(ui->mcuComboBox->currentIndex());
	project.programmer = programmerList.at(ui->programmerComboBox->currentIndex());
	project.mcu.clock = ui->clockEdit->text();
	project.programmer.portName = ui->portEdit->text();
	if(ui->pathToProjectRequister->url().isEmpty())
	{
		msgBox.setText("Select project file");
		msgBox.exec();
		err = true;
	}
	else
		project.path = QUrl(QString(ui->pathToProjectRequister->text()).append("/").append(project.name));

	if(err == false)
	{
		QDir projectDir(ui->pathToProjectRequister->text());
		projectDir.mkdir(ui->projectNameEdit->text());
		projectDir.cd(ui->projectNameEdit->text());

		QStringList templateListFile = selectedTemplateDir.entryList(QDir::Files);

		for(int i = 0; i < templateListFile.count(); i++)
		{
			QString templateFileUrl = selectedTemplateDir.path();
			templateFileUrl.append("/");
			templateFileUrl.append(templateListFile.at(i));

			QString projectFileUrl = projectDir.path();
			projectFileUrl.append("/");

			if(templateListFile.at(i).contains(".avrguitemplate"))
				projectFileUrl.append(project.name).append(".avrgui");
			else
				projectFileUrl.append(templateListFile.at(i));

			QFile::copy(templateFileUrl,projectFileUrl);

			ui->descriptionTextEdit->setText(templateFileUrl);
		}

		project.fileList.append(QString(project.name).append(".avrgui"));

		for(int i = 0; i < project.fileList.count(); i++)
		{
			QFile file(QString(projectDir.path().append("/").append(project.fileList.at(i))));

			if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
				return;

			QTextStream stream(&file);
			QString fileString = stream.readAll();

			file.remove();

			fileString.replace("[avrguiVersion]", AvrGuiVersion,Qt::CaseInsensitive);
			fileString.replace("[projectName]", project.name,Qt::CaseInsensitive);
			fileString.replace("[mcu]", project.mcu.id,Qt::CaseInsensitive);
			fileString.replace("[mmcu]", project.getMMCU(),Qt::CaseInsensitive);
			fileString.replace("[programmer]", project.programmer.id,Qt::CaseInsensitive);
			fileString.replace("[programmerPort]", project.programmer.portName,Qt::CaseInsensitive);
			if(!project.programmer.portName.isEmpty())
				fileString.replace("#PORT_PROGRAMMER = -P", QString("PORT_PROGRAMMER = -P ").append(project.programmer.portName),Qt::CaseInsensitive);
			fileString.replace("[clock]", project.mcu.clock,Qt::CaseInsensitive);

			if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
				return;
			stream.setDevice(&file);
			stream << fileString;
		}
	}

	if(err == false)
		this->accept();
}
예제 #16
0
QDomDocument SaveOMOptim::ProjectToXml(Project * project)
{
    // MO file
    QDomDocument doc("MOProjectXML");
    QDomElement root = doc.createElement( "MOProject" );
    doc.appendChild( root );
    root.setAttribute("Version",Version::version());

    // Project info
    QDir projectDir(project->folder());
    QDomElement cBasic = doc.createElement( "Basic" );
    cBasic.setAttribute( "name", project->name() );
    root.appendChild(cBasic);

    QString relPath;

    // Mo files
    bool useRelativePath;
    QFileInfoList moFilesPath = project->moFiles();
    if(moFilesPath.size()>0)
    {
        QDomElement cMoFiles = doc.createElement("MoFiles");
        for(int i=0;i<moFilesPath.size();i++)
        {
            // if mo file is in project folder, use relative path
            useRelativePath = (moFilesPath.at(i).absoluteFilePath().indexOf(projectDir.absolutePath())==0);
            QDomElement cMoFile = doc.createElement("MoFile");
            if(useRelativePath)
                cMoFile.setAttribute("path",projectDir.relativeFilePath(moFilesPath.at(i).absoluteFilePath()));
            else
                cMoFile.setAttribute("path",moFilesPath.at(i).absoluteFilePath());
            cMoFiles.appendChild(cMoFile);
        }
        root.appendChild(cMoFiles);
    }


    // Mmo files
    QFileInfoList mmoFilesPath = project->mmoFiles();
    if(mmoFilesPath.size()>0)
    {
        QDomElement cMmoFiles = doc.createElement("MmoFiles");
        for(int i=0;i<mmoFilesPath.size();i++)
        {
            QDomElement cMmoFile = doc.createElement("MmoFile");
            relPath = projectDir.relativeFilePath(mmoFilesPath.at(i).filePath());
            qDebug(mmoFilesPath.at(i).filePath().toLatin1());
            cMmoFile.setAttribute("path",relPath);
            cMmoFiles.appendChild(cMmoFile);
        }
        root.appendChild(cMmoFiles);
    }

    // plugins loaded
    QStringList pluginsPaths = project->pluginsLoaded().values();
    if(pluginsPaths.size()>0)
    {
        QDomElement cPlugins = doc.createElement("Plugins");
        for(int i=0;i<pluginsPaths.size();i++)
        {
            QDomElement cPlugin = doc.createElement("Plugin");
            cPlugin.setAttribute("path",pluginsPaths.at(i));
            cPlugins.appendChild(cPlugin);
        }
        root.appendChild(cPlugins);
    }

    // Project problems
    if(project->problems()->size()>0)
    {
        QDomElement cOMCases = doc.createElement( "Problems" );
        for (int nr=0;nr<project->problems()->size();nr++)
        {
            QDomElement cProblem = doc.createElement( "Problem" );
            relPath = projectDir.relativeFilePath(project->problems()->at(nr)->entireSavePath());
            cProblem.setAttribute("path",relPath);
            cOMCases.appendChild(cProblem);
        }
        root.appendChild(cOMCases);
    }

    // Project results
    if(project->results()->size()>0)
    {
        QDomElement cResults = doc.createElement( "Results" );

        for (int nr=0;nr<project->results()->size();nr++)
        {
            QDomElement cResult = doc.createElement( "Result" );
            relPath = projectDir.relativeFilePath(project->results()->at(nr)->entireSavePath());
            cResult.setAttribute("path",relPath);
            cResults.appendChild(cResult);
        }
        root.appendChild(cResults);
    }

    return doc;
}
예제 #17
0
bool TargetRunner::Load()
{
    LOG (INFO) << "Reading config file...";
    TiXmlDocument doc( VFS->GetRelativePath(this->configPath).c_str());
    bool status = doc.LoadFile();
    if (!status)
    {
        LOG (LERROR) << "LERROR on loading xml document!";
        return false;
    }

    TiXmlElement *target = doc
                    .FirstChildElement(Constants::XML_TAG_BUILD_CONFIG)
                    ->FirstChildElement(Constants::XML_TAG_BUILD_TARGET);
    TiXmlElement *opt;
    while (target)
    {
        const char* value = target->Attribute(Constants::XML_ATTR_TARGET_NAME);
        if (!value)
        {
            LOG(LERROR) << "Every target must have a name!";
            return false;
        }
        cpp0x::shared_ptr<Target> buildTarget (new Target());
        cpp0x::shared_ptr<std::string> name(new std::string(value));
        buildTarget->SetTargetName(name);

        if (std::string(value).compare(Constants::DEFAULT_TARGET_NAME) == 0)
        {
            value = target->Attribute(Constants::XML_ATTR_TO_BE_BUILT);
            if (value)
            {
                defaultTargetName = std::string(value);
            }
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_PLATFORM))
        {
            cpp0x::shared_ptr<std::string> platform(new std::string(opt->GetText()));
            buildTarget->SetPlatform(platform);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_PROJECT_DIR))
        {
            cpp0x::shared_ptr<std::string> projectDir(new std::string(opt->GetText()));
            buildTarget->SetProjectDir(projectDir);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_BUILD_DIR))
        {
            cpp0x::shared_ptr<std::string> buildDir(new std::string(opt->GetText()));
            buildTarget->SetBuildDir(buildDir);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_CMAKE_PROJECT_TYPE))
        {
            cpp0x::shared_ptr<std::string> cmakeProjectType(new std::string(opt->GetText()));
            buildTarget->SetCmakeProjectType(cmakeProjectType);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_CUSTOM_ARGS))
        {
            cpp0x::shared_ptr<std::string> customArgs(new std::string(opt->GetText()));
            buildTarget->SetCustomArgs(customArgs);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_PROJECTS_ROOT_DIR))
        {
            cpp0x::shared_ptr<std::string> projectsRootDir(new std::string(opt->GetText()));
            buildTarget->SetProjectsRootDir(projectsRootDir);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_KRAL_PATH))
        {
            cpp0x::shared_ptr<std::string> kralPath(new std::string(opt->GetText()));
            buildTarget->SetKralPath(kralPath);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_CMAKE))
        {
            cpp0x::shared_ptr<std::string> cmake(new std::string(opt->GetText()));
            buildTarget->SetCmake(cmake);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_ANDROID_API_LEVEL))
        {
            cpp0x::shared_ptr<std::string> androidApiLevel(new std::string(opt->GetText()));
            buildTarget->SetAndroidApiLevel(androidApiLevel);
        }

        if (opt = target->FirstChildElement(Constants::XML_TAG_ANDROID_ARM_TARGET))
        {
            cpp0x::shared_ptr<std::string> value(new std::string(opt->GetText()));
            buildTarget->SetAndroidArmTarget(value);
        }

           if (opt = target->FirstChildElement(Constants::XML_TAG_BUILD_TYPE))
        {
            cpp0x::shared_ptr<std::string> value(new std::string(opt->GetText()));
            buildTarget->SetBuildType(value);
        } else {
            cpp0x::shared_ptr<std::string> value(new std::string("Debug"));
            buildTarget->SetBuildType(value);
        }

           if (opt = target->FirstChildElement(Constants::XML_TAG_ANDROID_ASSETS))
        {
            cpp0x::shared_ptr<std::string> value(new std::string(opt->GetText()));
            buildTarget->SetAssets(value);
        }
   
        if (opt = target->FirstChildElement(Constants::XML_TAG_COMPILER_CUSTOM_OPTS))
        {
            cpp0x::shared_ptr<std::string> value(new std::string(opt->GetText()));
            buildTarget->SetCompilerCustomOptions(value);
        }
        
        if (opt = target->FirstChildElement(Constants::XML_TAG_PACKAGE_DIRS))
        {
            cpp0x::shared_ptr<std::string> value(new std::string(opt->GetText()));
            buildTarget->SetPackageDirs(value);
        }

        if (buildTarget->GetTargetName()->compare(Constants::DEFAULT_TARGET_NAME) == 0)
        {
            this->defaultTarget = buildTarget;
        } else {
            this->targets.push_back(buildTarget);
        }
        target = target->NextSiblingElement();
    }
    return true;
}
예제 #18
0
Project* Project::create(const QString& path, const QString& name, QObject* parent)
{
    Project* project = new Project(parent);
    project->_name = name.toStdString();
    project->_path = path.toStdString();
    project->_scenePath = std::string(RESOURCE_DIR) + std::string("/") + std::string(SCENE_NEW) + std::string(SCENE_EXT);

    // Create a resource directory
    QDir projectDir(path);
    if (!projectDir.mkdir("res"))
    {
        SAFE_DELETE(project);
        return nullptr;
    }
    // Create a project file
    if (!_serializerActivated)
    {
        Serializer::getActivator()->registerClass("gameplay::Project", &Project::createInstance);
        _serializerActivated = true;
    }
    QString projectFilePath(path + QString("/") + QString(QLatin1String(PROJECT_FILE)));
    QByteArray projectFilePathByteArray = projectFilePath.toLatin1();
    const char* projectFilePathStr = projectFilePathByteArray.data();
    Serializer* projectWriter = SerializerJson::createWriter(projectFilePathStr);
    projectWriter->writeObject(nullptr, project);
    projectWriter->close();
    SAFE_DELETE(projectWriter);

    // Create a config file
    QString configFilePath(path + QString("/") + QString(QLatin1String(CONFIG_FILE)));
    QByteArray configFilePathByteArray = configFilePath.toLatin1();
    const char* configFilePathStr = configFilePathByteArray.data();
    Serializer* configWriter = SerializerJson::createWriter(configFilePathStr);
    Game::Config config;
    configWriter->writeObject(nullptr, &config);
    configWriter->close();
    SAFE_DELETE(configWriter);

    // Create an empty scene.
    std::string id = SCENE_NEW;
    Scene* scene = Scene::create(id.c_str());

    // Add a perspective camera
    float aspectRatio = (float)config.width / (float)config.height;
    Camera* camera = Camera::createPerspective(45.0f, aspectRatio, 1.0f, 10.0f);
    Node* cameraNode = scene->addNode(NODE_NEW);
    cameraNode->setCamera(camera);
    scene->setActiveCamera(camera);
    SAFE_RELEASE(camera);

    // Add a directional light
    Light* light = Light::createDirectional(Vector3::one());
    Node* lightNode = Node::create(NODE_NEW);
    lightNode->setLight(light);
    lightNode->setTranslation(0.0f, 0.0f, 10.0f);
    SAFE_RELEASE(light);
    scene->addNode(lightNode);

    QString sceneFilePath(path + QDir::separator() + QString(QLatin1String(RESOURCE_DIR)) +
                                 QDir::separator() + QString(QLatin1String(SCENE_NEW)) + QString(QLatin1String(SCENE_EXT)));
    QByteArray sceneFilePathByteArray = sceneFilePath.toLatin1();
    const char* sceneFilePathStr = sceneFilePathByteArray.data();
    Serializer* sceneWriter = SerializerJson::createWriter(sceneFilePathStr);
    sceneWriter->writeObject(nullptr, scene);
    sceneWriter->close();
    SAFE_DELETE(sceneWriter)
    SAFE_RELEASE(scene);

    return project;
}
예제 #19
0
bool Project::remove()
{
    ofDirectory projectDir(getPath());
    return projectDir.remove(true);
}
예제 #20
0
/*
  Return the path of the project file
  for the current project.
*/
QString ProjectInfo::projectFilePath( QString projectPath )
{
  QDir projectDir(projectPath);
  return projectDir.filePath(projectDir.dirName() + ".xml"); 
}
예제 #21
0
void MeasuresTabController::selectBaseline()
{
  boost::optional<analysisdriver::SimpleProject> project = PatApp::instance()->project();
  if (!project){
    return;
  }

  if (project->isRunning()){
    // warn user that they will have to stop running to change baseline model
    QMessageBox::StandardButton test = QMessageBox::question( measuresTabView, "Stop Current Analysis?", "You must stop the currently running analysis before changing the baseline model, do you want to proceed?", QMessageBox::Yes |  QMessageBox::No, QMessageBox::No );
    if (test == QMessageBox::No){
      return;
    }

    project->stop();
  }

  if (project->analysis().completeDataPoints().size() > 0u){
    // warn user that this will blow away their data points
    QMessageBox::StandardButton test = QMessageBox::question( 
        measuresTabView, 
        "Change Baseline Model?", 
        "Changing your baseline model will remove all results and save your project, do you want to proceed?", 
        QMessageBox::Yes |  QMessageBox::No, 
        QMessageBox::No );
    if (test == QMessageBox::No){
      return;
    }
  }

  // DLM: todo, allow user to clear baseline?

  QString fileName = QFileDialog::getOpenFileName( measuresTabView,
                                                   tr("Select Baseline Model"),
                                                   QDir::homePath(),
                                                   tr("(*.osm)") );

  if (!fileName.isEmpty()){
    QDir projectDir(toQString(project->projectDir()));
    if (projectDir.relativeFilePath(fileName).startsWith("seed")){
      QMessageBox::warning( measuresTabView, "Changing Baseline Model Failed", QString("The new baseline model cannot be located within the project's seed directory."));
      return;
    }
    FileReference seed(toPath(fileName));
    // DLM: make sure to call setSeed on the real project, not a copy
    if (PatApp::instance()->setSeed(seed)){

      if (seed.displayName().empty() || seed.displayName() == "*"){
        measuresTabView->baselineCautionLabel->setHidden(false);
        measuresTabView->baselineNameBackground->setHidden(true);
        measuresTabView->baselineLabel->setText(QString());
      }else{
        measuresTabView->baselineCautionLabel->setHidden(true);
        measuresTabView->baselineNameBackground->setHidden(false);
        measuresTabView->baselineLabel->setText(toQString(seed.displayName()));
      }

      // change cannot be undone, save the project
      PatApp::instance()->project()->save();

      //QMessageBox::information( measuresTabView, "Baseline Model Changed", QString("Baseline model has been changed, please run a baseline simulation with this new baseline model before continuing on with new work.") );

      m_variableGroupListController->selectionController()->unselectAllItems();

    }else{
      // tell user that this failed
      QMessageBox::critical( measuresTabView, "Changing Baseline Model Failed", QString("Failed to change baseline model to file at '") + fileName + QString("'."));
    }
  }
}
예제 #22
0
파일: tupfilemanager.cpp 프로젝트: KDE/tupi
bool TupFileManager::save(const QString &fileName, TupProject *project)
{
    #ifdef K_DEBUG
        QString msg = "TupFileManager::save() - Saving file -> " + fileName;
            #ifdef Q_OS_WIN32
                qWarning() << msg;
            #else
                tWarning() << msg;
        #endif
    #endif

	/* 
    int indexPath = fileName.lastIndexOf(QDir::separator());
    int indexFile = fileName.length() - indexPath;
    QString name = fileName.right(indexFile - 1);
    int indexDot = name.lastIndexOf(".");
    name = name.left(indexDot);
    */
	
	QFileInfo info(fileName);
	QString name = info.baseName();	
    QString oldDirName = CACHE_DIR + project->projectName();
    QDir projectDir(oldDirName);

    if (name.compare(project->projectName()) != 0) {
        project->setProjectName(name);
        projectDir.setPath(CACHE_DIR + name);    
        project->library()->updatePaths(CACHE_DIR + name);
        if (!projectDir.exists()) {
            if (projectDir.rename(oldDirName, projectDir.path())) {
                #ifdef K_DEBUG
                    QString msg = "TupFileManager::save() - Directory renamed to -> " + projectDir.path(); 
                    #ifdef Q_OS_WIN32
                        qWarning() << msg;
                    #else
                        tWarning() << msg;
                    #endif
                #endif
            } else {
                // SQA: Check if these lines are really needed
                if (! projectDir.mkdir(projectDir.path())) {
                    #ifdef K_DEBUG
                        QString msg = "TupFileManager::save() - Error: Can't create path -> " + projectDir.path();
                        #ifdef Q_OS_WIN32
                            qDebug() << msg;
                        #else
                            tError() << msg;
                        #endif
                    #endif
                    return false;
                } else {
                    #ifdef K_DEBUG
                        QString msg = "TupFileManager::save() - Directory was created successfully -> " + projectDir.path();
                        #ifdef Q_OS_WIN32
                            qWarning() << msg;
                        #else
                            tWarning() << msg;
                        #endif
                    #endif
                }
            }
        }
    } else {
        if (!projectDir.exists()) {
            if (! projectDir.mkdir(projectDir.path())) {
                #ifdef K_DEBUG
                    QString msg = "TupFileManager::save() - Error: Can't create path -> " + projectDir.path();
                    #ifdef Q_OS_WIN32
                        qDebug() << msg;
                    #else
                        tError() << msg;
                    #endif
                #endif
                return false;
            } else {
                #ifdef K_DEBUG
                    QString msg = "TupFileManager::save() - Directory was created successfully -> " + projectDir.path();
                    #ifdef Q_OS_WIN32
                        qWarning() << msg;
                    #else
                        tWarning() << msg;
                    #endif
                #endif
            }
        }
    }

    {
     // Save project
     QFile projectFile(projectDir.path() + QDir::separator() + "project.tpp");

     if (projectFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
         QTextStream ts(&projectFile);
         QDomDocument doc;
         project->setProjectName(name);
         doc.appendChild(project->toXml(doc));
         ts << doc.toString();
         projectFile.close();
     } else {
         #ifdef K_DEBUG
             QString msg = "TupFileManager::save() - Error: Can't create file -> " + projectDir.path() + QDir::separator() + "project.tpp";
             #ifdef Q_OS_WIN32
                 qDebug() << msg;
             #else
                 tError() << msg;
             #endif
         #endif
     }
    }

    // Save scenes
    {
     int index = 0;
     int totalScenes = project->scenes().size();
     for (int i = 0; i < totalScenes; i++) {
          TupScene *scene = project->scenes().at(i);
          QDomDocument doc;
          doc.appendChild(scene->toXml(doc));
          QString scenePath = projectDir.path() + QDir::separator() + "scene" + QString::number(index) + ".tps";
          QFile sceneFile(scenePath);

          if (sceneFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
              QTextStream st(&sceneFile);
              st << doc.toString();
              index += 1;
              sceneFile.close();
          } else {
              #ifdef K_DEBUG
                  QString msg = "TupFileManager::save() - Error: Can't create file -> " + scenePath;
                  #ifdef Q_OS_WIN32
                      qDebug() << msg;
                  #else
                      tError() << msg;
                  #endif
              #endif
          }
     }
    }

    {
     // Save library
     QFile lbr(projectDir.path() + QDir::separator() + "library.tpl");

     if (lbr.open(QIODevice::WriteOnly | QIODevice::Text)) {
         QTextStream ts(&lbr);

         QDomDocument doc;
         doc.appendChild(project->library()->toXml(doc));

         ts << doc.toString();
         lbr.close();
     } else {
         #ifdef K_DEBUG
             QString msg = "TupFileManager::save() - Error: Can't create file -> " + projectDir.path() + QDir::separator() + "library.tpl";
             #ifdef Q_OS_WIN32
                 qDebug() << msg;
             #else
                 tError() << msg;
             #endif
         #endif
     }
    }

    TupPackageHandler packageHandler;
    bool ok = packageHandler.makePackage(projectDir.path(), fileName);

    if (ok) {
        #ifdef K_DEBUG
            QString msg = "TupFileManager::save() - Project saved in -> " + fileName;
            #ifdef Q_OS_WIN32
                qWarning() << msg;
            #else
                tWarning() << msg;
            #endif
        #endif
    } else {
        #ifdef K_DEBUG
            QString msg = "TupFileManager::save() - Error: Project couldn't be saved in -> " + fileName;
            #ifdef Q_OS_WIN32
                qDebug() << msg;
            #else
                tError() << msg;
            #endif
        #endif
    }

    return ok;
}
예제 #23
0
void Project::addFile(QTreeView* treeView, QSortFilterProxyModel* sort, const QString &fileName)
{
    if (_files.contains(fileName))
        return;
    QFileInfo fi(fileName);
    QString absFileName = fi.absoluteFilePath();
    QString relFileName;
    if (!projectRoot.isEmpty()) {
        QDir projectDir(QFileInfo(projectRoot).absoluteDir());
        relFileName = projectDir.relativeFilePath(absFileName);
    } else {
        relFileName = absFileName;
    }

    QStringList path = relFileName.split(QDir::separator());
    while (path.first().isEmpty()) {
        path.pop_front();
    }
    QStandardItem* curItem;
    bool isMiniZinc = true;
    bool isCoursera = false;
    if (fi.suffix()=="mzn") {
        curItem = mzn;
    } else if (fi.suffix()=="dzn") {
        curItem = dzn;
    } else if (fi.suffix()=="fzn") {
        return;
    } else {
        curItem = other;
        isMiniZinc = false;
        isCoursera = fi.completeBaseName()=="_coursera";
    }

    if (isCoursera) {
        if (_courseraProject) {
            QMessageBox::warning(treeView,"MiniZinc IDE",
                                "Cannot add second Coursera options file",
                                QMessageBox::Ok);
            return;
        }
        QFile metadata(absFileName);
        if (!metadata.open(QIODevice::ReadOnly)) {
            QMessageBox::warning(treeView,"MiniZinc IDE",
                                 "Cannot open Coursera options file",
                                 QMessageBox::Ok);
            return;
        }
        QTextStream in(&metadata);
        CourseraProject* cp = new CourseraProject;
        if (in.status() != QTextStream::Ok) {
            delete cp;
            goto coursera_done;
        }
        cp->course = in.readLine();
        if (in.status() != QTextStream::Ok) {
            delete cp;
            goto coursera_done;
        }
        cp->checkpwdSid= in.readLine();
        if (in.status() != QTextStream::Ok) {
            delete cp;
            goto coursera_done;
        }
        cp->name = in.readLine();
        QString nSolutions_s = in.readLine();
        int nSolutions = nSolutions_s.toInt();
        for (int i=0; i<nSolutions; i++) {
            if (in.status() != QTextStream::Ok) {
                delete cp;
                goto coursera_done;
            }
            QString line = in.readLine();
            QStringList tokens = line.split(", ");
            if (tokens.size() < 5) {
                delete cp;
                goto coursera_done;
            }
            CourseraItem item(tokens[0].trimmed(),tokens[1].trimmed(),tokens[2].trimmed(),
                              tokens[3].trimmed(),tokens[4].trimmed());
            cp->problems.append(item);
        }
        if (in.status() != QTextStream::Ok) {
            delete cp;
            goto coursera_done;
        }
        nSolutions_s = in.readLine();
        nSolutions = nSolutions_s.toInt();
        for (int i=0; i<nSolutions; i++) {
            if (in.status() != QTextStream::Ok) {
                delete cp;
                goto coursera_done;
            }
            QString line = in.readLine();
            QStringList tokens = line.split(", ");
            if (tokens.size() < 3) {
                delete cp;
                goto coursera_done;
            }
            CourseraItem item(tokens[0].trimmed(),tokens[1].trimmed(),tokens[2].trimmed());
            cp->models.append(item);
        }
        _courseraProject = cp;
        ui->actionSubmit_to_Coursera->setVisible(true);
    }
coursera_done:

    setModified(true, true);
    QStandardItem* prevItem = curItem;
    treeView->expand(sort->mapFromSource(curItem->index()));
    curItem = curItem->child(0);
    int i=0;
    while (curItem != NULL) {
        if (curItem->text() == path.first()) {
            path.pop_front();
            treeView->expand(sort->mapFromSource(curItem->index()));
            prevItem = curItem;
            curItem = curItem->child(0);
            i = 0;
        } else {
            i += 1;
            curItem = curItem->parent()->child(i);
        }
    }
    for (int i=0; i<path.size(); i++) {
        QStandardItem* newItem = new QStandardItem(path[i]);
        prevItem->appendRow(newItem);
        if (i<path.size()-1) {
            newItem->setIcon(QIcon(":/icons/images/folder.png"));
        } else {
            _files.insert(absFileName,newItem->index());
            if (isMiniZinc) {
                newItem->setIcon(QIcon(":/images/mznicon.png"));
            }
        }
        treeView->expand(sort->mapFromSource(newItem->index()));
        prevItem = newItem;
    }
}
예제 #24
0
파일: tupfilemanager.cpp 프로젝트: KDE/tupi
bool TupFileManager::load(const QString &fileName, TupProject *project)
{
    #ifdef K_DEBUG
        #ifdef Q_OS_WIN32
            qDebug() << "[TupFileManager::load()] - fileName: " + fileName;
        #else
            T_FUNCINFO << fileName; 
        #endif
    #endif

    TupPackageHandler packageHandler;

    if (packageHandler.importPackage(fileName)) {
        QDir projectDir(packageHandler.importedProjectPath());
        QFile pfile(projectDir.path() + QDir::separator() + "project.tpp");

        if (pfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
            project->fromXml(QString::fromLocal8Bit(pfile.readAll()));
            pfile.close();
        } else {
            #ifdef K_DEBUG
                QString msg1 = "TupFileManager::load() - Error while open .tpp file. Name: " + pfile.fileName();
                QString msg2 = "TupFileManager::load() - Path: " + projectDir.path();
                QString msg3 = "TupFileManager::load() - Error Description: " + pfile.errorString(); 
                #ifdef Q_OS_WIN32
                    qDebug() << msg1;
                    qDebug() << msg2;
                    qDebug() << msg3;
                #else
                    tError() << msg1;
                    tError() << msg2;
                    tError() << msg3;
                #endif
            #endif

            return false;
        }

        project->setDataDir(packageHandler.importedProjectPath());
        project->loadLibrary(projectDir.path() + QDir::separator() + "library.tpl");

        QStringList scenes = projectDir.entryList(QStringList() << "*.tps", QDir::Readable | QDir::Files);

        if (scenes.count() > 0) {
            int index = 0;
            foreach (QString scenePath, scenes) {
                     scenePath = projectDir.path() + QDir::separator() + scenePath;
                     QFile file(scenePath);

                     if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
                         QString xml = QString::fromLocal8Bit(file.readAll());
                         QDomDocument document;
                         if (! document.setContent(xml))
                             return false;
                         QDomElement root = document.documentElement();

                         TupScene *scene = project->createScene(root.attribute("name"), index, true);
                         scene->fromXml(xml);

                         index += 1;
                         file.close();
                     } else {
                         #ifdef K_DEBUG
                             QString msg = "TupFileManager::load() - Error: Can't open file -> " + scenePath;
                             #ifdef Q_OS_WIN32
                                 qDebug() << msg;
                             #else
                                 tError() << msg;
                             #endif
                         #endif
                         return false;
                     }
            }