Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JumpSliceType setting option to Markups settings panel #1202

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 37 additions & 24 deletions Modules/Loadable/Markups/Logic/vtkSlicerMarkupsLogic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

==============================================================================*/

// Qt includes
#include <QSettings>

// Markups includes
#include "vtkSlicerMarkupsLogic.h"

Expand Down Expand Up @@ -145,36 +148,46 @@ void vtkSlicerMarkupsLogic::ProcessMRMLNodesEvents(vtkObject *caller,
}
else if (event == vtkMRMLMarkupsDisplayNode::JumpToPointEvent)
{
int controlPointIndex = -1;
int viewGroup = -1;
vtkMRMLSliceNode* sliceNode = nullptr;
if (callData != nullptr)
QSettings settings;
std::string leftButtonClickEvent = "Centered"; //default
if (settings.contains("Markups/JumpSliceType"))
{
vtkMRMLInteractionEventData* eventData = reinterpret_cast<vtkMRMLInteractionEventData*>(callData);
if (eventData->GetComponentType() == vtkMRMLMarkupsDisplayNode::ComponentControlPoint)
{
controlPointIndex = eventData->GetComponentIndex();
}
if (eventData->GetViewNode())
{
viewGroup = eventData->GetViewNode()->GetViewGroup();
sliceNode = vtkMRMLSliceNode::SafeDownCast(eventData->GetViewNode());
}
leftButtonClickEvent = settings.value("Markups/JumpSliceType").toString().toLatin1();
}
// Jump current slice node to the plane of the control point (do not center)
if (sliceNode)
if (leftButtonClickEvent != "None")
{
vtkMRMLMarkupsNode* markupsNode = vtkMRMLMarkupsNode::SafeDownCast(markupsDisplayNode->GetDisplayableNode());
if (markupsNode)
int controlPointIndex = -1;
int viewGroup = -1;
vtkMRMLSliceNode* sliceNode = nullptr;
if (callData != nullptr)
{
double worldPos[3] = { 0.0 };
markupsNode->GetNthControlPointPositionWorld(controlPointIndex, worldPos);
sliceNode->JumpSliceByOffsetting(worldPos[0], worldPos[1], worldPos[2]);
vtkMRMLInteractionEventData* eventData = reinterpret_cast<vtkMRMLInteractionEventData*>(callData);
if (eventData->GetComponentType() == vtkMRMLMarkupsDisplayNode::ComponentControlPoint)
{
controlPointIndex = eventData->GetComponentIndex();
}
if (eventData->GetViewNode())
{
viewGroup = eventData->GetViewNode()->GetViewGroup();
sliceNode = vtkMRMLSliceNode::SafeDownCast(eventData->GetViewNode());
}
}
// Jump current slice node to the plane of the control point (do not center)
if (sliceNode)
{
vtkMRMLMarkupsNode* markupsNode = vtkMRMLMarkupsNode::SafeDownCast(markupsDisplayNode->GetDisplayableNode());
if (markupsNode)
{
double worldPos[3] = { 0.0 };
markupsNode->GetNthControlPointPositionWorld(controlPointIndex, worldPos);
sliceNode->JumpSliceByOffsetting(worldPos[0], worldPos[1], worldPos[2]);
}
}
bool center = (leftButtonClickEvent == "Centered");
// Jump centered in all other slices in the view group
this->JumpSlicesToNthPointInMarkup(markupsDisplayNode->GetDisplayableNode()->GetID(), controlPointIndex,
center, viewGroup, sliceNode);
}
// Jump centered in all other slices in the view group
this->JumpSlicesToNthPointInMarkup(markupsDisplayNode->GetDisplayableNode()->GetID(), controlPointIndex,
true /* centered */, viewGroup, sliceNode);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,35 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="defaultJumpSliceTypeLabel">
<property name="text">
<string>LeftButtonClick Jump Slice Type:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="defaultJumpSliceTypeComboBox">
<property name="currentIndex">
<number>2</number>
</property>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>Offset</string>
</property>
</item>
<item>
<property name="text">
<string>Centered</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
5 changes: 1 addition & 4 deletions Modules/Loadable/Markups/qSlicerMarkupsModule.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
#include "qSlicerMarkupsModule.h"
#include "qSlicerMarkupsModuleWidget.h"
#include "qSlicerMarkupsReader.h"
//#include "qSlicerMarkupsSettingsPanel.h"
//#include "vtkSlicerMarkupsLogic.h"
#include "qSlicerMarkupsSettingsPanel.h"
#include "vtkMRMLMarkupsDisplayNode.h"

// DisplayableManager initialization
Expand Down Expand Up @@ -134,7 +133,6 @@ void qSlicerMarkupsModule::setup()
QStringList() << "vtkMRMLMarkupsNode", true, this));

// settings
/*
if (qSlicerApplication::application())
{
qSlicerMarkupsSettingsPanel* panel =
Expand All @@ -143,7 +141,6 @@ void qSlicerMarkupsModule::setup()
"Markups", panel);
panel->setMarkupsLogic(vtkSlicerMarkupsLogic::SafeDownCast(this->logic()));
}
*/

// Register Subject Hierarchy core plugins
qSlicerSubjectHierarchyPluginHandler::instance()->registerPlugin(new qSlicerSubjectHierarchyMarkupsPlugin());
Expand Down
130 changes: 90 additions & 40 deletions Modules/Loadable/Markups/qSlicerMarkupsSettingsPanel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// Qt includes
#include <QDebug>
#include <QSettings>

// QtGUI includes
#include "qSlicerApplication.h"
Expand Down Expand Up @@ -117,57 +118,55 @@ ::setMarkupsLogic(vtkSlicerMarkupsLogic* logic)
"defaultTextScale", SIGNAL(defaultTextScaleChanged(double)));
this->registerProperty("Markups/Opacity", this,
"defaultOpacity", SIGNAL(defaultOpacityChanged(double)));
this->registerProperty("Markups/JumpSliceType", this,
"defaultJumpSliceType", SIGNAL(defaultJumpSliceTypeChanged(QString)));
}

