This WIP PR is another absolute monster: forgive me 🙏🏼
This PR takes the improved manipulator and related component models from #63 and hooks everything up to our BaseManipulator
class in a way which I think makes it nice and easy to implement desired behaviour in specific Manipulator
implementations.
I have so far only reimplemented the RenderPlaneManipulator
, widget autogeneration is working as before
https://user-images.githubusercontent.com/7307488/197223256-978fdd9c-6c09-48e6-ad75-1ca411495a1a.mp4
the implementation for this is...
class RenderPlaneManipulator(BaseManipulator):
"""A manipulator for moving and orienting an image layer rendering plane."""
def __init__(self, viewer, layer=None):
super().__init__(viewer, layer, rotator_axes='yz', translator_axes='z')
def set_layers(self, layers: napari.layers.Image):
super().set_layers(layers)
def _initialize_transform(self):
self.origin = np.array(self.layer.plane.position)
plane_normal = self.layer.plane.normal
self.rotation_matrix = rotation_matrix_from_vectors_3d([1, 0, 0], plane_normal)
def _while_dragging_translator(self):
self.layer.plane.position = self.origin
def _while_dragging_rotator(self):
self.layer.plane.normal = self.z_vector
something else worth highlighting is how simple this new separation made the mouse callback on the BaseManipulator
class
def _mouse_callback(self, layer, event):
"""Update the manipulated object via subclass implementations of drag/rotate behaviour."""
yield
if self._viewer.dims.ndisplay != 3 or self._backend.is_dragging is False:
return # early exit if manipulator is not being manipulated
self._pre_drag()
while event.type == 'mouse_move':
selected_object_type = self._backend.manipulator_model.selected_object_type
if selected_object_type == 'translator':
self._while_dragging_translator()
elif selected_object_type == 'rotator':
self._while_dragging_rotator()
yield
self._post_drag()
edit: things left to do
- [ ] check and add tests for various instantiation possibilities of manipulator implementations (with layer, no layer)
- [ ] hook up other manipulators