Skip to content

Commit

Permalink
Merge pull request #720 from openstudiocoalition/measure_fixes
Browse files Browse the repository at this point in the history
Fix issues with MeasureManager
  • Loading branch information
jmarrec authored Aug 2, 2024
2 parents 2fd41ec + da2d1ed commit 55f5cc3
Show file tree
Hide file tree
Showing 175 changed files with 2,076 additions and 14,496 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ endif()

# TODO: Modify the more specific variables as needed to indicate prerelease, etc
# Keep in beta in-between release cycles. Set to empty string (or comment out) for official)
set(PROJECT_VERSION_PRERELEASE "")
set(PROJECT_VERSION_PRERELEASE "rc1")

# OpenStudio version: Only include Major.Minor.Patch, eg "3.0.0", even if you have a prerelease tag
set(OPENSTUDIOAPPLICATION_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
Expand Down Expand Up @@ -645,6 +645,16 @@ endif()

set(CMAKE_AUTOMOC OFF)

include(FetchContent)

FetchContent_Declare(
openstudio-coalition-measures
GIT_REPOSITORY https://github.com/openstudiocoalition/openstudio-coalition-measures.git
GIT_TAG da6832b3eec8e3ecccaadd39142e7c3d9c2da10f # release-1.8.0
)

FetchContent_MakeAvailable(openstudio-coalition-measures)

###############################################################################
# I N C L U D E P A T H S #
###############################################################################
Expand Down Expand Up @@ -776,7 +786,7 @@ install(IMPORTED_RUNTIME_ARTIFACTS openstudio::pythonengine DESTINATION ${LIB_DE

# TODO: we should probably just install the **entire** OS SDK bin/ directory...
if(WIN32)
install(PROGRAMS "${openstudio_ROOT_DIR}/bin/python38.dll" DESTINATION bin COMPONENT "CLI")
install(PROGRAMS $<$<CONFIG:Debug>:${openstudio_ROOT_DIR}/bin/python38_d.dll>$<$<CONFIG:Release>:${openstudio_ROOT_DIR}/bin/python38.dll>$<$<CONFIG:RelWithDebInfo>:${openstudio_ROOT_DIR}/bin/python38.dll>$<$<CONFIG:MinSizeRel>:${openstudio_ROOT_DIR}/bin/python38.dll> DESTINATION bin COMPONENT "CLI")
endif()

# install(PROGRAMS ${OS_CLI_IMPORTED_PATH} DESTINATION bin COMPONENT "CLI" RENAME "${OS_CLI_IMPORTED_NAME}")
Expand Down
40 changes: 26 additions & 14 deletions src/openstudio_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,35 @@ get_target_property(os_lib_location openstudio::openstudiolib LOCATION)
get_filename_component(os_lib_dir ${os_lib_location} DIRECTORY)
set(DIRS "${QT_INSTALL_DIR}/bin" "${QT_INSTALL_DIR}/lib" "${os_lib_dir}")

if(APPLE)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/openstudio_app/Resources/
DESTINATION OpenStudioApp.app/Contents/Resources
COMPONENT "Resources"
)
elseif(WIN32)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/openstudio_app/Resources/
DESTINATION Resources
COMPONENT "Resources"
)
# install resources directory
if( APPLE )
set(RESOURCES_DEST "OpenStudioApp.app/Contents/Resources")
else()
install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/openstudio_app/Resources/
DESTINATION Resources
COMPONENT "Resources"
)
set(RESOURCES_DEST "Resources")
endif()

install(DIRECTORY ${CMAKE_SOURCE_DIR}/src/openstudio_app/Resources/
DESTINATION ${RESOURCES_DEST}
COMPONENT "Resources"
)

# install measures/models from openstudio-coalition-measures

install(FILES ${openstudio-coalition-measures_SOURCE_DIR}/models/ShoeboxExample.osm
DESTINATION ${RESOURCES_DEST}/ShoeboxModel
COMPONENT "Resources"
)

install(DIRECTORY ${openstudio-coalition-measures_SOURCE_DIR}/models/ShoeboxExample
DESTINATION ${RESOURCES_DEST}/ShoeboxModel
COMPONENT "Resources"
)

install(DIRECTORY ${openstudio-coalition-measures_SOURCE_DIR}/models/ShoeboxExample/measures/openstudio_results
DESTINATION ${RESOURCES_DEST}/openstudio_results
COMPONENT "Resources"
)

# since on apple the whole app bundle is installed (including these webkit components) we can exclude apple
if( NOT APPLE )

Expand Down
83 changes: 53 additions & 30 deletions src/openstudio_app/OpenStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ OpenStudioApp::OpenStudioApp(int& argc, char** argv)
waitDialog->show();
emit resetWaitDialog();

