Exemple #1
0
  openstudio::path MainWindow::getOutDir(const openstudio::path &t_file, const openstudio::runmanager::Workflow &t_wf, const std::string &t_jobstring, bool t_simpleName)
  {
    openstudio::path outpath = m_runmanager.getConfigOptions().getOutputLocation();
    openstudio::path parentdir = t_file.parent_path();
    openstudio::path jobname;
    openstudio::path tailpathname = toPath("workflow-" + (t_simpleName?t_jobstring:t_wf.key()));

    QString jobstring = toQString(t_jobstring);
    jobstring.remove(">");

    if (openstudio::toString(t_file.stem()) == "in")
    {
      // The file is called "in", let's use the parent path's name as our job name
      jobname = openstudio::toPath(parentdir.filename());
    } else {
      // Let's use the stem of the file name to create a working dir, since it's a meaningful name
      jobname = openstudio::toPath(t_file.stem());     
    }

    std::string workflowkey = "workflow-" + t_wf.key();

    if (outpath.empty())
    {
      if (openstudio::toString(t_file.stem()) == "in")
      {
        return parentdir / tailpathname; // if we are running in the parent dir, and our name is "in" no reason to make a subdir
      } else {
        return parentdir / jobname / tailpathname; // we are either reconstructing the path it was already in, or making a new one based on the file name
      }

    } else {
      return outpath / jobname / tailpathname; // use the outpath
    }

  }
Exemple #2
0
  bool initializeModelTempDir(const openstudio::path& osmPath, const openstudio::path& modelTempDir)
  {
    bool result = true;
    
    if( osmPath.empty() || !boost::filesystem::exists(osmPath)){
     
      LOG_FREE(Debug, "initializeModelTempDir", "OSM path '" << toString(osmPath) << "' is empty or does not exist");
      result = false;

    }else{
      LOG_FREE(Debug, "initializeModelTempDir", "Copying '" << toString(osmPath) << "' to '" << toString(modelTempDir / toPath("in.osm")) << "'");
   
      // copy osm file
      bool test = QFile::copy(toQString(osmPath), toQString(modelTempDir / toPath("in.osm")));
      if (!test){
        LOG_FREE(Error, "initializeModelTempDir", "Could not copy '" << toString(osmPath) << "' to '" << toString(modelTempDir / toPath("in.osm")) << "'");
      }

      // Copy all files from existing resources dir into temp dir when opening
      openstudio::path sourceDir = osmPath.parent_path() / osmPath.stem();
      openstudio::path destDir = modelTempDir / toPath("resources");
      if (boost::filesystem::exists(sourceDir)){
        LOG_FREE(Debug, "initializeModelTempDir", "Copying '" << toString(sourceDir) << "' to '" << toString(destDir) << "'");

        test = copyDir(toQString(sourceDir), toQString(destDir));
        if (!test){
          LOG_FREE(Error, "initializeModelTempDir", "Could not copy '" << toString(sourceDir) << "' to '" << toString(destDir) << "'");
          result = false;
        }
      }
    }

    return result;
  }
  ScriptsVectorController::ScriptsVectorController(const openstudio::path &t_path,
      const std::shared_ptr<QFileSystemWatcher> &t_fswatcher)
    : m_path(t_path), m_fswatcher(t_fswatcher)
  {
    connect(m_fswatcher.get(), &QFileSystemWatcher::directoryChanged, this, &ScriptsVectorController::directoryChanged);
    if (boost::filesystem::exists(t_path))
    {
      m_fswatcher->addPath(openstudio::toQString(t_path));
    }

    if (boost::filesystem::exists(t_path.parent_path()))
    {
      m_fswatcher->addPath(openstudio::toQString(t_path.parent_path()));
    }

    directoryChanged(openstudio::toQString(m_path));

    LOG(Debug, "Created ScriptVectorController " << m_path);
  }
  bool ForwardTranslator::modelToSDD(const openstudio::model::Model& model, const openstudio::path& path, ProgressBar* progressBar)
  {
    m_progressBar = progressBar;
    m_translatedObjects.clear();
    m_ignoreTypes.clear();
    m_ignoreObjects.clear();

    m_logSink.setThreadId(QThread::currentThread());

    m_logSink.resetStringStream();

    model::Model modelCopy = model.clone().cast<model::Model>();

    // remove unused resource objects
    modelCopy.purgeUnusedResourceObjects();

    boost::optional<QDomDocument> doc = this->translateModel(modelCopy);
    logUntranslatedObjects(modelCopy);
    if (!doc){
      return false;
    }

    if (exists(path)){
      remove(path);
    }

    if (!exists(path.parent_path())){
      create_directory(path.parent_path());
    }

    QFile file(toQString(path));
    if (file.open(QFile::WriteOnly)){
      QTextStream textStream(&file);
      textStream.setCodec("UTF-8");
      textStream << doc->toString(2);
      file.close();
      return true;
    }

    return false;
  }
