Skip to content
Merged
142 changes: 129 additions & 13 deletions src/openstudio_lib/LocationTabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#include "OSItemSelectorButtons.hpp"
#include "SchedulesTabController.hpp"

#include "../shared_gui_components/OSComboBox.hpp"
#include "../shared_gui_components/OSGridView.hpp"
#include "../shared_gui_components/OSQuantityEdit.hpp"
#include "../shared_gui_components/OSSwitch.hpp"

#include "../openstudio_app/OpenStudioApp.hpp"

Expand Down Expand Up @@ -70,6 +73,7 @@
#include <QCoreApplication>
#include <QObject>
#include <QPushButton>
#include <span>

static constexpr auto NAME("Name: ");
static constexpr auto LATITUDE("Latitude: ");
Expand Down Expand Up @@ -174,6 +178,11 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
weatherFileGridLayout->setContentsMargins(7, 3, 7, 7);
weatherFileGridLayout->setSpacing(7);

// ***** Measure Tags GridLayout *****
auto* siteInfoGridLayout = new QGridLayout();
siteInfoGridLayout->setContentsMargins(7, 7, 7, 7);
siteInfoGridLayout->setSpacing(7);

// ***** Measure Tags GridLayout *****
auto* measureTagsGridLayout = new QGridLayout();
measureTagsGridLayout->setContentsMargins(7, 7, 7, 7);
Expand Down Expand Up @@ -236,16 +245,13 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&

weatherFileGridLayout->addLayout(hLayout, i++, 0);

m_latitudeLbl = new QLabel(tr("Latitude: "));
m_latitudeLbl = new QLabel(tr(LATITUDE));
weatherFileGridLayout->addWidget(m_latitudeLbl, i++, 0);

m_longitudeLbl = new QLabel(tr("Longitude: "));
m_longitudeLbl = new QLabel(tr(LONGITUDE));
weatherFileGridLayout->addWidget(m_longitudeLbl, i++, 0);

m_elevationLbl = new QLabel(tr("Elevation: "));
weatherFileGridLayout->addWidget(m_elevationLbl, i++, 0);

m_timeZoneLbl = new QLabel(tr("Time Zone: "));
m_timeZoneLbl = new QLabel(tr(TIME_ZONE));
weatherFileGridLayout->addWidget(m_timeZoneLbl, i++, 0);

// ***** Weather File Download Location *****
Expand All @@ -258,6 +264,91 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
leftVLayout->addLayout(weatherFileGridLayout);
leftVLayout->addStretch();

// Site Information
{
label = new QLabel(tr("Site Information:"));
label->setObjectName("H2");
leftVLayout->addWidget(label);

i = 0;

{
label = new QLabel(tr("Keep Site Location Information"));
label->setToolTip(tr("If enabled, this will write the Site:Location object that will keep the Elevation change for example."));

m_keepSiteLocationInfo = new OSSwitch2();

m_keepSiteLocationInfo->bind(*m_site, BoolGetter([this] { return m_site->keepSiteLocationInformation(); }),
boost::optional<BoolSetter>([this](bool b) {
bool result = m_site->setKeepSiteLocationInformation(b);

if (result) {

// force the style to update
m_elevation->clearCachedText();

if (b) {
// set elevation if turning on
if (m_site->isElevationDefaulted()) {
m_site->setElevation(m_weatherFileElevation);
} else {
m_site->setElevation(m_site->elevation());
}
} else {
// reset elevation if turning off
if (std::abs(m_weatherFileElevation) > 0.01) {
m_site->setElevation(m_weatherFileElevation);
} else {
m_site->resetElevation();
}
}
}
return result;
}),
boost::optional<NoFailAction>([this] { m_site->resetKeepSiteLocationInformation(); }),
boost::optional<BasicQuery>([this] { return m_site->isKeepSiteLocationInformationDefaulted(); }));

siteInfoGridLayout->addWidget(label, i, 0);
siteInfoGridLayout->addWidget(m_keepSiteLocationInfo, i++, 1);
}
{
label = new QLabel(tr(ELEVATION));
label->setToolTip(tr("Elevation affects the wind speed at the site, and is defaulted to the Weather File's elevation"));

m_elevation = new OSQuantityEdit2("m", "m", "ft", m_isIP);
connect(this, &LocationView::toggleUnitsClicked, m_elevation, &OSQuantityEdit2::onUnitSystemChange);

// Bind is delayed until after update() is called, so that the weatherFileElevation is set correctly.

m_elevation->setFixedWidth(200);

siteInfoGridLayout->addWidget(label, i, 0);
siteInfoGridLayout->addWidget(m_elevation, i++, 1);
}
// Terrain
{
label = new QLabel(tr("Terrain"));
label->setToolTip(tr("Terrain affects the wind speed at the site."));

m_terrain = new OSComboBox2();
m_terrain->bind<std::string>(*m_site, static_cast<std::string (*)(const std::string&)>(&openstudio::toString), &model::Site::validTerrainValues,
std::bind(&model::Site::terrain, m_site.get_ptr()),
std::bind(&model::Site::setTerrain, m_site.get_ptr(), std::placeholders::_1),
boost::optional<NoFailAction>(std::bind(&model::Site::resetTerrain, m_site.get_ptr())),
boost::optional<BasicQuery>(std::bind(&model::Site::isTerrainDefaulted, m_site.get_ptr())));

m_terrain->setFixedWidth(200);

siteInfoGridLayout->addWidget(label, i, 0);
siteInfoGridLayout->addWidget(m_terrain, i++, 1);
}

// ***** Site Info GridLayout *****
siteInfoGridLayout->setColumnStretch(++i, 10);
leftVLayout->addLayout(siteInfoGridLayout);
leftVLayout->addStretch();
}

