示例#1
0
def run_solve(override_current_frame=None):
    """
    Run the solver for the active collection.

    If the Solver UI is found, the window will update and show
    progress messages.

    This function is strongly dependant on the Solver UI.
    The following state information is set via the Solver UI.

    - Active Collection
    - Log Level
    - Refresh Viewport

    :param override_current_frame: Before running the solver, change
                                   the "override current frame" state to
                                   this value.
    :type override_current_frame: bool
    """
    assert (override_current_frame is None
            or isinstance(override_current_frame, bool))
    if override_current_frame is None:
        override_current_frame = False

    col = lib_state.get_active_collection()
    if col is None:
        msg = 'No active Collection found. Skipping solve.'
        LOG.warning(msg)
        return
    log_level = lib_state.get_log_level()

    layout = None
    win = solver_window.SolverWindow.get_instance()
    win_valid = uiutils.isValidQtObject(win)
    if win is None and win_valid:
        msg = 'Could not get window.'
        LOG.warning(msg)
    else:
        layout = win.getSubForm()

    # Set 'override current frame' value.
    tab = lib_col_state.get_solver_tab_from_collection(col)
    prev_value = None
    if override_current_frame is True:
        prev_value = __get_override_current_frame_value(col, tab)
        __set_override_current_frame_value(col, layout, tab, override_current_frame)

    # Run Solver
    options = lib_col.gather_execute_options()
    lib_col.run_solve_ui(
        col,
        options,
        log_level,
        win,
    )

    # Restore previous value.
    if override_current_frame is True:
        __set_override_current_frame_value(col, layout, tab, prev_value)
    return
 def apply(self):
     """
     This button launches a solve, but can also be used to cancel a solve.
     """
     running_state = lib_state.get_solver_is_running_state()
     if running_state is True:
         # Cancel out of a running solve if the user presses
         # the button again.
         lib_state.set_solver_user_interrupt_state(True)
         return
     undo_id = 'mmSolver: '
     undo_id += str(datetime.datetime.isoformat(datetime.datetime.now()))
     undo_id += ' '
     undo_id += str(uuid.uuid4())
     with undo_utils.undo_chunk_context(undo_id):
         block = self.blockSignals(True)
         try:
             mmapi.set_solver_running(True)
             options = lib_collection.gather_execute_options()
             log_level = lib_state.get_log_level()
             col = lib_state.get_active_collection()
             lib_collection.run_solve_ui(col, options, log_level, self)
         finally:
             mmapi.set_solver_running(False)
             self.blockSignals(block)
     return
示例#3
0
 def apply(self):
     """
     This button launches a solve, but can also be used to cancel a solve.
     """
     running_state = lib_state.get_solver_is_running_state()
     if running_state is True:
         # Cancel out of a running solve if the user presses
         # the button again.
         lib_state.set_solver_user_interrupt_state(True)
         return
     undo_id = 'mmSolver: '
     undo_id += str(datetime.datetime.isoformat(datetime.datetime.now()))
     undo_id += ' '
     undo_id += str(uuid.uuid4())
     with tools_utils.tool_context(use_undo_chunk=True,
                                   undo_chunk_name=undo_id,
                                   restore_current_frame=False,
                                   pre_update_frame=False,
                                   post_update_frame=False,
                                   use_dg_evaluation_mode=True,
                                   disable_viewport=False):
         block = self.blockSignals(True)
         try:
             mmapi.set_solver_running(True)
             options = lib_collection.gather_execute_options()
             log_level = lib_state.get_log_level()
             col = lib_state.get_active_collection()
             lib_collection.run_solve_ui(col, options, log_level, self)
         finally:
             mmapi.set_solver_running(False)
             self.blockSignals(block)
     return