Skip to content

Commit 4706e1e

Browse files
Add confirmation to Remove Solver Nodes tool, and 'save scene' feature.
The options in the UI will be saved and reloaded the next time the user opens the UI.
1 parent b6e3501 commit 4706e1e

5 files changed

Lines changed: 340 additions & 81 deletions

File tree

python/mmSolver/tools/removesolvernodes/constants.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@
2020
"""
2121

2222
WINDOW_TITLE = 'Remove Solver Nodes'
23+
CONFIG_FILE_NAME = "tools_removesolvernodes.json"
24+
25+
# The default values for deleting different types of nodes
26+
DELETE_MARKERS_DEFAULT_VALUE = False
27+
DELETE_BUNDLES_DEFAULT_VALUE = False
28+
DELETE_MARKER_GROUPS_DEFAULT_VALUE = False
29+
DELETE_COLLECTIONS_DEFAULT_VALUE = False
30+
DELETE_OTHERS_DEFAULT_VALUE = False
31+
32+
# Save scene files by default?
33+
SAVE_SCENE_DEFAULT_VALUE = True

python/mmSolver/tools/removesolvernodes/tool.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
Remove Solver Nodes - user facing.
2020
"""
2121

22+
from __future__ import absolute_import
23+
from __future__ import division
24+
from __future__ import print_function
25+
2226
import mmSolver.logger
2327
import mmSolver.api as mmapi
2428
import maya.cmds as cmds
@@ -31,20 +35,21 @@ def filter_nodes(what_to_delete_dict):
3135
cmds.select([])
3236
node_categories = mmapi.filter_nodes_into_categories(nodes)
3337
unknown_node_found = False
34-
LOG.info('removesolvernodes: filter_nodes run')
35-
all_list_to_delete = list()
38+
found_nodes_map = dict()
3639
if what_to_delete_dict.get('markers') is True:
37-
all_list_to_delete += collect_nodes(node_categories, mode='marker')
40+
found_nodes_map['markers'] = collect_nodes(node_categories, mode='marker')
3841
if what_to_delete_dict.get('other_nodes') is True:
39-
all_list_to_delete += collect_misc_nodes()
42+
found_nodes_map['other_nodes'] = collect_misc_nodes()
4043
if what_to_delete_dict.get('bundles') is True:
4144
delete_list, unknown_node_found = collect_bundles(node_categories)
42-
all_list_to_delete += delete_list
45+
found_nodes_map['bundles'] = delete_list
4346
if what_to_delete_dict.get('marker_groups') is True:
44-
all_list_to_delete += collect_nodes(node_categories, mode='markergroup')
47+
found_nodes = collect_nodes(node_categories, mode='markergroup')
48+
found_nodes_map['marker_groups'] = found_nodes
4549
if what_to_delete_dict.get('collections') is True:
46-
all_list_to_delete += collect_nodes(node_categories, mode='collection')
47-
return all_list_to_delete, unknown_node_found
50+
found_nodes = collect_nodes(node_categories, mode='collection')
51+
found_nodes_map['collections'] = found_nodes
52+
return found_nodes_map, unknown_node_found
4853

4954

5055
def collect_nodes(node_categories, mode=None):
@@ -55,7 +60,7 @@ def collect_nodes(node_categories, mode=None):
5560
continue
5661
for node in node_categories[mode]:
5762
list_to_delete.append(node)
58-
return list_to_delete
63+
return list(sorted(set(list_to_delete)))
5964

6065

6166
def collect_misc_nodes():
@@ -65,7 +70,7 @@ def collect_misc_nodes():
6570
'mmMarkerGroupTransform'])
6671
other_nodes = cmds.ls('mmSolver*', long=True)
6772
combined_set = set(misc_nodes+other_nodes)
68-
return list(combined_set)
73+
return list(sorted(combined_set))
6974

7075

7176
def collect_bundles(node_categories):
@@ -81,7 +86,7 @@ def collect_bundles(node_categories):
8186
for child in children:
8287
if mmapi.get_object_type(child) != 'bundle':
8388
unknown_node_found = True
84-
return list_to_delete, unknown_node_found
89+
return list(sorted(set(list_to_delete))), unknown_node_found
8590

8691

8792
def delete_nodes(nodes_to_delete):
@@ -92,7 +97,7 @@ def delete_nodes(nodes_to_delete):
9297

