Не подтверждена Коммит f75719f4 создал по автору Dealga McArdle's avatar Dealga McArdle Зафиксировано автором GitHub
Просмотр файлов

Snlite corrections 8 (#4210)

* change tooltip

* rewrite dynamic enum creator

* small back end changes to printing and comments

* add storage locally

* Add corresponding clear func
владелец 5a3492f8
...@@ -20,6 +20,7 @@ import os ...@@ -20,6 +20,7 @@ import os
import sys import sys
import ast import ast
import json import json
import textwrap
import traceback import traceback
import numpy as np import numpy as np
...@@ -30,7 +31,7 @@ from sverchok.utils.sv_update_utils import sv_get_local_path ...@@ -30,7 +31,7 @@ from sverchok.utils.sv_update_utils import sv_get_local_path
from sverchok.utils.snlite_importhelper import ( from sverchok.utils.snlite_importhelper import (
UNPARSABLE, set_autocolor, parse_sockets, are_matched) UNPARSABLE, set_autocolor, parse_sockets, are_matched)
from sverchok.utils.snlite_utils import vectorize, ddir from sverchok.utils.snlite_utils import vectorize, ddir, sv_njit, sv_njit_clear
from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata, pydata_from_bmesh from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata, pydata_from_bmesh
from sverchok.node_tree import SverchCustomTreeNode from sverchok.node_tree import SverchCustomTreeNode
from sverchok.utils.nodes_mixins.sv_animatable_nodes import SvAnimatableNode from sverchok.utils.nodes_mixins.sv_animatable_nodes import SvAnimatableNode
...@@ -107,29 +108,34 @@ class SvScriptNodeLiteTextImport(bpy.types.Operator): ...@@ -107,29 +108,34 @@ class SvScriptNodeLiteTextImport(bpy.types.Operator):
class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode): class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode):
''' snl SN Lite /// a lite version of SN '''
"""
Triggers: snl
Tooltip: Script Node Lite
This code represents a conscious weighing of conveniences to the user, vs somewhat harder to understand
code under the hood. This code evolved as design specs changed, while providing continued support for
previous implementation details.
"""
bl_idname = 'SvScriptNodeLite' bl_idname = 'SvScriptNodeLite'
bl_label = 'Scripted Node Lite' bl_label = 'Scripted Node Lite'
bl_icon = 'SCRIPTPLUGINS' bl_icon = 'SCRIPTPLUGINS'
def custom_enum_func(self, context): def return_enumeration(self, enum_name=""):
ND = self.node_dict.get(hash(self)) ND = self.node_dict.get(hash(self))
if ND: if ND:
enum_list = ND['sockets']['custom_enum'] enum_list = ND['sockets'][enum_name]
if enum_list: if enum_list:
return [(ce, ce, '', idx) for idx, ce in enumerate(enum_list)] return [(ce, ce, '', idx) for idx, ce in enumerate(enum_list)]
return [("A", "A", '', 0), ("B", "B", '', 1)] return [("A", "A", '', 0), ("B", "B", '', 1)]
def custom_enum_func_2(self, context): def custom_enum_func(self, context):
ND = self.node_dict.get(hash(self)) return self.return_enumeration(enum_name='custom_enum')
if ND:
enum_list = ND['sockets']['custom_enum_2']
if enum_list:
return [(ce, ce, '', idx) for idx, ce in enumerate(enum_list)]
return [("A", "A", '', 0), ("B", "B", '', 1)] def custom_enum_func_2(self, context):
return self.return_enumeration(enum_name='custom_enum_2')
def custom_callback(self, context, operator): def custom_callback(self, context, operator):
...@@ -205,15 +211,15 @@ class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode): ...@@ -205,15 +211,15 @@ class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode):
for idx, (socket_description) in enumerate(v): for idx, (socket_description) in enumerate(v):
""" """
Socket description at the moment of typing is list of: [ Socket description at the moment of typing is list of: [
socket_type: str, socket_type: str,
socket_name: str, socket_name: str,
default: int value, float value or None, default: int value, float value or None,
nested: int] nested: int]
""" """
default_value = socket_description[2] default_value = socket_description[2]
if socket_description is UNPARSABLE: if socket_description is UNPARSABLE:
print(socket_description, idx, 'was unparsable') self.info(f"{socket_description}, {idx}, was unparsable")
return return
if len(sockets) > 0 and idx in set(range(len(sockets))): if len(sockets) > 0 and idx in set(range(len(sockets))):
...@@ -419,6 +425,8 @@ class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode): ...@@ -419,6 +425,8 @@ class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode):
'bpy': bpy, 'bpy': bpy,
'np': np, 'np': np,
'ddir': ddir, 'ddir': ddir,
'sv_njit': sv_njit,
'sv_njit_clear': sv_njit_clear,
'bmesh_from_pydata': bmesh_from_pydata, 'bmesh_from_pydata': bmesh_from_pydata,
'pydata_from_bmesh': pydata_from_bmesh 'pydata_from_bmesh': pydata_from_bmesh
}) })
...@@ -556,11 +564,14 @@ class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode): ...@@ -556,11 +564,14 @@ class SvScriptNodeLite(bpy.types.Node, SverchCustomTreeNode, SvAnimatableNode):
if include_name == new_text.name: if include_name == new_text.name:
continue continue
print('| in', self.name, 'the importer encountered') multi_string_msg = textwrap.dedent(f"""\
print('| an include called', include_name, '. While trying') | in {self.name} the importer encountered
print('| to write this file to bpy.data.texts another file') | an include called {include_name}. While trying
print('| with the same name was encountered. The importer') | to write this file to bpy.data.texts another file
print('| automatically made a datablock called', new_text.name) | with the same name was encountered. The importer
| automatically made a datablock called {new_text.name}.
""")
self.info(multi_string_msg)
def load_from_json(self, node_data: dict, import_version: float): def load_from_json(self, node_data: dict, import_version: float):
......
...@@ -17,10 +17,13 @@ ...@@ -17,10 +17,13 @@
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
import bpy from logging import info
import bpy
from sverchok.data_structure import match_long_repeat from sverchok.data_structure import match_long_repeat
njit_function_storage = {}
def vectorize(all_data): def vectorize(all_data):
...@@ -42,3 +45,22 @@ def ddir(content, filter_str=None): ...@@ -42,3 +45,22 @@ def ddir(content, filter_str=None):
else: else:
vals = [n for n in dir(content) if not n.startswith('__') and filter_str in n] vals = [n for n in dir(content) if not n.startswith('__') and filter_str in n]
return vals return vals
def sv_njit(function_to_njit, parameters):
fn_name = function_to_njit.__name__
njit_func = njit_function_storage.get(fn_name)
if not njit_func:
result = function_to_njit(*parameters)
njit_function_storage[fn_name] = function_to_njit
info(f"caching function: {fn_name}")
else:
result = njit_func(*parameters)
return result
def sv_njit_clear(function_to_njit):
fn_name = function_to_njit.__name__
njit_func = njit_function_storage.get(fn_name)
if njit_func:
del njit_function_storage[fn_name]
info(f"cleared cached function: {fn_name}")
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать