Skip to content
Merged
86 changes: 61 additions & 25 deletions src/shared_gui_components/BuildingComponentDialogCentralWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include <cstddef>
#include <openstudio/measure/OSArgument.hpp>

#include <openstudio/utilities/bcl/BCL.hpp>
#include <openstudio/utilities/bcl/LocalBCL.hpp>
#include <openstudio/utilities/bcl/RemoteBCL.hpp>
Expand Down Expand Up @@ -169,53 +168,90 @@ void BuildingComponentDialogCentralWidget::setTid() {
requestComponents(m_filterType, m_tid, m_pageIdx, m_searchString);
}

std::vector<openstudio::BCLSearchResult> BuildingComponentDialogCentralWidget::fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString) {
m_allResponses.clear();

RemoteBCL remoteBCL;
remoteBCL.setTimeOutSeconds(m_timeoutSeconds);

std::vector<BCLSearchResult> responses;
int totalPages = 1;
int currentPage = 0;

// Collect all responses from all pages
do {
std::vector<BCLSearchResult> pageResponses;
if (filterType == "components") {
pageResponses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, currentPage);
} else if (filterType == "measures") {
pageResponses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, currentPage);
}
responses.insert(responses.end(), pageResponses.begin(), pageResponses.end());
totalPages = remoteBCL.numResultPages();
} while (++currentPage < totalPages);

if (!responses.empty()) {
std::sort(responses.begin(), responses.end(), [](const BCLSearchResult& a, const BCLSearchResult& b) {
return a.name() < b.name();
});
}
Comment on lines +193 to +197
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm following correctly, you just factored a bit of code into a function, and added this bit that sorts the results.


Side note: the if (!responses.empty()) is not technically needed and does not make it faster. https://quick-bench.com/q/5lPbGyQNKctVRq7IdoD_fUVTPt4

(Running it a bunch of times locally produces results where one is sometimes faster than the other, so they're the same).

-----------------------------------------------------------
Benchmark                 Time             CPU   Iterations
-----------------------------------------------------------
SortNoIf_Items         4732 ns         4730 ns       147972
SortWithIf_Items       5040 ns         5038 ns       138705


return responses;
}

