Example #1
0
    def change_socket(self, context):

        change = self.inputs[1].label != 'Vertices' and self.mode == 'VERTS'
        change = change or (self.inputs[1].label != 'Matrices'
                            and self.mode == 'FACES')
        if change:
            new_type = 'SvMatrixSocket' if self.mode == 'FACES' else 'SvVerticesSocket'
            new_name = 'Matrices' if self.mode == 'FACES' else 'Vertices'
            replace_socket(self.inputs[1], new_type)
            self.inputs[1].label = new_name
            updateNode(self, context)
Example #2
0
    def execute(self, context):
        # make changes to this node's socket name
        node, kind, socket = self.get_data(context)
        monad = node.id_data

        replace_socket(socket, self.socket_type)

        for instance in monad.instances:
            sockets = getattr(instance, reverse_lookup[kind])
            replace_socket(sockets[self.pos], self.socket_type)

        monad.update_cls()
        return {"FINISHED"}
Example #3
0
 def verify_prop(self, context):
     try:
         obj = self.obj
     except:
         traceback.print_exc()        
         self.bad_prop = True
         return
     self.bad_prop = False
     s_type = types.get(type(obj))
     outputs = self.outputs
     if s_type and outputs:
         replace_socket(outputs[0], s_type)
     elif s_type:
         outputs.new(s_type, "Data")
Example #4
0
 def update(self):
     inputs_A = [i for i in self.inputs if i.name[0] == 'A']
     for in_soc, out_soc in zip(inputs_A, self.outputs):
         
         if not in_soc.links:
             new_type = in_soc.bl_idname
         else:
             in_other = get_other_socket(in_soc)
             new_type = in_other.bl_idname
             
         if new_type == out_soc.bl_idname:
             continue
         
         replace_socket(out_soc, new_type)
Example #5
0
 def verify_prop(self, context):
     try:
         obj = self.obj
     except:
         traceback.print_exc()
         self.bad_prop = True
         return
     self.bad_prop = False
     s_type = types.get(type(obj))
     outputs = self.outputs
     if s_type and outputs:
         replace_socket(outputs[0], s_type)
     elif s_type:
         outputs.new(s_type, "Data")
Example #6
0
    def add_or_update_sockets(self, k, v):
        '''
        'sockets' are either 'self.inputs' or 'self.outputs'
        '''
        sockets = getattr(self, k)

        for idx, (socket_description) in enumerate(v):
            if socket_description is UNPARSABLE:
                print(socket_description, idx, 'was unparsable')
                return

            if len(sockets) > 0 and idx in set(range(len(sockets))):
                if not are_matched(sockets[idx], socket_description):
                    replace_socket(sockets[idx], *socket_description[:2])
            else:
                sockets.new(*socket_description[:2])

        return True
Example #7
0
    def add_or_update_sockets(self, k, v):
        '''
        'sockets' are either 'self.inputs' or 'self.outputs'
        '''
        sockets = getattr(self, k)

        for idx, (socket_description) in enumerate(v):
            if socket_description is UNPARSABLE: 
                print(socket_description, idx, 'was unparsable')
                return

            if len(sockets) > 0 and idx in set(range(len(sockets))):
                if not are_matched(sockets[idx], socket_description):
                    replace_socket(sockets[idx], *socket_description[:2])
            else:
                sockets.new(*socket_description[:2])

        return True
