Sun Position: expose Sun properties to Python
[blender-addons.git] / sun_position / properties.py
blob673845df7bc7fb6479d320a50a6ce0bb25836c44
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)
8 from .sun_calc import sun_update, parse_coordinates, surface_update, analemmas_update, sun
9 from .draw import north_update
11 from math import pi
12 from datetime import datetime
13 TODAY = datetime.today()
15 ############################################################################
16 # Sun panel properties
17 ############################################################################
20 class SunPosProperties(PropertyGroup):
21 usage_mode: EnumProperty(
22 name="Usage Mode",
23 description="Operate in normal mode or environment texture mode",
24 items=(
25 ('NORMAL', "Normal", ""),
26 ('HDR', "Sun + HDR texture", ""),
28 default='NORMAL',
29 update=sun_update)
31 use_daylight_savings: BoolProperty(
32 name="Daylight Savings",
33 description="Daylight savings time adds 1 hour to standard time",
34 default=False,
35 update=sun_update)
37 use_refraction: BoolProperty(
38 name="Use Refraction",
39 description="Show apparent Sun position due to refraction",
40 default=True,
41 update=sun_update)
43 show_north: BoolProperty(
44 name="Show North",
45 description="Draw line pointing north",
46 default=False,
47 update=north_update)
49 north_offset: FloatProperty(
50 name="North Offset",
51 description="Rotate the scene to choose North direction",
52 unit="ROTATION",
53 soft_min=-pi, soft_max=pi, step=10.0, default=0.0,
54 update=sun_update)
56 show_surface: BoolProperty(
57 name="Show Surface",
58 description="Draw sun surface",
59 default=False,
60 update=surface_update)
62 show_analemmas: BoolProperty(
63 name="Show Analemmas",
64 description="Draw sun analemmas",
65 default=False,
66 update=analemmas_update)
68 latitude: FloatProperty(
69 name="Latitude",
70 description="Latitude: (+) Northern (-) Southern",
71 soft_min=-90.0, soft_max=90.0,
72 step=5, precision=3,
73 default=0.0,
74 update=sun_update)
76 longitude: FloatProperty(
77 name="Longitude",
78 description="Longitude: (-) West of Greenwich (+) East of Greenwich",
79 soft_min=-180.0, soft_max=180.0,
80 step=5, precision=3,
81 default=0.0,
82 update=sun_update)
84 sunrise_time: FloatProperty(
85 name="Sunrise Time",
86 description="Time at which the Sun rises",
87 soft_min=0.0, soft_max=24.0,
88 default=0.0,
89 get=lambda _: sun.sunrise.time)
91 sunset_time: FloatProperty(
92 name="Sunset Time",
93 description="Time at which the Sun sets",
94 soft_min=0.0, soft_max=24.0,
95 default=0.0,
96 get=lambda _: sun.sunset.time)
98 sun_azimuth: FloatProperty(
99 name="Sun Azimuth",
100 description="Rotation angle of the Sun from the north direction",
101 soft_min=-pi, soft_max=pi,
102 default=0.0,
103 get=lambda _: sun.azimuth)
105 sun_elevation: FloatProperty(
106 name="Sunset Time",
107 description="Elevation angle of the Sun",
108 soft_min=-pi/2, soft_max=pi/2,
109 default=0.0,
110 get=lambda _: sun.elevation)
112 co_parser: StringProperty(
113 name="Enter coordinates",
114 description="Enter coordinates from an online map",
115 update=parse_coordinates)
117 month: IntProperty(
118 name="Month",
119 min=1, max=12, default=TODAY.month,
120 update=sun_update)
122 day: IntProperty(
123 name="Day",
124 min=1, max=31, default=TODAY.day,
125 update=sun_update)
127 year: IntProperty(
128 name="Year",
129 min=1, max=4000, default=TODAY.year,
130 update=sun_update)
132 use_day_of_year: BoolProperty(
133 description="Use a single value for day of year",
134 name="Use day of year",
135 default=False,
136 update=sun_update)
138 day_of_year: IntProperty(
139 name="Day of year",
140 min=1, max=366, default=1,
141 update=sun_update)
143 UTC_zone: FloatProperty(
144 name="UTC zone",
145 description="Time zone: Difference from Greenwich, England in hours",
146 precision=1,
147 min=-14.0, max=13, step=50, default=0.0,
148 update=sun_update)
150 time: FloatProperty(
151 name="Time",
152 description="Time of the day",
153 precision=4,
154 soft_min=0.0, soft_max=23.9999, step=1.0, default=12.0,
155 update=sun_update)
157 sun_distance: FloatProperty(
158 name="Distance",
159 description="Distance to sun from origin",
160 unit="LENGTH",
161 min=0.0, soft_max=3000.0, step=10.0, default=50.0,
162 update=sun_update)
164 sun_object: PointerProperty(
165 name="Sun Object",
166 type=bpy.types.Object,
167 description="Sun object to set in the scene",
168 poll=lambda self, obj: obj.type == 'LIGHT',
169 update=sun_update)
171 object_collection: PointerProperty(
172 name="Collection",
173 type=bpy.types.Collection,
174 description="Collection of objects used to visualize sun motion",
175 update=sun_update)
177 object_collection_type: EnumProperty(
178 name="Display type",
179 description="Show object collection as sun motion",
180 items=(
181 ('ANALEMMA', "Analemma", ""),
182 ('DIURNAL', "Diurnal", ""),
184 default='ANALEMMA',
185 update=sun_update)
187 sky_texture: StringProperty(
188 name="Sky Texture",
189 default="",
190 description="Name of sky texture to be used",
191 update=sun_update)
193 hdr_texture: StringProperty(
194 default="Environment Texture",
195 name="Environment Texture",
196 description="Name of texture to use. World nodes must be enabled "
197 "and color set to Environment Texture",
198 update=sun_update)
200 hdr_azimuth: FloatProperty(
201 name="Rotation",
202 description="Rotation angle of sun and environment texture",
203 unit="ROTATION",
204 step=10.0,
205 default=0.0, precision=3,
206 update=sun_update)
208 hdr_elevation: FloatProperty(
209 name="Elevation",
210 description="Elevation angle of sun",
211 unit="ROTATION",
212 step=10.0,
213 default=0.0, precision=3,
214 update=sun_update)
216 bind_to_sun: BoolProperty(
217 name="Bind Texture to Sun",
218 description="If true, Environment texture moves with sun",
219 default=False,
220 update=sun_update)
222 time_spread: FloatProperty(
223 name="Time Spread",
224 description="Time period in which to spread object collection",
225 precision=4,
226 soft_min=1.0, soft_max=24.0, step=1.0, default=23.0,
227 update=sun_update)
229 ############################################################################
230 # Preference panel properties
231 ############################################################################
234 class SunPosAddonPreferences(AddonPreferences):
235 bl_idname = __package__
237 show_time_place: BoolProperty(
238 name="Time and place presets",
239 description="Show time/place presets",
240 default=False)
242 show_dms: BoolProperty(
243 name="D° M' S\"",
244 description="Show lat/long degrees, minutes, seconds labels",
245 default=True)
247 show_north: BoolProperty(
248 name="Show North",
249 description="Show north offset choice and slider",
250 default=True,
251 update=sun_update)
253 show_surface: BoolProperty(
254 name="Show Surface",
255 description="Show sun surface choice and slider",
256 default=True,
257 update=sun_update)
259 show_analemmas: BoolProperty(
260 name="Show Analemmas",
261 description="Show analemmas choice and slider",
262 default=True,
263 update=sun_update)
265 show_refraction: BoolProperty(
266 name="Refraction",
267 description="Show sun refraction choice",
268 default=True,
269 update=sun_update)
271 show_az_el: BoolProperty(
272 name="Azimuth and elevation info",
273 description="Show azimuth and solar elevation info",
274 default=True)
276 show_daylight_savings: BoolProperty(
277 name="Daylight savings",
278 description="Show daylight savings time choice",
279 default=True,
280 update=sun_update)
282 show_rise_set: BoolProperty(
283 name="Sunrise and sunset info",
284 description="Show sunrise and sunset labels",
285 default=True)
287 def draw(self, context):
288 layout = self.layout
290 box = layout.box()
291 col = box.column()
293 col.label(text="Show options or labels:")
294 flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
295 flow.prop(self, "show_time_place")
296 flow.prop(self, "show_dms")
297 flow.prop(self, "show_north")
298 flow.prop(self, "show_surface")
299 flow.prop(self, "show_analemmas")
300 flow.prop(self, "show_refraction")
301 flow.prop(self, "show_az_el")
302 flow.prop(self, "show_daylight_savings")
303 flow.prop(self, "show_rise_set")