/** path to a temporary directory. */ path tempDir() { return toPath(QDir::tempPath()); }
/** UTF-8 encoded char* to path*/ path toPath(const char* s) { return toPath(toString(s)); }
void ModelInModelOutJob::startImpl(const boost::shared_ptr<ProcessCreator> &) { openstudio::path outpath = outdir(true); QWriteLocker l(&m_mutex); if (!m_model) { m_model = modelFile(); resetFiles(m_files, m_model); } std::vector<boost::shared_ptr<ModelInModelOutJob> > mergedJobs = m_mergedJobs; boost::optional<FileInfo> model = m_model; LOG(Info, "ModelInModelOut starting, filename: " << toString(m_model->fullPath)); LOG(Info, "ModelInModelOut starting, outdir: " << toString(outpath)); LOG(Info, "ModelInModelOut starting, num merged jobs: " << m_mergedJobs.size()); m_lastrun = QDateTime::currentDateTime(); JobErrors errors; errors.result = ruleset::OSResultValue::Success; l.unlock(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Starting)); emitStarted(); emitStatusChanged(AdvancedStatus(AdvancedStatusEnum::Processing)); try { boost::filesystem::create_directories(outpath); model::OptionalModel m = model::Model::load(model->fullPath); if (!m) { errors.addError(ErrorType::Error, "Unable to load model: " + toString(model->fullPath)); errors.result = ruleset::OSResultValue::Fail; } else { LOG(Info, "ModelInModelOut executing primary job"); model::Model outmodel = modelToModelRun(*m); for (std::vector<boost::shared_ptr<ModelInModelOutJob> >::iterator itr = mergedJobs.begin(); itr != mergedJobs.end(); ++itr) { LOG(Info, "ModelInModelOut executing merged job"); outmodel = (*itr)->modelToModelRun(outmodel); } openstudio::path outFile = outpath / toPath("out.osm"); if (!outmodel.save(outFile,true)) { errors.addError(ErrorType::Error, "Error while writing final output file"); errors.result = ruleset::OSResultValue::Fail; } } } catch (const std::exception &e) { errors.addError(ErrorType::Error, "Error with processing: " + std::string(e.what())); errors.result = ruleset::OSResultValue::Fail; } emitOutputFileChanged(RunManager_Util::dirFile(outpath / openstudio::toPath("out.osm"))); setErrors(errors); }
/** UTF-8 encoded std::string to path*/ path toPath(const std::string& s) { return toPath(toQString(s)); }
boost::optional<openstudio::path> WorkflowJSON_Impl::findMeasure(const std::string& measureDirName) const { return findMeasure(toPath(measureDirName)); }
void XMLPreprocessorJob::startHandlerImpl() { getFiles(allInputFiles()); addRequiredFile(*m_xml, toPath("in.xml")); copyRequiredFiles(*m_xml, "idf", toPath("in.epw")); }
openstudio::path WorkflowJSON_Impl::outPath() const { Json::Value defaultValue("out.osw"); Json::Value path = m_value.get("out_name", defaultValue); return toPath(path.asString()); }
boost::optional<openstudio::path> WorkflowJSON_Impl::findFile(const std::string& fileName) const { return findFile(toPath(fileName)); }
openstudio::path WorkflowJSON_Impl::rootDir() const { Json::Value defaultValue("."); Json::Value root = m_value.get("root", defaultValue); return toPath(root.asString()); }
openstudio::path WorkflowJSON_Impl::runDir() const { Json::Value defaultValue("./run"); Json::Value runDirectory = m_value.get("run_directory", defaultValue); return toPath(runDirectory.asString()); }
void FilePath::setPath(const std::string & path) { m_originalPath = path; m_path = toPath(m_originalPath); }
FilePath::FilePath(const char * path) : m_originalPath(path) , m_path(toPath(m_originalPath)) { }
FilePath::FilePath(const std::string & path) : m_originalPath(path) , m_path(toPath(m_originalPath)) { }
void FileInfo::addRequiredFile(const QUrl &t_url) { addRequiredFile(t_url, toPath(toPath(t_url.toLocalFile()).filename())); }
/// get the QApplication, if no QApplication has been set this will create a default one QCoreApplication* ApplicationSingleton::application(bool gui) { if (!m_qApplication){ if (QApplication::instance()) { m_qApplication = QApplication::instance(); } else { QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true); QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true); #if defined(Q_OS_MAC) openstudio::path p = getApplicationRunDirectory().parent_path().parent_path().parent_path() / toPath("Ruby/openstudio"); QCoreApplication::addLibraryPath(QString::fromStdString(toString(p))); #endif #if defined(Q_OS_WIN32) openstudio::path p = getApplicationRunDirectory().parent_path() / toPath("Ruby/openstudio"); QCoreApplication::addLibraryPath(QString::fromStdString(toString(p))); #endif // Add this path for gem case QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory() / toPath("plugins"))); // And for any other random cases QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory().parent_path() / toPath("share/openstudio/qtplugins"))); static char *argv[] = {NULL}; static int argc = sizeof(argv) / sizeof(char*) - 1; m_qApplication = new QApplication(argc, argv, gui); dynamic_cast<QApplication*>(m_qApplication)->setQuitOnLastWindowClosed(false); defaultInstance = true; // check if we are in a SketchUp process #if _WIN32 || _MSC_VER DWORD pId = GetCurrentProcessId(); //HMODULE hModule = GetModuleHandle(NULL); // same as hInstance LPTSTR className = new TCHAR[255]; LPTSTR typeName = new TCHAR[255]; HWND h = GetTopWindow(0); while ( h ) { DWORD pId2; GetWindowThreadProcessId(h, &pId2); if ( pId == pId2 ){ GetClassName(h, className, 255); GetWindowText(h, typeName, 255); if (boost::regex_match(toString(typeName), boost::regex(".*- SketchUp.*"))){ m_sketchUpWidget = new QWinWidget(h); break; } } h = GetNextWindow(h , GW_HWNDNEXT); } delete[] className; delete[] typeName; #endif } } return m_qApplication; }