Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support holidays in schedule GUI #60

Merged
merged 7 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openstudio_lib/IconLibrary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#define OPENSTUDIO_ICONLIBRARY_HPP

#include "OpenStudioAPI.hpp"
#include "../utilities/core/Logger.hpp"
#include <openstudio/src/utilities/core/Logger.hpp>

#include <QPixmap>
#include <map>
Expand Down
30 changes: 30 additions & 0 deletions src/openstudio_lib/SchedulesTabController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,34 @@ void SchedulesTabController::addWinterProfile(model::ScheduleRuleset & scheduleR
}
}

void SchedulesTabController::addHolidayProfile(model::ScheduleRuleset & scheduleRuleset, UUID scheduleDayHandle)
{
boost::optional<model::ScheduleDay> scheduleDay;
if (!scheduleDayHandle.isNull()){
boost::optional<model::ScheduleDay> scheduleDayToCopy = scheduleRuleset.model().getModelObject<model::ScheduleDay>(scheduleDayHandle);
if (scheduleDayToCopy){
scheduleDay = scheduleDayToCopy->clone().cast<model::ScheduleDay>();
}
}
if (!scheduleDay){
scheduleDay = model::ScheduleDay(scheduleRuleset.model());
boost::optional<model::ScheduleTypeLimits> limits = scheduleRuleset.scheduleTypeLimits();
if (limits) {
scheduleDay->setScheduleTypeLimits(*limits);
}
scheduleDay->addValue(Time(1, 0), defaultStartingValue(*scheduleDay));
}
OS_ASSERT(scheduleDay);

scheduleRuleset.setHolidaySchedule(*scheduleDay);

scheduleDay->remove();

if (qobject_cast<SchedulesView *>(m_currentView)) {
(qobject_cast<SchedulesView *>(m_currentView))->showHolidayScheduleDay(scheduleRuleset);
}
}

void SchedulesTabController::onDayScheduleSceneChanged( DayScheduleScene * scene, double lowerLimitValue, double upperLimitValue )
{
std::vector<CalendarSegmentItem *> segments = scene->segments();
Expand Down Expand Up @@ -467,6 +495,7 @@ void SchedulesTabController::setSubTab(int index)
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::addRuleClicked, this, &SchedulesTabController::addRule);
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::addSummerProfileClicked, this, &SchedulesTabController::addSummerProfile);
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::addWinterProfileClicked, this, &SchedulesTabController::addWinterProfile);
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::addHolidayProfileClicked, this, &SchedulesTabController::addHolidayProfile);
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::dayScheduleSceneChanged, this, &SchedulesTabController::onDayScheduleSceneChanged);
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::startDateTimeChanged, this, &SchedulesTabController::onStartDateTimeChanged);
disconnect(qobject_cast<SchedulesView *>(m_currentView), &SchedulesView::endDateTimeChanged, this, &SchedulesTabController::onEndDateTimeChanged);
Expand Down Expand Up @@ -504,6 +533,7 @@ void SchedulesTabController::setSubTab(int index)
connect(schedulesView, &SchedulesView::addRuleClicked, this, &SchedulesTabController::addRule);
connect(schedulesView, &SchedulesView::addSummerProfileClicked, this, &SchedulesTabController::addSummerProfile);
connect(schedulesView, &SchedulesView::addWinterProfileClicked, this, &SchedulesTabController::addWinterProfile);
connect(schedulesView, &SchedulesView::addHolidayProfileClicked, this, &SchedulesTabController::addHolidayProfile);
connect(schedulesView, &SchedulesView::dayScheduleSceneChanged, this, &SchedulesTabController::onDayScheduleSceneChanged);
connect(schedulesView, &SchedulesView::startDateTimeChanged, this, &SchedulesTabController::onStartDateTimeChanged);
connect(schedulesView, &SchedulesView::endDateTimeChanged, this, &SchedulesTabController::onEndDateTimeChanged);
Expand Down
2 changes: 2 additions & 0 deletions src/openstudio_lib/SchedulesTabController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class SchedulesTabController : public MainTabController

