Skip to content

Commit

Permalink
Crank: manage evaluation mode and callback #386
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcampos committed Feb 20, 2024
1 parent 81b15d8 commit 1cb129a
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion release/scripts/mgear/crank/crank_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,11 @@ def __init__(self, parent=None):
self.create_connections()
self._refreshList()

self.time_change_cb()
self.eval_mode = self.get_evaluation_mode()

# check if the eval model is DG , if is not the callback will be deactivated
if self.check_evaluation_mode():
self.time_change_cb()

self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.installEventFilter(self)
Expand All @@ -626,8 +630,12 @@ def close(self):
pm.displayInfo("Closing Crank")
self.clear_random_color()
self.edit_all_off()
# callback cleaning
if self.cbm:
self.cbm.removeAllManagedCB()
# set the previous state in the evaluation manager if it was parallel
if self.eval_mode == "parallel":
self.set_eval_to_parallel()
self.deleteLater()

def closeEvent(self, evnt):
Expand Down Expand Up @@ -752,6 +760,74 @@ def edit_all_off(self, *args):
print("Turn off Edit triggered")
_edit_all_off()

def get_evaluation_mode(self):
"""
Checks the current evaluation mode in Autodesk Maya.
Returns:
str: The current evaluation mode, either 'off' or 'parallel'.
"""
# Query the current evaluation mode
mode = cmds.evaluationManager(query=True, mode=True)

# The evaluationManager command returns a list of modes. The first
# mode in the list is the current evaluation mode.
current_mode = mode[0]

return current_mode

def set_eval_to_parallel(self, parallel=True):
# Function to set evaluation mode to parallel or DG
if parallel:
eval_mode = "parallel"
else:
eval_mode = "off"

def set_eval():
cmds.evaluationManager(mode=eval_mode)

# Use Maya's main thread to change evaluation mode
pm.displayInfo("Parallel evaluation: {}".format(eval_mode))
utils.executeInMainThreadWithResult(set_eval)
# cmds.evaluationManager(mode="parallel")

def check_evaluation_mode(self):
"""
Checks the current evaluation mode. If it is in Parallel, prompts the
user with a dialog to ask if they want to change to DG mode. If Yes,
changes the evaluation mode to DG.
"""
# Check current evaluation mode
current_mode = self.get_evaluation_mode()

# If in Parallel mode, prompt the user
if current_mode == "parallel":
# Define the dialog message
message = (
"The current evaluation mode is Parallel. \n"
"For shot sculpting is recommended to use DG. \n"
"Do you want to change it to DG?"
)

# Show confirmation dialog
result = cmds.confirmDialog(
title="Change Evaluation Mode",
message=message,
button=["Yes", "No"],
defaultButton="Yes",
cancelButton="No",
dismissString="No",
)

# If user chooses 'Yes', change to DG mode
if result == "Yes":
self.set_eval_to_parallel(False)
pm.displayInfo("Evaluation mode changed to DG.")
return True
else:
pm.displayInfo("Evaluation mode remains as Parallel.")
return False

###########################
# Callback
###########################
Expand Down

0 comments on commit 1cb129a

Please sign in to comment.