// --------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel
::onMarkupsLogicModified()
{
Q_D(qSlicerMarkupsSettingsPanel);
/* disable it for now; if we want a settings panel then use the same pattern that is used for default view options
this->readDefaultMarkupsDisplaySettings();

// update the gui to match the logic
QString glyphType = QString(d->MarkupsLogic->GetDefaultMarkupsDisplayNodeGlyphTypeAsString().c_str());

QObject::connect(d->defaultGlyphTypeComboBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(onDefaultGlyphTypeChanged(int)),Qt::UniqueConnection);
}

// TODO: do I need to use the strings?
// d->defaultGlyphTypeComboBox->setCurrentIndex(glyphType - 1);
int glyphTypeIndex = d->defaultGlyphTypeComboBox->findData(glyphType);
if (glyphTypeIndex != -1)
//-----------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel::readDefaultMarkupsDisplaySettings()
{
QSettings settings;
if (settings.contains("Markups/GlyphType"))
{
d->defaultGlyphTypeComboBox->setCurrentIndex(glyphTypeIndex);
setDefaultGlyphType(settings.value("Markups/GlyphType").toString().toLatin1());
}
if (settings.contains("Markups/SelectedColor"))
{
QVariant variant = settings.value("Markups/SelectedColor");
QColor qcolor = variant.value<QColor>();
setDefaultSelectedColor(qcolor);
}
if (settings.contains("Markups/UnselectedColor"))
{
QVariant variant = settings.value("Markups/UnselectedColor");
QColor qcolor = variant.value<QColor>();
setDefaultUnselectedColor(qcolor);
}
if (settings.contains("Markups/GlyphScale"))
{
setDefaultGlyphScale(settings.value("Markups/GlyphScale").toDouble());
}
if (settings.contains("Markups/TextScale"))
{
setDefaultTextScale(settings.value("Markups/TextScale").toDouble());
}
if (settings.contains("Markups/Opacity"))
{
setDefaultOpacity(settings.value("Markups/Opacity").toDouble());
}
if (settings.contains("Markups/JumpSliceType"))
{
setDefaultGlyphType(settings.value("Markups/JumpSliceType").toString().toLatin1());
}


double *unselectedColor = d->MarkupsLogic->GetDefaultMarkupsDisplayNodeColor();
QObject::connect(d->defaultUnselectedColorPickerButton, SIGNAL(colorChanged(QColor)),
this, SLOT(onDefaultUnselectedColorChanged(QColor)));
QColor qcolor = QColor::fromRgbF(unselectedColor[0], unselectedColor[1], unselectedColor[2]);
d->defaultUnselectedColorPickerButton->setColor(qcolor);

double *selectedColor = d->MarkupsLogic->GetDefaultMarkupsDisplayNodeSelectedColor();
QObject::connect(d->defaultSelectedColorPickerButton, SIGNAL(colorChanged(QColor)),
this, SLOT(onDefaultSelectedColorChanged(QColor)),Qt::UniqueConnection);
qcolor = QColor::fromRgbF(selectedColor[0], selectedColor[1], selectedColor[2]);
d->defaultSelectedColorPickerButton->setColor(qcolor);

double glyphScale = d->MarkupsLogic->GetDefaultMarkupsDisplayNodeGlyphScale();
QObject::connect(d->defaultGlyphScaleSliderWidget, SIGNAL(valueChanged(double)),
this, SLOT(onDefaultGlyphScaleChanged(double)),Qt::UniqueConnection);
d->defaultGlyphScaleSliderWidget->setValue(glyphScale);

double textScale = d->MarkupsLogic->GetDefaultMarkupsDisplayNodeTextScale();
QObject::connect(d->defaultTextScaleSliderWidget, SIGNAL(valueChanged(double)),
this, SLOT(onDefaultTextScaleChanged(double)),Qt::UniqueConnection);
d->defaultTextScaleSliderWidget->setValue(textScale);

double opacity = d->MarkupsLogic->GetDefaultMarkupsDisplayNodeOpacity();
QObject::connect(d->defaultOpacitySliderWidget, SIGNAL(valueChanged(double)),
this, SLOT(onDefaultOpacityChanged(double)),Qt::UniqueConnection);
d->defaultOpacitySliderWidget->setValue(opacity);
*/
}

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -235,6 +234,21 @@ double qSlicerMarkupsSettingsPanel::defaultOpacity()const
return opacity;
}

// --------------------------------------------------------------------------
QString qSlicerMarkupsSettingsPanel::defaultJumpSliceType()const
{
Q_D(const qSlicerMarkupsSettingsPanel);

int currentIndex = d->defaultJumpSliceTypeComboBox->currentIndex();
QString jumpSliceType;
if (currentIndex != -1)
{
jumpSliceType =
d->defaultJumpSliceTypeComboBox->itemText(currentIndex);
}
return jumpSliceType;
}

// --------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel::setDefaultGlyphType(const QString& glyphType)
{
Expand Down Expand Up @@ -288,6 +302,19 @@ void qSlicerMarkupsSettingsPanel::setDefaultOpacity(const double opacity)
d->defaultOpacitySliderWidget->setValue(opacity);
}

// --------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel::setDefaultJumpSliceType(const QString& jumpSliceType)
{
Q_D(qSlicerMarkupsSettingsPanel);

int jumpSliceTypeIndex = d->defaultJumpSliceTypeComboBox->findData(jumpSliceType);

if (jumpSliceTypeIndex != -1)
{
d->defaultJumpSliceTypeComboBox->setCurrentIndex(jumpSliceTypeIndex);
}
}

