Esempio n. 1
0
def sv_post_load(scene):
    """
    Upgrade nodes, apply preferences and do an update.
    THe update order is next:
    1. pre_load handler
    2. update methods of trees in a file
    3. post_load handler
    4. evaluate trees from main tree handler
    post_load handler is also called when Blender is first ran
    The method should initialize Sverchok parts which are required by loaded tree
    """
    from sverchok import node_tree, settings

    # ensure current nodeview view scale / location parameters reflect users' system settings
    node_tree.SverchCustomTree.update_gl_scale_info(None, "sv_post_load")

    # register and mark old and dependent nodes
    with catch_log_error():
        if any(not n.is_registered_node_type() for ng in BlTrees().sv_trees
               for n in ng.nodes):
            old_nodes.register_all()
            old_nodes.mark_all()
            dummy_nodes.register_all()
            dummy_nodes.mark_all()

    with catch_log_error():
        settings.apply_theme_if_necessary()

    # when a file is opened as a startup file update method of its trees is not called (Blender inconsistency??)
    for tree in BlTrees().sv_main_trees:
        tree.update()
Esempio n. 2
0
def sv_post_load(scene):
    """
    Upgrade nodes, apply preferences and do an update.
    THe update order is next:
    1. pre_load handler
    2. update methods of trees in a file
    3. post_load handler
    post_load handler is also called when Blender is first ran
    The method should remove throttling trees made in pre_load event,
    initialize Sverchok parts which are required by loaded tree
    and update all Sverchok trees
    """
    from sverchok import node_tree, settings

    # ensure current nodeview view scale / location parameters reflect users' system settings
    node_tree.SverchCustomTree.update_gl_scale_info(None, "sv_post_load")

    # register and mark old and dependent nodes
    with catch_log_error():
        if any(not n.is_registered_node_type() for ng in BlTrees().sv_trees
               for n in ng.nodes):
            old_nodes.register_all()
            old_nodes.mark_all()
            dummy_nodes.register_all()
            dummy_nodes.mark_all()

    with catch_log_error():
        settings.apply_theme_if_necessary()

    # release all trees and update them
    set_first_run(False)
    build_update_list()
    process_tree()
Esempio n. 3
0
def sv_update_handler(scene):
    """
    Update sverchok node groups on frame change events.
    """
    if not has_frame_changed(scene):
        return

    for ng in sverchok_trees():
        with catch_log_error():
            ng.process_ani()
Esempio n. 4
0
def tree_event_loop(delay):
    """Sverchok event handler"""
    with catch_log_error():
        if NodesUpdater.is_running():
            NodesUpdater.run_task()
        elif NodesUpdater.has_task(
        ):  # task should be run via timer only https://developer.blender.org/T82318#1053877
            NodesUpdater.start_task()
            NodesUpdater.run_task()
    return delay
Esempio n. 5
0
    def init(self, context):
        """
        this function is triggered upon node creation,
        - delegates further initialization information to sv_init
        """
        if self.sv_default_color:
            self.use_custom_color = True
            self.color = self.sv_default_color

        with catch_log_error():
            self.sv_init(context)
Esempio n. 6
0
def sv_update_handler(scene):
    """
    Update sverchok node groups on frame change events.
    Jump from one frame to another: has_frame_changed=True, is_animation_playing=False
    Scrubbing variant 1: has_frame_changed=True, is_animation_playing=True
    Scrubbing variant 2(stop): has_frame_changed=True, is_animation_playing=False
    Scrubbing variant 3: has_frame_changed=False, is_animation_playing=True
    Scrubbing variant 4(stop): has_frame_changed=False, is_animation_playing=False
    Playing animation: has_frame_changed=True, is_animation_playing=True
    Playing animation(stop): has_frame_changed=False, is_animation_playing=False
    """
    is_playing = bpy.context.screen.is_animation_playing
    is_frame_changed = has_frame_changed(scene)
    # print(f"Frame changed: {is_frame_changed}, Animation is playing: {is_playing}")

    for ng in sverchok_trees(
    ):  # Comparatively small overhead with 200 trees in a file
        with catch_log_error():
            ng.process_ani(is_frame_changed, is_playing)
Esempio n. 7
0
    def update_ui(self, group_nodes_path: List['SvGroupTreeNode']):
        """updating tree contextual information -> node colors, objects number in sockets, debugger nodes"""
        self.handler.send(
            GroupEvent(GroupEvent.EDIT_GROUP_NODE, group_nodes_path))

        nodes_errors = self.handler.get_error_nodes(group_nodes_path)
        to_show_update_time = group_nodes_path[0].id_data.sv_show_time_nodes
        time_mode = group_nodes_path[0].id_data.show_time_mode
        if to_show_update_time:
            update_time = (
                self.handler.get_cum_time(group_nodes_path)
                if time_mode == "Cumulative" else
                self.handler.get_nodes_update_time(group_nodes_path))
        else:
            update_time = cycle([None])
        for node, error, update in zip(self.nodes, nodes_errors, update_time):
            if hasattr(node, 'update_ui'):
                node.update_ui(error, update,
                               NodeIdManager.extract_node_id(node))

            # update debug nodes
            if BlNode(node).is_debug_node:
                with catch_log_error():
                    node.process()
Esempio n. 8
0
def tree_event_loop(delay):
    """Sverchok tasks handler"""
    with catch_log_error():
        if tasks:
            tasks.run()
    return delay