Commit 4f64c9fe authored by Emmanuel Promayon's avatar Emmanuel Promayon

NEW CamiTK action MVC principles applied to the visible viewer radio buttons

parent 8964ce8b
......@@ -32,6 +32,9 @@
#include <ImageComponent.h>
#include <Log.h>
// to get the enum as a string
#include <QMetaEnum>
#include "AnglesAndTranslationWidget.h"
using namespace camitk;
......@@ -74,6 +77,12 @@ AnglesAndTranslationAction::AnglesAndTranslationAction(ActionExtension* extensio
actionProperty->setAttribute("maximum", 360);
addParameter(actionProperty);
actionProperty = new Property("Visible Viewer", MedicalImageViewer::VIEWER_ARBITRARY, "Visible viewer in the main window", "");
// To set the enum type, use the same name of the enum as declared in the class
actionProperty->setEnumTypeName("LayoutVisibility");
// Add the property as an action parameter
addParameter(actionProperty);
// be notified automatically when the parameters change
setAutoUpdateProperties(true);
}
......@@ -92,49 +101,46 @@ QWidget* AnglesAndTranslationAction::getWidget() {
// update the pointer
currentImageComp = dynamic_cast<ImageComponent*>(getTargets().last())->getArbitrarySlices();
// show the arbitrary viewer
setViewer(camitk::MedicalImageViewer::VIEWER_ARBITRARY);
// make sure the arbitrary slice is visible in 3D
currentImageComp->setViewSliceIn3D(true);
// update the properties
updateParameters();
update();
return actionWidget;
}
// ---------------------- updateParameters ----------------------------
void AnglesAndTranslationAction::updateParameters() {
void AnglesAndTranslationAction::update() {
// update current action properties safely (i.e. without event(..) to be doing anything on the component)
blockEvent = true;
// current translation along the z axis of the arbitrary slice
setProperty("Translation", currentImageComp->getTranslationInVolume()*100.0);
setProperty("Translation", currentImageComp->getTranslationInVolume() * 100.0);
// update widget
dynamic_cast<AnglesAndTranslationWidget*>(actionWidget)->updateGUI();
// update central viewer
MedicalImageViewer::LayoutVisibility visibleViewer = static_cast<MedicalImageViewer::LayoutVisibility>(property("Visible Viewer").toInt());
MedicalImageViewer::getInstance()->setVisibleViewer(visibleViewer);
// keep property up-to-date when the GUI will change
blockEvent = false;
}
// ---------------------- setViewer ----------------------------
void AnglesAndTranslationAction::setViewer(camitk::MedicalImageViewer::LayoutVisibility visibleViewer) {
MedicalImageViewer::getInstance()->setVisibleViewer(visibleViewer);
}
// ---------------------- resetTransform ----------------------------
void AnglesAndTranslationAction::resetTransform() {
currentImageComp->resetTransform();
// Reset the angle to zero
blockEvent = true;
setProperty("X Angle", 0);
setProperty("Y Angle", 0);
setProperty("Z Angle", 0);
blockEvent = false;
updateParameters();
update();
currentImageComp->refresh();
}
......@@ -151,15 +157,19 @@ bool AnglesAndTranslationAction::event(QEvent* e) {
return false;
// do something depending of the property that has changed
if (changeEvent->propertyName() == "Translation") {
currentImageComp->setTransformTranslation(0.0, 0.0, property(changeEvent->propertyName()).toDouble()/100.0);
}
else {
currentImageComp->setTransformRotation(property("X Angle").toInt(), property("Y Angle").toInt(), property("Z Angle").toInt());
if (changeEvent->propertyName() != "Visible Viewer") {
// only translation and rotation angle are of interest here (the "Visible Viewer" changes will automatically be
// taken into account in the update() method
if (changeEvent->propertyName() == "Translation") {
currentImageComp->setTransformTranslation(0.0, 0.0, property(changeEvent->propertyName()).toDouble() / 100.0);
}
else {
currentImageComp->setTransformRotation(property("X Angle").toInt(), property("Y Angle").toInt(), property("Z Angle").toInt());
}
}
// needed as rotation might change the translation value or translation might have been rejected
updateParameters();
update();
currentImageComp->refresh();
......
......@@ -57,9 +57,6 @@ public:
/// manage change in the action parameters (angles and slice number)
virtual bool event(QEvent* e);
/// show or hide the arbitrary viewer, 3D or all viewer
void setViewer(camitk::MedicalImageViewer::LayoutVisibility);
// reset transform to identity
void resetTransform();
......@@ -73,8 +70,9 @@ public slots:
private:
/// update action's parameter using the current image state + update widget GUI
void updateParameters();
/// + update the central viewer depending on the current value of the "Visible Viewer" property
void update();
/// currently controled image
camitk::ArbitrarySingleImageComponent* currentImageComp;
......
......@@ -84,28 +84,24 @@ void AnglesAndTranslationWidget::updateGUI() {
// -------------------- showArbitraryViewer --------------------
void AnglesAndTranslationWidget::showArbitraryViewer(bool buttonState) {
if (buttonState) {
myAction->setViewer(camitk::MedicalImageViewer::VIEWER_ARBITRARY);
myAction->setProperty("Visible Viewer", camitk::MedicalImageViewer::VIEWER_ARBITRARY);
}
}
// -------------------- show3DViewer --------------------
void AnglesAndTranslationWidget::show3DViewer(bool buttonState) {
if (buttonState) {
myAction->setViewer(camitk::MedicalImageViewer::VIEWER_3D);
myAction->setProperty("Visible Viewer", camitk::MedicalImageViewer::VIEWER_3D);
}
}
// -------------------- showAllViewer --------------------
void AnglesAndTranslationWidget::showAllViewer(bool buttonState) {
if (buttonState) {
myAction->setViewer(camitk::MedicalImageViewer::VIEWER_ALL);
myAction->setProperty("Visible Viewer", camitk::MedicalImageViewer::VIEWER_ALL);
}
}
// -------------------- updateAngleSliderLabel --------------------
void AnglesAndTranslationWidget::resetTransform() {
myAction->resetTransform();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment