diff --git a/src/openstudio_lib/CMakeLists.txt b/src/openstudio_lib/CMakeLists.txt index a467ff77d..ba4447e1c 100644 --- a/src/openstudio_lib/CMakeLists.txt +++ b/src/openstudio_lib/CMakeLists.txt @@ -254,6 +254,16 @@ set(${target_name}_SRC SchedulesTabView.hpp SchedulesView.cpp SchedulesView.hpp + ScheduleOthersController.cpp + ScheduleOthersController.hpp + ScheduleOthersView.cpp + ScheduleOthersView.hpp + ScheduleConstantInspectorView.cpp + ScheduleConstantInspectorView.hpp + ScheduleCompactInspectorView.cpp + ScheduleCompactInspectorView.hpp + ScheduleFileInspectorView.cpp + ScheduleFileInspectorView.hpp ScriptItem.cpp ScriptItem.hpp ScriptsTabController.cpp @@ -393,6 +403,7 @@ set(${target_name}_SRC ../shared_gui_components/CollapsibleComponentHeader.hpp ../shared_gui_components/CollapsibleComponentList.cpp ../shared_gui_components/CollapsibleComponentList.hpp + ../shared_gui_components/ColorPalettes.hpp ../shared_gui_components/Component.cpp ../shared_gui_components/Component.hpp ../shared_gui_components/ComponentList.cpp @@ -608,6 +619,11 @@ set(${target_name}_moc SchedulesTabController.hpp SchedulesTabView.hpp SchedulesView.hpp + ScheduleOthersView.hpp + ScheduleOthersController.hpp + ScheduleConstantInspectorView.hpp + ScheduleCompactInspectorView.hpp + ScheduleFileInspectorView.hpp ScriptItem.hpp ScriptsTabController.hpp ScriptsTabView.hpp diff --git a/src/openstudio_lib/GridItem.cpp b/src/openstudio_lib/GridItem.cpp index b2bffbbe4..06c99c792 100644 --- a/src/openstudio_lib/GridItem.cpp +++ b/src/openstudio_lib/GridItem.cpp @@ -31,11 +31,11 @@ #include "ServiceWaterGridItems.hpp" #include "IconLibrary.hpp" #include "LoopScene.hpp" -#include "SchedulesView.hpp" #include "OSDocument.hpp" #include "OSAppBase.hpp" #include "MainRightColumnController.hpp" #include "ModelObjectItem.hpp" +#include "../shared_gui_components/ColorPalettes.hpp" #include #include @@ -1380,11 +1380,11 @@ QColor SystemItem::plenumColor(const Handle& plenumHandle) { } else { int index = plenumIndex(plenumHandle); if (index < 0) { - color = SchedulesView::colors[0]; + color = ColorPalettes::schedule_rules_colors[0]; } else if (index > 12) { - color = SchedulesView::colors[12]; + color = ColorPalettes::schedule_rules_colors[12]; } else { - color = SchedulesView::colors[index]; + color = ColorPalettes::schedule_rules_colors[index]; } // DLM: Create a RenderingColor and associate it with the thermal zone? diff --git a/src/openstudio_lib/IconLibrary.cpp b/src/openstudio_lib/IconLibrary.cpp index 044c564da..161adf76b 100644 --- a/src/openstudio_lib/IconLibrary.cpp +++ b/src/openstudio_lib/IconLibrary.cpp @@ -448,6 +448,7 @@ IconLibrary::IconLibrary() { new QPixmap(":/images/mini_icons/mini_water_cooled.png"); m_miniIcons[openstudio::IddObjectType(openstudio::IddObjectType::OS_Schedule_Compact).value()] = new QPixmap(":/images/mini_icons/schedule.png"); m_miniIcons[openstudio::IddObjectType(openstudio::IddObjectType::OS_Schedule_Constant).value()] = new QPixmap(":/images/mini_icons/schedule.png"); + m_miniIcons[openstudio::IddObjectType(openstudio::IddObjectType::OS_Schedule_File).value()] = new QPixmap(":/images/mini_icons/schedule.png"); m_miniIcons[openstudio::IddObjectType(openstudio::IddObjectType::OS_Schedule_FixedInterval).value()] = new QPixmap(":/images/mini_icons/schedule.png"); m_miniIcons[openstudio::IddObjectType(openstudio::IddObjectType::OS_Schedule_Ruleset).value()] = new QPixmap(":/images/mini_icons/schedule.png"); diff --git a/src/openstudio_lib/MainRightColumnController.cpp b/src/openstudio_lib/MainRightColumnController.cpp index 25c2468a1..d7ea7e819 100644 --- a/src/openstudio_lib/MainRightColumnController.cpp +++ b/src/openstudio_lib/MainRightColumnController.cpp @@ -319,6 +319,25 @@ void MainRightColumnController::configureForSchedulesSubTab(int subTabID) { break; } + case SchedulesTabController::SCHEDULESOTHER: { + model::Model lib = doc->componentLibrary(); + + // my library + auto* myLibraryList = new ModelObjectTypeListView(lib, true, OSItemType::CollapsibleListHeader, true); + myLibraryList->setItemsDraggable(true); + myLibraryList->setItemsRemoveable(false); + myLibraryList->setItemsType(OSItemType::LibraryItem); + + myLibraryList->addModelObjectType(IddObjectType::OS_Schedule_Constant, "Constant Schedules"); + // myLibraryList->addModelObjectType(IddObjectType::OS_Schedule_Compact, "Compact Schedules"); + myLibraryList->addModelObjectCategoryPlaceholder("Schedules"); + + setLibraryView(myLibraryList); + doc->openSidebar(); + //doc->closeSidebar(); + + break; + } default: break; } diff --git a/src/openstudio_lib/ScheduleCompactInspectorView.cpp b/src/openstudio_lib/ScheduleCompactInspectorView.cpp new file mode 100644 index 000000000..c43835b28 --- /dev/null +++ b/src/openstudio_lib/ScheduleCompactInspectorView.cpp @@ -0,0 +1,148 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#include "ScheduleCompactInspectorView.hpp" + +#include "../shared_gui_components/OSLineEdit.hpp" +#include "../shared_gui_components/OSDoubleEdit.hpp" +#include "../model_editor/Utilities.hpp" + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +namespace openstudio { + +// ScheduleCompactInspectorView + +ScheduleCompactInspectorView::ScheduleCompactInspectorView(const openstudio::model::Model& model, QWidget* parent) + : ModelObjectInspectorView(model, true, parent) { + createLayout(); +} + +void ScheduleCompactInspectorView::createLayout() { + auto* hiddenWidget = new QWidget(); + this->stackedWidget()->addWidget(hiddenWidget); + + auto* visibleWidget = new QWidget(); + this->stackedWidget()->addWidget(visibleWidget); + + auto* mainGridLayout = new QGridLayout(); + mainGridLayout->setContentsMargins(7, 7, 7, 7); + mainGridLayout->setSpacing(14); + visibleWidget->setLayout(mainGridLayout); + + int row = mainGridLayout->rowCount(); + + QLabel* label = nullptr; + + // Name + + label = new QLabel("Name: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row, 0); + + ++row; + + m_nameEdit = new OSLineEdit2(); + mainGridLayout->addWidget(m_nameEdit, row, 0, 1, 1); + + ++row; + + // Value + + label = new QLabel("Content: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row++, 0); + + m_content = new QPlainTextEdit(); + m_content->setReadOnly(true); + const QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont); + m_content->setFont(f); + + mainGridLayout->addWidget(m_content, row++, 0, 1, 2); + + // Stretch + + mainGridLayout->setRowStretch(100, 100); + mainGridLayout->setColumnStretch(0, 3); + mainGridLayout->setColumnStretch(1, 1); + mainGridLayout->setColumnStretch(2, 1); +} + +void ScheduleCompactInspectorView::onClearSelection() { + ModelObjectInspectorView::onClearSelection(); // call parent implementation + detach(); +} + +void ScheduleCompactInspectorView::onSelectModelObject(const openstudio::model::ModelObject& modelObject) { + detach(); + auto sch = modelObject.cast(); + attach(sch); + refresh(); +} + +void ScheduleCompactInspectorView::onUpdate() { + refresh(); +} + +void ScheduleCompactInspectorView::attach(openstudio::model::ScheduleCompact& sch) { + m_sch = sch; + + m_nameEdit->bind( + *m_sch, OptionalStringGetter(std::bind(&model::ScheduleCompact::name, m_sch.get_ptr(), true)), + boost::optional(std::bind(&model::ScheduleCompact::setName, m_sch.get_ptr(), std::placeholders::_1))); + + std::stringstream ss; + sch.print(ss); + + m_content->setPlainText(toQString(ss.str())); + + this->stackedWidget()->setCurrentIndex(1); +} + +void ScheduleCompactInspectorView::detach() { + this->stackedWidget()->setCurrentIndex(0); + + m_nameEdit->unbind(); + + m_sch = boost::none; +} + +void ScheduleCompactInspectorView::refresh() {} + +} // namespace openstudio diff --git a/src/openstudio_lib/ScheduleCompactInspectorView.hpp b/src/openstudio_lib/ScheduleCompactInspectorView.hpp new file mode 100644 index 000000000..504ad3813 --- /dev/null +++ b/src/openstudio_lib/ScheduleCompactInspectorView.hpp @@ -0,0 +1,76 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#ifndef OPENSTUDIO_SCHEDULECOMPACTINSPECTORVIEW_HPP +#define OPENSTUDIO_SCHEDULECOMPACTINSPECTORVIEW_HPP + +#include "ModelObjectInspectorView.hpp" +#include + +class QPlainTextEdit; + +namespace openstudio { + +class OSLineEdit2; + +class ScheduleCompactInspectorView : public ModelObjectInspectorView +{ + Q_OBJECT + + public: + explicit ScheduleCompactInspectorView(const openstudio::model::Model& model, QWidget* parent = nullptr); + + virtual ~ScheduleCompactInspectorView() = default; + + protected: + virtual void onClearSelection() override; + + virtual void onSelectModelObject(const openstudio::model::ModelObject& modelObject) override; + + virtual void onUpdate() override; + + private: + void createLayout(); + + void attach(openstudio::model::ScheduleCompact& sch); + + void detach(); + + void refresh(); + + boost::optional m_sch; + + OSLineEdit2* m_nameEdit = nullptr; + + QPlainTextEdit* m_content = nullptr; +}; + +} // namespace openstudio + +#endif // OPENSTUDIO_SCHEDULECOMPACTINSPECTORVIEW_HPP diff --git a/src/openstudio_lib/ScheduleConstantInspectorView.cpp b/src/openstudio_lib/ScheduleConstantInspectorView.cpp new file mode 100644 index 000000000..ff7d58313 --- /dev/null +++ b/src/openstudio_lib/ScheduleConstantInspectorView.cpp @@ -0,0 +1,144 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#include "ScheduleConstantInspectorView.hpp" + +#include "../shared_gui_components/OSLineEdit.hpp" +#include "../shared_gui_components/OSDoubleEdit.hpp" + +#include +#include + +#include + +#include +#include +#include + +namespace openstudio { + +// ScheduleConstantInspectorView + +ScheduleConstantInspectorView::ScheduleConstantInspectorView(const openstudio::model::Model& model, QWidget* parent) + : ModelObjectInspectorView(model, true, parent) { + createLayout(); +} + +void ScheduleConstantInspectorView::createLayout() { + auto* hiddenWidget = new QWidget(); + this->stackedWidget()->addWidget(hiddenWidget); + + auto* visibleWidget = new QWidget(); + this->stackedWidget()->addWidget(visibleWidget); + + auto* mainGridLayout = new QGridLayout(); + mainGridLayout->setContentsMargins(7, 7, 7, 7); + mainGridLayout->setSpacing(14); + visibleWidget->setLayout(mainGridLayout); + + int row = mainGridLayout->rowCount(); + + QLabel* label = nullptr; + + // Name + + label = new QLabel("Name: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row, 0); + + ++row; + + m_nameEdit = new OSLineEdit2(); + mainGridLayout->addWidget(m_nameEdit, row, 0, 1, 2); + + ++row; + + // Value + + label = new QLabel(" Value: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row++, 0); + + m_value = new OSDoubleEdit2(); + mainGridLayout->addWidget(m_value, row++, 0, 1, 1); + + // Stretch + + mainGridLayout->setRowStretch(100, 100); + + mainGridLayout->setColumnStretch(0, 1); + mainGridLayout->setColumnStretch(1, 1); + mainGridLayout->setColumnStretch(2, 1); +} + +void ScheduleConstantInspectorView::onClearSelection() { + ModelObjectInspectorView::onClearSelection(); // call parent implementation + detach(); +} + +void ScheduleConstantInspectorView::onSelectModelObject(const openstudio::model::ModelObject& modelObject) { + detach(); + auto sch = modelObject.cast(); + attach(sch); + refresh(); +} + +void ScheduleConstantInspectorView::onUpdate() { + refresh(); +} + +void ScheduleConstantInspectorView::attach(openstudio::model::ScheduleConstant& sch) { + m_sch = sch; + + // m_nameEdit->bind(sch,"name"); + m_nameEdit->bind( + *m_sch, OptionalStringGetter(std::bind(&model::ScheduleConstant::name, m_sch.get_ptr(), true)), + boost::optional(std::bind(&model::ScheduleConstant::setName, m_sch.get_ptr(), std::placeholders::_1))); + + // m_value->bind(sch,"value",m_isIP); + m_value->bind(*m_sch, DoubleGetter(std::bind(&model::ScheduleConstant::value, m_sch.get_ptr())), + //static_cast(&Client::foobar) + boost::optional(std::bind(static_cast(&model::ScheduleConstant::setValue), + m_sch.get_ptr(), std::placeholders::_1))); + + this->stackedWidget()->setCurrentIndex(1); +} + +void ScheduleConstantInspectorView::detach() { + this->stackedWidget()->setCurrentIndex(0); + + m_nameEdit->unbind(); + m_value->unbind(); + + m_sch = boost::none; +} + +void ScheduleConstantInspectorView::refresh() {} + +} // namespace openstudio diff --git a/src/openstudio_lib/ScheduleConstantInspectorView.hpp b/src/openstudio_lib/ScheduleConstantInspectorView.hpp new file mode 100644 index 000000000..0046593da --- /dev/null +++ b/src/openstudio_lib/ScheduleConstantInspectorView.hpp @@ -0,0 +1,76 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#ifndef OPENSTUDIO_SCHEDULECONSTANTINSPECTORVIEW_HPP +#define OPENSTUDIO_SCHEDULECONSTANTINSPECTORVIEW_HPP + +#include "ModelObjectInspectorView.hpp" +#include + +namespace openstudio { + +class OSLineEdit2; + +class OSDoubleEdit2; + +class ScheduleConstantInspectorView : public ModelObjectInspectorView +{ + Q_OBJECT + + public: + explicit ScheduleConstantInspectorView(const openstudio::model::Model& model, QWidget* parent = nullptr); + + virtual ~ScheduleConstantInspectorView() = default; + + protected: + virtual void onClearSelection() override; + + virtual void onSelectModelObject(const openstudio::model::ModelObject& modelObject) override; + + virtual void onUpdate() override; + + private: + void createLayout(); + + void attach(openstudio::model::ScheduleConstant& sch); + + void detach(); + + void refresh(); + + boost::optional m_sch; + + OSLineEdit2* m_nameEdit = nullptr; + + OSDoubleEdit2* m_value = nullptr; +}; + +} // namespace openstudio + +#endif // OPENSTUDIO_SCHEDULECONSTANTINSPECTORVIEW_HPP diff --git a/src/openstudio_lib/ScheduleFileInspectorView.cpp b/src/openstudio_lib/ScheduleFileInspectorView.cpp new file mode 100644 index 000000000..9b3476713 --- /dev/null +++ b/src/openstudio_lib/ScheduleFileInspectorView.cpp @@ -0,0 +1,522 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#include "ScheduleFileInspectorView.hpp" + +#include "../shared_gui_components/OSLineEdit.hpp" +#include "../shared_gui_components/OSIntegerEdit.hpp" +#include "../shared_gui_components/OSComboBox.hpp" +#include "../shared_gui_components/OSSwitch.hpp" +#include "../model_editor/Utilities.hpp" + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include // Qt namespace, for SplitBehaviorFlags + +namespace openstudio { + +// ScheduleFileInspectorView + +ScheduleFileInspectorView::ScheduleFileInspectorView(const openstudio::model::Model& model, QWidget* parent) + : ModelObjectInspectorView(model, true, parent) { + createLayout(); +} + +void ScheduleFileInspectorView::createLayout() { + auto* hiddenWidget = new QWidget(); + this->stackedWidget()->addWidget(hiddenWidget); + + auto* visibleWidget = new QWidget(); + this->stackedWidget()->addWidget(visibleWidget); + + auto* mainGridLayout = new QGridLayout(); + mainGridLayout->setContentsMargins(7, 7, 7, 7); + mainGridLayout->setSpacing(14); + visibleWidget->setLayout(mainGridLayout); + + int row = mainGridLayout->rowCount(); + + QLabel* label = nullptr; + + // Name + + label = new QLabel("Name: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row, 0); + + ++row; + + m_nameEdit = new OSLineEdit2(); + mainGridLayout->addWidget(m_nameEdit, row, 0, 1, 3); + + // FilePath + ++row; + + label = new QLabel("FilePath: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row, 0); + + ++row; + + m_filePath = new QLineEdit(); + m_filePath->setReadOnly(true); + mainGridLayout->addWidget(m_filePath, row, 0, 1, 3); + + ++row; + + QVBoxLayout* vLayout = nullptr; + + // Column Number + vLayout = new QVBoxLayout(); + + label = new QLabel("Column Number: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_columnNumber = new OSIntegerEdit2(); + vLayout->addWidget(m_columnNumber); + + mainGridLayout->addLayout(vLayout, row, 0); + + // Rows to Skip + vLayout = new QVBoxLayout(); + + label = new QLabel("Rows to Skip at Top: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_rowstoSkipatTop = new OSIntegerEdit2(); + vLayout->addWidget(m_rowstoSkipatTop); + + mainGridLayout->addLayout(vLayout, row, 1); + + // Will be done in a lambda below, otherwise there's a race condition, the modelObject itself isn't modified when refreshContent is called + // connect(m_rowstoSkipatTop, &OSIntegerEdit2::editingFinished, this, &ScheduleFileInspectorView::refreshContent); + + ++row; + + // Number of Hours of Data + vLayout = new QVBoxLayout(); + + label = new QLabel("Number of Hours of Data: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_numberofHoursofData = new OSIntegerEdit2(); + vLayout->addWidget(m_numberofHoursofData); + + mainGridLayout->addLayout(vLayout, row, 0); + + // Column Separator + vLayout = new QVBoxLayout(); + + label = new QLabel("Column Separator: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_columnSeparator = new OSComboBox2(); + m_columnSeparator->addItem("Comma"); + m_columnSeparator->addItem("Tab"); + m_columnSeparator->addItem("Space"); + m_columnSeparator->addItem("Semicolon"); + m_columnSeparator->setEnabled(true); + vLayout->addWidget(m_columnSeparator); + + mainGridLayout->addLayout(vLayout, row, 1); + + ++row; + + // Interpolate + vLayout = new QVBoxLayout(); + + label = new QLabel("Interpolate to Timestep: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_interpolatetoTimestep = new OSSwitch2(); + vLayout->addWidget(m_interpolatetoTimestep); + + mainGridLayout->addLayout(vLayout, row, 0); + + // Minutes per Item + vLayout = new QVBoxLayout(); + + label = new QLabel("Minutes per Item: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_minutesperItem = new OSComboBox2(); + for (const auto& val : model::ScheduleFile::minutesperItemValues()) { + m_minutesperItem->addItem(QString::fromStdString(val)); + } + m_minutesperItem->setEnabled(true); + vLayout->addWidget(m_minutesperItem); + + mainGridLayout->addLayout(vLayout, row, 1); + + ++row; + + // Adjust Schedule for Daylight Savings + vLayout = new QVBoxLayout(); + + label = new QLabel("Adjust Schedule for Daylight Savings: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_adjustScheduleforDaylightSavings = new OSSwitch2(); + vLayout->addWidget(m_adjustScheduleforDaylightSavings); + + mainGridLayout->addLayout(vLayout, row, 0); + + // Translate File With Relative Path + vLayout = new QVBoxLayout(); + + label = new QLabel("Translate File With Relative Path: "); + label->setObjectName("H2"); + vLayout->addWidget(label); + + m_translateFileWithRelativePath = new OSSwitch2(); + vLayout->addWidget(m_translateFileWithRelativePath); + + mainGridLayout->addLayout(vLayout, row, 1); + + ++row; + + auto* line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + mainGridLayout->addWidget(line, row, 0, 1, -1); + row++; + + label = new QLabel("Content: "); + label->setObjectName("H2"); + mainGridLayout->addWidget(label, row, 0); + + ++row; + + label = new QLabel("Number of Lines in file: "); + label->setObjectName("H3"); + mainGridLayout->addWidget(label, row, 0); + + m_numLines = new QLineEdit(); + m_numLines->setReadOnly(true); + mainGridLayout->addWidget(m_numLines, row, 1, 1, 1); + + m_error = new QLabel(); + m_error->setStyleSheet("QLabel { color : red; font: bold }"); + m_error->hide(); + mainGridLayout->addWidget(m_error, row, 2, 1, 1); + + ++row; + + label = new QLabel("Display All File Content: "); + label->setObjectName("H3"); + mainGridLayout->addWidget(label, row, 0); + + // Mimic an OSSwitch2 + m_displayAllContentSwitch = new QPushButton(); + m_displayAllContentSwitch->setAcceptDrops(false); + m_displayAllContentSwitch->setFlat(true); + m_displayAllContentSwitch->setFixedSize(63, 21); + m_displayAllContentSwitch->setObjectName("OnOffSliderButton"); + m_displayAllContentSwitch->setCheckable(true); + mainGridLayout->addWidget(m_displayAllContentSwitch, row, 1, 1, 1); + + connect(m_displayAllContentSwitch, &QPushButton::toggled, [this](bool) { + m_displayAllContent = !m_displayAllContent; + refreshContent(); + }); + + ++row; + + m_contentLines = new QPlainTextEdit(); + m_contentLines->setReadOnly(true); + const QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont); + m_contentLines->setFont(f); + + mainGridLayout->addWidget(m_contentLines, row, 0, 1, 5); + + ++row; + + // Stretch + + mainGridLayout->setRowStretch(100, 100); + + mainGridLayout->setColumnStretch(4, 3); + mainGridLayout->setColumnStretch(5, 1); +} + +void ScheduleFileInspectorView::onClearSelection() { + ModelObjectInspectorView::onClearSelection(); // call parent implementation + detach(); +} + +void ScheduleFileInspectorView::onSelectModelObject(const openstudio::model::ModelObject& modelObject) { + detach(); + auto sch = modelObject.cast(); + attach(sch); + refresh(); +} + +void ScheduleFileInspectorView::onUpdate() { + refresh(); +} + +void ScheduleFileInspectorView::attach(openstudio::model::ScheduleFile& sch) { + m_sch = sch; + + // m_nameEdit->bind(sch,"name"); + m_nameEdit->bind( + *m_sch, OptionalStringGetter(std::bind(&model::ScheduleFile::name, m_sch.get_ptr(), true)), + boost::optional(std::bind(&model::ScheduleFile::setName, m_sch.get_ptr(), std::placeholders::_1))); + + // OSIntegerEdit2 + m_columnNumber->bind(*m_sch, IntGetter(std::bind(&model::ScheduleFile::columnNumber, m_sch.get_ptr())), + boost::optional([this](int value) -> bool { + bool result = m_sch->setColumnNumber(value); + if (result) { + refreshContent(); + refreshError(); + } + return result; + })); + + m_rowstoSkipatTop->bind(*m_sch, IntGetter(std::bind(&model::ScheduleFile::rowstoSkipatTop, m_sch.get_ptr())), + boost::optional([this](int value) -> bool { + bool result = m_sch->setRowstoSkipatTop(value); + if (result) { + refreshContent(); + refreshError(); + } + return result; + }) + // boost::optional(std::bind(&model::ScheduleFile::setRowstoSkipatTop, m_sch.get_ptr(), std::placeholders::_1)) + ); + + m_numberofHoursofData->bind(*m_sch, OptionalIntGetter(std::bind(&model::ScheduleFile::numberofHoursofData, m_sch.get_ptr())), + boost::optional([this](int value) -> bool { + bool result = m_sch->setNumberofHoursofData(value); + if (result) { + refreshError(); + } + return result; + })); + + // OSComboBox2 + + m_columnSeparator->bind( + *m_sch, static_cast(&openstudio::toString), + // ScheduleFile::columnSeparatorValues does not exist: https://github.com/NREL/OpenStudio/issues/5246 + []() { + return std::vector{"Comma", "Tab", "Space", "Semicolon"}; + }, + std::bind(&model::ScheduleFile::columnSeparator, m_sch.get_ptr()), + [this](const std::string& value) -> bool { + bool result = m_sch->setColumnSeparator(value); + if (result) { + refreshContent(); + } + return result; + }, + boost::none, boost::none); + + m_minutesperItem->bind( + *m_sch, + static_cast(&openstudio::toString), // toString + &model::ScheduleFile::minutesperItemValues, // choices + // Getter + // This returns an optional std::string when it really has a default... + // OptionalStringGetter(std::bind(&model::ScheduleFile::minutesperItem, m_sch.get_ptr())), + [sch_ptr = m_sch.get_ptr()]() -> std::string { return sch_ptr->minutesperItem().get(); }, + // Setter, another weirdness, but for backward compat it takes a std::string or an int... and the std::string one is deprecated + // std::bind(&model::ScheduleFile::setMinutesperItem, m_sch.get_ptr(), std::placeholders::_1), + [this](const std::string& minutesperItem) { + bool result = m_sch->setMinutesperItem(std::stoi(minutesperItem)); + if (result) { + refreshError(); + } + return result; + }, + boost::optional(std::bind(&model::ScheduleFile::resetMinutesperItem, m_sch.get_ptr())), // reset + boost::optional(std::bind(&model::ScheduleFile::isMinutesperItemDefaulted, m_sch.get_ptr())) // isDefaulted + + ); + + // OSSwitch2 + + m_interpolatetoTimestep->bind( + *m_sch, std::bind(&model::ScheduleFile::interpolatetoTimestep, m_sch.get_ptr()), + boost::optional(std::bind(&model::ScheduleFile::setInterpolatetoTimestep, m_sch.get_ptr(), std::placeholders::_1)), + boost::optional(std::bind(&model::ScheduleFile::resetInterpolatetoTimestep, m_sch.get_ptr())), + boost::optional(std::bind(&model::ScheduleFile::isInterpolatetoTimestepDefaulted, m_sch.get_ptr()))); + + m_adjustScheduleforDaylightSavings->bind( + *m_sch, std::bind(&model::ScheduleFile::adjustScheduleforDaylightSavings, m_sch.get_ptr()), + boost::optional(std::bind(&model::ScheduleFile::setAdjustScheduleforDaylightSavings, m_sch.get_ptr(), std::placeholders::_1)), + boost::optional(std::bind(&model::ScheduleFile::resetAdjustScheduleforDaylightSavings, m_sch.get_ptr())), + boost::optional(std::bind(&model::ScheduleFile::isAdjustScheduleforDaylightSavingsDefaulted, m_sch.get_ptr()))); + + m_translateFileWithRelativePath->bind( + *m_sch, std::bind(&model::ScheduleFile::translateFileWithRelativePath, m_sch.get_ptr()), + boost::optional(std::bind(&model::ScheduleFile::setTranslateFileWithRelativePath, m_sch.get_ptr(), std::placeholders::_1)), + boost::optional(std::bind(&model::ScheduleFile::resetTranslateFileWithRelativePath, m_sch.get_ptr())), + boost::optional(std::bind(&model::ScheduleFile::isTranslateFileWithRelativePathDefaulted, m_sch.get_ptr()))); + + refreshContent(); + + this->stackedWidget()->setCurrentIndex(1); +} + +void ScheduleFileInspectorView::detach() { + this->stackedWidget()->setCurrentIndex(0); + + m_nameEdit->unbind(); + m_columnNumber->unbind(); + m_rowstoSkipatTop->unbind(); + m_numberofHoursofData->unbind(); + m_columnSeparator->unbind(); + m_interpolatetoTimestep->unbind(); + m_minutesperItem->unbind(); + m_adjustScheduleforDaylightSavings->unbind(); + m_translateFileWithRelativePath->unbind(); + + m_sch = boost::none; +} + +void ScheduleFileInspectorView::refresh() {} + +void ScheduleFileInspectorView::refreshError() { + const int minutesperItem = std::stoi(m_sch->minutesperItem().get()); + const int numHours = m_sch->numberofHoursofData().value_or(8760); + const int expectedRecords = numHours * 60 / minutesperItem; + + const int rowstoSkipatTop = m_sch->rowstoSkipatTop(); + const int totalLines = m_lines.size(); + const int numRecords = totalLines - rowstoSkipatTop; + if (numRecords != expectedRecords) { + m_error->setText(QString("Expected %1 records but only %2 are selected").arg(expectedRecords).arg(numRecords)); + m_error->show(); + } else { + m_error->hide(); + } +} + +void ScheduleFileInspectorView::refreshContent() { + // QLineEdit + m_filePath->setText(toQString(m_sch->externalFile().fileName())); + + openstudio::path fpath = m_sch->externalFile().filePath(); + m_contentLines->clear(); + + if (openstudio::filesystem::is_regular_file(fpath)) { + const int rowstoSkipatTop = m_sch->rowstoSkipatTop(); + + const int colNum = m_sch->columnNumber() - 1; // Turn 1-indexed to 0-indexed + + QString sep; + Qt::SplitBehavior behavior = Qt::KeepEmptyParts; + if (openstudio::istringEqual(m_sch->columnSeparator(), "Comma")) { + sep = ','; + } else if (openstudio::istringEqual(m_sch->columnSeparator(), "Tab")) { + sep = '\t'; + } else if (openstudio::istringEqual(m_sch->columnSeparator(), "Space")) { + sep = ' '; // QRegularExpression("\\s+") + behavior = Qt::SkipEmptyParts; + } else if (openstudio::istringEqual(m_sch->columnSeparator(), "Semicolon")) { + sep = ';'; + } // Fixed: not handled + + if (m_lines.isEmpty()) { + m_lines.clear(); + + QFile inputFile(toQString(fpath)); + + if (inputFile.open(QIODevice::ReadOnly)) { + int curLine = 0; + + QTextStream in(&inputFile); + while (!in.atEnd()) { // && curLine < read_n_lines) { + m_lines.append(in.readLine()); + ++curLine; + } + inputFile.close(); + } + m_numLines->setText(QString::number(m_lines.size())); + } + + const int read_n_lines = std::min(std::max(rowstoSkipatTop + 2, 10), static_cast(m_lines.size())); + + auto constructStyledLine = [&sep, &behavior, &colNum](const QString& line, const QString& color) { + QStringList vals = line.split(sep, behavior); + QString str; + for (int j = 0; j < vals.size(); ++j) { + QString val = vals[j]; + if (j == colNum) { + str.append(QString("%2").arg(color).arg(val)); + } else { + str.append(QString("%1").arg(val)); + } + if (j < vals.size() - 1) { + str.append(","); + } + } + return str; + }; + + int curLine = 0; + for (const QString& line : m_lines) { + if (curLine < rowstoSkipatTop) { + m_contentLines->appendHtml(constructStyledLine(line, "black")); + } else if (m_displayAllContent || (curLine < read_n_lines) || (curLine > m_lines.size() - 5)) { + m_contentLines->appendHtml(constructStyledLine(line, "green")); + } else if (curLine == read_n_lines) { + m_contentLines->appendHtml("[...]"); + } + ++curLine; + } + } else { + m_contentLines->setPlainText(QString("File not found at '%1'").arg(toQString(fpath))); + } +} + +} // namespace openstudio diff --git a/src/openstudio_lib/ScheduleFileInspectorView.hpp b/src/openstudio_lib/ScheduleFileInspectorView.hpp new file mode 100644 index 000000000..e11f02446 --- /dev/null +++ b/src/openstudio_lib/ScheduleFileInspectorView.hpp @@ -0,0 +1,99 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#ifndef OPENSTUDIO_SCHEDULEFILEINSPECTORVIEW_HPP +#define OPENSTUDIO_SCHEDULEFILEINSPECTORVIEW_HPP + +#include "ModelObjectInspectorView.hpp" +#include + +class QLineEdit; +class QPlainTextEdit; +class QPushButton; + +namespace openstudio { + +class OSLineEdit2; +class OSIntegerEdit2; +class OSComboBox2; +class OSSwitch2; + +class ScheduleFileInspectorView : public ModelObjectInspectorView +{ + Q_OBJECT + + public: + explicit ScheduleFileInspectorView(const openstudio::model::Model& model, QWidget* parent = nullptr); + + virtual ~ScheduleFileInspectorView() = default; + + protected: + virtual void onClearSelection() override; + + virtual void onSelectModelObject(const openstudio::model::ModelObject& modelObject) override; + + virtual void onUpdate() override; + + private: + void createLayout(); + + void attach(openstudio::model::ScheduleFile& sch); + + void detach(); + + void refresh(); + + void refreshContent(); + + void refreshError(); + + boost::optional m_sch; + + OSLineEdit2* m_nameEdit = nullptr; + QLineEdit* m_filePath = nullptr; + OSIntegerEdit2* m_columnNumber = nullptr; + OSIntegerEdit2* m_rowstoSkipatTop = nullptr; + OSIntegerEdit2* m_numberofHoursofData = nullptr; + OSComboBox2* m_columnSeparator = nullptr; + OSSwitch2* m_interpolatetoTimestep = nullptr; + OSComboBox2* m_minutesperItem = nullptr; + OSSwitch2* m_adjustScheduleforDaylightSavings = nullptr; + OSSwitch2* m_translateFileWithRelativePath = nullptr; + + QLineEdit* m_numLines = nullptr; + QLabel* m_error = nullptr; + bool m_displayAllContent = false; + QPushButton* m_displayAllContentSwitch = nullptr; + QPlainTextEdit* m_contentLines = nullptr; + QStringList m_lines; +}; + +} // namespace openstudio + +#endif // OPENSTUDIO_SCHEDULEFILEINSPECTORVIEW_HPP diff --git a/src/openstudio_lib/ScheduleOthersController.cpp b/src/openstudio_lib/ScheduleOthersController.cpp new file mode 100644 index 000000000..6312f9048 --- /dev/null +++ b/src/openstudio_lib/ScheduleOthersController.cpp @@ -0,0 +1,109 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#include "ScheduleOthersController.hpp" +#include "ScheduleOthersView.hpp" + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include + +namespace openstudio { + +ScheduleOthersController::ScheduleOthersController(const model::Model& model) : ModelSubTabController(new ScheduleOthersView(model), model) {} + +void ScheduleOthersController::onAddObject(const openstudio::IddObjectType& iddObjectType) { + switch (iddObjectType.value()) { + case IddObjectType::OS_Schedule_Constant: { + openstudio::model::ScheduleConstant(this->model()); + break; + } + case IddObjectType::OS_Schedule_Compact: { + QMessageBox message(subTabView()); + message.setText("Creation of Schedule:Compact is not supported, you should use a ScheduleRuleset instead"); + message.exec(); + return; + } + case IddObjectType::OS_Schedule_File: { + QString selfilter = tr("CSV Files(*.csv)"); + QString fileName = QFileDialog::getOpenFileName(this->subTabView(), tr("Select External File"), QDir::homePath(), + tr("All files (*.*);;CSV Files(*.csv);;TSV Files(*.tsv)"), &selfilter); + if (!fileName.isNull()) { + boost::optional e_ = model::ExternalFile::getExternalFile(this->model(), fileName.toStdString()); + if (e_) { + model::ScheduleFile(*e_, 1, 1); + } + } + break; + } + default: + LOG_FREE_AND_THROW("ScheduleOthersController", "Unknown IddObjectType '" << iddObjectType.valueName() << "'"); + } +} + +void ScheduleOthersController::onCopyObject(const openstudio::model::ModelObject& modelObject) { + modelObject.clone(this->model()); +} + +void ScheduleOthersController::onRemoveObject(openstudio::model::ModelObject modelObject) { + modelObject.remove(); +} + +void ScheduleOthersController::onReplaceObject(openstudio::model::ModelObject modelObject, const OSItemId& replacementItemId) { + // not yet implemented +} + +void ScheduleOthersController::onPurgeObjects(const openstudio::IddObjectType& iddObjectType) { + this->model().purgeUnusedResourceObjects(iddObjectType); +} + +void ScheduleOthersController::onDrop(const OSItemId& itemId) { + boost::optional modelObject = this->getModelObject(itemId); + if (modelObject) { + if (modelObject->optionalCast()) { + if (this->fromComponentLibrary(itemId)) { + modelObject->clone(this->model()); + } + } + } +} + +void ScheduleOthersController::onInspectItem(OSItem* item) {} + +} // namespace openstudio diff --git a/src/openstudio_lib/ScheduleOthersController.hpp b/src/openstudio_lib/ScheduleOthersController.hpp new file mode 100644 index 000000000..f82e01d26 --- /dev/null +++ b/src/openstudio_lib/ScheduleOthersController.hpp @@ -0,0 +1,64 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#ifndef OPENSTUDIO_SCHEDULEOTHERSCONTROLLER_HPP +#define OPENSTUDIO_SCHEDULEOTHERSCONTROLLER_HPP + +#include "ModelSubTabController.hpp" + +namespace openstudio { + +class ScheduleOthersController : public ModelSubTabController +{ + Q_OBJECT + + public: + explicit ScheduleOthersController(const model::Model& model); + + virtual ~ScheduleOthersController() = default; + + protected: + virtual void onAddObject(const openstudio::IddObjectType& iddObjectType) override; + + virtual void onCopyObject(const openstudio::model::ModelObject& modelObject) override; + + virtual void onRemoveObject(openstudio::model::ModelObject modelObject) override; + + virtual void onReplaceObject(openstudio::model::ModelObject modelObject, const OSItemId& replacementItemId) override; + + virtual void onPurgeObjects(const openstudio::IddObjectType& iddObjectType) override; + + virtual void onDrop(const OSItemId& itemId) override; + + virtual void onInspectItem(OSItem* item) override; +}; + +} // namespace openstudio + +#endif // OPENSTUDIO_SCHEDULEOTHERSCONTROLLER_HPP diff --git a/src/openstudio_lib/ScheduleOthersView.cpp b/src/openstudio_lib/ScheduleOthersView.cpp new file mode 100644 index 000000000..84e6633b2 --- /dev/null +++ b/src/openstudio_lib/ScheduleOthersView.cpp @@ -0,0 +1,126 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#include "ScheduleOthersView.hpp" +#include "ModelObjectTypeListView.hpp" + +#include "ScheduleConstantInspectorView.hpp" +#include "ScheduleCompactInspectorView.hpp" +#include "ScheduleFileInspectorView.hpp" + +#include + +#include +#include + +#include + +namespace openstudio { + +ScheduleOthersView::ScheduleOthersView(const openstudio::model::Model& model, QWidget* parent) + : ModelSubTabView( + new ModelObjectTypeListView(ScheduleOthersView::modelObjectTypesAndNames(), model, true, OSItemType::CollapsibleListHeader, false, parent), + new ScheduleOthersInspectorView(model, parent), false, parent) {} + +std::vector> ScheduleOthersView::modelObjectTypesAndNames() { + return {{ + {IddObjectType::OS_Schedule_Constant, "Schedule Constant"}, + {IddObjectType::OS_Schedule_Compact, "Schedule Compact"}, + {IddObjectType::OS_Schedule_File, "Schedule File"}, + }}; +} + +ScheduleOthersInspectorView::ScheduleOthersInspectorView(const model::Model& model, QWidget* parent) + : ModelObjectInspectorView(model, false, parent) {} + +void ScheduleOthersInspectorView::onClearSelection() { + QWidget* widget = this->stackedWidget()->currentWidget(); + auto* modelObjectInspectorView = qobject_cast(widget); + if (modelObjectInspectorView) { + modelObjectInspectorView->clearSelection(); + } + + this->stackedWidget()->setCurrentIndex(0); +} + +void ScheduleOthersInspectorView::onUpdate() {} + +void ScheduleOthersInspectorView::onSelectModelObject(const openstudio::model::ModelObject& modelObject) { + switch (modelObject.iddObjectType().value()) { + case IddObjectType::OS_Schedule_Constant: + this->showScheduleConstantView(modelObject); + break; + case IddObjectType::OS_Schedule_Compact: + this->showScheduleCompactView(modelObject); + break; + case IddObjectType::OS_Schedule_File: + this->showScheduleFileView(modelObject); + break; + default: + showDefaultView(); + } +} + +void ScheduleOthersInspectorView::showScheduleConstantView(const openstudio::model::ModelObject& modelObject) { + auto* view = new ScheduleConstantInspectorView(m_model); + view->selectModelObject(modelObject); + this->showInspector(view); +} + +void ScheduleOthersInspectorView::showScheduleCompactView(const openstudio::model::ModelObject& modelObject) { + auto* view = new ScheduleCompactInspectorView(m_model); + view->selectModelObject(modelObject); + this->showInspector(view); +} + +void ScheduleOthersInspectorView::showScheduleFileView(const openstudio::model::ModelObject& modelObject) { + auto* view = new ScheduleFileInspectorView(m_model); + view->selectModelObject(modelObject); + this->showInspector(view); +} + +void ScheduleOthersInspectorView::showInspector(QWidget* widget) { + if (QWidget* _widget = this->stackedWidget()->currentWidget()) { + this->stackedWidget()->removeWidget(_widget); + + delete _widget; + } + + this->stackedWidget()->addWidget(widget); +} + +void ScheduleOthersInspectorView::showDefaultView() { + if (QWidget* widget = this->stackedWidget()->currentWidget()) { + this->stackedWidget()->removeWidget(widget); + + delete widget; + } +} + +} // namespace openstudio diff --git a/src/openstudio_lib/ScheduleOthersView.hpp b/src/openstudio_lib/ScheduleOthersView.hpp new file mode 100644 index 000000000..b737d979c --- /dev/null +++ b/src/openstudio_lib/ScheduleOthersView.hpp @@ -0,0 +1,85 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#ifndef OPENSTUDIO_SCHEDULEOTHERSVIEW_HPP +#define OPENSTUDIO_SCHEDULEOTHERSVIEW_HPP + +#include "ModelSubTabView.hpp" +#include "ModelObjectInspectorView.hpp" + +#include + +class QStackedWidget; + +namespace openstudio { + +class ScheduleOthersView : public ModelSubTabView +{ + Q_OBJECT + + public: + explicit ScheduleOthersView(const openstudio::model::Model& model, QWidget* parent = nullptr); + + virtual ~ScheduleOthersView() = default; + + private: + static std::vector> modelObjectTypesAndNames(); +}; + +class ScheduleOthersInspectorView : public ModelObjectInspectorView +{ + Q_OBJECT + + public: + explicit ScheduleOthersInspectorView(const model::Model& model, QWidget* parent = nullptr); + + virtual ~ScheduleOthersInspectorView() = default; + + protected: + virtual void onClearSelection() override; + + virtual void onSelectModelObject(const openstudio::model::ModelObject& modelObject) override; + + virtual void onUpdate() override; + + private: + void showScheduleConstantView(const openstudio::model::ModelObject& modelObject); + void showScheduleCompactView(const openstudio::model::ModelObject& modelObject); + void showScheduleFileView(const openstudio::model::ModelObject& modelObject); + + void showInspector(QWidget* widget); + + void showDefaultView(); + + std::map m_inspectorIndexMap; +}; + +} // namespace openstudio + +#endif // OPENSTUDIO_SCHEDULEOTHERSVIEW_HPP diff --git a/src/openstudio_lib/SchedulesTabController.cpp b/src/openstudio_lib/SchedulesTabController.cpp index 982c17604..00de7b2c5 100644 --- a/src/openstudio_lib/SchedulesTabController.cpp +++ b/src/openstudio_lib/SchedulesTabController.cpp @@ -39,6 +39,8 @@ #include "SchedulesTabView.hpp" #include "SchedulesView.hpp" #include "ScheduleDayView.hpp" +#include "ScheduleOthersController.hpp" +#include "ScheduleOthersView.hpp" #include "SubTabView.hpp" #include @@ -71,6 +73,7 @@ SchedulesTabController::SchedulesTabController(bool isIP, const model::Model& mo : MainTabController(new SchedulesTabView(model)), m_model(model), m_isIP(isIP) { mainContentWidget()->addSubTab("Schedule Sets", SCHEDULE_SETS); mainContentWidget()->addSubTab("Schedules", SCHEDULES); + mainContentWidget()->addSubTab("Other Schedules", SCHEDULESOTHER); connect(this->mainContentWidget(), &MainTabView::tabSelected, this, &SchedulesTabController::setSubTab); } @@ -449,13 +452,20 @@ void SchedulesTabController::setSubTab(int index) { disconnect(qobject_cast(m_currentView), &SchedulesView::itemDropped, this, &SchedulesTabController::onItemDropped); disconnect(qobject_cast(m_currentView), &SchedulesView::modelObjectSelected, this, &SchedulesTabController::modelObjectSelected); disconnect(this, &SchedulesTabController::toggleUnitsClicked, this, &SchedulesTabController::toggleUnits); + } else if (qobject_cast(m_currentView) && qobject_cast(m_currentController)) { + disconnect(qobject_cast(m_currentController), &ScheduleOthersController::downloadComponentsClicked, this, + &SchedulesTabController::downloadComponentsClicked); + disconnect(qobject_cast(m_currentController), &ScheduleOthersController::openLibDlgClicked, this, + &SchedulesTabController::openLibDlgClicked); + disconnect(this, &SchedulesTabController::toggleUnitsClicked, this, &SchedulesTabController::toggleUnits); + m_currentController = nullptr; } else if (m_currentView) { // Oops! Should never get here OS_ASSERT(false); } switch (index) { - case 0: { + case TabID::SCHEDULE_SETS: { auto* scheduleSetsController = new ScheduleSetsController(m_model); connect(scheduleSetsController, &ScheduleSetsController::downloadComponentsClicked, this, &SchedulesTabController::downloadComponentsClicked); connect(scheduleSetsController, &ScheduleSetsController::openLibDlgClicked, this, &SchedulesTabController::openLibDlgClicked); @@ -465,7 +475,7 @@ void SchedulesTabController::setSubTab(int index) { m_currentController = scheduleSetsController; break; } - case 1: { + case TabID::SCHEDULES: { auto* schedulesView = new SchedulesView(m_isIP, m_model); addQObject(schedulesView); connect(this, &SchedulesTabController::toggleUnitsClicked, schedulesView, &SchedulesView::toggleUnitsClicked); @@ -488,6 +498,17 @@ void SchedulesTabController::setSubTab(int index) { m_currentView = schedulesView; break; } + case TabID::SCHEDULESOTHER: { + auto* scheduleOthersController = new ScheduleOthersController(m_model); + connect(scheduleOthersController, &ScheduleOthersController::downloadComponentsClicked, this, + &SchedulesTabController::downloadComponentsClicked); + connect(scheduleOthersController, &ScheduleOthersController::openLibDlgClicked, this, &SchedulesTabController::openLibDlgClicked); + connect(this, &SchedulesTabController::toggleUnitsClicked, this, &SchedulesTabController::toggleUnits); + this->mainContentWidget()->setSubTab(scheduleOthersController->subTabView()); + m_currentView = scheduleOthersController->subTabView(); + m_currentController = scheduleOthersController; + break; + } default: OS_ASSERT(false); break; diff --git a/src/openstudio_lib/SchedulesTabController.hpp b/src/openstudio_lib/SchedulesTabController.hpp index 637a5dade..ebc4083ba 100644 --- a/src/openstudio_lib/SchedulesTabController.hpp +++ b/src/openstudio_lib/SchedulesTabController.hpp @@ -75,7 +75,8 @@ class SchedulesTabController : public MainTabController { //YEAR_SETTINGS, SCHEDULE_SETS, - SCHEDULES + SCHEDULES, + SCHEDULESOTHER }; static double defaultStartingValue(const model::ScheduleDay& scheduleDay); diff --git a/src/openstudio_lib/SchedulesView.cpp b/src/openstudio_lib/SchedulesView.cpp index f73e07907..9ab460f2b 100644 --- a/src/openstudio_lib/SchedulesView.cpp +++ b/src/openstudio_lib/SchedulesView.cpp @@ -35,6 +35,7 @@ #include "OSItem.hpp" #include "OSItemSelectorButtons.hpp" #include "../shared_gui_components/OSLineEdit.hpp" +#include "../shared_gui_components/ColorPalettes.hpp" #include #include @@ -58,6 +59,7 @@ #include #include +#include #include #include #include @@ -88,28 +90,6 @@ namespace openstudio { // SchedulesView /******************************************************************************/ -const std::vector SchedulesView::colors = SchedulesView::initializeColors(); - -std::vector SchedulesView::initializeColors() { - std::vector _colors(13); - - _colors[0] = QColor(170, 68, 153); - _colors[1] = QColor(51, 34, 136); - _colors[2] = QColor(17, 119, 51); - _colors[3] = QColor(153, 153, 51); - _colors[4] = QColor(221, 204, 119); - _colors[5] = QColor(204, 102, 119); - _colors[6] = QColor(136, 34, 85); - _colors[7] = QColor(68, 170, 153); - _colors[8] = QColor(102, 153, 204); - _colors[9] = QColor(102, 17, 0); - _colors[10] = QColor(170, 68, 102); - _colors[11] = QColor(80, 80, 80); - _colors[12] = QColor(136, 204, 238); - - return _colors; -} - SchedulesView::SchedulesView(bool isIP, const model::Model& model) : m_model(model), m_leftVLayout(new QVBoxLayout()), m_contentLayout(new QHBoxLayout()), m_isIP(isIP) { setObjectName("GrayWidgetWithLeftTopBorders"); @@ -1056,7 +1036,7 @@ void ScheduleTabRule::paintEvent(QPaintEvent* /*event*/) { p.drawRect(0, 0, size().width() - 1, size().height() - 1); } - p.setBrush(QBrush(m_scheduleTab->schedulesView()->colors[i])); + p.setBrush(QBrush(ColorPalettes::schedule_rules_colors[i])); p.setPen(Qt::SolidLine); @@ -1167,7 +1147,7 @@ void ScheduleTabDefault::paintEvent(QPaintEvent* /*event*/) { // 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])); + p.setBrush(QBrush(ColorPalettes::schedule_rules_colors[12])); p.drawRect(0, 0, 5, size().height() - 1); } @@ -1585,7 +1565,7 @@ ScheduleRuleView::ScheduleRuleView(bool isIP, const model::ScheduleRule& schedul if (colorIndex > 12) { colorIndex = 12; } - QColor color = m_schedulesView->colors[colorIndex]; + QColor color = ColorPalettes::schedule_rules_colors[colorIndex]; colorStyle.append(color.name()); colorStyle.append("; }"); colorWidget->setStyleSheet(colorStyle); @@ -2103,14 +2083,14 @@ void ScheduleCalendarWidget::paintCell(QPainter* painter, const QRect& rect, QDa int ruleIndex = m_monthView->yearOverview()->activeRuleIndices()[dayOfYear - 1]; - QColor ruleColor = SchedulesView::colors[12]; + QColor ruleColor = ColorPalettes::schedule_rules_colors[12]; if (ruleIndex > 12) { ruleIndex = 12; } if (ruleIndex > -1) { - ruleColor = SchedulesView::colors[ruleIndex]; + ruleColor = ColorPalettes::schedule_rules_colors[ruleIndex]; } QString dateString = QString::number(date.day()); diff --git a/src/openstudio_lib/SchedulesView.hpp b/src/openstudio_lib/SchedulesView.hpp index fe14d894f..0faced0b1 100644 --- a/src/openstudio_lib/SchedulesView.hpp +++ b/src/openstudio_lib/SchedulesView.hpp @@ -45,8 +45,6 @@ #include #include -#include - #include #include #include @@ -132,10 +130,6 @@ class SchedulesView Q_OBJECT public: - static const std::vector colors; - - static std::vector initializeColors(); - SchedulesView(bool isIP, const model::Model& model); virtual ~SchedulesView() = default; diff --git a/src/shared_gui_components/ColorPalettes.hpp b/src/shared_gui_components/ColorPalettes.hpp new file mode 100644 index 000000000..a7e1dad10 --- /dev/null +++ b/src/shared_gui_components/ColorPalettes.hpp @@ -0,0 +1,63 @@ +/*********************************************************************************************************************** +* OpenStudio(R), Copyright (c) 2020-2023, OpenStudio Coalition and other contributors. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +* following conditions are met: +* +* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following +* disclaimer. +* +* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the distribution. +* +* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products +* derived from this software without specific prior written permission from the respective party. +* +* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works +* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior +* written permission from Alliance for Sustainable Energy, LLC. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED +* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +***********************************************************************************************************************/ + +#ifndef SHAREDGUICOMPONENTS_COLORPALETTES_HPP +#define SHAREDGUICOMPONENTS_COLORPALETTES_HPP + +#include + +#include + +namespace openstudio { + +namespace ColorPalettes { + +static constexpr std::array schedule_rules_colors{{ + // {r, g, b}, // **approximative** color name (found closest match from SVG color keyword name from World Wide Web Consortium) + {170, 68, 153}, // darkorchid + {51, 34, 136}, // darkslateblue + {17, 119, 51}, // forestgreen + {153, 153, 51}, // olivedrab + {221, 204, 119}, // burlywood + {204, 102, 119}, // indianred + {136, 34, 85}, // brown + {68, 170, 153}, // cadetblue + {102, 153, 204}, // cornflowerblue + {102, 17, 0}, // maroon + {170, 68, 102}, // indianred + {80, 80, 80}, // darkslategray + {136, 204, 238}, // skyblue + +}}; + +} // namespace ColorPalettes + +} // namespace openstudio + +#endif // SHAREDGUICOMPONENTS_COLORPALETTES_HPP diff --git a/src/shared_gui_components/OSGridController.cpp b/src/shared_gui_components/OSGridController.cpp index 97ed457f3..0a6892bf8 100644 --- a/src/shared_gui_components/OSGridController.cpp +++ b/src/shared_gui_components/OSGridController.cpp @@ -43,7 +43,6 @@ #include "../openstudio_lib/OSDropZone.hpp" #include "../openstudio_lib/OSItemSelector.hpp" #include "../openstudio_lib/RenderingColorWidget.hpp" -#include "../openstudio_lib/SchedulesView.hpp" #include #include @@ -76,8 +75,6 @@ namespace openstudio { -const std::vector OSGridController::m_colors = SchedulesView::initializeColors(); - OSGridController::OSGridController() : m_hasHorizontalHeader(true), m_currentCategoryIndex(0), diff --git a/src/shared_gui_components/OSGridController.hpp b/src/shared_gui_components/OSGridController.hpp index 77e00062b..66c8c599f 100644 --- a/src/shared_gui_components/OSGridController.hpp +++ b/src/shared_gui_components/OSGridController.hpp @@ -530,8 +530,6 @@ class OSGridController : public QObject std::vector m_customFields; - static const std::vector m_colors; - model::Model m_model; bool m_isIP;