Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. import bpy
  20. from bpy.props import StringProperty, EnumProperty, IntProperty
  21.  
  22. from sverchok.node_tree import SverchCustomTreeNode
  23. from sverchok.data_structure import multi_socket, node_id, replace_socket
  24. from sverchok.core.update_system import make_tree_from_nodes, do_update
  25. import ast
  26.  
  27.  
  28. socket_types = [
  29. ("StringsSocket", "s", "Numbers, polygon data, generic"),
  30. ("VerticesSocket", "v", "Vertices, point and vector data"),
  31. ("MatrixSocket", "m", "Matrix")
  32. ]
  33.  
  34. def group_make(self, new_group_name):
  35. self.node_tree = bpy.data.node_groups.new(new_group_name, 'SverchCustomTreeType')
  36. self.group_name = self.node_tree.name
  37.  
  38. nodes = self.node_tree.nodes
  39. # inputnode = nodes.new('SvGroupInputsNode')
  40. # outputnode = nodes.new('SvGroupOutputsNode')
  41. inputnode = nodes.new('NodeGroupInput')
  42. outputnode = nodes.new('NodeGroupOutput')
  43. inputnode.location = (-300, 0)
  44. outputnode.location = (300, 0)
  45. return self.node_tree
  46.  
  47. class SvGroupEdit(bpy.types.Operator):
  48. bl_idname = "node.sv_group_edit"
  49. bl_label = "edits an sv group"
  50.  
  51. group_name = StringProperty()
  52.  
  53. def execute(self, context):
  54. node = context.node
  55. ng = bpy.data.node_groups
  56.  
  57. group_node = ng.get(self.group_name)
  58. if not group_node:
  59. group_node = group_make(node, new_group_name=self.group_name)
  60.  
  61. bpy.ops.node.sv_switch_layout(layout_name=self.group_name)
  62.  
  63. # by switching, space_data is now different
  64. parent_tree_name = node.id_data.name
  65. path = context.space_data.path
  66. path.clear()
  67. path.append(ng[parent_tree_name]) # below the green opacity layer
  68. path.append(ng[self.group_name]) # top level
  69.  
  70. # this should happen in the `tree_path_parent` operator, but the doesn't seem to.
  71. # context.space_data.node_tree = bpy.data.node_groups[self.group_name]
  72. return {"FINISHED"}
  73.  
  74. class SvTreePathParent(bpy.types.Operator):
  75. '''Go to parent node tree'''
  76. bl_idname = "node.sv_tree_path_parent"
  77. bl_label = "Parent Sv Node Tree"
  78. bl_options = {'REGISTER', 'UNDO'}
  79.  
  80. @classmethod
  81. def poll(cls, context):
  82. space = context.space_data
  83. return space.type == 'NODE_EDITOR' and len(space.path) > 1
  84.  
  85. def execute(self, context):
  86. space = context.space_data
  87. space.path.pop()
  88. context.space_data.node_tree = space.path[0].node_tree
  89. return {'FINISHED'}
  90.  
  91.  
  92. class SvGroupNodeExp(bpy.types.NodeCustomGroup, SverchCustomTreeNode):
  93. bl_idname = 'SvGroupNodeExp'
  94. bl_label = 'Group Exp'
  95. bl_icon = 'OUTLINER_OB_EMPTY'
  96.  
  97. group_name = StringProperty()
  98.  
  99. def update(self):
  100. ''' Override inherited '''
  101. pass
  102.  
  103. def draw_buttons_ext(self, context, layout):
  104. pass
  105.  
  106. def draw_buttons(self, context, layout):
  107. c = layout.column()
  108. c.prop(self, 'group_name', text='name')
  109.  
  110. d = layout.column()
  111. d.active = bool(self.group_name)
  112. f = d.operator('node.sv_group_edit', text='edit!')
  113. f.group_name = self.group_name
  114.  
  115. def process(self):
  116. pass
  117.  
  118. def load(self):
  119. pass
  120.  
  121.  
  122. classes = [SvGroupEdit, SvTreePathParent, SvGroupNodeExp]
  123.  
  124. def register():
  125. for cls in classes:
  126. bpy.utils.register_class(cls)
  127.  
  128.  
  129. def unregister():
  130. for cls in classes:
  131. bpy.utils.unregister_class(cls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement