Commit 5dd059cd authored by Damien Picard's avatar Damien Picard
Browse files

sun_position: cleanup

parent 30203a6d
......@@ -52,11 +52,11 @@ if "bpy" in locals():
import importlib
importlib.reload(properties)
importlib.reload(ui_sun)
importlib.reload(map)
# importlib.reload(map)
importlib.reload(hdr)
else:
from . import properties, ui_sun, map, hdr
from . import properties, ui_sun, hdr#, map
import bpy
......
......@@ -23,7 +23,6 @@ import gpu
import bgl
from gpu_extras.batch import batch_for_shader
from mathutils import Vector
from gpu_extras.presets import draw_texture_2d
from math import sqrt, pi, atan2, asin
......@@ -68,7 +67,6 @@ def draw_callback_px(self, context):
if image.gl_load():
raise Exception()
left = 0
bottom = 0
top = context.area.height
right = context.area.width
......
......@@ -73,7 +73,6 @@ else:
# less 90 degrees. This forces the unit circle to begin at the
# 12 O'clock instead of 3 O'clock position.
# ------------------------------------------------------------------
addon_prefs = bpy.context.preferences.addons[__package__].preferences
sun_props = bpy.context.scene.sun_pos_properties
color = (0.2, 0.6, 1.0, 0.7)
......
......@@ -46,12 +46,12 @@ class SunPosProperties(PropertyGroup):
default=False,
update=sun_update)
daylight_savings: BoolProperty(
use_daylight_savings: BoolProperty(
description="Daylight savings time adds 1 hour to standard time.",
default=0,
update=sun_update)
show_refraction: BoolProperty(
use_refraction: BoolProperty(
description="Show apparent sun position due to refraction.",
default=1,
update=sun_update)
......@@ -61,12 +61,22 @@ class SunPosProperties(PropertyGroup):
default=0,
update=north_update)
north_offset: FloatProperty(
attr="",
name="",
description="North offset in degrees or radians "
"from scene's units settings",
unit="ROTATION",
soft_min=-3.14159265, soft_max=3.14159265, step=10.00, default=0.00,
update=sun_update)
latitude: FloatProperty(
attr="",
name="Latitude",
description="Latitude: (+) Northern (-) Southern",
soft_min=-90.000, soft_max=90.000, step=3.001,
default=40.000, precision=3,
soft_min=-90.000, soft_max=90.000,
step=5, precision=3,
default=0.000,
update=sun_update)
longitude: FloatProperty(
......@@ -74,7 +84,8 @@ class SunPosProperties(PropertyGroup):
name="Longitude",
description="Longitude: (-) West of Greenwich (+) East of Greenwich",
soft_min=-180.000, soft_max=180.000,
step=3.001, default=1.000, precision=3,
step=5, precision=3,
default=0.000,
update=sun_update)
co_parser: StringProperty(
......@@ -132,15 +143,6 @@ class SunPosProperties(PropertyGroup):
soft_min=0.00, soft_max=23.9999, step=1.00, default=12.00,
update=sun_update)
north_offset: FloatProperty(
attr="",
name="",
description="North offset in degrees or radians "
"from scene's units settings",
unit="ROTATION",
soft_min=-3.14159265, soft_max=3.14159265, step=10.00, default=0.00,
update=sun_update)
sun_distance: FloatProperty(
attr="",
name="Distance",
......@@ -233,12 +235,6 @@ class SunPosProperties(PropertyGroup):
soft_min=1.00, soft_max=24.00, step=1.00, default=23.00,
update=sun_update)
location: StringProperty(
default="view3d",
name="location",
description="panel location",
update=sun_update)
############################################################################
# Preference panel properties
......@@ -248,22 +244,23 @@ class SunPosProperties(PropertyGroup):
class SunPosAddonPreferences(AddonPreferences):
bl_idname = __package__
map_location: EnumProperty(
name="Map location",
description="Display map in viewport or world panel",
items=(
('VIEWPORT', "Viewport", ""),
('PANEL', "Panel", ""),
),
default='VIEWPORT')
# map_location: EnumProperty(
# name="Map location",
# description="Display map in viewport or world panel",
# items=(
# ('VIEWPORT', "Viewport", ""),
# ('PANEL', "Panel", ""),
# ),
# default='VIEWPORT')
use_time_place: BoolProperty(
show_time_place: BoolProperty(
description="Show time/place presets",
default=False)
use_object_collection: BoolProperty(
show_object_collection: BoolProperty(
description="Use object collection",
default=True)
default=True,
update=sun_update)
show_dms: BoolProperty(
description="Show lat/long degrees, minutes, seconds labels",
......@@ -283,9 +280,10 @@ class SunPosAddonPreferences(AddonPreferences):
description="Show azimuth and solar elevation info",
default=True)
show_dst: BoolProperty(
show_daylight_savings: BoolProperty(
description="Show daylight savings time choice",
default=True)
default=True,
update=sun_update)
show_rise_set: BoolProperty(
description="Show sunrise and sunset",
......@@ -310,16 +308,16 @@ class SunPosAddonPreferences(AddonPreferences):
# 'map_presets', text=Sun.map_name)
# col.separator()
col.prop(self, "map_location")
col.separator()
# col.prop(self, "map_location")
# col.separator()
col.label(text="Show or use:")
flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
flow.prop(self, "use_time_place", text="Time/place presets")
flow.prop(self, "use_object_collection", text="Use collection")
flow.prop(self, "show_time_place", text="Time/place presets")
flow.prop(self, "show_object_collection", text="Use collection")
flow.prop(self, "show_dms", text="D° M' S\"")
flow.prop(self, "show_north", text="North offset")
flow.prop(self, "show_refraction", text="Refraction")
flow.prop(self, "show_az_el", text="Azimuth, elevation")
flow.prop(self, "show_dst", text="Daylight savings time")
flow.prop(self, "show_daylight_savings", text="Daylight savings time")
flow.prop(self, "show_rise_set", text="Sunrise, sunset")
......@@ -18,7 +18,6 @@
import bpy
from bpy.app.handlers import persistent
from mathutils import *
import math
from math import degrees, radians, pi
import datetime
......@@ -65,7 +64,7 @@ class SunClass:
UTC_zone = 0
sun_distance = 0.0
daylight_savings = False
use_daylight_savings = False
sun = SunClass()
......@@ -141,7 +140,9 @@ def move_sun(context):
zone = sun_props.UTC_zone * -1
else:
zone = sun_props.UTC_zone
if sun_props.daylight_savings:
sun.use_daylight_savings = (addon_prefs.show_daylight_savings and
sun_props.use_daylight_savings)
if sun.use_daylight_savings:
zone -= 1
north_offset = degrees(sun_props.north_offset)
......@@ -175,7 +176,7 @@ def move_sun(context):
math.radians(-sun.az_north)))
# Sun collection
if (addon_prefs.use_object_collection
if (addon_prefs.show_object_collection
and sun_props.use_object_collection
and sun_props.object_collection):
sun_objects = sun_props.object_collection.objects
......@@ -216,7 +217,6 @@ def move_sun(context):
math.radians(-sun.az_north)))
def update_time(context):
addon_prefs = context.preferences.addons[__package__].preferences
sun_props = context.scene.sun_pos_properties
if not sun_props.use_day_of_year:
......@@ -368,7 +368,7 @@ def get_sun_position(local_time, latitude, longitude, north_offset,
exoatm_elevation = 90.0 - degrees(zenith)
if addon_prefs.show_refraction and sun_props.show_refraction:
if addon_prefs.show_refraction and sun_props.use_refraction:
if exoatm_elevation > 85.0:
refraction_correction = 0.0
else:
......@@ -472,7 +472,7 @@ def calc_sunrise_sunset(rise):
get_sun_position(tl, sun.latitude, sun.longitude, 0.0,
zone, sun.month, sun.day, sun.year,
sun.sun_distance)
if sun.daylight_savings:
if sun.use_daylight_savings:
time_local += 60.0
tl = time_local / 60.0
if tl < 0.0:
......@@ -483,7 +483,7 @@ def calc_sunrise_sunset(rise):
sun.sunrise.time = tl
sun.sunrise.azimuth = sun.azimuth
sun.sunrise.elevation = sun.elevation
calc_solar_noon(jd, sun.longitude, -zone, sun.daylight_savings)
calc_solar_noon(jd, sun.longitude, -zone, sun.use_daylight_savings)
get_sun_position(sun.solar_noon.time, sun.latitude, sun.longitude,
0.0, zone, sun.month, sun.day, sun.year,
sun.sun_distance)
......
......@@ -20,11 +20,8 @@ import bpy
from bpy.types import Operator, Menu
from bl_operators.presets import AddPresetBase
import os
import datetime
from math import radians
from .sun_calc import (format_lat_long, format_time, format_hms,
move_sun, sun)
from .sun_calc import (format_lat_long, format_time, format_hms, sun)
# -------------------------------------------------------------------
......@@ -57,7 +54,7 @@ class SUNPOS_OT_AddPreset(AddPresetBase, Operator):
"sun_props.time",
"sun_props.year",
"sun_props.UTC_zone",
"sun_props.daylight_savings",
"sun_props.use_daylight_savings",
"sun_props.latitude",
"sun_props.longitude",
]
......@@ -92,7 +89,7 @@ sun_props.time = {:f}
sun_props.UTC_zone = {:d}
sun_props.latitude = {:f}
sun_props.longitude = {:f}
sun_props.daylight_savings = {}
sun_props.use_daylight_savings = {}
'''
for path, p in presets.items():
......@@ -134,7 +131,6 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
box = self.layout.box()
flow = box.grid_flow(row_major=True, columns=0, even_columns=True,
even_rows=False, align=False)
have_texture = False
col = flow.column()
col.label(text="Environment texture:")
......@@ -169,7 +165,7 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
row.operator("world.sunpos_show_hdr", icon='LIGHT_SUN')
def draw_normal_mode_panel(self, context, sp, p, layout):
if p.use_time_place:
if p.show_time_place:
row = layout.row(align=True)
row.menu(SUNPOS_MT_Presets.__name__, text=SUNPOS_MT_Presets.bl_label)
row.operator(SUNPOS_OT_AddPreset.bl_idname, text="", icon='ADD')
......@@ -193,7 +189,7 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
col.separator()
col = flow.column()
if p.use_object_collection:
if p.show_object_collection:
col.prop(sp, "use_object_collection", text="Use collection")
if sp.use_object_collection:
col.prop(sp, "object_collection", text="")
......@@ -203,7 +199,7 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
col.prop(sp, "time_spread")
box = self.layout.box()
box.prop(sp, "show_map", text="Show Map", toggle=True, icon='WORLD')
# box.prop(sp, "show_map", text="Show Map", toggle=True, icon='WORLD')
col = box.column(align=True)
col.label(text="Enter coordinates:")
......@@ -248,7 +244,7 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
if p.show_refraction:
col = flow.column()
col.prop(sp, "show_refraction", text="Show refraction")
col.prop(sp, "use_refraction", text="Show refraction")
col.separator()
col = flow.column()
......@@ -272,12 +268,12 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
col = flow.column(align=True)
lt, ut = format_time(sp.time,
sp.UTC_zone,
sp.daylight_savings,
p.show_daylight_savings and sp.use_daylight_savings,
sp.longitude)
col.prop(sp, "time")
col.prop(sp, "UTC_zone")
if p.show_dst:
col.prop(sp, "daylight_savings", text="Daylight Savings")
if p.show_daylight_savings:
col.prop(sp, "use_daylight_savings", text="Daylight Savings")
col.separator()
col = flow.column(align=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment