Example #1
0
    def updateModel(self):
        """
        Refresh the name_comboBox with the current Maya scene state.
        """
        self.populateModel(self.model)

        index = None
        col = lib_state.get_active_collection()
        if col is None:
            cols = lib_col.get_collections()
            if len(cols) > 0:
                # If there is no active collection, but there are
                # collections already created, we make sure the first
                # collection is marked active.
                col = cols[0]
                lib_state.set_active_collection(col)
        else:
            index = self.getActiveIndex(self.model, col)

        block = self.blockSignals(True)
        if index is not None:
            self.name_comboBox.setCurrentIndex(index)
        self.nameChanged.emit()
        self.blockSignals(block)
        return
Example #2
0
    def removeActiveNode(self):
        """
        Delete the currently active collection.
        """
        col = lib_state.get_active_collection()
        if col is None:
            LOG.warning('No active collection to delete.')
            return
        title = 'Remove Collection?'
        text = 'Would you like to remove the current Collection?'
        text += '\n\nRemove "' + str(col.get_node()) + '"?'
        clicked_button = QtWidgets.QMessageBox.question(self, title, text)
        if clicked_button != QtWidgets.QMessageBox.Yes:
            LOG.warn('User cancelled operation.')
            return

        cols = lib_col.get_collections()
        prev_col = lib_col.get_previous_collection(cols, col)

        steps = lib_col.get_solver_steps_from_collection(col)
        for step in steps:
            lib_col.remove_solver_step_from_collection(col, step)

        lib_col.delete_collection(col)
        lib_state.set_active_collection(prev_col)

        self.itemRemoved.emit()
        self.itemChanged.emit()
        self.nameChanged.emit()
        return
Example #3
0
    def removeCollectionNode(self):
        col = lib_state.get_active_collection()
        if col is None:
            LOG.warning('No active collection to delete.')
            return

        cols = lib_col.get_collections()
        prev_col = lib_col.get_previous_collection(cols, col)

        steps = lib_col.get_solver_steps_from_collection(col)
        for step in steps:
            lib_col.remove_solver_step_from_collection(col, step)

        lib_col.delete_collection(col)
        lib_state.set_active_collection(prev_col)

        self.updateDynamicWindowTitle()
        self.updateStatusWithSolveResult()
        self.updateCollectionModel()
        self.updateObjectToggleButtons()
        self.updateObjectColumnVisibility()
        self.updateObjectModel()
        self.updateAttributeToggleButtons()
        self.updateAttributeColumnVisibility()
        self.updateAttributeModel()
        self.updateSolverModel()
        self.updateSolveValidState()
        return
Example #4
0
 def populateCollectionModel(self, model):
     cols = lib_col.get_collections()
     string_data_list = []
     for col in cols:
         node = col.get_node()
         string_data_list.append((node, col))
     model.setStringDataList(string_data_list)
     return
Example #5
0
 def collectionUpdateClicked(self):
     col_list = col_lib.get_collections()
     active_col = state_lib.get_active_collection()
     self.updateCollectionList(
         self.collection_comboBox,
         self.collection_model,
         active_col,
         col_list,
     )
     return
Example #6
0
 def populateCollectionModel(self, model):
     valid = uiutils.isValidQtObject(model)
     if valid is False:
         return
     cols = lib_col.get_collections()
     string_data_list = []
     for col in cols:
         node = col.get_node()
         string_data_list.append((node, col))
     model.setStringDataList(string_data_list)
     return
Example #7
0
 def populateModel(self, model):
     """
     Set the model based on the current Maya scene state.
     """
     valid = uiutils.isValidQtObject(model)
     if valid is False:
         return
     cols = lib_col.get_collections()
     string_data_list = []
     for col in cols:
         node = col.get_node()
         string_data_list.append((node, col))
     model.setStringDataList(string_data_list)
     return