void addWinterProfile(model::ScheduleRuleset & scheduleRuleset, UUID scheduleDayHandle);

void addHolidayProfile(model::ScheduleRuleset & scheduleRuleset, UUID scheduleDayHandle);

void removeScheduleRule(model::ScheduleRule & scheduleRule);

void onDayScheduleSceneChanged(DayScheduleScene * scene, double lowerLimitValue, double upperLimitValue);
Expand Down
127 changes: 111 additions & 16 deletions src/openstudio_lib/SchedulesView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,9 @@ void SchedulesView::showSummerScheduleDay(model::ScheduleRuleset schedule)
if (!schedule.isSummerDesignDayScheduleDefaulted())
{

auto scheduleView = new SizingScheduleDayView(m_isIP, schedule, this, SizingScheduleDayView::SUMMER);
auto scheduleView = new SpecialScheduleDayView(m_isIP, schedule, this, SpecialScheduleDayView::SUMMER);

connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SizingScheduleDayView::toggleUnitsClicked);
connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SpecialScheduleDayView::toggleUnitsClicked);

m_contentLayout->addWidget(scheduleView);

Expand Down Expand Up @@ -560,9 +560,9 @@ void SchedulesView::showWinterScheduleDay(model::ScheduleRuleset schedule)

if (!schedule.isWinterDesignDayScheduleDefaulted())
{
auto scheduleView = new SizingScheduleDayView(m_isIP, schedule, this, SizingScheduleDayView::WINTER);
auto scheduleView = new SpecialScheduleDayView(m_isIP, schedule, this, SpecialScheduleDayView::WINTER);

connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SizingScheduleDayView::toggleUnitsClicked);
connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SpecialScheduleDayView::toggleUnitsClicked);

m_contentLayout->addWidget(scheduleView);

Expand All @@ -582,6 +582,42 @@ void SchedulesView::showWinterScheduleDay(model::ScheduleRuleset schedule)
setUpdatesEnabled(true);
}

void SchedulesView::showHolidayScheduleDay(model::ScheduleRuleset schedule)
{
setUpdatesEnabled(false);

QLayoutItem *child;
while ((child = m_contentLayout->takeAt(0)) != nullptr)
{
delete child->widget();

delete child;
}

if (!schedule.isHolidayScheduleDefaulted())
{
auto scheduleView = new SpecialScheduleDayView(m_isIP, schedule, this, SpecialScheduleDayView::HOLIDAY);

connect(this, &SchedulesView::toggleUnitsClicked, scheduleView, &SpecialScheduleDayView::toggleUnitsClicked);

m_contentLayout->addWidget(scheduleView);

scheduleView->show();

boost::optional<model::ModelObject> mo = schedule.holidaySchedule();
emit modelObjectSelected(mo, true);
} else {
auto newProfileView = new NewProfileView(schedule, this, NewProfileView::HOLIDAY);

m_contentLayout->addWidget(newProfileView, 100);

boost::optional<model::ModelObject> mo;
emit modelObjectSelected(mo, true);
}

setUpdatesEnabled(true);
}

