def selectionChanged(self, selected, deselected):
        select_indexes = [idx for idx in selected.indexes()]
        deselect_indexes = [idx for idx in deselected.indexes()]
        selected_indexes = self.selModel.selectedRows()
        select_nodes = _lookupMayaNodesFromAttrUINodes(select_indexes,
                                                       self.filterModel)
        deselect_nodes = _lookupMayaNodesFromAttrUINodes(
            deselect_indexes, self.filterModel)
        selected_nodes = _lookupMayaNodesFromAttrUINodes(
            selected_indexes, self.filterModel)
        if self.isActiveWindow() is True:
            # Only allow Maya selection changes when the user has the
            # UI focused. This breaks the Maya and Qt selection
            # callback cycle.

            # Because an attribute and node may refer to the same
            # underlying node name, we must be sure we don't deselect a
            # node that has other attributes selected.
            deselect_nodes = list(set(deselect_nodes) - set(selected_nodes))
            try:
                mmapi.set_solver_running(True)  # disable selection callback.
                lib_maya_utils.add_scene_selection(select_nodes)
                lib_maya_utils.remove_scene_selection(deselect_nodes)
            finally:
                mmapi.set_solver_running(False)  # enable selection callback
        return
 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 selectionChanged(self, selected, deselected):
     """
     Look up the Maya node from the 'selected' nodes, and add them
     to the Maya selection.
     """
     select_indexes = [idx for idx in selected.indexes()]
     deselect_indexes = [idx for idx in deselected.indexes()]
     select_nodes = _lookupUINodesFromIndexes(
         select_indexes,
         self.filterModel
     )
     deselect_nodes = _lookupUINodesFromIndexes(
         deselect_indexes,
         self.filterModel
     )
     if self.isActiveWindow() is True:
         # Only allow Maya selection changes when the user has the
         # UI focused. This breaks the Maya and Qt selection
         # callback cycle.
         try:
             mmapi.set_solver_running(True)  # disable selection callback.
             lib_maya_utils.add_scene_selection(select_nodes)
             lib_maya_utils.remove_scene_selection(deselect_nodes)
         finally:
             mmapi.set_solver_running(False)  # enable selection callback
     return