Example #8
0
    def updateCollectionModel(self):
        self.populateCollectionModel(self.collectionName_model)

        col = lib_state.get_active_collection()
        if col is None:
            cols = lib_col.get_collections()
            if len(cols) > 0:
                # If there is no active collection, but there are
                # collections already created, we make sure the first
                # collection is marked active.
                col = cols[0]
                lib_state.set_active_collection(col)

        if col is not None:
            index = self.getDefaultCollectionIndex(self.collectionName_model, col)
            if index is not None:
                self.collectionName_comboBox.setCurrentIndex(index)

        self.updateDynamicWindowTitle()
        return
    def removeActiveNode(self):
        """
        Delete the currently active collection.
        """
        col = lib_state.get_active_collection()
        if col is None:
            LOG.warning('No active collection to delete.')
            return

        cols = lib_col.get_collections()
        prev_col = lib_col.get_previous_collection(cols, col)

        steps = lib_col.get_solver_steps_from_collection(col)
        for step in steps:
            lib_col.remove_solver_step_from_collection(col, step)

        lib_col.delete_collection(col)
        lib_state.set_active_collection(prev_col)

        self.itemRemoved.emit()
        self.itemChanged.emit()
        self.nameChanged.emit()
        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
Example #11
0
    def populateUi(self):
        config = get_config()
        self._file_info = None

        w, h = lib.get_default_image_resolution()
        self.imageRes_label.setEnabled(False)
        self.imageResWidth_label.setEnabled(False)
        self.imageResWidth_spinBox.setValue(w)
        self.imageResWidth_spinBox.setEnabled(False)
        self.imageResHeight_label.setEnabled(False)
        self.imageResHeight_spinBox.setValue(h)
        self.imageResHeight_spinBox.setEnabled(False)

        self.fileInfo_plainTextEdit.setReadOnly(True)

        value = get_config_value(
            config,
            'data/load_bundle_position',
            const.LOAD_BUNDLE_POS_DEFAULT_VALUE)
        self.loadBndPositions_checkBox.setChecked(value)

        # Get the file path from the clipboard.
        try:
            clippy = QtGui.QClipboard()
            text = str(clippy.text()).strip()
            if fileutils.is_valid_file_path(text):
                self.setFilePath(text)
        except Exception as e:
            msg = 'Could not get file path from clipboard.'
            LOG.warning(msg)
            LOG.info(str(e))

        all_camera_nodes = lib.get_cameras()
        selected_cameras = lib.get_selected_cameras()
        active_camera = lib.get_active_viewport_camera()
        self.updateCameraList(
            self.camera_comboBox,
            self.camera_model,
            all_camera_nodes,
            selected_cameras,
            active_camera
        )
        active_camera = self.getCameraData()
        mkr_grp_nodes = lib.get_marker_groups(active_camera)
        active_mkr_grp = None
        self.updateMarkerGroupList(
            self.markerGroup_comboBox,
            self.markerGroup_model,
            active_mkr_grp,
            mkr_grp_nodes
        )

        col_list = col_lib.get_collections()
        active_col = state_lib.get_active_collection()
        self.updateCollectionList(
            self.collection_comboBox,
            self.collection_model,
            active_col,
            col_list
        )
        # If the user's preferences say to add the marker to the
        # collection, then turn on the feature.
        auto_add_marker = get_user_prefs_add_marker_to_collection()
        self.collection_checkBox.setChecked(auto_add_marker)
        self.updateCollectionEnabledState()

        value = get_config_value(
            config,
            "data/load_mode",
            const.LOAD_MODE_DEFAULT_VALUE
        )
        self.populateLoadModeModel(self.loadMode_model)
        index = self.loadMode_model.stringList().index(value)
        self.loadMode_comboBox.setCurrentIndex(index)

        value = get_config_value(
            config,
            "data/distortion_mode",
            const.DISTORTION_MODE_DEFAULT_VALUE
        )
        self.populateDistortionModeModel(self.distortionMode_model)
        index = self.distortionMode_model.stringList().index(value)
        self.distortionMode_comboBox.setCurrentIndex(index)

        value = get_config_value(
            config,
            'data/use_overscan',
            const.USE_OVERSCAN_DEFAULT_VALUE)
        self.overscan_checkBox.setChecked(value)
        self.updateOverscanValues()
        return