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
def smooth_selected_keyframes(): """ Smooth the selected keyframes in the Graph Editor. Usage: 1. Select keyframes in Graph Editor. 2. Run tool 3. Keyframe values will be smoothed. """ key_attrs = maya.cmds.keyframe(query=True, name=True) or [] if len(key_attrs) == 0: msg = ( 'Please select keyframes ' '(in the Graph Editor) to smooth.' ) LOG.warning(msg) return smooth_type = configmaya.get_scene_option( const.CONFIG_MODE_KEY, default=const.DEFAULT_MODE) width = configmaya.get_scene_option( const.CONFIG_WIDTH_KEY, default=const.DEFAULT_WIDTH) blend_smooth_type = utils_const.SMOOTH_TYPE_GAUSSIAN blend_width = configmaya.get_scene_option( const.CONFIG_BLEND_WIDTH_KEY, default=const.DEFAULT_BLEND_WIDTH) undo_id = 'smoothkeyframes: ' undo_id += str(datetime.datetime.isoformat(datetime.datetime.now())) undo_id += ' ' undo_id += str(uuid.uuid4()) with undo_utils.undo_chunk_context(undo_id): for key_attr in key_attrs: selected_keyframes = maya.cmds.keyframe( key_attr, query=True, selected=True ) or [] if len(selected_keyframes) == 0: msg = ( 'Please select keyframes ' '(in the Graph Editor) to smooth.' ) LOG.warning(msg) continue lib.smooth_animcurve( key_attr, selected_keyframes, smooth_type, width, blend_smooth_type, blend_width) return
def run_solve_on_all_frames(): """ Run the solver, forcing 'Override Current Frame' off. """ 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): run_solve(override_current_frame=False) return
def apply(self): cam = None mkr_grp = None col = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() add_to_collection = self.subForm.getAddToCollectionValue() collection_text = self.subForm.getCollectionText() collection_data = self.subForm.getCollectionData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() use_overscan = self.subForm.getUseOverscanValue() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() camera_field_of_view = None if use_overscan is True: camera_field_of_view = self.subForm.getCameraFieldOfViewValue() # Temporarily disable adding new Markers to the Active # Collection. config = userprefs_lib.get_config() key = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_KEY old_value = userprefs_lib.get_value(config, key) temp_value = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_NONE_VALUE userprefs_lib.set_value(config, key, temp_value) try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: # Get Camera and MarkerGroup. if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() mkr_grp = lib.create_new_marker_group(cam) else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) # Get Collection col = None if add_to_collection is True: if collection_text == const.NEW_COLLECTION_VALUE: col = col_lib.create_collection() else: col = collection_data self.progressBar.setValue(70) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, col=col, with_bundles=True, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() # NOTE: camera_field_of_view can only be from one # camera, because (we assume) only one MarkerData # file can be loaded at once. mayareadfile.update_nodes( mkr_list, mkr_data_list, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Restore original config value. lib.deferred_revert_of_config_value(config, key, old_value) # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes) # Update the list of Collections, and pick the last used # Collection. active_col = col col_list = col_lib.get_collections() self.subForm.updateCollectionList(self.subForm.collection_comboBox, self.subForm.collection_model, active_col, col_list) # Update config file with latest values. config = get_config() if config is not None: config.set_value("data/use_overscan", use_overscan) config.set_value("data/load_bundle_position", load_bnd_pos) config.set_value("data/distortion_mode", undist_mode) config.set_value("data/load_mode", load_mode) config.write() return
def apply(self): cam = None mkr_grp = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() use_overscan = self.subForm.getUseOverscanValue() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() camera_field_of_view = None if use_overscan is True: camera_field_of_view = self.subForm.getCameraFieldOfViewValue() try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() mkr_grp = lib.create_new_marker_group(cam) else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() # NOTE: camera_field_of_view can only be from one # camera, because (we assume) only one MarkerData # file can be loaded at once. mayareadfile.update_nodes( mkr_list, mkr_data_list, load_bundle_position=load_bnd_pos, camera_field_of_view=camera_field_of_view) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList(self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes) # Update config file with latest values. config = get_config() if config is not None: config.set_value("data/use_overscan", use_overscan) config.set_value("data/load_bundle_position", load_bnd_pos) config.set_value("data/distortion_mode", undist_mode) config.set_value("data/load_mode", load_mode) config.write() return
def apply(self): cam = None mkr_grp = None file_path = self.subForm.getFilePath() load_mode = self.subForm.getLoadModeText() camera_text = self.subForm.getCameraText() camera_data = self.subForm.getCameraData() mkr_grp_text = self.subForm.getMarkerGroupText() mkr_grp_data = self.subForm.getMarkerGroupData() load_bnd_pos = self.subForm.getLoadBundlePositions() undist_mode = self.subForm.getDistortionModeText() undistorted = undist_mode == const.UNDISTORTION_MODE_VALUE width, height = self.subForm.getImageResolution() try: self.progressBar.setValue(0) self.progressBar.show() with undoutils.undo_chunk_context(): _, mkr_data_list = mayareadfile.read( file_path, image_width=width, image_height=height, undistorted=undistorted, ) self.progressBar.setValue(50) if load_mode == const.LOAD_MODE_NEW_VALUE: if camera_text == const.NEW_CAMERA_VALUE: cam = lib.create_new_camera() else: cam = camera_data if mkr_grp_text == const.NEW_MARKER_GROUP_VALUE: mkr_grp = lib.create_new_marker_group(cam) else: mkr_grp = mkr_grp_data self.progressBar.setValue(60) mayareadfile.create_nodes( mkr_data_list, cam=cam, mkr_grp=mkr_grp, with_bundles=True, load_bundle_position=load_bnd_pos, ) elif load_mode == const.LOAD_MODE_REPLACE_VALUE: self.progressBar.setValue(60) mkr_list = lib.get_selected_markers() mayareadfile.update_nodes(mkr_list, mkr_data_list) else: raise ValueError('Load mode is not valid: %r' % load_mode) self.progressBar.setValue(99) lib.trigger_maya_to_refresh() finally: self.progressBar.setValue(100) self.progressBar.hide() # Update the camera comboBox with the created camera, or # the last used camera. all_camera_nodes = lib.get_cameras() selected_cameras = [cam] active_camera = cam self.subForm.updateCameraList( self.subForm.camera_comboBox, self.subForm.camera_model, all_camera_nodes, selected_cameras, active_camera ) active_camera = cam active_mkr_grp = mkr_grp mkr_grp_nodes = lib.get_marker_groups(active_camera) self.subForm.updateMarkerGroupList( self.subForm.markerGroup_comboBox, self.subForm.markerGroup_model, active_mkr_grp, mkr_grp_nodes ) return