void SchedulesView::showEmptyPage()
{
this->setUpdatesEnabled(false);
Expand Down Expand Up @@ -944,8 +980,8 @@ ScheduleTabContent::ScheduleTabContent(ScheduleTab * scheduleTab, QWidget * pare
mainVLayout->setSpacing(5);
setLayout(mainVLayout);

QLabel * designDayLabel = new QLabel("Design Day Profiles");
mainVLayout->addWidget(designDayLabel);
QLabel * specialDayLabel = new QLabel("Special Day Profiles");
mainVLayout->addWidget(specialDayLabel);

auto summerDesignDayLayout = new QHBoxLayout();
summerDesignDayLayout->setContentsMargins(0, 0, 0, 0);
Expand All @@ -961,6 +997,13 @@ ScheduleTabContent::ScheduleTabContent(ScheduleTab * scheduleTab, QWidget * pare
auto winterTab = new ScheduleTabDefault(m_scheduleTab, ScheduleTabDefault::WINTER);
winterDesignDayLayout->addWidget(winterTab);

auto holidayLayout = new QHBoxLayout();
holidayLayout->setContentsMargins(0, 0, 0, 0);
mainVLayout->addLayout(holidayLayout);

auto holidayTab = new ScheduleTabDefault(m_scheduleTab, ScheduleTabDefault::HOLIDAY);
holidayLayout->addWidget(holidayTab);

auto runPeriodLayout = new QHBoxLayout();
runPeriodLayout->setContentsMargins(0, 0, 0, 0);
mainVLayout->addLayout(runPeriodLayout);
Expand Down Expand Up @@ -1204,9 +1247,11 @@ ScheduleTabDefault::ScheduleTabDefault(ScheduleTab * scheduleTab, ScheduleTabDef

connect(this, &ScheduleTabDefault::defaultClicked, m_scheduleTab->schedulesView(), &SchedulesView::showDefaultScheduleDay);

connect(this, &ScheduleTabDefault::summerClicked, m_scheduleTab->schedulesView(), &SchedulesView::showSummerScheduleDay);

connect(this, &ScheduleTabDefault::winterClicked, m_scheduleTab->schedulesView(), &SchedulesView::showWinterScheduleDay);

connect(this, &ScheduleTabDefault::summerClicked, m_scheduleTab->schedulesView(), &SchedulesView::showSummerScheduleDay);
connect(this, &ScheduleTabDefault::holidayClicked, m_scheduleTab->schedulesView(), &SchedulesView::showHolidayScheduleDay);

auto mainHLayout = new QHBoxLayout();
mainHLayout->setContentsMargins(10, 0, 0, 0);
Expand All @@ -1217,13 +1262,17 @@ ScheduleTabDefault::ScheduleTabDefault(ScheduleTab * scheduleTab, ScheduleTabDef
switch (m_type)
{
case SUMMER:
m_label = new QLabel("Summer");
m_label = new QLabel("Summer Design Day");
setToolTip("Click to edit summer design day profile");
break;
case WINTER:
m_label = new QLabel("Winter");
m_label = new QLabel("Winter Design Day");
setToolTip("Click to edit winter design day profile");
break;
case HOLIDAY:
m_label = new QLabel("Holiday");
setToolTip("Click to edit holiday profile");
break;
default:
m_label = new QLabel("Default");
setToolTip("Click to edit default profile");
Expand Down Expand Up @@ -1253,7 +1302,7 @@ void ScheduleTabDefault::paintEvent(QPaintEvent * event)

p.setPen(Qt::SolidLine);

// DLM: don't draw color squares for summer and winter design days
// DLM: don't draw color squares for special days (winter/summer design days and Holiday)
if (m_type == DEFAULT)
{
p.setBrush(QBrush(m_scheduleTab->schedulesView()->colors[12]));
Expand Down Expand Up @@ -1284,6 +1333,9 @@ void ScheduleTabDefault::mouseReleaseEvent(QMouseEvent * event)
case WINTER:
emit winterClicked(schedule);
break;
case HOLIDAY:
emit holidayClicked(schedule);
break;
}
}

Expand Down Expand Up @@ -1363,6 +1415,18 @@ NewProfileView::NewProfileView(const model::ScheduleRuleset & scheduleRuleset, S
mainVLayout->addSpacing(10);
break;
}
case HOLIDAY:
{
auto label = new QLabel();
QString text;
text.append("The holiday profile is not set, therefore the default run period profile will be used.");
text.append(" Create a new profile to override the default run period profile.");
label->setText(text);
label->setWordWrap(true);
mainVLayout->addWidget(label);
mainVLayout->addSpacing(10);
break;
}
default:
break;
}
Expand Down Expand Up @@ -1409,6 +1473,7 @@ NewProfileView::NewProfileView(const model::ScheduleRuleset & scheduleRuleset, S
connect(this, &NewProfileView::addRuleClicked, schedulesView, &SchedulesView::addRuleClicked);
connect(this, &NewProfileView::addSummerProfileClicked, schedulesView, &SchedulesView::addSummerProfileClicked);
connect(this, &NewProfileView::addWinterProfileClicked, schedulesView, &SchedulesView::addWinterProfileClicked);
connect(this, &NewProfileView::addHolidayProfileClicked, schedulesView, &SchedulesView::addHolidayProfileClicked);

innerVLayout->addStretch();

Expand All @@ -1428,6 +1493,9 @@ void NewProfileView::onAddClicked()
case WINTER:
emit addWinterProfileClicked(m_scheduleRuleset, handle);
break;
case HOLIDAY:
emit addHolidayProfileClicked(m_scheduleRuleset, handle);
break;
default:
emit addRuleClicked(m_scheduleRuleset, handle);
}
Expand All @@ -1449,6 +1517,10 @@ void NewProfileView::populateComboBox(const model::ScheduleRuleset & scheduleRul
m_scheduleRuleComboBox->addItem("Winter Design Day Schedule", toQString(scheduleRuleset.winterDesignDaySchedule().handle()));
}

if (!scheduleRuleset.isHolidayScheduleDefaulted()){
m_scheduleRuleComboBox->addItem("Holiday Design Day Schedule", toQString(scheduleRuleset.holidaySchedule().handle()));
}

for (const auto& rule : scheduleRuleset.scheduleRules()){
m_scheduleRuleComboBox->addItem(toQString(rule.name().get()), toQString(rule.daySchedule().handle()));
}
Expand Down Expand Up @@ -1531,13 +1603,13 @@ DefaultScheduleDayView::DefaultScheduleDayView(bool isIP,
}

/******************************************************************************/
// SizingScheduleDayView
// SpecialScheduleDayView
/******************************************************************************/

SizingScheduleDayView::SizingScheduleDayView(bool isIP,
SpecialScheduleDayView::SpecialScheduleDayView(bool isIP,
const model::ScheduleRuleset & scheduleRuleset,
SchedulesView * schedulesView,
SizingScheduleDayType type)
SpecialScheduleDayType type)
: QWidget(schedulesView),
m_type(type)
{
Expand Down Expand Up @@ -1576,11 +1648,11 @@ SizingScheduleDayView::SizingScheduleDayView(bool isIP,

auto scheduleDayView = new ScheduleDayView(isIP, scheduleDay, schedulesView);

connect(this, &SizingScheduleDayView::toggleUnitsClicked, scheduleDayView, &ScheduleDayView::toggleUnitsClicked);
connect(this, &SpecialScheduleDayView::toggleUnitsClicked, scheduleDayView, &ScheduleDayView::toggleUnitsClicked);

mainVLayout->addWidget(scheduleDayView);
}
} else
} else if (m_type == WINTER)
{
if (!scheduleRuleset.isWinterDesignDayScheduleDefaulted())
{
Expand All @@ -1596,10 +1668,33 @@ SizingScheduleDayView::SizingScheduleDayView(bool isIP,

auto scheduleDayView = new ScheduleDayView(isIP, scheduleDay, schedulesView);

connect(this, &SizingScheduleDayView::toggleUnitsClicked, scheduleDayView, &ScheduleDayView::toggleUnitsClicked);
connect(this, &SpecialScheduleDayView::toggleUnitsClicked, scheduleDayView, &ScheduleDayView::toggleUnitsClicked);

mainVLayout->addWidget(scheduleDayView);
}
} else if (m_type == HOLIDAY)
{
if (!scheduleRuleset.isHolidayScheduleDefaulted())
{
QLabel * label = new QLabel("Holiday profile.");
label->setObjectName("H2");

auto hLayout = new QHBoxLayout();
hLayout->setContentsMargins(60, 0, 0, 10);
hLayout->addWidget(label);
mainVLayout->addLayout(hLayout);

model::ScheduleDay scheduleDay = scheduleRuleset.holidaySchedule();

auto scheduleDayView = new ScheduleDayView(isIP, scheduleDay, schedulesView);

connect(this, &SpecialScheduleDayView::toggleUnitsClicked, scheduleDayView, &ScheduleDayView::toggleUnitsClicked);

mainVLayout->addWidget(scheduleDayView);
}
} else {
// Shouldn't happen
OS_ASSERT(false);
}
}

Expand Down
Loading