Sun Position: group some prefs under show_overlays
[blender-addons.git] / sun_position / properties.py
blob42a89b8e3e855a41ddcad50e604ce8287bc7b075
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 format_lat_long, parse_coordinates, sun, update_time, move_sun
9 from .draw import north_update, surface_update, analemmas_update
11 from math import pi
12 from datetime import datetime
13 TODAY = datetime.today()
15 ############################################################################
16 # Sun panel properties
17 ############################################################################
19 def sun_update(self, context):
20 sun_props = context.scene.sun_pos_properties
22 update_time(context)
23 move_sun(context)
25 if sun_props.show_surface:
26 surface_update(self, context)
27 if sun_props.show_analemmas:
28 analemmas_update(self, context)
29 if sun_props.show_north:
30 north_update(self, context)
33 class SunPosProperties(PropertyGroup):
34 usage_mode: EnumProperty(
35 name="Usage Mode",
36 description="Operate in normal mode or environment texture mode",
37 items=(
38 ('NORMAL', "Normal", ""),
39 ('HDR', "Sun + HDR texture", ""),
41 default='NORMAL',
42 update=sun_update)
44 use_daylight_savings: BoolProperty(
45 name="Daylight Savings",
46 description="Daylight savings time adds 1 hour to standard time",
47 default=False,
48 update=sun_update)
50 use_refraction: BoolProperty(
51 name="Use Refraction",
52 description="Show the apparent Sun position due to atmospheric refraction",
53 default=True,
54 update=sun_update)
56 show_north: BoolProperty(
57 name="Show North",
58 description="Draw a line pointing to the north",
59 default=False,
60 update=north_update)
62 north_offset: FloatProperty(
63 name="North Offset",
64 description="Rotate the scene to choose the North direction",
65 unit="ROTATION",
66 soft_min=-pi, soft_max=pi, step=10.0, default=0.0,
67 update=sun_update)
69 show_surface: BoolProperty(
70 name="Show Surface",
71 description="Draw the surface that the Sun occupies in the sky",
72 default=False,
73 update=surface_update)
75 show_analemmas: BoolProperty(
76 name="Show Analemmas",
77 description="Draw Sun analemmas. These help visualize the motion of the Sun in the sky during the year, for each hour of the day",
78 default=False,
79 update=analemmas_update)
81 latitude: FloatProperty(
82 name="Latitude",
83 description="Latitude: (+) Northern (-) Southern",
84 soft_min=-90.0, soft_max=90.0,
85 step=5, precision=3,
86 default=0.0,
87 update=sun_update)
89 longitude: FloatProperty(
90 name="Longitude",
91 description="Longitude: (-) West of Greenwich (+) East of Greenwich",
92 soft_min=-180.0, soft_max=180.0,
93 step=5, precision=3,
94 default=0.0,
95 update=sun_update)
97 sunrise_time: FloatProperty(
98 name="Sunrise Time",
99 description="Time at which the Sun rises",
100 soft_min=0.0, soft_max=24.0,
101 default=0.0,
102 get=lambda _: sun.sunrise)
104 sunset_time: FloatProperty(
105 name="Sunset Time",
106 description="Time at which the Sun sets",
107 soft_min=0.0, soft_max=24.0,
108 default=0.0,
109 get=lambda _: sun.sunset)
111 sun_azimuth: FloatProperty(
112 name="Sun Azimuth",
113 description="Rotation angle of the Sun from the direction of the north",
114 soft_min=-pi, soft_max=pi,
115 default=0.0,
116 get=lambda _: sun.azimuth)
118 sun_elevation: FloatProperty(
119 name="Sun Elevation",
120 description="Elevation angle of the Sun",
121 soft_min=-pi/2, soft_max=pi/2,
122 default=0.0,
123 get=lambda _: sun.elevation)
125 co_parser: StringProperty(
126 name="Enter Coordinates",
127 description="Enter coordinates from an online map",
128 update=parse_coordinates)
130 month: IntProperty(
131 name="Month",
132 min=1, max=12, default=TODAY.month,
133 update=sun_update)
135 day: IntProperty(
136 name="Day",
137 min=1, max=31, default=TODAY.day,
138 update=sun_update)
140 year: IntProperty(
141 name="Year",
142 min=1, max=4000, default=TODAY.year,
143 update=sun_update)
145 use_day_of_year: BoolProperty(
146 description="Use a single value for the day of year",
147 name="Use day of year",
148 default=False,
149 update=sun_update)
151 day_of_year: IntProperty(
152 name="Day of Year",
153 min=1, max=366, default=1,
154 update=sun_update)
156 UTC_zone: FloatProperty(
157 name="UTC Zone",
158 description="Difference from Greenwich, England, in hours",
159 precision=1,
160 min=-14.0, max=13, step=50, default=0.0,
161 update=sun_update)
163 time: FloatProperty(
164 name="Time",
165 description="Time of the day",
166 precision=4,
167 soft_min=0.0, soft_max=23.9999, step=1.0, default=12.0,
168 update=sun_update)
170 sun_distance: FloatProperty(
171 name="Distance",
172 description="Distance to the Sun from the origin",
173 unit="LENGTH",
174 min=0.0, soft_max=3000.0, step=10.0, default=50.0,
175 update=sun_update)
177 sun_object: PointerProperty(
178 name="Sun Object",
179 type=bpy.types.Object,
180 description="Sun object to use in the scene",
181 poll=lambda self, obj: obj.type == 'LIGHT',
182 update=sun_update)
184 object_collection: PointerProperty(
185 name="Collection",
186 type=bpy.types.Collection,
187 description="Collection of objects used to visualize the motion of the Sun",
188 update=sun_update)
190 object_collection_type: EnumProperty(
191 name="Display type",
192 description="Type of Sun motion to visualize.",
193 items=(
194 ('ANALEMMA', "Analemma", "Trajectory of the Sun in the sky during the year, for a given time of the day"),
195 ('DIURNAL', "Diurnal", "Trajectory of the Sun in the sky during a single day"),
197 default='ANALEMMA',
198 update=sun_update)
200 sky_texture: StringProperty(
201 name="Sky Texture",
202 default="",
203 description="Name of the sky texture to use",
204 update=sun_update)
206 hdr_texture: StringProperty(
207 default="Environment Texture",
208 name="Environment Texture",
209 description="Name of the environment texture to use. World nodes must be enabled "
210 "and the color set to an environment Texture",
211 update=sun_update)
213 hdr_azimuth: FloatProperty(
214 name="Rotation",
215 description="Rotation angle of the Sun and environment texture",
216 unit="ROTATION",
217 step=10.0,
218 default=0.0, precision=3,
219 update=sun_update)
221 hdr_elevation: FloatProperty(
222 name="Elevation",
223 description="Elevation angle of the Sun",
224 unit="ROTATION",
225 step=10.0,
226 default=0.0, precision=3,
227 update=sun_update)
229 bind_to_sun: BoolProperty(
230 name="Bind Texture to Sun",
231 description="If enabled, the environment texture moves with the Sun",
232 default=False,
233 update=sun_update)
235 time_spread: FloatProperty(
236 name="Time Spread",
237 description="Time period around which to spread object collection",
238 precision=4,
239 soft_min=1.0, soft_max=24.0, step=1.0, default=23.0,
240 update=sun_update)
242 ############################################################################
243 # Preference panel properties
244 ############################################################################
247 class SunPosAddonPreferences(AddonPreferences):
248 bl_idname = __package__
250 show_time_place: BoolProperty(
251 name="Time and Place Presets",
252 description="Show time and place presets",
253 default=False)
255 show_dms: BoolProperty(
256 name="D° M' S\"",
257 description="Show degrees, minutes, seconds labels for the latitude and longitude",
258 default=True)
260 show_overlays: BoolProperty(
261 name="Show Overlays",
262 description="Display overlays in the viewport: the direction of the north, analemmas and the Sun surface",
263 default=True,
264 update=sun_update)
266 show_refraction: BoolProperty(
267 name="Refraction",
268 description="Show Sun Refraction choice",
269 default=True,
270 update=sun_update)
272 show_az_el: BoolProperty(
273 name="Azimuth and Elevation Info",
274 description="Show azimuth and solar elevation info",
275 default=True)
277 show_daylight_savings: BoolProperty(
278 name="Daylight Savings",
279 description="Show daylight savings time choice",
280 default=True,
281 update=sun_update)
283 show_rise_set: BoolProperty(
284 name="Sunrise and Sunset Info",
285 description="Show sunrise and sunset labels",
286 default=True)
288 def draw(self, context):
289 layout = self.layout
291 box = layout.box()
292 col = box.column()
294 col.label(text="Show options or labels:")
295 flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
296 flow.prop(self, "show_time_place")
297 flow.prop(self, "show_dms")
298 flow.prop(self, "show_refraction")
299 flow.prop(self, "show_overlays")
300 flow.prop(self, "show_az_el")
301 flow.prop(self, "show_daylight_savings")
302 flow.prop(self, "show_rise_set")