9398
def main():
9499
"""
95-
Open the Channel Sensitivity window.
100+
Open the 'Remove Solver Nodes' window.
96101
"""
97102
import mmSolver.tools.removesolvernodes.ui.removesolvernodes_window as window
98103
window.main()

python/mmSolver/tools/removesolvernodes/ui/removesolvernodes_layout.py

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,101 @@
1616
# along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
1717
#
1818
"""
19-
The main component of the user interface for the channel sensitivity
20-
window.
19+
The main component of the user interface for the remove solver
20+
nodes window.
2121
"""
2222

23+
from __future__ import absolute_import
24+
from __future__ import division
25+
from __future__ import print_function
26+
27+
import os
28+
2329
import mmSolver.ui.qtpyutils as qtpyutils
2430
qtpyutils.override_binding_order()
2531

2632
import Qt.QtWidgets as QtWidgets
2733

2834
import mmSolver.logger
35+
import mmSolver.utils.config as config_utils
36+
import mmSolver.tools.removesolvernodes.constants as const
2937
import mmSolver.tools.removesolvernodes.ui.ui_removesolvernodes_layout as ui_removesolvernodes_layout
3038

3139
LOG = mmSolver.logger.get_logger()
3240

3341

42+
def get_config():
43+
"""Get the Remove Solver Nodes config object or None."""
44+
file_name = const.CONFIG_FILE_NAME
45+
config_path = config_utils.get_home_dir_path(file_name)
46+
config = config_utils.Config(config_path)
47+
config.set_autoread(False)
48+
config.set_autowrite(False)
49+
if os.path.isfile(config.file_path):
50+
config.read()
51+
return config
52+
53+
54+
def get_config_value(config, key, fallback):
55+
"""Query the attribute from the user's home directory. If the user's
56+
option is saved, use that value instead.
57+
"""
58+
value = fallback
59+
if config is not None:
60+
value = config.get_value(key, fallback)
61+
return value
62+
63+
3464
class RemoveSolverNodesLayout(QtWidgets.QWidget, ui_removesolvernodes_layout.Ui_Form):
3565
def __init__(self, parent=None, *args, **kwargs):
3666
super(RemoveSolverNodesLayout, self).__init__(*args, **kwargs)
3767
self.setupUi(self)
3868

3969
def reset_options(self):
40-
self.markers_checkBox.setChecked(False)
41-
self.bundles_checkBox.setChecked(False)
42-
self.markerGroup_checkBox.setChecked(False)
43-
self.collections_checkBox.setChecked(False)
44-
self.otherNodes_checkBox.setChecked(False)
70+
# Read these values from the config file.
71+
config = get_config()
72+
save_scene = get_config_value(
73+
config, 'data/save_scene',
74+
const.SAVE_SCENE_DEFAULT_VALUE)
75+
markers = get_config_value(
76+
config, 'data/delete_markers',
77+
const.DELETE_MARKERS_DEFAULT_VALUE)
78+
bundles = get_config_value(
79+
config, 'data/delete_bundles',
80+
const.DELETE_BUNDLES_DEFAULT_VALUE)
81+
marker_groups = get_config_value(
82+
config, 'data/delete_marker_groups',
83+
const.DELETE_MARKER_GROUPS_DEFAULT_VALUE)
84+
collections = get_config_value(
85+
config, 'data/delete_collections',
86+
const.DELETE_COLLECTIONS_DEFAULT_VALUE)
87+
others = get_config_value(
88+
config, 'data/delete_others',
89+
const.DELETE_OTHERS_DEFAULT_VALUE)
90+
91+
self.saveSceneBefore_checkBox.setChecked(save_scene)
92+
self.markers_checkBox.setChecked(markers)
93+
self.bundles_checkBox.setChecked(bundles)
94+
self.markerGroup_checkBox.setChecked(marker_groups)
95+
self.collections_checkBox.setChecked(collections)
96+
self.otherNodes_checkBox.setChecked(others)
97+
98+
def save_options(self):
99+
# Update config file with widget values.
100+
save_scene = self.saveSceneBefore_checkBox.isChecked()
101+
markers = self.markers_checkBox.isChecked()
102+
bundles = self.bundles_checkBox.isChecked()
103+
marker_groups = self.markerGroup_checkBox.isChecked()
104+
collections = self.collections_checkBox.isChecked()
105+
others = self.otherNodes_checkBox.isChecked()
106+
107+
config = get_config()
108+
if config is not None:
109+
config.set_value("data/save_scene", save_scene)
110+
config.set_value("data/delete_markers", markers)
111+
config.set_value("data/delete_bundles", bundles)
112+
config.set_value("data/delete_marker_groups", marker_groups)
113+
config.set_value("data/delete_collections", collections)
114+
config.set_value("data/delete_others", others)
115+
config.write()
116+
return