// Note: don't call this directly if the "wait" screen is desired
void BuildingComponentDialogCentralWidget::setTid(const std::string& filterType, int tid, int pageIdx, const QString& title,
const QString& searchString) {

if (m_tid != tid || m_searchString != searchString) {
m_collapsibleComponentList->firstPage();
}
std::string newKey = std::to_string(tid) + filterType + searchString.toStdString();
std::string currentKey = std::to_string(m_tid) + m_filterType + m_searchString.toStdString();

m_searchString = searchString;
m_filterType = filterType;

m_tid = tid;

m_searchString = searchString;
if (newKey != currentKey) {
m_allResponses = fetchAndSortResponses(filterType, tid, searchString);
m_collapsibleComponentList->firstPage();
pageIdx = 0;
}

//std::vector<Component *> components = m_collapsibleComponentList->components();
// Clear existing components
std::vector<Component*> components = m_componentList->components(); // TODO replace with code above

for (auto& comp : components) {
delete comp;
}

RemoteBCL remoteBCL;
remoteBCL.setTimeOutSeconds(m_timeoutSeconds);
std::vector<BCLSearchResult> responses;
if (filterType == "components") {
responses = remoteBCL.searchComponentLibrary(searchString.toStdString(), tid, pageIdx);
} else if (filterType == "measures") {
responses = remoteBCL.searchMeasureLibrary(searchString.toStdString(), tid, pageIdx);
}

for (const auto& response : responses) {
auto* component = new Component(response);

// TODO replace with a componentList owned by m_collapsibleComponentList
m_componentList->addComponent(component);
// Paginate responses
int itemsPerPage = 10; // Assuming 10 items per page

if (!m_allResponses.empty()) {
size_t startIdx = pageIdx * itemsPerPage;
size_t endIdx = std::min(startIdx + itemsPerPage, m_allResponses.size());
std::vector<BCLSearchResult> paginatedResponses(m_allResponses.begin() + startIdx, m_allResponses.begin() + endIdx);

for (const auto& response : paginatedResponses) {
auto* component = new Component(response);

// TODO replace with a componentList owned by m_collapsibleComponentList
m_componentList->addComponent(component);
}
}

// the parent taxonomy
m_collapsibleComponentList->setText(title);

// the total number of results
int lastTotalResults = remoteBCL.lastTotalResults();
int lastTotalResults = m_allResponses.size();
m_collapsibleComponentList->setNumResults(lastTotalResults);

// the number of pages of results
int numResultPages = remoteBCL.numResultPages();
m_collapsibleComponentList->setNumPages(numResultPages);
if (lastTotalResults == 0) {
m_collapsibleComponentList->setNumPages(0);
} else {
int numResultPages = (lastTotalResults % itemsPerPage == 0) ? (lastTotalResults / itemsPerPage) : (lastTotalResults / itemsPerPage) + 1;
m_collapsibleComponentList->setNumPages(numResultPages);
}

// make sure the header is expanded
if (m_collapsibleComponentList->checkedCollapsibleComponent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <openstudio/nano/nano_signal_slot.hpp> // Signal-Slot replacement
#include <openstudio/utilities/bcl/BCLComponent.hpp>
#include <openstudio/utilities/bcl/BCLMeasure.hpp>
#include <openstudio/utilities/bcl/BCL.hpp>

#include "../shared_gui_components/ProgressBarWithError.hpp"

Expand Down Expand Up @@ -54,6 +55,9 @@ class BuildingComponentDialogCentralWidget
void setTid();
void componentDownloadComplete(const std::string& uid, const boost::optional<BCLComponent>& component);
void measureDownloadComplete(const std::string& uid, const boost::optional<BCLMeasure>& measure);
std::vector<openstudio::BCLSearchResult> m_allResponses;

std::vector<openstudio::BCLSearchResult> fetchAndSortResponses(const std::string& filterType, int tid, const QString& searchString);

int m_tid;
CollapsibleComponentList* m_collapsibleComponentList;
Expand Down
4 changes: 2 additions & 2 deletions src/shared_gui_components/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Component::Component(const BCLMeasure& bclMeasure, bool showAbridgedView, bool s
setCheckBoxEnabled(false);
m_updateAvailable = false;
if (m_msg) {
m_msg->setText("This measure requires a newer version of OpenStudio");
m_msg->setText("This measure is not compatible with the current version of OpenStudio");
m_msg->setVisible(true);
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ Component::Component(const BCLSearchResult& bclSearchResult, bool showAbridgedVi
setCheckBoxEnabled(false);
m_updateAvailable = false;
if (m_msg) {
m_msg->setText("This measure requires a newer version of OpenStudio");
m_msg->setText("This measure is not compatible with the current version of OpenStudio");
m_msg->setVisible(true);
}
}
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,12 @@ If you would like to see the OpenStudioApplication translated in your language o
<context>
<name>openstudio::MainWindow</name>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_ca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,12 @@ Si voleu que OpeStudioApplication estigui a la vostra llengua, esperem la vostra
<translation type="obsolete">S&apos;ha de reiniciar</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,12 @@ Wenn Sie möchten, dass die OpenStudio-Applikation in die Sprache Ihrer Wahl üb
<translation type="obsolete">Neustart erforderlich</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,12 @@ If you would like to see the OpenStudioApplication translated in your language o
<translation type="obsolete">Απαιτείται επανεκκίνηση</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ Si le gustaría ver la AplicaciónOpenStudio traducido a algun otro lenguaje, le
<translation type="obsolete">Se requiere reiniciar</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,12 @@ If you would like to see the OpenStudioApplication translated in your language o
<translation type="obsolete">راه اندازی مجدد لازم است</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,12 +817,12 @@ Si vous voulez voir l&apos;Application OpenStudio traduite dans la langue de vot
<translation type="obsolete">Redémarrage requis</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_he.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,12 @@ If you would like to see the OpenStudioApplication translated in your language o
<translation type="obsolete">אתחול נדרש</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_hi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ If you would like to see the OpenStudioApplication translated in your language o
<translation type="obsolete">पुनरारंभ करना आवश्यक है</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,12 +819,12 @@ Se vuoi vedere OpenStudioApplication tradotto nel tuo linguaggio preferito, appr
<translation type="obsolete">Riavvio Richiesto</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ If you would like to see the OpenStudioApplication translated in your language o
<translation type="obsolete">再起動してください</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ Jeśli chcesz zobaczyć aplikację OpenStudio przetłumaczoną na wybrany przez
<translation type="obsolete">Wymagane jest ponowne uruchomienie</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
4 changes: 2 additions & 2 deletions translations/OpenStudioApp_vi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,12 @@ Nếu bạn muốn thấy OpenStudioApplication được dịch sang ngôn ngữ
<translation type="obsolete">Cần khởi động lại</translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="394"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="406"/>
<source>Allow Analytics</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="395"/>
<location filename="../src/openstudio_lib/MainWindow.cpp" line="407"/>
<source>Allow OpenStudio Coalition to collect anonymous usage statistics to help improve the OpenStudio Application? See the &lt;a href=&quot;https://openstudiocoalition.org/about/privacy_policy/&quot;&gt;privacy policy&lt;/a&gt; for more information.</source>
<translation type="unfinished"></translation>
</message>
Expand Down
Loading
Loading