-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCommandManager.rb
808 lines (635 loc) · 28.9 KB
/
CommandManager.rb
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
########################################################################################################################
# OpenStudio(R), Copyright (c) OpenStudio Coalition and other contributors.
# See also https://openstudiocoalition.org/about/software_license/
########################################################################################################################
require("openstudio/lib/dialogs/PreferencesDialog")
module OpenStudio
class CommandManager
def initialize
# This is an unsual class; it is all methods, no data.
# Should this just be a Mixin? or module?
end
# this method starts a new OpenStudio Model from the minimal template with no user input
def new_openstudio
if (prompt_to_continue_open)
# load minimal template
Plugin.model_manager.open_openstudio(Plugin.minimal_template_path, Sketchup.active_model, false, false)
end
end
# this method starts a new OpenStudio Model from the empty template and then requests user input from a wizard
def new_openstudio_from_wizard
if (prompt_to_continue_open)
# load empty model
Plugin.model_manager.open_openstudio(Plugin.empty_template_path, Sketchup.active_model, false, false)
# DLM: this is causing a crash on Mac
if (Plugin.platform == Platform_Windows)
# run user script in future process so SketchUp entities are made for each color
proc = Proc.new {
# run on demand user script on new file
if Plugin.user_script_runner.run_user_script("Space Type and Construction Set Wizard")
UI.messagebox("Run the \"Space Type and Construction Set Wizard\" user script under \"On Demand Template Generators\" to add additional space types or construction sets.", MB_OK)
else
# user cancelled or measure fails open the minimal template instead
# warn user that they have an empty model
UI.messagebox("Model is currently empty. Run the \"Space Type and Construction Set Wizard\" user script under \"On Demand Template Generators\" to add additional space types or construction sets.", MB_OK)
end
}
Plugin.add_event( proc )
else
UI.messagebox("Model is currently empty. Run the \"Space Type and Construction Set Wizard\" user script under \"On Demand Template Generators\" to add additional space types or construction sets.", MB_OK)
end
end
end
def open_openstudio
result = false
if (prompt_to_continue_open)
openstudio_dir = Plugin.read_pref("Last OpenStudio Dir")
if Plugin.model_manager.model_interface
openstudio_dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Open OpenStudio Model File", openstudio_dir, "*.osm")) # bug in SU7 prevents file filters from working
success = Plugin.model_manager.open_openstudio(path, Sketchup.active_model)
if success
# Save the dir so we can start here next time
Plugin.write_pref("Last OpenStudio Dir", File.dirname(path))
else
UI.messagebox("Failed to open #{path}")
end
end
end
return(result)
end
def save_openstudio
result = nil
path = Plugin.model_manager.model_interface.openstudio_path
if (path.nil?)
result = save_openstudio_as
else
# check if writable?
result = Plugin.model_manager.model_interface.export_openstudio(path)
if not result
UI.messagebox("Failed to save OpenStudio Model to '#{path}'")
end
end
return result
end
def save_openstudio_as
result = false
if (path = OpenStudio.save_panel("Save OpenStudio Model", Plugin.model_manager.model_interface.openstudio_dir, Plugin.model_manager.model_interface.openstudio_name))
extension = OpenStudio::toString(OpenStudio::Path.new(path).extension)
stem = OpenStudio::toString(OpenStudio::Path.new(path).stem)
if extension.empty?
path = path + '.osm'
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return save_openstudio_as
end
end
elsif extension != '.osm'
path = OpenStudio::Path.new(path).replace_extension("osm").to_s
new_name = OpenStudio::toString(OpenStudio::Path.new(path).filename)
result = UI.messagebox("File name must have .osm extension. Do you want to rename your file to #{new_name}?",MB_YESNO)
if result == 6 # YES
# save file
else
return save_openstudio_as
end
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return save_openstudio_as
end
end
end
# store copy for restore
old_path = Plugin.model_manager.model_interface.openstudio_path
# do save
result = Plugin.model_manager.model_interface.export_openstudio(path)
if result
# Save the dir so we can start here next time
Plugin.write_pref("Last OpenStudio Dir", File.dirname(path))
# set path again to establish path watcher as file now exists
Plugin.model_manager.model_interface.openstudio_path = path
else
UI.messagebox("Failed to save OpenStudio Model to '#{path}'")
# will create a new path watcher for old path
Plugin.model_manager.model_interface.openstudio_path = old_path
end
end
return result
end
def import_openstudio
if (prompt_to_continue_import("OpenStudio Model"))
openstudio_dir = Plugin.read_pref("Last OpenStudio Import Dir")
if not openstudio_dir
openstudio_dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import OpenStudio Model", openstudio_dir, "*.osm")) # bug in SU7 prevents file filters from working
success = Plugin.model_manager.open_openstudio(path, Sketchup.active_model, false, true)
if success
# Save the dir so we can start here next time
Plugin.write_pref("Last OpenStudio Import Dir", File.dirname(path))
else
UI.messagebox("Failed to import #{path}.")
end
end
end
end
def import_constructions
dir = Plugin.read_pref("Last Constructions Import Dir")
if not dir
dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import Constructions", dir, "*.osm")) # bug in SU7 prevents file filters from working
# Save the dir so we can start here next time
Plugin.write_pref("Last Constructions Import Dir", File.dirname(path))
success = false
openstudio_model = Plugin.model_manager.model_from_openstudio_path(path)
if openstudio_model
Plugin.model_manager.model_interface.import_constructions(openstudio_model)
success = true
end
if not success
UI.messagebox("Failed to import #{path}")
end
end
end
def import_schedules
dir = Plugin.read_pref("Last Schedules Import Dir")
if not dir
dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import Schedules", dir, "*.osm")) # bug in SU7 prevents file filters from working
# Save the dir so we can start here next time
Plugin.write_pref("Last Schedules Import Dir", File.dirname(path))
success = false
openstudio_model = Plugin.model_manager.model_from_openstudio_path(path)
if openstudio_model
Plugin.model_manager.model_interface.import_schedules(openstudio_model)
success = true
end
if not success
UI.messagebox("Failed to import #{path}")
end
end
end
def import_space_types
dir = Plugin.read_pref("Last Space Types Import Dir")
if not dir
dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import Space Types", dir, "*.osm")) # bug in SU7 prevents file filters from working
# Save the dir so we can start here next time
Plugin.write_pref("Last Space Types Import Dir", File.dirname(path))
success = false
openstudio_model = Plugin.model_manager.model_from_openstudio_path(path)
if openstudio_model
Plugin.model_manager.model_interface.import_space_types(openstudio_model)
success = true
end
if not success
UI.messagebox("Failed to import #{path}")
end
end
end
def import_idf
if (prompt_to_continue_import("EnergyPlus Idf"))
idf_dir = Plugin.read_pref("Last Idf Import Dir")
if not idf_dir
idf_dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import EnergyPlus Idf", idf_dir, "*.idf")) # bug in SU7 prevents file filters from working
success = false
workspace = Plugin.model_manager.workspace_from_idf_path(path)
if workspace
openstudio_model, errors, warnings, untranslated_idf_objects = Plugin.model_manager.model_from_workspace(workspace)
Plugin.model_manager.attach_openstudio_model(openstudio_model, Sketchup.active_model, nil, false, true, errors, warnings, untranslated_idf_objects)
success = true
end
if success
# Save the dir so we can start here next time
Plugin.write_pref("Last Idf Import Dir", File.dirname(path))
else
UI.messagebox("Failed to import #{path}. If this is an older EnergyPlus Idf please upgrade to version #{OpenStudio::energyPlusVersion} using the EnergyPlus transition program.")
end
end
end
end
def import_idf_constructions
dir = Plugin.read_pref("Last Idf Constructions Import Dir")
if not dir
dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import EnergyPlus Idf Constructions", dir, "*.idf; *.imf")) # bug in SU7 prevents file filters from working
# Save the dir so we can start here next time
Plugin.write_pref("Last Idf Constructions Import Dir", File.dirname(path))
success = false
workspace = Plugin.model_manager.workspace_from_idf_path(path)
if workspace
Plugin.model_manager.model_interface.import_idf_constructions(workspace)
success = true
end
if not success
UI.messagebox("Failed to import #{path}")
end
end
end
def import_idf_schedules
dir = Plugin.read_pref("Last Idf Schedules Import Dir")
if not dir
dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import EnergyPlus Idf Schedules", dir, "*.idf; *.imf")) # bug in SU7 prevents file filters from working
# Save the dir so we can start here next time
Plugin.write_pref("Last Idf Schedules Import Dir", File.dirname(path))
success = false
workspace = Plugin.model_manager.workspace_from_idf_path(path)
if workspace
Plugin.model_manager.model_interface.import_idf_schedules(workspace)
success = true
end
if not success
UI.messagebox("Failed to import #{path}")
end
end
end
def import_gbxml
if (prompt_to_continue_import("gbXML Model"))
gbxml_dir = Plugin.read_pref("Last gbXML Import Dir")
if not gbxml_dir
gbxml_dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = OpenStudio.open_panel("Import gbXML Model", gbxml_dir, "*.xml")) # bug in SU7 prevents file filters from working
success = false
openstudio_model, errors, warnings = Plugin.model_manager.model_from_gbXML_path(path)
if openstudio_model
Plugin.model_manager.attach_openstudio_model(openstudio_model, Sketchup.active_model, nil, false, true, errors, warnings)
success = true
end
if success
# Save the dir so we can start here next time
Plugin.write_pref("Last gbXML Import Dir", File.dirname(path))
else
message = "Failed to import gbXML file at #{path}.\n\n"
errors.each {|error| message += "Error: #{error.logMessage}\n\n"}
warnings.each {|warning| message += "Warning: #{warning.logMessage}\n\n"}
UI.messagebox(message, MB_MULTILINE)
end
end
end
end
def import_sdd
if (prompt_to_continue_import("SDD Sim XML Model"))
sdd_dir = Plugin.read_pref("Last SDD Import Dir")
if not sdd_dir
sdd_dir = Plugin.model_manager.model_interface.openstudio_dir
end
if (path = UI.open_panel("Import SDD Sim XML Model", sdd_dir, "*.xml")) # bug in SU7 prevents file filters from working
success = false
openstudio_model, errors, warnings = Plugin.model_manager.model_from_sdd_path(path)
if openstudio_model
Plugin.model_manager.attach_openstudio_model(openstudio_model, Sketchup.active_model, nil, false, true, errors, warnings)
success = true
end
if success
# Save the dir so we can start here next time
Plugin.write_pref("Last SDD Import Dir", File.dirname(path))
else
message = "Failed to import SDD Sim XML file at #{path}. "
message = "Note that OpenStudio only imports SDD Sim XML, it cannot import SDD Input XML.\n\n"
errors.each {|error| message += "Error: #{error.logMessage}\n\n"}
warnings.each {|warning| message += "Warning: #{warning.logMessage}\n\n"}
UI.messagebox(message, MB_MULTILINE)
end
end
end
end
def export_openstudio
if (path = OpenStudio.save_panel("Export OpenStudio Model", Plugin.model_manager.model_interface.openstudio_dir, Plugin.model_manager.model_interface.openstudio_name))
extension = OpenStudio::toString(OpenStudio::Path.new(path).extension)
stem = OpenStudio::toString(OpenStudio::Path.new(path).stem)
if extension.empty?
path = path + '.osm'
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_openstudio
end
end
elsif extension != '.osm'
path = OpenStudio::Path.new(path).replace_extension("osm").to_s
new_name = OpenStudio::toString(OpenStudio::Path.new(path).filename)
result = UI.messagebox("File name must have .osm extension. Do you want to rename your file to #{new_name}?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_openstudio
end
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_openstudio
end
end
end
result = Plugin.model_manager.model_interface.export_openstudio(path)
if not result
UI.messagebox("Failed to export OpenStudio Model to #{path}")
end
end
end
def export_untranslated_idf
if (path = OpenStudio.save_panel("Export Untranslated EnergyPlus Idf", Plugin.model_manager.model_interface.openstudio_dir, Plugin.model_manager.model_interface.openstudio_name.gsub(/\.osm$/, "-Untranslated.idf")))
extension = OpenStudio::toString(OpenStudio::Path.new(path).extension)
stem = OpenStudio::toString(OpenStudio::Path.new(path).stem)
if extension.empty?
path = path + '.idf'
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_untranslated_idf
end
end
elsif extension != '.idf'
path = OpenStudio::Path.new(path).replace_extension("idf").to_s
new_name = OpenStudio::toString(OpenStudio::Path.new(path).filename)
result = UI.messagebox("File name must have .idf extension. Do you want to rename your file to #{new_name}?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_untranslated_idf
end
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_untranslated_idf
end
end
end
result = Plugin.model_manager.model_interface.export_untranslated_idf(path)
if not result
UI.messagebox("Failed to export Untranslated EnergyPlus Idf to #{path}")
end
end
end
def export_idf
if Plugin.read_pref('Warn on Idf Export')
# YESNO messagebox, user can cancel at save_panel
result = UI.messagebox("Translation of OpenStudio Model to EnergyPlus Idf may result in loss of information for unsupported object types. Choose Yes to ignore this warning from now on or No to continue showing this warning.", MB_YESNO)
if result == 6 # YES
Plugin.write_pref('Warn on Idf Export', false)
end
end
if (path = OpenStudio.save_panel("Export EnergyPlus Idf", Plugin.model_manager.model_interface.openstudio_dir, Plugin.model_manager.model_interface.openstudio_name.gsub(/\.osm$/, ".idf")))
extension = OpenStudio::toString(OpenStudio::Path.new(path).extension)
stem = OpenStudio::toString(OpenStudio::Path.new(path).stem)
if extension.empty?
path = path + '.idf'
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_idf
end
end
elsif extension != '.idf'
path = OpenStudio::Path.new(path).replace_extension("idf").to_s
new_name = OpenStudio::toString(OpenStudio::Path.new(path).filename)
result = UI.messagebox("File name must have .idf extension. Do you want to rename your file to #{new_name}?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_idf
end
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_idf
end
end
end
result = Plugin.model_manager.model_interface.export_idf(path)
if not result
UI.messagebox("Failed to export EnergyPlus Idf to #{path}")
end
end
end
def export_gbxml
if Plugin.read_pref('Warn on gbXML Export')
# YESNO messagebox, user can cancel at save_panel
result = UI.messagebox("Translation of OpenStudio Model to gbXML may result in loss of information for unsupported object types. Choose Yes to ignore this warning from now on or No to continue showing this warning.", MB_YESNO)
if result == 6 # YES
Plugin.write_pref('Warn on gbXML Export', false)
end
end
if (path = OpenStudio.save_panel("Export gbXML Model", Plugin.model_manager.model_interface.openstudio_dir, Plugin.model_manager.model_interface.openstudio_name.gsub(/\.osm$/, ".xml")))
extension = OpenStudio::toString(OpenStudio::Path.new(path).extension)
stem = OpenStudio::toString(OpenStudio::Path.new(path).stem)
if extension.empty?
path = path + '.xml'
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_gbxml
end
end
elsif extension != '.xml'
path = OpenStudio::Path.new(path).replace_extension("xml").to_s
new_name = OpenStudio::toString(OpenStudio::Path.new(path).filename)
result = UI.messagebox("File name must have .xml extension. Do you want to rename your file to #{new_name}?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_gbxml
end
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_gbxml
end
end
end
result = Plugin.model_manager.model_interface.export_gbxml(path)
if not result
UI.messagebox("Failed to export gbXML model to #{path}")
end
end
end
def export_sdd
if Plugin.read_pref('Warn on SDD Export')
# YESNO messagebox, user can cancel at save_panel
result = UI.messagebox("Translation of OpenStudio Model to SDD Input XML may result in loss of information for unsupported object types. Choose Yes to ignore this warning from now on or No to continue showing this warning.", MB_YESNO)
if result == 6 # YES
Plugin.write_pref('Warn on SDD Export', false)
end
end
if (path = OpenStudio.save_panel("Export SDD Input XML Model", Plugin.model_manager.model_interface.openstudio_dir, Plugin.model_manager.model_interface.openstudio_name.gsub(/\.osm$/, ".xml")))
extension = OpenStudio::toString(OpenStudio::Path.new(path).extension)
stem = OpenStudio::toString(OpenStudio::Path.new(path).stem)
if extension.empty?
path = path + '.xml'
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_sdd
end
end
elsif extension != '.xml'
path = OpenStudio::Path.new(path).replace_extension("xml").to_s
new_name = OpenStudio::toString(OpenStudio::Path.new(path).filename)
result = UI.messagebox("File name must have .xml extension. Do you want to rename your file to #{new_name}?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_sdd
end
# see if file exists and prompt user if they want to overwrite it
# only needed because not caught by sketchup save dialog
if File.exist?(path)
result = UI.messagebox("File named " + path + " exists. Do you want to overwrite it?",MB_YESNO)
if result == 6 # YES
# save file
else
return export_sdd
end
end
end
result = Plugin.model_manager.model_interface.export_sdd(path)
if not result
UI.messagebox("Failed to export SDD Input XML model to #{path}")
end
end
end
def check_site(source_name, new_name, new_lat, new_lon, new_time, new_elev)
# if we already have site set check distance between site and weather file
if site = Plugin.model_manager.model_interface.site
site_name = site.model_object.name.get
site_lat = site.model_object.latitude
site_lon = site.model_object.longitude
site_elev = site.model_object.elevation
distance = OpenStudio::getDistanceLatLon(new_lat, new_lon, site_lat, site_lon) / 1000.0 # km
delta_elev = (new_elev - site_elev).abs
if distance > 50 # 50 km
result = UI.messagebox("Distance between #{source_name} location and site location is #{distance.round} km. Do you want to set site location to #{source_name} location?", MB_YESNOCANCEL)
if result == 6 # Yes
# set the model object fields
site.model_object.setName(new_name.gsub(',', '-'))
site.model_object.setLatitude(new_lat)
site.model_object.setLongitude(new_lon)
site.model_object.setTimeZone(new_time)
site.model_object.setElevation(new_elev)
# delta_elev is now 0
delta_elev = 0
elsif result == 2 # Cancel
# no-op
return
end
end
if delta_elev > 200 # 200 m
result = UI.messagebox("Distance between #{source_name} elevation and site elevation is #{delta_elev.round} m. Do you want to set site location to #{source_name} location?", MB_YESNOCANCEL)
if result == 6 # Yes
# set the model object fields
site.model_object.setName(new_name.gsub(',', '-'))
site.model_object.setLatitude(new_lat)
site.model_object.setLongitude(new_lon)
site.model_object.setTimeZone(new_time)
site.model_object.setElevation(new_elev)
elsif result == 2 # Cancel
# no-op
return
end
end
else
# no site offer to set it
result = UI.messagebox("This model does not yet specify a site, do you want to set it to the #{source_name} location", MB_YESNO)
if result == 6 # Yes
# create the site
site = Site.new
site.create_entity
site.create_model_object
site.update_model_object
site.add_watcher
site.add_observers
# set the model object fields
site.model_object.setName(new_name.gsub(',', '-'))
site.model_object.setLatitude(new_lat)
site.model_object.setLongitude(new_lon)
site.model_object.setTimeZone(new_time)
site.model_object.setElevation(new_elev)
end
end
end
def prompt_to_continue_open
result = false
if Plugin.model_manager.model_interface and Plugin.model_manager.model_interface.openstudio_model
button = UI.messagebox("Would you like to save your current OpenStudio Model? " , MB_YESNOCANCEL )
if (button == 6) # YES
result = save_openstudio
elsif (button == 7) # NO
result = true
end
else
result = true
end
return result
end
def prompt_to_continue_import(name)
result = false
if Plugin.model_manager.model_interface
button = UI.messagebox("Would you like to save your current OpenStudio Model before importing an #{name}? " , MB_YESNOCANCEL )
if (button == 6) # YES
result = save_openstudio
elsif (button == 7) # NO
result = true
end
else
result = true
end
return result
end
end
end