Exemple #4
0
 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 tools_utils.tool_context(use_undo_chunk=True,
                                   undo_chunk_name=undo_id,
                                   restore_current_frame=False,
                                   pre_update_frame=False,
                                   post_update_frame=False,
                                   use_dg_evaluation_mode=True,
                                   disable_viewport=False):
         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 removeClicked(self):
        """
        Remove the selected nodes or node attributes from the output
        attributes data model.
        """
        try:
            mmapi.set_solver_running(True)  # disable selection callback.

            s = time.time()
            col = lib_state.get_active_collection()
            if col is None:
                return
            e = time.time()
            LOG.debug("attribute removeClicked1: t=%s", e - s)

            s = time.time()
            sel = lib_maya_utils.get_scene_selection()
            ui_nodes = lib_uiquery.get_selected_ui_nodes(
                self.treeView, self.filterModel)
            node_list = lib_uiquery.convert_ui_nodes_to_nodes(ui_nodes, 'data')
            e = time.time()
            LOG.debug("attribute removeClicked2: t=%s", e - s)

            s = time.time()
            attr_list = _convertNodeListToAttrList(node_list)
            lib_attr.remove_attr_from_collection(attr_list, col)

            e = time.time()
            LOG.debug("attribute removeClicked3: t=%s", e - s)

            # Remove Callbacks
            s = time.time()
            callback_manager = self.callback_manager
            if callback_manager is not None:
                lib_attr.remove_callbacks_from_attributes(
                    attr_list, callback_manager)
            e = time.time()
            LOG.debug("attribute removeClicked4: t=%s", e - s)
        finally:
            mmapi.set_solver_running(False)  # enable selection callback

        s = time.time()
        self.dataChanged.emit()
        self.viewUpdated.emit()
        e = time.time()
        LOG.debug("attribute removeClicked5: t=%s", e - s)

        # Restore selection.
        s = time.time()
        lib_maya_utils.set_scene_selection(sel)
        e = time.time()
        LOG.debug("attribute removeClicked5: t=%s", e - s)
        return
 def set_details_selected_attributes(self):
     try:
         # Disable selection callback.
         mmapi.set_solver_running(True)
         col = lib_state.get_active_collection()
         attr_list = _get_selected_attrs(self)
         lib_attr.set_details_selected_attributes(attr_list, col)
     finally:
         # Enable selection callback
         mmapi.set_solver_running(False)
         # TODO: Force the changed data model to update the UI.
     return
    def addClicked(self):
        """
        Add the selected nodes or node attributes to the data model.
        """
        # Store the selection, in case any tools or callbacks
        # accidentally change the scene selection.
        sel = lib_maya_utils.get_scene_selection()

        s = time.time()
        col = lib_state.get_active_collection()
        if col is None:
            msg = 'Cannot add attributes, active collection is not defined.'
            LOG.warning(msg)
            return
        e = time.time()
        LOG.debug("attribute addClicked1: t=%s", e - s)

        s = time.time()
        attr_list = lib_maya_utils.get_selected_maya_attributes()
        attr_list = lib_maya_utils.input_attributes_filter(attr_list)
        if len(attr_list) == 0:
            attr_list = lib_maya_utils.get_node_default_attributes(sel)
            attr_list = lib_maya_utils.input_attributes_filter(attr_list)
        if len(attr_list) == 0:
            msg = 'Please select nodes or attributes in the channel box.'
            LOG.warning(msg)
            return
        e = time.time()
        LOG.debug("attribute addClicked2: t=%s", e - s)

        s = time.time()
        try:
            mmapi.set_solver_running(True)  # disable selection callback.
            lib_attr.add_attributes_to_collection(attr_list, col)
        finally:
            mmapi.set_solver_running(False)  # enable selection callback
        e = time.time()
        LOG.debug("attribute addClicked3: t=%s", e - s)

        # Restore selection.
        s = time.time()
        lib_maya_utils.set_scene_selection(sel)
        e = time.time()
        LOG.debug("attribute addClicked6: t=%s", e - s)
        return
Exemple #8
0
def remove():
    """
    Remove the centering nodes in the current active viewport.
    """
    model_editor = viewport_utils.get_active_model_editor()
    if model_editor is None:
        msg = 'Please select an active 3D viewport.'
        LOG.warning(msg)
        return

    cam_tfm, cam_shp = viewport_utils.get_viewport_camera(model_editor)
    if cam_shp is None:
        msg = 'Please select an active 3D viewport to get a camera.'
        LOG.warning(msg)
        return

    try:
        mmapi.set_solver_running(True)
        mmapi.load_plugin()
        reproject_utils.remove_reprojection_from_camera(cam_tfm, cam_shp)
        reproject_utils.reset_pan_zoom(cam_tfm, cam_shp)
    finally:
        mmapi.set_solver_running(False)
    return
    def addClicked(self):
        """
        Add the selected nodes or node attributes to the data model.
        """
        s = time.time()
        col = lib_state.get_active_collection()
        if col is None:
            msg = 'Cannot add attributes, active collection is not defined.'
            LOG.warning(msg)
            return
        e = time.time()
        LOG.debug("attribute addClicked1: t=%s", e - s)

        s = time.time()
        sel = lib_maya_utils.get_scene_selection()
        attr_list = lib_maya_utils.get_selected_maya_attributes()
        attr_list = lib_maya_utils.input_attributes_filter(attr_list)
        if len(attr_list) == 0:
            attr_list = lib_maya_utils.get_selected_node_default_attributes()
            attr_list = lib_maya_utils.input_attributes_filter(attr_list)
        if len(attr_list) == 0:
            msg = 'Please select nodes or attributes in the channel box.'
            LOG.warning(msg)
            return
        e = time.time()
        LOG.debug("attribute addClicked2: t=%s", e - s)

        s = time.time()
        try:
            mmapi.set_solver_running(True)  # disable selection callback.
            lib_attr.add_attributes_to_collection(attr_list, col)
        finally:
            mmapi.set_solver_running(False)  # enable selection callback
        e = time.time()
        LOG.debug("attribute addClicked3: t=%s", e - s)

        def update_func():
            if uiutils.isValidQtObject(self) is False:
                return
            self.dataChanged.emit()
            self.viewUpdated.emit()
            return

        # Add Callbacks
        s = time.time()
        callback_manager = self.callback_manager
        if callback_manager is not None:
            lib_attr.add_callbacks_to_attributes(
                attr_list,
                update_func,
                callback_manager,
            )
        e = time.time()
        LOG.debug("attribute addClicked4: t=%s", e - s)

        s = time.time()
        update_func()
        e = time.time()
        LOG.debug("attribute addClicked5: t=%s", e - s)

        # Restore selection.
        s = time.time()
        lib_maya_utils.set_scene_selection(sel)
        e = time.time()
        LOG.debug("attribute addClicked6: t=%s", e - s)
        return
