AutodeskRoboticsLab / Mimic

An open-source Maya plugin for controlling Industrial Robots. Written in Python 3.
https://www.mimicformaya.com/
172 stars 39 forks source link

Add user prefs #22

Closed hsouders closed 3 years ago

hsouders commented 3 years ago

@evanatherton

There's still some code cleanup and a couple bugs that I haven't had time to investigate, so don't accept the pull request! I wanted you to take a look at functionality and let me know what you think before I start locking things down.

How it should work: There are three levels of preferences:

Couple things to note:

Lastly, "it works on my machine" but I've been playing with a lot of Maya variables, so it's possible I've created a situation where is works on my local machine but not elsewhere. Let me know if you run into any issues or we need to change functionality.

evanatherton commented 3 years ago

@hsouders This looks great!! So much work you've put into this \m/.

A few thoughts/findings with some initial testing:

# Error: 
# Traceback (most recent call last):
#   File "/Applications/Autodesk/maya2020/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.7/site-packages/pymel/internal/factories.py", line 830, in callback
#     res = origCallback(*newargs)
#   File "/Applications/Autodesk/maya2020/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.7/site-packages/pymel/internal/factories.py", line 807, in __call__
#     return self.func(*self.args + args, **kwargsFinal)
#   File "/Users/evanatherton/Library/Preferences/Autodesk/maya/modules/mimic/scripts/mimic_config.py", line 387, in set
#     prefs = cls.get_prefs_dict(pref_level)
#   File "/Users/evanatherton/Library/Preferences/Autodesk/maya/modules/mimic/scripts/mimic_config.py", line 374, in get_prefs_dict
#     assert not 'Invalid pref_level passed'
# AssertionError # 
# Traceback (most recent call last):
#   File "/Applications/Autodesk/maya2020/Maya.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python2.7/site-packages/pymel/internal/factories.py", line 830, in callback
#     res = origCallback(*newargs)
#   File "/Users/evanatherton/Library/Preferences/Autodesk/maya/modules/mimic/scripts/mimic_utils.py", line 1061, in write_limits_to_ui
#     write_deriv_limits_to_ui('Jerk')
#   File "/Users/evanatherton/Library/Preferences/Autodesk/maya/modules/mimic/scripts/mimic_utils.py", line 1098, in write_deriv_limits_to_ui
#     axis_deriv_limits = _get_limits(robot, limit_type)
#   File "/Users/evanatherton/Library/Preferences/Autodesk/maya/modules/mimic/scripts/mimic_utils.py", line 1317, in _get_limits
#     add_limits_to_robot(robot, limit_type)
#   File "/Users/evanatherton/Library/Preferences/Autodesk/maya/modules/mimic/scripts/mimic_utils.py", line 2807, in add_limits_to_robot
#     nominal_limit = mimic_config.Pref.get('NOMINAL_JERK_LIMIT')
# AttributeError: 'module' object has no attribute 'Pref' # 

Thanks again man, this is awesome!

evanatherton commented 3 years ago

One more thought regarding how the file level prefs interact with the global prefs: it’d also be nice if there was a way to “push” the current prefs state of the Mimic UI over to the Preferences UI to then save as the global user prefs without having to set all the options again in the Prefs UI

hsouders commented 3 years ago

Thanks for catching those bugs! I'll look into them.

Other things:

evanatherton commented 3 years ago
  • Good point about the Prefs window being long. I'm on a large display and forget about this sometimes. I can make the frames collapsible. Do you think it's also worth putting the Postproc options in their own tab?

I'm a big fan of tabs (as you can probably tell haha). So I'm definitely in favor of moving the postproc settings into their own tab.

  • I'll look into moving files outside of /scripts, I don't think there will be a problem if the json file is located there, but I'm not sure if Maya will execute a python file outside of /scripts. I'll investigate.

That's a good point, that might be a messy way of doing it. It'd probably be more clear to at least keep the .py file in /scripts. Feels silly then to make an entirely new directory to hold a single .json, so we can just keep it as-is for now and see if it bothers us in the future.

  • If we're planning to keep print statements around, I think it probably makes more sense to use python's logging module instead. Logging gives you some more flexibility and it's easy to pipe messages to a file if needed. I think I'll probably end up doing that unless you have any concerns?

No concerns here :) I haven't used the logging module before, but definitely seems like the right tool

  • I can't complain about you doing the cross platform testing. Phew! Should I leave the Mimic logo as the header to the Preferences window? I could see people getting confused and not realizing which window they're looking at? It looks weird if it's empty, but 🤷

You can just leave it as is and I'll give the "branding" some more thought on my end. I might do it like I did the mFIZ window or something to keep a consistent style for the "add-ons"

  • Restoring defaults to a Maya file: I think this is a good idea. There are three possible implementations of this:

    1. Delete all preferences in the file. (You'll definitely want to do this before you distribute a new model that you rigged).
    2. Set all preferences in the file to match Mimic defaults.
    3. Set all preferences in the file to match the User defaults.
  • Additionally, loading user preferences from the current file could be useful. I suppose there could be an "Advanced" tab in the Preferences window that would give you this option (and the options above + a bit more), but things start to get a little confusing:

    • Save User Preferences (to json)
    • Load User Preferences (from arbitrary json)
    • Reset User Preferences to Mimic Defaults
    • Load User Preferences from Current File
    • Delete All Preferences in Current File
    • Set File Preferences to Mimic Defaults
    • Set File Preferences to User Defaults
  • Maybe the best move is to leave the "Save Preferences" button where it is, and move all these other options to the "Advanced" tab?

Yeah I can see it getting confusing for users to pick up the difference between "user", "file", and "default" preferences without a tutorial video or something (which isn't a huge deal). We could make a little "Help" button that launches a dialog with a 1-sentence description of each and/or use the hover tool tips for each of those options. I think, for now at least, leaving "Save Preferences" where it is and moving the rest to an "Advanced" tab sounds like the best solution

hsouders commented 3 years ago

Ok!

Well, I got pretty busy for a while, but I had some time to clean this up and add those features. Here are the highlights:

Notes on the "Advanced" tab:

  1. When file preferences are updated in the advanced tab, I force a file save. If we don't force the save, the standard Maya save doesn't detect that you've made changes to the file and won't let you save unless you make some additional change to the file.
  2. When deleting file preferences (something you'll probably want to do when rigging a robot?) the Mimic UI doesn't relaunch -- this is intentional. If it did, it would automatically reload some preferences into the file.

Things that I'd still like to fix/implement, but I don't think they're going to make it in this PR:

I would definitely appreciate some QA help, as I'm sure I missed something. I added a TODO so you should be able to find that header image pretty easily. (Search "TODO(evanatherton)") Let me know!

evanatherton commented 3 years ago

Epic work @hsouders! I've only managed to find 1 bug (sample rate is saving as a string value instead of a float). I'm merging now, will fix that bug, the header, and the <2020 shelves from there. Thanks again man!

hsouders commented 3 years ago

Ha, There's always one, isn't there.....