-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDialogManager.rb
313 lines (242 loc) · 9.78 KB
/
DialogManager.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
########################################################################################################################
# OpenStudio(R), Copyright (c) OpenStudio Coalition and other contributors.
# See also https://openstudiocoalition.org/about/software_license/
########################################################################################################################
require("set")
module OpenStudio
class DialogManager
attr_accessor :dialog_interfaces, :inspector_dialog
def initialize
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
@dialog_interfaces = Set.new
@inspector_dialog = PluginInspectorDialog.new
@inspector_dialog.hide
update_units
selection_changed
restore_state
end
def save_state
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
interface_names = @dialog_interfaces.collect { |interface| interface.class.to_s[12..-1] } # Clip the "OpenStudio::" part
Plugin.write_pref('Open Dialogs', interface_names.to_a.join(','))
Plugin.write_pref('Inspector Dialog Visible', @inspector_dialog.isVisible)
@inspector_dialog.saveState
end
def restore_state
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
interface_names = Plugin.read_pref('Open Dialogs').split(',')
interface_names.each do |interface_name|
proc = Proc.new do
begin
show(OpenStudio.const_get(interface_name))
rescue
# interface_name does not map to a current class
end
end
Plugin.add_event(proc)
end
inspector_dialog_visible = Plugin.read_pref('Inspector Dialog Visible')
if inspector_dialog_visible
@inspector_dialog.restoreState
@inspector_dialog.show
end
end
def active_interface(interface_class)
#Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
if interface_class == PluginInspectorDialog
return @inspector_dialog.isVisible
end
return(@dialog_interfaces.find { |interface| interface.is_a? interface_class })
end
def show(interface_class)
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
if (not interface = active_interface(interface_class))
interface = interface_class.new
@dialog_interfaces.add(interface)
end
interface.show
save_state
end
def validate(interface_class)
#Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
result = MF_GRAYED
if model_manager = Plugin.model_manager
if model_manager.model_interface
if (active_interface(interface_class))
result = MF_CHECKED
else
result = MF_UNCHECKED
end
end
end
return(result)
end
def update(interface_class)
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
if (interface = active_interface(interface_class))
interface.update
end
end
def update_all
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
@inspector_dialog.update
@dialog_interfaces.each { |interface| interface.update }
end
def units_system
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
return @units_system
end
def update_units
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
puts "current @units_system = #{@units_system}"
@units_system = Plugin.read_pref("Unit System")
puts "new @units_system = #{@units_system}"
if (@units_system == "IP")
@inspector_dialog.displayIP(true)
else
@inspector_dialog.displayIP(false)
end
end
def remove(interface)
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
@dialog_interfaces.delete(interface)
save_state
end
def close_all
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
save_state
@inspector_dialog.hide
@dialog_interfaces.each do |interface|
proc = Proc.new { interface.close }
Plugin.add_event( proc )
end
end
def selection_changed
Plugin.log(OpenStudio::Trace, "#{OpenStudio.current_method_name}")
was_dialog_enabled = @inspector_dialog.disable
# updates the model
@inspector_dialog.update
model_interface = Plugin.model_manager.model_interface
# drawing_interface may be changed if another object is displayed in the inspector
drawing_interface = model_interface.selection_interface.selected_drawing_interface
idd_object_type = nil
handles = nil
if drawing_interface
# default is to select the current model object
model_object = drawing_interface.model_object
idd_object_type = model_object.iddObject.type
handles = OpenStudio::UUIDVector.new
handles << model_object.handle
# modify idd_object_type amd handles based on render mode and render_defaults
rendering_mode = model_interface.materials_interface.rendering_mode
render_defaults = model_interface.materials_interface.render_defaults
if (rendering_mode == RenderWaiting)
# no-op
elsif (rendering_mode == RenderByClass)
# no-op
elsif (rendering_mode == RenderByDataValue)
# no-op
elsif (rendering_mode == RenderByBoundary)
# no-op
elsif (rendering_mode == RenderByLayer)
# no-op
elsif (rendering_mode == RenderBySurfaceNormal)
# no-op
elsif (rendering_mode == RenderByConstruction)
# select surface since there are no more construction objects in the inspector
elsif (rendering_mode == RenderBySpaceType)
space = nil
space_type = nil
if model_object.is_a?(OpenStudio::Model::Space)
space = model_object
elsif model_object.is_a?(OpenStudio::Model::PlanarSurface) or
model_object.is_a?(OpenStudio::Model::SpaceItem) or
model_object.is_a?(OpenStudio::Model::ShadingSurfaceGroup) or
model_object.is_a?(OpenStudio::Model::InteriorPartitionSurfaceGroup)
o_space = model_object.space
if not o_space.empty?
space = o_space.get
end
end
if space
if (not space.isSpaceTypeDefaulted) or render_defaults
space_type = space.spaceType
end
end
if space_type and (not space_type.empty?)
#drawing_interface = space_type.get.drawing_interface
drawing_interface = nil
idd_object_type = space_type.get.iddObject.type
handles = OpenStudio::UUIDVector.new
handles << space_type.get.handle
end
elsif (rendering_mode == RenderByThermalZone)
space = nil
thermal_zone = nil
if model_object.is_a?(OpenStudio::Model::Space)
space = model_object
elsif model_object.is_a?(OpenStudio::Model::PlanarSurface) or
model_object.is_a?(OpenStudio::Model::SpaceItem) or
model_object.is_a?(OpenStudio::Model::ShadingSurfaceGroup) or
model_object.is_a?(OpenStudio::Model::InteriorPartitionSurfaceGroup)
o_space = model_object.space
if not o_space.empty?
space = o_space.get
end
end
if space
thermal_zone = space.thermalZone
end
if thermal_zone and (not thermal_zone.empty?)
#drawing_interface = thermal_zone.get.drawing_interface
drawing_interface = nil
idd_object_type = thermal_zone.get.iddObject.type
handles = OpenStudio::UUIDVector.new
handles << thermal_zone.get.handle
end
elsif (rendering_mode == RenderByBuildingStory)
space = nil
building_story = nil
if model_object.is_a?(OpenStudio::Model::Space)
space = model_object
elsif model_object.is_a?(OpenStudio::Model::PlanarSurface) or
model_object.is_a?(OpenStudio::Model::SpaceItem) or
model_object.is_a?(OpenStudio::Model::ShadingSurfaceGroup) or
model_object.is_a?(OpenStudio::Model::InteriorPartitionSurfaceGroup)
o_space = model_object.space
if not o_space.empty?
space = o_space.get
end
end
if space
building_story = space.buildingStory
end
if building_story and (not building_story.empty?)
#drawing_interface = building_story.get.drawing_interface
drawing_interface = nil
idd_object_type = building_story.get.iddObject.type
handles = OpenStudio::UUIDVector.new
handles << building_story.get.handle
end
end
else
# select nothing
drawing_interface = nil
idd_object_type = nil
handles = OpenStudio::UUIDVector.new
end
# prevent watch from firing if inspector changes the object
watcher_enabled = drawing_interface.disable_watcher if drawing_interface
if idd_object_type
result = @inspector_dialog.setIddObjectType(idd_object_type)
Plugin.log(OpenStudio::Debug, "selection_changed: setting iddObjectType to #{idd_object_type}, result = #{result.to_s}")
end
if handles
result = @inspector_dialog.setSelectedObjectHandles(handles)
Plugin.log(OpenStudio::Debug, "selection_changed: setting setSelectedObjectHandles to #{handles.size.to_s}, result = #{result.to_s}")
end
drawing_interface.enable_watcher if watcher_enabled
@inspector_dialog.enable if was_dialog_enabled
end
end
end