python/mmSolver/tools/removesolvernodes/ui/removesolvernodes_layout.ui

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,89 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>150</width>
10-
<height>129</height>
9+
<width>326</width>
10+
<height>323</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="main_verticalLayout">
1717
<item>
18-
<layout class="QVBoxLayout" name="checkboxes_verticalLayout">
19-
<item>
20-
<widget class="QCheckBox" name="markers_checkBox">
21-
<property name="text">
22-
<string>Markers</string>
23-
</property>
24-
</widget>
25-
</item>
26-
<item>
27-
<widget class="QCheckBox" name="bundles_checkBox">
28-
<property name="text">
29-
<string>Bundles</string>
30-
</property>
31-
</widget>
32-
</item>
33-
<item>
34-
<widget class="QCheckBox" name="markerGroup_checkBox">
35-
<property name="text">
36-
<string>Marker Groups</string>
37-
</property>
38-
</widget>
39-
</item>
40-
<item>
41-
<widget class="QCheckBox" name="collections_checkBox">
42-
<property name="text">
43-
<string>Collections</string>
44-
</property>
45-
</widget>
46-
</item>
47-
<item>
48-
<widget class="QCheckBox" name="otherNodes_checkBox">
49-
<property name="text">
50-
<string>Other Nodes</string>
51-
</property>
52-
</widget>
53-
</item>
54-
</layout>
18+
<widget class="QGroupBox" name="options_groupBox">
19+
<property name="title">
20+
<string>Options</string>
21+
</property>
22+
<layout class="QVBoxLayout" name="verticalLayout">
23+
<item>
24+
<widget class="QCheckBox" name="saveSceneBefore_checkBox">
25+
<property name="text">
26+
<string>Save Maya Scene Before Deleting</string>
27+
</property>
28+
<property name="checked">
29+
<bool>true</bool>
30+
</property>
31+
</widget>
32+
</item>
33+
</layout>
34+
</widget>
35+
</item>
36+
<item>
37+
<widget class="QGroupBox" name="nodeTypes_groupBox">
38+
<property name="title">
39+
<string>Nodes Types to Delete</string>
40+
</property>
41+
<layout class="QVBoxLayout" name="checkboxes_verticalLayout">
42+
<item>
43+
<widget class="QCheckBox" name="markers_checkBox">
44+
<property name="text">
45+
<string>Markers</string>
46+
</property>
47+
</widget>
48+
</item>
49+
<item>
50+
<widget class="QCheckBox" name="bundles_checkBox">
51+
<property name="text">
52+
<string>Bundles</string>
53+
</property>
54+
</widget>
55+
</item>
56+
<item>
57+
<widget class="QCheckBox" name="markerGroup_checkBox">
58+
<property name="text">
59+
<string>Marker Groups</string>
60+
</property>
61+
</widget>
62+
</item>
63+
<item>
64+
<widget class="QCheckBox" name="collections_checkBox">
65+
<property name="text">
66+
<string>Collections</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item>
71+
<widget class="QCheckBox" name="otherNodes_checkBox">
72+
<property name="text">
73+
<string>Other Nodes</string>
74+
</property>
75+
</widget>
76+
</item>
77+
</layout>
78+
</widget>
79+
</item>
80+
<item>
81+
<spacer name="verticalSpacer">
82+
<property name="orientation">
83+
<enum>Qt::Vertical</enum>
84+
</property>
85+
<property name="sizeHint" stdset="0">
86+
<size>
87+
<width>20</width>
88+
<height>40</height>
89+
</size>
90+
</property>
91+
</spacer>
5592
</item>
5693
</layout>
5794
</widget>

0 commit comments

Comments
 (0)