ComputationalBiomechanicsLab / opensim-creator

A UI for building OpenSim models
https://opensimcreator.com
Apache License 2.0
153 stars 18 forks source link

Muscle-plotting: do not record coordinate changes made via the plotter as historical curves #395

Closed adamkewley closed 2 years ago

adamkewley commented 2 years ago

Suggestion by @tgeijten

On letting go of the mouse, the muscle plotter will "commit" a coordinate change to the model as a new default value. This is to match the behavior that the coordinate editor currently has (which is contentious behavior, because it differs from OpenSim GUI), where coordinate edits are saved to the model and are considered for undo/redo.

Saving, or not saving, coordinate edits to the model was a design decision that was made during 0.2.0. However, it interferes with the muscle plotting panel. This is because the panel automatically polls the undo/redo history of the model for any changes and dutifully (unconditionally) re-plots the latest version of a model - regardless of what kind of edit was made.

This behavior is quite hard to eliminate from the plotter, because a robust algorithm will have to perform a model-to-model comparison to "figure out" whether two models only differ by a single coordinate change. Separately storing coordinate edits in a separate datastructure that are independent from the model should probably be re-implemented, but that will take time.

The hacky solution to this is to manually play around with the widget's plotting history whenever a coordinate edit is performed. Essentially, the plotting widget will install the new (post-coordinate-edit) model commit as the "active" curve of the plot, so that the subsequent version-poll detects "no changes", rather than detecting that a coordinate edit has come in and that it should emit a new plot line.

adamkewley commented 2 years ago

The hacky change of switching commits etc. rather than adding new historical curves seems to work, but will probably break with multiple muscle plots.

I'll close this and open a more general (big work) ticket to cover holding coordinate changes properly over the model lifetime.