Skip to content

Commit

Permalink
Always select newly added armature.
Browse files Browse the repository at this point in the history
This will help preventing conlficts where two armature nodes are added in
the tree view.

See Issue #13668
  • Loading branch information
vovythevov committed Dec 12, 2012
1 parent c1bac15 commit a80c5c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Modules/Loadable/Armatures/qSlicerArmaturesModuleWidget.cxx
Expand Up @@ -44,6 +44,7 @@
#include <vtkMRMLHierarchyNode.h>
#include <vtkMRMLInteractionNode.h>
#include <vtkMRMLSelectionNode.h>
#include <vtkMRMLScene.h>

//-----------------------------------------------------------------------------
// qSlicerArmaturesModuleWidgetPrivate methods
Expand Down Expand Up @@ -611,11 +612,9 @@ ::setMRMLArmatureNode(vtkMRMLArmatureNode* armatureNode)
{
Q_D(qSlicerArmaturesModuleWidget);

if (armatureNode && !d->ArmatureNodeComboBox->currentNode())
if (armatureNode && armatureNode != d->ArmatureNodeComboBox->currentNode())
{
bool wasBlocking = d->ArmatureNodeComboBox->blockSignals(true);
d->ArmatureNodeComboBox->setCurrentNode(armatureNode);
d->ArmatureNodeComboBox->blockSignals(wasBlocking);
}

this->qvtkReconnect(d->ArmatureNode, armatureNode,
Expand Down Expand Up @@ -713,6 +712,16 @@ void qSlicerArmaturesModuleWidget::enter()
}
}

//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidget::setMRMLScene(vtkMRMLScene* scene)
{
vtkMRMLScene* oldMRMLScene = this->mrmlScene();
this->Superclass::setMRMLScene(scene);
this->qvtkReconnect(oldMRMLScene, scene, vtkMRMLScene::NodeAddedEvent, this,
SLOT(onMRMLNodeAdded(vtkObject*, void*)));
}


//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidget
::setMRMLBoneNode(vtkMRMLBoneNode* boneNode)
Expand Down Expand Up @@ -912,3 +921,14 @@ void qSlicerArmaturesModuleWidget::updateCurrentMRMLBoneNode()

d->BoneNode->EndModify(wasModifying);
}

//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidget
::onMRMLNodeAdded(vtkObject* scene, void* callData)
{
vtkMRMLNode* node = reinterpret_cast<vtkMRMLNode*>(callData);
if (node && node->IsA("vtkMRMLArmatureNode"))
{
this->setMRMLArmatureNode(node);
}
}
8 changes: 8 additions & 0 deletions Modules/Loadable/Armatures/qSlicerArmaturesModuleWidget.h
Expand Up @@ -63,6 +63,11 @@ class Q_SLICER_QTMODULES_ARMATURES_EXPORT qSlicerArmaturesModuleWidget
virtual void enter();

public slots:
/// Set the mrml scene.
/// Listens to add added node to select the newly added armature node
/// as selected.

This comment has been minimized.

Copy link
@finetjul

finetjul Dec 12, 2012

Contributor

please review comment.

virtual void setMRMLScene(vtkMRMLScene* scene);

/// Set \a armatureNode as current.
/// \sa setMRMLArmatureNode(vtkMRMLNode*) setMRMLNode(vtkMRMLNode* node)
void setMRMLArmatureNode(vtkMRMLArmatureNode* armatureNode);
Expand Down Expand Up @@ -109,6 +114,9 @@ protected slots:
void updateCurrentMRMLArmatureNode();
void updateCurrentMRMLBoneNode();

/// Update the selected armature if the new bone added is an armature
void onMRMLNodeAdded(vtkObject*, void*);

protected:
QScopedPointer<qSlicerArmaturesModuleWidgetPrivate> d_ptr;

Expand Down

4 comments on commit a80c5c7

@finetjul
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure to understand the reason of this behavior. Can you explain with the "conflict" ?

@vovythevov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conflicts was that when importing armatures, a new armature node is created but the old armature node stays the same in the node selection combo-box. Meanwhile, the bones tree view "sees" the new armature node and adds it to the tree view, with the old armature.
This selects automatically the latest armature so this does happen.

@finetjul
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is normal that the old armature node stays "current" in the node selection combobox.
However, the fact that the bones tree view "sees" the new armature node is a mistake. It should be fixed in the tree view level. I can look at it if you want.

Nonetheless, if you desire to have the loaded armature being current (like what is done for the volumes), you can look at qSlicerVolumesIO::load

@vovythevov
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll revert this commit then.

Please sign in to comment.