示例#1
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;
  }
示例#2
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);
  }
示例#3
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);
  }
  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;
  }
示例#5
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;
  }
示例#6
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;
  }
}
示例#7
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;
}
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;
}
示例#9
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;
 }
示例#10
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;
}