# Observing modification of table node from the other node and logic

**URL:** https://discourse.slicer.org/t/observing-modification-of-table-node-from-the-other-node-and-logic/9227
**Category:** Development
**Tags:** extensions-manager, module
**Created:** [November 20, 2019, 10:01am UTC](https://discourse.slicer.org/t/observing-modification-of-table-node-from-the-other-node-and-logic/9227 "2019-11-20T10:01:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)
#### Post date: [November 20, 2019, 10:01am UTC](https://discourse.slicer.org/t/observing-modification-of-table-node-from-the-other-node-and-logic/9227/1 "2019-11-20T10:01:42Z")

</div>

Greetings,

A couple of questions of loadable module development, some general stuff.

1. What king of event generated when cells in table node are modified  
via “Tables” module or in table viewer?  
`vtkCommand::ModifiedEvent`,  
`vtkMRMLTableNode::ReferencedNodeModifiedEvent`,  
`vtkMRMLTableNode::ReferenceModifiedEvent`

2. What overridden methods in logic must be modified to process a table node modifications?  
`vtkMyModuleLogic::ProcessMRMLNodesEvents`,  
`vtkMyModuleLogic::OnMRMLSceneNodeAdded`,  
`vtkMyModuleLogic::SetMRMLSceneInternal`

3. When module logic is ready to process table node events, and table node on the same scene with other node , how should i observe table node from other node?  
`other_node->SetNodeReferenceID( "Role", tableNode->GetID());`  
or  
`other_node->SetAndObserveNodeReferenceID( "Role", tableNode->GetID());`

Best regards,  
Mikhail

---

<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: [November 20, 2019, 4:53pm UTC](https://discourse.slicer.org/t/observing-modification-of-table-node-from-the-other-node-and-logic/9227/2 "2019-11-20T16:53:10Z")

</div>

> [@Mik](#):
>
> What king of event generated when cells in table node are modified  
> via “Tables” module or in table viewer?  
> `vtkCommand::ModifiedEvent` ,  
> `vtkMRMLTableNode::ReferencedNodeModifiedEvent` ,  
> `vtkMRMLTableNode::ReferenceModifiedEvent`

When you modify a cell in a table, it invokes `vtkCommand::ModifiedEvent` event on the vtkMRMLTableNode.

`vtkMRMLNode::ReferencedNodeModifiedEvent` and `vtkMRMLNode::ReferenceModifiedEvent` invoked on a node that references another node. If you reference a table node from node A, then ReferencedNodeModifiedEvent will be invoked on A if the table is modified; and ReferenceModifiedEvent will be invoked if you switch which table node you reference.

> [@Mik](#):
>
> What overridden methods in logic must be modified to process a table node modifications?

If you want to observe all changes of all table nodes in the scene then you need to observe all scene setting and scene node added/removed/batch update events so that you can add observer to all table nodes, and then override ProcessMRMLNodesEvents to get notification about changes in any nodes. See for example [vtkSlicerBreachWarningLogic](https://github.com/SlicerIGT/SlicerIGT/blob/master/BreachWarning/Logic/vtkSlicerBreachWarningLogic.cxx).

> [@Mik](#):
>
> When module logic is ready to process table node events, and table node on the same scene with other node , how should i observe table node from other node?

You observe changes of another node from a module logic as I described above.

If you want to observe referenced node changes from another node then you need to declare the node reference role in the constructor (specifying which events you want to observe) and add node reference using SetAndObserveNodeReferenceID. See for example [vtkMRMLTransformableNode](https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Core/vtkMRMLTransformableNode.cxx#L40).

---

<div class="post-metadata">

### Author: ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://discourse.slicer.org/u/Mik)
#### Post date: [November 22, 2019, 6:19pm UTC](https://discourse.slicer.org/t/observing-modification-of-table-node-from-the-other-node-and-logic/9227/3 "2019-11-22T18:19:50Z")

</div>

Thank you for explanation!

The easiest method was using logic class by adding observer to table node modified event in  
[OnMRMLSceneNodeAdded](https://github.com/MichaelColonel/SlicerRT/blob/multi-leaf-collimators/Beams/Logic/vtkSlicerBeamsModuleLogic.cxx#L109-#L114), and then process table node events in [ProcessMRMLNodesEvents](https://github.com/MichaelColonel/SlicerRT/blob/multi-leaf-collimators/Beams/Logic/vtkSlicerBeamsModuleLogic.cxx#L239-#L261).

Offtopic: The [developer manual](https://www.slicer.org/wiki/Documentation/Nightly/Developers/FAQ#Can_I_use_C.2B.2B11.2F14.2F17_language_features_.3F) doesn’t recommend using C++11 elements, but many modules have _override_, _default_ keywords, _std::array_ variables and _nullptr_. What about using java-like cycles, auto, lambda expressions and initializer lists?

---

<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: [November 22, 2019, 7:48pm UTC](https://discourse.slicer.org/t/observing-modification-of-table-node-from-the-other-node-and-logic/9227/4 "2019-11-22T19:48:40Z")

</div>

> [@Mik](#):
>
> The [developer manual](https://www.slicer.org/wiki/Documentation/Nightly/Developers/FAQ#Can_I_use_C.2B.2B11.2F14.2F17_language_features_.3F) doesn’t recommend using C++11 elements,

The developer manual has not been updated. I would say Slicer follows VTK conventions in this (which is now accepts usage of most C++11 features).
