aboutsummaryrefslogtreecommitdiff
path: root/scripts/artv2/tools/rigging/group_reset_ui.py
blob: ce34496ccdce257340b033dc282ce93107951820 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-

"""
:author:
    Jeremy Ernst
:description:
    This module contains a class that creates an interface for selecting multiple components and resetting their
    settings or transforms or both.
"""

import artv2.utilities.interface_utilities as interface_utils
import artv2.utilities.component_utilities as component_utils
from artv2.third_party.Qt import QtWidgets, QtCore
import artv2.tools.system.logger.output_logger as logger

import pymel.core as pm


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
class GroupResetUI(interface_utils.ARTv2Window):
    """
    This class creates a user interface for selecting components and resetting their settings and/or transforms. It is
    invoked from the RigBuilderUI toolbar.

    :param parent: the instance of the RigBuilderUI this widget will be parented to.

    .. figure:: /images/group_reset_ui.png
        :width: 198px
        :align: center
        :height: 429px
        :figclass: align-center

    """

    SETTINGS_NAME = "GroupResetWIN"
    WINDOW_NAME = "artv2_group_reset_window"

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def __init__(self, parent=None):

        super(GroupResetUI, self).__init__(200, 400, "Group Reset", parent)

        self.logger = logger.OutputLogger(self.__class__.__name__)
        self.parent_inst = parent
        self._build_interface()

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _build_interface(self):

        main_widget = QtWidgets.QWidget()
        main_layout = QtWidgets.QVBoxLayout(main_widget)
        self.setCentralWidget(main_widget)

        self.component_list = QtWidgets.QListWidget()
        self.component_list.setSortingEnabled(True)
        self.component_list.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
        self.component_list.setMinimumHeight(interface_utils.scale_by_dpi(240))
        main_layout.addWidget(self.component_list)
        self._populate_list()

        self.settings_checkbox = QtWidgets.QCheckBox("Reset Settings")
        self.settings_checkbox.setChecked(False)
        main_layout.addWidget(self.settings_checkbox)

        self.transforms_checkbox = QtWidgets.QCheckBox("Reset Transformations")
        self.transforms_checkbox.setChecked(False)
        main_layout.addWidget(self.transforms_checkbox)

        spacer = QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding)
        main_layout.addItem(spacer)

        button = QtWidgets.QPushButton("Reset")
        button.clicked.connect(self._reset)
        main_layout.addWidget(button)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _populate_list(self):

        components = component_utils.get_all_component_names()
        for each in components.keys():
            item = QtWidgets.QListWidgetItem()
            item.setData(QtCore.Qt.UserRole, components.get(each).nodeName())
            item.setText(each)
            self.component_list.addItem(item)

    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    def _reset(self):

        self.logger.interface("{0}._reset: Resetting selected components.".format(self.__class__.__name__))

        selected = self.component_list.selectedItems()
        settings = self.settings_checkbox.isChecked()
        transforms = self.transforms_checkbox.isChecked()

        instances = []
        for each in selected:
            data = each.data(QtCore.Qt.UserRole)
            inst = component_utils.get_component_instance(pm.PyNode(data))
            instances.append(inst)

            if settings:
                inst.reset_settings()
            if transforms:
                if not inst.network_node.pinned.get():
                    inst.joint_mover.toggle_pin_component()

        if transforms:
            for instance in instances:
                instance.joint_mover.reset_movers("all")
                if instance.network_node.pinned.get():
                    instance.joint_mover.toggle_pin_component()
                del instance


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
def show_window(parent):
    """
    Shows the GroupResetUI instance
    """
    if pm.window("artv2_group_reset_window", exists=True):
        pm.deleteUI("artv2_group_reset_window")

    gui = GroupResetUI(parent)
    gui.show()