| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- import bpy
- from .base_definitions import SchemaUINode
- from bpy.types import Node
- from .utilities import (prRed, prGreen, prPurple, prWhite,
- prOrange,
- wrapRed, wrapGreen, wrapPurple, wrapWhite,
- wrapOrange,)
- from bpy.props import BoolProperty
- from .utilities import get_socket_maps, relink_socket_map, do_relink
- def TellClasses():
- return [
- # tree i/o
- SchemaIndex,
- SchemaArrayInput,
- SchemaArrayInputGet,
- SchemaArrayInputAll,
- SchemaArrayOutput,
- SchemaConstInput,
- SchemaConstOutput,
- SchemaOutgoingConnection,
- SchemaIncomingConnection,
- ]
- # IMPORTANT TODO:
- # - check what happens when these get plugged into each other
- # - probably disallow all or most of these connections in insert_link or update
- class SchemaIndex(Node, SchemaUINode):
- '''The current index of the schema execution'''
- bl_idname = 'SchemaIndex'
- bl_label = "Index"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
-
- def init(self, context):
- self.outputs.new("IntSocket", "Index")
- self.outputs.new("IntSocket", "Schema Length")
- self.initialized = True
- class SchemaArrayInput(Node, SchemaUINode):
- '''Array Inputs'''
- bl_idname = 'SchemaArrayInput'
- bl_label = "Array Input at Current Index"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- # self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- output_map = socket_maps[1]
- self.outputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
- relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
- if '__extend__' in output_map.keys() and output_map['__extend__']:
- do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.outputs.new('WildcardSocket', '', identifier='__extend__')
- # self.initialized = True
- self.is_updating = False
- class SchemaArrayInputAll(Node, SchemaUINode):
- '''Array Inputs'''
- bl_idname = 'SchemaArrayInputAll'
- bl_label = "Get entire Array Input"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- output_map = socket_maps[1]
- self.outputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
- relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
- if '__extend__' in output_map.keys() and output_map['__extend__']:
- do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.outputs.new('WildcardSocket', '', identifier='__extend__')
- self.initialized = True
- self.is_updating = False
- class SchemaArrayInputGet(Node, SchemaUINode):
- '''Array Inputs'''
- bl_idname = 'SchemaArrayInputGet'
- bl_label = "Array Input at Index"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
- def init(self, context):
- self.inputs.new('EnumArrayGetOptions', 'OoB Behaviour')
- self.inputs.new("IntSocket", "Index")
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- output_map = socket_maps[1]
- self.outputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Array':
- relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
- if '__extend__' in output_map.keys() and output_map['__extend__']:
- do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Array' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.outputs.new('WildcardSocket', '', identifier='__extend__')
- self.initialized = True
- self.is_updating = False
- class SchemaArrayOutput(Node, SchemaUINode):
- '''Array Inputs'''
- bl_idname = 'SchemaArrayOutput'
- bl_label = "Array Output"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- input_map = socket_maps[0]
- self.inputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Array':
- relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
- if '__extend__' in input_map.keys() and input_map['__extend__']:
- do_relink(self, None, input_map, in_out='INPUT', parent_name='Array' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.inputs.new('WildcardSocket', '', identifier='__extend__')
- for s in self.outputs:
- s.input= True
- self.initialized = True
- self.is_updating = False
- class SchemaConstInput(Node, SchemaUINode):
- '''Constant Inputs'''
- bl_idname = 'SchemaConstInput'
- bl_label = "Constant Input"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
-
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- output_map = socket_maps[1]
- self.outputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Constant':
- relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
- if '__extend__' in output_map.keys() and output_map['__extend__']:
- do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Constant' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.outputs.new('WildcardSocket', '', identifier='__extend__')
- self.initialized = True
- self.is_updating = False
- class SchemaConstOutput(Node, SchemaUINode):
- '''Constant Outputs'''
- bl_idname = 'SchemaConstOutput'
- bl_label = "Constant Output"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
-
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- input_map = socket_maps[0]
- self.inputs.clear()
- s = self.inputs.new('UnsignedIntSocket', "Expose at Index")
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Constant':
- relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
- if '__extend__' in input_map.keys() and input_map['__extend__']:
- do_relink(self, None, input_map, in_out='INPUT', parent_name='Constant' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.inputs.new('WildcardSocket', '', identifier='__extend__')
- do_relink(self, s, input_map, in_out='INPUT')
- for s in self.outputs:
- s.input= True
-
- self.initialized = True
- self.is_updating = False
- class SchemaOutgoingConnection(Node, SchemaUINode):
- '''Outgoing Connections'''
- bl_idname = 'SchemaOutgoingConnection'
- bl_label = "Outgoing Connection"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
-
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- input_map = socket_maps[0]
- self.inputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'OUTPUT' and item.parent.name == 'Connection':
- relink_socket_map(self, self.inputs, input_map, item, in_out='INPUT')
- if '__extend__' in input_map.keys() and input_map['__extend__']:
- do_relink(self, None, input_map, in_out='INPUT', parent_name='Connection' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.inputs.new('WildcardSocket', '', identifier='__extend__')
- for s in self.outputs:
- s.input= True
- self.initialized = True
- self.is_updating = False
- class SchemaIncomingConnection(Node, SchemaUINode):
- '''Incoming Connections'''
- bl_idname = 'SchemaIncomingConnection'
- bl_label = "Incoming Connection"
- bl_icon = 'GIZMO'
- initialized : bpy.props.BoolProperty(default = False)
- mantis_node_class_name=bl_idname
- def init(self, context):
- self.update()
- def update(self):
- if self.is_updating:
- return
- self.is_updating = True
- self.initialized = False
- socket_maps = get_socket_maps(self)
- if socket_maps is None:
- return
- output_map = socket_maps[1]
- self.outputs.clear()
- for item in self.id_data.interface.items_tree:
- if item.item_type == 'PANEL': continue
- if item.parent and item.in_out == 'INPUT' and item.parent.name == 'Connection':
- relink_socket_map(self, self.outputs, output_map, item, in_out='OUTPUT')
- if '__extend__' in output_map.keys() and output_map['__extend__']:
- do_relink(self, None, output_map, in_out='OUTPUT', parent_name='Connection' )
- if len(self.inputs)<1 or self.inputs[-1].bl_idname not in ["WildcardSocket"]:
- self.outputs.new('WildcardSocket', '', identifier='__extend__')
- self.initialized = True
- self.is_updating = False
- for cls in TellClasses():
- cls.set_mantis_class()
|