Sun Position: remove show_daylight_savings preference
[blender-addons.git] / sun_position / properties.py
blob6355b520d829111fd225b85a8614d94b3dbf5155
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.types import AddonPreferences, PropertyGroup
5 from bpy.props import (StringProperty, EnumProperty, IntProperty,
6 FloatProperty, BoolProperty, PointerProperty)
7 from bpy.app.translations import pgettext_iface as iface_
10 from .sun_calc import format_lat_long, parse_position, sun, update_time, move_sun
11 from .draw import north_update, surface_update, analemmas_update
13 from math import pi
14 from datetime import datetime
15 TODAY = datetime.today()
17 ############################################################################
18 # Sun panel properties
19 ############################################################################
21 parse_success = True
24 def lat_long_update(self, context):
25 global parse_success
26 parse_success = True
27 sun_update(self, context)
30 def get_coordinates(self):
31 if parse_success:
32 return format_lat_long(self.latitude, self.longitude)
33 return iface_("ERROR: Could not parse coordinates")
36 def set_coordinates(self, value):
37 parsed_co = parse_position(value)
39 global parse_success
40 if parsed_co is not None and len(parsed_co) == 2:
41 latitude, longitude = parsed_co
42 self.latitude, self.longitude = latitude, longitude
43 else:
44 parse_success = False
46 sun_update(self, bpy.context)
49 def sun_update(self, context):
50 sun_props = context.scene.sun_pos_properties
52 update_time(context)
53 move_sun(context)
55 if sun_props.show_surface:
56 surface_update(self, context)
57 if sun_props.show_analemmas:
58 analemmas_update(self, context)
59 if sun_props.show_north:
60 north_update(self, context)
63 class SunPosProperties(PropertyGroup):
64 usage_mode: EnumProperty(
65 name="Usage Mode",
66 description="Operate in normal mode or environment texture mode",
67 items=(
68 ('NORMAL', "Normal", ""),
69 ('HDR', "Sun + HDR texture", ""),
71 default='NORMAL',
72 update=sun_update)
74 use_daylight_savings: BoolProperty(
75 name="Daylight Savings",
76 description="Daylight savings time adds 1 hour to standard time",
77 default=False,
78 update=sun_update)
80 use_refraction: BoolProperty(
81 name="Use Refraction",
82 description="Show the apparent Sun position due to atmospheric refraction",
83 default=True,
84 update=sun_update)
86 show_north: BoolProperty(
87 name="Show North",
88 description="Draw a line pointing to the north",
89 default=False,
90 update=north_update)
92 north_offset: FloatProperty(
93 name="North Offset",
94 description="Rotate the scene to choose the North direction",
95 unit="ROTATION",
96 soft_min=-pi, soft_max=pi, step=10.0, default=0.0,
97 update=sun_update)
99 show_surface: BoolProperty(
100 name="Show Surface",
101 description="Draw the surface that the Sun occupies in the sky",
102 default=False,
103 update=surface_update)
105 show_analemmas: BoolProperty(
106 name="Show Analemmas",
107 description="Draw Sun analemmas. These help visualize the motion of the Sun in the sky during the year, for each hour of the day",
108 default=False,
109 update=analemmas_update)
111 coordinates: StringProperty(
112 name="Coordinates",
113 description="Enter coordinates from an online map",
114 get=get_coordinates,
115 set=set_coordinates,
116 options={'SKIP_SAVE'})
118 latitude: FloatProperty(
119 name="Latitude",
120 description="Latitude: (+) Northern (-) Southern",
121 soft_min=-90.0, soft_max=90.0,
122 step=5, precision=3,
123 default=0.0,
124 update=lat_long_update)
126 longitude: FloatProperty(
127 name="Longitude",
128 description="Longitude: (-) West of Greenwich (+) East of Greenwich",
129 soft_min=-180.0, soft_max=180.0,
130 step=5, precision=3,
131 default=0.0,
132 update=lat_long_update)
134 sunrise_time: FloatProperty(
135 name="Sunrise Time",
136 description="Time at which the Sun rises",
137 soft_min=0.0, soft_max=24.0,
138 default=0.0,
139 get=lambda _: sun.sunrise)
141 sunset_time: FloatProperty(
142 name="Sunset Time",
143 description="Time at which the Sun sets",
144 soft_min=0.0, soft_max=24.0,
145 default=0.0,
146 get=lambda _: sun.sunset)
148 sun_elevation: FloatProperty(
149 name="Sun Elevation",
150 description="Elevation angle of the Sun",
151 soft_min=-pi/2, soft_max=pi/2,
152 precision=3,
153 default=0.0,
154 unit="ROTATION",
155 get=lambda _: sun.elevation)
157 sun_azimuth: FloatProperty(
158 name="Sun Azimuth",
159 description="Rotation angle of the Sun from the direction of the north",
160 soft_min=-pi, soft_max=pi,
161 precision=3,
162 default=0.0,
163 unit="ROTATION",
164 get=lambda _: sun.azimuth - bpy.context.scene.sun_pos_properties.north_offset)
166 month: IntProperty(
167 name="Month",
168 min=1, max=12, default=TODAY.month,
169 update=sun_update)
171 day: IntProperty(
172 name="Day",
173 min=1, max=31, default=TODAY.day,
174 update=sun_update)
176 year: IntProperty(
177 name="Year",
178 min=1, max=4000, default=TODAY.year,
179 update=sun_update)
181 use_day_of_year: BoolProperty(
182 description="Use a single value for the day of year",
183 name="Use day of year",
184 default=False,
185 update=sun_update)
187 day_of_year: IntProperty(
188 name="Day of Year",
189 min=1, max=366, default=1,
190 update=sun_update)
192 UTC_zone: FloatProperty(
193 name="UTC Zone",
194 description="Difference from Greenwich, England, in hours",
195 precision=1,
196 min=-14.0, max=13, step=50, default=0.0,
197 update=sun_update)
199 time: FloatProperty(
200 name="Time",
201 description="Time of the day",
202 precision=4,
203 soft_min=0.0, soft_max=23.9999, step=1.0, default=12.0,
204 update=sun_update)
206 sun_distance: FloatProperty(
207 name="Distance",
208 description="Distance to the Sun from the origin",
209 unit="LENGTH",
210 min=0.0, soft_max=3000.0, step=10.0, default=50.0,
211 update=sun_update)
213 sun_object: PointerProperty(
214 name="Sun Object",
215 type=bpy.types.Object,
216 description="Sun object to use in the scene",
217 poll=lambda self, obj: obj.type == 'LIGHT',
218 update=sun_update)
220 object_collection: PointerProperty(
221 name="Collection",
222 type=bpy.types.Collection,
223 description="Collection of objects used to visualize the motion of the Sun",
224 update=sun_update)
226 object_collection_type: EnumProperty(
227 name="Display type",
228 description="Type of Sun motion to visualize.",
229 items=(
230 ('ANALEMMA', "Analemma", "Trajectory of the Sun in the sky during the year, for a given time of the day"),
231 ('DIURNAL', "Diurnal", "Trajectory of the Sun in the sky during a single day"),
233 default='ANALEMMA',
234 update=sun_update)
236 sky_texture: StringProperty(
237 name="Sky Texture",
238 default="",
239 description="Name of the sky texture to use",
240 update=sun_update)
242 hdr_texture: StringProperty(
243 default="Environment Texture",
244 name="Environment Texture",
245 description="Name of the environment texture to use. World nodes must be enabled "
246 "and the color set to an environment Texture",
247 update=sun_update)
249 hdr_azimuth: FloatProperty(
250 name="Rotation",
251 description="Rotation angle of the Sun and environment texture",
252 unit="ROTATION",
253 step=10.0,
254 default=0.0, precision=3,
255 update=sun_update)
257 hdr_elevation: FloatProperty(
258 name="Elevation",
259 description="Elevation angle of the Sun",
260 unit="ROTATION",
261 step=10.0,
262 default=0.0, precision=3,
263 update=sun_update)
265 bind_to_sun: BoolProperty(
266 name="Bind Texture to Sun",
267 description="If enabled, the environment texture moves with the Sun",
268 default=False,
269 update=sun_update)
271 time_spread: FloatProperty(
272 name="Time Spread",
273 description="Time period around which to spread object collection",
274 precision=4,
275 soft_min=1.0, soft_max=24.0, step=1.0, default=23.0,
276 update=sun_update)
278 ############################################################################
279 # Preference panel properties
280 ############################################################################
283 class SunPosAddonPreferences(AddonPreferences):
284 bl_idname = __package__
286 show_overlays: BoolProperty(
287 name="Show Overlays",
288 description="Display overlays in the viewport: the direction of the north, analemmas and the Sun surface",
289 default=True,
290 update=sun_update)
292 show_refraction: BoolProperty(
293 name="Refraction",
294 description="Show Sun Refraction choice",
295 default=True)
297 show_az_el: BoolProperty(
298 name="Azimuth and Elevation Info",
299 description="Show azimuth and solar elevation info",
300 default=True)
302 show_rise_set: BoolProperty(
303 name="Sunrise and Sunset Info",
304 description="Show sunrise and sunset labels",
305 default=True)
307 def draw(self, context):
308 layout = self.layout
310 box = layout.box()
311 col = box.column()
313 col.label(text="Show options or labels:")
314 flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
315 flow.prop(self, "show_refraction")
316 flow.prop(self, "show_overlays")
317 flow.prop(self, "show_az_el")
318 flow.prop(self, "show_rise_set")