Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute only nodes connected to active Viewers #4738

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 65 additions & 13 deletions node_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from bpy.props import StringProperty, BoolProperty, EnumProperty
from bpy.types import NodeTree, NodeSocket

from sverchok.core.update_system import SearchTree
from sverchok.core.sv_custom_exceptions import SvNoDataError, DependencyError
import sverchok.core.events as ev
import sverchok.dependencies as sv_deps
Expand Down Expand Up @@ -227,6 +228,7 @@ def on_draft_mode_changed(self, context):
def update(self):
"""This method is called if collection of nodes or links of the tree was changed"""
handle_event(ev.TreeEvent(self))
self.disable_nodes()

def force_update(self):
"""Update whole tree from scratch"""
Expand All @@ -251,6 +253,18 @@ def process_ani(self, frame_changed: bool, animation_playing: bool):
"""
handle_event(ev.AnimationEvent(self, frame_changed, animation_playing))

def disable_nodes(self):
st = SearchTree(self)
active = []
for node in self.nodes:
if node.bl_idname in {"NodeReroute", "NodeFrame"}:
continue
node.set_temp_color('disable', (0.081, 0.081, 0.081))
if node.is_output and node.is_active:
active.append(node)
for node in st.nodes_to(active):
node.set_temp_color('disable')


class UpdateNodes:
"""Everything related with update system of nodes"""
Expand Down Expand Up @@ -335,6 +349,19 @@ def refresh_node(self, context):

![image](https://user-images.githubusercontent.com/28003269/193507101-60a28c3f-50a1-4117-a66f-25b0b4e07e13.png)"""

def update_active(self, context):
self.id_data.disable_nodes()
self.process_node(context)

is_active: BoolProperty(
name='Live',
default=True,
update=update_active,
description="When enabled this will process incoming data",
)

is_output = False

def sv_init(self, context):
"""
This method will be called during node creation
Expand Down Expand Up @@ -460,11 +487,11 @@ def update_ui(self, error=None, update_time=None):
# update error colors
if error is not None:
color = no_data_color if isinstance(error, SvNoDataError) else exception_color
self.set_temp_color(color)
self.set_temp_color('error', color)
sv_bgl.draw_text(self, str(error), error_pref + self.node_id, color, 1.3, "UP")
else:
sv_bgl.callback_disable(error_pref + self.node_id)
self.set_temp_color()
self.set_temp_color('error')

# show update timing
if update_time is not None:
Expand Down Expand Up @@ -680,6 +707,10 @@ def draw_buttons(self, context, layout):
use `SverchCustomTreeNode.sv_draw_buttons`."""
if self.id_data.bl_idname == SverchCustomTree.bl_idname:
row = layout.row(align=True)
if self.is_output:
row_ = row.row()
row_.ui_units_x = 1.5
row_.prop(self, 'is_active', toggle=True)
if self.is_animation_dependent:
row.prop(self, 'is_animatable', icon='ANIM', icon_only=True)
if self.is_scene_dependent:
Expand All @@ -700,6 +731,10 @@ def draw_buttons_ext(self, context, layout):
on a property panel of the tree editor."""
if self.id_data.bl_idname == SverchCustomTree.bl_idname:
row = layout.row(align=True)
if self.is_output:
row_ = row.row()
row_.ui_units_x = 1.5
row_.prop(self, 'is_active', toggle=True)
if self.is_animation_dependent:
row.prop(self, 'is_animatable', icon='ANIM')
if self.is_scene_dependent:
Expand Down Expand Up @@ -752,24 +787,41 @@ def sv_default_color(self):
"""Returns default color of the node which can be changed in add-on settings."""
return color_def.get_color(self.bl_idname)

def set_temp_color(self, color=None):
"""This method memorize its initial color and override it with given one
if given color is None it tries to return its initial color or do nothing"""
def set_temp_color(self, color_name: str, color=None):
"""This method memorize its initial color and override it with given one.
The node can keep several temporary colors simultaneously. It shows only
last temp color. When of a temp colors is removed (by colling the method
without color argument) it tries to show another temp color if available
otherwise it shows user color.

