Skip to content

Commit

Permalink
Merge pull request #4986 from nortikin/fix_4352_SvOB3BDataCollection_…
Browse files Browse the repository at this point in the history
…should_be_registered_only_once

Fix 4352. SvOB3BDataCollection should be registered only once
  • Loading branch information
satabol authored Aug 20, 2023
2 parents 48995d3 + fcf9d57 commit 29f929b
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 104 deletions.
24 changes: 12 additions & 12 deletions nodes/scene/get_objects_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
read_face_normal, read_face_center, read_face_area, read_materials_idx)


class SvOB3BDataCollection(bpy.types.PropertyGroup):
class SvOB3BDataCollectionMK2(bpy.types.PropertyGroup):
name: bpy.props.StringProperty()
icon: bpy.props.StringProperty(default="BLANK1")

Expand All @@ -28,7 +28,7 @@ class ReadingObjectDataError(Exception):
pass


class SVOB3B_UL_NamesList(bpy.types.UIList):
class SVOB3B_UL_NamesListMK2(bpy.types.UIList):

def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):

Expand All @@ -40,14 +40,14 @@ def draw_item(self, context, layout, data, item, icon, active_data, active_propn
item_icon = ""

layout.label(text=item.name, icon=item_icon)
action = data.wrapper_tracked_ui_draw_op(layout, "node.sv_ob3b_collection_operator", icon='X', text='')
action = data.wrapper_tracked_ui_draw_op(layout, "node.sv_ob3b_collection_operator_mk2", icon='X', text='')
action.fn_name = 'REMOVE'
action.idx = index


class SvOB3BItemOperator(bpy.types.Operator, SvGenericNodeLocator):
class SvOB3BItemOperatorMK2(bpy.types.Operator, SvGenericNodeLocator):

bl_idname = "node.sv_ob3b_collection_operator"
bl_idname = "node.sv_ob3b_collection_operator_mk2"
bl_label = "generic bladibla"

fn_name: StringProperty(default='')
Expand All @@ -59,9 +59,9 @@ def sv_execute(self, context, node):
node.process_node(None)


class SvOB3Callback(bpy.types.Operator, SvGenericNodeLocator):
class SvOB3CallbackMK2(bpy.types.Operator, SvGenericNodeLocator):

bl_idname = "node.ob3_callback"
bl_idname = "node.ob3_callback_mk2"
bl_label = "Object In mk3 callback"
bl_options = {'INTERNAL'}

Expand Down Expand Up @@ -126,7 +126,7 @@ def hide_show_versgroups(self, context):
description='sorting inserted objects by names',
default=True, update=updateNode)

object_names: bpy.props.CollectionProperty(type=SvOB3BDataCollection)
object_names: bpy.props.CollectionProperty(type=SvOB3BDataCollectionMK2)

active_obj_index: bpy.props.IntProperty()

Expand Down Expand Up @@ -189,7 +189,7 @@ def select_objs(self, ops):

def draw_obj_names(self, layout):
if self.object_names:
layout.template_list("SVOB3B_UL_NamesList", "", self, "object_names", self, "active_obj_index")
layout.template_list("SVOB3B_UL_NamesListMK2", "", self, "object_names", self, "active_obj_index")
else:
layout.label(text='--None--')

Expand All @@ -204,7 +204,7 @@ def sv_draw_buttons(self, context, layout):
row = col.row()

op_text = "Get selection" # fallback
callback = 'node.ob3_callback'
callback = 'node.ob3_callback_mk2'

if self.prefs_over_sized_buttons:
row.scale_y = 4.0
Expand Down Expand Up @@ -242,7 +242,7 @@ def rclick_menu(self, context, layout):

def draw_buttons_3dpanel(self, layout):
if not self.by_input:
callback = 'node.ob3_callback'
callback = 'node.ob3_callback_mk2'
row = layout.row(align=True)
row.label(text=self.label if self.label else self.name)
colo = row.row(align=True)
Expand Down Expand Up @@ -379,5 +379,5 @@ def process(self):
outputs['Object'].sv_set([data_objects.get(o.name) for o in self.object_names])


classes = [SvOB3BItemOperator, SvOB3BDataCollection, SVOB3B_UL_NamesList, SvOB3Callback, SvGetObjectsData]
classes = [SvOB3BItemOperatorMK2, SvOB3BDataCollectionMK2, SVOB3B_UL_NamesListMK2, SvOB3CallbackMK2, SvGetObjectsData]
register, unregister = bpy.utils.register_classes_factory(classes)
2 changes: 1 addition & 1 deletion nodes/scene/node_remote_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import dataCorrect, updateNode
from sverchok.old_nodes.getsetprop import assign_data
from sverchok.old_nodes.getprop import assign_data


# can't use a PointerProperty for type=bpy.data.node_group
Expand Down
90 changes: 0 additions & 90 deletions old_nodes/getsetprop.py → old_nodes/getprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,99 +207,9 @@ def process(self):
# print(">> Get process is called")
self.outputs[0].sv_set(wrap_output_data(self.obj))


class SvSetPropNode(SverchCustomTreeNode, bpy.types.Node):
''' Set Property '''
bl_idname = 'SvSetPropNode'
bl_label = 'Set Property'
bl_icon = 'FORCE_VORTEX'
sv_icon = 'SV_PROP_SET'

ok_prop: BoolProperty(default=False)
bad_prop: BoolProperty(default=False)


@property
def obj(self):
eval_str = apply_alias(self.prop_name)
ast_path = ast.parse(eval_str)
path = parse_to_path(ast_path.body[0].value)
return get_object(path)