measureManager().setResourcesPath(resourcesPath());

// Non blocking
startMeasureManagerProcess();

Expand Down Expand Up @@ -266,14 +268,11 @@ void OpenStudioApp::onMeasureManagerAndLibraryReady() {
msgBox.setText(tr("Failed to start the Measure Manager. Would you like to keep waiting?"));
msgBox.setStandardButtons(QMessageBox::Retry | QMessageBox::Close);
if (msgBox.exec() == QMessageBox::Close) {
// this is a fatal error, application will close
showFailedMeasureManagerDialog();
QCoreApplication::exit();
return;
} else {
measureManager().waitForStarted(10000);
++currentTry;
// user can cancel out of this quit, turns into retry
quit();
}
measureManager().waitForStarted(10000);
++currentTry;
}
LOG(Info, "Recovered from Measure Manager problem, managed to start it on try " << currentTry
<< " at: " << toString(measureManager().url().toString()));
Expand Down Expand Up @@ -1174,8 +1173,9 @@ void OpenStudioApp::readSettings() {
setLastPath(settings.value("lastPath", QDir::homePath()).toString());
setDviewPath(openstudio::toPath(settings.value("dviewPath", "").toString()));
m_currLang = settings.value("language", "en").toString();
m_useClassicCLI = settings.value("useClassicCLI", false).toBool();
LOG_FREE(Debug, "OpenStudioApp", "\n\n\nm_currLang=[" << m_currLang.toStdString() << "], m_useClassicCLI=" << m_useClassicCLI << "\n\n\n");
LOG_FREE(Debug, "OpenStudioApp",
"\n\n\nm_currLang=[" << m_currLang.toStdString() << "]"
<< "\n\n\n");
if (m_currLang.isEmpty()) {
m_currLang = "en";
}
Expand Down Expand Up @@ -1246,6 +1246,7 @@ void OpenStudioApp::connectOSDocumentSignals() {
connect(m_osDocument.get(), &OSDocument::changeLanguageClicked, this, &OpenStudioApp::changeLanguage);
connect(m_osDocument.get(), &OSDocument::loadLibraryClicked, this, &OpenStudioApp::loadLibrary);
connect(m_osDocument.get(), &OSDocument::loadExampleModelClicked, this, &OpenStudioApp::loadExampleModel);
connect(m_osDocument.get(), &OSDocument::loadShoeboxModelClicked, this, &OpenStudioApp::loadShoeboxModel);
connect(m_osDocument.get(), &OSDocument::newClicked, this, &OpenStudioApp::newModel);
connect(m_osDocument.get(), &OSDocument::helpClicked, this, &OpenStudioApp::showHelp);
connect(m_osDocument.get(), &OSDocument::checkForUpdateClicked, this, &OpenStudioApp::checkForUpdate);
Expand All @@ -1267,6 +1268,7 @@ void OpenStudioApp::disconnectOSDocumentSignals() {
disconnect(m_osDocument.get(), &OSDocument::configureExternalToolsClicked, this, &OpenStudioApp::configureExternalTools);
disconnect(m_osDocument.get(), &OSDocument::loadLibraryClicked, this, &OpenStudioApp::loadLibrary);
disconnect(m_osDocument.get(), &OSDocument::loadExampleModelClicked, this, &OpenStudioApp::loadExampleModel);
disconnect(m_osDocument.get(), &OSDocument::loadShoeboxModelClicked, this, &OpenStudioApp::loadShoeboxModel);
disconnect(m_osDocument.get(), &OSDocument::newClicked, this, &OpenStudioApp::newModel);
disconnect(m_osDocument.get(), &OSDocument::helpClicked, this, &OpenStudioApp::showHelp);
disconnect(m_osDocument.get(), &OSDocument::checkForUpdateClicked, this, &OpenStudioApp::checkForUpdate);
Expand All @@ -1286,19 +1288,18 @@ void OpenStudioApp::measureManagerProcessFinished() {
QByteArray stdErr = m_measureManagerProcess->readAllStandardError();
QByteArray stdOut = m_measureManagerProcess->readAllStandardOutput();

QString text = tr("Measure Manager has crashed, attempting to restart. Do you want to reset Measure Manager settings?");
QString text = tr("Measure Manager has crashed. Do you want to retry?");
QString detailedText;
detailedText += stdErr;
detailedText += stdOut;

QMessageBox messageBox(QMessageBox::Warning, tr("Measure Manager Crashed"), text, QMessageBox::RestoreDefaults | QMessageBox::Close, mainWidget(),
QMessageBox messageBox(QMessageBox::Critical, tr("Measure Manager Crashed"), text, QMessageBox::Retry | QMessageBox::Close, mainWidget(),
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
messageBox.setDetailedText(detailedText);

if (messageBox.exec() == QMessageBox::RestoreDefaults) {
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
settings.setValue("useClassicCLI", true);
m_useClassicCLI = true;
if (messageBox.exec() == QMessageBox::Close) {
// user can cancel out of quit, turns into retry
quit();
}

startMeasureManagerProcess();
Expand Down Expand Up @@ -1351,9 +1352,7 @@ void OpenStudioApp::startMeasureManagerProcess() {
const QString program = toQString(openstudioCLIPath());
QStringList arguments;

if (m_useClassicCLI) {
arguments << "classic";
}
// MeasureManager does not work in classic CLI https://github.com/NREL/OpenStudio/issues/5212
arguments << "measure";
arguments << "-s";
arguments << portString;
Expand Down Expand Up @@ -1561,6 +1560,42 @@ void OpenStudioApp::loadExampleModel() {
OpenStudioApp::setQuitOnLastWindowClosed(wasQuitOnLastWindowClosed);
}

void OpenStudioApp::loadShoeboxModel() {

bool wasQuitOnLastWindowClosed = OpenStudioApp::quitOnLastWindowClosed();
OpenStudioApp::setQuitOnLastWindowClosed(false);

if (m_osDocument) {
if (!closeDocument()) {
OpenStudioApp::setQuitOnLastWindowClosed(wasQuitOnLastWindowClosed);
return;
}
processEvents();
}

osversion::VersionTranslator versionTranslator;
versionTranslator.setAllowNewerVersions(false);

auto filePath = resourcesPath() / toPath("ShoeboxModel/ShoeboxExample.osm");
boost::optional<openstudio::model::Model> model = versionTranslator.loadModel(filePath);
if (!model && isOpenStudioApplicationRunningFromBuildDirectory()) {
filePath = getOpenStudioCoalitionMeasuresSourceDirectory() / toPath("models/ShoeboxExample.osm");
model = versionTranslator.loadModel(filePath);
}

if (model) {
m_osDocument = std::make_shared<OSDocument>(componentLibrary(), resourcesPath(), model, toQString(filePath), false, startTabIndex());
m_osDocument->setSavePath("");
connectOSDocumentSignals();

QTimer::singleShot(0, m_osDocument.get(), &OSDocument::markAsModified);
}

waitDialog()->hide();

OpenStudioApp::setQuitOnLastWindowClosed(wasQuitOnLastWindowClosed);
}

void OpenStudioApp::changeDefaultLibraries() {
auto defaultPaths = defaultLibraryPaths();
auto paths = libraryPaths();
Expand Down Expand Up @@ -1590,18 +1625,6 @@ void OpenStudioApp::removeLibraryFromsSettings(const openstudio::path& path) {
writeLibraryPaths(paths);
}

void OpenStudioApp::showFailedMeasureManagerDialog() {

QString text = tr("The OpenStudio Application must close. Do you want to reset Measure Manager settings?\n\n");
QMessageBox::StandardButton reply = QMessageBox::critical(mainWidget(), QString("Failed to connect to Measure Manager"), text,
QMessageBox::RestoreDefaults | QMessageBox::Close, QMessageBox::RestoreDefaults);
if (reply == QMessageBox::RestoreDefaults) {
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
settings.setValue("useClassicCLI", true);
settings.sync();
}
}

void OpenStudioApp::showFailedLibraryDialog(const std::vector<std::string>& failedPaths) {
if (!failedPaths.empty()) {
QString text = tr("Failed to load the following libraries...\n\n");
Expand Down
6 changes: 3 additions & 3 deletions src/openstudio_app/OpenStudioApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ class OpenStudioApp : public OSAppBase
// Loads the result of openstudio::model::exampleModel()
void loadExampleModel();

// Creates a skeleton measure based model
void loadShoeboxModel();

// Checks what happened in the LibraryDialog preference panes, and calls writeLibraryPaths to set the user settings
void changeDefaultLibraries();

Expand Down Expand Up @@ -225,8 +228,6 @@ class OpenStudioApp : public OSAppBase
GBXML
};

void showFailedMeasureManagerDialog();

void showFailedLibraryDialog(const std::vector<std::string>& failedPaths);

void import(fileType type);
Expand Down Expand Up @@ -275,7 +276,6 @@ class OpenStudioApp : public OSAppBase
QTranslator m_qtTranslator;
QTranslator m_qtBaseTranslator;
QString m_currLang;
bool m_useClassicCLI;

// Try to find DView (or DView.exe) inside the PATH env variable. Will return an *empty* path if couldn't infer it
openstudio::path inferredDViewPath() const;
Expand Down
13 changes: 0 additions & 13 deletions src/openstudio_app/Resources/openstudio_results/LICENSE.md

This file was deleted.

Loading

0 comments on commit 55f5cc3

Please sign in to comment.