def run_connect_markers_to_active_collection(**kwargs): import mmSolver.tools.userpreferences.constant as userprefs_const import mmSolver.tools.userpreferences.lib as userprefs_lib # Enable a toggle to turn on or off this affect. config = userprefs_lib.get_config() key = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_KEY run_event = userprefs_lib.get_value(config, key) if run_event == userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_NONE_VALUE: return LOG.debug("run_connect_markers_to_active_collection: %s", kwargs) s = time.time() import mmSolver.api as mmapi import mmSolver.tools.solver.lib.state as state_lib mmapi.load_plugin() col = state_lib.get_active_collection() if col is None: return mkr = kwargs.get('mkr') if isinstance(mkr, list): col.add_marker_list(mkr) elif isinstance(mkr, mmapi.Marker): col.add_marker(mkr) e = time.time() LOG.debug("run_connect_markers_to_active_collection: time=%s", e - s) return
def _getAllowObjectRelations(): config = userprefs_lib.get_config() key = userprefs_const.SOLVER_UI_ALLOW_OBJECT_RELATIONS_KEY allow_obj_relations = userprefs_lib.get_value(config, key) true_value = userprefs_const.SOLVER_UI_ALLOW_OBJECT_RELATIONS_TRUE_VALUE visible = allow_obj_relations == true_value return visible
def gather_execute_options(): """ Query the current Solver UI ExecuteOptions state that is saved in the scene. :return: The ExecuteOptions ready to be passed to an execution function. :rtype: ExecuteOptions """ refresh_state = lib_state.get_refresh_viewport_state() disable_viewport_two_state = not refresh_state force_update_state = lib_state.get_force_dg_update_state() do_isolate_state = lib_state.get_isolate_object_while_solving_state() pre_solve_force_eval = lib_state.get_pre_solve_force_eval_state() # Display Types disp_node_types = dict() image_plane_state = lib_state.get_display_image_plane_while_solving_state() meshes_state = lib_state.get_display_meshes_while_solving_state() disp_node_types['imagePlane'] = image_plane_state disp_node_types['mesh'] = meshes_state # Minimal UI from config file. config = userprefs_lib.get_config() key = userprefs_const.SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY minimal_ui = userprefs_lib.get_value(config, key) minimal_ui = minimal_ui == userprefs_const.SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_TRUE_VALUE options = mmapi.createExecuteOptions( refresh=refresh_state, disable_viewport_two=disable_viewport_two_state, force_update=force_update_state, do_isolate=do_isolate_state, pre_solve_force_eval=pre_solve_force_eval, display_node_types=disp_node_types, use_minimal_ui=minimal_ui) return options
def _getShowValidateButton(): config = userprefs_lib.get_config() key = userprefs_const.SOLVER_UI_SHOW_VALIDATE_BTN_KEY show_validate_btn = userprefs_lib.get_value(config, key) true_value = userprefs_const.SOLVER_UI_SHOW_VALIDATE_BTN_TRUE_VALUE visible = show_validate_btn == true_value return visible
def updateSolverUIShowValidateButtonWidget(self, config): key = pref_const.SOLVER_UI_SHOW_VALIDATE_BTN_KEY value = userprefs_lib.get_value(config, key) label = userprefs_lib.get_label_from_value(key, value) assert isinstance(label, pycompat.TEXT_TYPE) labels = userprefs_lib.get_labels(key) self.showValidateButtonComboBox.clear() self.showValidateButtonComboBox.addItems(labels) self.showValidateButtonComboBox.setCurrentText(label) return
def updateAddNewMarkersToWidget(self, config): key = pref_const.REG_EVNT_ADD_NEW_MKR_TO_KEY value = userprefs_lib.get_value(config, key) label = userprefs_lib.get_label_from_value(key, value) assert isinstance(label, pycompat.TEXT_TYPE) labels = userprefs_lib.get_labels(key) self.addNewMarkersToComboBox.clear() self.addNewMarkersToComboBox.addItems(labels) self.addNewMarkersToComboBox.setCurrentText(label) return
def updateSolverUIMinimalUIWhileSolvingWidget(self, config): key = pref_const.SOLVER_UI_MINIMAL_UI_WHILE_SOLVING_KEY value = userprefs_lib.get_value(config, key) label = userprefs_lib.get_label_from_value(key, value) assert isinstance(label, pycompat.TEXT_TYPE) labels = userprefs_lib.get_labels(key) self.minimalUIWhileSolvingComboBox.clear() self.minimalUIWhileSolvingComboBox.addItems(labels) self.minimalUIWhileSolvingComboBox.setCurrentText(label) return
def updateSolverUIAllowObjectRelationsWidget(self, config): key = pref_const.SOLVER_UI_ALLOW_OBJECT_RELATIONS_KEY value = userprefs_lib.get_value(config, key) label = userprefs_lib.get_label_from_value(key, value) assert isinstance(label, pycompat.TEXT_TYPE) labels = userprefs_lib.get_labels(key) self.allowObjectRelationsComboBox.clear() self.allowObjectRelationsComboBox.addItems(labels) self.allowObjectRelationsComboBox.setCurrentText(label) return
def updateSolverUIValidateOnOpenWidget(self, config): key = pref_const.SOLVER_UI_VALIDATE_ON_OPEN_KEY value = userprefs_lib.get_value(config, key) label = userprefs_lib.get_label_from_value(key, value) assert isinstance(label, basestring) labels = userprefs_lib.get_labels(key) self.validateSolverOnUIOpenComboBox.clear() self.validateSolverOnUIOpenComboBox.addItems(labels) self.validateSolverOnUIOpenComboBox.setCurrentText(label) 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 get_user_prefs_add_marker_to_collection(): config = userprefs_lib.get_config() key = userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_KEY value = userprefs_lib.get_value(config, key) return value != userprefs_const.REG_EVNT_ADD_NEW_MKR_TO_NONE_VALUE
def _getValidateOnOpen(): config = userprefs_lib.get_config() key = userprefs_const.SOLVER_UI_VALIDATE_ON_OPEN_KEY validate_on_open = userprefs_lib.get_value(config, key) true_value = userprefs_const.SOLVER_UI_VALIDATE_ON_OPEN_TRUE_VALUE return validate_on_open == true_value