-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathlist_input.py
161 lines (138 loc) · 6.36 KB
/
list_input.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# ##### 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 bpy
from bpy.props import (
EnumProperty, FloatVectorProperty,
IntProperty, IntVectorProperty, BoolProperty)
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
from sverchok.utils.listutils import (
listinput_getI_needed,
listinput_getF_needed,
listinput_drawI,
listinput_drawF
)
from sverchok.utils.nodes_mixins.show_3d_properties import Show3DProperties
class SvListInputNode(Show3DProperties, SverchCustomTreeNode, bpy.types.Node):
''' Create a flat list of Integers, Floats, or Vectors.
int: [[1,5,42]],
float: [[1.0, -5.42, 12.0]]
vectors: [[ (0,0,0), (1,2,-2)]]
'''
bl_idname = 'SvListInputNode'
bl_label = 'List Input'
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = 'SV_LIST_INPUT'
defaults = [0 for i in range(32)]
int_: IntProperty(
name='int_', description='integer number', default=1, min=1, max=128, update=updateNode)
v_int: IntProperty(
name='int_', description='integer number', default=1, min=1, max=10, update=updateNode)
int_list: IntVectorProperty(
name='int_list', description="Integer list", default=defaults, size=32,update=updateNode)
int_list1: IntVectorProperty(
name='int_list1', description="Integer list", default=defaults, size=32,update=updateNode)
int_list2: IntVectorProperty(
name='int_list2', description="Integer list", default=defaults, size=32,update=updateNode)
int_list3: IntVectorProperty(
name='int_list3', description="Integer list", default=defaults, size=32,update=updateNode)
float_list: FloatVectorProperty(
name='float_list', description="Float list", default=defaults, size=32, update=updateNode)
float_list1: FloatVectorProperty(
name='float_list1', description="Float list", default=defaults, size=32, update=updateNode)
float_list2: FloatVectorProperty(
name='float_list2', description="Float list", default=defaults, size=32, update=updateNode)
float_list3: FloatVectorProperty(
name='float_list3', description="Float list", default=defaults, size=32, update=updateNode)
vector_list: FloatVectorProperty(
name='vector_list', description="Vector list", default=defaults, size=32, update=updateNode)
def changeMode(self, context):
if self.mode == 'vector':
if 'Vector List' not in self.outputs:
self.outputs.remove(self.outputs[0])
self.outputs.new('SvVerticesSocket', 'Vector List')
return
else:
if 'List' not in self.outputs:
self.outputs.remove(self.outputs[0])
self.outputs.new('SvStringsSocket', 'List')
return
modes = [
("int_list", "Int", "Integer", "", 1),
("float_list", "Float", "Float", "", 2),
("vector", "Vector", "Vector", "", 3)]
mode: EnumProperty(items=modes, default='int_list', update=changeMode)
def sv_init(self, context):
self.outputs.new('SvStringsSocket', "List")
def draw_buttons(self, context, layout):
if self.mode == 'vector':
layout.prop(self, "v_int", text="List Length")
else:
layout.prop(self, "int_", text="List Length")
layout.prop(self, "mode", expand=True)
if self.mode == 'vector':
col = layout.column(align=False)
for i in range(self.v_int):
row = col.row(align=True)
split = row.split(factor=0.08)
row1 = split.column().row(align=True)
row1.alignment = 'RIGHT'
row1.label(text=f"{i}.")
row2 = split.column().row(align=True)
for j in range(3):
row2.prop(self, 'vector_list', index=i*3+j, text='XYZ'[j])
elif self.mode == 'int_list':
col = layout.column(align=True)
listinput_drawI(self,col)
else:
col = layout.column(align=True)
listinput_drawF(self,col)
def draw_buttons_3dpanel(self, layout, in_menu=None):
if not in_menu:
menu = layout.row(align=True).operator('node.popup_3d_menu', text=f'Show: "{self.label or self.name}"')
menu.tree_name = self.id_data.name
menu.node_name = self.name
else:
layout.label(text=self.label or self.name)
if self.mode == 'vector':
colum_list = layout.column(align=True)
for i in range(self.v_int):
row = colum_list.row(align=True)
for j in range(3):
row.prop(self, 'vector_list', index=i*3+j, text='XYZ'[j]+(self.label if self.label else self.name))
else:
colum_list = layout.column(align=True)
for i in range(self.int_):
row = colum_list.row(align=True)
row.prop(self, self.mode, index=i, text=str(i)+(self.label if self.label else self.name))
row.scale_x = 0.8
def process(self):
if self.outputs[0].is_linked:
if self.mode == 'int_list':
data = listinput_getI_needed(self)
elif self.mode == 'float_list':
data = listinput_getF_needed(self)
elif self.mode == 'vector':
c = self.v_int*3
v_l = list(self.vector_list)
data = [list(zip(v_l[0:c:3], v_l[1:c:3], v_l[2:c:3]))]
self.outputs[0].sv_set(data)
def register():
bpy.utils.register_class(SvListInputNode)
def unregister():
bpy.utils.unregister_class(SvListInputNode)