Пример #1
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;
  }
Пример #2
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
    }

  }
Пример #3
0
SimFile::SimFile(openstudio::path path)
{
  m_hasLfr = false;
  m_hasNfr = false;
  m_hasNcr = false;
  // For now, we need to cheat and assume that the .lfr etc. actually exist
  // This means that simread has to have been run for this to work
  openstudio::path lfrPath = path.replace_extension(openstudio::toPath("lfr").string());
  m_hasLfr = readLfr(openstudio::toQString(lfrPath));
  openstudio::path nfrPath = path.replace_extension(openstudio::toPath("nfr").string());
  m_hasNfr = readNfr(openstudio::toQString(nfrPath));
}
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;
  }


}
Пример #5
0
 void MainWindow::rootPathChanged(const openstudio::path &p)
 {
   if (toPath(ui.txtRootPath->text()) != p)
   {
     ui.txtRootPath->setText(toQString(p.external_file_string()));
   }
 }
Пример #6
0
ScriptItem::ScriptItem(const openstudio::path& path,
                       OSItemType type,
                       QWidget * parent)
  : OSItem(scriptToItemId(path), type, parent),
    m_removed(false),
    m_scriptInfo(path, true, false)
{
  setText(openstudio::toQString(path.filename()));
  setLeftPixmap(QPixmap(":/images/icon_scripts.png"));
  if (boost::regex_search(toString(itemId().sourceId()),boost::regex("resource"))) {
    m_scriptInfo.isUserScript = false;
  }
  else {
    try {
      m_scriptInfo = runmanager::RubyJobBuilder::updateArgumentsFromDb(m_scriptInfo);
    } catch (const runmanager::ScriptDetectionError &e) {
      // Nothing to display here in the constructor
      m_scriptInfo = e.scriptInfo;
    }
  }


  std::shared_ptr<OSDocument> osDoc = OSAppBase::instance()->currentDocument();
  connect(this, &ScriptItem::argChanged, osDoc.get(), &OSDocument::markAsModified);
}
Пример #7
0
  boost::optional<EpwFile> WeatherFile_Impl::file(const openstudio::path& dir) const {
    boost::optional<EpwFile> result;

    // get current path
    boost::optional<openstudio::path> currentPath = this->path();
    if (currentPath){

      // try to load absolute path
      if (currentPath->is_complete() && boost::filesystem::exists(*currentPath)) {
        try {
          result = EpwFile(*currentPath);
          return result;
        }catch (...) {}

        // loading absolute path failed, try as relative path
        currentPath = toPath(currentPath->filename());
      }

      // try relative path
      if (!dir.empty()){
        openstudio::path newPath = boost::filesystem::complete(*currentPath, dir);
        if (boost::filesystem::exists(newPath)) {
          try {
            result = EpwFile(newPath);
            return result;
          }catch (...) {}
        }
      }
    }

    return boost::none;
  }
Пример #8
0
  Job JobFactory::createEnergyPlusJob(
      ToolInfo t_energyPlusTool,
      const openstudio::path &t_idd,
      const openstudio::path &t_idf,
      const openstudio::path &t_epw,
      const openstudio::path &t_outdir,
      const boost::optional<openstudio::UUID> &t_uuid)
  {
    JobParams params;
    params.append("outdir", toString(t_outdir));

    Tools tools;
    t_energyPlusTool.name = "energyplus";
    tools.append(t_energyPlusTool);

    Files files;
    FileInfo idf(t_idf, "idf");

    if (!t_idd.empty())
    {
      idf.addRequiredFile(t_idd,toPath("Energy+.idd"));
    }

    idf.addRequiredFile(t_epw, toPath("in.epw"));
    files.append(idf);

    return createEnergyPlusJob(tools, params, files, std::vector<openstudio::URLSearchPath>(), t_uuid);
  }
