# Setting mouse place mode for specific view

**URL:** <https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938>\
**Category:** Development\
**Created:** [December 3, 2018, 1:39pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938 "2018-12-03T13:39:17Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 1:39pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/1 "2018-12-03T13:39:17Z")

</div>

It is currently possible to globally change the interaction mode (PersistentPlaceMode, SinglePlaceMode, ViewTransformMode) by updating the interaction node singleton. This is exposed to the user using the place mode toolbar:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/5/25836f8301a8aee6e3f3e374c97a35f2aa3b0fb3.png)

In custom application, it is sometimes needed to disable placing of “annotations” only in specific view.

To support this, I proposed to:

- update `vtkAbstractViewNode` adding a `SupportedInteractionMode` bit field

- the `Place` and `ViewTransform` corresponds to values of mouse mode enum in [vtkMRMLInteractionNode](https://github.com/Slicer/Slicer/blob/f1b55fc99e948629e8a048c619d685a25ac0ba4d/Libs/MRML/Core/vtkMRMLInteractionNode.h#L45-L55)

This would allow to easily disable support for `Place` mode in specific view.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 2:12pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/2 "2018-12-03T14:12:52Z")

</div>

In addition to the `SupportedInteractionMode` bit field, we also need to keep track of the current interaction mode for each view.

There are two possible approaches:

1. add a `CurrentInteractionMode` property to the view
2. update `vtkMRMLInteractionNode` to keep track of interaction mode for all views.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 3, 2018, 2:47pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/3 "2018-12-03T14:47:07Z")

</div>

(I see Andras is replying too - let’s see if he says the same thing…)

Why not use the list of view names like in the display nodes?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 3, 2018, 2:47pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/4 "2018-12-03T14:47:15Z")

</div>

Currently, difference in behavior is usually managed by using display nodes. For example, we can already show/hide annotations in selected views. We could add a bitfield to display nodes that describe what interactions are allowed in that view.

Alternatively, we could use the technique that we use for connecting layout managers to views using ParentLayoutNode reference (if no parent node is defined then the default layout manager should be used). Implementation would be adding reference to InteractionNode (and maybe also to SelectionNode). If this node reference is undefined then the default interaction node would be used. This method would have the advantage that we could set what annotation to place in which view.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 2:59pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/5 "2018-12-03T14:59:49Z")

</div>

> [@lassoan](#):
>
> display nodes that describe what interactions are allowed in that view

The issue is that corresponding display node do not exist yet.

> [@lassoan](#):
>
> adding reference to InteractionNode

I like the idea but currently both interaction and selection node are singleton, these would be quite a disruptive change I think.

> [@pieper](#):
>
> Why not use the list of view names like in the display nodes?

I think we need more than a list. Indeed, the idea is to keep track of:

- which interaction modes are supported by which view.
- current mode of a given view

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 3, 2018, 3:09pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/6 "2018-12-03T15:09:59Z")

</div>

> [@jcfr](#):
>
> The issue is that corresponding display node do not exist yet.

If needed, you can pre-create annotation/markup node and corresponding display node. You can definitely do it for markup fiducials but may be some annotation nodes cannot be pre-created with 0 points. Anyway, this is not a good solution anyway, as it would not allow customization of markup/annotation node selection per view.

> [@jcfr](#):
>
> I like the idea but currently both interaction and selection node are singleton, these would be quite a disruptive change I think.

It is similar change as we implemented for managing virtual reality views by non-default layout manager. It does not seem disruptive to me.

I would not even consider any solution that only allows customization of interaction flags and not what markup node to place.

For example, in landmark registration module, we show fixed image in top row, moving image in middle row (and registration result in bottom row). It would be a bad solution to just enable landmark placement in either fixed or moving image views. We must keep placement enabled in all views but we need to place different landmarks in different view groups.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 3:22pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/7 "2018-12-03T15:22:51Z")

</div>

> [@lassoan](#):
>
> It is similar change as we implemented for managing virtual reality views by non-default layout manager. It does not seem disruptive to me.

In the virtual reality extension, we implemented a custom layout node. This means that we didn’t have to change the “singleton-ness” of the layout node.

To support different interaction node for different view, we would have to instantiate multiple interaction node.

Are you suggesting we change selection and interaction node to not be singleton anymore ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 3, 2018, 3:25pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/8 "2018-12-03T15:25:54Z")

</div>

If interaction (and/or selection) node ID is not defined in a view node then the default singleton interaction node is used. If a custom node interaction node ID is defined then that is used. This logic can be implemented at one place (probably in the view node) and can be used everywhere where interaction node for a view is needed.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [December 3, 2018, 3:32pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/9 "2018-12-03T15:32:39Z")

</div>

> [@lassoan](#):
>
> We must keep placement enabled in all views but we need to place different landmarks in different view groups

This would be such a great feature! No more switching between placed fiducial groups (markup nodes).

> [@lassoan](#):
>
> If a custom node interaction node ID is defined then that is used

How do you propose to do this without removing the singletonness of the interaction node? If you awnt to have a second interaction node in the scene then it cannot be singleton I think. Or do you propose keeping it out of the scene? It doesn’t seem like a good way to do it.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 3, 2018, 3:33pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/10 "2018-12-03T15:33:26Z")

</div>

Additional selection and interaction nodes would not need to be singletons.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 3:34pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/11 "2018-12-03T15:34:46Z")

</div>

That would work, doing the following allow to create additional interaction node:

```auto
n = slicer.mrmlScene.CreateNodeByClass("vtkMRMLInteractionNode")
n.SetSingletonOff()
slicer.mrmlScene.AddNode(n)

```

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 3:35pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/12 "2018-12-03T15:35:59Z")

</div>

I also suggest to add a reference between interaction and selection node, they both work in pair.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 10:24pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/13 "2018-12-03T22:24:38Z")

</div>

After adding a selection node reference to the view, it was pretty straightforward to update the code base.

That said, the following three widgets are directly interfaced with the default interaction node:

- `qSlicerMarkupsPlaceWidget`
- `qMRMLSegmentEditorWidget`
- `qSlicerMouseModeToolBar`:

By default, I suggest the widgets continue to look up the default interaction node but a new `SetInteractionNode(vtkMRMLInteractionNode* ...)` function will be added.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [December 3, 2018, 11:49pm UTC](https://discourse.slicer.org/t/setting-mouse-place-mode-for-specific-view/4938/14 "2018-12-03T23:49:41Z")

</div>

Here it is:

> <https://github.com/Slicer/Slicer/issues/1048>
>
> \_This issue was created automatically from an original \[Mantis Issue\](https://ma…ntisarchive.slicer.org/view.php?id=1048). Further discussion may take place here.\_
