Skip to content

Commit

Permalink
Update GUI when widget is selected
Browse files Browse the repository at this point in the history
We need to update the gui when the widget is selected so the current bone
in the tree is the selected bone in the API.
To this reason, we use a signal on the armature beacuse the gui listens
to the current armature.
(This prevent us from having the gui listening to all the bones in its
tree).
The event is fired with the modified bone node's ID. This ID is then used
in the GUI to select the current bone.

See Issue #13629
  • Loading branch information
vovythevov committed Nov 16, 2012
1 parent d71a55b commit 8023407
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
11 changes: 11 additions & 0 deletions Modules/Loadable/Armatures/MRML/Core/vtkMRMLArmatureNode.h
Expand Up @@ -26,6 +26,10 @@

// Armatures includes
#include "vtkBenderArmaturesModuleMRMLCoreExport.h"

// VTK includes
#include "vtkCommand.h"

class vtkMRMLBoneNode;

class vtkArmatureWidget;
Expand Down Expand Up @@ -144,6 +148,13 @@ class VTK_BENDER_ARMATURES_MRML_CORE_EXPORT vtkMRMLArmatureNode
void SetBoneLinkedWithParent(vtkBoneWidget* bone, bool linked);
bool GetBoneLinkedWithParent(vtkBoneWidget* bone);*/

//BTX
enum MRMLArmatureNode
{
ArmatureBoneModified = vtkCommand::UserEvent + 1
};
//ETX

//--------------------------------------------------------------------------
// Bone methods
//--------------------------------------------------------------------------
Expand Down
Expand Up @@ -662,6 +662,13 @@ ::UpdateBoneNodeFromWidget(vtkMRMLBoneNode* boneNode,
boneNode->EndModify(wasModifying);

this->UpdateBoneDisplayNodeFromWidget(boneNode->GetBoneDisplayNode(), widget);

vtkMRMLArmatureNode* armatureNode = this->GetArmatureNode(boneNode);
if (armatureNode && boneNode->GetSelected())
{
armatureNode->InvokeEvent(
vtkMRMLArmatureNode::ArmatureBoneModified, boneNode->GetID());
}
}

//---------------------------------------------------------------------------
Expand Down
51 changes: 45 additions & 6 deletions Modules/Loadable/Armatures/qSlicerArmaturesModuleWidget.cxx
Expand Up @@ -40,6 +40,7 @@
#include <vtkSlicerAnnotationModuleLogic.h>

// MRML includes
#include <vtkMRMLBoneDisplayNode.h>
#include <vtkMRMLHierarchyNode.h>
#include <vtkMRMLInteractionNode.h>
#include <vtkMRMLSelectionNode.h>
Expand Down Expand Up @@ -306,12 +307,12 @@ ::updateHierarchy(vtkMRMLBoneNode* boneNode)

wasBlocked = this->LinkedToParentCheckBox->blockSignals(true);
this->LinkedToParentCheckBox->setChecked(
this->BoneNode->GetBoneLinkedWithParent());
boneNode->GetBoneLinkedWithParent());
this->LinkedToParentCheckBox->blockSignals(false);
}

bool enable = this->BoneNode
&& this->BoneNode->GetWidgetState() != vtkMRMLBoneNode::Pose;
bool enable = boneNode
&& boneNode->GetWidgetState() != vtkMRMLBoneNode::Pose;

this->ParentBoneNodeComboBox->setEnabled(enable);
this->LinkedToParentCheckBox->setEnabled(enable);
Expand Down Expand Up @@ -439,6 +440,24 @@ ::setCoordinatesToBoneNode(vtkMRMLBoneNode* boneNode)
}
}

//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidgetPrivate
::selectBoneNode(vtkObject* sender, void* callData)
{
Q_Q(qSlicerArmaturesModuleWidget);

char* nodeID = reinterpret_cast<char*>(callData);
if (nodeID)
{
vtkMRMLBoneNode* boneNode =
vtkMRMLBoneNode::SafeDownCast(q->mrmlScene()->GetNodeByID(nodeID));
if (boneNode && boneNode->GetSelected())
{
this->BonesTreeView->setCurrentNode(boneNode);
}
}
}

//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidgetPrivate
::setCoordinatesFromBoneNode(vtkMRMLBoneNode* boneNode)
Expand Down Expand Up @@ -507,8 +526,7 @@ ::onParentNodeChanged(vtkMRMLNode* node)
}

//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidgetPrivate
::onLinkedWithParentChanged(int linked)
void qSlicerArmaturesModuleWidgetPrivate::onLinkedWithParentChanged(int linked)
{
if (!this->BoneNode)
{
Expand All @@ -518,6 +536,21 @@ ::onLinkedWithParentChanged(int linked)
this->BoneNode->SetBoneLinkedWithParent(linked);
}

//-----------------------------------------------------------------------------
void qSlicerArmaturesModuleWidgetPrivate::selectCurrentBoneDisplayNode(int select)
{
if (!this->BoneNode)
{
return;
}

vtkMRMLBoneDisplayNode* displayNode = this->BoneNode->GetBoneDisplayNode();
if (displayNode)
{
displayNode->SetSelected(select);
}
}

//-----------------------------------------------------------------------------
// qSlicerArmaturesModuleWidget methods

Expand Down Expand Up @@ -548,6 +581,9 @@ ::setMRMLArmatureNode(vtkMRMLArmatureNode* armatureNode)
Q_D(qSlicerArmaturesModuleWidget);
this->qvtkReconnect(d->ArmatureNode, armatureNode,
vtkCommand::ModifiedEvent, this, SLOT(updateWidgetFromArmatureNode()));
this->qvtkReconnect(d->ArmatureNode, armatureNode,
vtkMRMLArmatureNode::ArmatureBoneModified,
d, SLOT(selectBoneNode(vtkObject*, void*)));
d->ArmatureNode = armatureNode;

d->logic()->SetActiveArmature(armatureNode);
Expand Down Expand Up @@ -718,9 +754,12 @@ void qSlicerArmaturesModuleWidget::onTreeNodeSelected(vtkMRMLNode* node)
this->qvtkReconnect(d->BoneNode, boneNode, vtkCommand::ModifiedEvent,
this, SLOT(updateWidgetFromBoneNode()));
}
d->BoneNode = boneNode;

d->updateArmatureWidget(boneNode);

d->selectCurrentBoneDisplayNode(0); // Unselect previous bone node
d->BoneNode = boneNode; // Update bone node
d->selectCurrentBoneDisplayNode(1); // Select new bone node
}

//-----------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions Modules/Loadable/Armatures/qSlicerArmaturesModuleWidget_p.h
Expand Up @@ -29,6 +29,7 @@
class qSlicerWidget;
class vtkMRMLArmatureNode;
class vtkMRMLBoneNode;
class vtkObject;
class vtkSlicerArmaturesLogic;

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -78,6 +79,8 @@ public slots:
void setCoordinatesFromBoneNode(vtkMRMLBoneNode* boneNode);
void setCoordinatesToBoneNode(vtkMRMLBoneNode* boneNode);

void selectBoneNode(vtkObject*, void*);

protected slots:

void onPositionTypeChanged();
Expand All @@ -87,6 +90,10 @@ protected slots:
void onParentNodeChanged(vtkMRMLNode* node);
void onLinkedWithParentChanged(int linked);

protected:
// Select/Unselect the current bone node.
void selectCurrentBoneDisplayNode(int select);

private:
vtkMRMLArmatureNode* ArmatureNode;
vtkMRMLBoneNode* BoneNode;
Expand Down

0 comments on commit 8023407

Please sign in to comment.