From 8fc2a82996813426fc19f197bf3525248c79db1c Mon Sep 17 00:00:00 2001 From: Dan Macumber Date: Tue, 26 Mar 2024 21:57:53 -0600 Subject: [PATCH 1/7] Properly remove components and measures of the old version, add missing pngs to qrc, don't remove all old measures after updating measures --- src/openstudio_lib/OSDocument.cpp | 13 ++++++++++++ src/openstudio_lib/OSDocument.hpp | 1 + src/openstudio_lib/openstudio.qrc | 8 ++++++++ .../BuildingComponentDialogCentralWidget.cpp | 20 +++++++++++-------- src/shared_gui_components/MeasureManager.cpp | 3 --- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/openstudio_lib/OSDocument.cpp b/src/openstudio_lib/OSDocument.cpp index b58919680..c832b1965 100644 --- a/src/openstudio_lib/OSDocument.cpp +++ b/src/openstudio_lib/OSDocument.cpp @@ -1406,6 +1406,19 @@ boost::optional OSDocument::getLocalMeasure(const std::string& uid, return result; } +std::vector OSDocument::getLocalComponents() const { + std::vector result; + if (m_haveLocalBCL) { + try { + result = LocalBCL::instance().components(); + } catch (const std::exception& e) { + LOG(Error, "Cannot access local BCL: " << e.what()); + m_haveLocalBCL = false; + } + } + return result; +} + std::vector OSDocument::getLocalMeasures() const { std::vector result; if (m_haveLocalBCL) { diff --git a/src/openstudio_lib/OSDocument.hpp b/src/openstudio_lib/OSDocument.hpp index 2349bf172..c86413d7a 100644 --- a/src/openstudio_lib/OSDocument.hpp +++ b/src/openstudio_lib/OSDocument.hpp @@ -130,6 +130,7 @@ class OPENSTUDIO_API OSDocument : public OSQObjectController boost::optional getLocalMeasure(const std::string& uid) const; boost::optional getLocalMeasure(const std::string& uid, const std::string& versionId) const; + std::vector getLocalComponents() const; std::vector getLocalMeasures() const; std::vector componentAttributeSearch(const std::vector>& pairs) const; diff --git a/src/openstudio_lib/openstudio.qrc b/src/openstudio_lib/openstudio.qrc index 6d10bf19b..b5e52e5cf 100644 --- a/src/openstudio_lib/openstudio.qrc +++ b/src/openstudio_lib/openstudio.qrc @@ -1173,6 +1173,8 @@ ../shared_gui_components/images/checked_checkbox_green@2x.png ../shared_gui_components/images/checked_checkbox_locked.png ../shared_gui_components/images/checked_checkbox_locked@2x.png + ../shared_gui_components/images/checked_checkbox_update_available.png + ../shared_gui_components/images/checked_checkbox_update_available@2x.png ../shared_gui_components/images/delete_softer.png ../shared_gui_components/images/delete_softer@2x.png ../shared_gui_components/images/delete_softer_over.png @@ -1231,6 +1233,10 @@ ../shared_gui_components/images/openstudio_measure_icon_Ruby@2x.png ../shared_gui_components/images/partially_checked_checkbox.png ../shared_gui_components/images/partially_checked_checkbox@2x.png + ../shared_gui_components/images/partially_checked_checkbox_locked.png + ../shared_gui_components/images/partially_checked_checkbox_locked@2x.png + ../shared_gui_components/images/partially_checked_checkbox_update_available.png + ../shared_gui_components/images/partially_checked_checkbox_update_available@2x.png ../shared_gui_components/images/pause_over.png ../shared_gui_components/images/pause_over@2x.png ../shared_gui_components/images/pause_press.png @@ -1281,6 +1287,8 @@ ../shared_gui_components/images/unchecked_checkbox_green@2x.png ../shared_gui_components/images/unchecked_checkbox_locked.png ../shared_gui_components/images/unchecked_checkbox_locked@2x.png + ../shared_gui_components/images/unchecked_checkbox_update_available.png + ../shared_gui_components/images/unchecked_checkbox_update_available@2x.png ../shared_gui_components/images/check_for_updates.png ../shared_gui_components/images/check_for_updates@2x.png diff --git a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp index cc728e280..287bf9065 100644 --- a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp +++ b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp @@ -287,10 +287,12 @@ void BuildingComponentDialogCentralWidget::comboBoxIndexChanged(const QString& t void BuildingComponentDialogCentralWidget::componentDownloadComplete(const std::string& uid, const boost::optional& component) { if (component) { // good - // remove old component - boost::optional oldComponent = OSAppBase::instance()->currentDocument()->getLocalComponent(component->uid()); - if (oldComponent && oldComponent->versionId() != component->versionId()) { - LocalBCL::instance().removeComponent(*oldComponent); + + // remove old components + for (auto& oldComponent : OSAppBase::instance()->currentDocument()->getLocalComponents()) { + if ((oldComponent.uid() == component->uid()) && (oldComponent.versionId() != component->versionId())) { + LocalBCL::instance().removeComponent(oldComponent); + } } } else { // error downloading component @@ -306,11 +308,13 @@ void BuildingComponentDialogCentralWidget::measureDownloadComplete(const std::st if (measure) { // good - // remove old measure - boost::optional oldMeasure = OSAppBase::instance()->currentDocument()->getLocalMeasure(measure->uid()); - if (oldMeasure && oldMeasure->versionId() != measure->versionId()) { - LocalBCL::instance().removeMeasure(*oldMeasure); + // remove old measures + for (auto& oldMeasure : OSAppBase::instance()->currentDocument()->getLocalMeasures()) { + if ((oldMeasure.uid() == measure->uid()) && (oldMeasure.versionId() != measure->versionId())) { + LocalBCL::instance().removeMeasure(oldMeasure); + } } + } else { // error downloading measure downloadFailed(uid); diff --git a/src/shared_gui_components/MeasureManager.cpp b/src/shared_gui_components/MeasureManager.cpp index 26844776f..1124e283d 100644 --- a/src/shared_gui_components/MeasureManager.cpp +++ b/src/shared_gui_components/MeasureManager.cpp @@ -981,9 +981,6 @@ void MeasureManager::checkForRemoteBCLUpdates() { int result = msg.exec(); if (result == QMessageBox::Yes) { remoteBCL.updateMeasures(); - for (auto& oldMeasure : oldMeasures) { - LocalBCL::instance().removeMeasure(oldMeasure); - } updateMeasuresLists(false); } } From 13dad4f6f4ad8069161d2668aa1a37327374f39d Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Wed, 27 Mar 2024 11:55:10 +0100 Subject: [PATCH 2/7] Remove unnecessary overload. --- src/openstudio_lib/OSDocument.cpp | 26 -------------------------- src/openstudio_lib/OSDocument.hpp | 6 ++---- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/openstudio_lib/OSDocument.cpp b/src/openstudio_lib/OSDocument.cpp index c832b1965..37493ac56 100644 --- a/src/openstudio_lib/OSDocument.cpp +++ b/src/openstudio_lib/OSDocument.cpp @@ -1354,19 +1354,6 @@ void OSDocument::addStandardMeasures() { enable(); } -boost::optional OSDocument::getLocalComponent(const std::string& uid) const { - boost::optional result; - if (m_haveLocalBCL) { - try { - result = LocalBCL::instance().getComponent(uid); - } catch (const std::exception& e) { - LOG(Error, "Cannot access local BCL: " << e.what()); - m_haveLocalBCL = false; - } - } - return result; -} - boost::optional OSDocument::getLocalComponent(const std::string& uid, const std::string& versionId) const { boost::optional result; if (m_haveLocalBCL) { @@ -1380,19 +1367,6 @@ boost::optional OSDocument::getLocalComponent(const std::string& u return result; } -boost::optional OSDocument::getLocalMeasure(const std::string& uid) const { - boost::optional result; - if (m_haveLocalBCL) { - try { - result = LocalBCL::instance().getMeasure(uid); - } catch (const std::exception& e) { - LOG(Error, "Cannot access local BCL: " << e.what()); - m_haveLocalBCL = false; - } - } - return result; -} - boost::optional OSDocument::getLocalMeasure(const std::string& uid, const std::string& versionId) const { boost::optional result; if (m_haveLocalBCL) { diff --git a/src/openstudio_lib/OSDocument.hpp b/src/openstudio_lib/OSDocument.hpp index c86413d7a..9b3e75bbe 100644 --- a/src/openstudio_lib/OSDocument.hpp +++ b/src/openstudio_lib/OSDocument.hpp @@ -124,11 +124,9 @@ class OPENSTUDIO_API OSDocument : public OSQObjectController // returns false if the LocalBCL cannot be accessed bool haveLocalBCL() const; - boost::optional getLocalComponent(const std::string& uid) const; - boost::optional getLocalComponent(const std::string& uid, const std::string& versionId) const; + boost::optional getLocalComponent(const std::string& uid, const std::string& versionId = "") const; - boost::optional getLocalMeasure(const std::string& uid) const; - boost::optional getLocalMeasure(const std::string& uid, const std::string& versionId) const; + boost::optional getLocalMeasure(const std::string& uid, const std::string& versionId = "") const; std::vector getLocalComponents() const; std::vector getLocalMeasures() const; From 8538308158cf275b72953e9bc669aca3abe8b7fb Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Wed, 27 Mar 2024 11:56:49 +0100 Subject: [PATCH 3/7] Move LocalBCL stuff into OSDocument where we check if it's available. --- src/openstudio_lib/OSDocument.cpp | 49 +++++++++++++++++++ src/openstudio_lib/OSDocument.hpp | 5 ++ .../BuildingComponentDialogCentralWidget.cpp | 15 +----- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/src/openstudio_lib/OSDocument.cpp b/src/openstudio_lib/OSDocument.cpp index 37493ac56..1e62aa786 100644 --- a/src/openstudio_lib/OSDocument.cpp +++ b/src/openstudio_lib/OSDocument.cpp @@ -128,6 +128,7 @@ #include #include // Workaround for #659 +#include #include #if (defined(_WIN32) || defined(_WIN64)) @@ -1406,6 +1407,54 @@ std::vector OSDocument::getLocalMeasures() const { return result; } +size_t OSDocument::removeOutdatedLocalComponents(const std::string& uid, const std::string& currentVersionId) const { + // TODO: when https://github.com/NREL/OpenStudio/pull/5127 is merged, we can just call it + // size_t result = 0; + // if (m_haveLocalBCL) { + // try { + // result = LocalBCL::instance().removeOutdatedLocalComponents(uid, currentVersionId); + // } catch (const std::exception& e) { + // LOG(Error, "Cannot access local BCL: " << e.what()); + // m_haveLocalBCL = false; + // } + // } + // return result; + + auto components = getLocalComponents(); + if (components.empty()) { + return {}; + } + + // Not empty, we do have a localbcl + components.erase(std::remove_if(components.begin(), components.end(), + [&uid, ¤tVersionId](const auto& component) { + return (component.uid() != uid) || (component.versionId() == currentVersionId); + }), + components.end()); + for (auto& component : components) { + LocalBCL::instance().removeComponent(component); + } + return components.size(); +} + +size_t OSDocument::removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId) const { + // TODO: when https://github.com/NREL/OpenStudio/pull/5127 is merged, we can just call it + auto measures = getLocalMeasures(); + if (measures.empty()) { + return {}; + } + + // Not empty, we do have a localbcl + measures.erase( + std::remove_if(measures.begin(), measures.end(), + [&uid, ¤tVersionId](const auto& measure) { return (measure.uid() != uid) || (measure.versionId() == currentVersionId); }), + measures.end()); + for (auto& measure : measures) { + LocalBCL::instance().removeMeasure(measure); + } + return measures.size(); +} + std::vector OSDocument::componentAttributeSearch(const std::vector>& pairs) const { std::vector result; if (m_haveLocalBCL) { diff --git a/src/openstudio_lib/OSDocument.hpp b/src/openstudio_lib/OSDocument.hpp index 9b3e75bbe..ef402c189 100644 --- a/src/openstudio_lib/OSDocument.hpp +++ b/src/openstudio_lib/OSDocument.hpp @@ -131,6 +131,11 @@ class OPENSTUDIO_API OSDocument : public OSQObjectController std::vector getLocalComponents() const; std::vector getLocalMeasures() const; + // Removes all components with uid but NOT currentVersionId + size_t removeOutdatedLocalComponents(const std::string& uid, const std::string& currentVersionId) const; + // Removes all measures with uid but NOT currentVersionId + size_t removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId) const; + std::vector componentAttributeSearch(const std::vector>& pairs) const; boost::optional standardReportMeasure(); diff --git a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp index 287bf9065..1001e3413 100644 --- a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp +++ b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp @@ -288,12 +288,7 @@ void BuildingComponentDialogCentralWidget::componentDownloadComplete(const std:: if (component) { // good - // remove old components - for (auto& oldComponent : OSAppBase::instance()->currentDocument()->getLocalComponents()) { - if ((oldComponent.uid() == component->uid()) && (oldComponent.versionId() != component->versionId())) { - LocalBCL::instance().removeComponent(oldComponent); - } - } + OSAppBase::instance()->currentDocument()->removeOutdatedLocalComponents(component->uid(), component->versionId()); } else { // error downloading component downloadFailed(uid); @@ -308,13 +303,7 @@ void BuildingComponentDialogCentralWidget::measureDownloadComplete(const std::st if (measure) { // good - // remove old measures - for (auto& oldMeasure : OSAppBase::instance()->currentDocument()->getLocalMeasures()) { - if ((oldMeasure.uid() == measure->uid()) && (oldMeasure.versionId() != measure->versionId())) { - LocalBCL::instance().removeMeasure(oldMeasure); - } - } - + OSAppBase::instance()->currentDocument()->removeOutdatedLocalMeasures(measure->uid(), measure->versionId()); } else { // error downloading measure downloadFailed(uid); From 475f75e9229f73b7e2d33ce5628d2d17d07db11b Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Wed, 27 Mar 2024 12:37:21 +0100 Subject: [PATCH 4/7] remove other call to removeMeasure, RemoteBCL should take care of it --- src/shared_gui_components/MeasureManager.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/shared_gui_components/MeasureManager.cpp b/src/shared_gui_components/MeasureManager.cpp index 1124e283d..37d9b3c96 100644 --- a/src/shared_gui_components/MeasureManager.cpp +++ b/src/shared_gui_components/MeasureManager.cpp @@ -964,13 +964,11 @@ void MeasureManager::checkForRemoteBCLUpdates() { + tr("Would you like update them?")); QString detailedText; - std::vector oldMeasures; for (const BCLSearchResult& update : updates) { detailedText += toQString("* name: " + update.name() + "\n"); detailedText += toQString(" - uid: " + update.uid() + "\n"); auto current = m_bclMeasures.find(toUUID(update.uid())); if (current != m_bclMeasures.end()) { - oldMeasures.push_back(current->second); detailedText += toQString(" - old versionId: " + current->second.versionId() + "\n"); } detailedText += toQString(" - new versionId: " + update.versionId() + "\n\n"); @@ -995,22 +993,17 @@ void MeasureManager::downloadBCLMeasures() { std::vector updates = remoteBCL.measuresWithUpdates(); QString detailedText; - std::vector oldMeasures; for (const BCLSearchResult& update : updates) { detailedText += toQString("* name: " + update.name() + "\n"); detailedText += toQString(" - uid: " + update.uid() + "\n"); auto current = m_bclMeasures.find(toUUID(update.uid())); if (current != m_bclMeasures.end()) { - oldMeasures.push_back(current->second); detailedText += toQString(" - old versionId: " + current->second.versionId() + "\n"); } detailedText += toQString(" - new versionId: " + update.versionId() + "\n\n"); } remoteBCL.updateMeasures(); - for (auto& oldMeasure : oldMeasures) { - LocalBCL::instance().removeMeasure(oldMeasure); - } updateMeasuresLists(false); QMessageBox msg(m_app->mainWidget()); From 9efc747ce32ed94f0e5205cc5d422995a2801f83 Mon Sep 17 00:00:00 2001 From: Dan Macumber Date: Wed, 27 Mar 2024 21:21:21 -0600 Subject: [PATCH 5/7] Update --- src/openstudio_lib/OSDocument.cpp | 31 +++++++++++++++++-- src/openstudio_lib/OSDocument.hpp | 4 +-- .../BuildingComponentDialogCentralWidget.cpp | 21 +++---------- src/shared_gui_components/MeasureManager.cpp | 26 ++++++++++++---- 4 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/openstudio_lib/OSDocument.cpp b/src/openstudio_lib/OSDocument.cpp index c832b1965..74145908e 100644 --- a/src/openstudio_lib/OSDocument.cpp +++ b/src/openstudio_lib/OSDocument.cpp @@ -1380,6 +1380,25 @@ boost::optional OSDocument::getLocalComponent(const std::string& u return result; } +size_t OSDocument::removeOutdatedLocalComponents(const std::string& uid, const std::string& currentVersionId) { + size_t result = 0; + if (m_haveLocalBCL) { + try { + for (auto& oldComponent : LocalBCL::instance().components()) { + if ((oldComponent.uid() == uid) && (oldComponent.versionId() != currentVersionId)) { + if (LocalBCL::instance().removeComponent(oldComponent)) { + ++result; + } + } + } + } catch (const std::exception& e) { + LOG(Error, "Cannot access local BCL: " << e.what()); + m_haveLocalBCL = false; + } + } + return result; +} + boost::optional OSDocument::getLocalMeasure(const std::string& uid) const { boost::optional result; if (m_haveLocalBCL) { @@ -1406,11 +1425,17 @@ boost::optional OSDocument::getLocalMeasure(const std::string& uid, return result; } -std::vector OSDocument::getLocalComponents() const { - std::vector result; +size_t OSDocument::removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId) { + size_t result = 0; if (m_haveLocalBCL) { try { - result = LocalBCL::instance().components(); + for (auto& oldMeasure : LocalBCL::instance().measures()) { + if ((oldMeasure.uid() == uid) && (oldMeasure.versionId() != currentVersionId)) { + if (LocalBCL::instance().removeMeasure(oldMeasure)) { + ++result; + } + } + } } catch (const std::exception& e) { LOG(Error, "Cannot access local BCL: " << e.what()); m_haveLocalBCL = false; diff --git a/src/openstudio_lib/OSDocument.hpp b/src/openstudio_lib/OSDocument.hpp index c86413d7a..8699caa98 100644 --- a/src/openstudio_lib/OSDocument.hpp +++ b/src/openstudio_lib/OSDocument.hpp @@ -126,11 +126,11 @@ class OPENSTUDIO_API OSDocument : public OSQObjectController boost::optional getLocalComponent(const std::string& uid) const; boost::optional getLocalComponent(const std::string& uid, const std::string& versionId) const; + size_t removeOutdatedLocalComponents(const std::string& uid, const std::string& currentVersionId); boost::optional getLocalMeasure(const std::string& uid) const; boost::optional getLocalMeasure(const std::string& uid, const std::string& versionId) const; - - std::vector getLocalComponents() const; + size_t removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId); std::vector getLocalMeasures() const; std::vector componentAttributeSearch(const std::vector>& pairs) const; diff --git a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp index 287bf9065..d7c904d76 100644 --- a/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp +++ b/src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp @@ -286,14 +286,8 @@ void BuildingComponentDialogCentralWidget::comboBoxIndexChanged(const QString& t void BuildingComponentDialogCentralWidget::componentDownloadComplete(const std::string& uid, const boost::optional& component) { if (component) { - // good - - // remove old components - for (auto& oldComponent : OSAppBase::instance()->currentDocument()->getLocalComponents()) { - if ((oldComponent.uid() == component->uid()) && (oldComponent.versionId() != component->versionId())) { - LocalBCL::instance().removeComponent(oldComponent); - } - } + // remove outdated components + OSAppBase::instance()->currentDocument()->removeOutdatedLocalComponents(component->uid(), component->versionId()); } else { // error downloading component downloadFailed(uid); @@ -306,15 +300,8 @@ void BuildingComponentDialogCentralWidget::componentDownloadComplete(const std:: void BuildingComponentDialogCentralWidget::measureDownloadComplete(const std::string& uid, const boost::optional& measure) { if (measure) { - // good - - // remove old measures - for (auto& oldMeasure : OSAppBase::instance()->currentDocument()->getLocalMeasures()) { - if ((oldMeasure.uid() == measure->uid()) && (oldMeasure.versionId() != measure->versionId())) { - LocalBCL::instance().removeMeasure(oldMeasure); - } - } - + // remove outdated measures + OSAppBase::instance()->currentDocument()->removeOutdatedLocalMeasures(measure->uid(), measure->versionId()); } else { // error downloading measure downloadFailed(uid); diff --git a/src/shared_gui_components/MeasureManager.cpp b/src/shared_gui_components/MeasureManager.cpp index 1124e283d..aa2787402 100644 --- a/src/shared_gui_components/MeasureManager.cpp +++ b/src/shared_gui_components/MeasureManager.cpp @@ -56,6 +56,9 @@ #include #include +#include "../openstudio_lib/OSAppBase.hpp" +#include "../openstudio_lib/OSDocument.hpp" + #include #include @@ -964,13 +967,11 @@ void MeasureManager::checkForRemoteBCLUpdates() { + tr("Would you like update them?")); QString detailedText; - std::vector oldMeasures; for (const BCLSearchResult& update : updates) { detailedText += toQString("* name: " + update.name() + "\n"); detailedText += toQString(" - uid: " + update.uid() + "\n"); auto current = m_bclMeasures.find(toUUID(update.uid())); if (current != m_bclMeasures.end()) { - oldMeasures.push_back(current->second); detailedText += toQString(" - old versionId: " + current->second.versionId() + "\n"); } detailedText += toQString(" - new versionId: " + update.versionId() + "\n\n"); @@ -981,6 +982,15 @@ void MeasureManager::checkForRemoteBCLUpdates() { int result = msg.exec(); if (result == QMessageBox::Yes) { remoteBCL.updateMeasures(); + + // remoteBCL.updateMeasures should remove outdated measures, but won't work correctly until https://github.com/NREL/OpenStudio/pull/5129 + // if we have the new measure, delete outdated ones + for (const BCLSearchResult& update : updates) { + if (OSAppBase::instance()->currentDocument()->getLocalMeasure(update.uid(), update.versionId())) { + OSAppBase::instance()->currentDocument()->removeOutdatedLocalMeasures(update.uid(), update.versionId()); + } + } + updateMeasuresLists(false); } } @@ -995,22 +1005,26 @@ void MeasureManager::downloadBCLMeasures() { std::vector updates = remoteBCL.measuresWithUpdates(); QString detailedText; - std::vector oldMeasures; for (const BCLSearchResult& update : updates) { detailedText += toQString("* name: " + update.name() + "\n"); detailedText += toQString(" - uid: " + update.uid() + "\n"); auto current = m_bclMeasures.find(toUUID(update.uid())); if (current != m_bclMeasures.end()) { - oldMeasures.push_back(current->second); detailedText += toQString(" - old versionId: " + current->second.versionId() + "\n"); } detailedText += toQString(" - new versionId: " + update.versionId() + "\n\n"); } remoteBCL.updateMeasures(); - for (auto& oldMeasure : oldMeasures) { - LocalBCL::instance().removeMeasure(oldMeasure); + + // remoteBCL.updateMeasures should remove outdated measures, but won't work correctly until https://github.com/NREL/OpenStudio/pull/5129 + // if we have the new measure, delete outdated ones + for (const BCLSearchResult& update : updates) { + if (OSAppBase::instance()->currentDocument()->getLocalMeasure(update.uid(), update.versionId())) { + OSAppBase::instance()->currentDocument()->removeOutdatedLocalMeasures(update.uid(), update.versionId()); + } } + updateMeasuresLists(false); QMessageBox msg(m_app->mainWidget()); From dee268288e73c2c5722f7a4ac3879d0032d8d4e4 Mon Sep 17 00:00:00 2001 From: Dan Macumber Date: Wed, 27 Mar 2024 21:49:38 -0600 Subject: [PATCH 6/7] Update again --- src/openstudio_lib/OSDocument.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/openstudio_lib/OSDocument.cpp b/src/openstudio_lib/OSDocument.cpp index 8196f379c..dff7c16bb 100644 --- a/src/openstudio_lib/OSDocument.cpp +++ b/src/openstudio_lib/OSDocument.cpp @@ -1420,6 +1420,11 @@ size_t OSDocument::removeOutdatedLocalComponents(const std::string& uid, const s // } // return result; + auto components = getLocalComponents(); + if (components.empty()) { + return {}; + } + // Not empty, we do have a localbcl components.erase(std::remove_if(components.begin(), components.end(), [&uid, ¤tVersionId](const auto& component) { @@ -1434,6 +1439,17 @@ size_t OSDocument::removeOutdatedLocalComponents(const std::string& uid, const s size_t OSDocument::removeOutdatedLocalMeasures(const std::string& uid, const std::string& currentVersionId) const { // TODO: when https://github.com/NREL/OpenStudio/pull/5129 is merged, we can just call it + // size_t result = 0; + // if (m_haveLocalBCL) { + // try { + // result = LocalBCL::instance().removeOutdatedLocalMeasures(uid, currentVersionId); + // } catch (const std::exception& e) { + // LOG(Error, "Cannot access local BCL: " << e.what()); + // m_haveLocalBCL = false; + // } + // } + // return result; + auto measures = getLocalMeasures(); if (measures.empty()) { return {}; From 5b7bbc053327e38811b522fbac420c2b77c07241 Mon Sep 17 00:00:00 2001 From: Dan Macumber Date: Wed, 27 Mar 2024 21:59:24 -0600 Subject: [PATCH 7/7] Clang format --- src/shared_gui_components/MeasureManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared_gui_components/MeasureManager.cpp b/src/shared_gui_components/MeasureManager.cpp index aa2787402..8a95dbdac 100644 --- a/src/shared_gui_components/MeasureManager.cpp +++ b/src/shared_gui_components/MeasureManager.cpp @@ -990,7 +990,7 @@ void MeasureManager::checkForRemoteBCLUpdates() { OSAppBase::instance()->currentDocument()->removeOutdatedLocalMeasures(update.uid(), update.versionId()); } } - + updateMeasuresLists(false); } }