// ***** Climate Zones *****
label = new QLabel(tr("Measure Tags (Optional):"));
label->setObjectName("H2");
Expand Down Expand Up @@ -400,11 +491,37 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
connect(m_itemSelectorButtons, &OSItemSelectorButtons::purgeClicked, m_designDaysGridView, &DesignDayGridView::onPurgeClicked);

update();
{
m_elevation->bind(m_isIP, *m_site, DoubleGetter([this] { return m_site->elevation(); }), boost::optional<DoubleSetter>([this](double d) {
// turn keep site info on
m_site->setKeepSiteLocationInformation(true);
return m_site->setElevation(d);
}),
boost::optional<NoFailAction>([this] {
// turn keep site info off
m_site->setKeepSiteLocationInformation(false);

// force the style to update
m_elevation->clearCachedText();

if (std::abs(m_weatherFileElevation) > 0.01) {
m_site->setElevation(m_weatherFileElevation);
} else {
m_site->resetElevation();
}
}),
boost::none, // autosize
boost::none, // autocalculate
boost::optional<BasicQuery>([this] { //
return (m_site->isElevationDefaulted() || !m_site->keepSiteLocationInformation());
}));
}

onSelectItem();
}

LocationView::~LocationView() {
// m_terrain->unbind(); // NOTE: I don't think this is necessary
saveQSettings();
}

