13
13
#include " OSItemSelectorButtons.hpp"
14
14
#include " SchedulesTabController.hpp"
15
15
16
+ #include " ../shared_gui_components/OSComboBox.hpp"
16
17
#include " ../shared_gui_components/OSGridView.hpp"
18
+ #include " ../shared_gui_components/OSQuantityEdit.hpp"
19
+ #include " ../shared_gui_components/OSSwitch.hpp"
17
20
18
21
#include " ../openstudio_app/OpenStudioApp.hpp"
19
22
70
73
#include < QCoreApplication>
71
74
#include < QObject>
72
75
#include < QPushButton>
76
+ #include < span>
73
77
74
78
static constexpr auto NAME (" Name: " );
75
79
static constexpr auto LATITUDE (" Latitude: " );
@@ -174,6 +178,11 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
174
178
weatherFileGridLayout->setContentsMargins (7 , 3 , 7 , 7 );
175
179
weatherFileGridLayout->setSpacing (7 );
176
180
181
+ // ***** Measure Tags GridLayout *****
182
+ auto * siteInfoGridLayout = new QGridLayout ();
183
+ siteInfoGridLayout->setContentsMargins (7 , 7 , 7 , 7 );
184
+ siteInfoGridLayout->setSpacing (7 );
185
+
177
186
// ***** Measure Tags GridLayout *****
178
187
auto * measureTagsGridLayout = new QGridLayout ();
179
188
measureTagsGridLayout->setContentsMargins (7 , 7 , 7 , 7 );
@@ -236,16 +245,13 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
236
245
237
246
weatherFileGridLayout->addLayout (hLayout, i++, 0 );
238
247
239
- m_latitudeLbl = new QLabel (tr (" Latitude: " ));
248
+ m_latitudeLbl = new QLabel (tr (LATITUDE ));
240
249
weatherFileGridLayout->addWidget (m_latitudeLbl, i++, 0 );
241
250
242
- m_longitudeLbl = new QLabel (tr (" Longitude: " ));
251
+ m_longitudeLbl = new QLabel (tr (LONGITUDE ));
243
252
weatherFileGridLayout->addWidget (m_longitudeLbl, i++, 0 );
244
253
245
- m_elevationLbl = new QLabel (tr (" Elevation: " ));
246
- weatherFileGridLayout->addWidget (m_elevationLbl, i++, 0 );
247
-
248
- m_timeZoneLbl = new QLabel (tr (" Time Zone: " ));
254
+ m_timeZoneLbl = new QLabel (tr (TIME_ZONE));
249
255
weatherFileGridLayout->addWidget (m_timeZoneLbl, i++, 0 );
250
256
251
257
// ***** Weather File Download Location *****
@@ -258,6 +264,91 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
258
264
leftVLayout->addLayout (weatherFileGridLayout);
259
265
leftVLayout->addStretch ();
260
266
267
+ // Site Information
268
+ {
269
+ label = new QLabel (tr (" Site Information:" ));
270
+ label->setObjectName (" H2" );
271
+ leftVLayout->addWidget (label);
272
+
273
+ i = 0 ;
274
+
275
+ {
276
+ label = new QLabel (tr (" Keep Site Location Information" ));
277
+ label->setToolTip (tr (" If enabled, this will write the Site:Location object that will keep the Elevation change for example." ));
278
+
279
+ m_keepSiteLocationInfo = new OSSwitch2 ();
280
+
281
+ m_keepSiteLocationInfo->bind (*m_site, BoolGetter ([this ] { return m_site->keepSiteLocationInformation (); }),
282
+ boost::optional<BoolSetter>([this ](bool b) {
283
+ bool result = m_site->setKeepSiteLocationInformation (b);
284
+
285
+ if (result) {
286
+
287
+ // force the style to update
288
+ m_elevation->clearCachedText ();
289
+
290
+ if (b) {
291
+ // set elevation if turning on
292
+ if (m_site->isElevationDefaulted ()) {
293
+ m_site->setElevation (m_weatherFileElevation);
294
+ } else {
295
+ m_site->setElevation (m_site->elevation ());
296
+ }
297
+ } else {
298
+ // reset elevation if turning off
299
+ if (std::abs (m_weatherFileElevation) > 0.01 ) {
300
+ m_site->setElevation (m_weatherFileElevation);
301
+ } else {
302
+ m_site->resetElevation ();
303
+ }
304
+ }
305
+ }
306
+ return result;
307
+ }),
308
+ boost::optional<NoFailAction>([this ] { m_site->resetKeepSiteLocationInformation (); }),
309
+ boost::optional<BasicQuery>([this ] { return m_site->isKeepSiteLocationInformationDefaulted (); }));
310
+
311
+ siteInfoGridLayout->addWidget (label, i, 0 );
312
+ siteInfoGridLayout->addWidget (m_keepSiteLocationInfo, i++, 1 );
313
+ }
314
+ {
315
+ label = new QLabel (tr (ELEVATION));
316
+ label->setToolTip (tr (" Elevation affects the wind speed at the site, and is defaulted to the Weather File's elevation" ));
317
+
318
+ m_elevation = new OSQuantityEdit2 (" m" , " m" , " ft" , m_isIP);
319
+ connect (this , &LocationView::toggleUnitsClicked, m_elevation, &OSQuantityEdit2::onUnitSystemChange);
320
+
321
+ // Bind is delayed until after update() is called, so that the weatherFileElevation is set correctly.
322
+
323
+ m_elevation->setFixedWidth (200 );
324
+
325
+ siteInfoGridLayout->addWidget (label, i, 0 );
326
+ siteInfoGridLayout->addWidget (m_elevation, i++, 1 );
327
+ }
328
+ // Terrain
329
+ {
330
+ label = new QLabel (tr (" Terrain" ));
331
+ label->setToolTip (tr (" Terrain affects the wind speed at the site." ));
332
+
333
+ m_terrain = new OSComboBox2 ();
334
+ m_terrain->bind <std::string>(*m_site, static_cast <std::string (*)(const std::string&)>(&openstudio::toString), &model::Site::validTerrainValues,
335
+ std::bind (&model::Site::terrain, m_site.get_ptr ()),
336
+ std::bind (&model::Site::setTerrain, m_site.get_ptr (), std::placeholders::_1),
337
+ boost::optional<NoFailAction>(std::bind (&model::Site::resetTerrain, m_site.get_ptr ())),
338
+ boost::optional<BasicQuery>(std::bind (&model::Site::isTerrainDefaulted, m_site.get_ptr ())));
339
+
340
+ m_terrain->setFixedWidth (200 );
341
+
342
+ siteInfoGridLayout->addWidget (label, i, 0 );
343
+ siteInfoGridLayout->addWidget (m_terrain, i++, 1 );
344
+ }
345
+
346
+ // ***** Site Info GridLayout *****
347
+ siteInfoGridLayout->setColumnStretch (++i, 10 );
348
+ leftVLayout->addLayout (siteInfoGridLayout);
349
+ leftVLayout->addStretch ();
350
+ }
351
+
261
352
// ***** Climate Zones *****
262
353
label = new QLabel (tr (" Measure Tags (Optional):" ));
263
354
label->setObjectName (" H2" );
@@ -400,11 +491,37 @@ LocationView::LocationView(bool isIP, const model::Model& model, const QString&
400
491
connect (m_itemSelectorButtons, &OSItemSelectorButtons::purgeClicked, m_designDaysGridView, &DesignDayGridView::onPurgeClicked);
401
492
402
493
update ();
494
+ {
495
+ m_elevation->bind (m_isIP, *m_site, DoubleGetter ([this ] { return m_site->elevation (); }), boost::optional<DoubleSetter>([this ](double d) {
496
+ // turn keep site info on
497
+ m_site->setKeepSiteLocationInformation (true );
498
+ return m_site->setElevation (d);
499
+ }),
500
+ boost::optional<NoFailAction>([this ] {
501
+ // turn keep site info off
502
+ m_site->setKeepSiteLocationInformation (false );
503
+
504
+ // force the style to update
505
+ m_elevation->clearCachedText ();
506
+
507
+ if (std::abs (m_weatherFileElevation) > 0.01 ) {
508
+ m_site->setElevation (m_weatherFileElevation);
509
+ } else {
510
+ m_site->resetElevation ();
511
+ }
512
+ }),
513
+ boost::none, // autosize
514
+ boost::none, // autocalculate
515
+ boost::optional<BasicQuery>([this ] { //
516
+ return (m_site->isElevationDefaulted () || !m_site->keepSiteLocationInformation ());
517
+ }));
518
+ }
403
519
404
520
onSelectItem ();
405
521
}
406
522
407
523
LocationView::~LocationView () {
524
+ // m_terrain->unbind(); // NOTE: I don't think this is necessary
408
525
saveQSettings ();
409
526
}
410
527
@@ -496,6 +613,7 @@ void LocationView::update() {
496
613
497
614
if (fileExists) {
498
615
m_weatherFileBtn->setText (tr (" Change Weather File" ));
616
+ m_weatherFileElevation = weatherFile->elevation ();
499
617
setSiteInfo ();
500
618
} else {
501
619
m_weatherFileBtn->setText (tr (" Set Weather File" ));
@@ -526,11 +644,6 @@ void LocationView::setSiteInfo() {
526
644
info += temp;
527
645
m_longitudeLbl->setText (info);
528
646
529
- info = tr (ELEVATION);
530
- temp.setNum (m_site->elevation ());
531
- info += temp;
532
- m_elevationLbl->setText (info);
533
-
534
647
info = tr (TIME_ZONE);
535
648
temp.setNum (m_site->timeZone ());
536
649
info += temp;
@@ -544,9 +657,9 @@ void LocationView::clearSiteInfo() {
544
657
545
658
m_longitudeLbl->setText (tr (LONGITUDE));
546
659
547
- m_elevationLbl->setText (tr (ELEVATION));
548
-
549
660
m_timeZoneLbl->setText (tr (TIME_ZONE));
661
+
662
+ m_weatherFileElevation = 0.0 ;
550
663
}
551
664
552
665
// ***** SLOTS *****
@@ -637,7 +750,10 @@ void LocationView::onWeatherFileBtnClicked() {
637
750
m_site->setName (weatherFile->city ());
638
751
m_site->setLatitude (weatherFile->latitude ());
639
752
m_site->setLongitude (weatherFile->longitude ());
753
+ m_weatherFileElevation = weatherFile->elevation ();
754
+ m_site->setKeepSiteLocationInformation (false );
640
755
m_site->setElevation (weatherFile->elevation ());
756
+ m_site->resetTerrain ();
641
757
m_site->setTimeZone (weatherFile->timeZone ());
642
758
643
759
m_lastEpwPathOpened = QFileInfo (fileName).absoluteFilePath ();
0 commit comments