Skip to content

Commit

Permalink
ENH: Creating and registering VR data module widget
Browse files Browse the repository at this point in the history
Creates and registers the VR data module widget (which can be switched to from the VR home widget)

KitwareMedical#43
  • Loading branch information
mohammadrashid0917 authored and cpinter committed Aug 22, 2023
1 parent b99f096 commit a8fca31
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 6 deletions.
6 changes: 6 additions & 0 deletions VirtualReality/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(${KIT}_EXPORT_DIRECTIVE "Q_SLICER_QTMODULES_${MODULE_NAME_UPPER}_WIDGETS_EXP
set(${KIT}_INCLUDE_DIRECTORIES
${vtkSlicerVirtualRealityModuleMRML_INCLUDE_DIRS}
${VTK_INCLUDE_DIRS}
${qSlicerSubjectHierarchyModuleWidgets_INCLUDE_DIRS}
)

set(${KIT}_SRCS
Expand All @@ -18,17 +19,21 @@ set(${KIT}_SRCS
qMRML${MODULE_NAME}TransformWidget.h
qMRMLVirtualRealityHomeWidget.cxx
qMRMLVirtualRealityHomeWidget.h
qMRMLVirtualRealityDataModuleWidget.cxx
qMRMLVirtualRealityDataModuleWidget.h
)

set(${KIT}_MOC_SRCS
qMRML${MODULE_NAME}View.h
qMRML${MODULE_NAME}TransformWidget.h
qMRML${MODULE_NAME}View_p.h
qMRMLVirtualRealityHomeWidget.h
qMRMLVirtualRealityDataModuleWidget.h
)

set(${KIT}_UI_SRCS
Resources/UI/qMRMLVirtualRealityHomeWidget.ui
Resources/UI/qMRMLVirtualRealityDataModuleWidget.ui
Resources/UI/qMRML${MODULE_NAME}TransformWidget.ui
)

Expand All @@ -41,6 +46,7 @@ set(${KIT}_TARGET_LIBRARIES
vtkSlicer${MODULE_NAME}ModuleMRML
vtkSlicerCamerasModuleLogic
${VTK_LIBRARIES}
qSlicerSubjectHierarchyModuleWidgets
)

#-----------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>qMRMLVirtualRealityDataModuleWidget</class>
<widget class="qMRMLWidget" name="qMRMLVirtualRealityDataModuleWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>530</width>
<height>263</height>
</rect>
</property>
<property name="windowTitle">
<string>VR Data</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item>
<widget class="qMRMLSubjectHierarchyTreeView" name="SubjectHierarchyTreeView"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>qMRMLWidget</class>
<extends>QWidget</extends>
<header>qMRMLWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>qMRMLSubjectHierarchyTreeView</class>
<extends>QTreeView</extends>
<header>qMRMLSubjectHierarchyTreeView.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>qMRMLVirtualRealityDataModuleWidget</sender>
<signal>mrmlSceneChanged(vtkMRMLScene*)</signal>
<receiver>SubjectHierarchyTreeView</receiver>
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>1</y>
</hint>
<hint type="destinationlabel">
<x>152</x>
<y>37</y>
</hint>
</hints>
</connection>
</connections>
</ui>
112 changes: 112 additions & 0 deletions VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*==============================================================================
Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
Queen's University, Kingston, ON, Canada. All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file was originally developed by Csaba Pinter, PerkLab, Queen's University
and was supported through the Applied Cancer Research Unit program of Cancer Care
Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
and CANARIE.
==============================================================================*/

// VirtualReality Widgets includes
#include "qMRMLVirtualRealityDataModuleWidget.h"
#include "ui_qMRMLVirtualRealityDataModuleWidget.h"

// VirtualReality MRML includes
#include "vtkMRMLVirtualRealityViewNode.h"

// Qt includes
#include <QDebug>

//-----------------------------------------------------------------------------
class qMRMLVirtualRealityDataModuleWidgetPrivate : public Ui_qMRMLVirtualRealityDataModuleWidget
{
Q_DECLARE_PUBLIC(qMRMLVirtualRealityDataModuleWidget);

protected:
qMRMLVirtualRealityDataModuleWidget* const q_ptr;

public:
qMRMLVirtualRealityDataModuleWidgetPrivate(qMRMLVirtualRealityDataModuleWidget& object);
virtual ~qMRMLVirtualRealityDataModuleWidgetPrivate();

void init();

public:
/// Virtual reality view MRML node
vtkWeakPointer<vtkMRMLVirtualRealityViewNode> VirtualRealityViewNode;
};

//-----------------------------------------------------------------------------
qMRMLVirtualRealityDataModuleWidgetPrivate::qMRMLVirtualRealityDataModuleWidgetPrivate(qMRMLVirtualRealityDataModuleWidget& object)
: q_ptr(&object)
{
}

//-----------------------------------------------------------------------------
qMRMLVirtualRealityDataModuleWidgetPrivate::~qMRMLVirtualRealityDataModuleWidgetPrivate()
{
}

//-----------------------------------------------------------------------------
void qMRMLVirtualRealityDataModuleWidgetPrivate::init()
{
Q_Q(qMRMLVirtualRealityDataModuleWidget);
this->setupUi(q);
}

//-----------------------------------------------------------------------------
// qMRMLVirtualRealityDataModuleWidget methods

//-----------------------------------------------------------------------------
qMRMLVirtualRealityDataModuleWidget::qMRMLVirtualRealityDataModuleWidget(QWidget* _parent)
: qMRMLWidget(_parent)
, d_ptr(new qMRMLVirtualRealityDataModuleWidgetPrivate(*this))
{
Q_D(qMRMLVirtualRealityDataModuleWidget);
d->init();

this->updateWidgetFromMRML();
}

//-----------------------------------------------------------------------------
qMRMLVirtualRealityDataModuleWidget::~qMRMLVirtualRealityDataModuleWidget()
= default;

//-----------------------------------------------------------------------------
vtkMRMLVirtualRealityViewNode* qMRMLVirtualRealityDataModuleWidget::virtualRealityViewNode() const
{
Q_D(const qMRMLVirtualRealityDataModuleWidget);
return d->VirtualRealityViewNode;
}

//-----------------------------------------------------------------------------
QString qMRMLVirtualRealityDataModuleWidget::virtualRealityViewNodeID()const
{
Q_D(const qMRMLVirtualRealityDataModuleWidget);
return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString());
}

//-----------------------------------------------------------------------------
void qMRMLVirtualRealityDataModuleWidget::updateWidgetFromMRML()
{
//Q_D(qMRMLVirtualRealityDataModuleWidget);
}

//-----------------------------------------------------------------------------
qMRMLSubjectHierarchyTreeView* qMRMLVirtualRealityDataModuleWidget::treeView()
{
Q_D(qMRMLVirtualRealityDataModuleWidget);
return d->SubjectHierarchyTreeView;
}
76 changes: 76 additions & 0 deletions VirtualReality/Widgets/qMRMLVirtualRealityDataModuleWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*==============================================================================
Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
Queen's University, Kingston, ON, Canada. All Rights Reserved.
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This file was originally developed by Csaba Pinter, PerkLab, Queen's University
and was supported through the Applied Cancer Research Unit program of Cancer Care
Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
and CANARIE.
==============================================================================*/

#ifndef __qMRMLVirtualRealityDataModuleWidget_h
#define __qMRMLVirtualRealityDataModuleWidget_h

// VirtualReality Widgets includes
#include "qSlicerVirtualRealityModuleWidgetsExport.h"

// MRMLWidgets includes
#include "qMRMLWidget.h"

// CTK includes
#include <ctkPimpl.h>
#include <ctkVTKObject.h>

// MRML includes
#include "qMRMLSubjectHierarchyTreeView.h"
#include "qMRMLSubjectHierarchyModel.h"

class vtkMRMLVirtualRealityViewNode;
class qMRMLVirtualRealityDataModuleWidgetPrivate;

/// \ingroup SlicerVirtualReality_Widgets
class Q_SLICER_QTMODULES_VIRTUALREALITY_WIDGETS_EXPORT qMRMLVirtualRealityDataModuleWidget : public qMRMLWidget
{
Q_OBJECT
QVTK_OBJECT

public:
typedef qMRMLWidget Superclass;
/// Constructor
explicit qMRMLVirtualRealityDataModuleWidget(QWidget* parent = nullptr);
/// Destructor
~qMRMLVirtualRealityDataModuleWidget() override;

/// Get virtual reality view MRML node
Q_INVOKABLE vtkMRMLVirtualRealityViewNode* virtualRealityViewNode()const;
Q_INVOKABLE QString virtualRealityViewNodeID()const;

/// Get subject hierarchy tree view
Q_INVOKABLE qMRMLSubjectHierarchyTreeView* treeView();

public slots:

protected slots:
/// Update widgets from the MRML node
void updateWidgetFromMRML();

protected:
QScopedPointer<qMRMLVirtualRealityDataModuleWidgetPrivate> d_ptr;

private:
Q_DECLARE_PRIVATE(qMRMLVirtualRealityDataModuleWidget);
Q_DISABLE_COPY(qMRMLVirtualRealityDataModuleWidget);
};

#endif
21 changes: 17 additions & 4 deletions VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

// VirtualReality Widgets includes
#include "qMRMLVirtualRealityHomeWidget.h"

#include "ui_qMRMLVirtualRealityHomeWidget.h"

// VirtualReality MRML includes
#include "vtkMRMLVirtualRealityViewNode.h"
#include "qMRMLVirtualRealityDataModuleWidget.h"

// VTK includes
#include <vtkWeakPointer.h>
Expand Down Expand Up @@ -53,13 +53,15 @@ class qMRMLVirtualRealityHomeWidgetPrivate : public Ui_qMRMLVirtualRealityHomeWi
public:
/// Virtual reality view MRML node
vtkWeakPointer<vtkMRMLVirtualRealityViewNode> VirtualRealityViewNode;
qMRMLVirtualRealityDataModuleWidget* DataModuleWidget;
};

