Sun Position: remove show_daylight_savings preference
[blender-addons.git] / sun_position / ui_sun.py
blobd0e8b045fed323ebed4266b83d7354c3d0d8d10f
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.types import Operator, Menu
5 from bl_operators.presets import AddPresetBase
6 from bl_ui.utils import PresetPanel
7 import os
8 from math import degrees
10 from .sun_calc import format_lat_long, format_time, format_hms, sun
13 # -------------------------------------------------------------------
14 # Choice list of places, month and day at 12:00 noon
15 # -------------------------------------------------------------------
18 class SUNPOS_MT_Presets(PresetPanel, bpy.types.Panel):
19 bl_label = "Sun Position Presets"
20 preset_subdir = "operator/sun_position"
21 preset_operator = "script.execute_preset"
22 preset_add_operator = "world.sunpos_add_preset"
25 class SUNPOS_OT_AddPreset(AddPresetBase, Operator):
26 '''Add Sun Position preset'''
27 bl_idname = "world.sunpos_add_preset"
28 bl_label = "Add Sun Position preset"
29 preset_menu = "SUNPOS_MT_Presets"
31 # variable used for all preset values
32 preset_defines = [
33 "sun_props = bpy.context.scene.sun_pos_properties"
36 # properties to store in the preset
37 preset_values = [
38 "sun_props.day",
39 "sun_props.month",
40 "sun_props.time",
41 "sun_props.year",
42 "sun_props.UTC_zone",
43 "sun_props.use_daylight_savings",
44 "sun_props.latitude",
45 "sun_props.longitude",
48 # where to store the preset
49 preset_subdir = "operator/sun_position"
52 # -------------------------------------------------------------------
54 # Draw the Sun Panel, sliders, et. al.
56 # -------------------------------------------------------------------
58 class SUNPOS_PT_Panel(bpy.types.Panel):
59 bl_space_type = "PROPERTIES"
60 bl_region_type = "WINDOW"
61 bl_context = "world"
62 bl_label = "Sun Position"
63 bl_options = {'DEFAULT_CLOSED'}
65 def draw_header_preset(self, _context):
66 SUNPOS_MT_Presets.draw_panel_header(self.layout)
68 def draw(self, context):
69 sun_props = context.scene.sun_pos_properties
70 layout = self.layout
71 layout.use_property_split = True
72 layout.use_property_decorate = False
74 layout.prop(sun_props, "usage_mode", expand=True)
75 layout.separator()
77 if sun_props.usage_mode == "HDR":
78 self.draw_environment_mode_panel(context)
79 else:
80 self.draw_normal_mode_panel(context)
82 def draw_environment_mode_panel(self, context):
83 sun_props = context.scene.sun_pos_properties
84 layout = self.layout
86 col = layout.column(align=True)
87 col.prop_search(sun_props, "sun_object",
88 context.view_layer, "objects")
89 if context.scene.world is not None:
90 if context.scene.world.node_tree is not None:
91 col.prop_search(sun_props, "hdr_texture",
92 context.scene.world.node_tree, "nodes")
93 else:
94 col.label(text="Please activate Use Nodes in the World panel.",
95 icon="ERROR")
96 else:
97 col.label(text="Please select World in the World panel.",
98 icon="ERROR")
100 layout.use_property_decorate = True
102 col = layout.column(align=True)
103 col.prop(sun_props, "bind_to_sun", text="Bind Texture to Sun")
104 col.prop(sun_props, "hdr_azimuth")
105 row = col.row(align=True)
106 row.active = not sun_props.bind_to_sun
107 row.prop(sun_props, "hdr_elevation")
108 col.prop(sun_props, "sun_distance")
109 col.separator()
111 col = layout.column(align=True)
112 row = col.row(align=True)
113 row.enabled = not sun_props.bind_to_sun
114 row.operator("world.sunpos_show_hdr", icon='LIGHT_SUN')
116 def draw_normal_mode_panel(self, context):
117 sun_props = context.scene.sun_pos_properties
118 addon_prefs = context.preferences.addons[__package__].preferences
119 layout = self.layout
121 col = layout.column(align=True)
122 col.prop(sun_props, "sun_object")
123 col.separator()
125 col.prop(sun_props, "object_collection")
126 if sun_props.object_collection:
127 col.prop(sun_props, "object_collection_type")
128 if sun_props.object_collection_type == 'DIURNAL':
129 col.prop(sun_props, "time_spread")
130 col.separator()
132 if context.scene.world is not None:
133 if context.scene.world.node_tree is not None:
134 col.prop_search(sun_props, "sky_texture",
135 context.scene.world.node_tree, "nodes")
136 else:
137 col.label(text="Please activate Use Nodes in the World panel.",
138 icon="ERROR")
139 else:
140 col.label(text="Please select World in the World panel.",
141 icon="ERROR")
143 if addon_prefs.show_overlays:
144 col = layout.column(align=True, heading="Show")
145 col.prop(sun_props, "show_north", text="North")
146 col.prop(sun_props, "show_analemmas", text="Analemmas")
147 col.prop(sun_props, "show_surface", text="Surface")
149 if addon_prefs.show_refraction:
150 col = layout.column(align=True, heading="Use")
151 col.prop(sun_props, "use_refraction", text="Refraction")
154 class SUNPOS_PT_Location(bpy.types.Panel):
155 bl_space_type = "PROPERTIES"
156 bl_region_type = "WINDOW"
157 bl_context = "world"
158 bl_label = "Location"
159 bl_parent_id = "SUNPOS_PT_Panel"
161 @classmethod
162 def poll(self, context):
163 sun_props = context.scene.sun_pos_properties
164 return sun_props.usage_mode != "HDR"
166 def draw(self, context):
167 layout = self.layout
168 layout.use_property_split = True
170 sun_props = context.scene.sun_pos_properties
171 addon_prefs = context.preferences.addons[__package__].preferences
173 col = layout.column(align=True)
174 col.prop(sun_props, "coordinates", icon='URL')
175 col.prop(sun_props, "latitude")
176 col.prop(sun_props, "longitude")
178 col.separator()
180 col = layout.column(align=True)
181 col.prop(sun_props, "north_offset", text="North Offset")
183 if addon_prefs.show_az_el:
184 col = layout.column(align=True)
185 col.prop(sun_props, "sun_elevation", text="Elevation")
186 col.prop(sun_props, "sun_azimuth", text="Azimuth")
187 col.separator()
189 col = layout.column()
190 col.prop(sun_props, "sun_distance")
191 col.separator()
194 class SUNPOS_PT_Time(bpy.types.Panel):
195 bl_space_type = "PROPERTIES"
196 bl_region_type = "WINDOW"
197 bl_context = "world"
198 bl_label = "Time"
199 bl_parent_id = "SUNPOS_PT_Panel"
201 @classmethod
202 def poll(self, context):
203 sun_props = context.scene.sun_pos_properties
204 return sun_props.usage_mode != "HDR"
206 def draw(self, context):
207 layout = self.layout
208 layout.use_property_split = True
210 sun_props = context.scene.sun_pos_properties
211 addon_prefs = context.preferences.addons[__package__].preferences
213 col = layout.column(align=True)
214 col.prop(sun_props, "use_day_of_year")
215 if sun_props.use_day_of_year:
216 col.prop(sun_props, "day_of_year")
217 else:
218 col.prop(sun_props, "day")
219 col.prop(sun_props, "month")
220 col.prop(sun_props, "year")
221 col.separator()
223 col = layout.column(align=True)
224 col.prop(sun_props, "time", text="Time", text_ctxt="Hour")
225 col.prop(sun_props, "UTC_zone")
226 col.prop(sun_props, "use_daylight_savings")
227 col.separator()
229 local_time = format_time(sun_props.time,
230 sun_props.use_daylight_savings,
231 sun_props.longitude)
232 utc_time = format_time(sun_props.time,
233 sun_props.use_daylight_savings,
234 sun_props.longitude,
235 sun_props.UTC_zone)
237 col = layout.column(align=True)
238 col.alignment = 'CENTER'
240 split = col.split(factor=0.5, align=True)
241 sub = split.column(align=True)
242 sub.alignment = 'RIGHT'
243 sub.label(text="Time Local:")
244 sub.label(text="UTC:")
246 sub = split.column(align=True)
247 sub.label(text=local_time)
248 sub.label(text=utc_time)
249 col.separator()
251 if addon_prefs.show_rise_set:
252 sunrise = format_hms(sun.sunrise)
253 sunset = format_hms(sun.sunset)
255 col = layout.column(align=True)
256 col.alignment = 'CENTER'
258 split = col.split(factor=0.5, align=True)
259 sub = split.column(align=True)
260 sub.alignment = 'RIGHT'
261 sub.label(text="Sunrise:")
262 sub.label(text="Sunset:")
264 sub = split.column(align=True)
265 sub.label(text=sunrise)
266 sub.label(text=sunset)
268 col.separator()