def verify_prop(self, context):

# test first
try:
obj = self.obj
except:
traceback.print_exc()
self.bad_prop = True
return

# execute second
self.bad_prop = False

s_type = types.get(type(self.obj))
if not s_type:
s_type = secondary_type_assesment(self.obj)

p_name = {
float: "float_prop",
int: "int_prop",
bpy_prop_array: "color_prop"
}.get(type(self.obj),"")

inputs = self.inputs

if inputs and s_type:
socket = inputs[0].replace_socket(s_type)
socket.prop_name = p_name
elif s_type:
inputs.new(s_type, "Data").prop_name = p_name
if s_type == "SvVerticesSocket":
inputs[0].use_prop = True

updateNode(self, context)

def local_updateNode(self, context):
# no further interaction with the nodetree is required.
self.process()

prop_name: StringProperty(name='', update=verify_prop)
float_prop: FloatProperty(update=updateNode, name="x")
int_prop: IntProperty(update=updateNode, name="x")
color_prop: FloatVectorProperty(
name="Color", description="Color", size=4,
min=0.0, max=1.0, subtype='COLOR', update=local_updateNode)

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

def process(self):
# print("<< Set process is called")
data = self.inputs[0].sv_get()
eval_str = apply_alias(self.prop_name)
ast_path = ast.parse(eval_str)
path = parse_to_path(ast_path.body[0].value)
obj = get_object(path)

if isinstance(obj, (int, float, bpy_prop_array)):
obj = get_object(path[:-1])
p_type, value = path[-1]
if p_type == "attr":
setattr(obj, value, data[0][0])
else:
obj[value] = data[0][0]
else:
assign_data(obj, data)


def register():
bpy.utils.register_class(SvSetPropNode)
bpy.utils.register_class(SvGetPropNode)


def unregister():
bpy.utils.unregister_class(SvSetPropNode)
bpy.utils.unregister_class(SvGetPropNode)
2 changes: 1 addition & 1 deletion old_nodes/node_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import dataCorrect, updateNode
from sverchok.old_nodes.getsetprop import assign_data
from sverchok.old_nodes.getprop import assign_data


class SvNodePickup(bpy.types.Operator):
Expand Down
1 change: 1 addition & 0 deletions old_nodes/objects_mk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sverchok.utils.nodes_mixins.show_3d_properties import Show3DProperties

class SvOB3BDataCollection(bpy.types.PropertyGroup):
bl_idname = "SvOB3BDataCollection"
name: bpy.props.StringProperty()
icon: bpy.props.StringProperty(default="BLANK1")

Expand Down
123 changes: 123 additions & 0 deletions old_nodes/setprop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# ##### 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 ast
import traceback

import bpy
from bpy.props import StringProperty, BoolProperty, IntProperty, FloatProperty, FloatVectorProperty
from bpy.types import bpy_prop_array
import mathutils
from mathutils import Matrix, Vector, Euler, Quaternion, Color

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import Matrix_generate, updateNode, node_id
from sverchok.old_nodes.getprop import assign_data, get_object, apply_alias, parse_to_path, secondary_type_assesment, types

class SvSetPropNode(SverchCustomTreeNode, bpy.types.Node):
''' Set Property '''
bl_idname = 'SvSetPropNode'
bl_label = 'Set Property'
bl_icon = 'FORCE_VORTEX'
sv_icon = 'SV_PROP_SET'

ok_prop: BoolProperty(default=False)
bad_prop: BoolProperty(default=False)


@property
def obj(self):
eval_str = apply_alias(self.prop_name)
ast_path = ast.parse(eval_str)
path = parse_to_path(ast_path.body[0].value)
return get_object(path)

def verify_prop(self, context):

# test first
try:
obj = self.obj
except:
traceback.print_exc()
self.bad_prop = True
return

# execute second
self.bad_prop = False

s_type = types.get(type(self.obj))
if not s_type:
s_type = secondary_type_assesment(self.obj)

p_name = {
float: "float_prop",
int: "int_prop",
bpy_prop_array: "color_prop"
}.get(type(self.obj),"")

inputs = self.inputs

if inputs and s_type:
socket = inputs[0].replace_socket(s_type)
socket.prop_name = p_name
elif s_type:
inputs.new(s_type, "Data").prop_name = p_name
if s_type == "SvVerticesSocket":
inputs[0].use_prop = True

updateNode(self, context)

def local_updateNode(self, context):
# no further interaction with the nodetree is required.
self.process()

prop_name: StringProperty(name='', update=verify_prop)
float_prop: FloatProperty(update=updateNode, name="x")
int_prop: IntProperty(update=updateNode, name="x")
color_prop: FloatVectorProperty(
name="Color", description="Color", size=4,
min=0.0, max=1.0, subtype='COLOR', update=local_updateNode)

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

def process(self):
# print("<< Set process is called")
data = self.inputs[0].sv_get()
eval_str = apply_alias(self.prop_name)
ast_path = ast.parse(eval_str)
path = parse_to_path(ast_path.body[0].value)
obj = get_object(path)

if isinstance(obj, (int, float, bpy_prop_array)):
obj = get_object(path[:-1])
p_type, value = path[-1]
if p_type == "attr":
setattr(obj, value, data[0][0])
else:
obj[value] = data[0][0]
else:
assign_data(obj, data)


def register():
bpy.utils.register_class(SvSetPropNode)

def unregister():
bpy.utils.unregister_class(SvSetPropNode)

0 comments on commit 29f929b

Please sign in to comment.