//-----------------------------------------------------------------------------
qMRMLVirtualRealityHomeWidgetPrivate::qMRMLVirtualRealityHomeWidgetPrivate(qMRMLVirtualRealityHomeWidget& object)
: q_ptr(&object)
{
this->VirtualRealityViewNode = nullptr;
this->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget;
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -92,6 +94,7 @@ void qMRMLVirtualRealityHomeWidgetPrivate::init()
// qMRMLVirtualRealityHomeWidget methods

//-----------------------------------------------------------------------------

qMRMLVirtualRealityHomeWidget::qMRMLVirtualRealityHomeWidget(QWidget* _parent)
: qMRMLWidget(_parent)
, d_ptr(new qMRMLVirtualRealityHomeWidgetPrivate(*this))
Expand All @@ -112,6 +115,13 @@ vtkMRMLVirtualRealityViewNode* qMRMLVirtualRealityHomeWidget::virtualRealityView
return d->VirtualRealityViewNode;
}

//-----------------------------------------------------------------------------
QString qMRMLVirtualRealityHomeWidget::virtualRealityViewNodeID()const
{
Q_D(const qMRMLVirtualRealityHomeWidget);
return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString());
}

//-----------------------------------------------------------------------------
void qMRMLVirtualRealityHomeWidget::addModuleButton(QWidget* moduleWidget, QIcon& icon)
{
Expand Down Expand Up @@ -174,10 +184,13 @@ void qMRMLVirtualRealityHomeWidget::onBackButtonPressed()
}

