I’m trying to implement a custom mouse-based interaction mechanism to move/rotate a model node in the 3D view (scripted module). I want a different interaction than the one provided by the transform node widget. For example, I would like the user to be able to press the left mouse button to “pick” a model and then rotate the model around the picked point by moving the mouse.
Is there a simple way to override the interactor style of the 3D view without breaking anything else? I see many posts suggesting to create temporary markups to do similar things, but it seems overkill and I’m thinking there must be a simpler way.
For context, the interactions associated with widget like the “CameraWidget” ones are currently hard-coded in the associated constructor[1] by mapping event to specific actions with calls to functions like:
SetKeyboardEventTranslation
SetEventTranslationClickAndDrag
This concept is applied to all the other widgets[2] used to update properties of various object.
to override the interactor style of the 3D view without breaking anything else?
To override the mapping describe above, we would need to redefine the mapping. This could be done either globally (or an a per-context basis).
For reference, the segment editor is handling this in a ad-hoc way through the qMRMLSegmentEditorWidget::setupViewObservations[3]
Waiting we further improve the framework, addressing what you are describing by relying on existing capabilities (e.g markups) is sensible.
The SlicerMarkupConstraints may also provide some useful concept we could integrate into Slicer core.
Default translation from interaction even to widget action is defined in each widget, but you are free to remove those and/or add new translations, as shown in examples in the script repository.
The current transformation widget is very limited and @Sunderlandkyl is working on a much better widget that will replace it, which works in both 3D and slice views, has adjustable center of rotation, allows translation/rotation around a single axis, supports non-linear transform hiearchies, etc. At the project week Kyle could work with you to refine the widget in a way that it fulfills your requirements. He also has a prototype on node focus: allow picking a node (such as a model) in 3D/slice views or in subject hierarchy widgets by clicking on it and then interact with it (e.g., show interaction handles to translate/rotate).
You can of course override the entire event translation infrastructure, as it is done in the Segment Editor, but I would not recommend it, as it can have many unintended side-effects (e.g., interactive slice intersections are not compatible with Segment Editor). At some point the Segment Editor will be fixed to use the proper event translation mechanism.
In the script repository linked here, you can see that reference to widgets like the ones mentioned above are retrieved and then calls to SetKeyboardEventTranslation and SetEventTranslationClickAndDrag are done to customize the behavior.