-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathSpacesInteriorPartitionsGridView.cpp
More file actions
277 lines (235 loc) · 14 KB
/
SpacesInteriorPartitionsGridView.cpp
File metadata and controls
277 lines (235 loc) · 14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) OpenStudio Coalition and other contributors.
* See also https://openstudiocoalition.org/about/software_license/
***********************************************************************************************************************/
#include "SpacesInteriorPartitionsGridView.hpp"
#include "OSDropZone.hpp"
#include "OSItemSelectorButtons.hpp"
#include "../shared_gui_components/OSCheckBox.hpp"
#include "../shared_gui_components/OSGridController.hpp"
#include "../shared_gui_components/OSGridView.hpp"
#include "../shared_gui_components/OSObjectSelector.hpp"
#include <openstudio/model/ConstructionBase.hpp>
#include <openstudio/model/ConstructionBase_Impl.hpp>
#include <openstudio/model/DaylightingDeviceShelf.hpp>
#include <openstudio/model/DaylightingDeviceShelf_Impl.hpp>
#include <openstudio/model/InteriorPartitionSurface.hpp>
#include <openstudio/model/InteriorPartitionSurface_Impl.hpp>
#include <openstudio/model/InteriorPartitionSurfaceGroup.hpp>
#include <openstudio/model/InteriorPartitionSurfaceGroup_Impl.hpp>
#include <openstudio/model/Space.hpp>
#include <openstudio/model/Space_Impl.hpp>
#include <openstudio/utilities/core/Assert.hpp>
#include <openstudio/utilities/core/Compare.hpp>
#include <openstudio/utilities/idd/IddEnums.hxx>
#include <openstudio/utilities/idd/OS_Space_FieldEnums.hxx>
#include <QCheckBox>
// These defines provide a common area for field display names
// used on column headers, and other grid widgets
#define NAME "Space Name"
#define SELECTED "All"
#define DISPLAYNAME "Display Name"
#define CADOBJECTID "CAD Object ID"
// GENERAL
#define INTERIORPARTITIONGROUPNAME "Interior Partition Group Name" // read only
#define INTERIORPARTITIONNAME "Interior Partition Name"
#define CONSTRUCTIONNAME "Construction Name"
#define CONVERTTOINTERNALMASS "Convert to Internal Mass"
#define SURFACEAREA "Surface Area"
#define DAYLIGHTINGSHELFNAME "Daylighting Shelf Name" // read only
namespace openstudio {
SpacesInteriorPartitionsGridView::SpacesInteriorPartitionsGridView(bool isIP, bool displayAdditionalProps, const model::Model& model, QWidget* parent)
: SpacesSubtabGridView(isIP, displayAdditionalProps, model, parent) {
showStoryFilter();
showThermalZoneFilter();
showSpaceTypeFilter();
showInteriorPartitionGroupFilter();
m_filterGridLayout->setRowStretch(m_filterGridLayout->rowCount(), 100);
m_filterGridLayout->setColumnStretch(m_filterGridLayout->columnCount(), 100);
m_gridController =
new SpacesInteriorPartitionsGridController(isIP, displayAdditionalProps, "Space", IddObjectType::OS_Space, model, m_spacesModelObjects);
m_gridView = new OSGridView(m_gridController, "Space", "Drop\nSpace", false, parent);
setGridController(m_gridController);
setGridView(m_gridView);
m_gridView->addLayoutToContentLayout(m_filterGridLayout);
m_gridView->addSpacingToContentLayout(7);
m_gridView->showDropZone(false);
clearSelection();
}
void SpacesInteriorPartitionsGridView::onSelectItem() {
//m_itemSelectorButtons->enableAddButton();
//m_itemSelectorButtons->enableCopyButton();
//m_itemSelectorButtons->enableRemoveButton();
//m_itemSelectorButtons->enablePurgeButton();
}
void SpacesInteriorPartitionsGridView::onClearSelection() {
clearSelection();
}
void SpacesInteriorPartitionsGridView::clearSelection() {
m_itemSelectorButtons->disableAddButton();
//m_itemSelectorButtons->disableCopyButton();
//m_itemSelectorButtons->disableRemoveButton();
m_itemSelectorButtons->disablePurgeButton();
}
SpacesInteriorPartitionsGridController::SpacesInteriorPartitionsGridController(bool isIP, bool displayAdditionalProps, const QString& headerText,
IddObjectType iddObjectType, const model::Model& model,
const std::vector<model::ModelObject>& modelObjects)
: OSGridController(isIP, headerText, iddObjectType, model, modelObjects, displayAdditionalProps) {
setCategoriesAndFields();
}
void SpacesInteriorPartitionsGridController::setCategoriesAndFields() {
{
std::vector<QString> fields{
INTERIORPARTITIONNAME, INTERIORPARTITIONGROUPNAME, CONSTRUCTIONNAME, CONVERTTOINTERNALMASS,
//SURFACEAREA,
//DAYLIGHTINGSHELFNAME,
};
std::pair<QString, std::vector<QString>> categoryAndFields = std::make_pair(QString("General"), fields);
addCategoryAndFields(categoryAndFields);
}
OSGridController::setCategoriesAndFields();
}
void SpacesInteriorPartitionsGridController::onCategorySelected(int index) {
OSGridController::onCategorySelected(index);
}
void SpacesInteriorPartitionsGridController::addColumns(const QString& category, std::vector<QString>& fields) {
if (isDisplayAdditionalProps()) {
fields.insert(fields.begin(), {DISPLAYNAME, CADOBJECTID});
}
// always show name and selected columns
fields.insert(fields.begin(), {NAME, SELECTED});
resetBaseConcepts();
for (const auto& field : fields) {
if (field == NAME) {
addParentNameLineEditColumn(Heading(QString(NAME), false, false), false, CastNullAdapter<model::Space>(&model::Space::name),
CastNullAdapter<model::Space>(&model::Space::setName));
} else if (field == DISPLAYNAME) {
addNameLineEditColumn(Heading(QString(DISPLAYNAME), false, false), // heading
false, // isInspectable
false, // isLocked
DisplayNameAdapter<model::Space>(&model::Space::displayName), // getter
DisplayNameAdapter<model::Space>(&model::Space::setDisplayName) // setter
);
} else if (field == CADOBJECTID) {
addNameLineEditColumn(Heading(QString(CADOBJECTID), false, false), // heading
false, // isInspectable
false, // isLocked
DisplayNameAdapter<model::Space>(&model::Space::cadObjectId), // getter
DisplayNameAdapter<model::Space>(&model::Space::setCADObjectId) // setter
);
} else {
std::function<std::vector<model::ModelObject>(const model::Space&)> allInteriorPartitionSurfaceGroups([](const model::Space& t_space) {
std::vector<model::ModelObject> allModelObjects;
auto interiorPartitionSurfaceGroups = t_space.interiorPartitionSurfaceGroups();
allModelObjects.insert(allModelObjects.end(), interiorPartitionSurfaceGroups.begin(), interiorPartitionSurfaceGroups.end());
return allModelObjects;
});
std::function<std::vector<model::ModelObject>(const model::Space&)> allInteriorPartitionSurfaces(
[allInteriorPartitionSurfaceGroups](const model::Space& t_space) {
std::vector<model::ModelObject> allModelObjects;
for (const auto& interiorPartitionSurfaceGroup : allInteriorPartitionSurfaceGroups(t_space)) {
auto interiorPartitionSurfaces = interiorPartitionSurfaceGroup.cast<model::InteriorPartitionSurfaceGroup>().interiorPartitionSurfaces();
for (const auto& interiorPartitionSurface : interiorPartitionSurfaces) {
allModelObjects.push_back(interiorPartitionSurface);
}
}
return allModelObjects;
});
std::function<std::vector<boost::optional<model::ModelObject>>(const model::Space&)> allInteriorPartitionSurfaceInteriorPartitionSurfaceGroups(
[allInteriorPartitionSurfaceGroups](const model::Space& t_space) {
std::vector<boost::optional<model::ModelObject>> allModelObjects;
for (const auto& interiorPartitionSurfaceGroup : allInteriorPartitionSurfaceGroups(t_space)) {
auto interiorPartitionSurfaces = interiorPartitionSurfaceGroup.cast<model::InteriorPartitionSurfaceGroup>().interiorPartitionSurfaces();
for (const auto& interiorPartitionSurface : interiorPartitionSurfaces) {
auto group = interiorPartitionSurface.interiorPartitionSurfaceGroup();
if (group) {
allModelObjects.push_back(*group);
} else {
allModelObjects.emplace_back();
}
}
}
return allModelObjects;
});
if (field == SELECTED) {
auto checkbox = QSharedPointer<OSSelectAllCheckBox>(new OSSelectAllCheckBox());
checkbox->setToolTip("Check to select all rows");
connect(checkbox.data(), &OSSelectAllCheckBox::checkStateChanged, this, &SpacesInteriorPartitionsGridController::onSelectAllStateChanged);
connect(this, &SpacesInteriorPartitionsGridController::gridRowSelectionChanged, checkbox.data(),
&OSSelectAllCheckBox::onGridRowSelectionChanged);
addSelectColumn(Heading(QString(SELECTED), false, false, checkbox), "Check to select this row",
DataSource(allInteriorPartitionSurfaces, true));
} else if (field == INTERIORPARTITIONGROUPNAME) {
addNameLineEditColumn(Heading(QString(INTERIORPARTITIONGROUPNAME), true, false), false, false,
CastNullAdapter<model::InteriorPartitionSurfaceGroup>(&model::InteriorPartitionSurfaceGroup::name),
CastNullAdapter<model::InteriorPartitionSurfaceGroup>(&model::InteriorPartitionSurfaceGroup::setName),
boost::optional<std::function<void(model::InteriorPartitionSurfaceGroup*)>>(),
boost::optional<std::function<bool(model::InteriorPartitionSurfaceGroup*)>>(),
DataSource(allInteriorPartitionSurfaceInteriorPartitionSurfaceGroups, true));
} else if (field == INTERIORPARTITIONNAME) {
addNameLineEditColumn(Heading(QString(INTERIORPARTITIONNAME), true, false), false, false,
CastNullAdapter<model::InteriorPartitionSurface>(&model::InteriorPartitionSurface::name),
CastNullAdapter<model::InteriorPartitionSurface>(&model::InteriorPartitionSurface::setName),
boost::optional<std::function<void(model::InteriorPartitionSurface*)>>(),
boost::optional<std::function<bool(model::InteriorPartitionSurface*)>>(),
DataSource(allInteriorPartitionSurfaces, true));
} else if (field == CONSTRUCTIONNAME) {
setConstructionColumn(4);
addDropZoneColumn(
Heading(QString(CONSTRUCTIONNAME), true, false),
CastNullAdapter<model::InteriorPartitionSurface>(&model::InteriorPartitionSurface::construction),
CastNullAdapter<model::InteriorPartitionSurface>(&model::InteriorPartitionSurface::setConstruction),
boost::optional<std::function<void(model::InteriorPartitionSurface*)>>(NullAdapter(&model::InteriorPartitionSurface::resetConstruction)),
boost::optional<std::function<bool(model::InteriorPartitionSurface*)>>(
NullAdapter(&model::InteriorPartitionSurface::isConstructionDefaulted)),
boost::optional<std::function<std::vector<model::ModelObject>(const model::InteriorPartitionSurface*)>>(),
DataSource(allInteriorPartitionSurfaces, true));
} else if (field == CONVERTTOINTERNALMASS) {
// We add the "Apply Selected" button to this column by passing 3rd arg, t_showColumnButton=true
addCheckBoxColumn(Heading(QString(CONVERTTOINTERNALMASS), true, true), std::string("Check to enable convert to InternalMass."),
NullAdapter(&model::InteriorPartitionSurface::converttoInternalMass),
NullAdapter(&model::InteriorPartitionSurface::setConverttoInternalMass), DataSource(allInteriorPartitionSurfaces, true));
} else if (field == SURFACEAREA) {
std::function<bool(model::InteriorPartitionSurface*, double)> setter(
[](model::InteriorPartitionSurface* t_interiorPartitionSurface, double t_arg) {
return t_interiorPartitionSurface->setSurfaceArea(t_arg);
});
addValueEditColumn(Heading(QString(SURFACEAREA)),
CastNullAdapter<model::InteriorPartitionSurface>(&model::InteriorPartitionSurface::surfaceArea), setter
// boost::optional<std::function<void(model::ModelObject *)>>(),
// boost::optional<std::function<bool(model::ModelObject *)>>()//,
// DataSource(
// allInteriorPartitionSurfaces,
// true
// )
);
//boost::optional<double> surfaceArea() const; // TODO this optional is causing troubles
//bool setSurfaceArea(boost::optional<double> surfaceArea);
//bool setSurfaceArea(double surfaceArea);
//void resetSurfaceArea();
} else if (field == DAYLIGHTINGSHELFNAME) {
//boost::optional<DaylightingDeviceShelf> daylightingDeviceShelf() const;
} else {
// unhandled
OS_ASSERT(false);
}
}
}
}
QString SpacesInteriorPartitionsGridController::getColor(const model::ModelObject& modelObject) {
QColor defaultColor(Qt::lightGray);
return defaultColor.name();
}
void SpacesInteriorPartitionsGridController::checkSelectedFields() {
if (!this->hasHorizontalHeader()) {
return;
}
OSGridController::checkSelectedFields();
}
void SpacesInteriorPartitionsGridController::onItemDropped(const OSItemId& itemId) {}
void SpacesInteriorPartitionsGridController::refreshModelObjects() {
auto spaces = model().getConcreteModelObjects<model::Space>();
std::sort(spaces.begin(), spaces.end(), openstudio::WorkspaceObjectNameLess());
setModelObjects(subsetCastVector<model::ModelObject>(spaces));
}
} // namespace openstudio