Пример #9
0
  Job JobFactory::createEnergyPlusJob(
      const openstudio::runmanager::Tools &t_tools,
      const openstudio::path &t_idd,
      const openstudio::path &t_idf,
      const openstudio::path &t_epw,
      const openstudio::path &t_outdir,
      const boost::optional<openstudio::UUID> &t_uuid)
  {
    JobParams params;
    params.append("outdir", toString(t_outdir));

    Files files;
    FileInfo idf(t_idf, "idf");

    if (!t_idd.empty())
    {
      idf.addRequiredFile(t_idd,toPath("Energy+.idd"));
    }

    if (boost::filesystem::is_directory(t_epw))
    {
      params.append("epwdir", toString(t_epw));
    } else {
      idf.addRequiredFile(t_epw, toPath("in.epw"));
    }

    files.append(idf);

    return createEnergyPlusJob(t_tools, params, files, std::vector<openstudio::URLSearchPath>(), t_uuid);
  }
Пример #10
0
  boost::optional<TimeDependentValuationFile> TimeDependentValuation_Impl::file(const openstudio::path& dir) const {
    if (!m_file) {

      // get current path
      boost::optional<openstudio::path> currentPath = this->path();
      if (currentPath){
  
        // try to load absolute path
        if (currentPath->is_complete() && boost::filesystem::exists(*currentPath)) {
          m_file = TimeDependentValuationFile::load(*currentPath);

          // loading absolute path failed, try as relative path
          if (!m_file){
            currentPath = toPath(currentPath->filename());
          }
        }

        // try relative path
        if (!m_file){
          if (!dir.empty()){
            openstudio::path newPath = boost::filesystem::complete(*currentPath, dir);
            if (boost::filesystem::exists(newPath)) { 
              m_file = TimeDependentValuationFile::load(*currentPath);
            }
          }
        }
      }
    }
    return m_file;
  }
Пример #11
0
  openstudio::path NormalizeURLs::getFilename(const QUrl &t_url, const openstudio::path &t_filename)
  {
    const std::map<QUrl, openstudio::path>::const_iterator itr = m_url_map.find(t_url);

    if (itr != m_url_map.end())
    {
      // we've already mapped this url, let's return the same one
      return itr->second;
    }

    const size_t existingcount = m_filenames.count(t_filename);

    if (existingcount == 0)
    {
      m_filenames.insert(t_filename);
      m_url_map[t_url] = t_filename;
      return t_filename;
    } else {
      openstudio::path newfilename 
        = toPath(t_filename.stem().string() + toPath("-" + boost::lexical_cast<std::string>(existingcount)).string() + t_filename.extension().string());

      // Make sure both the newly generated file name and the passed in file name are tracked for counting purposes
      m_filenames.insert(newfilename);
      m_filenames.insert(t_filename);

      m_url_map[t_url] = newfilename;
      return newfilename;
    }

  }
Пример #12
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.

    }
  }
Пример #13
0
  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);
  }
Пример #14
0
FileInfo FileInfo::complete(const openstudio::path &t_basePath) const
{
  if (t_basePath.empty() || fullPath.empty())
  {
    return *this;
  } else {
    FileInfo fi = *this;
    fi.fullPath = boost::filesystem::complete(fullPath, t_basePath);
    return fi;
  }
}
Пример #15
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());
    }
  }
Пример #16
0
  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;
  }
Пример #17
0
void ScriptFolderListView::addScriptToFolder(const openstudio::path &t_path, const openstudio::path& folder_name)
{
  openstudio::path folder = m_rootPath / folder_name;
  boost::filesystem::create_directories(folder);
  openstudio::path filename = folder / t_path.filename();
  filename = iterateFileName(filename);
  boost::filesystem::copy_file(t_path, filename, boost::filesystem::copy_option::overwrite_if_exists);
  

  ScriptsListView *lv = m_scriptsListViews[folder];
  if (lv)
  {
    lv->updateData();
  }
}
Пример #18
0
bool FileReference::makePathRelative(const openstudio::path& basePath) {
  openstudio::path newPath;
  if (basePath.empty()) {
    newPath = path().filename();
  }
  else {
    newPath = relativePath(path(),basePath);
  }
  if (newPath.empty()) {
    return false;
  }
  m_path = newPath;
  m_versionUUID = createUUID();
  return true;
}
Пример #19
0
 bool WeatherFile_Impl::makeUrlRelative(const openstudio::path& basePath) {
   boost::optional<openstudio::path> currentPath = this->path();
   if (currentPath){
     openstudio::path newPath;
     if (basePath.empty()) {
       newPath = toPath(currentPath->filename());
     } else {
       newPath = relativePath(*currentPath,basePath);
     }
     if (!newPath.empty()) {
       std::string weatherFileUrl = toString(toURL(newPath));
       LOG(Debug,"Setting weather file url to " << weatherFileUrl);
       return setString(OS_WeatherFileFields::Url,weatherFileUrl);
     }
   }
   return false;
 }
