Fix: Node Wrangler: new reroutes offset when output hidden
[blender-addons.git] / sun_position / properties.py
bloba081ec596d71c5b04472f9f8411c6e6dec1caa0d
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 .draw import north_update, surface_update, analemmas_update
11 from .geo import parse_position
12 from .sun_calc import format_lat_long, sun, update_time, move_sun
14 from math import pi
15 from datetime import datetime
16 TODAY = datetime.today()
18 ############################################################################
19 # Sun panel properties
20 ############################################################################
22 parse_success = True
25 def lat_long_update(self, context):
26 global parse_success
27 parse_success = True
28 sun_update(self, context)
31 def get_coordinates(self):
32 if parse_success:
33 return format_lat_long(self.latitude, self.longitude)
34 return iface_("ERROR: Could not parse coordinates")
37 def set_coordinates(self, value):
38 parsed_co = parse_position(value)
40 global parse_success
41 if parsed_co is not None and len(parsed_co) == 2:
42 latitude, longitude = parsed_co
43 self.latitude, self.longitude = latitude, longitude
44 else:
45 parse_success = False
47 sun_update(self, bpy.context)
50 def sun_update(self, context):
51 sun_props = context.scene.sun_pos_properties
53 update_time(context)
54 move_sun(context)
56 if sun_props.show_surface:
57 surface_update(self, context)
58 if sun_props.show_analemmas:
59 analemmas_update(self, context)
60 if sun_props.show_north:
61 north_update(self, context)
64 class SunPosProperties(PropertyGroup):
65 usage_mode: EnumProperty(
66 name="Usage Mode",
67 description="Operate in normal mode or environment texture mode",
68 items=(
69 ('NORMAL', "Normal", ""),
70 ('HDR', "Sun + HDR texture", ""),
72 default='NORMAL',
73 update=sun_update)
75 use_daylight_savings: BoolProperty(
76 name="Daylight Savings",
77 description="Daylight savings time adds 1 hour to standard time",
78 default=False,
79 update=sun_update)
81 use_refraction: BoolProperty(
82 name="Use Refraction",
83 description="Show the apparent Sun position due to atmospheric refraction",
84 default=True,
85 update=sun_update)
87 show_north: BoolProperty(
88 name="Show North",
89 description="Draw a line pointing to the north",
90 default=False,
91 update=north_update)
93 north_offset: FloatProperty(
94 name="North Offset",
95 description="Rotate the scene to choose the North direction",
96 unit="ROTATION",
97 soft_min=-pi, soft_max=pi, step=10.0, default=0.0,
98 update=sun_update)
100 show_surface: BoolProperty(
101 name="Show Surface",
102 description="Draw the surface that the Sun occupies in the sky",
103 default=False,
104 update=surface_update)
106 show_analemmas: BoolProperty(
107 name="Show Analemmas",
108 description="Draw Sun analemmas. These help visualize the motion of the Sun in the sky during the year, for each hour of the day",
109 default=False,
110 update=analemmas_update)
112 coordinates: StringProperty(
113 name="Coordinates",
114 description="Enter coordinates from an online map",
115 get=get_coordinates,
116 set=set_coordinates,
117 options={'SKIP_SAVE'})
119 latitude: FloatProperty(
120 name="Latitude",
121 description="Latitude: (+) Northern (-) Southern",
122 soft_min=-90.0, soft_max=90.0,
123 step=5, precision=3,
124 default=0.0,
125 update=lat_long_update)
127 longitude: FloatProperty(
128 name="Longitude",
129 description="Longitude: (-) West of Greenwich (+) East of Greenwich",
130 soft_min=-180.0, soft_max=180.0,
131 step=5, precision=3,
132 default=0.0,
133 update=lat_long_update)
135 sunrise_time: FloatProperty(
136 name="Sunrise Time",
137 description="Time at which the Sun rises",
138 soft_min=0.0, soft_max=24.0,
139 default=0.0,
140 get=lambda _: sun.sunrise)
142 sunset_time: FloatProperty(
143 name="Sunset Time",
144 description="Time at which the Sun sets",
145 soft_min=0.0, soft_max=24.0,
146 default=0.0,
147 get=lambda _: sun.sunset)
149 sun_elevation: FloatProperty(
150 name="Sun Elevation",
151 description="Elevation angle of the Sun",
152 soft_min=-pi/2, soft_max=pi/2,
153 precision=3,
154 default=0.0,
155 unit="ROTATION",
156 get=lambda _: sun.elevation)
158 sun_azimuth: FloatProperty(
159 name="Sun Azimuth",
160 description="Rotation angle of the Sun from the direction of the north",
161 soft_min=-pi, soft_max=pi,
162 precision=3,
163 default=0.0,
164 unit="ROTATION",
165 get=lambda _: sun.azimuth - bpy.context.scene.sun_pos_properties.north_offset)
167 month: IntProperty(
168 name="Month",
169 min=1, max=12, default=TODAY.month,
170 update=sun_update)
172 day: IntProperty(
173 name="Day",
174 min=1, max=31, default=TODAY.day,
175 update=sun_update)
177 year: IntProperty(
178 name="Year",
179 min=1, max=4000, default=TODAY.year,
180 update=sun_update)
182 use_day_of_year: BoolProperty(
183 description="Use a single value for the day of year",
184 name="Use day of year",
185 default=False,
186 update=sun_update)
188 day_of_year: IntProperty(
189 name="Day of Year",
190 min=1, max=366, default=1,
191 update=sun_update)
193 UTC_zone: FloatProperty(
194 name="UTC Zone",
195 description="Difference from Greenwich, England, in hours",
196 precision=1,
197 min=-14.0, max=13, step=50, default=0.0,
198 update=sun_update)
200 time: FloatProperty(
201 name="Time",
202 description="Time of the day",
203 precision=4,
204 soft_min=0.0, soft_max=23.9999, step=1.0, default=12.0,
205 update=sun_update)
207 sun_distance: FloatProperty(
208 name="Distance",
209 description="Distance to the Sun from the origin",
210 unit="LENGTH",
211 min=0.0, soft_max=3000.0, step=10.0, default=50.0,
212 update=sun_update)
214 sun_object: PointerProperty(
215 name="Sun Object",
216 type=bpy.types.Object,
217 description="Sun object to use in the scene",
218 poll=lambda self, obj: obj.type == 'LIGHT',
219 update=sun_update)
221 object_collection: PointerProperty(
222 name="Collection",
223 type=bpy.types.Collection,
224 description="Collection of objects used to visualize the motion of the Sun",
225 update=sun_update)
227 object_collection_type: EnumProperty(
228 name="Display type",
229 description="Type of Sun motion to visualize.",
230 items=(
231 ('ANALEMMA', "Analemma", "Trajectory of the Sun in the sky during the year, for a given time of the day"),
232 ('DIURNAL', "Diurnal", "Trajectory of the Sun in the sky during a single day"),
234 default='ANALEMMA',
235 update=sun_update)
237 sky_texture: StringProperty(
238 name="Sky Texture",
239 default="",
240 description="Name of the sky texture to use",
241 update=sun_update)
243 hdr_texture: StringProperty(
244 default="Environment Texture",
245 name="Environment Texture",
246 description="Name of the environment texture to use. World nodes must be enabled "
247 "and the color set to an environment Texture",
248 update=sun_update)
250 hdr_azimuth: FloatProperty(
251 name="Rotation",
252 description="Rotation angle of the Sun and environment texture",
253 unit="ROTATION",
254 step=10.0,
255 default=0.0, precision=3,
256 update=sun_update)
258 hdr_elevation: FloatProperty(
259 name="Elevation",
260 description="Elevation angle of the Sun",
261 unit="ROTATION",
262 step=10.0,
263 default=0.0, precision=3,
264 update=sun_update)
266 bind_to_sun: BoolProperty(
267 name="Bind Texture to Sun",
268 description="If enabled, the environment texture moves with the Sun",
269 default=False,
270 update=sun_update)
272 time_spread: FloatProperty(
273 name="Time Spread",
274 description="Time period around which to spread object collection",
275 precision=4,
276 soft_min=1.0, soft_max=24.0, step=1.0, default=23.0,
277 update=sun_update)
279 ############################################################################
280 # Preference panel properties
281 ############################################################################
284 class SunPosAddonPreferences(AddonPreferences):
285 bl_idname = __package__
287 show_overlays: BoolProperty(
288 name="Show Overlays",
289 description="Display overlays in the viewport: the direction of the north, analemmas and the Sun surface",
290 default=True,
291 update=sun_update)
293 show_refraction: BoolProperty(
294 name="Refraction",
295 description="Show Sun Refraction choice",
296 default=True)
298 show_az_el: BoolProperty(
299 name="Azimuth and Elevation Info",
300 description="Show azimuth and solar elevation info",
301 default=True)
303 show_rise_set: BoolProperty(
304 name="Sunrise and Sunset Info",
305 description="Show sunrise and sunset labels",
306 default=True)
308 def draw(self, context):
309 layout = self.layout
311 box = layout.box()
312 col = box.column()
314 col.label(text="Show options and info:")
315 flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
316 flow.prop(self, "show_refraction")
317 flow.prop(self, "show_overlays")
318 flow.prop(self, "show_az_el")
319 flow.prop(self, "show_rise_set")