`color_name` is used to distinguish temp colors of different types
"""
use_key = 'use_user_color'
color_key = 'user_color'
names_key = 'temp_colors'
if names_key not in self:
self[names_key] = dict()

# restore user or other tem color
if color is None:
if color_name in self[names_key]:
del self[names_key][color_name]
if self[names_key]: # there are other temp colors to show
self.color = list(self[names_key].values())[0]
# looks like the node should return its initial color (user choice)
if 'user_color' in self:
self.use_custom_color = self['use_user_color']
del self['use_user_color']
self.color = self['user_color']
del self['user_color']
elif color_key in self:
self.use_custom_color = self[use_key]
del self[use_key]
self.color = self[color_key]
del self[color_key]

# set temporary color
else:
# save overridden color (only once)
if 'user_color' not in self:
self['use_user_color'] = self.use_custom_color
self['user_color'] = self.color
if color_key not in self:
self[use_key] = self.use_custom_color
self[color_key] = self.color
self[names_key][color_name] = color
self.use_custom_color = True
self.color = color

Expand Down
1 change: 1 addition & 0 deletions nodes/exchange/gcode_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class SvExportGcodeNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvExportGcodeNode'
bl_label = 'Export G-code'
bl_icon = 'COPYDOWN'
is_output = True

last_e: FloatProperty(name="Pull", default=5.0, min=0, soft_max=10)
path_length: FloatProperty(name="Pull", default=5.0, min=0, soft_max=10)
Expand Down
1 change: 1 addition & 0 deletions nodes/logic/evolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ class SvEvolverNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvEvolverNode'
bl_label = 'Evolver'
bl_icon = 'RNA'
is_output = True

def props_changed(self, context):
if self.node_id in evolver_mem:
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/armature_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SvArmaturePropsNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvArmaturePropsNode'
bl_label = 'Armature Props'
bl_icon = 'MOD_ARMATURE'
is_output = True
is_scene_dependent = True
is_animation_dependent = True

Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/assign_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class SvAssignMaterialListNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvAssignMaterialListNode'
bl_label = "Assign Materials List"
bl_icon = 'MATERIAL'
is_output = True

@property
def is_scene_dependent(self):
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/color_uv_texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SvMeshUVColorNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvMeshUVColorNode'
bl_label = 'Set UV Color'
bl_icon = 'UV_DATA'
is_output = True
is_scene_dependent = True
is_animation_dependent = True

Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/copy_modifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SvCopyModifiersNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvCopyModifiersNode'
bl_label = 'Copy Modifiers'
bl_icon = 'MODIFIER_DATA'
is_output = True

@property
def is_scene_dependent(self):
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/custom_mesh_normals.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SvSetCustomMeshNormals(SverchCustomTreeNode, bpy.types.Node):
bl_label = 'Set Custom Normals'
bl_icon = 'SNAP_NORMAL'
sv_icon = 'SV_CUSTOM_NORMALS'
is_output = True

@property
def is_scene_dependent(self):
Expand Down
3 changes: 2 additions & 1 deletion nodes/object_nodes/getsetprop_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ class SvSetPropNodeMK2(SverchCustomTreeNode, bpy.types.Node, SvPropNodeMixin):
bl_label = 'Set Property MK2'
bl_icon = 'FORCE_VORTEX'
sv_icon = 'SV_PROP_SET'
is_output = True

def local_updateNode(self, context):
# no further interaction with the nodetree is required.
Expand All @@ -288,7 +289,7 @@ def execute_inside_throttle(self):
if s_type == "SvVerticesSocket":
inputs[0].use_prop = True

def draw_buttons(self, context, layout):
def sv_draw_buttons(self, context, layout):
layout.alert = self.bad_prop
layout.prop(self, "prop_name", text="")

Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/lattice_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SvLatticePropsNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvLatticePropsNode'
bl_label = 'Lattice Props'
bl_icon = 'MOD_LATTICE'
is_output = True
is_scene_dependent = True
is_animation_dependent = True

Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/material_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SvMaterialIndexNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvMaterialIndexNode'
bl_label = "Set Material Index"
bl_icon = 'MATERIAL'
is_output = True

@property
def is_scene_dependent(self):
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/sculpt_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SvSculptMaskNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvSculptMaskNode'
bl_label = 'Vertex Sculpt Masking'
bl_icon = 'SCULPTMODE_HLT'
is_output = True

def sv_init(self, context):
self.inputs.new('SvObjectSocket', "Object")
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/select_mesh_verts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SvSelectMeshVerts(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvSelectMeshVerts'
bl_label = 'Select Object Vertices'
bl_icon = 'EDITMODE_HLT'
is_output = True
is_animation_dependent = True
is_scene_dependent = True

Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/set_blenddata2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class SvSetDataObjectNodeMK2(SverchCustomTreeNode, bpy.types.Node):
bl_label = 'Object ID Set MK2'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_OBJECT_ID_SET'
is_output = True
is_scene_dependent = True
is_animation_dependent = True

Expand Down
3 changes: 2 additions & 1 deletion nodes/object_nodes/set_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class SvSetCollection(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvSetCollection'
bl_label = 'Set Collection'
bl_icon = 'OUTLINER_COLLECTION'
is_output = True

collection: bpy.props.PointerProperty(type=bpy.types.Collection, update=updateNode)
last_objects: bpy.props.CollectionProperty(type=SvObjectsWithCollections)
Expand All @@ -93,7 +94,7 @@ def sv_copy(self, original):
# new node new history
self.last_objects.clear()

def draw_buttons(self, context, layout):
def sv_draw_buttons(self, context, layout):
layout.operator('node.sv_unlink_from_other_collections', text="Unlink others", icon='UNLINKED')

def process(self):
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/set_custom_uv_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SvSetCustomUVMap(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvSetCustomUVMap'
bl_label = 'Set Custom UV Map'
bl_icon = 'GROUP_UVS'
is_output = True

@property
def is_scene_dependent(self):
Expand Down
3 changes: 2 additions & 1 deletion nodes/object_nodes/set_loop_normals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class SvSetLoopNormalsNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvSetLoopNormalsNode'
bl_label = 'Set Loop Normals'
bl_icon = 'NORMALS_VERTEX'
is_output = True

normalize: bpy.props.BoolProperty(name="Normalize", default=True, description="Normalize input normals",
update=updateNode)

def draw_buttons(self, context, layout):
def sv_draw_buttons(self, context, layout):
layout.prop(self, 'normalize')

def sv_init(self, context):
Expand Down
3 changes: 2 additions & 1 deletion nodes/object_nodes/set_mesh_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class SvSetMeshAttributeNode(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvSetMeshAttributeNode'
bl_label = 'Set Mesh Attribute'
bl_icon = 'SORTALPHA'
is_output = True

def update_type(self, context):
self.inputs['Value'].hide_safe = self.value_type not in ['FLOAT', 'INT', 'BOOLEAN']
Expand All @@ -96,7 +97,7 @@ def update_type(self, context):
value_type: bpy.props.EnumProperty(items=[(i, i.capitalize(), '') for i in value_types], update=update_type)
last_objects: bpy.props.CollectionProperty(type=SvObjectsWithAttributes)

def draw_buttons(self, context, layout):
def sv_draw_buttons(self, context, layout):
layout.prop(self, 'domain', text='Domain')
layout.prop(self, 'value_type', text='Type')

Expand Down
3 changes: 2 additions & 1 deletion nodes/object_nodes/vertex_colors_mk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class SvVertexColorNodeMK3(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvVertexColorNodeMK3'
bl_label = 'Vertex Color MK3'
bl_icon = 'COLOR'
is_output = True

modes = [
("vertices", "Vert", "Vcol - color per vertex", 1),
Expand Down Expand Up @@ -117,7 +118,7 @@ class SvVertexColorNodeMK3(SverchCustomTreeNode, bpy.types.Node):
default="RGBA", update=updateNode)


def draw_buttons(self, context, layout):
def sv_draw_buttons(self, context, layout):
layout.prop(self, 'use_active')
layout.prop(self, 'vertex_color')
layout.prop(self, "mode", expand=True)
Expand Down
1 change: 1 addition & 0 deletions nodes/object_nodes/weightsmk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SvVertexGroupNodeMK2(SverchCustomTreeNode, bpy.types.Node):
bl_label = 'Vertex Group Weights'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_VERTEX_WEIGHT'
is_output = True
is_animation_dependent = True
is_scene_dependent = True

Expand Down
3 changes: 2 additions & 1 deletion nodes/scene/node_remote_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ class SvNodeRemoteNodeMK2(SverchCustomTreeNode, bpy.types.Node):
bl_label = 'Node Remote (Control)+'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_REMOTE_NODE'
is_output = True

activate: BoolProperty(
default=True,
name='Show', description='Activate node?',
update=updateNode)
update=lambda s, c: setattr(s, 'is_active', s.activate))

nodegroup_name: StringProperty(
default='',
Expand Down
4 changes: 1 addition & 3 deletions nodes/scene/obj_remote_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ class SvObjRemoteNodeMK2(SverchCustomTreeNode, bpy.types.Node):
bl_label = 'Object Remote (Control) MK2'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_REMOTE_OBJECT'
is_output = True

def sv_init(self, context):
self.inputs.new('SvMatrixSocket', 'matrices')
self.inputs.new('SvObjectSocket', 'objects')
self.outputs.new('SvObjectSocket', 'objects')

def draw_buttons(self, context, layout):
pass

def process(self):
if not self.inputs[1] and not self.inputs[1].is_linked:
return
Expand Down
1 change: 1 addition & 0 deletions nodes/scene/particles_MK2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SvParticlesMK2Node(SverchCustomTreeNode, bpy.types.Node):
bl_idname = 'SvParticlesMK2Node'
bl_label = 'Particles MK2'
bl_icon = 'PARTICLES'
is_output = True
is_animation_dependent = True
is_scene_dependent = True

Expand Down
7 changes: 6 additions & 1 deletion nodes/solid/solid_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class SvSolidViewerNode(SverchCustomTreeNode, bpy.types.Node):
sv_icon = 'SV_DRAW_VIEWER'
sv_category = "Solid Outputs"
sv_dependencies = {'FreeCAD'}
is_output = True
node_dict = {}

def wrapped_update(self, context=None):
Expand All @@ -265,7 +266,11 @@ def wrapped_update(self, context=None):
self.process_node(context)

#n_id: StringProperty(default='')
activate: BoolProperty(name='Show', description='Activate', default=True, update=updateNode)
activate: BoolProperty(
name='Show',
description='Activate',
default=True,
update=lambda s, c: setattr(s, 'is_active', s.activate))

vert_color: FloatVectorProperty(
subtype='COLOR', min=0, max=1, default=(0.8, 0.8, 0.8, 1.0),
Expand Down
Loading