Merge branch 'blender-v3.3-release'
[blender-addons.git] / sun_position / properties.py
blobac791d4391fdc7bf0b87ad00914e9ff8b02ec97b
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
9 from .north 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 latitude: FloatProperty(
57 name="Latitude",
58 description="Latitude: (+) Northern (-) Southern",
59 soft_min=-90.0, soft_max=90.0,
60 step=5, precision=3,
61 default=0.0,
62 update=sun_update)
64 longitude: FloatProperty(
65 name="Longitude",
66 description="Longitude: (-) West of Greenwich (+) East of Greenwich",
67 soft_min=-180.0, soft_max=180.0,
68 step=5, precision=3,
69 default=0.0,
70 update=sun_update)
72 co_parser: StringProperty(
73 name="Enter coordinates",
74 description="Enter coordinates from an online map",
75 update=parse_coordinates)
77 month: IntProperty(
78 name="Month",
79 min=1, max=12, default=TODAY.month,
80 update=sun_update)
82 day: IntProperty(
83 name="Day",
84 min=1, max=31, default=TODAY.day,
85 update=sun_update)
87 year: IntProperty(
88 name="Year",
89 min=1, max=4000, default=TODAY.year,
90 update=sun_update)
92 use_day_of_year: BoolProperty(
93 description="Use a single value for day of year",
94 name="Use day of year",
95 default=False,
96 update=sun_update)
98 day_of_year: IntProperty(
99 name="Day of year",
100 min=1, max=366, default=1,
101 update=sun_update)
103 UTC_zone: FloatProperty(
104 name="UTC zone",
105 description="Time zone: Difference from Greenwich, England in hours",
106 precision=1,
107 min=-14.0, max=13, step=50, default=0.0,
108 update=sun_update)
110 time: FloatProperty(
111 name="Time",
112 description="Time of the day",
113 precision=4,
114 soft_min=0.0, soft_max=23.9999, step=1.0, default=12.0,
115 update=sun_update)
117 sun_distance: FloatProperty(
118 name="Distance",
119 description="Distance to sun from origin",
120 unit="LENGTH",
121 min=0.0, soft_max=3000.0, step=10.0, default=50.0,
122 update=sun_update)
124 sun_object: PointerProperty(
125 name="Sun Object",
126 type=bpy.types.Object,
127 description="Sun object to set in the scene",
128 poll=lambda self, obj: obj.type == 'LIGHT',
129 update=sun_update)
131 object_collection: PointerProperty(
132 name="Collection",
133 type=bpy.types.Collection,
134 description="Collection of objects used to visualize sun motion",
135 update=sun_update)
137 object_collection_type: EnumProperty(
138 name="Display type",
139 description="Show object collection as sun motion",
140 items=(
141 ('ANALEMMA', "Analemma", ""),
142 ('DIURNAL', "Diurnal", ""),
144 default='ANALEMMA',
145 update=sun_update)
147 sky_texture: StringProperty(
148 name="Sky Texture",
149 default="",
150 description="Name of sky texture to be used",
151 update=sun_update)
153 hdr_texture: StringProperty(
154 default="Environment Texture",
155 name="Environment Texture",
156 description="Name of texture to use. World nodes must be enabled "
157 "and color set to Environment Texture",
158 update=sun_update)
160 hdr_azimuth: FloatProperty(
161 name="Rotation",
162 description="Rotation angle of sun and environment texture",
163 unit="ROTATION",
164 step=10.0,
165 default=0.0, precision=3,
166 update=sun_update)
168 hdr_elevation: FloatProperty(
169 name="Elevation",
170 description="Elevation angle of sun",
171 unit="ROTATION",
172 step=10.0,
173 default=0.0, precision=3,
174 update=sun_update)
176 bind_to_sun: BoolProperty(
177 description="If true, Environment texture moves with sun",
178 default=False,
179 update=sun_update)
181 time_spread: FloatProperty(
182 name="Time Spread",
183 description="Time period in which to spread object collection",
184 precision=4,
185 soft_min=1.0, soft_max=24.0, step=1.0, default=23.0,
186 update=sun_update)
189 ############################################################################
190 # Preference panel properties
191 ############################################################################
194 class SunPosAddonPreferences(AddonPreferences):
195 bl_idname = __package__
197 show_time_place: BoolProperty(
198 name="Time and place presets",
199 description="Show time/place presets",
200 default=False)
202 show_dms: BoolProperty(
203 name="D° M' S\"",
204 description="Show lat/long degrees, minutes, seconds labels",
205 default=True)
207 show_north: BoolProperty(
208 name="Show North",
209 description="Show north offset choice and slider",
210 default=True,
211 update=sun_update)
213 show_refraction: BoolProperty(
214 name="Refraction",
215 description="Show sun refraction choice",
216 default=True,
217 update=sun_update)
219 show_az_el: BoolProperty(
220 name="Azimuth and elevation info",
221 description="Show azimuth and solar elevation info",
222 default=True)
224 show_daylight_savings: BoolProperty(
225 name="Daylight savings",
226 description="Show daylight savings time choice",
227 default=True,
228 update=sun_update)
230 show_rise_set: BoolProperty(
231 name="Sunrise and sunset info",
232 description="Show sunrise and sunset labels",
233 default=True)
235 def draw(self, context):
236 layout = self.layout
238 box = layout.box()
239 col = box.column()
241 col.label(text="Show options or labels:")
242 flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
243 flow.prop(self, "show_time_place")
244 flow.prop(self, "show_dms")
245 flow.prop(self, "show_north")
246 flow.prop(self, "show_refraction")
247 flow.prop(self, "show_az_el")
248 flow.prop(self, "show_daylight_savings")
249 flow.prop(self, "show_rise_set")