openstudio::path ScriptFolderListView::iterateFileName(const openstudio::path &t_path)
{
  struct BuildFileName
  {
    static openstudio::path doit(const openstudio::path &t_root,
        const std::string &t_stem,
        const std::string &t_extension,
        int iteration)
    {
      std::stringstream numportion;
      if (iteration > 0)
      {
        numportion << "-";
        if (iteration < 10)
        {
          numportion << "0";
        } 
        numportion << iteration;
      }
      return t_root / openstudio::toPath(t_stem + numportion.str() + t_extension);
    }
  };

  std::string stem = openstudio::toString(t_path.stem());

  if (boost::regex_match(openstudio::toString(stem), boost::regex(".*-[0-9][0-9]")))
  {
    stem = stem.substr(0, stem.size() - 3);
  }

  int num = 99;
  openstudio::path p;
  openstudio::path last;
  do
  {
    last = p;
    p = BuildFileName::doit(t_path.parent_path(), openstudio::toString(stem), openstudio::toString(t_path.extension()), num);
    --num;
  } while (!boost::filesystem::exists(p) && num > -1);

  if (!boost::filesystem::exists(p))
  {
    return p;
  } else {
    return last;
  }


}
Exemple #6
0
  void saveModelTempDir(const openstudio::path& modelTempDir, const openstudio::path& osmPath)
  {
    bool test = true;

    // must remove file, QFile::copy does not overwrite
    QFileInfo osmInfo(toQString(osmPath));
    if (osmInfo.exists() && osmInfo.isFile()){
      test = QFile::remove(toQString(osmPath));
      if (!test){
        LOG_FREE(Error, "saveModelTempDir", "Could not remove previous osm at '" << toString(osmPath) << "'");
      }
    }

    // copy osm file
    openstudio::path srcPath = modelTempDir / toPath("in.osm");
    test = QFile::copy(toQString(srcPath), toQString(osmPath));
    if (!test){
      LOG_FREE(Error, "saveModelTempDir", "Could not copy osm from '" << toString(srcPath) << "' to '" << toString(osmPath) << "'");
    }

    if( QFileInfo(toQString(osmPath)).exists() ) {

      // copy resources
      openstudio::path srcDir = modelTempDir / toPath("resources");
      openstudio::path dstDir =  osmPath.parent_path() / osmPath.stem();

      openstudio::path srcproject = srcDir / toPath("project.osp");
      openstudio::path destproject = dstDir / toPath("project.osp");

//      LOG_FREE(Debug, "saveModelTempDir", "copying project file: " << toString(srcproject) << " to " << toString(destproject));
//      QFile::copy(toQString(srcproject), toQString(destproject));

      LOG_FREE(Debug, "saveModelTempDir", "Copying " << toString(srcDir) << " to " << toString(dstDir));

      test = copyDir(toQString(srcDir), toQString(dstDir));
      if (!test){
        LOG_FREE(Error, "saveModelTempDir", "Could not copy '" << toString(srcDir) << "' to '" << toString(dstDir) << "'");
      }

      // TODO: Open all osps just copied over to make the stored paths look reasonable.

    }
  }
Exemple #7
0
  void MainWindow::queueSimulation(const openstudio::path &t_input, const openstudio::path &t_epw)
  {
    try {
      // Build list of jobs to create
      std::string jobsstring = toString(ui.cbWorkflow->currentText());

      if (jobsstring == "<Custom>")
      {
        openstudio::path expecteddb = t_input.parent_path() / t_input.stem() / openstudio::toPath("run.db");

        if (!boost::filesystem::exists(expecteddb))
        {
          QMessageBox::critical(this, "Unable to launch job", "Db containing custom workflow for OpenStudio UI created OSM not found at the expected location: " + openstudio::toQString(expecteddb));
        } else {
          try {
            m_runmanager.loadJobs(expecteddb);
            statusBar()->showMessage("Job Queued - " + openstudio::toQString(t_input));
          } catch (const std::exception &e) {
            QMessageBox::critical(this, "Unable to launch job", e.what());
          }
        }
      } else {
        // parse the string list with the workflow constructor
        openstudio::runmanager::Workflow workflow(jobsstring);

        // Build list of tools
        openstudio::runmanager::Tools tools;
        ConfigOptions co = m_runmanager.getConfigOptions();
        tools.append(co.getTools());
        workflow.add(tools);

        workflow.setInputFiles(t_input, t_epw);
        openstudio::runmanager::Job job = workflow.create(getOutDir(t_input, workflow, jobsstring, co.getSimpleName()));

        m_runmanager.enqueue(job, false);
        statusBar()->showMessage("Job Queued - " + openstudio::toQString(job.description()));
      }
    } catch (const std::exception &e) {
      QMessageBox::critical(this, "Unable to launch job", e.what());
    }
  }
Exemple #8
0
OSItemId scriptToItemId(const openstudio::path &t_path)
{
  return OSItemId(openstudio::toQString(t_path), openstudio::toQString(t_path.parent_path().filename()), false, "");
}