int main(int argc, char *argv[]) { ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); } #if _DEBUG || (__GNUC__ && !NDEBUG) #ifdef _WIN32 const char *logfilepath = "./openstudio_pat.log"; #else const char *logfilepath = "/var/log/openstudio_pat.log"; #endif openstudio::Logger::instance().standardOutLogger().setLogLevel(Debug); openstudio::FileLogSink fileLog(openstudio::toPath(logfilepath)); fileLog.setLogLevel(Debug); #else openstudio::Logger::instance().standardOutLogger().setLogLevel(Warn); #endif // list of Ruby modules we want to load into the interpreter std::vector<std::string> modules; modules.push_back("openstudioutilitiescore"); modules.push_back("openstudioutilitiesbcl"); modules.push_back("openstudioutilitiesidd"); modules.push_back("openstudioutilitiesidf"); modules.push_back("openstudioutilities"); modules.push_back("openstudiomodel"); modules.push_back("openstudiomodelcore"); modules.push_back("openstudiomodelsimulation"); modules.push_back("openstudiomodelresources"); modules.push_back("openstudiomodelgeometry"); modules.push_back("openstudiomodelhvac"); modules.push_back("openstudiomodelrefrigeration"); modules.push_back("openstudioenergyplus"); modules.push_back("openstudioruleset"); bool cont = true; while(cont) { cont = false; // Initialize the embedded Ruby interpreter std::shared_ptr<openstudio::detail::RubyInterpreter> rubyInterpreter( new openstudio::detail::RubyInterpreter(openstudio::getOpenStudioRubyPath(), openstudio::getOpenStudioRubyScriptsPath(), modules)); // Initialize the argument getter QSharedPointer<openstudio::ruleset::RubyUserScriptInfoGetter> infoGetter( new openstudio::ruleset::EmbeddedRubyUserScriptInfoGetter<openstudio::detail::RubyInterpreter>(rubyInterpreter)); // Make the run path the default plugin search location QCoreApplication::addLibraryPath(openstudio::toQString(openstudio::getApplicationRunDirectory())); openstudio::pat::PatApp app(argc, argv, infoGetter); openstudio::Application::instance().setApplication(&app); try { return app.exec(); } catch (const std::exception &e) { LOG_FREE(Fatal, "PatApp", "An unhandled exception has occurred: " << e.what()); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unhandled Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unhandled exception has occurred."); msgBox.setInformativeText(e.what()); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } catch (...) { LOG_FREE(Fatal, "PatApp", "An unknown exception has occurred."); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unknown Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unknown exception has occurred."); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } } }
int main(int argc, char *argv[]) { #if RUBY_API_VERSION_MAJOR && RUBY_API_VERSION_MAJOR==2 ruby_sysinit(&argc, &argv); { RUBY_INIT_STACK; ruby_init(); } #endif #if _DEBUG || (__GNUC__ && !NDEBUG) openstudio::Logger::instance().standardOutLogger().setLogLevel(Debug); openstudio::FileLogSink fileLog(openstudio::toPath(logfilepath)); fileLog.setLogLevel(Debug); #else openstudio::Logger::instance().standardOutLogger().setLogLevel(Warn); #endif bool cont = true; while(cont) { cont = false; std::vector<std::string> modules; modules.push_back("openstudioutilitiescore"); modules.push_back("openstudioutilitiesbcl"); modules.push_back("openstudioutilitiesidd"); modules.push_back("openstudioutilitiesidf"); modules.push_back("openstudioutilities"); modules.push_back("openstudiomodel"); modules.push_back("openstudiomodelcore"); modules.push_back("openstudiomodelsimulation"); modules.push_back("openstudiomodelresources"); modules.push_back("openstudiomodelgeometry"); modules.push_back("openstudiomodelhvac"); modules.push_back("openstudioenergyplus"); modules.push_back("openstudioruleset"); //try { // Initialize the embedded Ruby interpreter boost::shared_ptr<openstudio::detail::RubyInterpreter> rubyInterpreter( new openstudio::detail::RubyInterpreter(openstudio::getOpenStudioRubyPath(), openstudio::getOpenStudioRubyScriptsPath(), modules)); // Initialize the argument getter QSharedPointer<openstudio::ruleset::RubyUserScriptArgumentGetter> argumentGetter( new openstudio::ruleset::detail::RubyUserScriptArgumentGetter_Impl<openstudio::detail::RubyInterpreter>(rubyInterpreter)); openstudio::OpenStudioApp app(argc, argv, argumentGetter); openstudio::Application::instance().setApplication(&app); try { return app.exec(); } catch (const std::exception &e) { LOG_FREE(Fatal, "OpenStudio", "An unhandled exception has occurred: " << e.what()); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unhandled Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unhandled exception has occurred."); msgBox.setInformativeText(e.what()); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } catch (...) { LOG_FREE(Fatal, "OpenStudio", "An unknown exception has occurred."); cont = true; QMessageBox msgBox; msgBox.setWindowTitle("Unknown Exception"); msgBox.setIcon(QMessageBox::Critical); msgBox.setText("An unknown exception has occurred."); msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close); msgBox.button(QMessageBox::Retry)->setText("Relaunch"); if (msgBox.exec() == QMessageBox::Close) { cont = false; } } } }