Пример #20
0
std::vector<openstudio::path> ProjectVersioningFixture::projectDatabasePaths(
    openstudio::path basePath)
{
  std::vector<openstudio::path> result;

  if (basePath.empty()) {
    basePath = toPath("ProjectVersioningFixtureData") / toPath(toString(uuid));
  }

  for (boost::filesystem::directory_iterator it(basePath), itend; it != itend; ++it)
  {
    if (getFileExtension(it->path()) == "osp") {
      result.push_back(it->path());
    }
  }
  return result;
}
Пример #21
0
FileReference::FileReference(const openstudio::path& p)
  : m_uuid(createUUID()),
    m_versionUUID(createUUID()),
    m_name(toString(p)),
    m_displayName(toString(p.filename())),
    m_path(completeAndNormalize(p)),
    m_timestampLast(),
    m_checksumCreate(checksum(m_path)),
    m_checksumLast(m_checksumCreate)
{
  try {
    m_fileType = FileReferenceType(getFileExtension(p));
  }
  catch (...) {
    m_fileType = FileReferenceType::Unknown;
  }
  update(openstudio::path());
}
Пример #22
0
  boost::optional<openstudio::path> WorkflowJSON_Impl::findFile(const openstudio::path& file) const
  {
    // if absolute check if exists
    if (file.is_absolute()){
      if (boost::filesystem::exists(file)){
        return file;
      }

      // absolute path does not exist
      return boost::none;
    }

    for (const auto& path : absoluteFilePaths()){
      openstudio::path p = path / file;
      if (boost::filesystem::exists(p) && boost::filesystem::is_regular_file(p)){
        return canonicalOrAbsolute(p);
      }
    }
    return boost::none;
  }
Пример #23
0
  boost::optional<openstudio::path> WorkflowJSON_Impl::findMeasure(const openstudio::path& measureDir) const
  {
    // if absolute check if exists
    if (measureDir.is_absolute()){
      if (boost::filesystem::exists(measureDir)){
        return measureDir;
      }

      // absolute path does not exist
      return boost::none;
    }

    for (const auto& path : absoluteMeasurePaths()){
      openstudio::path p = path / measureDir;
      if (boost::filesystem::exists(p) && boost::filesystem::is_directory(p)){
        return canonicalOrAbsolute(p);
      }
    }
    return boost::none;
  }
Пример #24
0
bool FileReference::makePathAbsolute(const openstudio::path& searchDirectory) {
  // trivial completion
  openstudio::path currentPath = path();
  if (currentPath.is_complete() && openstudio::filesystem::exists(currentPath)) {
    return true;
  }
  openstudio::path workingPath(currentPath);
  // if currentPath is complete but does not exist, go to extreme measures
  if (currentPath.is_complete()) {
    workingPath = currentPath.filename();
  }
  if (searchDirectory.empty()) {
    return false;
  }
  openstudio::path newPath = openstudio::filesystem::complete(workingPath,searchDirectory);
  if (newPath.empty() || !openstudio::filesystem::exists(newPath)) {
    return false;
  }
  m_path = completeAndNormalize(newPath);
  m_versionUUID = createUUID();
  return true;
}
Пример #25
0
void FileInfo::addRequiredFile(const openstudio::path &t_location)
{
  addRequiredFile(QUrl::fromLocalFile(toQString(t_location.native_file_string())));
}
Пример #26
0
OSItemId scriptToItemId(const openstudio::path &t_path)
{
  return OSItemId(openstudio::toQString(t_path), openstudio::toQString(t_path.parent_path().filename()), false, "");
}
bool AnalysisDriverTestLibrarySingleton::pathStemEquals(const openstudio::path& p, const std::string& str) {
    return (toString(p.stem()) == str);
}