Cleanup: strip trailing space, remove BOM
[blender-addons.git] / sun_position / properties.py
blob8d505414076f40c97421c16368bc7e68f8874b34
1 ### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import bpy
20 from bpy.types import AddonPreferences, PropertyGroup
21 from bpy.props import (StringProperty, EnumProperty, IntProperty,
22 FloatProperty, BoolProperty, PointerProperty)
24 from .sun_calc import sun_update, parse_coordinates
25 from .north import north_update
27 from math import pi
28 from datetime import datetime
29 TODAY = datetime.today()
31 ############################################################################
32 # Sun panel properties
33 ############################################################################
36 class SunPosProperties(PropertyGroup):
37 usage_mode: EnumProperty(
38 name="Usage mode",
39 description="Operate in normal mode or environment texture mode",
40 items=(
41 ('NORMAL', "Normal", ""),
42 ('HDR', "Sun + HDR texture", ""),
44 default='NORMAL',
45 update=sun_update)
47 use_daylight_savings: BoolProperty(
48 name="Daylight savings",
49 description="Daylight savings time adds 1 hour to standard time",
50 default=False,
51 update=sun_update)
53 use_refraction: BoolProperty(
54 name="Use refraction",
55 description="Show apparent sun position due to refraction",
56 default=True,
57 update=sun_update)
59 show_north: BoolProperty(
60 name="Show North",
61 description="Draw line pointing north",
62 default=False,
63 update=north_update)
65 north_offset: FloatProperty(
66 name="North Offset",
67 description="Rotate the scene to choose North direction",
68 unit="ROTATION",
69 soft_min=-pi, soft_max=pi, step=10.0, default=0.0,
70 update=sun_update)
72 latitude: FloatProperty(
73 name="Latitude",
74 description="Latitude: (+) Northern (-) Southern",
75 soft_min=-90.0, soft_max=90.0,
76 step=5, precision=3,
77 default=0.0,
78 update=sun_update)
80 longitude: FloatProperty(
81 name="Longitude",
82 description="Longitude: (-) West of Greenwich (+) East of Greenwich",
83 soft_min=-180.0, soft_max=180.0,
84 step=5, precision=3,
85 default=0.0,
86 update=sun_update)
88 co_parser: StringProperty(
89 name="Enter coordinates",
90 description="Enter coordinates from an online map",
91 update=parse_coordinates)
93 month: IntProperty(
94 name="Month",
95 min=1, max=12, default=TODAY.month,
96 update=sun_update)
98 day: IntProperty(
99 name="Day",
100 min=1, max=31, default=TODAY.day,
101 update=sun_update)
103 year: IntProperty(
104 name="Year",
105 min=1, max=4000, default=TODAY.year,
106 update=sun_update)
108 use_day_of_year: BoolProperty(
109 description="Use a single value for day of year",
110 name="Use day of year",
111 default=False,
112 update=sun_update)
114 day_of_year: IntProperty(
115 name="Day of year",
116 min=1, max=366, default=1,
117 update=sun_update)
119 UTC_zone: FloatProperty(
120 name="UTC zone",
121 description="Time zone: Difference from Greenwich, England in hours",
122 precision=1,
123 min=-14.0, max=13, step=50, default=0.0,
124 update=sun_update)
126 time: FloatProperty(
127 name="Time",
128 description="Time of the day",
129 precision=4,
130 soft_min=0.0, soft_max=23.9999, step=1.0, default=12.0,
131 update=sun_update)
133 sun_distance: FloatProperty(
134 name="Distance",
135 description="Distance to sun from origin",
136 unit="LENGTH",
137 min=0.0, soft_max=3000.0, step=10.0, default=50.0,
138 update=sun_update)
140 sun_object: PointerProperty(
141 name="Sun Object",
142 type=bpy.types.Object,
143 description="Sun object to set in the scene",
144 poll=lambda self, obj: obj.type == 'LIGHT',
145 update=sun_update)
147 object_collection: PointerProperty(
148 name="Collection",
149 type=bpy.types.Collection,
150 description="Collection of objects used to visualize sun motion",
151 update=sun_update)
153 object_collection_type: EnumProperty(
154 name="Display type",
155 description="Show object group as sun motion",
156 items=(
157 ('ANALEMMA', "Analemma", ""),
158 ('DIURNAL', "Diurnal", ""),
160 default='ANALEMMA',
161 update=sun_update)
163 sky_texture: StringProperty(
164 name="Sky Texture",
165 default="",
166 description="Name of sky texture to be used",
167 update=sun_update)
169 hdr_texture: StringProperty(
170 default="Environment Texture",
171 name="Environment Texture",
172 description="Name of texture to use. World nodes must be enabled "
173 "and color set to Environment Texture",
174 update=sun_update)
176 hdr_azimuth: FloatProperty(
177 name="Rotation",
178 description="Rotation angle of sun and environment texture",
179 unit="ROTATION",
180 step=10.0,
181 default=0.0, precision=3,
182 update=sun_update)
184 hdr_elevation: FloatProperty(
185 name="Elevation",
186 description="Elevation angle of sun",
187 unit="ROTATION",
188 step=10.0,
189 default=0.0, precision=3,
190 update=sun_update)
192 bind_to_sun: BoolProperty(
193 description="If true, Environment texture moves with sun",
194 default=False,
195 update=sun_update)
197 time_spread: FloatProperty(
198 name="Time Spread",
199 description="Time period in which to spread object collection",
200 precision=4,
201 soft_min=1.0, soft_max=24.0, step=1.0, default=23.0,
202 update=sun_update)
205 ############################################################################
206 # Preference panel properties
207 ############################################################################
210 class SunPosAddonPreferences(AddonPreferences):
211 bl_idname = __package__
213 show_time_place: BoolProperty(
214 name="Time and place presets",
215 description="Show time/place presets",
216 default=False)
218 show_dms: BoolProperty(
219 name="D° M' S\"",
220 description="Show lat/long degrees, minutes, seconds labels",
221 default=True)
223 show_north: BoolProperty(
224 name="Show North",
225 description="Show north offset choice and slider",
226 default=True,
227 update=sun_update)
229 show_refraction: BoolProperty(
230 name="Refraction",
231 description="Show sun refraction choice",
232 default=True,
233 update=sun_update)
235 show_az_el: BoolProperty(
236 name="Azimuth and elevation info",
237 description="Show azimuth and solar elevation info",
238 default=True)
240 show_daylight_savings: BoolProperty(
241 name="Daylight savings",
242 description="Show daylight savings time choice",
243 default=True,
244 update=sun_update)
246 show_rise_set: BoolProperty(
247 name="Sunrise and sunset info",
248 description="Show sunrise and sunset labels",
249 default=True)
251 def draw(self, context):
252 layout = self.layout
254 box = layout.box()
255 col = box.column()
257 col.label(text="Show options or labels:")
258 flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
259 flow.prop(self, "show_time_place")
260 flow.prop(self, "show_dms")
261 flow.prop(self, "show_north")
262 flow.prop(self, "show_refraction")
263 flow.prop(self, "show_az_el")
264 flow.prop(self, "show_daylight_savings")
265 flow.prop(self, "show_rise_set")