diff --git a/sdk/actions/application/Show3DViewer.cpp b/sdk/actions/application/Show3DViewer.cpp index fff2e5a5f6b1830fdbd0cf1c2ae008c905fcf0e7..d091c88b00de390c334bb211a7d0bdcc762dfabd 100644 --- a/sdk/actions/application/Show3DViewer.cpp +++ b/sdk/actions/application/Show3DViewer.cpp @@ -61,5 +61,6 @@ QWidget* Show3DViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus Show3DViewer::apply() { MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_3D); + Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowAllViewers.cpp b/sdk/actions/application/ShowAllViewers.cpp index 4d60fa4908864d5d3aa223e227358e058fe43957..7b687a2ec965434067b899b3bd4f528ff5b9d0fc 100644 --- a/sdk/actions/application/ShowAllViewers.cpp +++ b/sdk/actions/application/ShowAllViewers.cpp @@ -61,5 +61,6 @@ QWidget* ShowAllViewers::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowAllViewers::apply() { MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); + Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowArbitraryViewer.cpp b/sdk/actions/application/ShowArbitraryViewer.cpp index 6365450a043f0b5eb99c41286a3eb8460b5c961f..39094316b66441c248f698d57876bf1464907add 100644 --- a/sdk/actions/application/ShowArbitraryViewer.cpp +++ b/sdk/actions/application/ShowArbitraryViewer.cpp @@ -61,5 +61,6 @@ QWidget* ShowArbitraryViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowArbitraryViewer::apply() { MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_ARBITRARY); + Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowAxialViewer.cpp b/sdk/actions/application/ShowAxialViewer.cpp index 7046fb74e5db1ff5035bd6510d03f10993f129d6..c9ddb37c53cf3b519c58afec44724b8b6d625dc4 100644 --- a/sdk/actions/application/ShowAxialViewer.cpp +++ b/sdk/actions/application/ShowAxialViewer.cpp @@ -61,5 +61,6 @@ QWidget* ShowAxialViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowAxialViewer::apply() { MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_AXIAL); + Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowCoronalViewer.cpp b/sdk/actions/application/ShowCoronalViewer.cpp index 1ca2c8acafd773ad2411a26a6a516c2ae545525a..19beb6fcccda2b6ddb824adba92afdbe0d5730a9 100644 --- a/sdk/actions/application/ShowCoronalViewer.cpp +++ b/sdk/actions/application/ShowCoronalViewer.cpp @@ -61,5 +61,6 @@ QWidget* ShowCoronalViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowCoronalViewer::apply() { MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_CORONAL); + Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowSagittalViewer.cpp b/sdk/actions/application/ShowSagittalViewer.cpp index d0342ba7528be00f94fdd323f13652d9046eb2b5..6ec9e733edf4bf04f55f06d0265c73719d0ccde0 100644 --- a/sdk/actions/application/ShowSagittalViewer.cpp +++ b/sdk/actions/application/ShowSagittalViewer.cpp @@ -61,5 +61,6 @@ QWidget* ShowSagittalViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowSagittalViewer::apply() { MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_SAGITTAL); + Application::refresh(); return SUCCESS; } diff --git a/sdk/applications/config/testing/config-test.sh b/sdk/applications/config/testing/config-test.sh index 520a06c2add47ed5bb6c8b337c3b6df07921485b..5e3fae46379ca20800b1bf7bf06970834eec88b2 100644 --- a/sdk/applications/config/testing/config-test.sh +++ b/sdk/applications/config/testing/config-test.sh @@ -22,11 +22,11 @@ set -e # values to check initTestData() { # fill test data - extensionCount=( [4.2]=42 [4.1]=41 [4.0]=31 ) + extensionCount=( [4.2]=43 [4.1]=41 [4.0]=31 ) componentExtensionCount=( [4.2]=14 [4.1]=14 [4.0]=14 ) - actionExtensionCount=( [4.2]=28 [4.1]=27 [4.0]=27 ) + actionExtensionCount=( [4.2]=29 [4.1]=27 [4.0]=27 ) fileExtensionCount=( [4.2]=37 [4.1]=37 [4.0]=37 ) - actionCount=( [4.2]=106 [4.1]=105 [4.0]=105 ) + actionCount=( [4.2]=107 [4.1]=105 [4.0]=105 ) # fill release date releaseDate=( [4.2]="not yet released, current development version" \ diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index e48154e88eecd628f41a1ec1326b7cf2114b1eaa..6eccc8d05818536f92e8d1919a4a95f5b608bd28 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -85,7 +85,7 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { dockWidgetExplorer->raise(); } - showViewer(ActionViewer::getInstance(), false); + showDockViewer(ActionViewer::getInstance(), false); ActionViewer::getInstance()->setSearchPanelVisible(true); showStatusBar(true); } @@ -292,9 +292,9 @@ void ImpMainWindow::initMenuBar() { //--------------------------initToolBar------------------------------- void ImpMainWindow::initToolBar() { - mainToolbar = addToolBar("Main toolbar"); + mainToolbar = addToolBar("Main Toolbar"); // ensure object name is set for saving the state - mainToolbar->setObjectName("imp main toolbar"); + mainToolbar->setObjectName("ImpMainWindow Main Toolbar"); mainToolbar->addAction(fileOpen); mainToolbar->addAction(fileSave); mainToolbar->addAction(QWhatsThis::createAction(this)); @@ -387,21 +387,24 @@ void ImpMainWindow::resetWindows() { addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } - else if (it.value()->widget() == FrameExplorer::getInstance()->getWidget(NULL)) { - removeDockWidget(it.value()); - addDockWidget(Qt::LeftDockWidgetArea, it.value()); - it.value()->show(); - } - else if (it.value()->widget() == PropertyExplorer::getInstance()->getWidget()) { - removeDockWidget(it.value()); - addDockWidget(Qt::LeftDockWidgetArea, it.value()); - it.value()->show(); - } - else if (it.value()->widget() == ActionViewer::getInstance()->getWidget()) { - removeDockWidget(it.value()); - addDockWidget(Qt::RightDockWidgetArea, it.value()); - it.value()->show(); - } + else + if (it.value()->widget() == FrameExplorer::getInstance()->getWidget(NULL)) { + removeDockWidget(it.value()); + addDockWidget(Qt::LeftDockWidgetArea, it.value()); + it.value()->show(); + } + else + if (it.value()->widget() == PropertyExplorer::getInstance()->getWidget()) { + removeDockWidget(it.value()); + addDockWidget(Qt::LeftDockWidgetArea, it.value()); + it.value()->show(); + } + else + if (it.value()->widget() == ActionViewer::getInstance()->getWidget()) { + removeDockWidget(it.value()); + addDockWidget(Qt::RightDockWidgetArea, it.value()); + it.value()->show(); + } } //Merge Explorer and FrameExplorer viewers in one layout QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Explorer::getInstance(), NULL); @@ -478,6 +481,10 @@ void ImpMainWindow::openDirectory(QAction* emitter) { // ------------- updateViewMenu ----------------- void ImpMainWindow::updateViewMenu() { + // From Qt documentation: + // "Removes all the menu's actions. Actions owned by the menu and not shown in any other widget are deleted" + // I.e., the central viewer toggle action are own by viewMenu (they are created and used here), they will + // therefore be no memory leak viewMenu->clear(); // insert viewers menu @@ -489,6 +496,37 @@ void ImpMainWindow::updateViewMenu() { } } + // change the central viewer if there is more than one viewer in the central area + if (qobject_cast(centralWidget())->count() > 1) { + viewMenu->addSeparator()->setText(tr("Toggle Central Viewers")); + + // add a toggle action for each widget stacked inside the central widget + for (int i = 0; i < qobject_cast(centralWidget())->count(); i++) { + QWidget* cWidget = qobject_cast(centralWidget())->widget(i); + // Get the viewer associated with the widget in the central area + // As there is no map from widget to viewer, we need to find the viewer that + // has the given corresponding widget. + // Beware that getWidget(..) requires a parent and as the widget was setup inside centralWidget() + // it was reparented to centralWidget() → use getWidget(centralWidget()) and not getWidget(this) + // in order not to modify the central widget parenting + auto it = std::find_if(viewers.begin(), viewers.end(), [&](Viewer * v) { + return v->getWidget(centralWidget()) == cWidget; + }); + Viewer* cViewer = (*it); + // viewerAction is own by viewMenu, viewMenu->clear() will delete it + QAction *viewerAction = viewMenu->addAction(cViewer->objectName()); + viewerAction->setCheckable(true); + viewerAction->setChecked(cViewer == centralViewer); + QString tipString = "Hide/show the " + cViewer->objectName() + " central viewer"; + viewerAction->setStatusTip(tr(tipString.toStdString().c_str())); + viewerAction->setWhatsThis(tr(tipString.toStdString().c_str())); + // add the toggle action slot using C++11 lambda so that everything is contained inside viewMenu + connect(viewerAction, &QAction::toggled, [=](bool) { + setCentralViewer(cViewer); + }); + } + } + // insert viewers on/off actions viewMenu->addSeparator()->setText(tr("Toggle Viewers")); viewMenu->addAction(viewResetWindows); diff --git a/sdk/libraries/core/application/MainWindow.cpp b/sdk/libraries/core/application/MainWindow.cpp index 82c6c52da99282a86768e0c1aee2e28ca0d83522..fc0bf12b5e9fb7b91357cf97e07fd590b47f6653 100644 --- a/sdk/libraries/core/application/MainWindow.cpp +++ b/sdk/libraries/core/application/MainWindow.cpp @@ -45,6 +45,7 @@ #include #include #include +#include namespace camitk { // ------------- constructor ----------------- @@ -186,15 +187,10 @@ void MainWindow::setWindowSubtitle(QString subtitle) { bool MainWindow::addViewer(Viewer* theViewer) { if (!viewers.contains(theViewer)) { viewers.append(theViewer); + // connect connect(theViewer, SIGNAL(selectionChanged()), this, SLOT(refresh())); - // add the toolbar - if (theViewer->getToolBar()) { - QToolBar* viewerToolBar = theViewer->getToolBar(); - addToolBar(viewerToolBar); - } - return true; } @@ -203,27 +199,39 @@ bool MainWindow::addViewer(Viewer* theViewer) { // ------------- removeViewer ----------------- bool MainWindow::removeViewer(Viewer* viewer) { - if (!viewers.contains(viewer)) { - return false; - } + return true; +} - // tell all component not to be visible anymore in this viewer - foreach (Component* comp, Application::getAllComponents()) { - comp->setVisibility(viewer, false); +// ------------- showDockViewer ----------------- +void MainWindow::showDockViewer(Viewer* theViewer, bool visible) { + if (dockWidgetMap.contains(theViewer)) { + // set visibility of the viewer + dockWidgetMap[theViewer]->setVisible(visible); + // set visibility of the toolbar + showViewerToolbar(theViewer, visible); } - - // remove it properly - disconnect(viewer, SIGNAL(selectionChanged()), this, SLOT(refresh())); - viewers.removeAll(viewer); - delete viewer; - - return true; } // ------------- showViewer ----------------- void MainWindow::showViewer(Viewer* theViewer, bool visible) { - if (viewers.contains(theViewer)) { - dockWidgetMap[theViewer]->setVisible(visible); + showDockViewer(theViewer, visible); +} + +// ------------- showViewerToolbar ----------------- +void MainWindow::showViewerToolbar(Viewer* theViewer, bool visible) { + if (theViewer == nullptr) + return; + + QToolBar* viewerToolBar = theViewer->getToolBar(); + if (viewerToolBar != nullptr) { + if (visible && theViewer->getToolBarVisibility()) { + addToolBar(viewerToolBar); + viewerToolBar->setVisible(true); + } + else { + removeToolBar(viewerToolBar); + viewerToolBar->setVisible(false); + } } } @@ -232,43 +240,56 @@ void MainWindow::refreshViewers() { foreach (Viewer* v, viewers) { v->refresh(); } + // update the central viewer toolbar visibility + showViewerToolbar(centralViewer, true); } // ------------- addDockViewer ----------------- void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer) { if (addViewer(theViewer)) { - // create the dock widget and insert it - QDockWidget* viewerDock = new QDockWidget(theViewer->objectName(), this); - viewerDock->setObjectName(theViewer->objectName()); - QWidget* viewerWidget = theViewer->getWidget(viewerDock); - + // create the dock widget and insert it only if the viewer has a widget + QWidget* viewerWidget = theViewer->getWidget(this); if (viewerWidget) { + // add the widget + QDockWidget* viewerDock = new QDockWidget(theViewer->objectName(), this); + viewerDock->setObjectName(theViewer->objectName()); viewerDock->setWidget(viewerWidget); addDockWidget(dockingArea, viewerDock); - // update map + + // update the map dockWidgetMap.insert(theViewer, viewerDock); } - else { - delete viewerDock; - } - } - else { - dockWidgetMap.value(theViewer)->show(); + } + // show the viewer anyway + showDockViewer(theViewer, true); } // ------------- setCentralViewer ----------------- void MainWindow::setCentralViewer(Viewer* theViewer) { - if (theViewer->getWidget(this) && addViewer(theViewer)) { - // remove actual central viewer properly - if (centralViewer && (theViewer != centralViewer)) { - removeViewer(centralViewer); + // get the viewer widget (must have something to show as it is a viewer after all!) + QWidget* viewerWidget = theViewer->getWidget(this); + if (viewerWidget != nullptr) { + // add the viewer to the list (if not already in the list) + addViewer(theViewer); + + // if needed, create the default (empty) central widget inside which the central viewers can be added + if (centralWidget() == 0) { + setCentralWidget(new QStackedWidget(this)); } - - // set the central widget - setCentralWidget(theViewer->getWidget(this)); + else { + // there is already a central viewer, just hide its toolbar + showViewerToolbar(centralViewer, false); + } + + // add the viewer's widget + qobject_cast(centralWidget())->addWidget(viewerWidget); + qobject_cast(centralWidget())->setCurrentWidget(viewerWidget); centralViewer = theViewer; + + // show its toolbar + showViewerToolbar(centralViewer, true); } } @@ -285,6 +306,8 @@ void MainWindow::refresh() { v->refresh(); } } + // update the central viewer toolbar visibility + showViewerToolbar(centralViewer, true); } // ------------- showStatusBar ----------------- @@ -297,7 +320,6 @@ QProgressBar* MainWindow::getProgressBar() { return myProgressBar; } - // ------------- setApplicationConsole ----------------- void MainWindow::redirectToConsole(bool visible) { if (visible) { diff --git a/sdk/libraries/core/application/MainWindow.h b/sdk/libraries/core/application/MainWindow.h index 37125e148c9eeab6fb6fbd1c2690fd1b76b07476..ae70e8882ac5325d85449aa3fc9b470f428d3b3c 100644 --- a/sdk/libraries/core/application/MainWindow.h +++ b/sdk/libraries/core/application/MainWindow.h @@ -50,14 +50,20 @@ class Viewer; * @ingroup group_sdk_libraries_core_application * * @brief - * This Class is the base class for your application. It sets up the main - * window and providing a menubar, toolbar and statusbar (all hidden). + * This class is the base class for your application. It sets up the main + * window and creates a menubar, toolbar and statusbar (all hidden by default). + * * It is the default main window for a application. * * Create a class that inherits from MainWindow to - * get all the goodies of Core and add your own customization/UI. - * See applications for examples. + * get all the goodies of CamiTK and add your own customization/UI. + * + * See tutorials applications for examples. * + * The central widget is a QStackWidget: when new central viewers are added, the previous central + * viewer is hidden, not destroyed. See the "switchviewer" action tutorial for some example on + * how to embed an new central viewer to the imp main window (and switch back to medical image viewer + * whenever required). */ class CAMITK_API MainWindow : public QMainWindow { Q_OBJECT @@ -118,12 +124,28 @@ public: /// @name Viewers ///@{ + ///@cond + /** + * TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0 + * @deprecated + * + * DEPRECATED (CamiTK 5.0) -> to be removed + * This method is now called showDockViewer. + */ /// set the visibility for the given viewer (if it is in a dock) virtual void showViewer(Viewer*, bool); + ///@endcond + /// set the visibility for the given docked viewer and its toolbar + virtual void showDockViewer(Viewer*, bool); + /** add a Viewer to the application as a docking widget and specify where it has to be docked * Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time. + * * This method calls addViewer(...). + * This method calls showDockViewer(..,true) and therefore showViewerToolbar(..,true) + * + * \note MainWindow takes ownership of the viewer pointer and deletes it when it is itself destroyed. */ virtual void addDockViewer(Qt::DockWidgetArea, Viewer*); @@ -131,16 +153,26 @@ public: void refreshViewers(); /** set the central Viewer of the application. - * Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time. - * This method calls addViewer(...). + * The central viewer has a specific behaviour in a MainWindow. It uses a QStackWidget to keep + * all the central viewer that are used. When a new central viewers is set, the previous central + * viewer (i.e., its widget) is hidden but not destroyed. + * + * This method calls addViewer(..). + * This method calls showViewerToolbar(..,true) + * + * \note MainWindow takes ownership of the viewer pointer and deletes it when it is itself destroyed. */ virtual void setCentralViewer(Viewer*); /** - * @Return the actual central viewer. - * @return + * @return the current central viewer. */ virtual const Viewer& getCentralViewer() const; + + /** Set the visibility of a viewer's toolbar. + * This method respect the toolbar visibility property of the viewer. + */ + virtual void showViewerToolbar(Viewer* theViewer, bool visible); ///@} public slots: @@ -184,13 +216,22 @@ protected: /// just call open with the dragged uri void dropEvent(QDropEvent* event) override; + ///@cond /** + * TODO CAMITK_DEPRECATED. This section list all the methods marked as deprecated. They are to be removed in CamiTK 5.0 + * @deprecated + * + * DEPRECATED (CamiTK 5.0) -> to be removed + * Removing viewers can be harmful. Central viewer is now simply hidden, therefore there is no need to remove it. + * It will keep itself refreshed and when shown again will be up to date. + * * @brief Remove the given viewer from the list of viewer. * @note This tell all Component not to be visible anymore in this viewer instance, remove it from the list of viewers and delete it. * @param viewer The viewer to remove. * @return True if removing succeeded, false otherwise. */ bool removeViewer(Viewer* viewer); + ///@endcond /** * @brief The actual central Viewer. @@ -203,12 +244,11 @@ private: /** * Add a viewer (called by addDockViewer and setCentralViewer), returns true if not already added. - * Note that MainWindow takes ownership of the Viewer pointer and deletes it at the appropriate time. - * This method connects the selectionChanged signal of the viewer to the refresh method. - * Before CamiTK 4.x this method was a public method. + * Note that MainWindow takes ownership of the Viewer pointer and deletes it when it is itself destroyed. + * + * This method connects the selectionChanged signal of the viewer to the refresh method of MainWindow. */ virtual bool addViewer(Viewer*); - ///@endcond /// the output stream for the application console ConsoleStream cout; @@ -227,6 +267,7 @@ private: /// the main part of the title QString mainTitle; + }; } diff --git a/sdk/libraries/core/component/mesh/MeshComponent.cpp b/sdk/libraries/core/component/mesh/MeshComponent.cpp index e696f79e318823a3a3da2bc7c0317f1b23046ef4..9377deb09ad16436d462c116b684a5e57f25a74c 100644 --- a/sdk/libraries/core/component/mesh/MeshComponent.cpp +++ b/sdk/libraries/core/component/mesh/MeshComponent.cpp @@ -145,13 +145,13 @@ void MeshComponent::init() { // build the selection widget auto* hbox = new QVBoxLayout(selectionWidget); - auto* selectionToolBar = new QToolBar(selectionWidget); - selectionToolBar->addAction(removeSelections); - selectionToolBar->addAction(mergeSelection); - selectionToolBar->addAction(inspectSelection); - selectionToolBar->addWidget(insertionPolicyBox); + auto* selectionToolbar = new QToolBar(selectionWidget); + selectionToolbar->addAction(removeSelections); + selectionToolbar->addAction(mergeSelection); + selectionToolbar->addAction(inspectSelection); + selectionToolbar->addWidget(insertionPolicyBox); hbox->addWidget(selectionView); - hbox->addWidget(selectionToolBar); + hbox->addWidget(selectionToolbar); selectionWidget->setLayout(hbox); // data widget @@ -200,13 +200,13 @@ void MeshComponent::init() { // build the data widget auto* dataBox = new QVBoxLayout(dataWidget); - auto* dataToolBar = new QToolBar(dataWidget); - dataToolBar->addAction(removeData); - dataToolBar->addAction(inspectData); - dataToolBar->addWidget(displayTypePolicyBox); - dataToolBar->addWidget(vectorRepresentationPolicyBox); + auto* dataToolbar = new QToolBar(dataWidget); + dataToolbar->addAction(removeData); + dataToolbar->addAction(inspectData); + dataToolbar->addWidget(displayTypePolicyBox); + dataToolbar->addWidget(vectorRepresentationPolicyBox); dataBox->addWidget(dataView); - dataBox->addWidget(dataToolBar); + dataBox->addWidget(dataToolbar); dataWidget->setLayout(dataBox); } diff --git a/sdk/libraries/core/viewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/InteractiveViewer.cpp index 544d6bb98fd82a90e0c81c077543e054c29280be..dc7ce7b09aa2f10136d45bf516cfc71401a0f079 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/InteractiveViewer.cpp @@ -130,27 +130,30 @@ InteractiveViewer* InteractiveViewer::getViewer(QString name) { QString letters[4] = {QString("R"), QString("L"), QString("A"), QString("P") }; singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters); singletonInstance->toggleOrientationDecorations(true); - singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection(1); + singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); } - else if (name == defaultNames[2]) { // Coronal Viewer - singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK); - QString letters[4] = {QString("R"), QString("L"), QString("S"), QString("I") }; - singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters); - singletonInstance->toggleOrientationDecorations(true); - singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection(1); - } - else if (name == defaultNames[3]) { // Sagittal Viewer - singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN); - QString letters[4] = {QString("A"), QString("P"), QString("S"), QString("I") }; - singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters); - singletonInstance->toggleOrientationDecorations(true); - singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection(1); - } - else if (name == defaultNames[4]) { // Arbitrary Viewer + else + if (name == defaultNames[2]) { // Coronal Viewer + singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK); + QString letters[4] = {QString("R"), QString("L"), QString("S"), QString("I") }; + singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters); + singletonInstance->toggleOrientationDecorations(true); + singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else + if (name == defaultNames[3]) { // Sagittal Viewer + singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN); + QString letters[4] = {QString("A"), QString("P"), QString("S"), QString("I") }; + singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters); + singletonInstance->toggleOrientationDecorations(true); + singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else + if (name == defaultNames[4]) { // Arbitrary Viewer // singletonInstance->getRendererWidget()->setCameraOrientation ( RendererWidget::RIGHT_DOWN ); - singletonInstance->toggleOrientationDecorations(false); -// singletonInstance->getRendererWidget()->getActiveCamera()->SetParallelProjection ( 1 ); - } + singletonInstance->toggleOrientationDecorations(false); +// singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } return singletonInstance; @@ -203,7 +206,7 @@ InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(na //-- create the slice slider if needed viewerMenu = nullptr; - viewerToolBar = nullptr; + viewerToolbar = nullptr; screenshotActionMenu = nullptr; displayedTopLevelComponents = 0; @@ -211,14 +214,12 @@ InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(na pickingEffectIsSelecting = true; // default effect isPicking = false; // by default, viewer is not picking - if (myType == SLICE_VIEWER) + if (myType == SLICE_VIEWER) { // by default, the 2D scenes are set to pick slice pixels - { initPicking(InteractiveViewer::PIXEL_PICKING); } - else + else { // no picking - { initPicking(InteractiveViewer::NO_PICKING); } @@ -243,8 +244,8 @@ InteractiveViewer::~InteractiveViewer() { delete viewerMenu; viewerMenu = nullptr; - delete viewerToolBar; - viewerToolBar = nullptr; + delete viewerToolbar; + viewerToolbar = nullptr; delete frame; frame = nullptr; @@ -471,9 +472,7 @@ QWidget* InteractiveViewer::getWidget(QWidget* parent) { else { if (frame->parentWidget() != parent) { bool isVisible = frame->isVisible(); - //frame->parentWidget()->layout()->removeWidget(frame); frame->setParent(parent); - //parent->layout()->addWidget(frame); frame->setVisible(isVisible); } } @@ -760,42 +759,44 @@ QMenu* InteractiveViewer::getMenu() { // ---------------------- getToolBar ---------------------------- QToolBar* InteractiveViewer::getToolBar() { - if (frame && !viewerToolBar && myType == GEOMETRY_VIEWER) { - viewerToolBar = new QToolBar(objectName() + " ToolBar"); - // ensure object name is set for saving the state - viewerToolBar->setObjectName(objectName() + " ToolBar"); - - viewerToolBar->addAction(pickPointAction); - viewerToolBar->addAction(pickCellAction); - viewerToolBar->addAction(pickPointRegionAction); - viewerToolBar->addAction(pickCellRegionAction); + if (frame && !viewerToolbar) { + if (myType == GEOMETRY_VIEWER) { + viewerToolbar = new QToolBar(objectName() + " Toolbar"); + // ensure object name is set for saving the state + viewerToolbar->setObjectName(objectName() + " Toolbar"); + + viewerToolbar->addAction(pickPointAction); + viewerToolbar->addAction(pickCellAction); + viewerToolbar->addAction(pickPointRegionAction); + viewerToolbar->addAction(pickCellRegionAction); + + viewerToolbar->addSeparator(); + + viewerToolbar->addAction(surfaceAction); + viewerToolbar->addAction(wireframeAction); + viewerToolbar->addAction(pointsAction); + if (colorAction) { + viewerToolbar->addAction(colorAction); + } + viewerToolbar->addAction(glyphAction); + viewerToolbar->addAction(toggleLabelAction); - viewerToolBar->addSeparator(); + viewerToolbar->addSeparator(); - viewerToolBar->addAction(surfaceAction); - viewerToolBar->addAction(wireframeAction); - viewerToolBar->addAction(pointsAction); - if (colorAction) { - viewerToolBar->addAction(colorAction); - } - viewerToolBar->addAction(glyphAction); - viewerToolBar->addAction(toggleLabelAction); + viewerToolbar->addAction(toggleAxesAction); + viewerToolbar->addAction(screenshotAction); - viewerToolBar->addSeparator(); + viewerToolbar->addSeparator(); - viewerToolBar->addAction(toggleAxesAction); - if (myType == SLICE_VIEWER) { + viewerToolbar->addAction(scalarDataColorAction); + } + /* if (myType == SLICE_VIEWER) { viewerToolBar->addAction(toggleOrientationDecorationsAction); } - viewerToolBar->addAction(screenshotAction); - - viewerToolBar->addSeparator(); - - viewerToolBar->addAction(scalarDataColorAction); - + */ } - return viewerToolBar; + return viewerToolbar; } // ---------------------- initActions ---------------------------- @@ -848,7 +849,7 @@ void InteractiveViewer::initActions() { scalarDataModel = new MeshDataFilterModel(MeshComponent::POINTS | MeshComponent::CELLS, MeshComponent::SCALARS, this); // combo box for viewing the scalar data model - scalarDataComboBox = new QComboBox(viewerToolBar); + scalarDataComboBox = new QComboBox(viewerToolbar); scalarDataComboBox->setModel(scalarDataModel); scalarDataComboBox->setMinimumWidth(150); @@ -1119,11 +1120,12 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { if (e->modifiers() == Qt::NoModifier && myType == GEOMETRY_VIEWER) { toggleLabelAction->toggle(); } - else if (e->modifiers() == Qt::AltModifier) { - // addWhatsThisItem("Alt+L", "Toggle light follows camera"); - rendererWidget->setLightFollowCamera(!rendererWidget->getLightFollowCamera()); - rendererWidget->refresh(); - } + else + if (e->modifiers() == Qt::AltModifier) { + // addWhatsThisItem("Alt+L", "Toggle light follows camera"); + rendererWidget->setLightFollowCamera(!rendererWidget->getLightFollowCamera()); + rendererWidget->refresh(); + } break; @@ -1164,10 +1166,11 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { refresh(this); } - else if (e->modifiers() == Qt::NoModifier) { - // addWhatsThisItem("S", "Take a screenshot"); - screenshot(); - } + else + if (e->modifiers() == Qt::NoModifier) { + // addWhatsThisItem("S", "Take a screenshot"); + screenshot(); + } break; @@ -1383,31 +1386,35 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { found = true; debugStream << "\t- Surface Actor" << endl; } - else if (c->getActor(InterfaceGeometry::Wireframe) == p) { - found = true; - debugStream << "\t- Wireframe Actor" << endl; - } - else if (c->getActor(InterfaceGeometry::Points) == p) { - found = true; - debugStream << "\t- Points Actor" << endl; - } + else + if (c->getActor(InterfaceGeometry::Wireframe) == p) { + found = true; + debugStream << "\t- Wireframe Actor" << endl; + } + else + if (c->getActor(InterfaceGeometry::Points) == p) { + found = true; + debugStream << "\t- Points Actor" << endl; + } break; case SLICE_VIEWER: if (c->getPixelActor() == p) { found = true; debugStream << "\t- Pixel Actor" << endl; } - else if (c->get2DImageActor() == p) { - found = true; - debugStream << "\t- 2D Image Actor" << endl; - } - else if (c->getPickPlaneActor() == p) { - found = true; - debugStream << "\t- Picked Plane Actor" << endl; - /* } else if (c->get2DAxesActor() == p) { - found = true; - debugStream << "\t- 2D Axes Actor" << endl; */ - } + else + if (c->get2DImageActor() == p) { + found = true; + debugStream << "\t- 2D Image Actor" << endl; + } + else + if (c->getPickPlaneActor() == p) { + found = true; + debugStream << "\t- Picked Plane Actor" << endl; + /* } else if (c->get2DAxesActor() == p) { + found = true; + debugStream << "\t- 2D Axes Actor" << endl; */ + } break; default: @@ -1957,20 +1964,21 @@ void InteractiveViewer::highlightModeChanged(QAction* selectedAction) { if (selectedAction == highlightSelectionAction) { propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::SELECTION); } - else if (selectedAction == highlightSelectionOnlyAction) { - propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::SELECTION_ONLY); - } else - - /* - if (selectedAction == highlightModeXtraHotAction) { - highlightMode = InteractiveViewer::XTRA_HOT; + if (selectedAction == highlightSelectionOnlyAction) { + propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::SELECTION_ONLY); } else - */ - if (selectedAction == highlightOffAction) { - propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::OFF); - } + + /* + if (selectedAction == highlightModeXtraHotAction) { + highlightMode = InteractiveViewer::XTRA_HOT; + } + else + */ + if (selectedAction == highlightOffAction) { + propertyObject->setProperty(highlightModeProperty->getName().toStdString().c_str(), InteractiveViewer::OFF); + } refresh(this); } @@ -1982,16 +1990,18 @@ void InteractiveViewer::cameraOrientationChanged(QAction* selectedAction) { resetCamera(); rendererWidget->refresh(); } - else if (selectedAction == cameraOrientationLeftUpAction) { - rendererWidget->setCameraOrientation(RendererWidget::LEFT_UP); - resetCamera(); - rendererWidget->refresh(); - } - else if (selectedAction == cameraOrientationRightUpAction) { - rendererWidget->setCameraOrientation(RendererWidget::RIGHT_UP); - resetCamera(); - rendererWidget->refresh(); - } + else + if (selectedAction == cameraOrientationLeftUpAction) { + rendererWidget->setCameraOrientation(RendererWidget::LEFT_UP); + resetCamera(); + rendererWidget->refresh(); + } + else + if (selectedAction == cameraOrientationRightUpAction) { + rendererWidget->setCameraOrientation(RendererWidget::RIGHT_UP); + resetCamera(); + rendererWidget->refresh(); + } QSettings& settings = Application::getSettings(); settings.beginGroup(Application::getName() + ".InteractiveViewer." + objectName().simplified().replace(" ", "")); @@ -2088,15 +2098,18 @@ void InteractiveViewer::pickingModeChanged(QAction* selectedAction) { if (selectedAction == pickCellAction) { initPicking(CELL_PICKING); } - else if (selectedAction == pickPointAction) { - initPicking(POINT_PICKING); - } - else if (selectedAction == pickCellRegionAction) { - initPicking(AREA_CELL_PICKING); - } - else if (selectedAction == pickPointRegionAction) { - initPicking(AREA_POINT_PICKING); - } + else + if (selectedAction == pickPointAction) { + initPicking(POINT_PICKING); + } + else + if (selectedAction == pickCellRegionAction) { + initPicking(AREA_CELL_PICKING); + } + else + if (selectedAction == pickPointRegionAction) { + initPicking(AREA_POINT_PICKING); + } } //-------------------- picked --------------------- diff --git a/sdk/libraries/core/viewer/InteractiveViewer.h b/sdk/libraries/core/viewer/InteractiveViewer.h index 2e6211414c22af0f375bc02499f155666bfe4075..7672e758a814ea731e9e905fc48429ece385e972 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/InteractiveViewer.h @@ -436,7 +436,7 @@ protected: QMenu* viewerMenu; /// the QToolBar for the InteractiveViewer - QToolBar* viewerToolBar; + QToolBar* viewerToolbar; /// the ComboBox for mesh scalar data QComboBox* scalarDataComboBox; diff --git a/sdk/libraries/core/viewer/MedicalImageViewer.cpp b/sdk/libraries/core/viewer/MedicalImageViewer.cpp index 2b77687046c3db674b125f890942ef694f0dfdb6..42a9fe1e1e1d8a06c21ae9eaa5c4d36deb779f67 100644 --- a/sdk/libraries/core/viewer/MedicalImageViewer.cpp +++ b/sdk/libraries/core/viewer/MedicalImageViewer.cpp @@ -135,25 +135,13 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) { viewers.insert(VIEWER_CORONAL, InteractiveViewer::getCoronalViewer()); viewers.insert(VIEWER_SAGITTAL, InteractiveViewer::getSagittalViewer()); - //-- add the InteractiveViewers -// topLeftLayout = new QVBoxLayout(); -// frameLayout->addLayout(topLeftLayout, 0, 0); -// topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame)); // north-west -// topLeftLayout->addWidget(InteractiveViewer::getArbitraryViewer()->getWidget(frame)); // north-west -// frameLayout->addWidget(InteractiveViewer::getCoronalViewer()->getWidget(frame), 0, 1); // north-east -// frameLayout->addWidget(InteractiveViewer::getSagittalViewer()->getWidget(frame), 1, 0); // south-west -// frameLayout->addWidget(InteractiveViewer::get3DViewer()->getWidget(frame), 1, 1); // south-east - topLeftLayout = new QVBoxLayout(); frameLayout->addLayout(topLeftLayout, 0, 0); - topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame)); -// frameLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame), 0, 0); // north-west + topLeftLayout->addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame)); // equivalent of addWidget(InteractiveViewer::getAxialViewer()->getWidget(frame), 0, 0) = north-west frameLayout->addWidget(InteractiveViewer::getCoronalViewer()->getWidget(frame), 1, 0); // north-east frameLayout->addWidget(InteractiveViewer::getSagittalViewer()->getWidget(frame), 1, 1); // south-west frameLayout->addWidget(InteractiveViewer::get3DViewer()->getWidget(frame), 0, 1); // south-east - - //-- connect foreach (LayoutVisibility v, viewerVisibility) { if (viewers.value(v)) { // prevent ALL @@ -247,8 +235,13 @@ void MedicalImageViewer::updateLayout() { viewers.value(visibleLayout)->getWidget(frame)->show(); } - if (autoUpdateToolbarVisibility && (visibleLayout == VIEWER_3D || visibleLayout == VIEWER_ALL)) { - getToolBar()->show(); + if (autoUpdateToolbarVisibility) { + if (visibleLayout == VIEWER_3D || visibleLayout == VIEWER_ALL) { + setToolBarVisibility(true); + } + else { + setToolBarVisibility(false); + } } } @@ -268,12 +261,9 @@ void MedicalImageViewer::synchronizeSelection() { } // -------------------- setToolbarAutoVisibility -------------------- -void MedicalImageViewer::setToolbarAutoVisibility(bool toolbarVisibility) { - autoUpdateToolbarVisibility = toolbarVisibility; - getToolBar()->setVisible(autoUpdateToolbarVisibility); - if (!autoUpdateToolbarVisibility) { - getToolBar()->close(); - } +void MedicalImageViewer::setToolbarAutoVisibility(bool toolbarAutoVisibility) { + autoUpdateToolbarVisibility = toolbarAutoVisibility; + setToolBarVisibility(false); } } diff --git a/sdk/libraries/core/viewer/RendererWidget.cpp b/sdk/libraries/core/viewer/RendererWidget.cpp index 25cdbe41c47a5503d06080768aa66c17ac1e8bc3..1f1ba75b820ef14e6af56ff54409fe6679aae298 100644 --- a/sdk/libraries/core/viewer/RendererWidget.cpp +++ b/sdk/libraries/core/viewer/RendererWidget.cpp @@ -1399,16 +1399,16 @@ void RendererWidget::resetCameraSettings() { switch (cameraOrientation) { case LEFT_UP: // default position - cam->SetPosition(0, 0, -1); - cam->SetFocalPoint(0, 0, 0); - cam->SetViewUp(0, 1, 0); + cam->SetPosition(0.0, 0.0, -1.0); + cam->SetFocalPoint(0.0, 0.0, 0.0); + cam->SetViewUp(0.0, 1.0, 0.0); cam->OrthogonalizeViewUp(); break; case RIGHT_DOWN: // default position - cam->SetPosition(0, 0, -1); - cam->SetFocalPoint(0, 0, 0); - cam->SetViewUp(0, -1, 0); + cam->SetPosition(0.0, 0.0, -1.0); + cam->SetFocalPoint(0.0, 0.0, 0.0); + cam->SetViewUp(0.0, -1.0, 0.0); cam->OrthogonalizeViewUp(); break; // For Coronal view of Coronal Viewer @@ -1427,9 +1427,9 @@ void RendererWidget::resetCameraSettings() { break; case RIGHT_UP: default: - cam->SetPosition(0, 0, 1); - cam->SetFocalPoint(0, 0, 0); - cam->SetViewUp(0, 1, 0); + cam->SetPosition(0.0, 0.0, 1.0); + cam->SetFocalPoint(0.0, 0.0, 0.0); + cam->SetViewUp(0.0, 1.0, 0.0); cam->OrthogonalizeViewUp(); break; } diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index ef44e0f09c45204b1466082a93275b0fd7849cc9..6f8714df74603edd2efda0d13000f9720e3d8366 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -32,6 +32,7 @@ namespace camitk { //---------------------- constructor ------------------------ Viewer::Viewer(QString name): QObject() { setObjectName(name); + toolbarVisibility = true; } //---------------------- selectionChanged ------------------------ @@ -54,5 +55,14 @@ void Viewer::clearSelection() { emit selectionChanged(); } +//---------------------- setToolBarVisibility ------------------------ +void Viewer::setToolBarVisibility(bool toolbarVisibility) { + this->toolbarVisibility = toolbarVisibility; +} + +//---------------------- getToolBarVisibility ------------------------ +bool Viewer::getToolBarVisibility() { + return toolbarVisibility; +} } diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index 9d68720e895803d0a4b637435580986c94a28b69..d32c10f7555789438a7c0755521b5b305fdf73b9 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -86,6 +86,14 @@ public: return nullptr; }; + /** set the visibility of the toolbar in the main window (true by default). + * If the visibility is set to false, the next call to setCentralViewer(..) or addDockViwer(...) will remove it + */ + void setToolBarVisibility(bool); + + /// get the current value of the toolbar visibility + bool getToolBarVisibility(); + /// Update the whole tree of the representation of the Component. /// Is actually useful (and defined) in Explorer. virtual void refreshInterfaceNode(Component* comp) {}; @@ -109,6 +117,9 @@ protected: /// clear the selection void clearSelection(); +private: + /// the current toolbar visibility + bool toolbarVisibility; }; } diff --git a/tutorials/actions/bitmapviewer/BitmapViewer.cpp b/tutorials/actions/bitmapviewer/BitmapViewer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0000490ce94f7acaa63a8befce1bb07eb0e7cd5c --- /dev/null +++ b/tutorials/actions/bitmapviewer/BitmapViewer.cpp @@ -0,0 +1,119 @@ +/***************************************************************************** +* $CAMITK_LICENCE_BEGIN$ +* +* CamiTK - Computer Assisted Medical Intervention ToolKit +* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO) +* +* Visit http://camitk.imag.fr for more information +* +* This file is part of CamiTK. +* +* CamiTK is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* CamiTK is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with CamiTK. If not, see . +* +* $CAMITK_LICENCE_END$ +****************************************************************************/ + +#include "BitmapViewer.h" + +#include +#include +#include +#include + +#include + +#include // to change the camera projection to parallel + +using namespace camitk; + +// initialize static variables +QString BitmapViewer::BitmapViewerName = "2D Bitmap Viewer"; // required due to QString ref needed by InteractiveViewer cstr +BitmapViewer* BitmapViewer::singleton = nullptr; + +BitmapViewer* BitmapViewer::getInstance() { + if (!singleton) { + singleton = new BitmapViewer(); + } + + return singleton; +} + + +// -------------------- Constructor -------------------- +BitmapViewer::BitmapViewer() : InteractiveViewer(BitmapViewerName, InteractiveViewer::SLICE_VIEWER) { + // 2D images need x right, y up, z front + getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_UP); + // no decoration and grey background + getRendererWidget()->toggleOrientationDecorations(false); + getRendererWidget()->setGradientBackground(false); + getRendererWidget()->setBackgroundColor(0.8, 0.8, 0.8); + // parallel projection + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + + myToolbar = nullptr; +} + +// -------------------- Destructor -------------------- +BitmapViewer::~BitmapViewer() { +} + +// -------------------- refresh -------------------- +void BitmapViewer::refresh(Viewer* whoIsAsking) { + updateVisibility(); + InteractiveViewer::refresh(); +} + +// -------------------- getWidget -------------------- +QWidget* BitmapViewer::getWidget(QWidget* parent) { + QWidget* myWidget = InteractiveViewer::getWidget(parent); + // hide slice slider + sideFrame->hide(); + updateVisibility(); + return myWidget; +} + +// -------------------- getToolBar -------------------- +QToolBar* BitmapViewer::getToolBar() { + if (myToolbar == nullptr) { + // create the toolbar and add the action to it + myToolbar = new QToolBar(objectName() + " Toolbar"); + // ensure object name is set for saving the state + myToolbar->setObjectName(objectName() + " Toolbar"); + + myToolbar->addAction(screenshotAction); + + // create the action to switch back to the medical image viewer + QAction* hideViewerAction = myToolbar->addAction(tr("Hide Bitmap Viewer")); + hideViewerAction->setIcon(QPixmap(":/fileClose")); + hideViewerAction->setStatusTip(tr("Switch back to the medical image viewer")); + hideViewerAction->setWhatsThis(tr("Switch back the ventral viewer to normal (i.e., show the Medical Image Viewer)")); + connect(hideViewerAction, &QAction::triggered, [=](bool) { + Application::getMainWindow()->setCentralViewer(MedicalImageViewer::getInstance()); + }); + } + return myToolbar; +} + + +// -------------------- updateVisibility -------------------- +void BitmapViewer::updateVisibility() { + // as the default component does not know anything about my2DBitmapViewer, + // tell all the components that are already visible in the axial slices to be also + // visible in my2DBitmapViewer + for (Component* comp : Application::getAllComponents()) { + if (comp->getVisibility(InteractiveViewer::getAxialViewer())) { + comp->setVisibility(this, true); + } + } +} + diff --git a/tutorials/actions/bitmapviewer/BitmapViewer.h b/tutorials/actions/bitmapviewer/BitmapViewer.h new file mode 100644 index 0000000000000000000000000000000000000000..b7cb7a59acce80b907c377f625f6010030ccbd2f --- /dev/null +++ b/tutorials/actions/bitmapviewer/BitmapViewer.h @@ -0,0 +1,72 @@ +/***************************************************************************** +* $CAMITK_LICENCE_BEGIN$ +* +* CamiTK - Computer Assisted Medical Intervention ToolKit +* (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO) +* +* Visit http://camitk.imag.fr for more information +* +* This file is part of CamiTK. +* +* CamiTK is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* CamiTK is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with CamiTK. If not, see . +* +* $CAMITK_LICENCE_END$ +****************************************************************************/ + + +#ifndef BITMAPVIEWER_H +#define BITMAPVIEWER_H + +#include + +class QToolBar; + +/** +* @brief +* InteractiveViewer specialized in 2D bitmap (images in jpeg, png...) +*/ +class BitmapViewer : public camitk::InteractiveViewer { + Q_OBJECT + +public: + + static BitmapViewer* getInstance(); + + virtual ~BitmapViewer() override; + + void refresh(camitk::Viewer* whoIsAsking = nullptr) override; + + QWidget* getWidget(QWidget* parent = nullptr) override; + + QToolBar* getToolBar() override; + +protected: + + BitmapViewer(); + +private: + + static BitmapViewer* singleton; + + static QString BitmapViewerName; + + QToolBar* myToolbar; + + // set visibility of all possible component (that is component that can be displayed in 2D) + void updateVisibility(); + +}; + + +#endif // BITMAPVIEWER_H + diff --git a/tutorials/actions/bitmapviewer/CMakeLists.txt b/tutorials/actions/bitmapviewer/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9cc3535dcf7afae05c4b361e09cf6302b159b3d9 --- /dev/null +++ b/tutorials/actions/bitmapviewer/CMakeLists.txt @@ -0,0 +1 @@ +camitk_extension(ACTION_EXTENSION) diff --git a/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp b/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9d92d29cba8b2c8647c46a086269eecc3cdda3a4 --- /dev/null +++ b/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp @@ -0,0 +1,68 @@ +/***************************************************************************** + * $CAMITK_LICENCE_BEGIN$ + * + * CamiTK - Computer Assisted Medical Intervention ToolKit + * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO) + * + * Visit http://camitk.imag.fr for more information + * + * This file is part of CamiTK. + * + * CamiTK is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * CamiTK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with CamiTK. If not, see . + * + * $CAMITK_LICENCE_END$ + ****************************************************************************/ + +#include "ShowBitmapViewer.h" +#include "BitmapViewer.h" + +#include +#include +#include + +#include +#include + +using namespace camitk; + +// -------------------- ShowBitmapViewer -------------------- +ShowBitmapViewer::ShowBitmapViewer(ActionExtension* extension) : Action(extension) { + setName("Show Bitmap Viewer"); + setEmbedded(false); // not embedded (and as the + setDescription("Tutorial action that set the bitmap viewer as the central viewer. Trigger this action when no component is selected"); + setComponent(""); + + setFamily("Tutorial"); + addTag("Viewer"); + addTag("BitmapViewer"); + addTag("MainWindow"); + + firstCall = true; +} + +// --------------- getWidget ------------------- +QWidget* ShowBitmapViewer::getWidget() { + return nullptr; +} + +// --------------- apply ------------------- +Action::ApplyStatus ShowBitmapViewer::apply() { + // just add the BitMap viewer in the central viewer + Application::getMainWindow()->setCentralViewer(BitmapViewer::getInstance()); + Application::refresh(); + if (firstCall) { + CAMITK_INFO("TIP: switch central wiewers from the menu: do you know that you can use the \"View Menu\" item \"Toggle Central Viewers\" to switch the central viewer from/to the Medical Image Viewer"); + firstCall = false; + } + return SUCCESS; +} diff --git a/tutorials/actions/bitmapviewer/ShowBitmapViewer.h b/tutorials/actions/bitmapviewer/ShowBitmapViewer.h new file mode 100644 index 0000000000000000000000000000000000000000..fc56562e4afc031ce027c4d3303c2da848702723 --- /dev/null +++ b/tutorials/actions/bitmapviewer/ShowBitmapViewer.h @@ -0,0 +1,58 @@ +/***************************************************************************** + * $CAMITK_LICENCE_BEGIN$ + * + * CamiTK - Computer Assisted Medical Intervention ToolKit + * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO) + * + * Visit http://camitk.imag.fr for more information + * + * This file is part of CamiTK. + * + * CamiTK is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * CamiTK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with CamiTK. If not, see . + * + * $CAMITK_LICENCE_END$ + ****************************************************************************/ + +#ifndef SHOW_BITMAP_VIEWER_H +#define SHOW_BITMAP_VIEWER_H + +#include + +namespace camitk { +class InteractiveViewer; +class Viewer; +} + +/** + * Demonstrates how to switch the central image viewer. + */ +class ShowBitmapViewer : public camitk::Action { + +public: + /// the constructor + ShowBitmapViewer(camitk::ActionExtension*); + + /// the destructor + virtual ~ShowBitmapViewer() = default; + + /// method called when the action when the action is triggered (i.e. started) + virtual QWidget* getWidget(); + +public slots: + /// method called when the action is applied + virtual ApplyStatus apply(); + + bool firstCall; +}; + +#endif // SHOW_BITMAP_VIEWER_H diff --git a/tutorials/actions/bitmapviewer/ShowBitmapViewerExtension.cpp b/tutorials/actions/bitmapviewer/ShowBitmapViewerExtension.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec10627b34786a3568a663fabdc22b7ef442bc8d --- /dev/null +++ b/tutorials/actions/bitmapviewer/ShowBitmapViewerExtension.cpp @@ -0,0 +1,32 @@ +/***************************************************************************** + * $CAMITK_LICENCE_BEGIN$ + * + * CamiTK - Computer Assisted Medical Intervention ToolKit + * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO) + * + * Visit http://camitk.imag.fr for more information + * + * This file is part of CamiTK. + * + * CamiTK is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * CamiTK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with CamiTK. If not, see . + * + * $CAMITK_LICENCE_END$ + ****************************************************************************/ +#include "ShowBitmapViewerExtension.h" +#include "ShowBitmapViewer.h" + +// -------------------- init -------------------- +void ShowBitmapViewerExtension::init() { + registerNewAction(ShowBitmapViewer); +} + diff --git a/tutorials/actions/bitmapviewer/ShowBitmapViewerExtension.h b/tutorials/actions/bitmapviewer/ShowBitmapViewerExtension.h new file mode 100644 index 0000000000000000000000000000000000000000..24800fd820796ee1cbcee1e463d8bfc2b87eb4cb --- /dev/null +++ b/tutorials/actions/bitmapviewer/ShowBitmapViewerExtension.h @@ -0,0 +1,62 @@ +/***************************************************************************** + * $CAMITK_LICENCE_BEGIN$ + * + * CamiTK - Computer Assisted Medical Intervention ToolKit + * (c) 2001-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO) + * + * Visit http://camitk.imag.fr for more information + * + * This file is part of CamiTK. + * + * CamiTK is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * CamiTK is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with CamiTK. If not, see . + * + * $CAMITK_LICENCE_END$ + ****************************************************************************/ + + +#ifndef SHOW_BITMAP_VIEWER_EXTENSION_H +#define SHOW_BITMAP_VIEWER_EXTENSION_H + +#include +#include +#include + +/// shows the bitmap viewer in the central viewer +class ShowBitmapViewerExtension : public camitk::ActionExtension { + Q_OBJECT + Q_INTERFACES(camitk::ActionExtension) + Q_PLUGIN_METADATA(IID "fr.imag.camitk.tutorials.action.showbitmapviewer") + +public: + /// the constructor + ShowBitmapViewerExtension() : ActionExtension() {}; + + /// the destructor + virtual ~ShowBitmapViewerExtension() = default; + + /// initialize all the actions + virtual void init(); + + /// Method that return the action extension name + virtual QString getName() { + return "Show Bitmap Viewer"; + }; + + /// Method that return the action extension descrption + virtual QString getDescription() { + return "This extension contains a simple 2D bitmap viewer and a simple action to show this bitmap viewer in the central viewer."; + }; + +}; + +#endif // SHOW_BITMAP_VIEWER_EXTENSION_H