[Bf-extensions-cvs] [efbc5e5d] master: sun_position: move to release: T69936

Damien Picard noreply at git.blender.org
Mon Dec 9 12:05:14 CET 2019


Commit: efbc5e5db7c73ae43ddc11abf8db8bc8f98c9945
Author: Damien Picard
Date:   Mon Dec 9 12:02:34 2019 +0100
Branches: master
https://developer.blender.org/rBAefbc5e5db7c73ae43ddc11abf8db8bc8f98c9945

sun_position: move to release: T69936

===================================================================

A	sun_position/__init__.py
A	sun_position/geo.py
A	sun_position/hdr.py
A	sun_position/north.py
A	sun_position/properties.py
A	sun_position/sun_calc.py
A	sun_position/ui_sun.py

===================================================================

diff --git a/sun_position/__init__.py b/sun_position/__init__.py
new file mode 100644
index 00000000..de2dd858
--- /dev/null
+++ b/sun_position/__init__.py
@@ -0,0 +1,85 @@
+### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# --------------------------------------------------------------------------
+# The sun positioning algorithms are based on the National Oceanic
+# and Atmospheric Administration's (NOAA) Solar Position Calculator
+# which rely on calculations of Jean Meeus' book "Astronomical Algorithms."
+# Use of NOAA data and products are in the public domain and may be used
+# freely by the public as outlined in their policies at
+#               www.nws.noaa.gov/disclaimer.php
+# --------------------------------------------------------------------------
+# The geo parser script is by Maximilian Högner, released
+# under the GNU GPL license:
+# http://hoegners.de/Maxi/geo/
+# --------------------------------------------------------------------------
+
+# <pep8 compliant>
+
+bl_info = {
+    "name": "Sun Position",
+    "author": "Michael Martin",
+    "version": (3, 1, 0),
+    "blender": (2, 80, 0),
+    "location": "World > Sun Position",
+    "description": "Show sun position with objects and/or sky texture",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+    "Scripts/3D_interaction/Sun_Position",
+    "tracker_url": "https://projects.blender.org/tracker/"
+    "index.php?func=detail&aid=29714",
+    "category": "Lighting"}
+
+if "bpy" in locals():
+    import importlib
+    importlib.reload(properties)
+    importlib.reload(ui_sun)
+    importlib.reload(hdr)
+
+else:
+    from . import properties, ui_sun, hdr
+
+import bpy
+
+
+def register():
+    bpy.utils.register_class(properties.SunPosProperties)
+    bpy.types.Scene.sun_pos_properties = (
+        bpy.props.PointerProperty(type=properties.SunPosProperties,
+                        name="Sun Position",
+                        description="Sun Position Settings"))
+    bpy.utils.register_class(properties.SunPosAddonPreferences)
+    bpy.utils.register_class(ui_sun.SUNPOS_OT_AddPreset)
+    bpy.utils.register_class(ui_sun.SUNPOS_OT_DefaultPresets)
+    bpy.utils.register_class(ui_sun.SUNPOS_MT_Presets)
+    bpy.utils.register_class(ui_sun.SUNPOS_PT_Panel)
+    bpy.utils.register_class(hdr.SUNPOS_OT_ShowHdr)
+
+    bpy.app.handlers.frame_change_post.append(sun_calc.sun_handler)
+
+
+def unregister():
+    bpy.utils.unregister_class(hdr.SUNPOS_OT_ShowHdr)
+    bpy.utils.unregister_class(ui_sun.SUNPOS_PT_Panel)
+    bpy.utils.unregister_class(ui_sun.SUNPOS_MT_Presets)
+    bpy.utils.unregister_class(ui_sun.SUNPOS_OT_DefaultPresets)
+    bpy.utils.unregister_class(ui_sun.SUNPOS_OT_AddPreset)
+    bpy.utils.unregister_class(properties.SunPosAddonPreferences)
+    del bpy.types.Scene.sun_pos_properties
+    bpy.utils.unregister_class(properties.SunPosProperties)
+
+    bpy.app.handlers.frame_change_post.remove(sun_calc.sun_handler)
diff --git a/sun_position/geo.py b/sun_position/geo.py
new file mode 100644
index 00000000..6d49f2ad
--- /dev/null
+++ b/sun_position/geo.py
@@ -0,0 +1,192 @@
+#!/usr/bin/env python
+#
+# geo.py is a python module with no dependencies on extra packages,
+# providing some convenience functions for working with geographic
+# coordinates
+#
+# Copyright (C) 2010  Maximilian Hoegner <hp.maxi at hoegners.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+### Part one - Functions for dealing with points on a sphere ###
+
+### Part two - A tolerant parser for position strings ###
+import re
+
+
+class Parser:
+    """ A parser class using regular expressions. """
+
+    def __init__(self):
+        self.patterns = {}
+        self.raw_patterns = {}
+        self.virtual = {}
+
+    def add(self, name, pattern, virtual=False):
+        """ Adds a new named pattern (regular expression) that can reference previously added patterns by %(pattern_name)s.
+		Virtual patterns can be used to make expressions more compact but don't show up in the parse tree. """
+        self.raw_patterns[name] = "(?:" + pattern + ")"
+        self.virtual[name] = virtual
+
+        try:
+            self.patterns[name] = ("(?:" + pattern + ")") % self.patterns
+        except KeyError as e:
+            raise (Exception, "Unknown pattern name: %s" % str(e))
+
+    def parse(self, pattern_name, text):
+        """ Parses 'text' with pattern 'pattern_name' and returns parse tree """
+
+        # build pattern with subgroups
+        sub_dict = {}
+        subpattern_names = []
+        for s in re.finditer("%\(.*?\)s", self.raw_patterns[pattern_name]):
+            subpattern_name = s.group()[2:-2]
+            if not self.virtual[subpattern_name]:
+                sub_dict[subpattern_name] = "(" + self.patterns[
+                    subpattern_name] + ")"
+                subpattern_names.append(subpattern_name)
+            else:
+                sub_dict[subpattern_name] = self.patterns[subpattern_name]
+
+        pattern = "^" + (self.raw_patterns[pattern_name] % sub_dict) + "$"
+
+        # do matching
+        m = re.match(pattern, text)
+
+        if m == None:
+            return None
+
+        # build tree recursively by parsing subgroups
+        tree = {"TEXT": text}
+
+        for i in range(len(subpattern_names)):
+            text_part = m.group(i + 1)
+            if not text_part == None:
+                subpattern = subpattern_names[i]
+                tree[subpattern] = self.parse(subpattern, text_part)
+
+        return tree
+
+
+position_parser = Parser()
+position_parser.add("direction_ns", r"[NSns]")
+position_parser.add("direction_ew", r"[EOWeow]")
+position_parser.add("decimal_separator", r"[\.,]", True)
+position_parser.add("sign", r"[+-]")
+
+position_parser.add("nmea_style_degrees", r"[0-9]{2,}")
+position_parser.add("nmea_style_minutes",
+                    r"[0-9]{2}(?:%(decimal_separator)s[0-9]*)?")
+position_parser.add(
+    "nmea_style", r"%(sign)s?\s*%(nmea_style_degrees)s%(nmea_style_minutes)s")
+
+position_parser.add(
+    "number",
+    r"[0-9]+(?:%(decimal_separator)s[0-9]*)?|%(decimal_separator)s[0-9]+")
+
+position_parser.add("plain_degrees", r"(?:%(sign)s\s*)?%(number)s")
+
+position_parser.add("degree_symbol", r"°", True)
+position_parser.add("minutes_symbol", r"'|′|`|´", True)
+position_parser.add("seconds_symbol",
+                    r"%(minutes_symbol)s%(minutes_symbol)s|″|\"",
+                    True)
+position_parser.add("degrees", r"%(number)s\s*%(degree_symbol)s")
+position_parser.add("minutes", r"%(number)s\s*%(minutes_symbol)s")
+position_parser.add("seconds", r"%(number)s\s*%(seconds_symbol)s")
+position_parser.add(
+    "degree_coordinates",
+    "(?:%(sign)s\s*)?%(degrees)s(?:[+\s]*%(minutes)s)?(?:[+\s]*%(seconds)s)?|(?:%(sign)s\s*)%(minutes)s(?:[+\s]*%(seconds)s)?|(?:%(sign)s\s*)%(seconds)s"
+)
+
+position_parser.add(
+    "coordinates_ns",
+    r"%(nmea_style)s|%(plain_degrees)s|%(degree_coordinates)s")
+position_parser.add(
+    "coordinates_ew",
+    r"%(nmea_style)s|%(plain_degrees)s|%(degree_coordinates)s")
+
+position_parser.add(
+    "position", """\
+\s*%(direction_ns)s\s*%(coordinates_ns)s[,;\s]*%(direction_ew)s\s*%(coordinates_ew)s\s*|\
+\s*%(direction_ew)s\s*%(coordinates_ew)s[,;\s]*%(direction_ns)s\s*%(coordinates_ns)s\s*|\
+\s*%(coordinates_ns)s\s*%(direction_ns)s[,;\s]*%(coordinates_ew)s\s*%(direction_ew)s\s*|\
+\s*%(coordinates_ew)s\s*%(direction_ew)s[,;\s]*%(coordinates_ns)s\s*%(direction_ns)s\s*|\
+\s*%(coordinates_ns)s[,;\s]+%(coordinates_ew)s\s*\
+""")
+
+
+def get_number(b):
+    """ Takes appropriate branch of parse tree and returns float. """
+    s = b["TEXT"].replace(",", ".")
+    return float(s)
+
+
+def get_coordinate(b):
+    """ Takes appropriate branch of the parse tree and returns degrees as a float. """
+
+    r = 0.
+
+    if b.get("nmea_style"):
+        if b["nmea_style"].get("nmea_style_degrees"):
+            r += get_number(b["nmea_style"]["nmea_style_degrees"])
+        if b["nmea_style"].get("nmea_style_minutes"):
+            r += get_number(b["nmea_style"]["nmea_style_minutes"]) / 60.
+        if b["nmea_style"].get(
+                "sign") and b["nmea_style"]["sign"]["TEXT"] == "-":
+            r *= -1.
+    elif b.get("plain_degrees"):
+        r += get_number(b["plain_degrees"]["number"])
+        if b["plain_degrees"].get(
+                "sign") and b["plain_degrees"]["sign"]["TEXT"] == "-":
+            r *= -1.
+    elif b.get("degree_coordinates"):
+        if b["degree_coordinates"].get("degrees"):
+            r += get_number(b["degree_coordinates"]["degrees"]["number"])
+        if b["degree_coordinates"].get("minutes"):
+            r += get_number(b["degree_coordinates"]["minutes"]["number"]) / 60.
+        if b["degree_coordinates"].get("seconds"):
+            r += get_number(
+                b["degree_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list