// --------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel::onDefaultGlyphTypeChanged(int index)
{
Expand Down Expand Up @@ -425,3 +452,26 @@ void qSlicerMarkupsSettingsPanel::updateMarkupsLogicDefaultOpacity()
// disable it for now; if we want a settings panel then use the same pattern that is used for default view options
// d->MarkupsLogic->SetDefaultMarkupsDisplayNodeOpacity(this->defaultOpacity());
}

// --------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel::onDefaultJumpSliceTypeChanged(int index)
{
// Q_D(qSlicerMarkupsSettingsPanel);
Q_UNUSED(index);

this->updateMarkupsLogicDefaultJumpSliceType();
emit defaultJumpSliceTypeChanged(this->defaultJumpSliceType());
}

// --------------------------------------------------------------------------
void qSlicerMarkupsSettingsPanel::updateMarkupsLogicDefaultJumpSliceType()
{
Q_D(qSlicerMarkupsSettingsPanel);

if (d->MarkupsLogic == nullptr)
{
return;
}
// disable it for now; if we want a settings panel then use the same pattern that is used for default view options
// d->MarkupsLogic->SetDefaultMarkupsDisplayNodeJumpSliceTypeFromString(this->defaultJumpSliceType().toLatin1());
}
9 changes: 9 additions & 0 deletions Modules/Loadable/Markups/qSlicerMarkupsSettingsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Q_SLICER_QTMODULES_MARKUPS_EXPORT qSlicerMarkupsSettingsPanel
Q_PROPERTY(double defaultGlyphScale READ defaultGlyphScale WRITE setDefaultGlyphScale NOTIFY defaultGlyphScaleChanged)
Q_PROPERTY(double defaultTextScale READ defaultTextScale WRITE setDefaultTextScale NOTIFY defaultTextScaleChanged)
Q_PROPERTY(double defaultOpacity READ defaultOpacity WRITE setDefaultOpacity NOTIFY defaultOpacityChanged)
Q_PROPERTY(QString defaultJumpSliceType READ defaultJumpSliceType WRITE setDefaultJumpSliceType NOTIFY defaultJumpSliceTypeChanged)

public:
/// Superclass typedef
Expand All @@ -59,12 +60,15 @@ class Q_SLICER_QTMODULES_MARKUPS_EXPORT qSlicerMarkupsSettingsPanel
void setMarkupsLogic(vtkSlicerMarkupsLogic* logic);
vtkSlicerMarkupsLogic* markupsLogic()const;

void readDefaultMarkupsDisplaySettings();

QString defaultGlyphType() const;
QColor defaultUnselectedColor() const;
QColor defaultSelectedColor() const;
double defaultGlyphScale() const;
double defaultTextScale() const;
double defaultOpacity() const;
QString defaultJumpSliceType() const;

public slots:
void setDefaultGlyphType(const QString& type);
Expand All @@ -73,6 +77,7 @@ public slots:
void setDefaultGlyphScale(const double scale);
void setDefaultTextScale(const double scale);
void setDefaultOpacity(const double scale);
void setDefaultJumpSliceType(const QString& type);

signals:
void defaultGlyphTypeChanged(const QString&);
Expand All @@ -81,6 +86,7 @@ public slots:
void defaultGlyphScaleChanged(const double);
void defaultTextScaleChanged(const double);
void defaultOpacityChanged(const double);
void defaultJumpSliceTypeChanged(const QString&);

protected slots:
void onMarkupsLogicModified();
Expand All @@ -103,6 +109,9 @@ protected slots:
void onDefaultOpacityChanged(double);
void updateMarkupsLogicDefaultOpacity();

void onDefaultJumpSliceTypeChanged(int);
void updateMarkupsLogicDefaultJumpSliceType();

protected:
QScopedPointer<qSlicerMarkupsSettingsPanelPrivate> d_ptr;

Expand Down