Exemple #10
0
def main():
    """
    Center the selected transform onto the camera view.

    .. todo::

        - Allow 2D Center on selected vertices.

        - Support Stereo-camera setups (center both cameras, and ensure
          both have the same zoom).

        - Allow centering on multiple objects at once. We will center
          on the middle of all transforms.

    """
    model_editor = viewport_utils.get_active_model_editor()
    if model_editor is None:
        msg = 'Please select an active 3D viewport.'
        LOG.warning(msg)
        return

    cam_tfm, cam_shp = viewport_utils.get_viewport_camera(model_editor)
    if cam_shp is None:
        msg = 'Please select an active 3D viewport to get a camera.'
        LOG.warning(msg)
        return

    try:
        mmapi.set_solver_running(True)

        save_sel = maya.cmds.ls(selection=True, long=True) or []

        # Get selection
        nodes = maya.cmds.ls(
            selection=True,
            long=True,
            type='transform',
        ) or []

        # Filter out selected imagePlanes.
        nodes_tmp = list(nodes)
        nodes = []
        for node in nodes_tmp:
            shps = maya.cmds.listRelatives(
                node, shapes=True, fullPath=True, type='imagePlane') or []
            if len(shps) == 0:
                nodes.append(node)

        # Create centering node network.
        if len(nodes) == 0:
            msg = 'No objects selected, removing 2D centering.'
            LOG.warning(msg)
            mmapi.load_plugin()
            reproject_utils.remove_reprojection_from_camera(cam_tfm, cam_shp)
            reproject_utils.reset_pan_zoom(cam_tfm, cam_shp)
        elif len(nodes) == 1:
            msg = 'Applying 2D centering to %r'
            LOG.warning(msg, nodes)
            mmapi.load_plugin()
            reproj_nodes = reproject_utils.find_reprojection_nodes(
                cam_tfm, cam_shp)
            if len(reproj_nodes) > 0:
                maya.cmds.delete(reproj_nodes)

            reproj_node = reproject_utils.create_reprojection_on_camera(
                cam_tfm, cam_shp)
            reproject_utils.connect_transform_to_reprojection(
                nodes[0], reproj_node)
        elif len(nodes) > 1:
            msg = 'Please select only 1 node to center on.'
            LOG.error(msg)

        if len(save_sel) > 0:
            maya.cmds.select(save_sel, replace=True)
    finally:
        mmapi.set_solver_running(False)
    return
def set_solver_is_running_state(value):
    if isinstance(value, bool) is False:
        msg = 'value cannot be %r; %r is not bool'
        raise TypeError(msg % (type(value), value))
    mmapi.set_solver_running(value)
    return