Esempio n. 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
    }

  }
Esempio n. 2
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;
    }

  }
Esempio n. 3
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;
  }
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;
  }


}
Esempio n. 5
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.

    }
  }
Esempio n. 6
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());
    }
  }
bool AnalysisDriverTestLibrarySingleton::pathStemEquals(const openstudio::path& p, const std::string& str) {
    return (toString(p.stem()) == str);
}