def save_program(*args): """ Save the program. :return: """ # Do this first upon button click! _clear_output_window() _initialize_export_progress_bar() # Check program, commands, raise exception on failure program_settings = _get_settings() animation_settings = program_settings[1] start_frame = animation_settings['Start Frame'] pm.currentTime(start_frame) # Force evaluation of reconcile rotation to ensure proper export mimic_utils.reconcile_rotation(force_eval=True) command_dicts = _get_command_dicts(*program_settings) violation_exception, violation_warning = _check_command_dicts(command_dicts, *program_settings) # If we're sampling keyframes only, we assume it's for a post-processor # that's not time-dependent, and, therefore, we shouldn't raise exceptions # for limit violations postproc_settings = program_settings[2] using_keyframes_only = postproc_settings['Using Keyframes Only'] if not using_keyframes_only: if violation_exception: _initialize_export_progress_bar(is_on=False) pm.scrollField(OUTPUT_WINDOW_NAME, insertText='\n\nNO PROGRAM EXPORTED!', edit=True) pm.headsUpMessage('WARNINGS: No Program Exported; ' \ 'See Mimic output window for details') raise mimic_utils.MimicError('Limit violations found. ' \ 'No Program Exported. ' \ 'See Mimic output window for details.') # Continue to save program: _process_program(command_dicts, *program_settings) if violation_warning: if not using_keyframes_only: pm.headsUpMessage('Program exported with warnings; ' \ 'See Mimic output window for details') else: pm.headsUpMessage('Program exported successfuly; ' \ 'See Mimic output window for details') else: pm.headsUpMessage('Program exported successfuly; ' \ 'See Mimic output window for details') _initialize_export_progress_bar(is_on=False)
def analyze_program(*args): """ Check program parameters, raise exception on failure :return: """ # Do this first upon button click! _clear_output_window() _initialize_export_progress_bar() # Check program, commands, raise exception on failure program_settings = _get_settings() robot_name = program_settings[0] animation_settings = program_settings[1] start_frame = animation_settings['Start Frame'] pm.currentTime(start_frame) # Force evaluation of reconcile rotation to ensure proper export mimic_utils.reconcile_rotation(force_eval=True) command_dicts = _get_command_dicts(*program_settings) limit_data = mimic_utils.get_all_limits(robot_name) violation_exception, violation_warning = _check_command_dicts(command_dicts, *program_settings) _initialize_export_progress_bar(is_on=False) # If PyQtGraph imports correctly, we can run the analysis graphing utility # Likeliest cause of import failure is no or improper installation of numPy # See Mimic installation instructions for more details on installing numPy try: import pyqtgraph as pg analysis.run(robot_name, command_dicts, limit_data) except ImportError: pm.warning('MIMIC: Analysis module did not load successfully; ' \ 'analysis graphing feature disabled. ' \ 'Check that you have numPy installed properly; ' \ 'see Mimic installation instructions for more details') # If we're sampling keyframes only, we assume it's for a post-processor # that's not time-dependent, and, therefore, we shouldn't raise exceptions # for limit violations postproc_settings = program_settings[2] using_keyframes_only = postproc_settings['Using Keyframes Only'] if violation_exception and not using_keyframes_only: raise mimic_utils.MimicError('Limit violations found. ' \ 'See Mimic output window for details.')
def _sample_frames_get_command_dicts(robot_name, frames, animation_settings, time_interval_in_seconds, user_options): """ Sample robot commands using a list of frames and user options. :param robot_name: :param frames: :param animation_settings: :param user_options: :return: """ # Initialize output array. command_dicts = [] time_index_count = 0 start_frame = animation_settings['Start Frame'] end_frame = animation_settings['End Frame'] for frame in frames: # Set the background to the current frame # TODO: Implement this! This rocks: # pm.currentTime(frame) # Create a dict of datatypes per frame command_dict = {} # Add this frame number/step/index to the dictionary command_dict['Frame'] = frame command_dict['Framerate'] = animation_settings['Framerate'] command_dict['Time Index'] = time_index_count * time_interval_in_seconds time_index_count += 1 # Get motion parameters if not user_options.Ignore_motion: if user_options.Include_axes: axes = _sample_frame_get_axes(robot_name, frame) command_dict[postproc.AXES] = postproc.Axes(*axes) if user_options.Include_pose: pose = _sample_frame_get_pose(robot_name, frame) command_dict[postproc.POSE] = postproc.Pose(*pose) if user_options.Include_external_axes: external_axes = _sample_frame_get_external_axes(robot_name, frame) command_dict[postproc.EXTERNAL_AXES] = postproc.ExternalAxes(*external_axes) if user_options.Include_configuration: configuration = _sample_frame_get_configuration(robot_name, frame) command_dict[postproc.CONFIGURATION] = postproc.Configuration(*configuration) # Get IO parameters if not user_options.Ignore_IOs: if user_options.Include_digital_outputs: digital_output = _sample_frame_get_outs(robot_name, frame, 'digital') command_dict[postproc.DIGITAL_OUTPUT] = digital_output if user_options.Include_digital_inputs: # TODO: Implement digital inputs # digital_input = None # command_dict[postproc.DIGITAL_INPUT'] = postproc.DigitalOutput(*digital_input) pass if user_options.Include_analog_outputs: analog_output = _sample_frame_get_outs(robot_name, frame, 'analog') command_dict[postproc.ANALOG_OUTPUT] = analog_output if user_options.Include_analog_inputs: # TODO: Implement analog inputs # analog_input = None # command_dict[postproc.ANALOG_INPUT] = postproc.DigitalOutput(*analog_input) pass command_dicts.append(command_dict) pm.refresh() _update_export_progress_bar(start_frame, end_frame, frame) # Reset current frame (just in case) pm.currentTime(frames[0]) mimic_utils.reconcile_rotation(force_eval=True) return command_dicts