1 # SPDX-License-Identifier: GPL-2.0-or-later
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
12 from datetime
import datetime
13 TODAY
= datetime
.today()
15 ############################################################################
16 # Sun panel properties
17 ############################################################################
20 class SunPosProperties(PropertyGroup
):
21 usage_mode
: EnumProperty(
23 description
="Operate in normal mode or environment texture mode",
25 ('NORMAL', "Normal", ""),
26 ('HDR', "Sun + HDR texture", ""),
31 use_daylight_savings
: BoolProperty(
32 name
="Daylight Savings",
33 description
="Daylight savings time adds 1 hour to standard time",
37 use_refraction
: BoolProperty(
38 name
="Use Refraction",
39 description
="Show apparent Sun position due to refraction",
43 show_north
: BoolProperty(
45 description
="Draw line pointing north",
49 north_offset
: FloatProperty(
51 description
="Rotate the scene to choose North direction",
53 soft_min
=-pi
, soft_max
=pi
, step
=10.0, default
=0.0,
56 show_surface
: BoolProperty(
58 description
="Draw sun surface",
60 update
=surface_update
)
62 show_analemmas
: BoolProperty(
63 name
="Show Analemmas",
64 description
="Draw sun analemmas",
66 update
=analemmas_update
)
68 latitude
: FloatProperty(
70 description
="Latitude: (+) Northern (-) Southern",
71 soft_min
=-90.0, soft_max
=90.0,
76 longitude
: FloatProperty(
78 description
="Longitude: (-) West of Greenwich (+) East of Greenwich",
79 soft_min
=-180.0, soft_max
=180.0,
84 sunrise_time
: FloatProperty(
86 description
="Time at which the Sun rises",
87 soft_min
=0.0, soft_max
=24.0,
89 get
=lambda _
: sun
.sunrise
.time
)
91 sunset_time
: FloatProperty(
93 description
="Time at which the Sun sets",
94 soft_min
=0.0, soft_max
=24.0,
96 get
=lambda _
: sun
.sunset
.time
)
98 sun_azimuth
: FloatProperty(
100 description
="Rotation angle of the Sun from the north direction",
101 soft_min
=-pi
, soft_max
=pi
,
103 get
=lambda _
: sun
.azimuth
)
105 sun_elevation
: FloatProperty(
107 description
="Elevation angle of the Sun",
108 soft_min
=-pi
/2, soft_max
=pi
/2,
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
)
119 min=1, max=12, default
=TODAY
.month
,
124 min=1, max=31, default
=TODAY
.day
,
129 min=1, max=4000, default
=TODAY
.year
,
132 use_day_of_year
: BoolProperty(
133 description
="Use a single value for day of year",
134 name
="Use day of year",
138 day_of_year
: IntProperty(
140 min=1, max=366, default
=1,
143 UTC_zone
: FloatProperty(
145 description
="Time zone: Difference from Greenwich, England in hours",
147 min=-14.0, max=13, step
=50, default
=0.0,
152 description
="Time of the day",
154 soft_min
=0.0, soft_max
=23.9999, step
=1.0, default
=12.0,
157 sun_distance
: FloatProperty(
159 description
="Distance to sun from origin",
161 min=0.0, soft_max
=3000.0, step
=10.0, default
=50.0,
164 sun_object
: PointerProperty(
166 type=bpy
.types
.Object
,
167 description
="Sun object to set in the scene",
168 poll
=lambda self
, obj
: obj
.type == 'LIGHT',
171 object_collection
: PointerProperty(
173 type=bpy
.types
.Collection
,
174 description
="Collection of objects used to visualize sun motion",
177 object_collection_type
: EnumProperty(
179 description
="Show object collection as sun motion",
181 ('ANALEMMA', "Analemma", ""),
182 ('DIURNAL', "Diurnal", ""),
187 sky_texture
: StringProperty(
190 description
="Name of sky texture to be used",
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",
200 hdr_azimuth
: FloatProperty(
202 description
="Rotation angle of sun and environment texture",
205 default
=0.0, precision
=3,
208 hdr_elevation
: FloatProperty(
210 description
="Elevation angle of sun",
213 default
=0.0, precision
=3,
216 bind_to_sun
: BoolProperty(
217 name
="Bind Texture to Sun",
218 description
="If true, Environment texture moves with sun",
222 time_spread
: FloatProperty(
224 description
="Time period in which to spread object collection",
226 soft_min
=1.0, soft_max
=24.0, step
=1.0, default
=23.0,
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",
242 show_dms
: BoolProperty(
244 description
="Show lat/long degrees, minutes, seconds labels",
247 show_north
: BoolProperty(
249 description
="Show north offset choice and slider",
253 show_surface
: BoolProperty(
255 description
="Show sun surface choice and slider",
259 show_analemmas
: BoolProperty(
260 name
="Show Analemmas",
261 description
="Show analemmas choice and slider",
265 show_refraction
: BoolProperty(
267 description
="Show sun refraction choice",
271 show_az_el
: BoolProperty(
272 name
="Azimuth and elevation info",
273 description
="Show azimuth and solar elevation info",
276 show_daylight_savings
: BoolProperty(
277 name
="Daylight savings",
278 description
="Show daylight savings time choice",
282 show_rise_set
: BoolProperty(
283 name
="Sunrise and sunset info",
284 description
="Show sunrise and sunset labels",
287 def draw(self
, context
):
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")