Example #8
0
    def update(self):
        kind = self.node_kind
        if not kind:
            return

        monad = self.id_data
        if monad.bl_idname == "SverchCustomTreeType":
            return

        socket_list = getattr(self, kind)
        _socket = self.socket_map.get(kind) # from_socket, to_socket

        if len(socket_list) == 0:
            print('sockets wiped, skipped update')
            return

        if socket_list[-1].is_linked:

            # first switch socket type
            socket = socket_list[-1]
            if kind == "outputs":
                prop_name = monad.add_prop_from(socket)
            else:
                prop_name = ""

            cls = monad.update_cls()

            if kind == "outputs":
                new_name, new_type, prop_data = cls.input_template[-1]
            else:
                new_name, new_type = cls.output_template[-1]
                prop_data = {}

            new_socket = replace_socket(socket, new_type, new_name=new_name)
            if prop_name:
                new_socket.prop_name = prop_name

            # if no 'linked_socket.prop_name' then use 'linked_socket.name'


            for instance in monad.instances:
                sockets = getattr(instance, reverse_lookup[kind])
                new_socket = sockets.new(new_type, new_name)
                for name, value in prop_data.items():
                    setattr(new_socket, name, value)

            # add new dangling dummy
            socket_list.new('SvDummySocket', 'connect me')
    def verify_prop(self, context):
        try:
            obj = self.obj
        except:
            traceback.print_exc()
            self.bad_prop = True
            return
        self.bad_prop = False

        s_type = types.get(type(obj))
        inputs = self.inputs
        p_name = {float: "float_prop", int: "int_prop"}.get(type(obj), "")
        if inputs and s_type:
            socket = replace_socket(inputs[0], s_type)
            socket.prop_name = p_name
        elif s_type:
            inputs.new(s_type, "Data").prop_name = p_name
        if s_type == "VerticesSocket":
            inputs[0].use_prop = True
Example #10
0
    def verify_prop(self, context):
        try:
            obj = self.obj
        except:
            traceback.print_exc()
            self.bad_prop = True
            return
        self.bad_prop = False

        s_type = types.get(type(obj))
        inputs = self.inputs
        p_name = {float: "float_prop", int: "int_prop"}.get(type(obj), "")
        if inputs and s_type:
            socket = replace_socket(inputs[0], s_type)
            socket.prop_name = p_name
        elif s_type:
            inputs.new(s_type, "Data").prop_name = p_name
        if s_type == "VerticesSocket":
            inputs[0].use_prop = True
Example #11
0
    def adjust_sockets(self, nodes):
        swap = {"inputs": "outputs", "outputs": "inputs"}
        for n in nodes:
            data = ast.literal_eval(n.socket_data)
            """
            This below is somewhat broken and needs
            to be reworked.
            """

            print("adjusting sockets", data)
            for k, values in data.items():
                sockets = getattr(self, swap[k])
                for i, socket_data in enumerate(values):
                    if len(socket_data) == 3 and socket_data[2]:
                        print(socket_data)
                        s_type, s_name, s_old_name = socket_data
                        curr_socket = sockets[s_old_name]
                        print(curr_socket.name)
                        s = replace_socket(curr_socket, s_type, s_name, i)
                        print(s.name)
                    else:
                        sockets.new(*socket_data)
Example #12
0
    def adjust_sockets(self, nodes):
        swap = {"inputs": "outputs", "outputs": "inputs"}
        for n in nodes:
            data = ast.literal_eval(n.socket_data)
            """
            This below is somewhat broken and needs
            to be reworked.
            """

            print("adjusting sockets", data)
            for k, values in data.items():
                sockets = getattr(self, swap[k])
                for i, socket_data in enumerate(values):
                    if len(socket_data) == 3 and socket_data[2]:
                        print(socket_data)
                        s_type, s_name, s_old_name = socket_data
                        curr_socket = sockets[s_old_name]
                        print(curr_socket.name)
                        s = replace_socket(curr_socket, s_type, s_name, i)
                        print(s.name)
                    else:
                        sockets.new(*socket_data)
Example #13
0
 def replace_socket(self, new_type, new_name=None):
     """Replace a socket with a socket of new_type and keep links,
     return the new socket, the old reference might be invalid"""
     return replace_socket(self, new_type, new_name)
Example #14
0
 def replace_socket(self, new_type, new_name=None):
     """Replace a socket with a socket of new_type and keep links,
     return the new socket, the old reference might be invalid"""
     return replace_socket(self, new_type, new_name)