//-----------------------------------------------------------------------------
QString qMRMLVirtualRealityHomeWidget::virtualRealityViewNodeID()const
void qMRMLVirtualRealityHomeWidget::registerDataModule()
{
Q_D(const qMRMLVirtualRealityHomeWidget);
return (d->VirtualRealityViewNode.GetPointer() ? d->VirtualRealityViewNode->GetID() : QString());
Q_D(qMRMLVirtualRealityHomeWidget);
QIcon dataIcon(QPixmap(":/Icons/SubjectHierarchy.png"));
addModuleButton(d->DataModuleWidget, dataIcon);
d->DataModuleWidget->setMRMLScene(this->mrmlScene());
d->DataModuleWidget->treeView()->setColumnHidden(d->DataModuleWidget->treeView()->model()->idColumn(),true);
}

//-----------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion VirtualReality/Widgets/qMRMLVirtualRealityHomeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public slots:
void addModuleButton(QWidget* moduleWidget, QIcon& icon);
void onModuleButtonPressed();
void onBackButtonPressed();

void registerDataModule();

protected slots:
/// Update widgets from the MRML node
void updateWidgetFromMRML();
Expand Down
4 changes: 3 additions & 1 deletion VirtualReality/Widgets/qMRMLVirtualRealityView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ qMRMLVirtualRealityViewPrivate::qMRMLVirtualRealityViewPrivate(qMRMLVirtualReali
{
this->MRMLVirtualRealityViewNode = nullptr;
this->HomeWidget = new qMRMLVirtualRealityHomeWidget(q_ptr);
this->DataModuleWidget = new qMRMLVirtualRealityDataModuleWidget;
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -685,7 +686,8 @@ qMRMLVirtualRealityView::~qMRMLVirtualRealityView()
void qMRMLVirtualRealityView::registerModule(QWidget* widget, QIcon& icon)
{
Q_D(qMRMLVirtualRealityView);
d->HomeWidget->addModuleButton(widget, icon);

d->HomeWidget->addModuleButton(widget, icon);
}

//------------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit a8fca31

Please sign in to comment.