Beispiel #1
0
const QSet<Utf8String> Document::dependedFilePaths() const
{
    checkIfNull();
    checkIfFileExists();

    return d->dependedFilePaths;
}
void SyncConnector::spawnSyncthingProcess(
  const QString& filePath, const bool shouldSpawn, const bool onSetPath)
{
  mSyncthingFilePath = filePath;
  if (shouldSpawn)
  {
    if (!checkIfFileExists(filePath) && onSetPath)
    {
      QMessageBox msgBox;
      msgBox.setText("Could not find Syncthing.");
      msgBox.setInformativeText("Are you sure the path is correct?");
      msgBox.setStandardButtons(QMessageBox::Ok);
      msgBox.setDefaultButton(QMessageBox::Ok);
      msgBox.exec();
    }
    if (!systemUtil.isBinaryRunning(std::string("syncthing")))
    {
      mpSyncProcess = std::unique_ptr<QProcess>(new QProcess(this));
      connect(mpSyncProcess.get(), SIGNAL(stateChanged(QProcess::ProcessState)),
        this, SLOT(syncThingProcessSpawned(QProcess::ProcessState)));
      QString processPath = QDir::toNativeSeparators(filePath);
      QStringList launchArgs;
      launchArgs << "-no-browser";
      mpSyncProcess->start(processPath, launchArgs);
    }
    else
    {
      emit(onProcessSpawned({{kSyncthingIdentifier, ProcessState::ALREADY_RUNNING}}));
    }
  }
}
rapp_platform_ros_communications::ontologyLoadDumpSrv::Response KnowrobWrapper::dumpOntologyQuery(rapp_platform_ros_communications::ontologyLoadDumpSrv::Request req)
{
  rapp_platform_ros_communications::ontologyLoadDumpSrv::Response res;

  std::string path = getenv("HOME");
  path=path+std::string("/rapp_platform_files/");

  if(req.file_url.empty())   // || req.file_url==std::string("")
  {
    res.success=false;
    res.trace.push_back(std::string("Empty file path"));
    res.trace.push_back(req.file_url);
    res.error=std::string("Empty file path");
    return res;
  }
  size_t pathDepth = std::count(req.file_url.begin(), req.file_url.end(), '/');
  std::string str2 ("/");
  std::size_t found = req.file_url.find(str2);
  if (found!=std::string::npos && pathDepth>1)
  {
    std::string folderFromPath=SplitFilename(req.file_url);
    const char * c = folderFromPath.c_str();
    if(!checkIfFileExists(c))
    {
      res.success=false;
      res.trace.push_back(std::string("Path does not exist, invalid folder?"));
      res.trace.push_back(req.file_url);
      res.error=std::string("Path does not exist, invalid folder?");
      return res;
    }
  }



  req.file_url=path+req.file_url;


  std::string query = std::string("rdf_save('") + req.file_url + std::string("')");
  json_prolog::PrologQueryProxy results = pl.query(query.c_str());


  char status = results.getStatus();
  if(status==0)
  {
    res.success=false;
    //std_msgs::String temp_std_msgs_string;
    //temp_std_msgs_string.data=std::string("Ontology dump failed");
    res.trace.push_back(std::string("Ontology dump failed"));
    res.error=std::string("Ontology dump failed");
    return res;
  }
  else if(status==3)
  {
    res.success=true;
  }
  return res;


}
TranslationUnit::TranslationUnit(const Utf8String &filePath,
                                 const ProjectPart &projectPart,
                                 TranslationUnits &translationUnits,
                                 FileExistsCheck fileExistsCheck)
    : d(std::make_shared<TranslationUnitData>(filePath, projectPart, translationUnits))
{
    if (fileExistsCheck == CheckIfFileExists)
        checkIfFileExists();
}
CXTranslationUnit TranslationUnit::cxTranslationUnitWithoutReparsing() const
{
    checkIfNull();
    checkIfFileExists();
    removeTranslationUnitIfProjectPartWasChanged();
    createTranslationUnitIfNeeded();

    return d->translationUnit;
}
bool CommonFunctions::copyFile(QString file) {
    QFileInfo fileInfo(file);
    if (checkIfFileExists(fileInfo)) {
        return true;
    } else {
        if (createDirectoryIfNotExists(fileInfo.dir())) {
            return QFile::copy(":/App/assets/database/database.db", file);
        } else {
            return false;
        }
    }
}
Beispiel #7
0
Document::Document(const Utf8String &filePath,
                   const ProjectPart &projectPart,
                   const Utf8StringVector &fileArguments,
                   Documents &documents,
                   FileExistsCheck fileExistsCheck)
    : d(std::make_shared<DocumentData>(filePath,
                                       projectPart,
                                       fileArguments,
                                       documents))
{
    if (fileExistsCheck == FileExistsCheck::Check)
        checkIfFileExists();
}
rapp_platform_ros_communications::ontologyLoadDumpSrv::Response KnowrobWrapper::loadOntologyQuery(rapp_platform_ros_communications::ontologyLoadDumpSrv::Request req)
{
  rapp_platform_ros_communications::ontologyLoadDumpSrv::Response res;



  if(req.file_url.empty())   // || req.file_url==std::string("")
  {
    res.success=false;
    res.trace.push_back(std::string("Empty file path"));
    res.trace.push_back(req.file_url);
    res.error=std::string("Empty file path");
    return res;
  }


  //std::string path = ros::package::getPath("rapp_knowrob_wrapper");
  std::string path = getenv("HOME");
  path=path+std::string("/rapp_platform_files/");

  req.file_url=path+req.file_url;
  const char * c = req.file_url.c_str();
  if(!checkIfFileExists(c))
  {
    res.success=false;
    res.trace.push_back(std::string("File does not exist in provided file path: '")
      + std::string(req.file_url) + std::string("'"));
    res.trace.push_back(req.file_url);
    res.error=std::string("File does not exist in provided file path: '"
      + std::string(req.file_url) + std::string("'"));
    return res;
  }
  std::string query = std::string("rdf_load('") + req.file_url + std::string("')");
  json_prolog::PrologQueryProxy results = pl.query(query.c_str());
  char status = results.getStatus();
  if(status==0)
  {
    res.success=false;
    //std_msgs::String temp_std_msgs_string;
    //temp_std_msgs_string.data=std::string("Ontology dump failed");
    res.trace.push_back(std::string("Ontology load failed"));
    res.error=std::string("Ontology load failed");
    return res;
  }
  else if(status==3)
  {
    res.success=true;
  }
  return res;
}
void SyncConnector::checkAndSpawnINotifyProcess(bool isRequestedExternal)
{
  if (isRequestedExternal)
  {
    onSettingsChanged();
    if (mpSyncthingNotifierProcess)
    {
      mpSyncthingNotifierProcess->terminate();
    }
  }
  if (mShouldLaunchINotify)
  {
    if (!checkIfFileExists(mINotifyFilePath) && isRequestedExternal)
    {
      QMessageBox msgBox;
      msgBox.setText("Could not find iNotify.");
      msgBox.setInformativeText("Are you sure the path is correct?");
      msgBox.setStandardButtons(QMessageBox::Ok);
      msgBox.setDefaultButton(QMessageBox::Ok);
      msgBox.exec();
    }
    if (!systemUtil.isBinaryRunning(std::string("syncthing-inotify")))
    {
      mpSyncthingNotifierProcess = std::unique_ptr<QProcess>(new QProcess(this));
      QString processPath = QDir::toNativeSeparators(mINotifyFilePath);
      connect(mpSyncthingNotifierProcess.get(), SIGNAL(stateChanged(QProcess::ProcessState)),
        this, SLOT(notifyProcessSpawned(QProcess::ProcessState)));
      mpSyncthingNotifierProcess->start(processPath, QStringList(), QIODevice::Unbuffered);
    }
    else
    {
      emit(onProcessSpawned({{kNotifyIdentifier, ProcessState::ALREADY_RUNNING}}));
    }
  }
  else
  {
    shutdownINotifyProcess();
  }
}
Beispiel #10
0
int bandageImage(QStringList arguments)
{
    QTextStream out(stdout);
    QTextStream err(stderr);

    if (checkForHelp(arguments))
    {
        printImageUsage(&out, false);
        return 0;
    }

    if (checkForHelpAll(arguments))
    {
        printImageUsage(&out, true);
        return 0;
    }

    if (arguments.size() < 2)
    {
        printImageUsage(&err, false);
        return 1;
    }

    QString graphFilename = arguments.at(0);
    arguments.pop_front();

    if (!checkIfFileExists(graphFilename))
    {
        err << "Bandage error: " << graphFilename << " does not exist" << endl;
        return 1;
    }

    QString imageSaveFilename = arguments.at(0);
    arguments.pop_front();

    QString imageFileExtension = imageSaveFilename.right(4);
    bool pixelImage;
    if (imageFileExtension == ".png" || imageFileExtension == ".jpg")
        pixelImage = true;
    else if (imageFileExtension == ".svg")
        pixelImage = false;
    else
    {
        err << "Bandage error: the output filename must end in .png, .jpg or .svg" << endl;
        return 1;
    }

    QString error = checkForInvalidImageOptions(arguments);
    if (error.length() > 0)
    {
        err << "Bandage error: " << error << endl;
        return 1;
    }

    bool loadSuccess = g_assemblyGraph->loadGraphFromFile(graphFilename);
    if (!loadSuccess)
    {
        err << "Bandage error: could not load " << graphFilename << endl;
        return 1;
    }

    int width = 0;
    int height = 0;
    parseImageOptions(arguments, &width, &height);

    //For Bandage image, it is necessary to position node labels at the
    //centre of the node, not the visible centre(s).  This is because there
    //is no viewport.
    g_settings->positionTextNodeCentre = true;

    //Since frame rate performance doesn't matter for a fixed image, set the
    //default node outline to a nonzero value.
    g_settings->outlineThickness = 0.3;

    bool blastUsed = isOptionPresent("--query", &arguments);

    if (blastUsed)
    {
        if (!createBlastTempDirectory())
        {
            err << "Error creating temporary directory for BLAST files" << endl;
            return 1;
        }

        QString blastError = g_blastSearch->doAutoBlastSearch();

        if (blastError != "")
        {
            err << blastError << endl;
            return 1;
        }
    }

    QString errorTitle;
    QString errorMessage;
    std::vector<DeBruijnNode *> startingNodes = g_assemblyGraph->getStartingNodes(&errorTitle, &errorMessage,
                                                                                  g_settings->doubleMode,
                                                                                  g_settings->startingNodes,
                                                                                  "all");

    if (errorMessage != "")
    {
        err << errorMessage << endl;
        return 1;
    }

    g_assemblyGraph->buildOgdfGraphFromNodesAndEdges(startingNodes, g_settings->nodeDistance);
    g_assemblyGraph->layoutGraph();

    MyGraphicsScene scene;
    g_assemblyGraph->addGraphicsItemsToScene(&scene);
    scene.setSceneRectangle();
    double sceneRectAspectRatio = scene.sceneRect().width() / scene.sceneRect().height();

    //Determine image size
    //If neither height nor width set, use a default of height = 1000.
    if (height == 0 && width == 0)
        height = 1000;

    //If only height or width is set, scale the other to fit.
    if (height > 0 && width == 0)
        width = height * sceneRectAspectRatio;
    else if (height == 0 && width > 0)
        height = width / sceneRectAspectRatio;

    bool success = true;
    QPainter painter;
    if (pixelImage)
    {
        QImage image(width, height, QImage::Format_ARGB32);
        image.fill(Qt::white);
        painter.begin(&image);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setRenderHint(QPainter::TextAntialiasing);
        scene.render(&painter);
        success = image.save(imageSaveFilename);
        painter.end();
    }
    else //SVG
    {
        QSvgGenerator generator;
        generator.setFileName(imageSaveFilename);
        generator.setSize(QSize(width, height));
        generator.setViewBox(QRect(0, 0, width, height));
        painter.begin(&generator);
        painter.fillRect(0, 0, width, height, Qt::white);
        painter.setRenderHint(QPainter::Antialiasing);
        painter.setRenderHint(QPainter::TextAntialiasing);
        scene.render(&painter);
        painter.end();
    }

    int returnCode;
    if (!success)
    {
        out << "There was an error writing the image to file." << endl;
        returnCode = 1;
    }
    else
        returnCode = 0;

    if (blastUsed)
        deleteBlastTempDirectory();

    return returnCode;
}
rapp_platform_ros_communications::createCognitiveExerciseTestSrv::Response KnowrobWrapper::create_cognitve_tests(rapp_platform_ros_communications::createCognitiveExerciseTestSrv::Request req)
{
  rapp_platform_ros_communications::createCognitiveExerciseTestSrv::Response res;
  if(req.test_type==std::string("") || req.test_difficulty<1 || req.test_path==std::string("") || req.test_subtype==std::string(""))
  {
    res.success=false;
    res.trace.push_back("Error, one or more arguments not provided or out of range. Test variation and test difficulty are positive integers >0");
    res.error=std::string("Error, one or more arguments not provided or out of range.  Test variation and test difficulty are positive integers >0");
    return res;
  }

  std::string path = ros::package::getPath("rapp_cognitive_exercise");
  //res.trace.push_back(path);
  //req.test_path=path+req.test_path;
  std::string temp_check_path=path+req.test_path;
  const char * c = temp_check_path.c_str();
  if(!checkIfFileExists(c))
  {
    res.success=false;
    res.trace.push_back(std::string("Test file does not exist in provided file path"));
    res.trace.push_back(req.test_path);
    res.error=std::string("Test file does not exist in provided file path");
    return res;
  }

  //std::string variation = intToString(req.test_variation);
  std::string difficulty = intToString(req.test_difficulty);
  //res.trace.push_back(variation);
  //res.trace.push_back(difficulty);
  //return res;
  std::string query = std::string("createCognitiveTest(knowrob:'")+req.test_type+std::string("',B,'")+difficulty+std::string("','")+req.test_path+std::string("',knowrob:'")+req.test_subtype+std::string("')");

  json_prolog::PrologQueryProxy results = pl.query(query.c_str());

  char status = results.getStatus();
  if(status==0)
  {
    res.success=false;
    //res.trace.push_back(std::string("Test type/subtype combination invalid. Either test type does not exist, or test sub type does not exist or if they exist the subtype does not correspond to the type"));
    //res.error=std::string("Test type/subtype combination invalid. Either test type does not exist, or test sub type does not exist or if they exist the subtype does not correspond to the type");
    res.trace.push_back(std::string("Test insertion into ontology FAILED, possible error is test type/subtype invalid"));
    res.error=std::string("Test insertion into ontology FAILED, possible error is test type/subtype invalid");
    return res;
  }
  else if(status==3)
  {
    res.success=true;
  }
  std::vector<std::string> query_ret_tests;
  for(json_prolog::PrologQueryProxy::iterator it = results.begin() ;
    it != results.end() ; it++)
  {
    json_prolog::PrologBindings bdg = *it;
    std::string temp_query_tests=bdg["B"];
    query_ret_tests.push_back(temp_query_tests);
  }

  for(unsigned int i = 0 ; i < query_ret_tests.size() ; i++)
  {
    res.test_name=(query_ret_tests[i]);
    //tmp_test_name=(query_ret_tests[i]);
  }


  std::string tmp_test_name;
  tmp_test_name.assign(res.test_name.c_str());
  std::vector<std::string> test_created=split(tmp_test_name,std::string("#"));

  if(test_created.size()==2)
  {
    for(unsigned int i=0 ; i < req.supported_languages.size(); i++)
    {
      query=std::string("rdf_assert(knowrob:'")+test_created[1]+std::string("',knowrob:supportedLanguages,knowrob:'")+req.supported_languages[i]+std::string("')");
      results = pl.query(query.c_str());
    }
  }

  rapp_platform_ros_communications::ontologyLoadDumpSrv::Request dmp;
  dmp.file_url=std::string("currentOntologyVersion.owl");
  KnowrobWrapper::dumpOntologyQuery(dmp);
  return res;
}