Expand Down Expand Up @@ -496,6 +613,7 @@ void LocationView::update() {

if (fileExists) {
m_weatherFileBtn->setText(tr("Change Weather File"));
m_weatherFileElevation = weatherFile->elevation();
setSiteInfo();
} else {
m_weatherFileBtn->setText(tr("Set Weather File"));
Expand Down Expand Up @@ -526,11 +644,6 @@ void LocationView::setSiteInfo() {
info += temp;
m_longitudeLbl->setText(info);

info = tr(ELEVATION);
temp.setNum(m_site->elevation());
info += temp;
m_elevationLbl->setText(info);

info = tr(TIME_ZONE);
temp.setNum(m_site->timeZone());
info += temp;
Expand All @@ -544,9 +657,9 @@ void LocationView::clearSiteInfo() {

m_longitudeLbl->setText(tr(LONGITUDE));

m_elevationLbl->setText(tr(ELEVATION));

m_timeZoneLbl->setText(tr(TIME_ZONE));

m_weatherFileElevation = 0.0;
}

// ***** SLOTS *****
Expand Down Expand Up @@ -637,7 +750,10 @@ void LocationView::onWeatherFileBtnClicked() {
m_site->setName(weatherFile->city());
m_site->setLatitude(weatherFile->latitude());
m_site->setLongitude(weatherFile->longitude());
m_weatherFileElevation = weatherFile->elevation();
m_site->setKeepSiteLocationInformation(false);
m_site->setElevation(weatherFile->elevation());
m_site->resetTerrain();
m_site->setTimeZone(weatherFile->timeZone());

m_lastEpwPathOpened = QFileInfo(fileName).absoluteFilePath();
Expand Down
23 changes: 16 additions & 7 deletions src/openstudio_lib/LocationTabView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ namespace openstudio {

class EpwFile;
class DesignDayGridView;
class OSComboBox2;
class OSItemSelectorButtons;
class OSQuantityEdit2;
class OSSwitch2;

namespace model {
class Model;
Expand Down Expand Up @@ -97,17 +100,23 @@ class LocationView : public QWidget
YearSettingsWidget* m_yearSettingsWidget = nullptr;
DesignDayGridView* m_designDaysGridView = nullptr;
OSItemSelectorButtons* m_itemSelectorButtons = nullptr;
QString m_modelTempDir = QString();
QString m_lastEpwPathOpened = QString();
QString m_lastDdyPathOpened = QString();
QComboBox* m_ashraeClimateZone = nullptr;
QComboBox* m_cecClimateZone = nullptr;
QString m_modelTempDir;
QString m_lastEpwPathOpened;
QString m_lastDdyPathOpened;

QPushButton* m_weatherFileBtn = nullptr;
QLineEdit* m_siteName = nullptr;
QLabel* m_latitudeLbl = nullptr;
QLabel* m_longitudeLbl = nullptr;
QLabel* m_elevationLbl = nullptr;
QLabel* m_timeZoneLbl = nullptr;
QPushButton* m_weatherFileBtn = nullptr;

OSComboBox2* m_terrain = nullptr;
OSSwitch2* m_keepSiteLocationInfo = nullptr;
OSQuantityEdit2* m_elevation = nullptr;
double m_weatherFileElevation = 0.0;
QComboBox* m_ashraeClimateZone = nullptr;
QComboBox* m_cecClimateZone = nullptr;

bool m_isIP;

signals:
Expand Down
23 changes: 13 additions & 10 deletions src/shared_gui_components/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,34 +430,37 @@ void Component::createAbridgedLayout() {
label = new QLabel(string);
leftLayout->addWidget(label);

QString labelString;
QString typeString = "Unknown";
if (m_componentType == "component") {
labelString = "Type: ";
} else if (m_componentType == "measure" || m_componentType == "MeasureType") {
labelString = "Measure Type: ";
}
for (const Attribute& attribute : m_attributes) {
string = attribute.name().c_str();
if (m_componentType == "component") {
if (string.toStdString() == OPENSTUDIO_TYPE) {
openstudio::AttributeValueType type = attribute.valueType();
if (type == AttributeValueType::String) {
string = attribute.valueAsString().c_str();
QString temp("Type: ");
temp += string;
label = new QLabel(temp);
leftLayout->addWidget(label);
typeString = attribute.valueAsString().c_str();
break;
}
}
} else if (m_componentType == "measure" || m_componentType == "MeasureType") {
if (string.toStdString() == "Measure Type") {
openstudio::AttributeValueType type = attribute.valueType();
if (type == AttributeValueType::String) {
string = attribute.valueAsString().c_str();
QString temp("Measure Type: ");
temp += string;
label = new QLabel(temp);
leftLayout->addWidget(label);
typeString = attribute.valueAsString().c_str();
}
}
}
}

labelString += typeString;
label = new QLabel(labelString);
leftLayout->addWidget(label);

m_msg = new QLabel(this);
if (m_error) {
m_msg->setStyleSheet("color:#F00;font-style:italic;");
Expand Down
9 changes: 9 additions & 0 deletions src/shared_gui_components/OSComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ void OSComboBox2::onModelObjectRemoved(const Handle& handle) {
unbind();
}

void OSComboBox2::onActivated(int index) {
if (m_choiceConcept) {
if (index == this->currentIndex() && m_choiceConcept->isDefaulted()) {
this->onCurrentIndexChanged(this->currentText());
}
}
}

void OSComboBox2::onCurrentIndexChanged(const QString& text) {
emit inFocus(m_focused, hasData());

Expand Down Expand Up @@ -347,6 +355,7 @@ void OSComboBox2::completeBind() {
m_modelObject->getImpl<openstudio::model::detail::ModelObject_Impl>()
->onRemoveFromWorkspace.connect<OSComboBox2, &OSComboBox2::onModelObjectRemoved>(this);

connect(this, static_cast<void (OSComboBox2::*)(int)>(&OSComboBox2::activated), this, &OSComboBox2::onActivated);
connect(this, static_cast<void (OSComboBox2::*)(const QString&)>(&OSComboBox2::currentTextChanged), this, &OSComboBox2::onCurrentIndexChanged);

if (isEditable()) {
Expand Down
2 changes: 2 additions & 0 deletions src/shared_gui_components/OSComboBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class OSComboBox2

void onModelObjectRemoved(const Handle& handle);

void onActivated(int index);

void onCurrentIndexChanged(const QString& text);

void onEditTextChanged(const QString& text);
Expand Down
4 changes: 4 additions & 0 deletions src/shared_gui_components/OSQuantityEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ void OSQuantityEdit2::setLocked(bool locked) {
m_lineEdit->setLocked(locked);
}

void OSQuantityEdit2::clearCachedText() {
m_text = "UNINITIALIZED";
}

QDoubleValidator* OSQuantityEdit2::doubleValidator() {
return m_doubleValidator;
}
Expand Down
2 changes: 2 additions & 0 deletions src/shared_gui_components/OSQuantityEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class OSQuantityEdit2

void setLocked(bool locked);

void clearCachedText();

QDoubleValidator* doubleValidator();

void bind(bool isIP, const model::ModelObject& modelObject, DoubleGetter get, boost::optional<DoubleSetter> set = boost::none,
Expand Down
Loading