def updateModel(self): """ Refresh the name_comboBox with the current Maya scene state. """ col = lib_state.get_active_collection() if col is None: return roots_enabled = True roots_string = self.getRootFramesValue(col) if roots_string is None: frame = lib_maya_utils.get_current_frame() start, end = utils_time.get_maya_timeline_range_inner() int_list = list(set([start, frame, end])) roots_string = convert_types.intListToString(int_list) self.setRootFramesValue(col, roots_string) else: int_list = convert_types.stringToIntList(roots_string) roots_string = convert_types.intListToString(int_list) assert roots_string is not None block = self.blockSignals(True) self.rootFrames_lineEdit.setEnabled(roots_enabled) self.rootFrames_lineEdit.setText(roots_string) self.blockSignals(block) return
def nextClicked(self): col = lib_state.get_active_collection() if col is None: return frames_string = self.getRootFramesValue(col) if frames_string is None: LOG.warn('Root Frames are not valid') return cur_frame = lib_maya_utils.get_current_frame() int_list = convert_types.stringToIntList(frames_string) next_frame = navigaterootframes_lib.get_next_frame(cur_frame, int_list) if next_frame is None: next_frame = cur_frame lib_maya_utils.set_current_frame(next_frame) return
def removeClicked(self): col = lib_state.get_active_collection() if col is None: return frame = lib_maya_utils.get_current_frame() frames_string = self.getRootFramesValue(col) if frames_string is None: int_list = [frame] frames_string = convert_types.intListToString(int_list) self.setRootFramesValue(col, frames_string) self.rootFrames_lineEdit.setText(frames_string) else: int_list = convert_types.stringToIntList(frames_string) if frame in int_list: int_list.remove(frame) frames_string = convert_types.intListToString(int_list) self.setRootFramesValue(col, frames_string) self.rootFrames_lineEdit.setText(frames_string) return
def compile_collection(col, prog_fn=None): """ Compiles, checks and validates the collection, ready for a solve. :param col: Collection to execute. :type col: Collection :param prog_fn: Progress function that is called each time progress is made. The function should take a single 'int' argument, and the integer is expected to be a percentage value, between 0 and 100. :type prog_fn: None or function """ s = time.time() sol_list = [] solver_tab = col_state.get_solver_tab_from_collection(col) assert isinstance(solver_tab, (str, unicode)) if solver_tab == const.SOLVER_TAB_BASIC_VALUE: sol = mmapi.SolverBasic() range_type = col_state.get_solver_range_type_from_collection(col) if range_type == const.RANGE_TYPE_CURRENT_FRAME_VALUE: frame_num = lib_maya_utils.get_current_frame() frame = mmapi.Frame(frame_num) sol.set_use_single_frame(True) sol.set_single_frame(frame) sol_list.append(sol) else: by_frame = col_state.get_solver_increment_by_frame_from_collection( col) frame_string = col_state.get_solver_frames_from_collection(col) frame_nums = __compile_frame_list(range_type, frame_string, by_frame) frames = [mmapi.Frame(f) for f in frame_nums] sol.set_frame_list(frames) sol_list.append(sol) elif solver_tab == const.SOLVER_TAB_STANDARD_VALUE: sol = mmapi.SolverStandard() range_type = col_state.get_solver_range_type_from_collection(col) if range_type == const.RANGE_TYPE_CURRENT_FRAME_VALUE: frame_num = lib_maya_utils.get_current_frame() frame = mmapi.Frame(frame_num) sol.set_use_single_frame(True) sol.set_single_frame(frame) sol_list.append(sol) else: # Frame numbers by_frame = col_state.get_solver_increment_by_frame_from_collection( col) frame_string = col_state.get_solver_frames_from_collection(col) frame_nums = __compile_frame_list(range_type, frame_string, by_frame) # Root frame numbers root_frame_num_string = col_state.get_solver_root_frames_from_collection( col) if root_frame_num_string is None: start, end = utils_time.get_maya_timeline_range_inner() root_frame_num_string = '{0},{1}'.format(start, end) root_frame_nums = converttypes.stringToIntList( root_frame_num_string) frames = [ mmapi.Frame(f) for f in frame_nums if f not in root_frame_nums ] root_frames = [mmapi.Frame(f) for f in root_frame_nums] sol.set_root_frame_list(root_frames) sol.set_frame_list(frames) global_solve = col_state.get_solver_global_solve_from_collection( col) only_root = col_state.get_solver_only_root_frames_from_collection( col) sol.set_global_solve(global_solve) sol.set_only_root_frames(only_root) sol_list.append(sol) elif solver_tab.lower() == const.SOLVER_TAB_LEGACY_VALUE: step_list = get_solver_steps_from_collection(col) sol_list = compile_solvers_from_steps(col, step_list, prog_fn=prog_fn) else: msg = 'Solver tab value is invalid: %r' raise TypeError(msg % solver_tab) col.set_solver_list(sol_list) e = time.time() LOG.debug('Compile time (GUI): %r seconds', e - s) return
def compile(self, col, override_current_frame=False): """ Convert Solver Step into a list of Solvers. :param col: The collection this solver step belongs to. :type col: Collection :param override_current_frame: Forces the solve to only use the current frame. :type override_current_frame: bool :returns: List of solvers compiled from this solver step. :rtype: list of Solver """ sol_list = [] enabled = self.get_enabled() if enabled is not True: return sol_list # Default Solver values max_iter_num = const.MAX_ITERATION_NUM_DEFAULT_VALUE auto_diff_type = const.AUTO_DIFF_TYPE_DEFAULT_VALUE strategy = self.get_strategy() # If the option 'override current frame' is on, we ignore the # frames given and override with the current frame number. int_list = [] if override_current_frame is True: cur_frame = lib_maya_utils.get_current_frame() int_list = [cur_frame] else: int_list = self.get_frame_list() # Use number of different attributes later on to switch strategies. attr_list = col.get_attribute_list() attrs_anim_num = 0 attrs_static_num = 0 for attr in attr_list: if attr.is_animated(): attrs_anim_num += 1 if attr.is_static(): attrs_static_num += 1 # If there are no static attributes, the solver will consider # "use_static_attrs" to be off. use_anim_attrs = self.get_use_anim_attrs() and attrs_anim_num > 0 use_static_attrs = self.get_use_static_attrs() and attrs_static_num > 0 if use_anim_attrs is True and use_static_attrs is False: # Solve only animated attributes. sol_list = _solve_anim_attrs( max_iter_num, auto_diff_type, int_list, ) elif ((use_anim_attrs is True and use_static_attrs is True) or (use_anim_attrs is False and use_static_attrs is True)): # Solve static attributes, as well as animated attributes. sol_list = _solve_all_attrs( max_iter_num, auto_diff_type, int_list, strategy, ) elif use_anim_attrs is False and use_static_attrs is False: msg = 'No attributes will be solved: ' msg += 'use_static_attrs=%r, use_anim_attrs=%r' msg = msg % (use_static_attrs, use_anim_attrs) LOG.debug(msg) else: msg = 'We should not get here: ' msg += 'use_static_attrs=%r, use_anim_attrs=%r' msg = msg % (use_static_attrs, use_anim_attrs) raise ValueError(msg) return sol_list