本文整理汇总了C++中openstudio::path类的典型用法代码示例。如果您正苦于以下问题:C++ path类的具体用法?C++ path怎么用?C++ path使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了path类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeModelTempDir
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: toPath
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: readLfr
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));
}
示例4: doit
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: rootPathChanged
void MainWindow::rootPathChanged(const openstudio::path &p)
{
if (toPath(ui.txtRootPath->text()) != p)
{
ui.txtRootPath->setText(toQString(p.external_file_string()));
}
}
示例6: OSItem
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: EpwFile
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: createEnergyPlusJob
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: toPath
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;
}
示例10: getFilename
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;
}
}
示例11: saveModelTempDir
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.
}
}
示例12: connect
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);
}
示例13: complete
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;
}
}
示例14: toString
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());
}
}
示例15: modelToSDD
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;
}