8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev#!/usr/bin/env python
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev"""
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevsynfig_fileformat.py
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevSynfig file format utilities
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevCopyright (C) 2011 Nikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevThis program is free software; you can redistribute it and/or modify
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevit under the terms of the GNU General Public License as published by
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevthe Free Software Foundation; either version 2 of the License, or
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev(at your option) any later version.
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevThis program is distributed in the hope that it will be useful,
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevbut WITHOUT ANY WARRANTY; without even the implied warranty of
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevGNU General Public License for more details.
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevYou should have received a copy of the GNU General Public License
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevalong with this program; if not, write to the Free Software
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita KitaevFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev"""
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev###### Constants ##########################################
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevkux = 60.0 # Number of SVG units (pixels) per Synfig "unit"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevgamma = 2.2
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevtangent_scale = 3.0 # Synfig tangents are scaled by a factor of 3
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev###### Layer parameters, types, and default values ########
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers = {}
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev# Layer_Composite is the parent of most layers
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevdefault_composite = {
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "z_depth": ["real", 0.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "amount": ["real", 1.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "blend_method": ["integer", 0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev }
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["PasteCanvas"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["PasteCanvas"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "origin": ["vector", [0.0, 0.0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "canvas": ["canvas", None],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "zoom": ["real", 0.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "time_offset": ["time", "0s"],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "children_lock": ["bool", False],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "focus": ["vector", [0.0, 0.0]]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev## Layers in mod_geometry
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["circle"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["circle"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "color": ["color", [0,0,0,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "radius": ["real", 1.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "feather": ["real", 0.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "origin": ["vector", [0.0, 0.0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "invert": ["bool", False],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "falloff": ["integer", 2]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["rectangle"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["rectangle"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "color": ["color", [0,0,0,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "point1": ["vector", [0,0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "point2": ["vector", [1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "expand": ["real", 0.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "invert": ["bool", False]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevdefault_shape = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevdefault_shape.update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "color": ["color", [0,0,0,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "origin": ["vector", [0.0, 0.0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "invert": ["bool", False],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "antialias": ["bool", True],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "feather": ["real", 0.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "blurtype": ["integer", 1],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "winding_style": ["integer", 0]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["region"] = default_shape.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["region"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "bline": ["bline", None]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["outline"] = default_shape.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["outline"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "bline": ["bline", None],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "round_tip[0]": ["bool", True],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "round_tip[1]": ["bool", True],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "sharp_cusps": ["bool", True],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "width": ["real", 1.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "loopyness": ["real", 1.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "expand": ["real", 0.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "homogeneous_width": ["bool", True]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev## Layers in mod_gradient
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["linear_gradient"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["linear_gradient"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "p1": ["vector", [0,0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "p2": ["vector", [1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "gradient": ["gradient", {0.0:[0,0,0,1], 1.0:[1,1,1,1]} ],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "loop": ["bool", False],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "zigzag": ["bool", False]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["radial_gradient"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["radial_gradient"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "gradient": ["gradient", {0.0:[0,0,0,1], 1.0:[1,1,1,1]} ],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "center": ["vector", [0,0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "radius": ["real", 1.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "loop": ["bool", False],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "zigzag": ["bool", False]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev## Layers in lyr_std
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["import"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["import"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "tl": ["vector", [-1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "br": ["vector", [1,-1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "c": ["integer", 1],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "gamma_adjust": ["real", 1.0],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "filename": ["string", ""], # <string>foo</string>
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "time_offset": ["time", "0s"]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev# transforms are not blending
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["warp"] = {
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "src_tl": ["vector", [-1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "src_br": ["vector", [1,-1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "dest_tl": ["vector", [-1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "dest_tr": ["vector", [1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "dest_br": ["vector", [1,-1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "dest_bl": ["vector", [-1,-1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "clip": ["bool", False],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "horizon": ["real", 4.0]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev }
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["rotate"] = {
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "origin": ["vector", [0.0, 0.0]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "amount": ["angle", 0] # <angle value=.../>
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev }
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["translate"] = {
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "origin": ["vector", [0.0, 0.0]]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev }
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev## Layers in mod_filter
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["blur"] = default_composite.copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayers["blur"].update({
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "size": ["vector", [1,1]],
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "type": ["integer", 3] # 1 is fast gaussian, 3 is regular
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev })
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev###### Layer versions #####################################
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevlayer_versions = {
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "outline" : "0.2",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "rectangle" : "0.2",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "linear_gradient" : "0.0",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev "blur" : "0.2",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev None : "0.1" # default
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev }
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev###### Blend Methods ######################################
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevblend_method_names = {
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 0 : "composite",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 1 : "straight",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 13 : "onto",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 21 : "straight onto",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 12 : "behind",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 16 : "screen",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 20 : "overlay",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 17 : "hand light",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 6 : "multiply",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 7 : "divide",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 4 : "add",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 5 : "subtract",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 18 : "difference",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 2 : "brighten",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 3 : "darken",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 8 : "color",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 9 : "hue",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 10 : "saturation",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 11 : "luminance",
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 14 : "alpha brighten", #deprecated
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 15 : "alpha darken", #deprecated
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev 19 : "alpha over" #deprecated
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev }
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevblend_methods = dict((v, k) for (k, v) in blend_method_names.iteritems())
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev###### Functions ##########################################
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevdef paramType(layer, param, value=None):
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if layer in layers.keys():
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev layer_params = layers[layer]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if param in layer_params.keys():
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return layer_params[param][0]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev else:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev raise Exception, "Invalid parameter type for layer"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev else:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev # Unknown layer, try to determine parameter type based on value
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if value is None:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev raise Exception, "No information for given layer"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if type(value) == int:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "integer"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif type(value) == float:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "real"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif type(value) == bool:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "bool"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif type(value) == dict:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if "points" in value.keys():
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "bline"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif 0.0 in value.keys():
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "gradient"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev else:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev raise Exception, "Could not automatically determine parameter type"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif type(value) == list:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if len(value) == 2:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "vector"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif len(value) == 3 or len(value) == 4:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "color"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev else:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev # The first two could also be canvases
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "canvas"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev elif type(value) == str:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return "string"
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevdef defaultLayerVersion(layer):
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if layer in layer_versions.keys():
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return layer_versions[layer]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev else:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return layer_versions[None]
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaevdef defaultLayerParams(layer):
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev if layer in layers.keys():
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return layers[layer].copy()
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev else:
8fe37a993fbb0c0a84a7ab4a77cd83c87162c2daNikita Kitaev return {}