Коммит 630f1177 создал по автору durman's avatar durman
Просмотр файлов

Remove monad tree

владелец b6e884f3
......@@ -11,10 +11,10 @@ root_modules = [
]
core_modules = [
"monad_properties", "sv_custom_exceptions",
"sv_custom_exceptions",
"node_id_dict", "links", "sockets",
"handlers", "update_system", "upgrade_nodes",
"monad", "events", "node_group", "group_handlers"
"events", "node_group", "group_handlers"
]
def sv_register_modules(modules):
......
......@@ -57,7 +57,6 @@ class GroupEvent:
class BlenderEventsTypes(Enum):
tree_update = auto() # this updates is calling last with exception of creating new node
monad_tree_update = auto()
node_update = auto() # it can be called last during creation new node event
add_node = auto() # it is called first in update wave
copy_node = auto() # it is called first in update wave
......
......@@ -42,13 +42,9 @@ def sverchok_trees():
yield ng
def get_all_sverchok_affiliated_trees():
sv_types = {'SverchCustomTreeType', 'SverchGroupTreeType', 'SvGroupTree'}
sv_types = {'SverchCustomTreeType', 'SvGroupTree'}
return list(ng for ng in bpy.data.node_groups if ng.bl_idname in sv_types and ng.nodes)
def update_all_monads_found():
for monad in (ng for ng in bpy.data.node_groups if ng.bl_idname == 'SverchGroupTreeType'):
if monad.input_node and monad.output_node:
monad.update_cls()
def ensure_all_encountered_nodes_are_valid(sv_trees):
for ng in sv_trees:
......@@ -195,8 +191,6 @@ def sv_post_load(scene):
# ensure current nodeview view scale / location parameters reflect users' system settings
node_tree.SverchCustomTree.update_gl_scale_info(None, "sv_post_load")
update_all_monads_found()
sv_trees = get_all_sverchok_affiliated_trees()
ensure_all_encountered_nodes_are_valid(sv_trees)
......
Это отличие свёрнуто
# 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 #####
import sys
import re
import bpy
from bpy.types import PropertyGroup
from bpy.props import (
FloatProperty, FloatVectorProperty, IntProperty, StringProperty, EnumProperty)
class PropsBase:
# ignored /internal names
internal_names = {"prop_name", "attr", "update", "bl_rna", "rna_type"}
prop_name: StringProperty(description="Internal name")
def get_settings(self):
settings = {k:v for k, v in self.items() if k not in self.internal_names}
return settings
def set_settings(self, settings):
for key, value in settings.items():
setattr(self, key, value)
def from_socket(self, socket):
p_type, p_dict = getattr(socket.node.rna_type, socket.prop_name)
self.set_settings(p_dict)
self.prop_name = socket.prop_name
def draw(self, context, layout):
"""
names = [name for name in dir(self) if not name in self.internal_names and not name.startswith("__")]
for name in sorted(names):
layout.prop(self, name)
"""
layout.prop(self, "default")
layout.prop(self, "soft_min")
layout.prop(self, "soft_max")
layout.prop(self, "description")
# FloatProperty
'''
bpy.props.FloatProperty(name="", description="", default=0.0,
min=sys.float_info.min, max=sys.float_info.max,
soft_min=sys.float_info.min, soft_max=sys.float_info.max,
step=3, precision=2, options={'ANIMATABLE'}, subtype='NONE',
unit='NONE', update=None, get=None, set=None)
subtype (string) – Enumerator in ['PIXEL', 'UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].
unit (string) – Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].
'''
unit_items = (
('NONE', 'NONE', 'NONE', 0),
('LENGTH', 'LENGTH', 'LENGTH', 1),
('AREA', 'AREA', 'AREA', 2),
('VOLUME', 'VOLUME', 'VOLUME', 3),
('ROTATION', 'ROTATION', 'ROTATION', 4),
('TIME', 'TIME', 'TIME', 5),
('VELOCITY', 'VELOCITY', 'VELOCITY', 6),
('ACCELERATION', 'ACCELERATION', 'ACCELERATION', 7)
)
float_items = (
('PIXEL', 'PIXEL', 'PIXEL', 0),
('UNSIGNED', 'UNSIGNED', 'UNSIGNED', 1),
('PERCENTAGE', 'PERCENTAGE', 'PERCENTAGE', 2),
('FACTOR', 'FACTOR', 'FACTOR', 3),
('ANGLE', 'ANGLE', 'ANGLE', 4),
('TIME', 'TIME', 'TIME', 5),
('DISTANCE', 'DISTANCE', 'DISTANCE', 6),
('NONE', 'NONE', 'NONE', 7)
)
class SvFloatPropertySettingsGroup(PropertyGroup, PropsBase):
def get_settings(self):
settings = super().get_settings()
# okay this code could perhaps be more clever
# but protects from gettings the index of the EnumProperty
# instead of the appropriate string value
if "subtype" in settings:
ref_nr = settings['subtype']
for item in float_items:
if ref_nr == item[-1]:
settings['subtype'] = item[0]
break
if "unit" in settings:
ref_nr = settings['unit']
for item in unit_items:
if ref_nr == item[-1]:
settings['unit'] = item[0]
break
return settings
name: StringProperty(description="Show name")
description: StringProperty()
default: FloatProperty(default=0.0)
min: FloatProperty(default=sys.float_info.min)
max: FloatProperty(default=sys.float_info.max)
soft_min: FloatProperty(default=sys.float_info.min)
soft_max: FloatProperty(default=sys.float_info.max)
step: IntProperty(default=3)
precision: IntProperty(default=2)
subtype: EnumProperty(items=float_items, name="Subtype", default='NONE')
unit: EnumProperty(items=unit_items, name="Unit", default='NONE')
# INT PROPERTY
'''
bpy.props.IntProperty(name="", description="",
default=0, min=-2**31, max=2**31-1,
soft_min=-2**31, soft_max=2**31-1,
step=1, options={'ANIMATABLE'},
subtype='NONE', update=None, get=None, set=None)
Returns a new int property definition.
Parameters:
name (string) – Name used in the user interface.
description (string) – Text used for the tooltip and api documentation.
min (int) – Hard minimum, trying to assign a value below will silently assign this minimum instead.
max (int) – Hard maximum, trying to assign a value above will silently assign this maximum instead.
soft_max (int) – Soft maximum (<= max), user won’t be able to drag the widget above this value in the UI.
soft_min (int) – Soft minimum (>= min), user won’t be able to drag the widget below this value in the UI.
step (int) – Step of increment/decrement in UI, in [1, 100], defaults to 1 (WARNING: unused currently!).
options (set) – Enumerator in [‘HIDDEN’, ‘SKIP_SAVE’, ‘ANIMATABLE’, ‘LIBRARY_EDITABLE’, ‘PROPORTIONAL’,’TEXTEDIT_UPDATE’].
subtype (string) – Enumerator in [‘PIXEL’, ‘UNSIGNED’, ‘PERCENTAGE’, ‘FACTOR’, ‘ANGLE’, ‘TIME’, ‘DISTANCE’, ‘NONE’].
update (function) – Function to be called when this value is modified, This function must take 2 values (self, context) and return None. Warning there are no safety checks to avoid infinite recursion.
get (function) – Function to be called when this value is ‘read’, This function must take 1 value (self) and return the value of the property.
set (function) – Function to be called when this value is ‘written’, This function must take 2 values (self, value) and return None.
'''
int_subtypes = [
('PIXEL', 'PIXEL', 'PIXEL', 0),
('UNSIGNED', 'UNSIGNED', 'UNSIGNED', 1),
('PERCENTAGE', 'PERCENTAGE', 'PERCENTAGE', 2),
('FACTOR', 'FACTOR', 'FACTOR', 3),
('ANGLE', 'ANGLE', 'ANGLE', 4),
('TIME', 'TIME', 'TIME', 5),
('DISTANCE', 'DISTANCE', 'DISTANCE', 6),
('NONE', 'NONE', 'NONE', 7)
]
class SvIntPropertySettingsGroup(PropertyGroup, PropsBase):
def get_settings(self):
# okay this code could perhaps be more clever
# but protects from gettings the index of the EnumProperty
# instead of the appropriate string value
settings = super().get_settings()
if "subtype" in settings:
ref_nr = settings['subtype']
for item in int_subtypes:
if ref_nr == item[-1]:
settings['subtype'] = item[0]
break
return settings
name: StringProperty(description="Show name")
description: StringProperty()
default: IntProperty(default=0)
min: IntProperty(default=-2**31)
max: IntProperty(default=2**31-1)
soft_min: IntProperty(default=-2**31)
soft_max: IntProperty(default=2**31-1)
step: IntProperty(default=1) # not used
subtype: EnumProperty(items=float_items, name="Subtype", default='NONE')
def find_hightest_num_in_matching_params(monad_prop_names, kind):
regex = "^(?P<kind>ints|floats)_(?P<number>\d+)_(?P<variable>\S+)$"
nums = [1]
for name in monad_prop_names:
matches = re.search(regex, name)
if matches and matches.group('kind') == kind:
nums.append(int(matches.group('number')))
return max(nums)
def ensure_unique(monad_prop_names, new_prop_name):
# can be used unchanged
if not (new_prop_name in monad_prop_names):
return new_prop_name
print(f"{new_prop_name} (prop_name) is used.. making a new one")
# find the highest token and return it plus one
kind, num, variable = new_prop_name.split('_', 2)
num = find_hightest_num_in_matching_params(monad_prop_names, kind)
proposed_new_name = f"{kind}_{int(num) + 1}_{variable}"
print(f"new prop_name {proposed_new_name}")
return proposed_new_name
classes = [
SvFloatPropertySettingsGroup,
SvIntPropertySettingsGroup
]
def register():
for class_name in classes:
bpy.utils.register_class(class_name)
def unregister():
for class_name in reversed(classes):
bpy.utils.unregister_class(class_name)
......@@ -307,9 +307,6 @@ def do_update_heat_map(node_list, nodes):
nodes[name].color = cold.lerp(hot, t / t_max)
def update_error_nodes(ng, name, err=Exception):
if ng.bl_idname == "SverchGroupTreeType":
return # ignore error color inside of monad
if "error nodes" in ng:
error_nodes = ast.literal_eval(ng["error nodes"])
else:
......@@ -413,7 +410,6 @@ def do_update_general(node_list, nodes, procesed_nodes=set()):
exception("Node %s had exception: %s", node_name, err)
if hasattr(ng, "sv_show_error_in_tree"):
# not yet supported in monad trees..
if ng.sv_show_error_in_tree:
error_text = traceback.format_exc()
start_exception_drawing_with_bgl(ng, node_name, error_text, err)
......
......@@ -41,7 +41,7 @@ from sverchok.utils.exception_drawing_with_bgl import clear_exception_drawing_wi
class SvNodeTreeCommon(object):
'''
Common methods shared between Sverchok node trees (normal and monad trees)
Common methods shared between Sverchok node trees
'''
# auto update toggle of the node tree
......@@ -61,28 +61,10 @@ class SvNodeTreeCommon(object):
self.tree_id_memory = str(hash(self) ^ hash(time.monotonic()))
return self.tree_id_memory
def get_groups(self):
"""
It gets monads of node tree,
Update them (the sv_update method will check if anything changed inside the monad
and will change the monad outputs in that case)
Return the monads that have changed (
to inform the caller function that the nodes downstream have to be updated with the new data)
"""
affected_groups =[]
for node in self.nodes:
if 'SvGroupNode' in node.bl_idname:
sub_tree = node.monad
sub_tree.sv_update()
if sub_tree.has_changed:
affected_groups.append(node)
sub_tree.has_changed = False
return affected_groups
def sv_update(self):
"""
the method checks if anything changed inside the normal tree or monad
and update them if necessary
the method checks if anything changed inside the tree
and update it if necessary
"""
self.sv_links.create_new_links(self)
if self.sv_links.links_have_changed(self):
......@@ -90,8 +72,6 @@ class SvNodeTreeCommon(object):
build_update_list(self)
process_from_nodes(self.sv_links.get_nodes(self))
self.sv_links.store_links_cache(self)
else:
process_from_nodes(self.get_groups())
def animation_update(self):
"""Find animatable nodes and update from them"""
......
......@@ -62,13 +62,6 @@ class SvDebugPrintNode(bpy.types.Node, SverchCustomTreeNode):
if not self.print_data:
return
if self.id_data.bl_idname == "SverchGroupTreeType":
instance = self.id_data.instances[0] ## uh oh..
if instance.loop_me:
index = instance.monad["current_index"]
total = instance.monad["current_total"]
self.info(f"Iteration/Total: {index} / {total}")
for i, socket in enumerate(self.inputs):
if socket.is_linked and self.print_socket[i]:
self.info(socket.sv_get(deepcopy=False))
......
......@@ -77,7 +77,7 @@ def reload_old(ng=False):
else:
for ng in bpy.data.node_groups:
reload_old(ng)
#if ng.bl_idname in { 'SverchCustomTreeType', 'SverchGroupTreeType'}:
#if ng.bl_idname in { 'SverchCustomTreeType', }:
# reload_old(ng)
def load_old(ng):
......
......@@ -39,7 +39,7 @@ from sverchok.utils.extra_categories import external_node_docs
def displaying_sverchok_nodes(context):
return context.space_data.tree_type in {'SverchCustomTreeType', 'SverchGroupTreeType'}
return context.space_data.tree_type in {'SverchCustomTreeType', }
def node_show_branch(self, context):
if not displaying_sverchok_nodes(context):
......
......@@ -33,7 +33,7 @@ from sverchok.ui.sv_icons import node_icon, icon, get_icon_switch, custom_icon
from sverchok.ui import presets
# from nodeitems_utils import _node_categories
sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
sv_tree_types = {'SverchCustomTreeType', }
node_cats = make_node_cats()
def category_has_nodes(cat_name):
......
......@@ -22,7 +22,6 @@ from bpy.types import Operator
from sverchok.ui.nodeview_rclick_menu import get_output_sockets_map
from sverchok.utils.sv_node_utils import frame_adjust
sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
def offset_node_location(existing_node, new_node, offset):
new_node.location = existing_node.location.x + offset[0] + existing_node.width, existing_node.location.y + offset[1]
......@@ -146,7 +145,7 @@ class SvTemporalViewerOperator(Operator):
space = context.space_data
if not space.type == "NODE_EDITOR":
return
return space.tree_type in sv_tree_types
return space.tree_type in {'SverchCustomTreeType', }
def execute(self, context):
......
......@@ -18,10 +18,7 @@
# ##### END GPL LICENSE BLOCK #####
import bpy
from sverchok.ui.nodeview_rclick_menu import get_output_sockets_map
from sverchok.utils.sv_node_utils import frame_adjust
sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
def similar_sockets(node_out, node_in, term):
socket_out, socket_in = -1, -1
......@@ -95,7 +92,7 @@ class SvNodeConnectorOperator(bpy.types.Operator):
space = context.space_data
tree_type = space.tree_type
return space.type == 'NODE_EDITOR' and tree_type in sv_tree_types
return space.type == 'NODE_EDITOR' and tree_type in {'SverchCustomTreeType', }
def execute(self, context):
verts_edges_faces_connector(self, context)
......
......@@ -95,7 +95,7 @@ def delete_data_block(data_block) -> None:
def get_sv_trees():
return [ng for ng in bpy.data.node_groups if ng.bl_idname in {'SverchCustomTreeType', 'SverchGroupTreeType'}]
return [ng for ng in bpy.data.node_groups if ng.bl_idname in {'SverchCustomTreeType',}]
# ~~~~ encapsulation Blender objects ~~~~
......
......@@ -198,13 +198,6 @@ def setLevel(level):
for handler in logging.getLogger().handlers:
handler.setLevel(level)
def inject_logger(name):
logger = getLogger(name)
globals()["debug"] = logger.debug
globals()["info"] = logger.info
globals()["warning"] = logger.warning
globals()["error"] = logger.error
globals()["exception"] = logger.exception
consoleHandler = None
......
......@@ -19,19 +19,17 @@
import os
import importlib.util as getutil
import bpy
import nodeitems_utils
import sverchok
from sverchok.menu import make_node_cats
from sverchok.utils import get_node_class_reference
from sverchok.utils.docstring import SvDocstring
from sverchok.ui.sv_icons import custom_icon
from sverchok.utils.sv_default_macros import macros, DefaultMacros
from nodeitems_utils import _node_categories
from sverchok.utils.extra_categories import get_extra_categories
# pylint: disable=c0326
sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
node_cats = make_node_cats()
addon_name = sverchok.__name__
......@@ -146,7 +144,7 @@ class SvExtraSearch(bpy.types.Operator):
@classmethod
def poll(cls, context):
tree_type = context.space_data.tree_type
if tree_type in sv_tree_types:
if tree_type in {'SverchCustomTreeType', }:
return True
def bl_idname_from_bl_label(self, context):
......
......@@ -5,8 +5,6 @@
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE
sv_tree_types = {'SverchCustomTreeType', 'SverchGroupTreeType'}
def recursive_framed_location_finder(node, loc_xy):
locx, locy = loc_xy
......@@ -25,23 +23,6 @@ def frame_adjust(caller_node, new_node):
locx, locy = recursive_framed_location_finder(new_node, loc_xy)
new_node.location = locx, locy
def absolute_location_generic(node):
"""
all nodes of type Sverchok Custom will have the absolute_location attribute,
but some nodes (at the moment only ReRoute) are "part of the pynodes API" and can not
be augmented, so this function will return the appropriate location for all nodes
"""
if hasattr(node, 'absolute_location'):
return node.absolute_location
return recursive_framed_location_finder(node, node.location[:])
def scaled_dpi():
"""
find the xy position for the blf content, adjusted for screen res.
"""
ps = bpy.context.preferences.system
return ps.dpi * ps.pixel_size / 72
def nodes_bounding_box(selected_nodes):
"""
......
......@@ -5,9 +5,9 @@
# SPDX-License-Identifier: GPL3
# License-Filename: LICENSE
import re
import bpy
from sverchok.utils.logging import getLogger, inject_logger
from sverchok.utils.logging import getLogger
def has_selection(self, text):
return not (text.select_end_line == text.current_line and
......@@ -42,7 +42,7 @@ class SvNodeRefreshFromTextEditor(bpy.types.Operator):
edit_text = bpy.context.edit_text
text_file_name = edit_text.name
is_sv_tree = lambda ng: ng.bl_idname in {'SverchCustomTreeType', 'SverchGroupTreeType'}
is_sv_tree = lambda ng: ng.bl_idname in {'SverchCustomTreeType', }
ngs = list(filter(is_sv_tree, ngs))
if not ngs:
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать