From 6ada5e783bb5d0b085b0002577c3da68ef2684b0 Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Fri, 29 Nov 2019 15:15:03 +0100 Subject: [PATCH 01/26] Add extension for each viewer --- .../config/testing/config-test.sh | 14 +++- sdk/libraries/core/CMakeLists.txt | 6 ++ .../core/viewer/{ => action}/ActionViewer.cpp | 0 .../core/viewer/{ => action}/ActionViewer.h | 2 + .../viewer/action/ActionViewerExtension.cpp | 40 +++++++++++ .../viewer/action/ActionViewerExtension.h | 66 +++++++++++++++++++ .../core/viewer/action/CMakeLists.txt | 8 +++ .../core/viewer/{ => explorer}/Explorer.cpp | 0 .../core/viewer/{ => explorer}/Explorer.h | 0 .../viewer/explorer/ExplorerExtension.cpp | 40 +++++++++++ .../core/viewer/explorer/ExplorerExtension.h | 65 ++++++++++++++++++ .../{ => frameexplorer}/FrameExplorer.cpp | 0 .../{ => frameexplorer}/FrameExplorer.h | 0 .../frameexplorer/FrameExplorerExtension.cpp | 40 +++++++++++ .../frameexplorer/FrameExplorerExtension.h | 65 ++++++++++++++++++ .../{ => interactive}/InteractiveViewer.cpp | 0 .../{ => interactive}/InteractiveViewer.h | 0 .../InteractiveViewerExtension.cpp | 40 +++++++++++ .../interactive/InteractiveViewerExtension.h | 65 ++++++++++++++++++ .../{ => interactive}/RendererWidget.cpp | 0 .../viewer/{ => interactive}/RendererWidget.h | 0 .../vtkInteractorStylePick.cpp | 0 .../vtkInteractorStylePick.h | 0 .../{ => medicalimage}/MedicalImageViewer.cpp | 0 .../{ => medicalimage}/MedicalImageViewer.h | 0 .../MedicalImageViewerExtension.cpp | 40 +++++++++++ .../MedicalImageViewerExtension.h | 65 ++++++++++++++++++ .../PropertyExplorer.cpp | 0 .../{ => propertyexplorer}/PropertyExplorer.h | 0 .../PropertyExplorerExtension.cpp | 40 +++++++++++ .../PropertyExplorerExtension.h | 65 ++++++++++++++++++ 31 files changed, 660 insertions(+), 1 deletion(-) rename sdk/libraries/core/viewer/{ => action}/ActionViewer.cpp (100%) rename sdk/libraries/core/viewer/{ => action}/ActionViewer.h (99%) create mode 100644 sdk/libraries/core/viewer/action/ActionViewerExtension.cpp create mode 100644 sdk/libraries/core/viewer/action/ActionViewerExtension.h create mode 100644 sdk/libraries/core/viewer/action/CMakeLists.txt rename sdk/libraries/core/viewer/{ => explorer}/Explorer.cpp (100%) rename sdk/libraries/core/viewer/{ => explorer}/Explorer.h (100%) create mode 100644 sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp create mode 100644 sdk/libraries/core/viewer/explorer/ExplorerExtension.h rename sdk/libraries/core/viewer/{ => frameexplorer}/FrameExplorer.cpp (100%) rename sdk/libraries/core/viewer/{ => frameexplorer}/FrameExplorer.h (100%) create mode 100644 sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp create mode 100644 sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h rename sdk/libraries/core/viewer/{ => interactive}/InteractiveViewer.cpp (100%) rename sdk/libraries/core/viewer/{ => interactive}/InteractiveViewer.h (100%) create mode 100644 sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp create mode 100644 sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h rename sdk/libraries/core/viewer/{ => interactive}/RendererWidget.cpp (100%) rename sdk/libraries/core/viewer/{ => interactive}/RendererWidget.h (100%) rename sdk/libraries/core/viewer/{ => interactive}/vtkInteractorStylePick.cpp (100%) rename sdk/libraries/core/viewer/{ => interactive}/vtkInteractorStylePick.h (100%) rename sdk/libraries/core/viewer/{ => medicalimage}/MedicalImageViewer.cpp (100%) rename sdk/libraries/core/viewer/{ => medicalimage}/MedicalImageViewer.h (100%) create mode 100644 sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp create mode 100644 sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h rename sdk/libraries/core/viewer/{ => propertyexplorer}/PropertyExplorer.cpp (100%) rename sdk/libraries/core/viewer/{ => propertyexplorer}/PropertyExplorer.h (100%) create mode 100644 sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp create mode 100644 sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h diff --git a/sdk/applications/config/testing/config-test.sh b/sdk/applications/config/testing/config-test.sh index 5e3fae46..0cf72848 100644 --- a/sdk/applications/config/testing/config-test.sh +++ b/sdk/applications/config/testing/config-test.sh @@ -22,11 +22,13 @@ set -e # values to check initTestData() { # fill test data - extensionCount=( [4.2]=43 [4.1]=41 [4.0]=31 ) + extensionCount=( [4.2]=44 [4.1]=41 [4.0]=31 ) componentExtensionCount=( [4.2]=14 [4.1]=14 [4.0]=14 ) actionExtensionCount=( [4.2]=29 [4.1]=27 [4.0]=27 ) + viewerExtensionCount=( [4.2]=1 [4.1]=0 [4.0]=0 ) fileExtensionCount=( [4.2]=37 [4.1]=37 [4.0]=37 ) actionCount=( [4.2]=107 [4.1]=105 [4.0]=105 ) + viewerCount=( [4.2]=1 [4.1]=0 [4.0]=0 ) # fill release date releaseDate=( [4.2]="not yet released, current development version" \ @@ -48,8 +50,10 @@ declareTestData() { declare -Ag extensionCount declare -Ag componentExtensionCount declare -Ag actionExtensionCount + declare -Ag viewerExtensionCount declare -Ag fileExtensionCount declare -Ag actionCount + declare -Ag viewerCount declare -Ag releaseDate } @@ -175,12 +179,18 @@ getExpectedValue() { "Number of Action Extensions") echo ${actionExtensionCount[$shortVersion]} ;; + "Number of Viewer Extensions") + echo ${viewerExtensionCount[$shortVersion]} + ;; "Number of File Extensions Supported") echo ${fileExtensionCount[$shortVersion]} ;; "Number of Actions") echo ${actionCount[$shortVersion]} ;; + "Number of Viewers") + echo ${viewerCount[$shortVersion]} + ;; esac } @@ -284,7 +294,9 @@ else fi checkValue "Number of Component Extensions" checkValue "Number of Action Extensions" +checkValue "Number of Viewer Extensions" checkValue "Number of File Extensions Supported" checkValue "Number of Actions" +checkValue "Number of Viewers" exit $exitStatus diff --git a/sdk/libraries/core/CMakeLists.txt b/sdk/libraries/core/CMakeLists.txt index 9a3e7002..d9b9cdb0 100644 --- a/sdk/libraries/core/CMakeLists.txt +++ b/sdk/libraries/core/CMakeLists.txt @@ -19,6 +19,12 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/operators ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/viewer + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/action + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/explorer + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/frameexplorer + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/interactive + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/medicalimage + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/propertyexplorer ${CAMITK_INCLUDE_DIRECTORIES} ) diff --git a/sdk/libraries/core/viewer/ActionViewer.cpp b/sdk/libraries/core/viewer/action/ActionViewer.cpp similarity index 100% rename from sdk/libraries/core/viewer/ActionViewer.cpp rename to sdk/libraries/core/viewer/action/ActionViewer.cpp diff --git a/sdk/libraries/core/viewer/ActionViewer.h b/sdk/libraries/core/viewer/action/ActionViewer.h similarity index 99% rename from sdk/libraries/core/viewer/ActionViewer.h rename to sdk/libraries/core/viewer/action/ActionViewer.h index 24f42d47..8e64c825 100644 --- a/sdk/libraries/core/viewer/ActionViewer.h +++ b/sdk/libraries/core/viewer/action/ActionViewer.h @@ -26,6 +26,8 @@ #ifndef ACTIONVIEWER_H #define ACTIONVIEWER_H +#include "CamiTKAPI.h" + #include #include #include diff --git a/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp b/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp new file mode 100644 index 00000000..40749448 --- /dev/null +++ b/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * $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 "ActionViewerExtension.h" + +// include generated actions headers +#include "ActionViewer.h" + +namespace camitk { + +// --------------- getViewers ------------------- +void ActionViewerExtension::init() { + registerNewViewer(ActionViewer); +} + +} + diff --git a/sdk/libraries/core/viewer/action/ActionViewerExtension.h b/sdk/libraries/core/viewer/action/ActionViewerExtension.h new file mode 100644 index 00000000..3b3ac056 --- /dev/null +++ b/sdk/libraries/core/viewer/action/ActionViewerExtension.h @@ -0,0 +1,66 @@ +/***************************************************************************** + * $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 ACTIONVIEWEREXTENSION_H +#define ACTIONVIEWEREXTENSION_H + +#include "CamiTKAPI.h" + +#include "ViewerExtension.h" + +namespace camitk { + +class CAMITK_API ActionViewerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionviewerextension.viewer.actionviewerextension") + +public: + /// Constructor + ActionViewerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~ActionViewerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Action Viewer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the viewer that display GUI action"; + }; + + /// initialize all the actions + virtual void init(); + +}; +} + +#endif // ACTIONVIEWEREXTENSION_H + + diff --git a/sdk/libraries/core/viewer/action/CMakeLists.txt b/sdk/libraries/core/viewer/action/CMakeLists.txt new file mode 100644 index 00000000..e94d62df --- /dev/null +++ b/sdk/libraries/core/viewer/action/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + DEFAULT + DEFINES COMPILE_ACTION_VIEWER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/libraries/core/viewer/Explorer.cpp b/sdk/libraries/core/viewer/explorer/Explorer.cpp similarity index 100% rename from sdk/libraries/core/viewer/Explorer.cpp rename to sdk/libraries/core/viewer/explorer/Explorer.cpp diff --git a/sdk/libraries/core/viewer/Explorer.h b/sdk/libraries/core/viewer/explorer/Explorer.h similarity index 100% rename from sdk/libraries/core/viewer/Explorer.h rename to sdk/libraries/core/viewer/explorer/Explorer.h diff --git a/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp b/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp new file mode 100644 index 00000000..919a196d --- /dev/null +++ b/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * $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 "ExplorerExtension.h" + +// include generated actions headers +#include "Explorer.h" + +namespace camitk { + +// --------------- getViewers ------------------- +void ExplorerExtension::init() { + registerNewViewer(Explorer); +} + +} + diff --git a/sdk/libraries/core/viewer/explorer/ExplorerExtension.h b/sdk/libraries/core/viewer/explorer/ExplorerExtension.h new file mode 100644 index 00000000..e4f394f8 --- /dev/null +++ b/sdk/libraries/core/viewer/explorer/ExplorerExtension.h @@ -0,0 +1,65 @@ +/***************************************************************************** + * $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 EXPLOREREXTENSION_H +#define EXPLOREREXTENSION_H + +#include "CamiTKAPI.h" + +#include "ViewerExtension.h" + +namespace camitk { + +class CAMITK_API ExplorerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + +public: + /// Constructor + ExplorerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~ExplorerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Explorer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the explorer"; + }; + + /// initialize all the actions + virtual void init(); + +}; +} + +#endif // EXPLOREREXTENSION_H + + diff --git a/sdk/libraries/core/viewer/FrameExplorer.cpp b/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp similarity index 100% rename from sdk/libraries/core/viewer/FrameExplorer.cpp rename to sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp diff --git a/sdk/libraries/core/viewer/FrameExplorer.h b/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h similarity index 100% rename from sdk/libraries/core/viewer/FrameExplorer.h rename to sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp b/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp new file mode 100644 index 00000000..8aa53372 --- /dev/null +++ b/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * $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 "FrameExplorerExtension.h" + +// include generated actions headers +#include "FrameExplorer.h" + +namespace camitk { + +// --------------- getViewers ------------------- +void FrameExplorerExtension::init() { + registerNewViewer(FrameExplorer); +} + +} + diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h b/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h new file mode 100644 index 00000000..cde71abb --- /dev/null +++ b/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h @@ -0,0 +1,65 @@ +/***************************************************************************** + * $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 FRAMEEXPLOREREXTENSION_H +#define FRAMEEXPLOREREXTENSION_H + +#include "CamiTKAPI.h" + +#include "ViewerExtension.h" + +namespace camitk { + +class CAMITK_API FrameExplorerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + +public: + /// Constructor + FrameExplorerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~FrameExplorerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Frame Explorer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the frame explorer"; + }; + + /// initialize all the actions + virtual void init(); + +}; +} + +#endif // FRAMEEXPLOREREXTENSION_H + + diff --git a/sdk/libraries/core/viewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp similarity index 100% rename from sdk/libraries/core/viewer/InteractiveViewer.cpp rename to sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp diff --git a/sdk/libraries/core/viewer/InteractiveViewer.h b/sdk/libraries/core/viewer/interactive/InteractiveViewer.h similarity index 100% rename from sdk/libraries/core/viewer/InteractiveViewer.h rename to sdk/libraries/core/viewer/interactive/InteractiveViewer.h diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp b/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp new file mode 100644 index 00000000..422e08d7 --- /dev/null +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * $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 "InteractiveViewerExtension.h" + +// include generated actions headers +#include "InteractiveViewer.h" + +namespace camitk { + +// --------------- getViewers ------------------- +void InteractiveViewerExtension::init() { + registerNewViewer(InteractiveViewer); +} + +} + diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h b/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h new file mode 100644 index 00000000..83375d3a --- /dev/null +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h @@ -0,0 +1,65 @@ +/***************************************************************************** + * $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 INTERACTIVEVIEWEREXTENSION_H +#define INTERACTIVEVIEWEREXTENSION_H + +#include "CamiTKAPI.h" + +#include "ViewerExtension.h" + +namespace camitk { + +class CAMITK_API InteractiveViewerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + +public: + /// Constructor + InteractiveViewerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~InteractiveViewerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Interactive Viewer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the interactive viewer"; + }; + + /// initialize all the actions + virtual void init(); + +}; +} + +#endif // INTERACTIVEVIEWEREXTENSION_H + + diff --git a/sdk/libraries/core/viewer/RendererWidget.cpp b/sdk/libraries/core/viewer/interactive/RendererWidget.cpp similarity index 100% rename from sdk/libraries/core/viewer/RendererWidget.cpp rename to sdk/libraries/core/viewer/interactive/RendererWidget.cpp diff --git a/sdk/libraries/core/viewer/RendererWidget.h b/sdk/libraries/core/viewer/interactive/RendererWidget.h similarity index 100% rename from sdk/libraries/core/viewer/RendererWidget.h rename to sdk/libraries/core/viewer/interactive/RendererWidget.h diff --git a/sdk/libraries/core/viewer/vtkInteractorStylePick.cpp b/sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.cpp similarity index 100% rename from sdk/libraries/core/viewer/vtkInteractorStylePick.cpp rename to sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.cpp diff --git a/sdk/libraries/core/viewer/vtkInteractorStylePick.h b/sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.h similarity index 100% rename from sdk/libraries/core/viewer/vtkInteractorStylePick.h rename to sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.h diff --git a/sdk/libraries/core/viewer/MedicalImageViewer.cpp b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp similarity index 100% rename from sdk/libraries/core/viewer/MedicalImageViewer.cpp rename to sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp diff --git a/sdk/libraries/core/viewer/MedicalImageViewer.h b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h similarity index 100% rename from sdk/libraries/core/viewer/MedicalImageViewer.h rename to sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp new file mode 100644 index 00000000..1eaec53f --- /dev/null +++ b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * $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 "MedicalImageViewerExtension.h" + +// include generated actions headers +#include "MedicalImageViewer.h" + +namespace camitk { + +// --------------- getViewers ------------------- +void MedicalImageViewerExtension::init() { + registerNewViewer(MedicalImageViewer); +} + +} + diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h new file mode 100644 index 00000000..305f14c6 --- /dev/null +++ b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h @@ -0,0 +1,65 @@ +/***************************************************************************** + * $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 MEDICALIMAGEVIEWEREXTENSION_H +#define MEDICALIMAGEVIEWEREXTENSION_H + +#include "CamiTKAPI.h" + +#include "ViewerExtension.h" + +namespace camitk { + +class CAMITK_API MedicalImageViewerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + +public: + /// Constructor + MedicalImageViewerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~MedicalImageViewerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Medical Image Viewer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the Medical Image Viewer"; + }; + + /// initialize all the actions + virtual void init(); + +}; +} + +#endif // MEDICALIMAGEVIEWEREXTENSION_H + + diff --git a/sdk/libraries/core/viewer/PropertyExplorer.cpp b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp similarity index 100% rename from sdk/libraries/core/viewer/PropertyExplorer.cpp rename to sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp diff --git a/sdk/libraries/core/viewer/PropertyExplorer.h b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h similarity index 100% rename from sdk/libraries/core/viewer/PropertyExplorer.h rename to sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp new file mode 100644 index 00000000..ce1860bf --- /dev/null +++ b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp @@ -0,0 +1,40 @@ +/***************************************************************************** + * $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 "PropertyExplorerExtension.h" + +// include generated actions headers +#include "PropertyExplorer.h" + +namespace camitk { + +// --------------- getViewers ------------------- +void PropertyExplorerExtension::init() { + registerNewViewer(PropertyExplorer); +} + +} + diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h new file mode 100644 index 00000000..bf49b5e9 --- /dev/null +++ b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h @@ -0,0 +1,65 @@ +/***************************************************************************** + * $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 PROPERTYEXPLOREREXTENSION_H +#define PROPERTYEXPLOREREXTENSION_H + +#include "CamiTKAPI.h" + +#include "ViewerExtension.h" + +namespace camitk { + +class CAMITK_API PropertyExplorerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + +public: + /// Constructor + PropertyExplorerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~PropertyExplorerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Property Explorer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the property explorer"; + }; + + /// initialize all the actions + virtual void init(); + +}; +} + +#endif // PROPERTYEXPLOREREXTENSION_H + + -- GitLab From 445b30b7da84a55e15e50895e94b293684c0bb50 Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Tue, 10 Dec 2019 11:40:45 +0100 Subject: [PATCH 02/26] Correct bug on viewer in Core.cpp on the count of the viewer --- sdk/libraries/core/Core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/libraries/core/Core.cpp b/sdk/libraries/core/Core.cpp index 5bfa0e0c..5252a5ce 100644 --- a/sdk/libraries/core/Core.cpp +++ b/sdk/libraries/core/Core.cpp @@ -270,7 +270,7 @@ const QString Core::getConfig() { diagnosis += actions; diagnosis << "- Registered viewers:"; - diagnosis += actions; + diagnosis += viewers; return diagnosis.join("\n"); } -- GitLab From cd8667c88f4b253ea439c6e82daa8d34a150d2bb Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Tue, 10 Dec 2019 11:43:14 +0100 Subject: [PATCH 03/26] Correct config camitk --- sdk/applications/config/testing/config-test.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/applications/config/testing/config-test.sh b/sdk/applications/config/testing/config-test.sh index 0cf72848..ba5ed290 100644 --- a/sdk/applications/config/testing/config-test.sh +++ b/sdk/applications/config/testing/config-test.sh @@ -22,13 +22,13 @@ set -e # values to check initTestData() { # fill test data - extensionCount=( [4.2]=44 [4.1]=41 [4.0]=31 ) + extensionCount=( [4.2]=46 [4.1]=41 [4.0]=31 ) componentExtensionCount=( [4.2]=14 [4.1]=14 [4.0]=14 ) - actionExtensionCount=( [4.2]=29 [4.1]=27 [4.0]=27 ) - viewerExtensionCount=( [4.2]=1 [4.1]=0 [4.0]=0 ) + actionExtensionCount=( [4.2]=30 [4.1]=27 [4.0]=27 ) + viewerExtensionCount=( [4.2]=2 [4.1]=0 [4.0]=0 ) fileExtensionCount=( [4.2]=37 [4.1]=37 [4.0]=37 ) - actionCount=( [4.2]=107 [4.1]=105 [4.0]=105 ) - viewerCount=( [4.2]=1 [4.1]=0 [4.0]=0 ) + actionCount=( [4.2]=108 [4.1]=105 [4.0]=105 ) + viewerCount=( [4.2]=2 [4.1]=0 [4.0]=0 ) # fill release date releaseDate=( [4.2]="not yet released, current development version" \ -- GitLab From 3317459892477ba7fc8ebc5351c99d5b1d40cee6 Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Thu, 19 Dec 2019 18:23:28 +0100 Subject: [PATCH 04/26] Change viewer extension creation --- sdk/actions/application/Show3DViewer.cpp | 2 +- sdk/actions/frame/editframes/FrameEditor.cpp | 23 ++-- .../pixelcolorchanger/PixelColorChanger.cpp | 12 +-- .../image/reorientimage/ReorientImage.cpp | 6 +- .../volumerendering/VolumeRenderingAction.cpp | 14 +-- sdk/actions/mesh/basicmesh/MeshPicking.cpp | 2 +- sdk/actions/mesh/basicmesh/RigidTransform.cpp | 4 +- .../mesh/meshprocessing/MeshClipping.cpp | 4 +- sdk/components/msh/MshComponent.cpp | 5 +- sdk/components/off/OffComponent.cpp | 3 +- .../vrml/VRMLComponentExtension.cpp | 3 +- sdk/libraries/core/action/Action.cpp | 2 +- .../core/application/Application.cpp | 5 +- sdk/libraries/core/application/Application.h | 3 +- .../core/component/image/ImageComponent.cpp | 3 +- .../component/image/SingleImageComponent.cpp | 10 +- .../core/component/mesh/MeshComponent.cpp | 12 +-- sdk/libraries/core/viewer/Viewer.cpp | 3 +- sdk/libraries/core/viewer/Viewer.h | 2 +- sdk/libraries/core/viewer/ViewerExtension.h | 3 +- .../core/viewer/action/ActionViewer.cpp | 13 +-- .../core/viewer/action/ActionViewer.h | 6 +- .../viewer/action/ActionViewerExtension.cpp | 2 +- .../core/viewer/explorer/Explorer.cpp | 13 +-- sdk/libraries/core/viewer/explorer/Explorer.h | 6 +- .../viewer/explorer/ExplorerExtension.cpp | 2 +- .../viewer/frameexplorer/FrameExplorer.cpp | 13 +-- .../core/viewer/frameexplorer/FrameExplorer.h | 6 +- .../frameexplorer/FrameExplorerExtension.cpp | 2 +- .../viewer/interactive/InteractiveViewer.cpp | 101 +----------------- .../viewer/interactive/InteractiveViewer.h | 29 +---- .../InteractiveViewerExtension.cpp | 5 +- .../medicalimage/MedicalImageViewer.cpp | 37 +++---- .../viewer/medicalimage/MedicalImageViewer.h | 8 +- .../MedicalImageViewerExtension.cpp | 2 +- .../propertyexplorer/PropertyExplorer.cpp | 13 +-- .../propertyexplorer/PropertyExplorer.h | 10 +- .../PropertyExplorerExtension.cpp | 2 +- 38 files changed, 100 insertions(+), 291 deletions(-) diff --git a/sdk/actions/application/Show3DViewer.cpp b/sdk/actions/application/Show3DViewer.cpp index d091c88b..68ebee60 100644 --- a/sdk/actions/application/Show3DViewer.cpp +++ b/sdk/actions/application/Show3DViewer.cpp @@ -60,7 +60,7 @@ QWidget* Show3DViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus Show3DViewer::apply() { - MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_3D); + Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_3D); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/frame/editframes/FrameEditor.cpp b/sdk/actions/frame/editframes/FrameEditor.cpp index c6b9de37..c900142c 100644 --- a/sdk/actions/frame/editframes/FrameEditor.cpp +++ b/sdk/actions/frame/editframes/FrameEditor.cpp @@ -160,7 +160,7 @@ QWidget* FrameEditor::getWidget() { void FrameEditor::initializeDialogWithCurrentComponent() { // update checkbox ui.displayFrameCheckBox->blockSignals(true); - bool isFrameDisplayed = currentComponent->getFrameVisibility(InteractiveViewer::get3DViewer()); + bool isFrameDisplayed = currentComponent->getFrameVisibility(Application::getViewer("3DViewer")); ui.displayFrameCheckBox->setChecked(isFrameDisplayed); ui.displayFrameCheckBox->blockSignals(false); @@ -218,19 +218,18 @@ void FrameEditor::initializeDialogWithCurrentComponent() { void FrameEditor::displayFrameToggled(bool display) { int frameSize = ui.frameSizeSpinBox->value(); currentComponent->getFrameAxisActor()->SetTotalLength(frameSize, frameSize, frameSize); - currentComponent->setFrameVisibility(InteractiveViewer::get3DViewer(), display); - - InteractiveViewer::get3DViewer()->refresh(); + currentComponent->setFrameVisibility(Application::getViewer("3DViewer"), display); + Application::getViewer("3DViewer")->refresh(); } // --------------- frameSizeChanged ------------------- void FrameEditor::frameSizeChanged(int val) { bool display = ui.displayFrameCheckBox->isChecked(); currentComponent->getFrameAxisActor()->SetTotalLength(val, val, val); - currentComponent->setFrameVisibility(InteractiveViewer::get3DViewer(), display); + currentComponent->setFrameVisibility(Application::getViewer("3DViewer"), display); - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); } // --------------- setParentFrame ------------------- @@ -251,7 +250,7 @@ void FrameEditor::setParentFrame() { } currentComponent->setParentFrame(parentFrame, keepTransform); - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -300,7 +299,7 @@ void FrameEditor::setTransformation() { matrixTransform->SetMatrix(matrix); currentComponent->setTransform(matrixTransform); - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -315,7 +314,7 @@ void FrameEditor::translate() { ui.yTranslationLineEdit->text().toDouble(), ui.zTranslationLineEdit->text().toDouble()); - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -325,7 +324,7 @@ void FrameEditor::setTranslation() { ui.yTranslationLineEdit->text().toDouble(), ui.zTranslationLineEdit->text().toDouble()); - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -348,7 +347,7 @@ void FrameEditor::rotate() { ui.zRotationLineEdit->text().toDouble()); } - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -365,7 +364,7 @@ void FrameEditor::setRotation() { ui.zRotationLineEdit->text().toDouble()); } - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } diff --git a/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp b/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp index eb88db78..35308a5e 100644 --- a/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp +++ b/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp @@ -79,9 +79,9 @@ QWidget* PixelColorChanger::getWidget() { if (!isConnected) { //-- run the action every time a picking is done in the axial/sagittal or coronal planes - QObject::connect(InteractiveViewer::getAxialViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::connect(InteractiveViewer::getCoronalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::connect(InteractiveViewer::getSagittalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); isConnected = true; } return Action::getWidget(); @@ -219,9 +219,9 @@ Action::ApplyStatus PixelColorChanger::apply() { } else { // disconnect - QObject::disconnect(InteractiveViewer::getAxialViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::disconnect(InteractiveViewer::getCoronalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::disconnect(InteractiveViewer::getSagittalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); isConnected = false; } return SUCCESS; diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index e795439d..61c29d87 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -333,7 +333,7 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); image->setTransform(updatedTransform); - image->setFrameVisibility(InteractiveViewer::get3DViewer(), true); + image->setFrameVisibility(Application::getViewer("3DViewer"), true); } else { @@ -357,9 +357,9 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); result->setTransform(updatedTransform); - result->setFrameVisibility(InteractiveViewer::get3DViewer(), true); + result->setFrameVisibility(Application::getViewer("3DViewer"), true); } - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); Application::refresh(); diff --git a/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp b/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp index fc4ca1ef..719e3db0 100644 --- a/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp +++ b/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp @@ -98,18 +98,18 @@ Action::ApplyStatus VolumeRenderingAction::apply() { // --------------- process --------------- void VolumeRenderingAction::process(ImageComponent* comp) { - bool isVisible = comp->getVolumeRenderingChild()->getVisibility(InteractiveViewer::get3DViewer()); + bool isVisible = comp->getVolumeRenderingChild()->getVisibility(Application::getViewer("3DViewer")); bool existVR = (comp->getVolumeRenderingChild()->getProp(volumeName) != NULL); if (existVR) { if (isVisible) { - comp->getVolumeRenderingChild()->setVisibility(InteractiveViewer::get3DViewer(), false); + comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), false); if (myWidget) { myWidget->close(); } Application::refresh(); } else { - comp->getVolumeRenderingChild()->setVisibility(InteractiveViewer::get3DViewer(), true); + comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), true); if (myWidget != nullptr) { myWidget->show(); Application::refresh(); @@ -253,16 +253,16 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) { if (oldVolume) { comp->getVolumeRenderingChild()->removeProp(volumeName); - //InteractiveViewer::get3DViewer()->getRendererWidget()->removeProp(oldVolume); + //Application::getViewer("3DViewer")->getRendererWidget()->removeProp(oldVolume); } // Add the new computed volume to the component and display it in the 3D viewer comp->getVolumeRenderingChild()->addProp(volumeName, volume); comp->getVolumeRenderingChild()->getProp(volumeName)->SetVisibility(true); - //InteractiveViewer::get3DViewer()->getRendererWidget()->addProp(volume); - comp->getVolumeRenderingChild()->setVisibility(InteractiveViewer::get3DViewer(), true); - InteractiveViewer::get3DViewer()->refresh(); + //Application::getViewer("3DViewer")->getRendererWidget()->addProp(volume); + comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), true); + Application::getViewer("3DViewer")->refresh(); } diff --git a/sdk/actions/mesh/basicmesh/MeshPicking.cpp b/sdk/actions/mesh/basicmesh/MeshPicking.cpp index 9d7c26b0..a1a1824c 100644 --- a/sdk/actions/mesh/basicmesh/MeshPicking.cpp +++ b/sdk/actions/mesh/basicmesh/MeshPicking.cpp @@ -61,7 +61,7 @@ QWidget* MeshPicking::getWidget() { informationLabel = new QLabel(); //-- run the action every time a picking is done in the axial/sagittal or coronal planes - QObject::connect(InteractiveViewer::get3DViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("3DViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); //-- the vertical layout, put every GUI elements in it auto* informationFrameLayout = new QVBoxLayout(); diff --git a/sdk/actions/mesh/basicmesh/RigidTransform.cpp b/sdk/actions/mesh/basicmesh/RigidTransform.cpp index 972c9046..c211db74 100644 --- a/sdk/actions/mesh/basicmesh/RigidTransform.cpp +++ b/sdk/actions/mesh/basicmesh/RigidTransform.cpp @@ -131,7 +131,7 @@ void RigidTransform::reset() { //-- init values double bounds[6]; - InteractiveViewer::get3DViewer()->getBounds(bounds); + Application::getViewer("3DViewer")->getBounds(bounds); double xLength = bounds[1] - bounds[0]; double yLength = bounds[3] - bounds[2]; double zLength = bounds[5] - bounds[4]; @@ -184,7 +184,7 @@ void RigidTransform::update(bool forceUpdate) { transformation->Scale(sx, sy, sz); // Refresh all the used viewers - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); } } diff --git a/sdk/actions/mesh/meshprocessing/MeshClipping.cpp b/sdk/actions/mesh/meshprocessing/MeshClipping.cpp index 773a4ce4..a80dc988 100644 --- a/sdk/actions/mesh/meshprocessing/MeshClipping.cpp +++ b/sdk/actions/mesh/meshprocessing/MeshClipping.cpp @@ -85,7 +85,7 @@ QWidget* MeshClipping::getWidget() { //-- Creating the clipping plane widget (the first time getWidget() is called) if (!widget->planeWidget) { vtkRenderWindowInteractor* iren = - InteractiveViewer::get3DViewer()-> + Application::getViewer("3DViewer")-> getRendererWidget()->GetRenderWindow()->GetInteractor(); //-- Configure the plane widget including callbacks @@ -96,7 +96,7 @@ QWidget* MeshClipping::getWidget() { //-- Bounding box definition and placement widget->planeWidget->SetPlaceFactor(1.5); - InteractiveViewer::get3DViewer()->getBounds(limBounds); + Application::getViewer("3DViewer")->getBounds(limBounds); widget->planeWidget->PlaceWidget(limBounds); QVector3D origin((limBounds[1] + limBounds[0]) / 2, (limBounds[3] + limBounds[2]) / 2, diff --git a/sdk/components/msh/MshComponent.cpp b/sdk/components/msh/MshComponent.cpp index 6dbbf7ee..694de836 100644 --- a/sdk/components/msh/MshComponent.cpp +++ b/sdk/components/msh/MshComponent.cpp @@ -28,6 +28,7 @@ #include +#include #include #include @@ -165,7 +166,7 @@ void MshComponent::readLegacyFormat(std::ifstream& fileStream) { initRepresentation(mesh); // add the represention in the 3D viewer - setVisibility(InteractiveViewer::get3DViewer(), true); + setVisibility(Application::getViewer("3DViewer"), true); } void MshComponent::readV2Format(std::ifstream& fileStream) { @@ -322,5 +323,5 @@ void MshComponent::readV2Format(std::ifstream& fileStream) { initRepresentation(mesh); // add the represention in the 3D viewer - setVisibility(InteractiveViewer::get3DViewer(), true); + setVisibility(Application::getViewer("3DViewer"), true); } diff --git a/sdk/components/off/OffComponent.cpp b/sdk/components/off/OffComponent.cpp index a9a52fee..597042db 100644 --- a/sdk/components/off/OffComponent.cpp +++ b/sdk/components/off/OffComponent.cpp @@ -27,6 +27,7 @@ #include +#include #include #include @@ -116,7 +117,7 @@ OffComponent::OffComponent(const QString& file) : MeshComponent(file) { initRepresentation(offMesh); // add the represention in the 3D viewer - setVisibility(InteractiveViewer::get3DViewer(), true); + setVisibility(Application::getViewer("3DViewer"), true); // initialize the dynamic properties //initDynamicProperties(); diff --git a/sdk/components/vrml/VRMLComponentExtension.cpp b/sdk/components/vrml/VRMLComponentExtension.cpp index 8c87b663..901447d9 100644 --- a/sdk/components/vrml/VRMLComponentExtension.cpp +++ b/sdk/components/vrml/VRMLComponentExtension.cpp @@ -28,6 +28,7 @@ #include "VRMLComponent.h" //-- CamiTK stuff +#include #include #include using namespace camitk; @@ -69,7 +70,7 @@ bool VRMLComponentExtension::save(Component* component) const { } else if (mesh->getPointSet()) { vtkSmartPointer exporter = vtkSmartPointer::New(); - exporter->SetInput(InteractiveViewer::get3DViewer()->getRendererWidget()->GetRenderWindow()); + exporter->SetInput(Application::getViewer("3DViewer")->getRendererWidget()->GetRenderWindow()); exporter->SetFileName(mesh->getFileName().toStdString().c_str()); exporter->Write(); return true; diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index a3a5bc4e..1d0f0c31 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -188,7 +188,7 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { if (isEmbedded) { // if there are no parents to use use the action viewer if (parent == nullptr) { - ActionViewer::getInstance()->embedActionWidget(this); + Application::getViewer("ActionViewer")->embedActionWidget(this); } else { getWidget()->setParent(parent); diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index 90b88af1..417b985e 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -866,8 +866,9 @@ ActionList Application::getActions(ComponentList selComp, QString tag) { } // ---------------- getViewer ---------------- -Viewer* Application::getViewer(QString name) { - return getViewerMap().value(name); +template +T* Application::getViewer(QString name) { + return dynamic_cast(getViewerMap().value(name)); } // -------------------- getViewers -------------------- diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index 1d139f5c..c9f3a11f 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -260,7 +260,8 @@ public: ///@} /// get a registered viewer given its name - static Viewer* getViewer(QString); + template + static T* getViewer(QString); /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); diff --git a/sdk/libraries/core/component/image/ImageComponent.cpp b/sdk/libraries/core/component/image/ImageComponent.cpp index 5e477908..4b6f4c4c 100644 --- a/sdk/libraries/core/component/image/ImageComponent.cpp +++ b/sdk/libraries/core/component/image/ImageComponent.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ // -- Core image component stuff +#include "Application.h" #include "ImageComponent.h" #include "ImageComponentExtension.h" #include "SingleImageComponent.h" @@ -523,7 +524,7 @@ void ImageComponent::update3DViewer() { } if (volumeRenderingChild) { - volumeRenderingChild->setVisibility(InteractiveViewer::get3DViewer(), viewIn3D); + volumeRenderingChild->setVisibility(Application::getViewer("3DViewer"), viewIn3D); } } diff --git a/sdk/libraries/core/component/image/SingleImageComponent.cpp b/sdk/libraries/core/component/image/SingleImageComponent.cpp index 55a16197..5ce2ca25 100644 --- a/sdk/libraries/core/component/image/SingleImageComponent.cpp +++ b/sdk/libraries/core/component/image/SingleImageComponent.cpp @@ -80,7 +80,7 @@ bool SingleImageComponent::getViewSliceIn3D() const { // -------------------- setViewSliceIn3D -------------------- void SingleImageComponent::setViewSliceIn3D(bool toggle) { this->viewSliceIn3D = toggle; - this->setVisibility(InteractiveViewer::get3DViewer(), viewSliceIn3D); + this->setVisibility(Application::getViewer("3DViewer"), viewSliceIn3D); } // -------------------- initRepresentation -------------------- @@ -91,16 +91,16 @@ void SingleImageComponent::initRepresentation() { switch (sliceOrientation) { case Slice::AXIAL: case Slice::AXIAL_NEURO: - setVisibility(InteractiveViewer::getAxialViewer(), true); + setVisibility(Application::getViewer("axialViewer"), true); break; case Slice::CORONAL: - setVisibility(InteractiveViewer::getCoronalViewer(), true); + setVisibility(Application::getViewer("coronalViewer"), true); break; case Slice::SAGITTAL: - setVisibility(InteractiveViewer::getSagittalViewer(), true); + setVisibility(Application::getViewer("sagittalViewer"), true); break; case Slice::ARBITRARY: - setVisibility(InteractiveViewer::getArbitraryViewer(), true); + setVisibility(Application::getViewer("arbitraryViewer"), true); break; } } diff --git a/sdk/libraries/core/component/mesh/MeshComponent.cpp b/sdk/libraries/core/component/mesh/MeshComponent.cpp index 9377deb0..9239110e 100644 --- a/sdk/libraries/core/component/mesh/MeshComponent.cpp +++ b/sdk/libraries/core/component/mesh/MeshComponent.cpp @@ -229,7 +229,7 @@ void MeshComponent::initRepresentation(vtkSmartPointer originalPoin myGeometry->setMeshWorldTransform(getTransformFromWorld()); // add it in the InteractiveViewer (automatically) - setVisibility(InteractiveViewer::get3DViewer(), true); + setVisibility(Application::getViewer("3DViewer"), true); // initialize selection initSelection(); @@ -808,8 +808,8 @@ void MeshComponent::setDataRepresentationOff(int dataType) { pointDataSet->SetActiveScalars(nullptr); cellDataSet->SetActiveScalars(nullptr); // remove all color bar - InteractiveViewer::get3DViewer()->setColorScaleTitle(""); - InteractiveViewer::get3DViewer()->setColorScale(false); + Application::getViewer("3DViewer")->setColorScaleTitle(""); + Application::getViewer("3DViewer")->setColorScale(false); } if (dataType & VECTORS) { @@ -855,9 +855,9 @@ void MeshComponent::setScalarDataRepresentationOn(vtkSmartPointer setMapperScalarRange(range[0], range[1]); //-- show the color scale in 3D - InteractiveViewer::get3DViewer()->setColorScale(true); - InteractiveViewer::get3DViewer()->setColorScaleTitle(dataArray->GetName()); - InteractiveViewer::get3DViewer()->setColorScaleMinMax(range[0], range[1]); + Application::getViewer("3DViewer")->setColorScale(true); + Application::getViewer("3DViewer")->setColorScaleTitle(dataArray->GetName()); + Application::getViewer("3DViewer")->setColorScaleMinMax(range[0], range[1]); } // -------------------- setDataRepresentationVisibility -------------------- diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index 1a01a092..2bd8a5f5 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -31,8 +31,9 @@ namespace camitk { //---------------------- constructor ------------------------ -Viewer::Viewer(QString name): QObject() { +Viewer::Viewer(ViewerExtension* extension, QString name): QObject() { this->name = name; + this->extension = extension; setObjectName(name); toolbarVisibility = true; } diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index eee75b11..4ea77b39 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -59,7 +59,7 @@ class CAMITK_API Viewer : public QObject { public: /// default constructor - Viewer(QString name); + Viewer(ViewerExtension*, QString name); /// default destructor ~Viewer() override = default; diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index 9a89752e..2f89b859 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -12,7 +12,8 @@ namespace camitk { class Viewer; -#define registerNewViewer(X) registerViewer(X::getInstance()) +#define registerNewViewer(X, Y) registerViewer(new X(this, QString(Y))) +#define registerNewViewerDefault(X) registerViewer(new X(this, QString("X"))) /** * @ingroup group_sdk_libraries_core_action diff --git a/sdk/libraries/core/viewer/action/ActionViewer.cpp b/sdk/libraries/core/viewer/action/ActionViewer.cpp index 35df1bb4..378b30db 100644 --- a/sdk/libraries/core/viewer/action/ActionViewer.cpp +++ b/sdk/libraries/core/viewer/action/ActionViewer.cpp @@ -40,7 +40,7 @@ namespace camitk { // ---------------- constructor ---------------- -ActionViewer::ActionViewer() : Viewer("Action Viewer") { +ActionViewer::ActionViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { myWidget = nullptr; familyComboBox = nullptr; nameComboBox = nullptr; @@ -48,17 +48,6 @@ ActionViewer::ActionViewer() : Viewer("Action Viewer") { searchFramePanel = nullptr; } -// ---------------- getInstance ---------------- -ActionViewer* ActionViewer::getInstance() { - //static instantiation, static method variable - static ActionViewer* actionViewer = nullptr; - if (!actionViewer) { - actionViewer = new ActionViewer(); - } - - return actionViewer; -} - // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer* whoIsAsking) { updateActionViewer(ViewerRefresh); diff --git a/sdk/libraries/core/viewer/action/ActionViewer.h b/sdk/libraries/core/viewer/action/ActionViewer.h index 8e64c825..07782bbb 100644 --- a/sdk/libraries/core/viewer/action/ActionViewer.h +++ b/sdk/libraries/core/viewer/action/ActionViewer.h @@ -64,15 +64,11 @@ public: */ ///@{ /// constructor - ActionViewer(); + ActionViewer(ViewerExtension*, QString); /// destructor ~ActionViewer() override = default; - /// returns the unique instance of ActionViewer - static ActionViewer* getInstance(); - //@} - /// @name Inherited from Viewer //@{ /// returns the number of Component that are displayed by this viewer diff --git a/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp b/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp index 40749448..9f01905b 100644 --- a/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp +++ b/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp @@ -33,7 +33,7 @@ namespace camitk { // --------------- getViewers ------------------- void ActionViewerExtension::init() { - registerNewViewer(ActionViewer); + registerNewViewerDefault(ActionViewer); } } diff --git a/sdk/libraries/core/viewer/explorer/Explorer.cpp b/sdk/libraries/core/viewer/explorer/Explorer.cpp index 2a3e8c73..1cd7f9a2 100644 --- a/sdk/libraries/core/viewer/explorer/Explorer.cpp +++ b/sdk/libraries/core/viewer/explorer/Explorer.cpp @@ -43,7 +43,7 @@ namespace camitk { //----------------------- constructor ------------------------ -Explorer::Explorer() : Viewer("Explorer") { +Explorer::Explorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { explorerTree = nullptr; explorerMenu = nullptr; } @@ -57,17 +57,6 @@ Explorer::~Explorer() { explorerMenu = nullptr; } -//----------------------- getInstance ------------------------ -Explorer* Explorer::getInstance() { - // static instanciation, static method variable - static Explorer* explorer = nullptr; - if (!explorer) { - explorer = new Explorer(); - } - - return explorer; -} - //----------------------- getWidget ------------------------ QWidget* Explorer::getWidget(QWidget* parent) { if (explorerTree == nullptr) { diff --git a/sdk/libraries/core/viewer/explorer/Explorer.h b/sdk/libraries/core/viewer/explorer/Explorer.h index fcb73c34..65c377f3 100644 --- a/sdk/libraries/core/viewer/explorer/Explorer.h +++ b/sdk/libraries/core/viewer/explorer/Explorer.h @@ -63,15 +63,11 @@ public: */ ///@{ /** Construtor */ - Explorer(); + Explorer(ViewerExtension*, QString); /** Destructor */ ~Explorer() override; - /// returns the unique instance of ActionViewer - static Explorer* getInstance(); - /// @} - /** @name Inherited from Viewer */ ///@{ diff --git a/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp b/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp index 919a196d..61307eaf 100644 --- a/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp +++ b/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp @@ -33,7 +33,7 @@ namespace camitk { // --------------- getViewers ------------------- void ExplorerExtension::init() { - registerNewViewer(Explorer); + registerNewViewerDefault(Explorer); } } diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp b/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp index 7548555d..9a566b05 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp +++ b/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp @@ -33,21 +33,10 @@ namespace camitk { //----------------------- constructor ------------------------ -FrameExplorer::FrameExplorer() : Viewer("Frame Explorer") { +FrameExplorer::FrameExplorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { explorerTree = nullptr; } -//----------------------- getInstance ------------------------ -FrameExplorer* FrameExplorer::getInstance() { - // static instantiation, static method variable - static FrameExplorer* frameExplorer = nullptr; - if (!frameExplorer) { - frameExplorer = new FrameExplorer(); - } - - return frameExplorer; -} - //----------------------- getWidget ------------------------ QWidget* FrameExplorer::getWidget(QWidget* parent) { if (explorerTree == nullptr) { diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h b/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h index 48b9154f..abf65414 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h +++ b/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h @@ -60,15 +60,11 @@ public: */ ///@{ /** Construtor */ - FrameExplorer(); + FrameExplorer(ViewerExtension*, QString); /** Destructor */ ~FrameExplorer() override = default; - /// returns the unique instance of ActionViewer - static FrameExplorer* getInstance(); - /// @} - /** @name Inherited from Viewer */ ///@{ diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp b/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp index 8aa53372..0ee0584e 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp +++ b/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp @@ -33,7 +33,7 @@ namespace camitk { // --------------- getViewers ------------------- void FrameExplorerExtension::init() { - registerNewViewer(FrameExplorer); + registerNewViewerDefault(FrameExplorer); } } diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp b/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp index effb3218..930e3af0 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp @@ -81,108 +81,9 @@ #include namespace camitk { -// ---------------------- singleton ---------------------------- -/// the register containing all the viewers (static instantiation, global variable, but global only for this file) -QMap InteractiveViewer::viewers; -std::array InteractiveViewer::defaultNames = {QString("3DViewer"), QString("axialViewer"), QString("coronalViewer"), QString("sagittalViewer"), QString("arbitraryViewer") }; - -InteractiveViewer* InteractiveViewer::getNewViewer(QString name, ViewerType type) { - if (!viewers.contains(name)) { - //-- Congratulation, you got yourself a new InteractiveViewer! (but are you really sure you need it?) - viewers[name] = new InteractiveViewer(name, type); - } - - return viewers.value(name); -} - -InteractiveViewer* InteractiveViewer::getViewer(QString name) { - const std::string nameChar = name.toStdString(); - - if (viewers.contains(name)) { - return viewers.value(name); - } - else { - //-- if this is a default scene, get a new one if it does not exists - // perform the singleton instantiation here! - unsigned int i = 0; - // special case, the first viewer is a 3D viewer - - if (name == defaultNames[i]) { - return getNewViewer(defaultNames[i], GEOMETRY_VIEWER); - } - - InteractiveViewer* singletonInstance = nullptr; - - i++; - - while (i < defaultNames.size() && !singletonInstance) { - if (name == defaultNames[i]) { - singletonInstance = getNewViewer(defaultNames[i], SLICE_VIEWER); - } - - i++; - } - - // default orientation for axial, sagittal and coronal is not the same - // See Image Reorientation Action Documentation... -// singletonInstance->toggleOrientationDecorations(false); - if (name == defaultNames[1]) { // Axial Viewer - singletonInstance->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); - QString letters[4] = {QString("R"), QString("L"), QString("A"), QString("P") }; - singletonInstance->getRendererWidget()->setOrientationDecorationsLetters(letters); - singletonInstance->toggleOrientationDecorations(true); - 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()->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()->ParallelProjectionOn(); - } - - - return singletonInstance; - } -} - -InteractiveViewer* InteractiveViewer::get3DViewer() { - return getViewer(defaultNames[0]); -} - -InteractiveViewer* InteractiveViewer::getAxialViewer() { - return getViewer(defaultNames[1]); -} - -InteractiveViewer* InteractiveViewer::getCoronalViewer() { - return getViewer(defaultNames[2]); -} - -InteractiveViewer* InteractiveViewer::getSagittalViewer() { - return getViewer(defaultNames[3]); -} - -InteractiveViewer* InteractiveViewer::getArbitraryViewer() { - return getViewer(defaultNames[4]); -} // ---------------------- constructor ---------------------------- -InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(name) { +InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, ViewerType type) : Viewer(extension, name) { myType = type; diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewer.h b/sdk/libraries/core/viewer/interactive/InteractiveViewer.h index 2809b0ee..a20291a8 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewer.h @@ -169,34 +169,7 @@ public: SELECTION_ONLY ///< the selected Components are in default mode, the non-selected are hidden }; - /** @name General/Singleton - * There is no public constructor for this class, but 5 default instances. - */ - /// @{ - /** Use this method to create a new custom instance of this class. - * Of course you can create as many InteractiveViewer instance as you like, but if you try to create - * a InteractiveViewer with a name that match one of the default InteractiveViewer name, getNewViewer(..) automatically - * will return the corresponding default InteractiveViewer instance. - */ - static InteractiveViewer* getNewViewer(QString, ViewerType type); - - /// get a viewer by its name (return NULL if no instance has the given name, use getNewViewer to create one viewer) - static InteractiveViewer* getViewer(QString); - - /// get the 3D viewer default InteractiveViewer (provided for convenience, equivalent to getViewer("3DViewer") - static InteractiveViewer* get3DViewer(); - - /// get the axial default InteractiveViewer (provided for convenience, equivalent to getViewer("axialViewer") - static InteractiveViewer* getAxialViewer(); - - /// get the coronal default InteractiveViewer (provided for convenience, equivalent to getViewer("coronalViewer") - static InteractiveViewer* getCoronalViewer(); - - /// get the sagittal default InteractiveViewer (provided for convenience, equivalent to getViewer("sagittalViewer") - static InteractiveViewer* getSagittalViewer(); - - /// get the arbitrary default InteractiveViewer (provided for convenience, equivalent to getViewer("arbitraryViewer") - static InteractiveViewer* getArbitraryViewer(); + InteractiveViewer(ViewerExtension * extension, QString & name, ViewerType type=SLICE_VIEWER); /** Destructor */ ~InteractiveViewer() override; diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp b/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp index 422e08d7..c317f13a 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp @@ -33,7 +33,10 @@ namespace camitk { // --------------- getViewers ------------------- void InteractiveViewerExtension::init() { - registerNewViewer(InteractiveViewer); + registerNewViewer(InteractiveViewer, "3DViewer"); + registerNewViewer(InteractiveViewer, "axialViewer"); + registerNewViewer(InteractiveViewer, "coronalViewer"); + registerNewViewer(InteractiveViewer, "arbitraryViewer"); } } diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp index 42a9fe1e..28a342f4 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp +++ b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp @@ -36,19 +36,10 @@ #include namespace camitk { -MedicalImageViewer* MedicalImageViewer::singleton = nullptr; - -MedicalImageViewer* MedicalImageViewer::getInstance() { - if (!singleton) { - singleton = new MedicalImageViewer(); - } - - return singleton; -} // -------------------- Constructor -------------------- -MedicalImageViewer::MedicalImageViewer() : Viewer("Medical Image Viewer") { +MedicalImageViewer::MedicalImageViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { // init view members frame = nullptr; frameLayout = nullptr; @@ -93,9 +84,9 @@ void MedicalImageViewer::refresh(Viewer* whoIsAsking) { if (displayedTopLevelComponents != (unsigned) Application::getTopLevelComponents().size()) { // if there the nr of Component changed since last refresh, // and if there is something displayed in the slices viewer, show all view - if (InteractiveViewer::getAxialViewer()->numberOfViewedComponent() > 0 - && InteractiveViewer::getCoronalViewer()->numberOfViewedComponent() > 0 - && InteractiveViewer::getSagittalViewer()->numberOfViewedComponent() > 0) { + if (Application::getViewer("axialViewer")->numberOfViewedComponent() > 0 + && Application::getViewer("coronalViewer")->numberOfViewedComponent() > 0 + && Application::getViewer("sagittalViewer")->numberOfViewedComponent() > 0) { visibleLayout = VIEWER_ALL; } else { @@ -129,18 +120,18 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) { viewerVisibility.append(VIEWER_ALL); // ALL has to be the end of visible viewers // list of viewer name - viewers.insert(VIEWER_3D, InteractiveViewer::get3DViewer()); - viewers.insert(VIEWER_ARBITRARY, InteractiveViewer::getArbitraryViewer()); - viewers.insert(VIEWER_AXIAL, InteractiveViewer::getAxialViewer()); - viewers.insert(VIEWER_CORONAL, InteractiveViewer::getCoronalViewer()); - viewers.insert(VIEWER_SAGITTAL, InteractiveViewer::getSagittalViewer()); + viewers.insert(VIEWER_3D, Application::getViewer("3DViewer")); + viewers.insert(VIEWER_ARBITRARY, Application::getViewer("arbitraryViewer")); + viewers.insert(VIEWER_AXIAL, Application::getViewer("axialViewer")); + viewers.insert(VIEWER_CORONAL, Application::getViewer("coronalViewer")); + viewers.insert(VIEWER_SAGITTAL, Application::getViewer("sagittalViewer")); topLeftLayout = new QVBoxLayout(); frameLayout->addLayout(topLeftLayout, 0, 0); - 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 + topLeftLayout->addWidget(Application::getViewer("axialViewer")->getWidget(frame)); // equivalent of addWidget(Application::getViewer("axialViewer")->getWidget(frame), 0, 0) = north-west + frameLayout->addWidget(Application::getViewer("coronalViewer")->getWidget(frame), 1, 0); // north-east + frameLayout->addWidget(Application::getViewer("sagittalViewer")->getWidget(frame), 1, 1); // south-west + frameLayout->addWidget(Application::getViewer("3DViewer")->getWidget(frame), 0, 1); // south-east //-- connect foreach (LayoutVisibility v, viewerVisibility) { @@ -158,7 +149,7 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) { // ---------------------- getPropertyObject ---------------------------- QObject* MedicalImageViewer::getPropertyObject() { - return InteractiveViewer::get3DViewer()->getPropertyObject(); + return Application::getViewer("3DViewer")->getPropertyObject(); } // -------------------- getMenu -------------------- diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h index bd4bf54e..5acaa44e 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h +++ b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h @@ -71,8 +71,7 @@ public: VIEWER_ARBITRARY ///< Only the arbitrary InteractiveViewer are visible }; - /// get singleton instance - static MedicalImageViewer* getInstance(); + MedicalImageViewer(ViewerExtension*, QString); /** destructor */ ~MedicalImageViewer() override; @@ -115,11 +114,6 @@ public slots: /// called when an internal InteractiveViewers has emitted a selectionChanged signal void synchronizeSelection(); -protected: - - /// Protected construtor (singleton) - MedicalImageViewer(); - private: /// set the current visibility of the different viewer void updateLayout(); diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp index 1eaec53f..b9ba8f2d 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp +++ b/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp @@ -33,7 +33,7 @@ namespace camitk { // --------------- getViewers ------------------- void MedicalImageViewerExtension::init() { - registerNewViewer(MedicalImageViewer); + registerNewViewerDefault(MedicalImageViewer); } } diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp index fa27382a..607c4d1e 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp +++ b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp @@ -38,7 +38,7 @@ namespace camitk { // ---------------- constructor ---------------- -PropertyExplorer::PropertyExplorer() : Viewer("Property Explorer") { +PropertyExplorer::PropertyExplorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { theController = nullptr; tabWidget = nullptr; revertButton = nullptr; @@ -59,17 +59,6 @@ PropertyExplorer::~PropertyExplorer() { } } -//----------------------- getInstance ------------------------ -PropertyExplorer* PropertyExplorer::getInstance() { - // static instantiation, static method variable - static PropertyExplorer* propExplorer = nullptr; - if (!propExplorer) { - propExplorer = new PropertyExplorer(); - } - - return propExplorer; -} - // ---------------- numberOfViewedComponent ---------------- unsigned int PropertyExplorer::numberOfViewedComponent() { if (currentComponent) { diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h index 2d7f3ad6..ee07777b 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h +++ b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h @@ -89,14 +89,10 @@ public: */ ///@{ /// constructor - PropertyExplorer(); + PropertyExplorer(ViewerExtension * extension, QString name); - /// destructor - ~PropertyExplorer() override; - - /// returns the unique instance of the PropertyExplorer - static PropertyExplorer* getInstance(); - ///@} + /// destructor + ~PropertyExplorer() override; /** @name Inherited from Viewer */ diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp index ce1860bf..2271eb80 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp +++ b/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp @@ -33,7 +33,7 @@ namespace camitk { // --------------- getViewers ------------------- void PropertyExplorerExtension::init() { - registerNewViewer(PropertyExplorer); + registerNewViewerDefault(PropertyExplorer); } } -- GitLab From e80a5a548b27206d10fd4b6870a3aecb404b35c1 Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Fri, 20 Dec 2019 17:17:48 +0100 Subject: [PATCH 05/26] Continue modif --- sdk/actions/application/ShowAllViewers.cpp | 2 +- .../application/ShowArbitraryViewer.cpp | 2 +- sdk/actions/application/ShowAxialViewer.cpp | 2 +- sdk/actions/application/ShowCoronalViewer.cpp | 2 +- .../application/ShowSagittalViewer.cpp | 2 +- .../image/reorientimage/ReorientImage.cpp | 38 +++++++++---------- .../actionstatemachine/ActionStateMachine.cpp | 6 +-- .../actionstatemachine/ActionStateViewer.cpp | 11 +----- .../actionstatemachine/ActionStateViewer.h | 7 ++-- sdk/applications/imp/ImpMainWindow.cpp | 30 +++++++-------- .../core/application/Application.cpp | 8 +--- sdk/libraries/core/application/Application.h | 16 +++++++- .../viewer/interactive/InteractiveViewer.cpp | 1 - .../viewer/interactive/InteractiveViewer.h | 3 -- 14 files changed, 63 insertions(+), 67 deletions(-) diff --git a/sdk/actions/application/ShowAllViewers.cpp b/sdk/actions/application/ShowAllViewers.cpp index 7b687a2e..5bb9b4dc 100644 --- a/sdk/actions/application/ShowAllViewers.cpp +++ b/sdk/actions/application/ShowAllViewers.cpp @@ -60,7 +60,7 @@ QWidget* ShowAllViewers::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowAllViewers::apply() { - MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); + Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowArbitraryViewer.cpp b/sdk/actions/application/ShowArbitraryViewer.cpp index 39094316..9e258c43 100644 --- a/sdk/actions/application/ShowArbitraryViewer.cpp +++ b/sdk/actions/application/ShowArbitraryViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowArbitraryViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowArbitraryViewer::apply() { - MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_ARBITRARY); + Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_ARBITRARY); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowAxialViewer.cpp b/sdk/actions/application/ShowAxialViewer.cpp index c9ddb37c..0d10b525 100644 --- a/sdk/actions/application/ShowAxialViewer.cpp +++ b/sdk/actions/application/ShowAxialViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowAxialViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowAxialViewer::apply() { - MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_AXIAL); + Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_AXIAL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowCoronalViewer.cpp b/sdk/actions/application/ShowCoronalViewer.cpp index 19beb6fc..42c65001 100644 --- a/sdk/actions/application/ShowCoronalViewer.cpp +++ b/sdk/actions/application/ShowCoronalViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowCoronalViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowCoronalViewer::apply() { - MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_CORONAL); + Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_CORONAL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowSagittalViewer.cpp b/sdk/actions/application/ShowSagittalViewer.cpp index 6ec9e733..94158fff 100644 --- a/sdk/actions/application/ShowSagittalViewer.cpp +++ b/sdk/actions/application/ShowSagittalViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowSagittalViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowSagittalViewer::apply() { - MedicalImageViewer::getInstance()->setVisibleViewer(MedicalImageViewer::VIEWER_SAGITTAL); + Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_SAGITTAL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index 61c29d87..a737e70b 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -191,17 +191,17 @@ void ReorientImage::initInternalViewer() { // get the nice vtk 3D representation from file buildGeometries(); - // Set up the 3D viewer to visualize actual origin/orientation locations - internalViewer = InteractiveViewer::getNewViewer("Image Orientation Viewer", InteractiveViewer::GEOMETRY_VIEWER); - internalViewer->setHighlightMode(InteractiveViewer::OFF); - internalViewer->toggleCopyright(false); - internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); - - if (modelBoundingBox) { - internalViewer->getRendererWidget()->addProp(modelBoundingBox->getActor(InterfaceGeometry::Wireframe)); - } - internalViewer->getRendererWidget()->addProp(axes); - internalViewer->getRendererWidget()->addProp(annotatedCube); + //// Set up the 3D viewer to visualize actual origin/orientation locations + //internalViewer = InteractiveViewer::getNewViewer("Image Orientation Viewer", InteractiveViewer::GEOMETRY_VIEWER); + //internalViewer->setHighlightMode(InteractiveViewer::OFF); + //internalViewer->toggleCopyright(false); + //internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); + + //if (modelBoundingBox) { + // internalViewer->getRendererWidget()->addProp(modelBoundingBox->getActor(InterfaceGeometry::Wireframe)); + //} + //internalViewer->getRendererWidget()->addProp(axes); + //internalViewer->getRendererWidget()->addProp(annotatedCube); } @@ -224,14 +224,14 @@ void ReorientImage::modelChanged(bool displayMaleModel) { return; } - if (displayMaleModel) { - internalViewer->getRendererWidget()->removeProp(femaleModel->getActor(InterfaceGeometry::Surface)); - internalViewer->getRendererWidget()->addProp(maleModel->getActor(InterfaceGeometry::Surface)); - } - else { - internalViewer->getRendererWidget()->removeProp(maleModel->getActor(InterfaceGeometry::Surface)); - internalViewer->getRendererWidget()->addProp(femaleModel->getActor(InterfaceGeometry::Surface)); - } + //if (displayMaleModel) { + // internalViewer->getRendererWidget()->removeProp(femaleModel->getActor(InterfaceGeometry::Surface)); + // internalViewer->getRendererWidget()->addProp(maleModel->getActor(InterfaceGeometry::Surface)); + //} + //else { + // internalViewer->getRendererWidget()->removeProp(maleModel->getActor(InterfaceGeometry::Surface)); + // internalViewer->getRendererWidget()->addProp(femaleModel->getActor(InterfaceGeometry::Surface)); + //} internalViewer->refresh(); } diff --git a/sdk/applications/actionstatemachine/ActionStateMachine.cpp b/sdk/applications/actionstatemachine/ActionStateMachine.cpp index 0009fdcb..00e16d15 100644 --- a/sdk/applications/actionstatemachine/ActionStateMachine.cpp +++ b/sdk/applications/actionstatemachine/ActionStateMachine.cpp @@ -154,12 +154,12 @@ void ActionStateMachine::autoNext() { void ActionStateMachine::initMainWindow() { mainWindow = new MainWindow(name); - mainWindow->setCentralViewer(MedicalImageViewer::getInstance()); + mainWindow->setCentralViewer(Application::getViewer("MedicalImageViewer")); mainWindow->addDockViewer(Qt::RightDockWidgetArea, ActionStateViewer::getActionStateViewer()); - mainWindow->addDockViewer(Qt::LeftDockWidgetArea, Explorer::getInstance()); + mainWindow->addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); // never show the toolbar - MedicalImageViewer::getInstance()->setToolbarAutoVisibility(false); + Application::getViewer("MedicalImageViewer")->setToolbarAutoVisibility(false); mainWindow->showStatusBar(true); this->setMainWindow(mainWindow); diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.cpp b/sdk/applications/actionstatemachine/ActionStateViewer.cpp index 57a5b671..05f74594 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewer.cpp @@ -37,17 +37,8 @@ /// the register containing all the viewers (static instantiation, global variable, but global only for this file) ActionStateViewer* ActionStateViewer::actionStateViewer; -// ---------------- getActionStateViewer ---------------- -ActionStateViewer* ActionStateViewer::getActionStateViewer() { - if (!actionStateViewer) { - actionStateViewer = new ActionStateViewer(); - } - - return actionStateViewer; -} - // ---------------- constructor ---------------- -ActionStateViewer::ActionStateViewer() : Viewer("Current State") { +ActionStateViewer::ActionStateViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { myWidget = nullptr; } diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.h b/sdk/applications/actionstatemachine/ActionStateViewer.h index 9635bdf6..a0a0874b 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.h +++ b/sdk/applications/actionstatemachine/ActionStateViewer.h @@ -25,6 +25,8 @@ #ifndef ACTIONSTATEVIEWER_H #define ACTIONSTATEVIEWER_H +#include + // Qt stuff #include #include @@ -46,8 +48,8 @@ class ActionStateViewer : public camitk::Viewer { Q_OBJECT public: - /// returns the unique instance oh ActionStateViewer - static ActionStateViewer* getActionStateViewer(); + + ActionStateViewer(ViewerExtension* extension, QString name); /// get the viewer widget. @param parent the parent widget for the viewer widget virtual QWidget* getWidget(QWidget* parent = nullptr); @@ -64,7 +66,6 @@ public: void setState(ActionState* actionState); private: - ActionStateViewer(); /// the singleton ActionStateViewer instance static ActionStateViewer* actionStateViewer; diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 6eccc8d0..14b3a066 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -71,22 +71,22 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { updateOpenDirectoryMenu(); // now add the different viewers - setCentralViewer(MedicalImageViewer::getInstance()); - addDockViewer(Qt::LeftDockWidgetArea, Explorer::getInstance()); - addDockViewer(Qt::LeftDockWidgetArea, FrameExplorer::getInstance()); - addDockViewer(Qt::LeftDockWidgetArea, PropertyExplorer::getInstance()); - addDockViewer(Qt::RightDockWidgetArea, ActionViewer::getInstance()); + setCentralViewer(Application::getViewer("MedicalImageViewer")); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("FrameExplorer")); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("PropertyExplorer")); + addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionViewer")); //Merge Explorer and FrameExplorer viewers in one layout - QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Explorer::getInstance(), NULL); - QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(FrameExplorer::getInstance(), NULL); + QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); + QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); if (dockWidgetExplorer && dockWidgetFrameExplorer) { tabifyDockWidget(dockWidgetExplorer, dockWidgetFrameExplorer); dockWidgetExplorer->raise(); } - showDockViewer(ActionViewer::getInstance(), false); - ActionViewer::getInstance()->setSearchPanelVisible(true); + showDockViewer(Application::getViewer("ActionViewer"), false); + Application::getViewer("ActionViewer")->setSearchPanelVisible(true); showStatusBar(true); } @@ -382,33 +382,33 @@ void ImpMainWindow::showStatusBar(bool b) { // ------------------------ resetWindows ---------------------------- void ImpMainWindow::resetWindows() { for (QMap::iterator it = dockWidgetMap.begin(); it != dockWidgetMap.end(); it++) { - if (it.value()->widget() == Explorer::getInstance()->getWidget(NULL)) { + if (it.value()->widget() == Application::getViewer("Explorer")->getWidget(NULL)) { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } else - if (it.value()->widget() == FrameExplorer::getInstance()->getWidget(NULL)) { + if (it.value()->widget() == Application::getViewer("FrameExplorer")->getWidget(NULL)) { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } else - if (it.value()->widget() == PropertyExplorer::getInstance()->getWidget()) { + if (it.value()->widget() == Application::getViewer("PropertyExplorer")->getWidget()) { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } else - if (it.value()->widget() == ActionViewer::getInstance()->getWidget()) { + if (it.value()->widget() == Application::getViewer("ActionViewer")->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); - QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(FrameExplorer::getInstance(), NULL); + QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); + QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); if (dockWidgetExplorer && dockWidgetFrameExplorer) { tabifyDockWidget(dockWidgetExplorer, dockWidgetFrameExplorer); dockWidgetExplorer->raise(); diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index 417b985e..fa2a402a 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -752,6 +752,8 @@ int Application::registerAllViewers(ViewerExtension* ext) { .arg(viewer->getName(), viewer->getDescription())) } else { + cout << typeid(viewer).name() << endl; + //viewerExtensionMap.insert(); getViewerMap().insert(viewer->getName(), viewer); registered++; } @@ -865,12 +867,6 @@ ActionList Application::getActions(ComponentList selComp, QString tag) { } -// ---------------- getViewer ---------------- -template -T* Application::getViewer(QString name) { - return dynamic_cast(getViewerMap().value(name)); -} - // -------------------- getViewers -------------------- const ViewerList Application::getViewers() { return getViewerMap().values(); diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index c9f3a11f..28398e6f 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -260,8 +260,18 @@ public: ///@} /// get a registered viewer given its name - template - static T* getViewer(QString); + template + static T* getViewer(QString name) { + return dynamic_cast(getViewerMap().value(name)); + } + + template + static void addViewer(QString name) { + typeof(T).Name; + T* viewer = new T(); + getViewerMap().insert(name, viewer); + registered++; + } /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); @@ -391,6 +401,8 @@ private: /// argv given from command line static char** argv; + static QMap viewerExtensionMap; + /// @name Recent document management ///@{ /// list of all the remembered recent documents (last opened is last inserted!) diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp b/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp index 930e3af0..a46a992d 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp @@ -141,7 +141,6 @@ InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, // ---------------------- destructor ---------------------------- InteractiveViewer::~InteractiveViewer() { - viewers.remove(this->getName()); delete viewerMenu; viewerMenu = nullptr; diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewer.h b/sdk/libraries/core/viewer/interactive/InteractiveViewer.h index a20291a8..a40a9407 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/interactive/InteractiveViewer.h @@ -334,9 +334,6 @@ protected: */ InteractiveViewer(QString& name, ViewerType type); - /// the map containing all the InteractiveViewer instances - static QMap viewers; - /// the QString array containing all InteractiveViewer instance default names static std::array defaultNames; -- GitLab From 2335b7c8a4a9accedd47d64f8a16f4a7a60e9693 Mon Sep 17 00:00:00 2001 From: calkam Date: Tue, 24 Dec 2019 12:47:39 +0100 Subject: [PATCH 06/26] Change of directory viewer extension and create API --- sdk/actions/application/CMakeLists.txt | 1 + sdk/actions/frame/editframes/CMakeLists.txt | 1 + .../image/pixelcolorchanger/CMakeLists.txt | 1 + .../image/reorientimage/CMakeLists.txt | 1 + sdk/actions/image/showin3d/CMakeLists.txt | 1 + .../image/volumerendering/CMakeLists.txt | 1 + sdk/actions/mesh/basicmesh/CMakeLists.txt | 1 + .../mesh/meshprocessing/CMakeLists.txt | 1 + .../actionstatemachine/ActionStateMachine.cpp | 4 +- .../actionstatemachine/ActionStateViewer.cpp | 7 +- .../actionstatemachine/ActionStateViewer.h | 5 +- .../ActionStateViewerExtension.cpp | 36 ++++++++++ .../ActionStateViewerExtension.h | 61 +++++++++++++++++ .../actionstatemachine/ActionTransition.cpp | 2 +- .../actionstatemachine/CMakeLists.txt | 1 + sdk/applications/imp/CMakeLists.txt | 1 + sdk/applications/wizard/CMakeLists.txt | 1 + sdk/libraries/core/CMakeLists.txt | 8 +-- sdk/libraries/core/ExtensionManager.cpp | 1 - .../core/component/image/ImageComponent.cpp | 1 - .../viewer/interactiveviewer/CMakeLists.txt | 8 +++ .../InteractiveViewer.cpp | 11 +--- .../InteractiveViewer.h | 65 ++++++++++--------- .../interactiveviewer/InteractiveViewerAPI.h | 9 +++ .../InteractiveViewerExtension.cpp | 4 -- .../InteractiveViewerExtension.h | 7 +- .../RendererWidget.cpp | 7 +- .../RendererWidget.h | 11 +--- .../vtkInteractorStylePick.cpp | 7 +- .../vtkInteractorStylePick.h | 2 - sdk/viewers/CMakeLists.txt | 18 +++++ .../actionviewer}/ActionViewer.cpp | 5 +- .../actionviewer}/ActionViewer.h | 18 ++--- sdk/viewers/actionviewer/ActionViewerAPI.h | 9 +++ .../actionviewer}/ActionViewerExtension.cpp | 4 -- .../actionviewer}/ActionViewerExtension.h | 7 +- .../actionviewer}/CMakeLists.txt | 4 +- sdk/viewers/explorer/CMakeLists.txt | 8 +++ .../viewer => viewers}/explorer/Explorer.cpp | 5 +- .../viewer => viewers}/explorer/Explorer.h | 38 +++++------ sdk/viewers/explorer/ExplorerAPI.h | 9 +++ .../explorer/ExplorerExtension.cpp | 4 -- .../explorer/ExplorerExtension.h | 7 +- sdk/viewers/frameexplorer/CMakeLists.txt | 8 +++ .../frameexplorer/FrameExplorer.cpp | 8 +-- .../frameexplorer/FrameExplorer.h | 21 +++--- sdk/viewers/frameexplorer/FrameExplorerAPI.h | 9 +++ .../frameexplorer/FrameExplorerExtension.cpp | 4 -- .../frameexplorer/FrameExplorerExtension.h | 7 +- sdk/viewers/medicalimageviewer/CMakeLists.txt | 8 +++ .../MedicalImageViewer.cpp | 4 +- .../medicalimageviewer}/MedicalImageViewer.h | 15 ++--- .../MedicalImageViewerAPI.h | 9 +++ .../MedicalImageViewerExtension.cpp | 4 -- .../MedicalImageViewerExtension.h | 7 +- sdk/viewers/propertyexplorer/CMakeLists.txt | 8 +++ .../propertyexplorer/PropertyExplorer.cpp | 7 +- .../propertyexplorer/PropertyExplorer.h | 24 +++---- .../propertyexplorer/PropertyExplorerAPI.h | 9 +++ .../PropertyExplorerExtension.cpp | 4 -- .../PropertyExplorerExtension.h | 7 +- 61 files changed, 349 insertions(+), 217 deletions(-) create mode 100644 sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp create mode 100644 sdk/applications/actionstatemachine/ActionStateViewerExtension.h create mode 100644 sdk/libraries/core/viewer/interactiveviewer/CMakeLists.txt rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/InteractiveViewer.cpp (99%) rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/InteractiveViewer.h (93%) create mode 100644 sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/InteractiveViewerExtension.cpp (98%) rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/InteractiveViewerExtension.h (93%) rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/RendererWidget.cpp (99%) rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/RendererWidget.h (99%) rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/vtkInteractorStylePick.cpp (99%) rename sdk/libraries/core/viewer/{interactive => interactiveviewer}/vtkInteractorStylePick.h (98%) create mode 100644 sdk/viewers/CMakeLists.txt rename sdk/{libraries/core/viewer/action => viewers/actionviewer}/ActionViewer.cpp (99%) rename sdk/{libraries/core/viewer/action => viewers/actionviewer}/ActionViewer.h (92%) create mode 100644 sdk/viewers/actionviewer/ActionViewerAPI.h rename sdk/{libraries/core/viewer/action => viewers/actionviewer}/ActionViewerExtension.cpp (98%) rename sdk/{libraries/core/viewer/action => viewers/actionviewer}/ActionViewerExtension.h (93%) rename sdk/{libraries/core/viewer/action => viewers/actionviewer}/CMakeLists.txt (72%) create mode 100644 sdk/viewers/explorer/CMakeLists.txt rename sdk/{libraries/core/viewer => viewers}/explorer/Explorer.cpp (99%) rename sdk/{libraries/core/viewer => viewers}/explorer/Explorer.h (85%) create mode 100644 sdk/viewers/explorer/ExplorerAPI.h rename sdk/{libraries/core/viewer => viewers}/explorer/ExplorerExtension.cpp (98%) rename sdk/{libraries/core/viewer => viewers}/explorer/ExplorerExtension.h (93%) create mode 100644 sdk/viewers/frameexplorer/CMakeLists.txt rename sdk/{libraries/core/viewer => viewers}/frameexplorer/FrameExplorer.cpp (99%) rename sdk/{libraries/core/viewer => viewers}/frameexplorer/FrameExplorer.h (89%) create mode 100644 sdk/viewers/frameexplorer/FrameExplorerAPI.h rename sdk/{libraries/core/viewer => viewers}/frameexplorer/FrameExplorerExtension.cpp (98%) rename sdk/{libraries/core/viewer => viewers}/frameexplorer/FrameExplorerExtension.h (93%) create mode 100644 sdk/viewers/medicalimageviewer/CMakeLists.txt rename sdk/{libraries/core/viewer/medicalimage => viewers/medicalimageviewer}/MedicalImageViewer.cpp (99%) rename sdk/{libraries/core/viewer/medicalimage => viewers/medicalimageviewer}/MedicalImageViewer.h (95%) create mode 100644 sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h rename sdk/{libraries/core/viewer/medicalimage => viewers/medicalimageviewer}/MedicalImageViewerExtension.cpp (98%) rename sdk/{libraries/core/viewer/medicalimage => viewers/medicalimageviewer}/MedicalImageViewerExtension.h (93%) create mode 100644 sdk/viewers/propertyexplorer/CMakeLists.txt rename sdk/{libraries/core/viewer => viewers}/propertyexplorer/PropertyExplorer.cpp (99%) rename sdk/{libraries/core/viewer => viewers}/propertyexplorer/PropertyExplorer.h (92%) create mode 100644 sdk/viewers/propertyexplorer/PropertyExplorerAPI.h rename sdk/{libraries/core/viewer => viewers}/propertyexplorer/PropertyExplorerExtension.cpp (98%) rename sdk/{libraries/core/viewer => viewers}/propertyexplorer/PropertyExplorerExtension.h (93%) diff --git a/sdk/actions/application/CMakeLists.txt b/sdk/actions/application/CMakeLists.txt index 288e7689..894ed42e 100644 --- a/sdk/actions/application/CMakeLists.txt +++ b/sdk/actions/application/CMakeLists.txt @@ -1,6 +1,7 @@ camitk_extension(ACTION_EXTENSION DEFINES COMPILE_APPLICATION_ACTION_API CEP_NAME SDK + NEEDS_VIEWER_EXTENSION medicalimageviewer DESCRIPTION "Features actions used at aplication level (these actions are mandatory for any CamiTK appliction to work)" ) diff --git a/sdk/actions/frame/editframes/CMakeLists.txt b/sdk/actions/frame/editframes/CMakeLists.txt index a0db214f..d975d7c7 100644 --- a/sdk/actions/frame/editframes/CMakeLists.txt +++ b/sdk/actions/frame/editframes/CMakeLists.txt @@ -2,6 +2,7 @@ camitk_extension(ACTION_EXTENSION DESCRIPTION "Manipulating Frames." ENABLE_AUTO_TEST + NEEDS_VIEWER_EXTENSION interactiveviewer TEST_FILES brain.mha structured.vtk ) diff --git a/sdk/actions/image/pixelcolorchanger/CMakeLists.txt b/sdk/actions/image/pixelcolorchanger/CMakeLists.txt index 5d27e4d5..26c2f6c5 100644 --- a/sdk/actions/image/pixelcolorchanger/CMakeLists.txt +++ b/sdk/actions/image/pixelcolorchanger/CMakeLists.txt @@ -1,5 +1,6 @@ # Call CamiTK CMake Macro to define the action camitk_extension(ACTION_EXTENSION + NEEDS_VIEWER_EXTENSION interactiveviewer DEFINES COMPILE_PIXELCOLORCHANGER_ACTION_API CEP_NAME SDK DESCRIPTION "Allows changing the color of the image pixels" diff --git a/sdk/actions/image/reorientimage/CMakeLists.txt b/sdk/actions/image/reorientimage/CMakeLists.txt index 5bddcd30..e1efd02a 100644 --- a/sdk/actions/image/reorientimage/CMakeLists.txt +++ b/sdk/actions/image/reorientimage/CMakeLists.txt @@ -1,6 +1,7 @@ # Call CamiTK CMake Macro to define the action camitk_extension(ACTION_EXTENSION NEEDS_COMPONENT_EXTENSION vtkmesh + NEEDS_VIEWER_EXTENSION interactiveviewer CEP_NAME SDK DESCRIPTION "Allows one to reorient a volumic image." ENABLE_AUTO_TEST diff --git a/sdk/actions/image/showin3d/CMakeLists.txt b/sdk/actions/image/showin3d/CMakeLists.txt index 20477a4c..b65d93a0 100644 --- a/sdk/actions/image/showin3d/CMakeLists.txt +++ b/sdk/actions/image/showin3d/CMakeLists.txt @@ -1,4 +1,5 @@ camitk_extension(ACTION_EXTENSION + NEEDS_VIEWER_EXTENSION interactiveviewer CEP_NAME SDK DESCRIPTION "Display in 3D the component" ENABLE_AUTO_TEST diff --git a/sdk/actions/image/volumerendering/CMakeLists.txt b/sdk/actions/image/volumerendering/CMakeLists.txt index 6fd90a6c..67dd4f10 100644 --- a/sdk/actions/image/volumerendering/CMakeLists.txt +++ b/sdk/actions/image/volumerendering/CMakeLists.txt @@ -1,5 +1,6 @@ camitk_extension(ACTION_EXTENSION NEEDS_QTXML + NEEDS_VIEWER_EXTENSION interactiveviewer DEFINES COMPILE_VOLUME_RENDERING_ACTION_API CEP_NAME SDK DESCRIPTION "Use ray tracing to produce a 3D reprensation of the image" diff --git a/sdk/actions/mesh/basicmesh/CMakeLists.txt b/sdk/actions/mesh/basicmesh/CMakeLists.txt index 89b936f9..5883c65f 100644 --- a/sdk/actions/mesh/basicmesh/CMakeLists.txt +++ b/sdk/actions/mesh/basicmesh/CMakeLists.txt @@ -2,6 +2,7 @@ camitk_extension(ACTION_EXTENSION DEFINES COMPILE_BASIC_MESH_ACTION_API CEP_NAME SDK DESCRIPTION "Provides basic actions on meshes" + NEEDS_VIEWER_EXTENSION interactiveviewer ENABLE_AUTO_TEST TEST_FILES brain.mha bassin.msh liver-smooth.obj Mesh.off robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk cube-with-point-and-cell-data.vtk fieldfile.vtk check-with-color-pointdata.vtk plate-with-data.vtk female.vtk brainImageSmooth.vtk structuredgrid-with-data.vtk male.vtk cube-with-tensors.vtk imageBoundingBox.vtk binary-mesh-with-pointdata.vtk unstructured_binary_with_celldata.vtk ) diff --git a/sdk/actions/mesh/meshprocessing/CMakeLists.txt b/sdk/actions/mesh/meshprocessing/CMakeLists.txt index bbd49baa..16bc7c13 100644 --- a/sdk/actions/mesh/meshprocessing/CMakeLists.txt +++ b/sdk/actions/mesh/meshprocessing/CMakeLists.txt @@ -1,5 +1,6 @@ camitk_extension(ACTION_EXTENSION NEEDS_COMPONENT_EXTENSION vtkmesh + NEEDS_VIEWER_EXTENSION interactiveviewer DEFINES COMPILE_MESHPROCESSING_ACTION_API CEP_NAME SDK DESCRIPTION "Features some nice algorithms for mesh processing" diff --git a/sdk/applications/actionstatemachine/ActionStateMachine.cpp b/sdk/applications/actionstatemachine/ActionStateMachine.cpp index 00e16d15..c7028025 100644 --- a/sdk/applications/actionstatemachine/ActionStateMachine.cpp +++ b/sdk/applications/actionstatemachine/ActionStateMachine.cpp @@ -155,7 +155,7 @@ void ActionStateMachine::initMainWindow() { mainWindow = new MainWindow(name); mainWindow->setCentralViewer(Application::getViewer("MedicalImageViewer")); - mainWindow->addDockViewer(Qt::RightDockWidgetArea, ActionStateViewer::getActionStateViewer()); + mainWindow->addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionStateViewer")); mainWindow->addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); // never show the toolbar @@ -231,7 +231,7 @@ QString ActionStateMachine::parseSCXMLTree() { QString initialStateName = scxmlDoc.documentElement().attribute("initial"); ActionState* initialState = statesMap->find(initialStateName).value(); machine.setInitialState(initialState); - ActionStateViewer::getActionStateViewer()->setState(initialState); + Application::getViewer("ActionStateViewer")->setState(initialState); // Connect the end of the machine with the end of the application QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit())); diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.cpp b/sdk/applications/actionstatemachine/ActionStateViewer.cpp index 05f74594..ae2c247f 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewer.cpp @@ -33,14 +33,9 @@ // Local includes #include "ActionStateViewer.h" -// ---------------------- singleton ---------------------------- -/// the register containing all the viewers (static instantiation, global variable, but global only for this file) -ActionStateViewer* ActionStateViewer::actionStateViewer; - // ---------------- constructor ---------------- -ActionStateViewer::ActionStateViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +ActionStateViewer::ActionStateViewer(camitk::ViewerExtension* extension, QString name) : Viewer(extension, name) { myWidget = nullptr; - } // ---------------- getWidget ---------------- diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.h b/sdk/applications/actionstatemachine/ActionStateViewer.h index a0a0874b..de9cb04e 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.h +++ b/sdk/applications/actionstatemachine/ActionStateViewer.h @@ -49,7 +49,7 @@ class ActionStateViewer : public camitk::Viewer { public: - ActionStateViewer(ViewerExtension* extension, QString name); + ActionStateViewer(camitk::ViewerExtension* extension, QString name); /// get the viewer widget. @param parent the parent widget for the viewer widget virtual QWidget* getWidget(QWidget* parent = nullptr); @@ -67,9 +67,6 @@ public: private: - /// the singleton ActionStateViewer instance - static ActionStateViewer* actionStateViewer; - QWidget* myWidget; QString name; diff --git a/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp b/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp new file mode 100644 index 00000000..41e03ff1 --- /dev/null +++ b/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp @@ -0,0 +1,36 @@ +/***************************************************************************** + * $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 "ActionStateViewerExtension.h" + +// include generated actions headers +#include "ActionStateViewer.h" + +// --------------- getActions ------------------- +void ActionStateViewerExtension::init() { + registerNewViewer(ActionStateViewer); +} + diff --git a/sdk/applications/actionstatemachine/ActionStateViewerExtension.h b/sdk/applications/actionstatemachine/ActionStateViewerExtension.h new file mode 100644 index 00000000..ce85ad03 --- /dev/null +++ b/sdk/applications/actionstatemachine/ActionStateViewerExtension.h @@ -0,0 +1,61 @@ +/***************************************************************************** + * $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 ACTION_STATE_VIEWER_EXTENSION_H +#define ACTION_STATE_VIEWER_EXTENSION_H + +#include + +class ActionStateViewerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionstatemachine.viewer.actionstateviewerextension") + +public: + /// Constructor + ActionStateViewerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~ActionStateViewerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Action State Viewer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "This extension provides Action State Viewer"; + }; + + /// initialize all the actions + virtual void init(); + +}; + +#endif // ACTION_STATE_VIEWER_EXTENSION_H + + diff --git a/sdk/applications/actionstatemachine/ActionTransition.cpp b/sdk/applications/actionstatemachine/ActionTransition.cpp index f9f61b7d..17a4ad98 100644 --- a/sdk/applications/actionstatemachine/ActionTransition.cpp +++ b/sdk/applications/actionstatemachine/ActionTransition.cpp @@ -132,7 +132,7 @@ void ActionTransition::onTransition(QEvent* e) { if (nextActionState) { nextActionState->setPreviousActionStatus(status); - ActionStateViewer::getActionStateViewer()->setState(nextActionState); + Application::getViewer("ActionStateViewer")->setState(nextActionState); } if (logStream != nullptr) { diff --git a/sdk/applications/actionstatemachine/CMakeLists.txt b/sdk/applications/actionstatemachine/CMakeLists.txt index 23268722..40f57dc7 100644 --- a/sdk/applications/actionstatemachine/CMakeLists.txt +++ b/sdk/applications/actionstatemachine/CMakeLists.txt @@ -2,6 +2,7 @@ camitk_application(NEEDS_QT_MODULES #we use QtXML ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx CEP_NAME SDK + NEEDS_VIEWER_EXTENSION explorer medicalimageviewer DESCRIPTION "Simple action state machine to pipeline actions from an XML file" ) diff --git a/sdk/applications/imp/CMakeLists.txt b/sdk/applications/imp/CMakeLists.txt index ee84d18b..c04549e5 100644 --- a/sdk/applications/imp/CMakeLists.txt +++ b/sdk/applications/imp/CMakeLists.txt @@ -1,5 +1,6 @@ camitk_application( ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx CEP_NAME SDK + NEEDS_VIEWER_EXTENSION actionviewer explorer medicalimageviewer propertyexplorer frameexplorer DESCRIPTION "All-in-one application to load actions and component and interact with them" ) diff --git a/sdk/applications/wizard/CMakeLists.txt b/sdk/applications/wizard/CMakeLists.txt index 3aec6ed5..d4fa21b8 100644 --- a/sdk/applications/wizard/CMakeLists.txt +++ b/sdk/applications/wizard/CMakeLists.txt @@ -1,6 +1,7 @@ camitk_application(NEEDS_XSD NEEDS_XERCESC NEEDS_CEP_LIBRARIES cepgenerator cepcoreschema + NEEDS_VIEWER_EXTENSION explorer CEP_NAME SDK ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx DESCRIPTION "Create CEP and file skeletons from GUI" diff --git a/sdk/libraries/core/CMakeLists.txt b/sdk/libraries/core/CMakeLists.txt index d9b9cdb0..8009bb3e 100644 --- a/sdk/libraries/core/CMakeLists.txt +++ b/sdk/libraries/core/CMakeLists.txt @@ -19,12 +19,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/operators ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/viewer - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/action - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/explorer - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/frameexplorer - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/interactive - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/medicalimage - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/propertyexplorer + ${CMAKE_CURRENT_SOURCE_DIR}/viewer/interactiveviewer ${CAMITK_INCLUDE_DIRECTORIES} ) @@ -159,3 +154,4 @@ set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_ set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/component/mesh CACHE INTERNAL "") set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/utils CACHE INTERNAL "") set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer CACHE INTERNAL "") +set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer/interactiveviewer CACHE INTERNAL "") \ No newline at end of file diff --git a/sdk/libraries/core/ExtensionManager.cpp b/sdk/libraries/core/ExtensionManager.cpp index 30f0844f..066aa6b3 100644 --- a/sdk/libraries/core/ExtensionManager.cpp +++ b/sdk/libraries/core/ExtensionManager.cpp @@ -180,7 +180,6 @@ bool ExtensionManager::loadExtension(ExtensionManager::ExtensionType type, QStri switch (type) { case ACTION: { ActionExtension* ext = qobject_cast (extension); - if (ext) { ext->setLocation(fileName); ext->initResources(); diff --git a/sdk/libraries/core/component/image/ImageComponent.cpp b/sdk/libraries/core/component/image/ImageComponent.cpp index 4b6f4c4c..6155ff43 100644 --- a/sdk/libraries/core/component/image/ImageComponent.cpp +++ b/sdk/libraries/core/component/image/ImageComponent.cpp @@ -32,7 +32,6 @@ // -- Core stuff #include "InteractiveViewer.h" -#include "PropertyExplorer.h" #include "MeshComponent.h" #include "Property.h" #include "Frame.h" diff --git a/sdk/libraries/core/viewer/interactiveviewer/CMakeLists.txt b/sdk/libraries/core/viewer/interactiveviewer/CMakeLists.txt new file mode 100644 index 00000000..d834e577 --- /dev/null +++ b/sdk/libraries/core/viewer/interactiveviewer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_INTERACTIVEVIEWER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.cpp similarity index 99% rename from sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp rename to sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.cpp index a46a992d..e4e3e7c6 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.cpp @@ -80,7 +80,7 @@ #include -namespace camitk { +using namespace camitk; // ---------------------- constructor ---------------------------- InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, ViewerType type) : Viewer(extension, name) { @@ -2304,11 +2304,4 @@ void InteractiveViewerFrame::keyPressEvent(QKeyEvent* e) { // CMake automoc generates a camitk namespace error on this moc // for the RendererWidget member of the InteractiveViewer class. // By including it, the file kept out library-camitkcore_automoc.cpp -#include "moc_InteractiveViewer.cpp" - -} - - - - - +#include "moc_InteractiveViewer.cpp" \ No newline at end of file diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewer.h b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.h similarity index 93% rename from sdk/libraries/core/viewer/interactive/InteractiveViewer.h rename to sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.h index a40a9407..be7e0e13 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.h @@ -28,8 +28,9 @@ #define INTERACTIVE_VIEWER_H // -- Core stuff -#include "CamiTKAPI.h" +#include "InteractiveViewerAPI.h" #include "Component.h" +#include "ViewerExtension.h" #include "Viewer.h" #include "RendererWidget.h" @@ -53,20 +54,22 @@ class vtkCamera; class vtkEventQtSlotConnect; namespace camitk { -// -- Core stuff classes -class SliderSpinBoxWidget; -class GeometricObject; -class InterfaceGeometry; -class InterfaceBitMap; + // -- Core stuff classes + class SliderSpinBoxWidget; + class GeometricObject; + class InterfaceGeometry; + class InterfaceBitMap; + class MeshDataFilterModel; + class PropertyObject; + class Property; +} + class InteractiveViewer; -class MeshDataFilterModel; -class PropertyObject; -class Property; using vtkSmartPointerCamera = vtkSmartPointer; /// InteractiveViewerFrame is just a QFrame that delegates all key events to its InteractiveViewer -class CAMITK_API InteractiveViewerFrame : public QFrame { +class INTERACTIVEVIEWER_API InteractiveViewerFrame : public QFrame { public: /// default constructor InteractiveViewerFrame(QWidget* parent, InteractiveViewer* s3D) : QFrame(parent), myInteractiveViewer(s3D) {} @@ -137,7 +140,7 @@ protected: * */ -class CAMITK_API InteractiveViewer : public Viewer { +class INTERACTIVEVIEWER_API InteractiveViewer : public camitk::Viewer { Q_OBJECT Q_ENUMS(HighlightMode RendererWidget::ControlMode RendererWidget::CameraOrientation) // so that it can be used in property editor @@ -169,7 +172,7 @@ public: SELECTION_ONLY ///< the selected Components are in default mode, the non-selected are hidden }; - InteractiveViewer(ViewerExtension * extension, QString & name, ViewerType type=SLICE_VIEWER); + InteractiveViewer(camitk::ViewerExtension * extension, QString & name, ViewerType type=SLICE_VIEWER); /** Destructor */ ~InteractiveViewer() override; @@ -185,7 +188,7 @@ public: unsigned int numberOfViewedComponent() override; /// Refresh the display. - void refresh(Viewer* whoIsAsking = nullptr) override; + void refresh(camitk::Viewer* whoIsAsking = nullptr) override; /// get the InteractiveViewer widget (QTreeWidget). @param parent the parent widget for the viewer widget QWidget* getWidget(QWidget* parent) override; @@ -362,16 +365,16 @@ protected: void toggleInterpolation(); /// Update the display of the given Component, according to its selection state and the current HighlightMode. - void updateSelectionDisplay(Component*); + void updateSelectionDisplay(camitk::Component*); /// the map containing all the actors in the InteractiveViewer - QMultiMap > actorMap; + QMultiMap > actorMap; /// add the given actor of the given Component to the renderer and insert it in the map - void addActor(Component*, vtkSmartPointer); + void addActor(camitk::Component*, vtkSmartPointer); /// remove all the given Component actors from the renderer and delete comp from the map - void removeAllActors(Component*); + void removeAllActors(camitk::Component*); /// number of top-level component that are currently displayed unsigned int displayedTopLevelComponents; @@ -384,11 +387,11 @@ protected: */ /// @{ /// The 3D scene itself, wrapping VTK render window, renderer and interactor in a single Qt widget - RendererWidget* rendererWidget; + RendererWidget* rendererWidget; /** Slider used to control the slice index in a InteractiveViewer. This slider is visible only when * the scene a 2D viewer (see constructor). */ - SliderSpinBoxWidget* sliceSlider; + camitk::SliderSpinBoxWidget* sliceSlider; /// the InteractiveViewer frame InteractiveViewerFrame* frame; @@ -411,7 +414,7 @@ protected: /// the ComboBox for mesh scalar data QComboBox* scalarDataComboBox; - MeshDataFilterModel* scalarDataModel; + camitk::MeshDataFilterModel* scalarDataModel; /// init all the actions (called only once in the getWidget() method) void initActions(); @@ -484,7 +487,7 @@ protected: * but for speed optimization that are not yet selected in the explorer. * They will all be selected in the explorer when the user release the mouse button. */ - std::vector pickedComponent; + std::vector pickedComponent; /** Current picking mode, NO_PICKING be default. */ PickingMode pickingMode; @@ -534,42 +537,42 @@ protected: /** * The property object that holds the properties of this viewer */ - PropertyObject* propertyObject; + camitk::PropertyObject* propertyObject; /** * The property that stands for the type of highlight mode of the 3D viewer. */ - Property* highlightModeProperty; + camitk::Property* highlightModeProperty; /** * The property that stands for the background color of the viewer. */ - Property* backgroundColorProperty; + camitk::Property* backgroundColorProperty; /** * Property that tells whether the viewer use a gradient background color or not. */ - Property* backgroundGradientColorProperty; + camitk::Property* backgroundGradientColorProperty; /** * Property that tells whether the viewer uses lines as tubes or not. */ - Property* linesAsTubesProperty; + camitk::Property* linesAsTubesProperty; /** * Property that tells whether the viewer uses the backface culling option or not. */ - Property* backfaceCullingProperty; + camitk::Property* backfaceCullingProperty; /** * Property that tells whether the screenshot action is visible or not. */ - Property* screenshotActionProperty; + camitk::Property* screenshotActionProperty; /** * Property which defines the point size of each point in the 3D viewer. */ - Property* pointSizeProperty; + camitk::Property* pointSizeProperty; /** * Create and handle the CamiTK properties of this viewer. @@ -623,9 +626,7 @@ protected slots: }; -} - -Q_DECLARE_METATYPE(camitk::InteractiveViewer::HighlightMode) +Q_DECLARE_METATYPE(InteractiveViewer::HighlightMode) #endif diff --git a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h new file mode 100644 index 00000000..ad6175e0 --- /dev/null +++ b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h @@ -0,0 +1,9 @@ +#if defined(_WIN32) // MSVC and mingw +#ifdef COMPILE_INTERACTIVEVIEWER_API +#define INTERACTIVEVIEWER_API __declspec(dllexport) +#else +#define INTERACTIVEVIEWER_API __declspec(dllimport) +#endif // COMPILE_INTERACTIVEVIEWER_API +#else // for all other platforms INTERACTIVEVIEWER_API is defined to be "nothing" +#define INTERACTIVEVIEWER_API +#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.cpp similarity index 98% rename from sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp rename to sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.cpp index c317f13a..93404aa6 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.cpp +++ b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.cpp @@ -29,8 +29,6 @@ // include generated actions headers #include "InteractiveViewer.h" -namespace camitk { - // --------------- getViewers ------------------- void InteractiveViewerExtension::init() { registerNewViewer(InteractiveViewer, "3DViewer"); @@ -39,5 +37,3 @@ void InteractiveViewerExtension::init() { registerNewViewer(InteractiveViewer, "arbitraryViewer"); } -} - diff --git a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.h similarity index 93% rename from sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h rename to sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.h index 83375d3a..dabfa61c 100644 --- a/sdk/libraries/core/viewer/interactive/InteractiveViewerExtension.h +++ b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.h @@ -27,13 +27,11 @@ #ifndef INTERACTIVEVIEWEREXTENSION_H #define INTERACTIVEVIEWEREXTENSION_H -#include "CamiTKAPI.h" +#include "InteractiveViewerAPI.h" #include "ViewerExtension.h" -namespace camitk { - -class CAMITK_API InteractiveViewerExtension : public camitk::ViewerExtension { +class INTERACTIVEVIEWER_API InteractiveViewerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); @@ -58,7 +56,6 @@ public: virtual void init(); }; -} #endif // INTERACTIVEVIEWEREXTENSION_H diff --git a/sdk/libraries/core/viewer/interactive/RendererWidget.cpp b/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.cpp similarity index 99% rename from sdk/libraries/core/viewer/interactive/RendererWidget.cpp rename to sdk/libraries/core/viewer/interactiveviewer/RendererWidget.cpp index 1f1ba75b..9c6e4015 100644 --- a/sdk/libraries/core/viewer/interactive/RendererWidget.cpp +++ b/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.cpp @@ -122,8 +122,6 @@ Q_COREAPP_STARTUP_FUNCTION(initialize) #endif -namespace camitk { - // static instantiation (global variable, global only for this file) QMap screenshotMap; @@ -1475,7 +1473,4 @@ void RendererWidget::setPicker(vtkSmartPointer woodyWood) // I know, it is really Woody Wood Pecker, but you know, with a french accent... GetInteractor()->SetPicker(woodyWood); } -} - - -} +} \ No newline at end of file diff --git a/sdk/libraries/core/viewer/interactive/RendererWidget.h b/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.h similarity index 99% rename from sdk/libraries/core/viewer/interactive/RendererWidget.h rename to sdk/libraries/core/viewer/interactiveviewer/RendererWidget.h index 7e9a0908..95e35e10 100644 --- a/sdk/libraries/core/viewer/interactive/RendererWidget.h +++ b/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.h @@ -31,7 +31,7 @@ #endif // -- Core stuff -#include "CamiTKAPI.h" +#include "InteractiveViewerAPI.h" // -- VTK stuff #include @@ -73,9 +73,6 @@ class vtkScalarBarWidget; class vtkTextMapper; class vtkAbstractPropPicker; - -namespace camitk { - class vtkInteractorStylePick; /** @@ -97,7 +94,7 @@ class vtkInteractorStylePick; * **/ #if VTK_MAJOR_VERSION == 6 -class CAMITK_API RendererWidget : public QVTKWidget2 { +class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget2 { #elif VTK_MAJOR_VERSION == 7 class CAMITK_API RendererWidget : public QVTKWidget { @@ -480,7 +477,7 @@ protected : bool pickingDiverter; /// picking interactor - vtkSmartPointer pickInteractorStyle; + vtkSmartPointer pickInteractorStyle; ///@} @@ -526,7 +523,5 @@ protected : }; -} - #endif //RENDERERWIDGET_H diff --git a/sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.cpp b/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.cpp similarity index 99% rename from sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.cpp rename to sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.cpp index ab47557c..2337c473 100644 --- a/sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.cpp +++ b/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.cpp @@ -35,9 +35,6 @@ #include #include - -namespace camitk { - //----------------------- Picking Interactor ----------------------- #if VTK_MAJOR_VERSION < 8 vtkInstantiatorNewMacro(vtkInteractorStylePick); @@ -303,6 +300,4 @@ void vtkInteractorStylePick::Pick() { // ------------------------------- PrintSelf ------------------------------- void vtkInteractorStylePick::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); -} - -} +} \ No newline at end of file diff --git a/sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.h b/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.h similarity index 98% rename from sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.h rename to sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.h index 5b92c597..22e27770 100644 --- a/sdk/libraries/core/viewer/interactive/vtkInteractorStylePick.h +++ b/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.h @@ -33,7 +33,6 @@ class vtkUnsignedCharArray; -namespace camitk { /// Specific backward compatible interactor for CamiTK RendererWidget /// Interactor used when we are in picking mode /// @@ -73,5 +72,4 @@ protected: bool areaPicking; }; -} #endif //VTKINTERACTORSTYLEPICK_H diff --git a/sdk/viewers/CMakeLists.txt b/sdk/viewers/CMakeLists.txt new file mode 100644 index 00000000..6c796fb5 --- /dev/null +++ b/sdk/viewers/CMakeLists.txt @@ -0,0 +1,18 @@ +# +# DO NOT EDIT THIS FILE (unless you REALLY know what you are doing) +# +# To add a component, just add a subdirectory (the component name is the +# directory name). Add all your code there and a text file called +# CMakeLists.txt +# In your CMakeLists.txt, use the camitk_extension(ACTION_EXTENSION ...) macro appropriately + +# find components +get_subdirectories(VIEWERS_LIST) + +# Recursively update the shiboken path variable containing the CamiTK SDK tree structure +set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") + +# Add subdirectories in CMake project +foreach(VIEWER_NAME ${VIEWERS_LIST}) + camitk_add_subdirectory(${VIEWER_NAME}) +endforeach() diff --git a/sdk/libraries/core/viewer/action/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp similarity index 99% rename from sdk/libraries/core/viewer/action/ActionViewer.cpp rename to sdk/viewers/actionviewer/ActionViewer.cpp index 378b30db..ba8c8bc2 100644 --- a/sdk/libraries/core/viewer/action/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -38,7 +38,8 @@ // Deprecated. Use Application.h to handle logger interface //#include "Log.h" -namespace camitk { +using namespace camitk; + // ---------------- constructor ---------------- ActionViewer::ActionViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { myWidget = nullptr; @@ -332,5 +333,3 @@ void ActionViewer::embedActionWidget(Action* action) { updateActionViewer(ActionFamilyChanged); // to have only the actions of the same family nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); } - -} diff --git a/sdk/libraries/core/viewer/action/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h similarity index 92% rename from sdk/libraries/core/viewer/action/ActionViewer.h rename to sdk/viewers/actionviewer/ActionViewer.h index 07782bbb..983c09ae 100644 --- a/sdk/libraries/core/viewer/action/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -26,7 +26,7 @@ #ifndef ACTIONVIEWER_H #define ACTIONVIEWER_H -#include "CamiTKAPI.h" +#include "ActionViewerAPI.h" #include #include @@ -38,10 +38,10 @@ #include #include "Viewer.h" +#include "ViewerExtension.h" #include "Action.h" #include "Component.h" -namespace camitk { /** * @ingroup group_sdk_libraries_core_viewer * @@ -56,7 +56,7 @@ namespace camitk { * You do not have to use it, but it is convienent (and sometimes preferable) to use this instance * instead of creating your own one. */ -class CAMITK_API ActionViewer : public Viewer { +class ACTIONVIEWER_API ActionViewer : public camitk::Viewer { Q_OBJECT public: @@ -64,7 +64,7 @@ public: */ ///@{ /// constructor - ActionViewer(ViewerExtension*, QString); + ActionViewer(camitk::ViewerExtension*, QString); /// destructor ~ActionViewer() override = default; @@ -86,7 +86,7 @@ public: /// @name Specific to the Action viewer //@{ /// embed an action widget in the stacked widget - void embedActionWidget(Action*); + void embedActionWidget(camitk::Action*); /// show/hide the search panel (hidden by default) void setSearchPanelVisible(bool); @@ -119,7 +119,7 @@ private: QComboBox* nameComboBox; /// Current action - Action* action; + camitk::Action* action; /// action tags line edit QLineEdit* tagLineEdit; @@ -134,11 +134,11 @@ private: int emptyActionWidgetIndex; /// this map stores the list of selected component and the corresponding stack index of their embedded action - QMap widgetHistory; + QMap widgetHistory; /// Used to evaluate modification of the list while execution - ComponentList currentlySelected; + camitk::ComponentList currentlySelected; }; -} + #endif // ACTIONVIEWER_H diff --git a/sdk/viewers/actionviewer/ActionViewerAPI.h b/sdk/viewers/actionviewer/ActionViewerAPI.h new file mode 100644 index 00000000..03355191 --- /dev/null +++ b/sdk/viewers/actionviewer/ActionViewerAPI.h @@ -0,0 +1,9 @@ +#if defined(_WIN32) // MSVC and mingw +#ifdef COMPILE_ACTIONVIEWER_API +#define ACTIONVIEWER_API __declspec(dllexport) +#else +#define ACTIONVIEWER_API __declspec(dllimport) +#endif // COMPILE_ACTIONVIEWER_API +#else // for all other platforms ACTIONVIEWER_API is defined to be "nothing" +#define ACTIONVIEWER_API +#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp b/sdk/viewers/actionviewer/ActionViewerExtension.cpp similarity index 98% rename from sdk/libraries/core/viewer/action/ActionViewerExtension.cpp rename to sdk/viewers/actionviewer/ActionViewerExtension.cpp index 9f01905b..f4511508 100644 --- a/sdk/libraries/core/viewer/action/ActionViewerExtension.cpp +++ b/sdk/viewers/actionviewer/ActionViewerExtension.cpp @@ -29,12 +29,8 @@ // include generated actions headers #include "ActionViewer.h" -namespace camitk { - // --------------- getViewers ------------------- void ActionViewerExtension::init() { registerNewViewerDefault(ActionViewer); } -} - diff --git a/sdk/libraries/core/viewer/action/ActionViewerExtension.h b/sdk/viewers/actionviewer/ActionViewerExtension.h similarity index 93% rename from sdk/libraries/core/viewer/action/ActionViewerExtension.h rename to sdk/viewers/actionviewer/ActionViewerExtension.h index 3b3ac056..6ccd6d42 100644 --- a/sdk/libraries/core/viewer/action/ActionViewerExtension.h +++ b/sdk/viewers/actionviewer/ActionViewerExtension.h @@ -27,13 +27,11 @@ #ifndef ACTIONVIEWEREXTENSION_H #define ACTIONVIEWEREXTENSION_H -#include "CamiTKAPI.h" +#include "ActionViewerAPI.h" #include "ViewerExtension.h" -namespace camitk { - -class CAMITK_API ActionViewerExtension : public camitk::ViewerExtension { +class ACTIONVIEWER_API ActionViewerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionviewerextension.viewer.actionviewerextension") @@ -59,7 +57,6 @@ public: virtual void init(); }; -} #endif // ACTIONVIEWEREXTENSION_H diff --git a/sdk/libraries/core/viewer/action/CMakeLists.txt b/sdk/viewers/actionviewer/CMakeLists.txt similarity index 72% rename from sdk/libraries/core/viewer/action/CMakeLists.txt rename to sdk/viewers/actionviewer/CMakeLists.txt index e94d62df..e3b83fcb 100644 --- a/sdk/libraries/core/viewer/action/CMakeLists.txt +++ b/sdk/viewers/actionviewer/CMakeLists.txt @@ -1,7 +1,7 @@ # Call CamiTK CMake Macro to define the action camitk_extension(VIEWER_EXTENSION - DEFAULT - DEFINES COMPILE_ACTION_VIEWER_API + CEP_NAME SDK + DEFINES COMPILE_ACTIONVIEWER_API DESCRIPTION "An extension for the viewer that display GUI action" INSTALL_ALL_HEADERS ) diff --git a/sdk/viewers/explorer/CMakeLists.txt b/sdk/viewers/explorer/CMakeLists.txt new file mode 100644 index 00000000..2bcb223c --- /dev/null +++ b/sdk/viewers/explorer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_EXPLORER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/libraries/core/viewer/explorer/Explorer.cpp b/sdk/viewers/explorer/Explorer.cpp similarity index 99% rename from sdk/libraries/core/viewer/explorer/Explorer.cpp rename to sdk/viewers/explorer/Explorer.cpp index 1cd7f9a2..4a90701c 100644 --- a/sdk/libraries/core/viewer/explorer/Explorer.cpp +++ b/sdk/viewers/explorer/Explorer.cpp @@ -40,8 +40,8 @@ //-- stl stuff #include +using namespace camitk; -namespace camitk { //----------------------- constructor ------------------------ Explorer::Explorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { explorerTree = nullptr; @@ -398,6 +398,3 @@ void Explorer::renameItem() { } } - -} - diff --git a/sdk/libraries/core/viewer/explorer/Explorer.h b/sdk/viewers/explorer/Explorer.h similarity index 85% rename from sdk/libraries/core/viewer/explorer/Explorer.h rename to sdk/viewers/explorer/Explorer.h index 65c377f3..101e35db 100644 --- a/sdk/libraries/core/viewer/explorer/Explorer.h +++ b/sdk/viewers/explorer/Explorer.h @@ -27,6 +27,9 @@ #ifndef EXPLORER_H #define EXPLORER_H +#include "ExplorerAPI.h" + +#include "ViewerExtension.h" // -- Core stuff #include "Viewer.h" @@ -35,11 +38,11 @@ #include namespace camitk { -// -- Core stuff classes -class InterfaceNode; -class Component; -class ExplorerItem; -class Explorer; + // -- Core stuff classes + class InterfaceNode; + class Component; + class ExplorerItem; +} /** * @ingroup group_sdk_libraries_core_viewer @@ -55,7 +58,7 @@ class Explorer; * You do not have to use it, but it is convienent (and sometimes preferable) to use this instance * instead of creating your own one. */ -class CAMITK_API Explorer : public Viewer { +class EXPLORER_API Explorer : public camitk::Viewer { Q_OBJECT public: @@ -63,7 +66,7 @@ public: */ ///@{ /** Construtor */ - Explorer(ViewerExtension*, QString); + Explorer(camitk::ViewerExtension*, QString); /** Destructor */ ~Explorer() override; @@ -75,7 +78,7 @@ public: unsigned int numberOfViewedComponent() override; /// refresh the explorer (can be interesting to know which other viewer is calling this) - void refresh(Viewer* whoIsAsking = nullptr) override; + void refresh(camitk::Viewer* whoIsAsking = nullptr) override; /// get the explorer widget (QTreeWidget). @param parent the parent widget for the viewer widget QWidget* getWidget(QWidget* parent) override; @@ -93,7 +96,7 @@ public: * If the component was not displayed in the explorer, this method does nothing. * @param comp The InterfaceNode provider to update list. */ - void refreshInterfaceNode(Component* comp) override; + void refreshInterfaceNode(camitk::Component* comp) override; ///@} public slots : @@ -117,27 +120,27 @@ private: /// @name QTreeWidgetItem/InterfaceNode map ///@{ /// the map to get the Component* from the QTreeWidgetItem* - QMap itemComponentMap; + QMap itemComponentMap; /// the map to get the QTreeWidgetItem corresponding to a parentComp - QMap topLevelCompItemMap; + QMap topLevelCompItemMap; /// Return the QTreeWidgetItem of a given Component (return NULL if not found) - QTreeWidgetItem* getItem(Component*); + QTreeWidgetItem* getItem(camitk::Component*); ///@} /// @name QTreeWidget and QTreeWidgetItem management ///@{ /// instanciate a new QTreeWidgetItem using names and properties from the InterfaceNode, and using parent - QTreeWidgetItem* getNewItem(QTreeWidgetItem* parent, Component*); + QTreeWidgetItem* getNewItem(QTreeWidgetItem* parent, camitk::Component*); /// recursively add the Component in the tree explorer and return the QTreeWidgetItem of the InterfaceNode - QTreeWidgetItem* add(QTreeWidgetItem*, Component*); + QTreeWidgetItem* add(QTreeWidgetItem*, camitk::Component*); /** Add the given Component to the explorer (at top level) and automatically create children Component items. * @param comp The Component to add in the tree view. */ - void addTopLevel(Component* comp, int index = -1); + void addTopLevel(camitk::Component* comp, int index = -1); /// remove a given item from the explorer (return its index in the parent item list) void remove(QTreeWidgetItem*); @@ -145,7 +148,7 @@ private: /** Remove the Component (its Component and its sub-item) from the explorer list (if present). * The Component itself is of course not deleted here. */ - void removeTopLevel(Component* comp); + void removeTopLevel(camitk::Component* comp); /// the list view @@ -162,7 +165,4 @@ private: ///@} }; -} - - #endif diff --git a/sdk/viewers/explorer/ExplorerAPI.h b/sdk/viewers/explorer/ExplorerAPI.h new file mode 100644 index 00000000..a4714e90 --- /dev/null +++ b/sdk/viewers/explorer/ExplorerAPI.h @@ -0,0 +1,9 @@ +#if defined(_WIN32) // MSVC and mingw +#ifdef COMPILE_EXPLORER_API +#define EXPLORER_API __declspec(dllexport) +#else +#define EXPLORER_API __declspec(dllimport) +#endif // COMPILE_EXPLORER_API +#else // for all other platforms EXPLORER_API is defined to be "nothing" +#define EXPLORER_API +#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp b/sdk/viewers/explorer/ExplorerExtension.cpp similarity index 98% rename from sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp rename to sdk/viewers/explorer/ExplorerExtension.cpp index 61307eaf..4c690364 100644 --- a/sdk/libraries/core/viewer/explorer/ExplorerExtension.cpp +++ b/sdk/viewers/explorer/ExplorerExtension.cpp @@ -29,12 +29,8 @@ // include generated actions headers #include "Explorer.h" -namespace camitk { - // --------------- getViewers ------------------- void ExplorerExtension::init() { registerNewViewerDefault(Explorer); } -} - diff --git a/sdk/libraries/core/viewer/explorer/ExplorerExtension.h b/sdk/viewers/explorer/ExplorerExtension.h similarity index 93% rename from sdk/libraries/core/viewer/explorer/ExplorerExtension.h rename to sdk/viewers/explorer/ExplorerExtension.h index e4f394f8..6d0e3acc 100644 --- a/sdk/libraries/core/viewer/explorer/ExplorerExtension.h +++ b/sdk/viewers/explorer/ExplorerExtension.h @@ -27,13 +27,11 @@ #ifndef EXPLOREREXTENSION_H #define EXPLOREREXTENSION_H -#include "CamiTKAPI.h" +#include "ExplorerAPI.h" #include "ViewerExtension.h" -namespace camitk { - -class CAMITK_API ExplorerExtension : public camitk::ViewerExtension { +class EXPLORER_API ExplorerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); @@ -58,7 +56,6 @@ public: virtual void init(); }; -} #endif // EXPLOREREXTENSION_H diff --git a/sdk/viewers/frameexplorer/CMakeLists.txt b/sdk/viewers/frameexplorer/CMakeLists.txt new file mode 100644 index 00000000..bf48a08a --- /dev/null +++ b/sdk/viewers/frameexplorer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_FRAMEEXPLORER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp b/sdk/viewers/frameexplorer/FrameExplorer.cpp similarity index 99% rename from sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp rename to sdk/viewers/frameexplorer/FrameExplorer.cpp index 9a566b05..7d88bb7a 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.cpp +++ b/sdk/viewers/frameexplorer/FrameExplorer.cpp @@ -31,7 +31,8 @@ //-- to stretch th first column to entirely show the names #include -namespace camitk { +using namespace camitk; + //----------------------- constructor ------------------------ FrameExplorer::FrameExplorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { explorerTree = nullptr; @@ -163,7 +164,4 @@ void FrameExplorer::remove() { void FrameExplorer::selectionChanged() { // refresh! refresh(this); -} - -} - +} \ No newline at end of file diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h b/sdk/viewers/frameexplorer/FrameExplorer.h similarity index 89% rename from sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h rename to sdk/viewers/frameexplorer/FrameExplorer.h index abf65414..68100a85 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorer.h +++ b/sdk/viewers/frameexplorer/FrameExplorer.h @@ -27,6 +27,9 @@ #ifndef FRAMEEXPLORER_H #define FRAMEEXPLORER_H +#include "FrameExplorerAPI.h" + +#include "ViewerExtension.h" // -- Core stuff #include "Viewer.h" @@ -35,8 +38,9 @@ #include namespace camitk { -// -- Core stuff classes -class InterfaceFrame; + // -- Core stuff classes + class InterfaceFrame; +} /** * @ingroup group_sdk_libraries_core_viewer @@ -52,7 +56,7 @@ class InterfaceFrame; * You do not have to use it, but it is convienent (and sometimes preferable) to use this instance * instead of creating your own one. */ -class CAMITK_API FrameExplorer : public Viewer { +class FRAMEEXPLORER_API FrameExplorer : public camitk::Viewer { Q_OBJECT public: @@ -60,7 +64,7 @@ public: */ ///@{ /** Construtor */ - FrameExplorer(ViewerExtension*, QString); + FrameExplorer(camitk::ViewerExtension*, QString); /** Destructor */ ~FrameExplorer() override = default; @@ -92,15 +96,15 @@ private: /// @name QTreeWidget and QTreeWidgetItem management ///@{ /// instantiate a new QTreeWidgetItem using names and properties from the InterfaceNode, and using parent - QTreeWidgetItem* getNewItem(QTreeWidgetItem* parent, Component*); + QTreeWidgetItem* getNewItem(QTreeWidgetItem* parent, camitk::Component*); /// recursively add the Component in the tree explorer and return the QTreeWidgetItem of the InterfaceNode - QTreeWidgetItem* add(QTreeWidgetItem*, Component*); + QTreeWidgetItem* add(QTreeWidgetItem*, camitk::Component*); /** Add the given Component to the explorer (at top level) and automatically create children Component items. * @param comp The Component to add in the tree view. */ - void add(Component* comp); + void add(camitk::Component* comp); /// clear the tree explorer void remove(); @@ -112,7 +116,4 @@ private: }; -} - - #endif diff --git a/sdk/viewers/frameexplorer/FrameExplorerAPI.h b/sdk/viewers/frameexplorer/FrameExplorerAPI.h new file mode 100644 index 00000000..50f9b566 --- /dev/null +++ b/sdk/viewers/frameexplorer/FrameExplorerAPI.h @@ -0,0 +1,9 @@ +#if defined(_WIN32) // MSVC and mingw +#ifdef COMPILE_FRAMEEXPLORER_API +#define FRAMEEXPLORER_API __declspec(dllexport) +#else +#define FRAMEEXPLORER_API __declspec(dllimport) +#endif // COMPILE_FRAMEEXPLORER_API +#else // for all other platforms FRAMEEXPLORER_API is defined to be "nothing" +#define FRAMEEXPLORER_API +#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp b/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp similarity index 98% rename from sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp rename to sdk/viewers/frameexplorer/FrameExplorerExtension.cpp index 0ee0584e..b5607b6f 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.cpp +++ b/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp @@ -29,12 +29,8 @@ // include generated actions headers #include "FrameExplorer.h" -namespace camitk { - // --------------- getViewers ------------------- void FrameExplorerExtension::init() { registerNewViewerDefault(FrameExplorer); } -} - diff --git a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h b/sdk/viewers/frameexplorer/FrameExplorerExtension.h similarity index 93% rename from sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h rename to sdk/viewers/frameexplorer/FrameExplorerExtension.h index cde71abb..608e70a2 100644 --- a/sdk/libraries/core/viewer/frameexplorer/FrameExplorerExtension.h +++ b/sdk/viewers/frameexplorer/FrameExplorerExtension.h @@ -27,13 +27,11 @@ #ifndef FRAMEEXPLOREREXTENSION_H #define FRAMEEXPLOREREXTENSION_H -#include "CamiTKAPI.h" +#include "FrameExplorerAPI.h" #include "ViewerExtension.h" -namespace camitk { - -class CAMITK_API FrameExplorerExtension : public camitk::ViewerExtension { +class FRAMEEXPLORER_API FrameExplorerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); @@ -58,7 +56,6 @@ public: virtual void init(); }; -} #endif // FRAMEEXPLOREREXTENSION_H diff --git a/sdk/viewers/medicalimageviewer/CMakeLists.txt b/sdk/viewers/medicalimageviewer/CMakeLists.txt new file mode 100644 index 00000000..670aec8d --- /dev/null +++ b/sdk/viewers/medicalimageviewer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_MEDICALIMAGEVIEWER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp similarity index 99% rename from sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp rename to sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp index 28a342f4..db3ce1ee 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp @@ -35,7 +35,7 @@ #include #include -namespace camitk { +using namespace camitk; // -------------------- Constructor -------------------- @@ -257,5 +257,3 @@ void MedicalImageViewer::setToolbarAutoVisibility(bool toolbarAutoVisibility) { setToolBarVisibility(false); } -} - diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h similarity index 95% rename from sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h rename to sdk/viewers/medicalimageviewer/MedicalImageViewer.h index 5acaa44e..42c5f33e 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewer.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h @@ -28,7 +28,8 @@ #define MEDICAL_IMAGE_VIEWER_H // -- Core stuff -#include "CamiTKAPI.h" +#include "MedicalImageViewerAPI.h" +#include "ViewerExtension.h" #include "Viewer.h" // -- QT stuff @@ -38,9 +39,9 @@ #include namespace camitk { -// -- Core stuff classes -class InteractiveViewer; - + // -- Core stuff classes + class InteractiveViewer; +} /** * @ingroup group_sdk_libraries_core_viewer * @@ -57,7 +58,7 @@ class InteractiveViewer; * \image html libraries/medicalimageviewer.png "The medical image viewer" * */ -class CAMITK_API MedicalImageViewer : public Viewer { +class MEDICALIMAGEVIEWER_API MedicalImageViewer : public camitk::Viewer { Q_OBJECT public: @@ -71,7 +72,7 @@ public: VIEWER_ARBITRARY ///< Only the arbitrary InteractiveViewer are visible }; - MedicalImageViewer(ViewerExtension*, QString); + MedicalImageViewer(camitk::ViewerExtension*, QString); /** destructor */ ~MedicalImageViewer() override; @@ -149,8 +150,6 @@ private: bool autoUpdateToolbarVisibility; }; -} - #endif diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h b/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h new file mode 100644 index 00000000..78b7c929 --- /dev/null +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h @@ -0,0 +1,9 @@ +#if defined(_WIN32) // MSVC and mingw +#ifdef COMPILE_MEDICALIMAGEVIEWER_API +#define MEDICALIMAGEVIEWER_API __declspec(dllexport) +#else +#define MEDICALIMAGEVIEWER_API __declspec(dllimport) +#endif // COMPILE_MEDICALIMAGEVIEWER_API +#else // for all other platforms MEDICALIMAGEVIEWER_API is defined to be "nothing" +#define MEDICALIMAGEVIEWER_API +#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp similarity index 98% rename from sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp rename to sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp index b9ba8f2d..f8cca86f 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp @@ -29,12 +29,8 @@ // include generated actions headers #include "MedicalImageViewer.h" -namespace camitk { - // --------------- getViewers ------------------- void MedicalImageViewerExtension::init() { registerNewViewerDefault(MedicalImageViewer); } -} - diff --git a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h similarity index 93% rename from sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h rename to sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h index 305f14c6..094ebde7 100644 --- a/sdk/libraries/core/viewer/medicalimage/MedicalImageViewerExtension.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h @@ -27,13 +27,11 @@ #ifndef MEDICALIMAGEVIEWEREXTENSION_H #define MEDICALIMAGEVIEWEREXTENSION_H -#include "CamiTKAPI.h" +#include "MedicalImageViewerAPI.h" #include "ViewerExtension.h" -namespace camitk { - -class CAMITK_API MedicalImageViewerExtension : public camitk::ViewerExtension { +class MEDICALIMAGEVIEWER_API MedicalImageViewerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); @@ -58,7 +56,6 @@ public: virtual void init(); }; -} #endif // MEDICALIMAGEVIEWEREXTENSION_H diff --git a/sdk/viewers/propertyexplorer/CMakeLists.txt b/sdk/viewers/propertyexplorer/CMakeLists.txt new file mode 100644 index 00000000..14423556 --- /dev/null +++ b/sdk/viewers/propertyexplorer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_PROPERTYEXPLORER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp similarity index 99% rename from sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp rename to sdk/viewers/propertyexplorer/PropertyExplorer.cpp index 607c4d1e..8ded11ce 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp @@ -35,7 +35,7 @@ #include #include -namespace camitk { +using namespace camitk; // ---------------- constructor ---------------- PropertyExplorer::PropertyExplorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { @@ -260,7 +260,4 @@ void PropertyExplorer::createProperties() { // ---------------- createProperties ---------------- void PropertyExplorer::refreshAll() { Application::refresh(); -} - - -} +} \ No newline at end of file diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h b/sdk/viewers/propertyexplorer/PropertyExplorer.h similarity index 92% rename from sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h rename to sdk/viewers/propertyexplorer/PropertyExplorer.h index ee07777b..0daef108 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorer.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.h @@ -25,7 +25,10 @@ #ifndef PROPERTYEXPLORER_H #define PROPERTYEXPLORER_H +#include "PropertyExplorerAPI.h" + // -- Core stuff +#include "ViewerExtension.h" #include "Viewer.h" #include "ObjectController.h" #include "PropertyObject.h" @@ -42,9 +45,8 @@ class QPushButton; class QWidget; namespace camitk { - - -class ObjectController; + class ObjectController; +} /** * @ingroup group_sdk_libraries_core_viewer @@ -80,7 +82,7 @@ class ObjectController; * * @see ObjectController */ -class CAMITK_API PropertyExplorer : public Viewer { +class PROPERTYEXPLORER_API PropertyExplorer : public camitk::Viewer { Q_OBJECT Q_ENUMS(camitk::ObjectController::ViewMode) // so that it can be used in property editor @@ -89,7 +91,7 @@ public: */ ///@{ /// constructor - PropertyExplorer(ViewerExtension * extension, QString name); + PropertyExplorer(camitk::ViewerExtension * extension, QString name); /// destructor ~PropertyExplorer() override; @@ -101,7 +103,7 @@ public: unsigned int numberOfViewedComponent() override; /// refresh the property editor - void refresh(Viewer* whoIsAsking = nullptr) override; + void refresh(camitk::Viewer* whoIsAsking = nullptr) override; /// get the viewer widget. @param parent the parent widget for the viewer widget QWidget* getWidget(QWidget* parent = nullptr) override; @@ -129,13 +131,13 @@ public: private: /// the widgets - ObjectController* theController; + camitk::ObjectController* theController; QTabWidget* tabWidget; QPushButton* revertButton; QPushButton* applyButton; /// the viewed Component - Component* currentComponent; + camitk::Component* currentComponent; /** * @name CamiTK Properties of this viewer @@ -144,12 +146,12 @@ private: /** * The property object that holds the properties of this viewer */ - PropertyObject* propertyObject; + camitk::PropertyObject* propertyObject; /** * The CamiTK property that stands for the ObjectController view mode. */ - Property* viewModeProperty; + camitk::Property* viewModeProperty; /** * Event filter of this class instance to watch its properties instances. @@ -183,5 +185,5 @@ private slots: /// in component or action codes. void refreshAll(); }; -} + #endif diff --git a/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h b/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h new file mode 100644 index 00000000..77df8ba3 --- /dev/null +++ b/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h @@ -0,0 +1,9 @@ +#if defined(_WIN32) // MSVC and mingw +#ifdef COMPILE_PROPERTYEXPLORER_API +#define PROPERTYEXPLORER_API __declspec(dllexport) +#else +#define PROPERTYEXPLORER_API __declspec(dllimport) +#endif // COMPILE_PROPERTYEXPLORER_API +#else // for all other platforms PROPERTYEXPLORER_API is defined to be "nothing" +#define PROPERTYEXPLORER_API +#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp similarity index 98% rename from sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp rename to sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp index 2271eb80..8cedc710 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp @@ -29,12 +29,8 @@ // include generated actions headers #include "PropertyExplorer.h" -namespace camitk { - // --------------- getViewers ------------------- void PropertyExplorerExtension::init() { registerNewViewerDefault(PropertyExplorer); } -} - diff --git a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h similarity index 93% rename from sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h rename to sdk/viewers/propertyexplorer/PropertyExplorerExtension.h index bf49b5e9..c639ec47 100644 --- a/sdk/libraries/core/viewer/propertyexplorer/PropertyExplorerExtension.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h @@ -27,13 +27,11 @@ #ifndef PROPERTYEXPLOREREXTENSION_H #define PROPERTYEXPLOREREXTENSION_H -#include "CamiTKAPI.h" +#include "PropertyExplorerAPI.h" #include "ViewerExtension.h" -namespace camitk { - -class CAMITK_API PropertyExplorerExtension : public camitk::ViewerExtension { +class PROPERTYEXPLORER_API PropertyExplorerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); @@ -58,7 +56,6 @@ public: virtual void init(); }; -} #endif // PROPERTYEXPLOREREXTENSION_H -- GitLab From 84dbe2c167198f18dff86f510cafa623a3c0434c Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Mon, 13 Jan 2020 14:52:07 +0100 Subject: [PATCH 07/26] Update tutorials and viewer creation in viewer extension --- sdk/actions/application/Show3DViewer.cpp | 3 +- sdk/actions/application/ShowAllViewers.cpp | 2 +- .../application/ShowArbitraryViewer.cpp | 2 +- sdk/actions/application/ShowAxialViewer.cpp | 2 +- sdk/actions/application/ShowCoronalViewer.cpp | 2 +- .../application/ShowSagittalViewer.cpp | 2 +- sdk/actions/frame/editframes/FrameEditor.cpp | 22 +++---- .../pixelcolorchanger/PixelColorChanger.cpp | 12 ++-- .../image/reorientimage/ReorientImage.cpp | 6 +- .../image/reorientimage/ReorientImage.h | 4 +- .../volumerendering/VolumeRenderingAction.cpp | 10 ++-- sdk/actions/mesh/basicmesh/MeshPicking.cpp | 2 +- sdk/actions/mesh/basicmesh/RigidTransform.cpp | 4 +- .../mesh/meshprocessing/MeshClipping.cpp | 6 +- .../actionstatemachine/ActionStateMachine.cpp | 10 ++-- .../actionstatemachine/ActionTransition.cpp | 2 +- sdk/applications/imp/ImpMainWindow.cpp | 30 +++++----- sdk/components/msh/CMakeLists.txt | 1 + sdk/components/msh/MshComponent.cpp | 4 +- sdk/components/off/CMakeLists.txt | 1 + sdk/components/off/OffComponent.cpp | 2 +- sdk/components/stl/CMakeLists.txt | 1 + sdk/components/vrml/CMakeLists.txt | 1 + .../vrml/VRMLComponentExtension.cpp | 2 +- sdk/libraries/core/CMakeLists.txt | 4 +- sdk/libraries/core/action/Action.cpp | 4 +- .../core/application/Application.cpp | 8 ++- sdk/libraries/core/application/Application.h | 13 +--- .../core/component/image/ImageComponent.cpp | 3 +- .../component/image/SingleImageComponent.cpp | 11 ++-- .../core/component/mesh/MeshComponent.cpp | 12 ++-- .../core/component/mesh/MeshDataModel.cpp | 1 - .../core/component/mesh/MeshDataModel.h | 4 +- sdk/libraries/core/viewer/ViewerExtension.h | 1 - .../interactiveviewer/InteractiveViewerAPI.h | 9 --- sdk/viewers/actionviewer/ActionViewerAPI.h | 52 +++++++++++++++- .../actionviewer/ActionViewerExtension.cpp | 2 +- sdk/viewers/actionviewer/CMakeLists.txt | 1 + sdk/viewers/explorer/ExplorerAPI.h | 52 +++++++++++++++- sdk/viewers/explorer/ExplorerExtension.cpp | 2 +- sdk/viewers/explorer/ExplorerExtension.h | 1 + sdk/viewers/frameexplorer/FrameExplorerAPI.h | 52 +++++++++++++++- .../frameexplorer/FrameExplorerExtension.cpp | 2 +- .../frameexplorer/FrameExplorerExtension.h | 1 + .../interactiveviewer/CMakeLists.txt | 0 .../interactiveviewer/InteractiveViewer.cpp | 0 .../interactiveviewer/InteractiveViewer.h | 0 .../interactiveviewer/InteractiveViewerAPI.h | 59 +++++++++++++++++++ .../InteractiveViewerExtension.cpp | 1 + .../InteractiveViewerExtension.h | 1 + .../interactiveviewer/RendererWidget.cpp | 0 .../interactiveviewer/RendererWidget.h | 4 +- .../vtkInteractorStylePick.cpp | 0 .../vtkInteractorStylePick.h | 3 +- sdk/viewers/medicalimageviewer/CMakeLists.txt | 1 + .../medicalimageviewer/MedicalImageViewer.cpp | 32 +++++----- .../medicalimageviewer/MedicalImageViewer.h | 7 --- .../MedicalImageViewerAPI.h | 52 +++++++++++++++- .../MedicalImageViewerExtension.cpp | 2 +- .../MedicalImageViewerExtension.h | 1 + .../propertyexplorer/PropertyExplorerAPI.h | 52 +++++++++++++++- .../PropertyExplorerExtension.cpp | 2 +- .../PropertyExplorerExtension.h | 1 + tutorials/actions/basicpicking/CMakeLists.txt | 1 + .../actions/basicpicking/ImagePicking.cpp | 12 ++-- tutorials/actions/bitmapviewer/CMakeLists.txt | 2 +- .../actions/bitmapviewer/ShowBitmapViewer.cpp | 2 +- .../shakerextension/CMakeLists.txt | 1 + .../actions/meshpointdata/CMakeLists.txt | 3 +- .../actions/showtextviewer/ShowTextViewer.cpp | 4 +- .../sleepingwhileworking/CMakeLists.txt | 1 + .../WorkingWhenSleepingLinear.cpp | 4 +- .../WorkingWhenSleepingRandom.cpp | 4 +- tutorials/actions/vtkwidget/BoxWidget.cpp | 4 +- tutorials/actions/vtkwidget/CMakeLists.txt | 1 + tutorials/actions/vtkwidget/ContourWidget.cpp | 7 +-- tutorials/applications/basic/CMakeLists.txt | 4 +- tutorials/applications/basic/main.cpp | 2 +- tutorials/applications/fancy/CMakeLists.txt | 4 +- .../applications/fancy/FancyMainWindow.cpp | 46 +++++++-------- .../applications/fancy/FancyMainWindow.h | 11 ++-- tutorials/applications/menubar/CMakeLists.txt | 4 +- .../applications/menubar/MyAppMainWindow.cpp | 4 +- tutorials/applications/simple/CMakeLists.txt | 4 +- .../applications/simple/SimpleMainWindow.cpp | 23 ++++---- .../applications/textviewer/CMakeLists.txt | 4 +- tutorials/applications/textviewer/main.cpp | 2 +- tutorials/viewers/bitmap/BitmapViewer.cpp | 20 +------ tutorials/viewers/bitmap/BitmapViewer.h | 14 +---- .../viewers/bitmap/BitmapViewerExtension.cpp | 2 +- tutorials/viewers/bitmap/CMakeLists.txt | 1 + tutorials/viewers/textviewer/CMakeLists.txt | 1 + tutorials/viewers/textviewer/TextViewer.cpp | 23 ++------ tutorials/viewers/textviewer/TextViewer.h | 5 +- .../textviewer/TextViewerExtension.cpp | 2 +- 95 files changed, 540 insertions(+), 268 deletions(-) delete mode 100644 sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/CMakeLists.txt (100%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/InteractiveViewer.cpp (100%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/InteractiveViewer.h (100%) create mode 100644 sdk/viewers/interactiveviewer/InteractiveViewerAPI.h rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/InteractiveViewerExtension.cpp (96%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/InteractiveViewerExtension.h (94%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/RendererWidget.cpp (100%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/RendererWidget.h (99%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/vtkInteractorStylePick.cpp (100%) rename sdk/{libraries/core/viewer => viewers}/interactiveviewer/vtkInteractorStylePick.h (94%) diff --git a/sdk/actions/application/Show3DViewer.cpp b/sdk/actions/application/Show3DViewer.cpp index 68ebee60..074e67d5 100644 --- a/sdk/actions/application/Show3DViewer.cpp +++ b/sdk/actions/application/Show3DViewer.cpp @@ -25,6 +25,7 @@ #include "Show3DViewer.h" #include + using namespace camitk; // --------------- constructor ------------------- @@ -60,7 +61,7 @@ QWidget* Show3DViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus Show3DViewer::apply() { - Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_3D); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(MedicalImageViewer::VIEWER_3D); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowAllViewers.cpp b/sdk/actions/application/ShowAllViewers.cpp index 5bb9b4dc..840a2dce 100644 --- a/sdk/actions/application/ShowAllViewers.cpp +++ b/sdk/actions/application/ShowAllViewers.cpp @@ -60,7 +60,7 @@ QWidget* ShowAllViewers::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowAllViewers::apply() { - Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowArbitraryViewer.cpp b/sdk/actions/application/ShowArbitraryViewer.cpp index 9e258c43..9830da24 100644 --- a/sdk/actions/application/ShowArbitraryViewer.cpp +++ b/sdk/actions/application/ShowArbitraryViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowArbitraryViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowArbitraryViewer::apply() { - Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_ARBITRARY); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(MedicalImageViewer::VIEWER_ARBITRARY); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowAxialViewer.cpp b/sdk/actions/application/ShowAxialViewer.cpp index 0d10b525..b69b774f 100644 --- a/sdk/actions/application/ShowAxialViewer.cpp +++ b/sdk/actions/application/ShowAxialViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowAxialViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowAxialViewer::apply() { - Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_AXIAL); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(MedicalImageViewer::VIEWER_AXIAL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowCoronalViewer.cpp b/sdk/actions/application/ShowCoronalViewer.cpp index 42c65001..8c713db3 100644 --- a/sdk/actions/application/ShowCoronalViewer.cpp +++ b/sdk/actions/application/ShowCoronalViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowCoronalViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowCoronalViewer::apply() { - Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_CORONAL); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(MedicalImageViewer::VIEWER_CORONAL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/application/ShowSagittalViewer.cpp b/sdk/actions/application/ShowSagittalViewer.cpp index 94158fff..80005ec0 100644 --- a/sdk/actions/application/ShowSagittalViewer.cpp +++ b/sdk/actions/application/ShowSagittalViewer.cpp @@ -60,7 +60,7 @@ QWidget* ShowSagittalViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowSagittalViewer::apply() { - Application::getViewer("MedicalImageViewer")->setVisibleViewer(MedicalImageViewer::VIEWER_SAGITTAL); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(MedicalImageViewer::VIEWER_SAGITTAL); Application::refresh(); return SUCCESS; } diff --git a/sdk/actions/frame/editframes/FrameEditor.cpp b/sdk/actions/frame/editframes/FrameEditor.cpp index c900142c..384a41e4 100644 --- a/sdk/actions/frame/editframes/FrameEditor.cpp +++ b/sdk/actions/frame/editframes/FrameEditor.cpp @@ -160,7 +160,7 @@ QWidget* FrameEditor::getWidget() { void FrameEditor::initializeDialogWithCurrentComponent() { // update checkbox ui.displayFrameCheckBox->blockSignals(true); - bool isFrameDisplayed = currentComponent->getFrameVisibility(Application::getViewer("3DViewer")); + bool isFrameDisplayed = currentComponent->getFrameVisibility(Application::getViewer("3DViewer")); ui.displayFrameCheckBox->setChecked(isFrameDisplayed); ui.displayFrameCheckBox->blockSignals(false); @@ -218,18 +218,18 @@ void FrameEditor::initializeDialogWithCurrentComponent() { void FrameEditor::displayFrameToggled(bool display) { int frameSize = ui.frameSizeSpinBox->value(); currentComponent->getFrameAxisActor()->SetTotalLength(frameSize, frameSize, frameSize); - currentComponent->setFrameVisibility(Application::getViewer("3DViewer"), display); + currentComponent->setFrameVisibility(Application::getViewer("3DViewer"), display); - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); } // --------------- frameSizeChanged ------------------- void FrameEditor::frameSizeChanged(int val) { bool display = ui.displayFrameCheckBox->isChecked(); currentComponent->getFrameAxisActor()->SetTotalLength(val, val, val); - currentComponent->setFrameVisibility(Application::getViewer("3DViewer"), display); + currentComponent->setFrameVisibility(Application::getViewer("3DViewer"), display); - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); } // --------------- setParentFrame ------------------- @@ -250,7 +250,7 @@ void FrameEditor::setParentFrame() { } currentComponent->setParentFrame(parentFrame, keepTransform); - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -299,7 +299,7 @@ void FrameEditor::setTransformation() { matrixTransform->SetMatrix(matrix); currentComponent->setTransform(matrixTransform); - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -314,7 +314,7 @@ void FrameEditor::translate() { ui.yTranslationLineEdit->text().toDouble(), ui.zTranslationLineEdit->text().toDouble()); - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -324,7 +324,7 @@ void FrameEditor::setTranslation() { ui.yTranslationLineEdit->text().toDouble(), ui.zTranslationLineEdit->text().toDouble()); - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -347,7 +347,7 @@ void FrameEditor::rotate() { ui.zRotationLineEdit->text().toDouble()); } - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } @@ -364,7 +364,7 @@ void FrameEditor::setRotation() { ui.zRotationLineEdit->text().toDouble()); } - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); initializeDialogWithCurrentComponent(); } diff --git a/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp b/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp index 35308a5e..042091ed 100644 --- a/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp +++ b/sdk/actions/image/pixelcolorchanger/PixelColorChanger.cpp @@ -79,9 +79,9 @@ QWidget* PixelColorChanger::getWidget() { if (!isConnected) { //-- run the action every time a picking is done in the axial/sagittal or coronal planes - QObject::connect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::connect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::connect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); isConnected = true; } return Action::getWidget(); @@ -219,9 +219,9 @@ Action::ApplyStatus PixelColorChanger::apply() { } else { // disconnect - QObject::disconnect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::disconnect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::disconnect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); isConnected = false; } return SUCCESS; diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index a737e70b..ea0c410e 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -333,7 +333,7 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); image->setTransform(updatedTransform); - image->setFrameVisibility(Application::getViewer("3DViewer"), true); + image->setFrameVisibility(Application::getViewer("3DViewer"), true); } else { @@ -357,9 +357,9 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); result->setTransform(updatedTransform); - result->setFrameVisibility(Application::getViewer("3DViewer"), true); + result->setFrameVisibility(Application::getViewer("3DViewer"), true); } - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); Application::refresh(); diff --git a/sdk/actions/image/reorientimage/ReorientImage.h b/sdk/actions/image/reorientimage/ReorientImage.h index 9ce4b3c2..064eeb60 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.h +++ b/sdk/actions/image/reorientimage/ReorientImage.h @@ -33,10 +33,10 @@ class vtkTransform; class vtkAnnotatedCubeActor; +class InteractiveViewer; namespace camitk { class Geometry; class ImageComponent; -class InteractiveViewer; } class ReorientImage : public camitk::Action { @@ -77,7 +77,7 @@ private: void setAxesOrientation(const QString orientation); - camitk::InteractiveViewer* internalViewer; + InteractiveViewer* internalViewer; /// Actually perform the image transformation ApplyStatus process(camitk::ImageComponent* image); diff --git a/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp b/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp index 719e3db0..e1f64a39 100644 --- a/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp +++ b/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp @@ -98,18 +98,18 @@ Action::ApplyStatus VolumeRenderingAction::apply() { // --------------- process --------------- void VolumeRenderingAction::process(ImageComponent* comp) { - bool isVisible = comp->getVolumeRenderingChild()->getVisibility(Application::getViewer("3DViewer")); + bool isVisible = comp->getVolumeRenderingChild()->getVisibility(Application::getViewer("3DViewer")); bool existVR = (comp->getVolumeRenderingChild()->getProp(volumeName) != NULL); if (existVR) { if (isVisible) { - comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), false); + comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), false); if (myWidget) { myWidget->close(); } Application::refresh(); } else { - comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), true); + comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), true); if (myWidget != nullptr) { myWidget->show(); Application::refresh(); @@ -261,8 +261,8 @@ void VolumeRenderingAction::createVolumeRendering(ImageComponent* comp) { comp->getVolumeRenderingChild()->getProp(volumeName)->SetVisibility(true); //Application::getViewer("3DViewer")->getRendererWidget()->addProp(volume); - comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), true); - Application::getViewer("3DViewer")->refresh(); + comp->getVolumeRenderingChild()->setVisibility(Application::getViewer("3DViewer"), true); + Application::getViewer("3DViewer")->refresh(); } diff --git a/sdk/actions/mesh/basicmesh/MeshPicking.cpp b/sdk/actions/mesh/basicmesh/MeshPicking.cpp index a1a1824c..9cab56d4 100644 --- a/sdk/actions/mesh/basicmesh/MeshPicking.cpp +++ b/sdk/actions/mesh/basicmesh/MeshPicking.cpp @@ -61,7 +61,7 @@ QWidget* MeshPicking::getWidget() { informationLabel = new QLabel(); //-- run the action every time a picking is done in the axial/sagittal or coronal planes - QObject::connect(Application::getViewer("3DViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("3DViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); //-- the vertical layout, put every GUI elements in it auto* informationFrameLayout = new QVBoxLayout(); diff --git a/sdk/actions/mesh/basicmesh/RigidTransform.cpp b/sdk/actions/mesh/basicmesh/RigidTransform.cpp index c211db74..6ab1bdba 100644 --- a/sdk/actions/mesh/basicmesh/RigidTransform.cpp +++ b/sdk/actions/mesh/basicmesh/RigidTransform.cpp @@ -131,7 +131,7 @@ void RigidTransform::reset() { //-- init values double bounds[6]; - Application::getViewer("3DViewer")->getBounds(bounds); + dynamic_cast(Application::getViewer("3DViewer"))->getBounds(bounds); double xLength = bounds[1] - bounds[0]; double yLength = bounds[3] - bounds[2]; double zLength = bounds[5] - bounds[4]; @@ -184,7 +184,7 @@ void RigidTransform::update(bool forceUpdate) { transformation->Scale(sx, sy, sz); // Refresh all the used viewers - Application::getViewer("3DViewer")->refresh(); + Application::getViewer("3DViewer")->refresh(); } } diff --git a/sdk/actions/mesh/meshprocessing/MeshClipping.cpp b/sdk/actions/mesh/meshprocessing/MeshClipping.cpp index a80dc988..ee8baf5a 100644 --- a/sdk/actions/mesh/meshprocessing/MeshClipping.cpp +++ b/sdk/actions/mesh/meshprocessing/MeshClipping.cpp @@ -85,8 +85,8 @@ QWidget* MeshClipping::getWidget() { //-- Creating the clipping plane widget (the first time getWidget() is called) if (!widget->planeWidget) { vtkRenderWindowInteractor* iren = - Application::getViewer("3DViewer")-> - getRendererWidget()->GetRenderWindow()->GetInteractor(); + dynamic_cast(Application::getViewer("3DViewer")) + ->getRendererWidget()->GetRenderWindow()->GetInteractor(); //-- Configure the plane widget including callbacks widget->planeWidget = @@ -96,7 +96,7 @@ QWidget* MeshClipping::getWidget() { //-- Bounding box definition and placement widget->planeWidget->SetPlaceFactor(1.5); - Application::getViewer("3DViewer")->getBounds(limBounds); + dynamic_cast(Application::getViewer("3DViewer"))->getBounds(limBounds); widget->planeWidget->PlaceWidget(limBounds); QVector3D origin((limBounds[1] + limBounds[0]) / 2, (limBounds[3] + limBounds[2]) / 2, diff --git a/sdk/applications/actionstatemachine/ActionStateMachine.cpp b/sdk/applications/actionstatemachine/ActionStateMachine.cpp index c7028025..67ac0cba 100644 --- a/sdk/applications/actionstatemachine/ActionStateMachine.cpp +++ b/sdk/applications/actionstatemachine/ActionStateMachine.cpp @@ -154,12 +154,12 @@ void ActionStateMachine::autoNext() { void ActionStateMachine::initMainWindow() { mainWindow = new MainWindow(name); - mainWindow->setCentralViewer(Application::getViewer("MedicalImageViewer")); - mainWindow->addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionStateViewer")); - mainWindow->addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); + mainWindow->setCentralViewer(Application::getViewer("MedicalImageViewer")); + mainWindow->addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionStateViewer")); + mainWindow->addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); // never show the toolbar - Application::getViewer("MedicalImageViewer")->setToolbarAutoVisibility(false); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setToolbarAutoVisibility(false); mainWindow->showStatusBar(true); this->setMainWindow(mainWindow); @@ -231,7 +231,7 @@ QString ActionStateMachine::parseSCXMLTree() { QString initialStateName = scxmlDoc.documentElement().attribute("initial"); ActionState* initialState = statesMap->find(initialStateName).value(); machine.setInitialState(initialState); - Application::getViewer("ActionStateViewer")->setState(initialState); + dynamic_cast(Application::getViewer("ActionStateViewer"))->setState(initialState); // Connect the end of the machine with the end of the application QObject::connect(&machine, SIGNAL(finished()), QApplication::instance(), SLOT(quit())); diff --git a/sdk/applications/actionstatemachine/ActionTransition.cpp b/sdk/applications/actionstatemachine/ActionTransition.cpp index 17a4ad98..e6240cae 100644 --- a/sdk/applications/actionstatemachine/ActionTransition.cpp +++ b/sdk/applications/actionstatemachine/ActionTransition.cpp @@ -132,7 +132,7 @@ void ActionTransition::onTransition(QEvent* e) { if (nextActionState) { nextActionState->setPreviousActionStatus(status); - Application::getViewer("ActionStateViewer")->setState(nextActionState); + dynamic_cast(Application::getViewer("ActionStateViewer"))->setState(nextActionState); } if (logStream != nullptr) { diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 14b3a066..74de1e99 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -71,22 +71,22 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { updateOpenDirectoryMenu(); // now add the different viewers - setCentralViewer(Application::getViewer("MedicalImageViewer")); - addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); - addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("FrameExplorer")); - addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("PropertyExplorer")); - addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionViewer")); + setCentralViewer(Application::getViewer("MedicalImageViewer")); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("FrameExplorer")); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("PropertyExplorer")); + addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionViewer")); //Merge Explorer and FrameExplorer viewers in one layout - QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); - QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); + QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); + QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); if (dockWidgetExplorer && dockWidgetFrameExplorer) { tabifyDockWidget(dockWidgetExplorer, dockWidgetFrameExplorer); dockWidgetExplorer->raise(); } - showDockViewer(Application::getViewer("ActionViewer"), false); - Application::getViewer("ActionViewer")->setSearchPanelVisible(true); + showDockViewer(Application::getViewer("ActionViewer"), false); + dynamic_cast(Application::getViewer("ActionViewer"))->setSearchPanelVisible(true); showStatusBar(true); } @@ -382,33 +382,33 @@ void ImpMainWindow::showStatusBar(bool b) { // ------------------------ resetWindows ---------------------------- void ImpMainWindow::resetWindows() { for (QMap::iterator it = dockWidgetMap.begin(); it != dockWidgetMap.end(); it++) { - if (it.value()->widget() == Application::getViewer("Explorer")->getWidget(NULL)) { + if (it.value()->widget() == Application::getViewer("Explorer")->getWidget(NULL)) { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } else - if (it.value()->widget() == Application::getViewer("FrameExplorer")->getWidget(NULL)) { + if (it.value()->widget() == Application::getViewer("FrameExplorer")->getWidget(NULL)) { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } else - if (it.value()->widget() == Application::getViewer("PropertyExplorer")->getWidget()) { + if (it.value()->widget() == Application::getViewer("PropertyExplorer")->getWidget()) { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } else - if (it.value()->widget() == Application::getViewer("ActionViewer")->getWidget()) { + if (it.value()->widget() == Application::getViewer("ActionViewer")->getWidget()) { removeDockWidget(it.value()); addDockWidget(Qt::RightDockWidgetArea, it.value()); it.value()->show(); } } //Merge Explorer and FrameExplorer viewers in one layout - QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); - QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); + QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); + QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); if (dockWidgetExplorer && dockWidgetFrameExplorer) { tabifyDockWidget(dockWidgetExplorer, dockWidgetFrameExplorer); dockWidgetExplorer->raise(); diff --git a/sdk/components/msh/CMakeLists.txt b/sdk/components/msh/CMakeLists.txt index 8d0f49c4..bea9a279 100644 --- a/sdk/components/msh/CMakeLists.txt +++ b/sdk/components/msh/CMakeLists.txt @@ -5,6 +5,7 @@ camitk_extension(COMPONENT_EXTENSION DEFINES COMPILE_MSH_COMPONENT_API HEADERS_TO_INSTALL MshComponent.h MshExtension.h MshComponentAPI.h ENABLE_AUTO_TEST + NEEDS_VIEWER_EXTENSION interactiveviewer ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/components/msh/MshComponent.cpp b/sdk/components/msh/MshComponent.cpp index 694de836..266917ae 100644 --- a/sdk/components/msh/MshComponent.cpp +++ b/sdk/components/msh/MshComponent.cpp @@ -166,7 +166,7 @@ void MshComponent::readLegacyFormat(std::ifstream& fileStream) { initRepresentation(mesh); // add the represention in the 3D viewer - setVisibility(Application::getViewer("3DViewer"), true); + setVisibility(Application::getViewer("3DViewer"), true); } void MshComponent::readV2Format(std::ifstream& fileStream) { @@ -323,5 +323,5 @@ void MshComponent::readV2Format(std::ifstream& fileStream) { initRepresentation(mesh); // add the represention in the 3D viewer - setVisibility(Application::getViewer("3DViewer"), true); + setVisibility(Application::getViewer("3DViewer"), true); } diff --git a/sdk/components/off/CMakeLists.txt b/sdk/components/off/CMakeLists.txt index b9dfe5c6..b6b0a7a7 100644 --- a/sdk/components/off/CMakeLists.txt +++ b/sdk/components/off/CMakeLists.txt @@ -3,6 +3,7 @@ camitk_extension(COMPONENT_EXTENSION CEP_NAME SDK DESCRIPTION "Support for .off files" ENABLE_AUTO_TEST + NEEDS_VIEWER_EXTENSION interactiveviewer ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/components/off/OffComponent.cpp b/sdk/components/off/OffComponent.cpp index 597042db..0b446795 100644 --- a/sdk/components/off/OffComponent.cpp +++ b/sdk/components/off/OffComponent.cpp @@ -117,7 +117,7 @@ OffComponent::OffComponent(const QString& file) : MeshComponent(file) { initRepresentation(offMesh); // add the represention in the 3D viewer - setVisibility(Application::getViewer("3DViewer"), true); + setVisibility(Application::getViewer("3DViewer"), true); // initialize the dynamic properties //initDynamicProperties(); diff --git a/sdk/components/stl/CMakeLists.txt b/sdk/components/stl/CMakeLists.txt index 59a94651..925f1f5a 100644 --- a/sdk/components/stl/CMakeLists.txt +++ b/sdk/components/stl/CMakeLists.txt @@ -4,4 +4,5 @@ camitk_extension(COMPONENT_EXTENSION DESCRIPTION "Support for STL 3D mesh format" ENABLE_AUTO_TEST TEST_FILES head1.STL skull1.stl + NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/sdk/components/vrml/CMakeLists.txt b/sdk/components/vrml/CMakeLists.txt index 6963a34a..0e8483ba 100644 --- a/sdk/components/vrml/CMakeLists.txt +++ b/sdk/components/vrml/CMakeLists.txt @@ -5,6 +5,7 @@ camitk_extension(COMPONENT_EXTENSION ENABLE_AUTO_TEST # vrml save cannot save VRML -> level 1 is the best we can do AUTO_TEST_LEVEL 1 + NEEDS_VIEWER_EXTENSION interactiveviewer ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/components/vrml/VRMLComponentExtension.cpp b/sdk/components/vrml/VRMLComponentExtension.cpp index 901447d9..2115e1cf 100644 --- a/sdk/components/vrml/VRMLComponentExtension.cpp +++ b/sdk/components/vrml/VRMLComponentExtension.cpp @@ -70,7 +70,7 @@ bool VRMLComponentExtension::save(Component* component) const { } else if (mesh->getPointSet()) { vtkSmartPointer exporter = vtkSmartPointer::New(); - exporter->SetInput(Application::getViewer("3DViewer")->getRendererWidget()->GetRenderWindow()); + exporter->SetInput(dynamic_cast(Application::getViewer("3DViewer"))->getRendererWidget()->GetRenderWindow()); exporter->SetFileName(mesh->getFileName().toStdString().c_str()); exporter->Write(); return true; diff --git a/sdk/libraries/core/CMakeLists.txt b/sdk/libraries/core/CMakeLists.txt index 8009bb3e..8f301461 100644 --- a/sdk/libraries/core/CMakeLists.txt +++ b/sdk/libraries/core/CMakeLists.txt @@ -19,7 +19,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/operators ${CMAKE_CURRENT_SOURCE_DIR}/utils ${CMAKE_CURRENT_SOURCE_DIR}/viewer - ${CMAKE_CURRENT_SOURCE_DIR}/viewer/interactiveviewer ${CAMITK_INCLUDE_DIRECTORIES} ) @@ -153,5 +152,4 @@ set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_ set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/component/image CACHE INTERNAL "") set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/component/mesh CACHE INTERNAL "") set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/utils CACHE INTERNAL "") -set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer CACHE INTERNAL "") -set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer/interactiveviewer CACHE INTERNAL "") \ No newline at end of file +set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR}/viewer CACHE INTERNAL "") \ No newline at end of file diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index 1d0f0c31..ec79a67e 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -25,7 +25,7 @@ #include "Action.h" #include "ActionExtension.h" -#include "ActionViewer.h" +//#include "ActionViewer.h" #include "Application.h" #include "Component.h" #include "ActionWidget.h" @@ -188,7 +188,7 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { if (isEmbedded) { // if there are no parents to use use the action viewer if (parent == nullptr) { - Application::getViewer("ActionViewer")->embedActionWidget(this); + //Application::getViewer("ActionViewer")->embedActionWidget(this); } else { getWidget()->setParent(parent); diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index fa2a402a..a564bafe 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -752,8 +752,7 @@ int Application::registerAllViewers(ViewerExtension* ext) { .arg(viewer->getName(), viewer->getDescription())) } else { - cout << typeid(viewer).name() << endl; - //viewerExtensionMap.insert(); + cout << viewer->getName().toStdString() << endl; getViewerMap().insert(viewer->getName(), viewer); registered++; } @@ -867,6 +866,11 @@ ActionList Application::getActions(ComponentList selComp, QString tag) { } +Viewer* camitk::Application::getViewer(QString name) +{ + return getViewerMap().value(name); +} + // -------------------- getViewers -------------------- const ViewerList Application::getViewers() { return getViewerMap().values(); diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index 28398e6f..35bdab6e 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -260,18 +260,7 @@ public: ///@} /// get a registered viewer given its name - template - static T* getViewer(QString name) { - return dynamic_cast(getViewerMap().value(name)); - } - - template - static void addViewer(QString name) { - typeof(T).Name; - T* viewer = new T(); - getViewerMap().insert(name, viewer); - registered++; - } + static Viewer* getViewer(QString name); /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); diff --git a/sdk/libraries/core/component/image/ImageComponent.cpp b/sdk/libraries/core/component/image/ImageComponent.cpp index 6155ff43..19e87355 100644 --- a/sdk/libraries/core/component/image/ImageComponent.cpp +++ b/sdk/libraries/core/component/image/ImageComponent.cpp @@ -31,7 +31,6 @@ #include "ImageOrientationHelper.h" // -- Core stuff -#include "InteractiveViewer.h" #include "MeshComponent.h" #include "Property.h" #include "Frame.h" @@ -523,7 +522,7 @@ void ImageComponent::update3DViewer() { } if (volumeRenderingChild) { - volumeRenderingChild->setVisibility(Application::getViewer("3DViewer"), viewIn3D); + volumeRenderingChild->setVisibility(Application::getViewer("3DViewer"), viewIn3D); } } diff --git a/sdk/libraries/core/component/image/SingleImageComponent.cpp b/sdk/libraries/core/component/image/SingleImageComponent.cpp index 5ce2ca25..6fc059c9 100644 --- a/sdk/libraries/core/component/image/SingleImageComponent.cpp +++ b/sdk/libraries/core/component/image/SingleImageComponent.cpp @@ -28,7 +28,6 @@ #include "ImageComponent.h" // -- Core stuff -#include "InteractiveViewer.h" #include "Log.h" #include "Application.h" #include "Frame.h" @@ -80,7 +79,7 @@ bool SingleImageComponent::getViewSliceIn3D() const { // -------------------- setViewSliceIn3D -------------------- void SingleImageComponent::setViewSliceIn3D(bool toggle) { this->viewSliceIn3D = toggle; - this->setVisibility(Application::getViewer("3DViewer"), viewSliceIn3D); + this->setVisibility(Application::getViewer("3DViewer"), viewSliceIn3D); } // -------------------- initRepresentation -------------------- @@ -91,16 +90,16 @@ void SingleImageComponent::initRepresentation() { switch (sliceOrientation) { case Slice::AXIAL: case Slice::AXIAL_NEURO: - setVisibility(Application::getViewer("axialViewer"), true); + setVisibility(Application::getViewer("axialViewer"), true); break; case Slice::CORONAL: - setVisibility(Application::getViewer("coronalViewer"), true); + setVisibility(Application::getViewer("coronalViewer"), true); break; case Slice::SAGITTAL: - setVisibility(Application::getViewer("sagittalViewer"), true); + setVisibility(Application::getViewer("sagittalViewer"), true); break; case Slice::ARBITRARY: - setVisibility(Application::getViewer("arbitraryViewer"), true); + setVisibility(Application::getViewer("arbitraryViewer"), true); break; } } diff --git a/sdk/libraries/core/component/mesh/MeshComponent.cpp b/sdk/libraries/core/component/mesh/MeshComponent.cpp index 9239110e..ba956619 100644 --- a/sdk/libraries/core/component/mesh/MeshComponent.cpp +++ b/sdk/libraries/core/component/mesh/MeshComponent.cpp @@ -25,7 +25,6 @@ #include "MeshComponent.h" #include "Geometry.h" -#include "InteractiveViewer.h" #include "Property.h" #include "Application.h" #include "MeshDataModel.h" @@ -36,6 +35,7 @@ //-- Qt stuff #include #include +#include //-- vtk stuff #include @@ -229,7 +229,7 @@ void MeshComponent::initRepresentation(vtkSmartPointer originalPoin myGeometry->setMeshWorldTransform(getTransformFromWorld()); // add it in the InteractiveViewer (automatically) - setVisibility(Application::getViewer("3DViewer"), true); + setVisibility(Application::getViewer("3DViewer"), true); // initialize selection initSelection(); @@ -808,8 +808,8 @@ void MeshComponent::setDataRepresentationOff(int dataType) { pointDataSet->SetActiveScalars(nullptr); cellDataSet->SetActiveScalars(nullptr); // remove all color bar - Application::getViewer("3DViewer")->setColorScaleTitle(""); - Application::getViewer("3DViewer")->setColorScale(false); + //Application::getViewer("3DViewer")->setColorScaleTitle(""); + //Application::getViewer("3DViewer")->setColorScale(false); } if (dataType & VECTORS) { @@ -855,9 +855,9 @@ void MeshComponent::setScalarDataRepresentationOn(vtkSmartPointer setMapperScalarRange(range[0], range[1]); //-- show the color scale in 3D - Application::getViewer("3DViewer")->setColorScale(true); + /*Application::getViewer("3DViewer")->setColorScale(true); Application::getViewer("3DViewer")->setColorScaleTitle(dataArray->GetName()); - Application::getViewer("3DViewer")->setColorScaleMinMax(range[0], range[1]); + Application::getViewer("3DViewer")->setColorScaleMinMax(range[0], range[1]);*/ } // -------------------- setDataRepresentationVisibility -------------------- diff --git a/sdk/libraries/core/component/mesh/MeshDataModel.cpp b/sdk/libraries/core/component/mesh/MeshDataModel.cpp index 261c0e69..e9dc330f 100644 --- a/sdk/libraries/core/component/mesh/MeshDataModel.cpp +++ b/sdk/libraries/core/component/mesh/MeshDataModel.cpp @@ -25,7 +25,6 @@ #include "MeshComponent.h" #include "MeshDataModel.h" -#include "InteractiveViewer.h" #include #include diff --git a/sdk/libraries/core/component/mesh/MeshDataModel.h b/sdk/libraries/core/component/mesh/MeshDataModel.h index 70cadacb..99bb85d8 100644 --- a/sdk/libraries/core/component/mesh/MeshDataModel.h +++ b/sdk/libraries/core/component/mesh/MeshDataModel.h @@ -42,7 +42,7 @@ namespace camitk { * * CamiTK intern class to represent mesh data. */ -class MeshDataModel : public QAbstractTableModel { +class CAMITK_API MeshDataModel : public QAbstractTableModel { Q_OBJECT @@ -105,7 +105,7 @@ private : * * For example: this is used in the InteractiveViewer to show a combobox of all the point and cell scalar data. */ -class MeshDataFilterModel : public QSortFilterProxyModel { +class CAMITK_API MeshDataFilterModel : public QSortFilterProxyModel { Q_OBJECT diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index 2f89b859..495a9a3c 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -13,7 +13,6 @@ namespace camitk { class Viewer; #define registerNewViewer(X, Y) registerViewer(new X(this, QString(Y))) -#define registerNewViewerDefault(X) registerViewer(new X(this, QString("X"))) /** * @ingroup group_sdk_libraries_core_action diff --git a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h b/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h deleted file mode 100644 index ad6175e0..00000000 --- a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerAPI.h +++ /dev/null @@ -1,9 +0,0 @@ -#if defined(_WIN32) // MSVC and mingw -#ifdef COMPILE_INTERACTIVEVIEWER_API -#define INTERACTIVEVIEWER_API __declspec(dllexport) -#else -#define INTERACTIVEVIEWER_API __declspec(dllimport) -#endif // COMPILE_INTERACTIVEVIEWER_API -#else // for all other platforms INTERACTIVEVIEWER_API is defined to be "nothing" -#define INTERACTIVEVIEWER_API -#endif // MSVC and mingw \ No newline at end of file diff --git a/sdk/viewers/actionviewer/ActionViewerAPI.h b/sdk/viewers/actionviewer/ActionViewerAPI.h index 03355191..0621922e 100644 --- a/sdk/viewers/actionviewer/ActionViewerAPI.h +++ b/sdk/viewers/actionviewer/ActionViewerAPI.h @@ -1,9 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- ACTIONVIEWER_API_H.h +#ifndef ACTIONVIEWER_API_H +#define ACTIONVIEWER_API_H + +// ----------------------------------------------------------------------- +// +// ACTIONVIEWER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_ACTIONVIEWER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// ACTIONVIEWER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + #if defined(_WIN32) // MSVC and mingw + #ifdef COMPILE_ACTIONVIEWER_API #define ACTIONVIEWER_API __declspec(dllexport) #else #define ACTIONVIEWER_API __declspec(dllimport) #endif // COMPILE_ACTIONVIEWER_API + #else // for all other platforms ACTIONVIEWER_API is defined to be "nothing" + +#ifndef ACTIONVIEWER_API #define ACTIONVIEWER_API -#endif // MSVC and mingw \ No newline at end of file +#endif // ACTIONVIEWER_API + +#endif // MSVC and mingw + +#endif // ACTIONVIEWER_API_H \ No newline at end of file diff --git a/sdk/viewers/actionviewer/ActionViewerExtension.cpp b/sdk/viewers/actionviewer/ActionViewerExtension.cpp index f4511508..9506bdfc 100644 --- a/sdk/viewers/actionviewer/ActionViewerExtension.cpp +++ b/sdk/viewers/actionviewer/ActionViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void ActionViewerExtension::init() { - registerNewViewerDefault(ActionViewer); + registerNewViewer(ActionViewer, "ActionViewer"); } diff --git a/sdk/viewers/actionviewer/CMakeLists.txt b/sdk/viewers/actionviewer/CMakeLists.txt index e3b83fcb..82df8fe1 100644 --- a/sdk/viewers/actionviewer/CMakeLists.txt +++ b/sdk/viewers/actionviewer/CMakeLists.txt @@ -3,6 +3,7 @@ camitk_extension(VIEWER_EXTENSION CEP_NAME SDK DEFINES COMPILE_ACTIONVIEWER_API DESCRIPTION "An extension for the viewer that display GUI action" + ENABLE_AUTO_TEST INSTALL_ALL_HEADERS ) diff --git a/sdk/viewers/explorer/ExplorerAPI.h b/sdk/viewers/explorer/ExplorerAPI.h index a4714e90..b8ead55c 100644 --- a/sdk/viewers/explorer/ExplorerAPI.h +++ b/sdk/viewers/explorer/ExplorerAPI.h @@ -1,9 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- EXPLORER_API_H.h +#ifndef EXPLORER_API_H +#define EXPLORER_API_H + +// ----------------------------------------------------------------------- +// +// EXPLORER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_EXPLORER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// EXPLORER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + #if defined(_WIN32) // MSVC and mingw + #ifdef COMPILE_EXPLORER_API #define EXPLORER_API __declspec(dllexport) #else #define EXPLORER_API __declspec(dllimport) #endif // COMPILE_EXPLORER_API + #else // for all other platforms EXPLORER_API is defined to be "nothing" + +#ifndef EXPLORER_API #define EXPLORER_API -#endif // MSVC and mingw \ No newline at end of file +#endif // EXPLORER_API + +#endif // MSVC and mingw + +#endif // EXPLORER_API_H \ No newline at end of file diff --git a/sdk/viewers/explorer/ExplorerExtension.cpp b/sdk/viewers/explorer/ExplorerExtension.cpp index 4c690364..a748c533 100644 --- a/sdk/viewers/explorer/ExplorerExtension.cpp +++ b/sdk/viewers/explorer/ExplorerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void ExplorerExtension::init() { - registerNewViewerDefault(Explorer); + registerNewViewer(Explorer, "Explorer"); } diff --git a/sdk/viewers/explorer/ExplorerExtension.h b/sdk/viewers/explorer/ExplorerExtension.h index 6d0e3acc..f228ff6a 100644 --- a/sdk/viewers/explorer/ExplorerExtension.h +++ b/sdk/viewers/explorer/ExplorerExtension.h @@ -34,6 +34,7 @@ class EXPLORER_API ExplorerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.explorerextension.viewer.explorerextension") public: /// Constructor diff --git a/sdk/viewers/frameexplorer/FrameExplorerAPI.h b/sdk/viewers/frameexplorer/FrameExplorerAPI.h index 50f9b566..1c53bd30 100644 --- a/sdk/viewers/frameexplorer/FrameExplorerAPI.h +++ b/sdk/viewers/frameexplorer/FrameExplorerAPI.h @@ -1,9 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- FRAMEEXPLORER_API_H.h +#ifndef FRAMEEXPLORER_API_H +#define FRAMEEXPLORER_API_H + +// ----------------------------------------------------------------------- +// +// FRAMEEXPLORER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_FRAMEEXPLORER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// FRAMEEXPLORER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + #if defined(_WIN32) // MSVC and mingw + #ifdef COMPILE_FRAMEEXPLORER_API #define FRAMEEXPLORER_API __declspec(dllexport) #else #define FRAMEEXPLORER_API __declspec(dllimport) #endif // COMPILE_FRAMEEXPLORER_API + #else // for all other platforms FRAMEEXPLORER_API is defined to be "nothing" + +#ifndef FRAMEEXPLORER_API #define FRAMEEXPLORER_API -#endif // MSVC and mingw \ No newline at end of file +#endif // FRAMEEXPLORER_API + +#endif // MSVC and mingw + +#endif // FRAMEEXPLORER_API_H \ No newline at end of file diff --git a/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp b/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp index b5607b6f..4806ac4e 100644 --- a/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp +++ b/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void FrameExplorerExtension::init() { - registerNewViewerDefault(FrameExplorer); + registerNewViewer(FrameExplorer, "FrameExplorer"); } diff --git a/sdk/viewers/frameexplorer/FrameExplorerExtension.h b/sdk/viewers/frameexplorer/FrameExplorerExtension.h index 608e70a2..3b50c36c 100644 --- a/sdk/viewers/frameexplorer/FrameExplorerExtension.h +++ b/sdk/viewers/frameexplorer/FrameExplorerExtension.h @@ -34,6 +34,7 @@ class FRAMEEXPLORER_API FrameExplorerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.frameexplorerextension.viewer.frameexplorerextension") public: /// Constructor diff --git a/sdk/libraries/core/viewer/interactiveviewer/CMakeLists.txt b/sdk/viewers/interactiveviewer/CMakeLists.txt similarity index 100% rename from sdk/libraries/core/viewer/interactiveviewer/CMakeLists.txt rename to sdk/viewers/interactiveviewer/CMakeLists.txt diff --git a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.cpp b/sdk/viewers/interactiveviewer/InteractiveViewer.cpp similarity index 100% rename from sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.cpp rename to sdk/viewers/interactiveviewer/InteractiveViewer.cpp diff --git a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.h b/sdk/viewers/interactiveviewer/InteractiveViewer.h similarity index 100% rename from sdk/libraries/core/viewer/interactiveviewer/InteractiveViewer.h rename to sdk/viewers/interactiveviewer/InteractiveViewer.h diff --git a/sdk/viewers/interactiveviewer/InteractiveViewerAPI.h b/sdk/viewers/interactiveviewer/InteractiveViewerAPI.h new file mode 100644 index 00000000..b08c2179 --- /dev/null +++ b/sdk/viewers/interactiveviewer/InteractiveViewerAPI.h @@ -0,0 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- INTERACTIVEVIEWER_API_H.h +#ifndef INTERACTIVEVIEWER_API_H +#define INTERACTIVEVIEWER_API_H + +// ----------------------------------------------------------------------- +// +// INTERACTIVEVIEWER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_INTERACTIVEVIEWER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// INTERACTIVEVIEWER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + +#if defined(_WIN32) // MSVC and mingw + +#ifdef COMPILE_INTERACTIVEVIEWER_API +#define INTERACTIVEVIEWER_API __declspec(dllexport) +#else +#define INTERACTIVEVIEWER_API __declspec(dllimport) +#endif // COMPILE_INTERACTIVEVIEWER_API + +#else // for all other platforms INTERACTIVEVIEWER_API is defined to be "nothing" + +#ifndef INTERACTIVEVIEWER_API +#define INTERACTIVEVIEWER_API +#endif // INTERACTIVEVIEWER_API + +#endif // MSVC and mingw + +#endif // INTERACTIVEVIEWER_API_H \ No newline at end of file diff --git a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.cpp b/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp similarity index 96% rename from sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.cpp rename to sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp index 93404aa6..fab47e2c 100644 --- a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.cpp +++ b/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp @@ -34,6 +34,7 @@ void InteractiveViewerExtension::init() { registerNewViewer(InteractiveViewer, "3DViewer"); registerNewViewer(InteractiveViewer, "axialViewer"); registerNewViewer(InteractiveViewer, "coronalViewer"); + registerNewViewer(InteractiveViewer, "sagittalViewer"); registerNewViewer(InteractiveViewer, "arbitraryViewer"); } diff --git a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.h b/sdk/viewers/interactiveviewer/InteractiveViewerExtension.h similarity index 94% rename from sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.h rename to sdk/viewers/interactiveviewer/InteractiveViewerExtension.h index dabfa61c..cc1a38e1 100644 --- a/sdk/libraries/core/viewer/interactiveviewer/InteractiveViewerExtension.h +++ b/sdk/viewers/interactiveviewer/InteractiveViewerExtension.h @@ -34,6 +34,7 @@ class INTERACTIVEVIEWER_API InteractiveViewerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.interactiveviewerextension.viewer.interactiveviewerextension") public: /// Constructor diff --git a/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.cpp b/sdk/viewers/interactiveviewer/RendererWidget.cpp similarity index 100% rename from sdk/libraries/core/viewer/interactiveviewer/RendererWidget.cpp rename to sdk/viewers/interactiveviewer/RendererWidget.cpp diff --git a/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.h b/sdk/viewers/interactiveviewer/RendererWidget.h similarity index 99% rename from sdk/libraries/core/viewer/interactiveviewer/RendererWidget.h rename to sdk/viewers/interactiveviewer/RendererWidget.h index 95e35e10..46da9929 100644 --- a/sdk/libraries/core/viewer/interactiveviewer/RendererWidget.h +++ b/sdk/viewers/interactiveviewer/RendererWidget.h @@ -97,10 +97,10 @@ class vtkInteractorStylePick; class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget2 { #elif VTK_MAJOR_VERSION == 7 -class CAMITK_API RendererWidget : public QVTKWidget { +class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget { #elif VTK_MAJOR_VERSION == 8 -class CAMITK_API RendererWidget : public QVTKOpenGLWidget { +class INTERACTIVEVIEWER_API RendererWidget : public QVTKOpenGLWidget { #else #error "Invalid VTK version: not (yet) supported." diff --git a/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.cpp b/sdk/viewers/interactiveviewer/vtkInteractorStylePick.cpp similarity index 100% rename from sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.cpp rename to sdk/viewers/interactiveviewer/vtkInteractorStylePick.cpp diff --git a/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.h b/sdk/viewers/interactiveviewer/vtkInteractorStylePick.h similarity index 94% rename from sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.h rename to sdk/viewers/interactiveviewer/vtkInteractorStylePick.h index 22e27770..21550110 100644 --- a/sdk/libraries/core/viewer/interactiveviewer/vtkInteractorStylePick.h +++ b/sdk/viewers/interactiveviewer/vtkInteractorStylePick.h @@ -27,6 +27,7 @@ #ifndef VTKINTERACTORSTYLEPICK_H #define VTKINTERACTORSTYLEPICK_H +#include "InteractiveViewerAPI.h" #include #include @@ -36,7 +37,7 @@ class vtkUnsignedCharArray; /// Specific backward compatible interactor for CamiTK RendererWidget /// Interactor used when we are in picking mode /// -class vtkInteractorStylePick : public vtkInteractorStyle { +class INTERACTIVEVIEWER_API vtkInteractorStylePick : public vtkInteractorStyle { public: diff --git a/sdk/viewers/medicalimageviewer/CMakeLists.txt b/sdk/viewers/medicalimageviewer/CMakeLists.txt index 670aec8d..c9f22b35 100644 --- a/sdk/viewers/medicalimageviewer/CMakeLists.txt +++ b/sdk/viewers/medicalimageviewer/CMakeLists.txt @@ -4,5 +4,6 @@ camitk_extension(VIEWER_EXTENSION DEFINES COMPILE_MEDICALIMAGEVIEWER_API DESCRIPTION "An extension for the viewer that display GUI action" INSTALL_ALL_HEADERS + NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp index db3ce1ee..a45319de 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp @@ -24,10 +24,10 @@ ****************************************************************************/ // -- Core stuff -#include "Action.h" #include "MedicalImageViewer.h" -#include "InteractiveViewer.h" -#include "Application.h" +#include +#include +#include //-- Qt stuff #include @@ -84,9 +84,9 @@ void MedicalImageViewer::refresh(Viewer* whoIsAsking) { if (displayedTopLevelComponents != (unsigned) Application::getTopLevelComponents().size()) { // if there the nr of Component changed since last refresh, // and if there is something displayed in the slices viewer, show all view - if (Application::getViewer("axialViewer")->numberOfViewedComponent() > 0 - && Application::getViewer("coronalViewer")->numberOfViewedComponent() > 0 - && Application::getViewer("sagittalViewer")->numberOfViewedComponent() > 0) { + if (Application::getViewer("axialViewer")->numberOfViewedComponent() > 0 + && Application::getViewer("coronalViewer")->numberOfViewedComponent() > 0 + && Application::getViewer("sagittalViewer")->numberOfViewedComponent() > 0) { visibleLayout = VIEWER_ALL; } else { @@ -120,18 +120,18 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) { viewerVisibility.append(VIEWER_ALL); // ALL has to be the end of visible viewers // list of viewer name - viewers.insert(VIEWER_3D, Application::getViewer("3DViewer")); - viewers.insert(VIEWER_ARBITRARY, Application::getViewer("arbitraryViewer")); - viewers.insert(VIEWER_AXIAL, Application::getViewer("axialViewer")); - viewers.insert(VIEWER_CORONAL, Application::getViewer("coronalViewer")); - viewers.insert(VIEWER_SAGITTAL, Application::getViewer("sagittalViewer")); + viewers.insert(VIEWER_3D, Application::getViewer("3DViewer")); + viewers.insert(VIEWER_ARBITRARY, Application::getViewer("arbitraryViewer")); + viewers.insert(VIEWER_AXIAL, Application::getViewer("axialViewer")); + viewers.insert(VIEWER_CORONAL, Application::getViewer("coronalViewer")); + viewers.insert(VIEWER_SAGITTAL, Application::getViewer("sagittalViewer")); topLeftLayout = new QVBoxLayout(); frameLayout->addLayout(topLeftLayout, 0, 0); - topLeftLayout->addWidget(Application::getViewer("axialViewer")->getWidget(frame)); // equivalent of addWidget(Application::getViewer("axialViewer")->getWidget(frame), 0, 0) = north-west - frameLayout->addWidget(Application::getViewer("coronalViewer")->getWidget(frame), 1, 0); // north-east - frameLayout->addWidget(Application::getViewer("sagittalViewer")->getWidget(frame), 1, 1); // south-west - frameLayout->addWidget(Application::getViewer("3DViewer")->getWidget(frame), 0, 1); // south-east + topLeftLayout->addWidget(Application::getViewer("axialViewer")->getWidget(frame)); // equivalent of addWidget(Application::getViewer("axialViewer")->getWidget(frame), 0, 0) = north-west + frameLayout->addWidget(Application::getViewer("coronalViewer")->getWidget(frame), 1, 0); // north-east + frameLayout->addWidget(Application::getViewer("sagittalViewer")->getWidget(frame), 1, 1); // south-west + frameLayout->addWidget(Application::getViewer("3DViewer")->getWidget(frame), 0, 1); // south-east //-- connect foreach (LayoutVisibility v, viewerVisibility) { @@ -149,7 +149,7 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) { // ---------------------- getPropertyObject ---------------------------- QObject* MedicalImageViewer::getPropertyObject() { - return Application::getViewer("3DViewer")->getPropertyObject(); + return Application::getViewer("3DViewer")->getPropertyObject(); } // -------------------- getMenu -------------------- diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h index 42c5f33e..d00b0f66 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h @@ -38,10 +38,6 @@ #include #include -namespace camitk { - // -- Core stuff classes - class InteractiveViewer; -} /** * @ingroup group_sdk_libraries_core_viewer * @@ -143,9 +139,6 @@ private: /// number of top-level component that are currently displayed unsigned int displayedTopLevelComponents; - /// the default instance (singleton) - static MedicalImageViewer* singleton; - /// if true, the toolbar automatically updated bool autoUpdateToolbarVisibility; }; diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h b/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h index 78b7c929..04f23d26 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerAPI.h @@ -1,9 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- MEDICALIMAGEVIEWER_API_H.h +#ifndef MEDICALIMAGEVIEWER_API_H +#define MEDICALIMAGEVIEWER_API_H + +// ----------------------------------------------------------------------- +// +// MEDICALIMAGEVIEWER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_MEDICALIMAGEVIEWER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// MEDICALIMAGEVIEWER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + #if defined(_WIN32) // MSVC and mingw + #ifdef COMPILE_MEDICALIMAGEVIEWER_API #define MEDICALIMAGEVIEWER_API __declspec(dllexport) #else #define MEDICALIMAGEVIEWER_API __declspec(dllimport) #endif // COMPILE_MEDICALIMAGEVIEWER_API + #else // for all other platforms MEDICALIMAGEVIEWER_API is defined to be "nothing" + +#ifndef MEDICALIMAGEVIEWER_API #define MEDICALIMAGEVIEWER_API -#endif // MSVC and mingw \ No newline at end of file +#endif // MEDICALIMAGEVIEWER_API + +#endif // MSVC and mingw + +#endif // MEDICALIMAGEVIEWER_API_H \ No newline at end of file diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp index f8cca86f..31c915f8 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void MedicalImageViewerExtension::init() { - registerNewViewerDefault(MedicalImageViewer); + registerNewViewer(MedicalImageViewer, "MedicalImageViewer"); } diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h index 094ebde7..208b7a94 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h @@ -34,6 +34,7 @@ class MEDICALIMAGEVIEWER_API MedicalImageViewerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.medicalimageviewerextension.viewer.medicalimageviewerextension") public: /// Constructor diff --git a/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h b/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h index 77df8ba3..dfbce441 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorerAPI.h @@ -1,9 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- PROPERTYEXPLORER_API_H.h +#ifndef PROPERTYEXPLORER_API_H +#define PROPERTYEXPLORER_API_H + +// ----------------------------------------------------------------------- +// +// PROPERTYEXPLORER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_PROPERTYEXPLORER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// PROPERTYEXPLORER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + #if defined(_WIN32) // MSVC and mingw + #ifdef COMPILE_PROPERTYEXPLORER_API #define PROPERTYEXPLORER_API __declspec(dllexport) #else #define PROPERTYEXPLORER_API __declspec(dllimport) #endif // COMPILE_PROPERTYEXPLORER_API + #else // for all other platforms PROPERTYEXPLORER_API is defined to be "nothing" + +#ifndef PROPERTYEXPLORER_API #define PROPERTYEXPLORER_API -#endif // MSVC and mingw \ No newline at end of file +#endif // PROPERTYEXPLORER_API + +#endif // MSVC and mingw + +#endif // PROPERTYEXPLORER_API_H \ No newline at end of file diff --git a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp index 8cedc710..f833a9aa 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void PropertyExplorerExtension::init() { - registerNewViewerDefault(PropertyExplorer); + registerNewViewer(PropertyExplorer, "PropertyExplorer"); } diff --git a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h index c639ec47..af20bb84 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h @@ -34,6 +34,7 @@ class PROPERTYEXPLORER_API PropertyExplorerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.propertyexplorerextension.viewer.propertyexplorerextension") public: /// Constructor diff --git a/tutorials/actions/basicpicking/CMakeLists.txt b/tutorials/actions/basicpicking/CMakeLists.txt index 32e74695..c2e21bb1 100644 --- a/tutorials/actions/basicpicking/CMakeLists.txt +++ b/tutorials/actions/basicpicking/CMakeLists.txt @@ -1,4 +1,5 @@ camitk_extension(ACTION_EXTENSION ENABLE_AUTO_TEST TEST_FILES bassin.msh brain.mha sinus.mhd + NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/tutorials/actions/basicpicking/ImagePicking.cpp b/tutorials/actions/basicpicking/ImagePicking.cpp index 78cffce7..75d558bf 100644 --- a/tutorials/actions/basicpicking/ImagePicking.cpp +++ b/tutorials/actions/basicpicking/ImagePicking.cpp @@ -72,9 +72,9 @@ QWidget* ImagePicking::getWidget() { if (!isConnected) { //-- run the action every time a picking is done in the axial/sagittal or coronal planes - QObject::connect(InteractiveViewer::getAxialViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::connect(InteractiveViewer::getCoronalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::connect(InteractiveViewer::getSagittalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::connect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); isConnected = true; } @@ -132,9 +132,9 @@ Action::ApplyStatus ImagePicking::apply() { else { // disconnect //-- run the action every time a picking is done in the axial/sagittal or coronal planes - QObject::disconnect(InteractiveViewer::getAxialViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::disconnect(InteractiveViewer::getCoronalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); - QObject::disconnect(InteractiveViewer::getSagittalViewer(), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("axialViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("coronalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); + QObject::disconnect(Application::getViewer("sagittalViewer"), SIGNAL(selectionChanged()), this, SLOT(apply())); isConnected = false; } } diff --git a/tutorials/actions/bitmapviewer/CMakeLists.txt b/tutorials/actions/bitmapviewer/CMakeLists.txt index 8f3993e8..0520470c 100644 --- a/tutorials/actions/bitmapviewer/CMakeLists.txt +++ b/tutorials/actions/bitmapviewer/CMakeLists.txt @@ -1,3 +1,3 @@ camitk_extension(ACTION_EXTENSION - NEEDS_VIEWER_EXTENSION bitmap + NEEDS_VIEWER_EXTENSION bitmap interactiveviewer ) diff --git a/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp b/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp index 01d7b23e..4271452f 100644 --- a/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp +++ b/tutorials/actions/bitmapviewer/ShowBitmapViewer.cpp @@ -55,7 +55,7 @@ QWidget* ShowBitmapViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowBitmapViewer::apply() { // just add the BitMap viewer in the central viewer - Application::getMainWindow()->setCentralViewer(BitmapViewer::getInstance()); + Application::getMainWindow()->setCentralViewer(Application::getViewer("BitmapViewer")); 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"); diff --git a/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt b/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt index 62fd9d30..6fe6ac1a 100644 --- a/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt +++ b/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt @@ -3,4 +3,5 @@ camitk_extension(ACTION_EXTENSION NEEDS_CEP_LIBRARIES shakerlib ENABLE_AUTO_TEST TEST_FILES brain.mha bassin.msh head1.STL liver-smooth.obj Mesh.off mixed_3D_beam.msh robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk + NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/tutorials/actions/meshpointdata/CMakeLists.txt b/tutorials/actions/meshpointdata/CMakeLists.txt index 474cc940..408b60ad 100644 --- a/tutorials/actions/meshpointdata/CMakeLists.txt +++ b/tutorials/actions/meshpointdata/CMakeLists.txt @@ -1,7 +1,8 @@ # Call CamiTK CMake Macro to define the action camitk_extension(ACTION_EXTENSION DESCRIPTION "This extension shows how to show/hide mesh point data using a color scale" - ENABLE_AUTO_TEST + ENABLE_AUTO_TEST + NEEDS_VIEWER_EXTENSION interactiveviewer TEST_FILES brain.mha bassin.msh head1.STL liver-smooth.obj Mesh.off robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk cube-with-point-and-cell-data.vtk fieldfile.vtk check-with-color-pointdata.vtk plate-with-data.vtk female.vtk brainImageSmooth.vtk structuredgrid-with-data.vtk male.vtk cube-with-tensors.vtk imageBoundingBox.vtk binary-mesh-with-pointdata.vtk unstructured_binary_with_celldata.vtk ) diff --git a/tutorials/actions/showtextviewer/ShowTextViewer.cpp b/tutorials/actions/showtextviewer/ShowTextViewer.cpp index 20e0827c..31db1b7b 100644 --- a/tutorials/actions/showtextviewer/ShowTextViewer.cpp +++ b/tutorials/actions/showtextviewer/ShowTextViewer.cpp @@ -57,10 +57,10 @@ QWidget* ShowTextViewer::getWidget() { // --------------- apply ------------------- Action::ApplyStatus ShowTextViewer::apply() { - CAMITK_INFO(" TextViewer = " + TextViewer::getInstance()->getName()) + CAMITK_INFO(" TextViewer = " + Application::getViewer("TextViewer")->getName()) // just add the TextViewer in the central viewer - Application::getMainWindow()->setCentralViewer(TextViewer::getInstance()); + Application::getMainWindow()->setCentralViewer(Application::getViewer("TextViewer")); Application::refresh(); return SUCCESS; } diff --git a/tutorials/actions/sleepingwhileworking/CMakeLists.txt b/tutorials/actions/sleepingwhileworking/CMakeLists.txt index ee4a067f..d585c8b3 100644 --- a/tutorials/actions/sleepingwhileworking/CMakeLists.txt +++ b/tutorials/actions/sleepingwhileworking/CMakeLists.txt @@ -2,4 +2,5 @@ camitk_extension(ACTION_EXTENSION ENABLE_AUTO_TEST TEST_FILES Mesh.off BigEndian.hdr BigEndian.img BigEndianCompressed1.hdr BigEndianCompressed1.img biorad.pic brain.mha cthead1.lsm LittleEndian1.hdr LittleEndian1.img LittleEndianCompressed1.hdr LittleEndianCompressed1.img LittleEndianZ1.hdr mini-complex-slow1.nrrd mini-ten-nomask-slow1.nrrd mini-vector-slow1.nrrd ramp1.gipl + NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer ) diff --git a/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingLinear.cpp b/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingLinear.cpp index 14b1a191..2b16641a 100644 --- a/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingLinear.cpp +++ b/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingLinear.cpp @@ -78,11 +78,11 @@ void WorkingWhenSleepingLinear::process(ImageComponent* comp) { inputImage->GetDimensions(dims); // Getting the Viewer - MedicalImageViewer* myMedicalImageViewer = camitk::MedicalImageViewer::getInstance(); + MedicalImageViewer* myMedicalImageViewer = dynamic_cast(Application::getViewer("MedicalImageViewer")); myMedicalImageViewer->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); // Getting the Camera of the 3DViewer - RendererWidget* myRendererWidget = InteractiveViewer::get3DViewer()->getRendererWidget(); + RendererWidget* myRendererWidget = dynamic_cast(Application::getViewer("3DViewer"))->getRendererWidget(); vtkCamera* myCamera = myRendererWidget->getActiveCamera(); // Getting the three images slices diff --git a/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingRandom.cpp b/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingRandom.cpp index 03478382..f4479fe2 100644 --- a/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingRandom.cpp +++ b/tutorials/actions/sleepingwhileworking/WorkingWhenSleepingRandom.cpp @@ -78,11 +78,11 @@ void WorkingWhenSleepingRandom::process(ImageComponent* comp) { inputImage->GetDimensions(dims); // Getting the Viewer - MedicalImageViewer* myMedicalImageViewer = camitk::MedicalImageViewer::getInstance(); + MedicalImageViewer* myMedicalImageViewer = dynamic_cast(Application::getViewer("MedicalImageViewer")); myMedicalImageViewer->setVisibleViewer(MedicalImageViewer::VIEWER_ALL); // Getting the Camera of the 3DViewer - RendererWidget* myRendererWidget = InteractiveViewer::get3DViewer()->getRendererWidget(); + RendererWidget* myRendererWidget = dynamic_cast(Application::getViewer("3DViewer"))->getRendererWidget(); vtkCamera* myCamera = myRendererWidget->getActiveCamera(); // Getting the three images slices diff --git a/tutorials/actions/vtkwidget/BoxWidget.cpp b/tutorials/actions/vtkwidget/BoxWidget.cpp index e52703e6..2fe5156b 100644 --- a/tutorials/actions/vtkwidget/BoxWidget.cpp +++ b/tutorials/actions/vtkwidget/BoxWidget.cpp @@ -74,7 +74,7 @@ BoxWidget::~BoxWidget() { QWidget* BoxWidget::getWidget() { if (boxWidget == nullptr) { - vtkRenderWindowInteractor* iren = InteractiveViewer::get3DViewer()->getRendererWidget()->GetRenderWindow()->GetInteractor(); + vtkRenderWindowInteractor* iren = dynamic_cast(Application::getViewer("3DViewer"))->getRendererWidget()->GetRenderWindow()->GetInteractor(); // Configure the box widget including callbacks boxWidget = vtkSmartPointer::New(); @@ -84,7 +84,7 @@ QWidget* BoxWidget::getWidget() { // Initialize the dimension using the current bounding box double bounds[6]; - InteractiveViewer::get3DViewer()->getBounds(bounds); + dynamic_cast(Application::getViewer("3DViewer"))->getBounds(bounds); boxWidget->PlaceWidget(bounds); // Set box possible interactions diff --git a/tutorials/actions/vtkwidget/CMakeLists.txt b/tutorials/actions/vtkwidget/CMakeLists.txt index 836c31ac..25fb18d7 100644 --- a/tutorials/actions/vtkwidget/CMakeLists.txt +++ b/tutorials/actions/vtkwidget/CMakeLists.txt @@ -1,4 +1,5 @@ camitk_extension(ACTION_EXTENSION ENABLE_AUTO_TEST TEST_FILES bassin.msh brain.mha sinus.mhd head1.STL liver-smooth.obj Mesh.off robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk cube-with-point-and-cell-data.vtk fieldfile.vtk check-with-color-pointdata.vtk plate-with-data.vtk female.vtk brainImageSmooth.vtk structuredgrid-with-data.vtk male.vtk cube-with-tensors.vtk imageBoundingBox.vtk binary-mesh-with-pointdata.vtk unstructured_binary_with_celldata.vtk + NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer ) diff --git a/tutorials/actions/vtkwidget/ContourWidget.cpp b/tutorials/actions/vtkwidget/ContourWidget.cpp index 3b84d758..fa60e141 100644 --- a/tutorials/actions/vtkwidget/ContourWidget.cpp +++ b/tutorials/actions/vtkwidget/ContourWidget.cpp @@ -51,7 +51,6 @@ #include #include #include -#include #include using namespace camitk; @@ -214,16 +213,16 @@ void ContourWidget::initContour() { if (currentImage != nullptr) { if (viewer == Coronal) { - interactor = InteractiveViewer::getCoronalViewer()->getRendererWidget()->GetRenderWindow()->GetInteractor(); + interactor = dynamic_cast(Application::getViewer("coronalViewer"))->getRendererWidget()->GetRenderWindow()->GetInteractor(); viewedSIC = currentImage->getCoronalSlices(); } else { if (viewer == Sagittal) { - interactor = InteractiveViewer::getSagittalViewer()->getRendererWidget()->GetRenderWindow()->GetInteractor(); + interactor = dynamic_cast(Application::getViewer("sagittalViewer"))->getRendererWidget()->GetRenderWindow()->GetInteractor(); viewedSIC = currentImage->getSagittalSlices(); } else { - interactor = InteractiveViewer::getAxialViewer()->getRendererWidget()->GetRenderWindow()->GetInteractor(); + interactor = dynamic_cast(Application::getViewer("axialViewer"))->getRendererWidget()->GetRenderWindow()->GetInteractor(); viewedSIC = currentImage->getAxialSlices(); } } diff --git a/tutorials/applications/basic/CMakeLists.txt b/tutorials/applications/basic/CMakeLists.txt index 306ee0ba..37ec6f1a 100644 --- a/tutorials/applications/basic/CMakeLists.txt +++ b/tutorials/applications/basic/CMakeLists.txt @@ -1 +1,3 @@ -camitk_application() +camitk_application( + NEEDS_VIEWER_EXTENSION interactiveviewer +) diff --git a/tutorials/applications/basic/main.cpp b/tutorials/applications/basic/main.cpp index d209cae3..2e370b06 100644 --- a/tutorials/applications/basic/main.cpp +++ b/tutorials/applications/basic/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char* argv[]) { Application a("basic", argc, argv); // add an axial viewer to the default main window - a.getMainWindow()->setCentralViewer(InteractiveViewer::getAxialViewer()); + a.getMainWindow()->setCentralViewer(Application::getViewer("axialViewer")); // open an image volume Application::open(Core::getTestDataDir() + "/brain.mha"); diff --git a/tutorials/applications/fancy/CMakeLists.txt b/tutorials/applications/fancy/CMakeLists.txt index 306ee0ba..5d615d50 100644 --- a/tutorials/applications/fancy/CMakeLists.txt +++ b/tutorials/applications/fancy/CMakeLists.txt @@ -1 +1,3 @@ -camitk_application() +camitk_application( + NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer +) diff --git a/tutorials/applications/fancy/FancyMainWindow.cpp b/tutorials/applications/fancy/FancyMainWindow.cpp index 74e8770a..f2c180a8 100644 --- a/tutorials/applications/fancy/FancyMainWindow.cpp +++ b/tutorials/applications/fancy/FancyMainWindow.cpp @@ -27,7 +27,6 @@ #include "FancyMainWindow.h" #include -#include #include #include @@ -52,23 +51,24 @@ FancyMainWindow::FancyMainWindow() : MainWindow("Fancy") { // add the medical image viewer visibility = MedicalImageViewer::VIEWER_AXIAL; - ui.viewer->addWidget(MedicalImageViewer::getInstance()->getWidget(this)); + ui.viewer->addWidget(Application::getViewer("MedicalImageViewer")->getWidget(this)); // hide slide bar and modify the color and background - InteractiveViewer::getAxialViewer()->setSideFrameVisible(false); - InteractiveViewer::getAxialViewer()->setGradientBackground(false); - InteractiveViewer::getAxialViewer()->setBackgroundColor(ui.dial->palette().background().color()); - InteractiveViewer::getSagittalViewer()->setSideFrameVisible(false); - InteractiveViewer::getSagittalViewer()->setGradientBackground(false); - InteractiveViewer::getSagittalViewer()->setBackgroundColor(ui.dial->palette().background().color()); - InteractiveViewer::getCoronalViewer()->setSideFrameVisible(false); - InteractiveViewer::getCoronalViewer()->setGradientBackground(false); - InteractiveViewer::getCoronalViewer()->setBackgroundColor(ui.dial->palette().background().color()); - InteractiveViewer::getArbitraryViewer()->setSideFrameVisible(false); - InteractiveViewer::getArbitraryViewer()->setGradientBackground(false); - InteractiveViewer::getArbitraryViewer()->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("axialViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("axialViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("axialViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("sagittalViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("sagittalViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("sagittalViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("coronalViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("coronalViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("coronalViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("arbitraryViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("arbitraryViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("arbitraryViewer"))->setBackgroundColor(ui.dial->palette().background().color()); // add the 3D small little viewer - viewer3D = InteractiveViewer::getNewViewer("Fancy 3D Viewer", camitk::InteractiveViewer::GEOMETRY_VIEWER); + //viewer3D = InteractiveViewer::getNewViewer("Fancy 3D Viewer", camitk::InteractiveViewer::GEOMETRY_VIEWER); + viewer3D = dynamic_cast(Application::getViewer("3DViewer")); ui.viewer3DLayout->addWidget(viewer3D->getWidget(this)); viewer3D->setSideFrameVisible(false); viewer3D->setGradientBackground(false); @@ -195,7 +195,7 @@ void FancyMainWindow::layoutChanged() { visibility = MedicalImageViewer::VIEWER_ARBITRARY; } - MedicalImageViewer::getInstance()->setVisibleViewer(visibility); + dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(visibility); ui.dial->show(); ui.slideValue->show(); @@ -206,21 +206,21 @@ void FancyMainWindow::layoutChanged() { // -------------------- xAngleDialValueChanged -------------------- void FancyMainWindow::xAngleDialValueChanged(int value) { - InteractiveViewer::getArbitraryViewer()->xAngleChanged(value); + dynamic_cast(Application::getViewer("arbitraryViewer"))->xAngleChanged(value); updateAngleSlider(ui.xAngledial, ui.xAngleValue); refresh(); } // -------------------- yAngleDialValueChanged -------------------- void FancyMainWindow::yAngleDialValueChanged(int value) { - InteractiveViewer::getArbitraryViewer()->yAngleChanged(value); + dynamic_cast(Application::getViewer("arbitraryViewer"))->yAngleChanged(value); updateAngleSlider(ui.yAngledial, ui.yAngleValue); refresh(); } // -------------------- zAngleDialValueChanged -------------------- void FancyMainWindow::zAngleDialValueChanged(int value) { - InteractiveViewer::getArbitraryViewer()->zAngleChanged(value); + dynamic_cast(Application::getViewer("arbitraryViewer"))->zAngleChanged(value); updateAngleSlider(ui.zAngledial, ui.zAngleValue); refresh(); } @@ -263,16 +263,16 @@ InteractiveViewer* FancyMainWindow::getVisibleViewer() { InteractiveViewer* visibleViewer = NULL; switch (visibility) { case MedicalImageViewer::VIEWER_AXIAL: - visibleViewer = InteractiveViewer::getAxialViewer(); + visibleViewer = dynamic_cast(Application::getViewer("axialViewer")); break; case MedicalImageViewer::VIEWER_CORONAL: - visibleViewer = InteractiveViewer::getCoronalViewer(); + visibleViewer = dynamic_cast(Application::getViewer("coronalViewer")); break; case MedicalImageViewer::VIEWER_SAGITTAL: - visibleViewer = InteractiveViewer::getSagittalViewer(); + visibleViewer = dynamic_cast(Application::getViewer("sagittalViewer")); break; default: // arbitrary (and... 3D!) - visibleViewer = InteractiveViewer::getArbitraryViewer(); + visibleViewer = dynamic_cast(Application::getViewer("arbitraryViewer")); break; } return visibleViewer; diff --git a/tutorials/applications/fancy/FancyMainWindow.h b/tutorials/applications/fancy/FancyMainWindow.h index 07603922..d72733f2 100644 --- a/tutorials/applications/fancy/FancyMainWindow.h +++ b/tutorials/applications/fancy/FancyMainWindow.h @@ -35,10 +35,7 @@ // -- Core stuff #include #include - -namespace camitk { - class InteractiveViewer; -} +#include /** * This Class describes the fancy bare application. It sets up the main @@ -77,7 +74,7 @@ public slots: private: /// currently shown viewer - camitk::MedicalImageViewer::LayoutVisibility visibility; + MedicalImageViewer::LayoutVisibility visibility; /// manage Angle Dialog void showAngleDials(bool isShown); @@ -95,10 +92,10 @@ private: QWidget* mainWidget; /// get the currently visible viewer (axial, sagittal, coronal or arbitrary) - camitk::InteractiveViewer* getVisibleViewer(); + InteractiveViewer* getVisibleViewer(); /// specific 3D viewer for fancy - camitk::InteractiveViewer* viewer3D; + InteractiveViewer* viewer3D; }; #endif // FANCYAPP_H diff --git a/tutorials/applications/menubar/CMakeLists.txt b/tutorials/applications/menubar/CMakeLists.txt index 306ee0ba..40168868 100644 --- a/tutorials/applications/menubar/CMakeLists.txt +++ b/tutorials/applications/menubar/CMakeLists.txt @@ -1 +1,3 @@ -camitk_application() +camitk_application( + NEEDS_VIEWER_EXTENSION explorer interactiveviewer +) diff --git a/tutorials/applications/menubar/MyAppMainWindow.cpp b/tutorials/applications/menubar/MyAppMainWindow.cpp index 95fdcf77..cc8d068a 100644 --- a/tutorials/applications/menubar/MyAppMainWindow.cpp +++ b/tutorials/applications/menubar/MyAppMainWindow.cpp @@ -71,8 +71,8 @@ MyAppMainWindow::MyAppMainWindow() : MainWindow("MyApp - " + tr(Core::version)) updateActionStates(); // now add the different viewers - addDockViewer(Qt::LeftDockWidgetArea, new Explorer()); - addDockViewer(Qt::RightDockWidgetArea, InteractiveViewer::get3DViewer()); + addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); + addDockViewer(Qt::RightDockWidgetArea, dynamic_cast(Application::getViewer("3DViewer"))); showStatusBar(true); } diff --git a/tutorials/applications/simple/CMakeLists.txt b/tutorials/applications/simple/CMakeLists.txt index 306ee0ba..777ce434 100644 --- a/tutorials/applications/simple/CMakeLists.txt +++ b/tutorials/applications/simple/CMakeLists.txt @@ -1 +1,3 @@ -camitk_application() +camitk_application( + NEEDS_VIEWER_EXTENSION medicalimageviewer interactiveviewer +) diff --git a/tutorials/applications/simple/SimpleMainWindow.cpp b/tutorials/applications/simple/SimpleMainWindow.cpp index bb5f0431..122f271f 100644 --- a/tutorials/applications/simple/SimpleMainWindow.cpp +++ b/tutorials/applications/simple/SimpleMainWindow.cpp @@ -27,6 +27,7 @@ #include "SimpleMainWindow.h" // -- Core stuff +#include #include #include #include @@ -41,24 +42,24 @@ using namespace camitk; SimpleMainWindow::SimpleMainWindow() : MainWindow("Simple Demo") { // only add a main viewers - setCentralViewer(MedicalImageViewer::getInstance()); + setCentralViewer(Application::getViewer("MedicalImageViewer")); // all black like if they were old-school OpenGL - InteractiveViewer::get3DViewer()->keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier)); // simulate "a" stroke - InteractiveViewer::get3DViewer()->setBackgroundColor(Qt::black); - InteractiveViewer::get3DViewer()->setGradientBackground(false); - InteractiveViewer::getAxialViewer()->setBackgroundColor(Qt::black); - InteractiveViewer::getAxialViewer()->setGradientBackground(false); - InteractiveViewer::getSagittalViewer()->setBackgroundColor(Qt::black); - InteractiveViewer::getSagittalViewer()->setGradientBackground(false); - InteractiveViewer::getCoronalViewer()->setBackgroundColor(Qt::black); - InteractiveViewer::getCoronalViewer()->setGradientBackground(false); + dynamic_cast(Application::getViewer("3DViewer"))->keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier)); // simulate "a" stroke + dynamic_cast(Application::getViewer("3DViewer"))->setBackgroundColor(Qt::black); + dynamic_cast(Application::getViewer("3DViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("axialViewer"))->setBackgroundColor(Qt::black); + dynamic_cast(Application::getViewer("axialViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("sagittalViewer"))->setBackgroundColor(Qt::black); + dynamic_cast(Application::getViewer("sagittalViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("coronalViewer"))->setBackgroundColor(Qt::black); + dynamic_cast(Application::getViewer("coronalViewer"))->setGradientBackground(false); } // ------------- aboutToShow ----------------- void SimpleMainWindow::aboutToShow() { // remove all but the main viewer - InteractiveViewer::get3DViewer()->getToolBar()->hide(); + dynamic_cast(Application::getViewer("3DViewer"))->getToolBar()->hide(); camitk::MainWindow::aboutToShow(); } diff --git a/tutorials/applications/textviewer/CMakeLists.txt b/tutorials/applications/textviewer/CMakeLists.txt index e5288be5..ce1997f1 100644 --- a/tutorials/applications/textviewer/CMakeLists.txt +++ b/tutorials/applications/textviewer/CMakeLists.txt @@ -1 +1,3 @@ -camitk_application(NEEDS_VIEWER_EXTENSION textviewer) +camitk_application( + NEEDS_VIEWER_EXTENSION textviewer explorer + ) diff --git a/tutorials/applications/textviewer/main.cpp b/tutorials/applications/textviewer/main.cpp index 506e5d14..6dde8ce4 100644 --- a/tutorials/applications/textviewer/main.cpp +++ b/tutorials/applications/textviewer/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) { Application a("textviewer-tutorial", argc, argv); // create a textViewer instance - auto* textViewer = new TextViewer(); + Viewer* textViewer = Application::getViewer("TextViewer"); // add myViewer to the main window a.getMainWindow()->setCentralViewer(textViewer); diff --git a/tutorials/viewers/bitmap/BitmapViewer.cpp b/tutorials/viewers/bitmap/BitmapViewer.cpp index 0000490c..9bbe2ab4 100644 --- a/tutorials/viewers/bitmap/BitmapViewer.cpp +++ b/tutorials/viewers/bitmap/BitmapViewer.cpp @@ -27,7 +27,6 @@ #include #include -#include #include #include @@ -36,21 +35,8 @@ 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) { +BitmapViewer::BitmapViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::SLICE_VIEWER) { // 2D images need x right, y up, z front getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_UP); // no decoration and grey background @@ -98,7 +84,7 @@ QToolBar* BitmapViewer::getToolBar() { 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()); + Application::getMainWindow()->setCentralViewer(Application::getViewer("MedicalImageViewer")); }); } return myToolbar; @@ -111,7 +97,7 @@ void BitmapViewer::updateVisibility() { // 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())) { + if (comp->getVisibility(Application::getViewer("axialViewer"))) { comp->setVisibility(this, true); } } diff --git a/tutorials/viewers/bitmap/BitmapViewer.h b/tutorials/viewers/bitmap/BitmapViewer.h index 38e3a1a3..02a86437 100644 --- a/tutorials/viewers/bitmap/BitmapViewer.h +++ b/tutorials/viewers/bitmap/BitmapViewer.h @@ -29,6 +29,7 @@ #include "BitmapViewerAPI.h" +#include #include class QToolBar; @@ -37,12 +38,11 @@ class QToolBar; * @brief * InteractiveViewer specialized in 2D bitmap (images in jpeg, png...) */ -class BITMAP_VIEWER_API BitmapViewer : public camitk::InteractiveViewer { +class BITMAP_VIEWER_API BitmapViewer : public InteractiveViewer { Q_OBJECT public: - - static BitmapViewer* getInstance(); + BitmapViewer(camitk::ViewerExtension* extension, QString name); virtual ~BitmapViewer() override; @@ -51,16 +51,8 @@ public: QWidget* getWidget(QWidget* parent = nullptr) override; QToolBar* getToolBar() override; - -protected: - - BitmapViewer(); private: - - static BitmapViewer* singleton; - - static QString BitmapViewerName; QToolBar* myToolbar; diff --git a/tutorials/viewers/bitmap/BitmapViewerExtension.cpp b/tutorials/viewers/bitmap/BitmapViewerExtension.cpp index af1e1870..92f734c1 100644 --- a/tutorials/viewers/bitmap/BitmapViewerExtension.cpp +++ b/tutorials/viewers/bitmap/BitmapViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getActions ------------------- void BitmapViewerExtension::init() { - registerNewViewer(BitmapViewer); + registerNewViewer(BitmapViewer, "BitmapViewer"); } diff --git a/tutorials/viewers/bitmap/CMakeLists.txt b/tutorials/viewers/bitmap/CMakeLists.txt index 58c4805a..b57f43cc 100644 --- a/tutorials/viewers/bitmap/CMakeLists.txt +++ b/tutorials/viewers/bitmap/CMakeLists.txt @@ -4,5 +4,6 @@ camitk_extension(VIEWER_EXTENSION DEFINES COMPILE_BITMAP_VIEWER_API DESCRIPTION "This extension provides a simple 2D image viewer" INSTALL_ALL_HEADERS + NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/tutorials/viewers/textviewer/CMakeLists.txt b/tutorials/viewers/textviewer/CMakeLists.txt index c47130cc..a1b1c4be 100644 --- a/tutorials/viewers/textviewer/CMakeLists.txt +++ b/tutorials/viewers/textviewer/CMakeLists.txt @@ -4,5 +4,6 @@ camitk_extension(VIEWER_EXTENSION DEFINES COMPILE_TEXT_VIEWER_API DESCRIPTION "An extension to add TextViewer (a pure simple text viewer)" INSTALL_ALL_HEADERS + NEEDS_VIEWER_EXTENSION medicalimageviewer ) diff --git a/tutorials/viewers/textviewer/TextViewer.cpp b/tutorials/viewers/textviewer/TextViewer.cpp index d95d9f63..185f3606 100644 --- a/tutorials/viewers/textviewer/TextViewer.cpp +++ b/tutorials/viewers/textviewer/TextViewer.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include //-- Qt stuff @@ -37,13 +36,10 @@ #include #include -QString TextViewer::viewerName = "Text Viewer"; -TextViewer* TextViewer::singleton = nullptr; - using namespace camitk; // -------------------- Constructor -------------------- -TextViewer::TextViewer() : Viewer(viewerName) { +TextViewer::TextViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { inverse = nullptr; myMenu = nullptr; myWidget = nullptr; @@ -51,30 +47,21 @@ TextViewer::TextViewer() : Viewer(viewerName) { displayedTopLevelComponents = 0; } -// -------------------- getInstance -------------------- -TextViewer* TextViewer::getInstance() { - if (!singleton) { - singleton = new TextViewer(); - } - - return singleton; -} - // -------------------- switchCentralViewer -------------------- void TextViewer::switchCentralViewer() { // if the central viewer is the medical image viewer switch to my2DBitmapViewer (if it is not switch back to the medical image viewer) if (isVisible) { // switch back to the default MedicalImageViewer //DualViewer::getInstance()->getToolBar()->setVisible(false); - Application::getMainWindow()->setCentralViewer(MedicalImageViewer::getInstance()); - disconnect(Explorer::getInstance(), SIGNAL(selectionChanged()), this, SLOT(switchCentralViewer())); + Application::getMainWindow()->setCentralViewer(Application::getViewer("MedicalImageViewer")); + disconnect(Application::getViewer("Explorer"), SIGNAL(selectionChanged()), this, SLOT(switchCentralViewer())); Application::refresh(); } else { // switch to the custom viewer //DualViewer::getInstance()->getToolBar()->setVisible(true); - Application::getMainWindow()->setCentralViewer(TextViewer::getInstance()); - connect(Explorer::getInstance(), SIGNAL(selectionChanged()), this, SLOT(switchCentralViewer())); + Application::getMainWindow()->setCentralViewer(Application::getViewer("TextViewer")); + connect(Application::getViewer("Explorer"), SIGNAL(selectionChanged()), this, SLOT(switchCentralViewer())); // force refresh refresh(this); } diff --git a/tutorials/viewers/textviewer/TextViewer.h b/tutorials/viewers/textviewer/TextViewer.h index 1181a2b9..c6f34b6e 100644 --- a/tutorials/viewers/textviewer/TextViewer.h +++ b/tutorials/viewers/textviewer/TextViewer.h @@ -30,6 +30,7 @@ #include "TextViewerAPI.h" // -- Core stuff +#include #include // -- QT stuff @@ -58,9 +59,7 @@ public: */ /// @{ /** construtor. */ - TextViewer(); - - static TextViewer* getInstance(); + TextViewer(camitk::ViewerExtension* extension, QString name); /** destructor */ virtual ~TextViewer(); diff --git a/tutorials/viewers/textviewer/TextViewerExtension.cpp b/tutorials/viewers/textviewer/TextViewerExtension.cpp index 648f3cf8..25954ef3 100644 --- a/tutorials/viewers/textviewer/TextViewerExtension.cpp +++ b/tutorials/viewers/textviewer/TextViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getActions ------------------- void TextViewerExtension::init() { - registerNewViewer(TextViewer); + registerNewViewer(TextViewer, "TextViewer"); } -- GitLab From 0c5d4a848f4424346eacdbb7e134127fb9926dad Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Tue, 14 Jan 2020 09:39:36 +0100 Subject: [PATCH 08/26] Debug Interactive Viewer --- sdk/CMakeLists.txt | 2 +- sdk/applications/imp/CMakeLists.txt | 2 +- sdk/applications/imp/ImpMainWindow.cpp | 10 +++--- .../core/application/Application.cpp | 1 - sdk/libraries/core/viewer/ViewerExtension.cpp | 4 +-- sdk/libraries/core/viewer/ViewerExtension.h | 1 + sdk/viewers/actionviewer/ActionViewer.h | 10 +++--- .../interactiveviewer/InteractiveViewer.cpp | 33 +++++++++++++++++++ .../InteractiveViewerExtension.cpp | 10 +++--- .../propertyexplorer/PropertyExplorer.cpp | 6 ++-- 10 files changed, 54 insertions(+), 25 deletions(-) diff --git a/sdk/CMakeLists.txt b/sdk/CMakeLists.txt index db305b7e..4e4bd7f7 100644 --- a/sdk/CMakeLists.txt +++ b/sdk/CMakeLists.txt @@ -109,8 +109,8 @@ camitk_parse_test_init() camitk_add_subdirectory(libraries) camitk_add_subdirectory(testapplications) camitk_add_subdirectory(components) -camitk_add_subdirectory(actions) camitk_add_subdirectory(viewers) +camitk_add_subdirectory(actions) camitk_add_subdirectory(applications) camitk_add_subdirectory(cmake) # for cmake module installation diff --git a/sdk/applications/imp/CMakeLists.txt b/sdk/applications/imp/CMakeLists.txt index c04549e5..a15e3b15 100644 --- a/sdk/applications/imp/CMakeLists.txt +++ b/sdk/applications/imp/CMakeLists.txt @@ -1,6 +1,6 @@ camitk_application( ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx CEP_NAME SDK - NEEDS_VIEWER_EXTENSION actionviewer explorer medicalimageviewer propertyexplorer frameexplorer + NEEDS_VIEWER_EXTENSION actionviewer DESCRIPTION "All-in-one application to load actions and component and interact with them" ) diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 74de1e99..18dffc2f 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -29,18 +29,15 @@ // -- Core stuff #include #include -#include -#include #include #include #include +#include #include // for getActionDirectories() -#include -#include -#include #include #include #include +//#include using namespace camitk; @@ -54,6 +51,7 @@ using namespace camitk; #include #include #include +#include #include // ------------- constructor ----------------- @@ -86,7 +84,7 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { } showDockViewer(Application::getViewer("ActionViewer"), false); - dynamic_cast(Application::getViewer("ActionViewer"))->setSearchPanelVisible(true); + //dynamic_cast(Application::getViewer("ActionViewer"))->setSearchPanelVisible(true); showStatusBar(true); } diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index a564bafe..98ea6197 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -752,7 +752,6 @@ int Application::registerAllViewers(ViewerExtension* ext) { .arg(viewer->getName(), viewer->getDescription())) } else { - cout << viewer->getName().toStdString() << endl; getViewerMap().insert(viewer->getName(), viewer); registered++; } diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index d0049b97..07cce4b3 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -59,9 +59,7 @@ ViewerExtension::~ViewerExtension() { while (!viewers.empty()) { Viewer* toDelete = viewers.takeFirst(); // do not delete the "Quit" action: it is the action that triggers this delete! - if (toDelete->getName() != "Quit") { - delete toDelete; - } + delete toDelete; } //delete internationalization instance diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index 495a9a3c..775c5a5c 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -13,6 +13,7 @@ namespace camitk { class Viewer; #define registerNewViewer(X, Y) registerViewer(new X(this, QString(Y))) +#define registerNewInteractiveViewer(X, Y, Z) registerViewer(new X(this, QString(Y), Z)) /** * @ingroup group_sdk_libraries_core_action diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index 983c09ae..8b289a75 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -28,6 +28,11 @@ #include "ActionViewerAPI.h" +#include +#include +#include +#include + #include #include #include @@ -37,11 +42,6 @@ #include #include -#include "Viewer.h" -#include "ViewerExtension.h" -#include "Action.h" -#include "Component.h" - /** * @ingroup group_sdk_libraries_core_viewer * diff --git a/sdk/viewers/interactiveviewer/InteractiveViewer.cpp b/sdk/viewers/interactiveviewer/InteractiveViewer.cpp index e4e3e7c6..a2f8cd90 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewer.cpp +++ b/sdk/viewers/interactiveviewer/InteractiveViewer.cpp @@ -82,6 +82,8 @@ using namespace camitk; +std::array InteractiveViewer::defaultNames = { QString("3DViewer"), QString("axialViewer"), QString("coronalViewer"), QString("sagittalViewer"), QString("arbitraryViewer") }; + // ---------------------- constructor ---------------------------- InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, ViewerType type) : Viewer(extension, name) { @@ -125,6 +127,36 @@ InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, initPicking(InteractiveViewer::NO_PICKING); } + + if (myType == SLICE_VIEWER) { + if (name == defaultNames[1]) { // Axial Viewer + getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); + QString letters[4] = { QString("R"), QString("L"), QString("A"), QString("P") }; + getRendererWidget()->setOrientationDecorationsLetters(letters); + toggleOrientationDecorations(true); + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else if (name == defaultNames[2]) { // Coronal Viewer + getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK); + QString letters[4] = { QString("R"), QString("L"), QString("S"), QString("I") }; + getRendererWidget()->setOrientationDecorationsLetters(letters); + toggleOrientationDecorations(true); + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else if (name == defaultNames[3]) { // Sagittal Viewer + getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN); + QString letters[4] = { QString("A"), QString("P"), QString("S"), QString("I") }; + getRendererWidget()->setOrientationDecorationsLetters(letters); + toggleOrientationDecorations(true); + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else if (name == defaultNames[4]) { // Arbitrary Viewer + //singletonInstance->getRendererWidget()->setCameraOrientation ( RendererWidget::RIGHT_DOWN ); + toggleOrientationDecorations(false); + //singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + } + //-- current interaction is not changing slice isChangingSlice = false; @@ -137,6 +169,7 @@ InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, // init from settings initSettings(); + } // ---------------------- destructor ---------------------------- diff --git a/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp b/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp index fab47e2c..3e8626f0 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp +++ b/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp @@ -31,10 +31,10 @@ // --------------- getViewers ------------------- void InteractiveViewerExtension::init() { - registerNewViewer(InteractiveViewer, "3DViewer"); - registerNewViewer(InteractiveViewer, "axialViewer"); - registerNewViewer(InteractiveViewer, "coronalViewer"); - registerNewViewer(InteractiveViewer, "sagittalViewer"); - registerNewViewer(InteractiveViewer, "arbitraryViewer"); + registerNewInteractiveViewer(InteractiveViewer, "3DViewer", InteractiveViewer::GEOMETRY_VIEWER); + registerNewInteractiveViewer(InteractiveViewer, "axialViewer", InteractiveViewer::SLICE_VIEWER); + registerNewInteractiveViewer(InteractiveViewer, "coronalViewer", InteractiveViewer::SLICE_VIEWER); + registerNewInteractiveViewer(InteractiveViewer, "sagittalViewer", InteractiveViewer::SLICE_VIEWER); + registerNewInteractiveViewer(InteractiveViewer, "arbitraryViewer", InteractiveViewer::SLICE_VIEWER); } diff --git a/sdk/viewers/propertyexplorer/PropertyExplorer.cpp b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp index 8ded11ce..502671f1 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorer.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp @@ -175,9 +175,9 @@ QObject* PropertyExplorer::getPropertyObject() { // ---------------- clear ---------------- void PropertyExplorer::clear() { // page #0 is the property widget (not be counted) - for (int i = tabWidget->count() - 1; i > 0; i--) { - tabWidget->removeTab(i); - } + for (int i = tabWidget->count() - 1; i > 0; i--) { + tabWidget->removeTab(i); + } if (currentComponent && Application::isAlive(currentComponent)) { currentComponent->setVisibility(this, false); -- GitLab From c38ec8dde5c350ce02d6edc1a1152c425e09083f Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Tue, 21 Jan 2020 10:28:30 +0100 Subject: [PATCH 09/26] Debug imp --- sdk/actions/application/CMakeLists.txt | 2 +- .../image/reorientimage/ReorientImage.cpp | 44 +++++++++---------- .../image/reorientimage/ReorientImage.h | 4 +- sdk/applications/imp/CMakeLists.txt | 2 +- sdk/applications/imp/ImpMainWindow.cpp | 4 +- .../macros/camitk/CamiTKApplication.cmake | 2 +- sdk/viewers/actionviewer/ActionViewer.cpp | 3 ++ sdk/viewers/actionviewer/ActionViewer.h | 12 ++--- sdk/viewers/actionviewer/ActionViewerAPI.h | 15 +++++++ sdk/viewers/actionviewer/CMakeLists.txt | 1 - 10 files changed, 53 insertions(+), 36 deletions(-) diff --git a/sdk/actions/application/CMakeLists.txt b/sdk/actions/application/CMakeLists.txt index 894ed42e..85029ba0 100644 --- a/sdk/actions/application/CMakeLists.txt +++ b/sdk/actions/application/CMakeLists.txt @@ -1,7 +1,7 @@ camitk_extension(ACTION_EXTENSION DEFINES COMPILE_APPLICATION_ACTION_API CEP_NAME SDK - NEEDS_VIEWER_EXTENSION medicalimageviewer + NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer DESCRIPTION "Features actions used at aplication level (these actions are mandatory for any CamiTK appliction to work)" ) diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index ea0c410e..e795439d 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -191,17 +191,17 @@ void ReorientImage::initInternalViewer() { // get the nice vtk 3D representation from file buildGeometries(); - //// Set up the 3D viewer to visualize actual origin/orientation locations - //internalViewer = InteractiveViewer::getNewViewer("Image Orientation Viewer", InteractiveViewer::GEOMETRY_VIEWER); - //internalViewer->setHighlightMode(InteractiveViewer::OFF); - //internalViewer->toggleCopyright(false); - //internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); - - //if (modelBoundingBox) { - // internalViewer->getRendererWidget()->addProp(modelBoundingBox->getActor(InterfaceGeometry::Wireframe)); - //} - //internalViewer->getRendererWidget()->addProp(axes); - //internalViewer->getRendererWidget()->addProp(annotatedCube); + // Set up the 3D viewer to visualize actual origin/orientation locations + internalViewer = InteractiveViewer::getNewViewer("Image Orientation Viewer", InteractiveViewer::GEOMETRY_VIEWER); + internalViewer->setHighlightMode(InteractiveViewer::OFF); + internalViewer->toggleCopyright(false); + internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); + + if (modelBoundingBox) { + internalViewer->getRendererWidget()->addProp(modelBoundingBox->getActor(InterfaceGeometry::Wireframe)); + } + internalViewer->getRendererWidget()->addProp(axes); + internalViewer->getRendererWidget()->addProp(annotatedCube); } @@ -224,14 +224,14 @@ void ReorientImage::modelChanged(bool displayMaleModel) { return; } - //if (displayMaleModel) { - // internalViewer->getRendererWidget()->removeProp(femaleModel->getActor(InterfaceGeometry::Surface)); - // internalViewer->getRendererWidget()->addProp(maleModel->getActor(InterfaceGeometry::Surface)); - //} - //else { - // internalViewer->getRendererWidget()->removeProp(maleModel->getActor(InterfaceGeometry::Surface)); - // internalViewer->getRendererWidget()->addProp(femaleModel->getActor(InterfaceGeometry::Surface)); - //} + if (displayMaleModel) { + internalViewer->getRendererWidget()->removeProp(femaleModel->getActor(InterfaceGeometry::Surface)); + internalViewer->getRendererWidget()->addProp(maleModel->getActor(InterfaceGeometry::Surface)); + } + else { + internalViewer->getRendererWidget()->removeProp(maleModel->getActor(InterfaceGeometry::Surface)); + internalViewer->getRendererWidget()->addProp(femaleModel->getActor(InterfaceGeometry::Surface)); + } internalViewer->refresh(); } @@ -333,7 +333,7 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); image->setTransform(updatedTransform); - image->setFrameVisibility(Application::getViewer("3DViewer"), true); + image->setFrameVisibility(InteractiveViewer::get3DViewer(), true); } else { @@ -357,9 +357,9 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); result->setTransform(updatedTransform); - result->setFrameVisibility(Application::getViewer("3DViewer"), true); + result->setFrameVisibility(InteractiveViewer::get3DViewer(), true); } - Application::getViewer("3DViewer")->refresh(); + InteractiveViewer::get3DViewer()->refresh(); Application::refresh(); diff --git a/sdk/actions/image/reorientimage/ReorientImage.h b/sdk/actions/image/reorientimage/ReorientImage.h index 064eeb60..9ce4b3c2 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.h +++ b/sdk/actions/image/reorientimage/ReorientImage.h @@ -33,10 +33,10 @@ class vtkTransform; class vtkAnnotatedCubeActor; -class InteractiveViewer; namespace camitk { class Geometry; class ImageComponent; +class InteractiveViewer; } class ReorientImage : public camitk::Action { @@ -77,7 +77,7 @@ private: void setAxesOrientation(const QString orientation); - InteractiveViewer* internalViewer; + camitk::InteractiveViewer* internalViewer; /// Actually perform the image transformation ApplyStatus process(camitk::ImageComponent* image); diff --git a/sdk/applications/imp/CMakeLists.txt b/sdk/applications/imp/CMakeLists.txt index a15e3b15..d3c3e9f7 100644 --- a/sdk/applications/imp/CMakeLists.txt +++ b/sdk/applications/imp/CMakeLists.txt @@ -1,7 +1,7 @@ camitk_application( ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx CEP_NAME SDK NEEDS_VIEWER_EXTENSION actionviewer - DESCRIPTION "All-in-one application to load actions and component and interact with them" + DESCRIPTION "All-in-one application to load actions and components and interact with them" ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 18dffc2f..0d410356 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -31,13 +31,13 @@ #include #include #include +#include #include #include #include // for getActionDirectories() #include #include #include -//#include using namespace camitk; @@ -84,7 +84,7 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { } showDockViewer(Application::getViewer("ActionViewer"), false); - //dynamic_cast(Application::getViewer("ActionViewer"))->setSearchPanelVisible(true); + dynamic_cast(Application::getViewer("ActionViewer"))->setSearchPanelVisible(true); showStatusBar(true); } diff --git a/sdk/cmake/modules/macros/camitk/CamiTKApplication.cmake b/sdk/cmake/modules/macros/camitk/CamiTKApplication.cmake index 01265a2f..774ef84e 100644 --- a/sdk/cmake/modules/macros/camitk/CamiTKApplication.cmake +++ b/sdk/cmake/modules/macros/camitk/CamiTKApplication.cmake @@ -508,7 +508,7 @@ macro(camitk_application) # # ######################################################################### # LINKING LIBRARIES - target_link_libraries(${APPLICATION_TARGET_NAME} ${CAMITK_CORE_LIBRARIES} ${CAMITK_LIBRARIES} ${COMPONENT_EXTENSION_LIBRARIES} ${ACTION_EXTENSION_LIBRARIES} ${VIEWER_EXTENSION_LIBRARIES} ${CEP_LIBRARIES} ${XERCESC_LIBRARY} ${CAMITK_ITK_LIBRARIES} ${PYTHON_LIBRARIES} ${EXTERNAL_LIBRARIES}) + target_link_libraries(${APPLICATION_TARGET_NAME} ${CAMITK_CORE_LIBRARIES} ${CAMITK_LIBRARIES} ${COMPONENT_EXTENSION_LIBRARIES} ${ACTION_EXTENSION_LIBRARIES} ${VIEWER_EXTENSION_LIBRARIES} ${CEP_LIBRARIES} ${XERCESC_LIBRARY} ${CAMITK_ITK_LIBRARIES} ${PYTHON_LIBRARIES} ${EXTERNAL_LIBRARIES}) diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index ba8c8bc2..3430b09c 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -49,6 +49,9 @@ ActionViewer::ActionViewer(ViewerExtension* extension, QString name) : Viewer(ex searchFramePanel = nullptr; } +ActionViewer::~ActionViewer() { +} + // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer* whoIsAsking) { updateActionViewer(ViewerRefresh); diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index 8b289a75..dcac6a0c 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -64,10 +64,10 @@ public: */ ///@{ /// constructor - ActionViewer(camitk::ViewerExtension*, QString); + ActionViewer(camitk::ViewerExtension* extension, QString name); /// destructor - ~ActionViewer() override = default; + virtual ~ActionViewer(); /// @name Inherited from Viewer //@{ @@ -77,19 +77,19 @@ public: }; /// refresh the view (can be interesting to know which other viewer is calling this) - void refresh(Viewer* whoIsAsking = nullptr) override; + virtual void refresh(Viewer* whoIsAsking = nullptr); /// get the viewer widget. @param parent the parent widget for the viewer widget - QWidget* getWidget(QWidget* parent = nullptr) override; + virtual QWidget* getWidget(QWidget* parent = nullptr); //@} /// @name Specific to the Action viewer //@{ /// embed an action widget in the stacked widget - void embedActionWidget(camitk::Action*); + virtual void embedActionWidget(camitk::Action*); /// show/hide the search panel (hidden by default) - void setSearchPanelVisible(bool); + virtual void setSearchPanelVisible(bool); //@} protected slots : diff --git a/sdk/viewers/actionviewer/ActionViewerAPI.h b/sdk/viewers/actionviewer/ActionViewerAPI.h index 0621922e..39229001 100644 --- a/sdk/viewers/actionviewer/ActionViewerAPI.h +++ b/sdk/viewers/actionviewer/ActionViewerAPI.h @@ -56,4 +56,19 @@ #endif // MSVC and mingw +// ----------------------------------------------------------------------- +// It seems that MSVC does not understand exception specification +// If I understand it well, when _declspec() is used, there is a default +// nothrow attribute. +// I did not find the throw attribute. It seems that msvc is therefore ignoring the +// specification of the type of the exception. +// The compiler therefore issues a warning. +// The following line is to avoid this particular warning. +// The best would be to ask msvc not only to take the exception into account, but also +// its type. Anyway, I did not find how to do that anywhere, and I am not sure this is +// possible... +#if defined(_WIN32) && !defined(__MINGW32__) // MSVC only +#pragma warning( disable : 4290 ) +#endif // MSVC only + #endif // ACTIONVIEWER_API_H \ No newline at end of file diff --git a/sdk/viewers/actionviewer/CMakeLists.txt b/sdk/viewers/actionviewer/CMakeLists.txt index 82df8fe1..e3b83fcb 100644 --- a/sdk/viewers/actionviewer/CMakeLists.txt +++ b/sdk/viewers/actionviewer/CMakeLists.txt @@ -3,7 +3,6 @@ camitk_extension(VIEWER_EXTENSION CEP_NAME SDK DEFINES COMPILE_ACTIONVIEWER_API DESCRIPTION "An extension for the viewer that display GUI action" - ENABLE_AUTO_TEST INSTALL_ALL_HEADERS ) -- GitLab From 235a9e86ee8a1fa9452b495d5f9d8cd9894804e4 Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Thu, 23 Jan 2020 14:52:30 +0100 Subject: [PATCH 10/26] New Architecture Viewer --- .../image/reorientimage/CMakeLists.txt | 2 +- .../image/reorientimage/ReorientImage.cpp | 10 +- .../image/reorientimage/ReorientImage.h | 5 +- .../core/application/Application.cpp | 99 +++++++++++-------- sdk/libraries/core/application/Application.h | 3 + .../core/viewer}/InteractiveViewer.cpp | 6 +- .../core/viewer}/InteractiveViewer.h | 62 ++++++------ .../core/viewer}/RendererWidget.cpp | 5 + .../core/viewer}/RendererWidget.h | 8 +- sdk/libraries/core/viewer/Viewer.cpp | 5 + sdk/libraries/core/viewer/Viewer.h | 2 + sdk/libraries/core/viewer/ViewerExtension.cpp | 14 +++ sdk/libraries/core/viewer/ViewerExtension.h | 6 ++ .../core/viewer}/vtkInteractorStylePick.cpp | 5 + .../core/viewer}/vtkInteractorStylePick.h | 8 +- .../interactivegeometryviewer/CMakeLists.txt | 8 ++ .../InteractiveGeometryViewer.cpp | 39 ++++++++ .../InteractiveGeometryViewer.h | 71 +++++++++++++ .../InteractiveGeometryViewerAPI.h | 59 +++++++++++ .../InteractiveGeometryViewerExtension.cpp | 36 +++++++ .../InteractiveGeometryViewerExtension.h | 63 ++++++++++++ .../CMakeLists.txt | 2 +- .../InteractiveSliceViewer.cpp | 39 ++++++++ .../InteractiveSliceViewer.h | 71 +++++++++++++ .../InteractiveSliceViewerAPI.h} | 30 +++--- .../InteractiveSliceViewerExtension.cpp} | 15 ++- .../InteractiveSliceViewerExtension.h} | 20 ++-- 27 files changed, 574 insertions(+), 119 deletions(-) rename sdk/{viewers/interactiveviewer => libraries/core/viewer}/InteractiveViewer.cpp (99%) rename sdk/{viewers/interactiveviewer => libraries/core/viewer}/InteractiveViewer.h (94%) rename sdk/{viewers/interactiveviewer => libraries/core/viewer}/RendererWidget.cpp (99%) rename sdk/{viewers/interactiveviewer => libraries/core/viewer}/RendererWidget.h (99%) rename sdk/{viewers/interactiveviewer => libraries/core/viewer}/vtkInteractorStylePick.cpp (99%) rename sdk/{viewers/interactiveviewer => libraries/core/viewer}/vtkInteractorStylePick.h (94%) create mode 100644 sdk/viewers/interactivegeometryviewer/CMakeLists.txt create mode 100644 sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp create mode 100644 sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h create mode 100644 sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h create mode 100644 sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp create mode 100644 sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h rename sdk/viewers/{interactiveviewer => interactivesliceviewer}/CMakeLists.txt (79%) create mode 100644 sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp create mode 100644 sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h rename sdk/viewers/{interactiveviewer/InteractiveViewerAPI.h => interactivesliceviewer/InteractiveSliceViewerAPI.h} (70%) rename sdk/viewers/{interactiveviewer/InteractiveViewerExtension.cpp => interactivesliceviewer/InteractiveSliceViewerExtension.cpp} (65%) rename sdk/viewers/{interactiveviewer/InteractiveViewerExtension.h => interactivesliceviewer/InteractiveSliceViewerExtension.h} (70%) diff --git a/sdk/actions/image/reorientimage/CMakeLists.txt b/sdk/actions/image/reorientimage/CMakeLists.txt index e1efd02a..00a9b67e 100644 --- a/sdk/actions/image/reorientimage/CMakeLists.txt +++ b/sdk/actions/image/reorientimage/CMakeLists.txt @@ -1,7 +1,7 @@ # Call CamiTK CMake Macro to define the action camitk_extension(ACTION_EXTENSION NEEDS_COMPONENT_EXTENSION vtkmesh - NEEDS_VIEWER_EXTENSION interactiveviewer + NEEDS_VIEWER_EXTENSION interactivegeometryviewer CEP_NAME SDK DESCRIPTION "Allows one to reorient a volumic image." ENABLE_AUTO_TEST diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index e795439d..db4def1e 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -28,7 +28,7 @@ // CamiTK #include -#include +#include #include #include #include @@ -192,7 +192,7 @@ void ReorientImage::initInternalViewer() { buildGeometries(); // Set up the 3D viewer to visualize actual origin/orientation locations - internalViewer = InteractiveViewer::getNewViewer("Image Orientation Viewer", InteractiveViewer::GEOMETRY_VIEWER); + internalViewer = dynamic_cast(Application::getNewViewer("Image Orientation Viewer", "InteractiveGeometryViewer")); internalViewer->setHighlightMode(InteractiveViewer::OFF); internalViewer->toggleCopyright(false); internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); @@ -333,7 +333,7 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); image->setTransform(updatedTransform); - image->setFrameVisibility(InteractiveViewer::get3DViewer(), true); + image->setFrameVisibility(Application::getViewer("3DViewer"), true); } else { @@ -357,9 +357,9 @@ Action::ApplyStatus ReorientImage::process(ImageComponent* image) { updatedTransform->SetMatrix(updatedMatrix); result->setTransform(updatedTransform); - result->setFrameVisibility(InteractiveViewer::get3DViewer(), true); + result->setFrameVisibility(Application::getViewer("3DViewer"), true); } - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); Application::refresh(); diff --git a/sdk/actions/image/reorientimage/ReorientImage.h b/sdk/actions/image/reorientimage/ReorientImage.h index 9ce4b3c2..51c02872 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.h +++ b/sdk/actions/image/reorientimage/ReorientImage.h @@ -31,12 +31,13 @@ // Include ui_ReorientImage.h to be able to declare an instance of Ui::ReorientImage #include "ui_ReorientImage.h" +#include + class vtkTransform; class vtkAnnotatedCubeActor; namespace camitk { class Geometry; class ImageComponent; -class InteractiveViewer; } class ReorientImage : public camitk::Action { @@ -77,7 +78,7 @@ private: void setAxesOrientation(const QString orientation); - camitk::InteractiveViewer* internalViewer; + InteractiveGeometryViewer* internalViewer; /// Actually perform the image transformation ApplyStatus process(camitk::ImageComponent* image); diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index 98ea6197..d8540c1b 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -704,13 +704,6 @@ QMap& Application::getActionMap() { return actionMap; } -// -------------------- getViewerMap -------------------- -QMap& Application::getViewerMap() { - static QMap viewerMap; - - return viewerMap; -} - // -------------------- getActions -------------------- const ActionList Application::getActions() { return getActionMap().values(); @@ -740,26 +733,6 @@ int Application::registerAllActions(ActionExtension* ext) { return registered; } -// -------------------- registerAllViewers -------------------- -int Application::registerAllViewers(ViewerExtension* ext) { - int registered = 0; - - foreach (Viewer* viewer, ext->getViewers()) { - // check if an action with same name was not already registered - if (getViewerMap().contains(viewer->getName())) { - CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" - "extension of same name already registered") - .arg(viewer->getName(), viewer->getDescription())) - } - else { - getViewerMap().insert(viewer->getName(), viewer); - registered++; - } - } - - return registered; -} - // -------------------- unregisterAllActions -------------------- int Application::unregisterAllActions(ActionExtension* ext) { int unregistered = 0; @@ -772,18 +745,6 @@ int Application::unregisterAllActions(ActionExtension* ext) { return unregistered; } -// -------------------- unregisterAllViewers -------------------- -int Application::unregisterAllViewers(ViewerExtension* ext) { - int unregistered = 0; - - foreach (Viewer* viewer, ext->getViewers()) { - getViewerMap().remove(viewer->getName()); - unregistered++; - } - - return unregistered; -} - // ---------------- actionLessThan ---------------- bool actionLessThan(const camitk::Action* a1, const camitk::Action* a2) { // This method is needed by qsort in the sort method to sort action by name @@ -865,16 +826,74 @@ ActionList Application::getActions(ComponentList selComp, QString tag) { } -Viewer* camitk::Application::getViewer(QString name) +// -------------------- getViewerMap -------------------- +QMap& Application::getViewerMap() { + static QMap viewerMap; + + return viewerMap; +} + +// -------------------- registerAllViewers -------------------- +int Application::registerAllViewers(ViewerExtension* ext) { + int registered = 0; + + foreach(Viewer* viewer, ext->getViewers()) { + // check if an action with same name was not already registered + if (getViewerMap().contains(viewer->getName())) { + CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" + "extension of same name already registered") + .arg(viewer->getName(), viewer->getDescription())) + } + else { + getViewerMap().insert(viewer->getName(), viewer); + registered++; + } + } + + return registered; +} + +Viewer* Application::getViewer(QString name) { return getViewerMap().value(name); } +Viewer* Application::getNewViewer(QString name, QString className) { + + int i = 0; + QList vl = ExtensionManager::getViewerExtensionsList(); + + while (i < vl.size() && vl.at(i)->getViewerClassName() != className) { + i++; + } + + if (i < vl.size()) { + ViewerExtension* ve = vl.at(i); + return ve->getNewInstance(name); + } + else { + CAMITK_ERROR_ALT(tr("No extension manage viewer of type %1\n").arg(className)) + return nullptr; + } +} + // -------------------- getViewers -------------------- const ViewerList Application::getViewers() { return getViewerMap().values(); } +// -------------------- unregisterAllViewers -------------------- +int Application::unregisterAllViewers(ViewerExtension* ext) { + int unregistered = 0; + + foreach(Viewer* viewer, ext->getViewers()) { + getViewerMap().remove(viewer->getName()); + unregistered++; + } + + return unregistered; +} + // ---------- isAlive ---------- bool Application::isAlive(Component* comp) { return getAllComponents().contains(comp); diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index 35bdab6e..24771c66 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -262,6 +262,8 @@ public: /// get a registered viewer given its name static Viewer* getViewer(QString name); + static Viewer * getNewViewer(QString name, QString className); + /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); @@ -528,6 +530,7 @@ private: * see http://www.parashift.com/c++-faq/ctors.html */ static QMap& getViewerMap(); + ///@} /// @name Property management diff --git a/sdk/viewers/interactiveviewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/InteractiveViewer.cpp similarity index 99% rename from sdk/viewers/interactiveviewer/InteractiveViewer.cpp rename to sdk/libraries/core/viewer/InteractiveViewer.cpp index a2f8cd90..1d3c0312 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/InteractiveViewer.cpp @@ -80,7 +80,7 @@ #include -using namespace camitk; +namespace camitk { std::array InteractiveViewer::defaultNames = { QString("3DViewer"), QString("axialViewer"), QString("coronalViewer"), QString("sagittalViewer"), QString("arbitraryViewer") }; @@ -2337,4 +2337,6 @@ void InteractiveViewerFrame::keyPressEvent(QKeyEvent* e) { // CMake automoc generates a camitk namespace error on this moc // for the RendererWidget member of the InteractiveViewer class. // By including it, the file kept out library-camitkcore_automoc.cpp -#include "moc_InteractiveViewer.cpp" \ No newline at end of file +#include "moc_InteractiveViewer.cpp" + +} \ No newline at end of file diff --git a/sdk/viewers/interactiveviewer/InteractiveViewer.h b/sdk/libraries/core/viewer/InteractiveViewer.h similarity index 94% rename from sdk/viewers/interactiveviewer/InteractiveViewer.h rename to sdk/libraries/core/viewer/InteractiveViewer.h index be7e0e13..a117fe39 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/InteractiveViewer.h @@ -28,7 +28,7 @@ #define INTERACTIVE_VIEWER_H // -- Core stuff -#include "InteractiveViewerAPI.h" +#include "CamiTKAPI.h" #include "Component.h" #include "ViewerExtension.h" #include "Viewer.h" @@ -54,22 +54,20 @@ class vtkCamera; class vtkEventQtSlotConnect; namespace camitk { - // -- Core stuff classes - class SliderSpinBoxWidget; - class GeometricObject; - class InterfaceGeometry; - class InterfaceBitMap; - class MeshDataFilterModel; - class PropertyObject; - class Property; -} - +// -- Core stuff classes +class SliderSpinBoxWidget; +class GeometricObject; +class InterfaceGeometry; +class InterfaceBitMap; class InteractiveViewer; +class MeshDataFilterModel; +class PropertyObject; +class Property; using vtkSmartPointerCamera = vtkSmartPointer; /// InteractiveViewerFrame is just a QFrame that delegates all key events to its InteractiveViewer -class INTERACTIVEVIEWER_API InteractiveViewerFrame : public QFrame { +class CAMITK_API InteractiveViewerFrame : public QFrame { public: /// default constructor InteractiveViewerFrame(QWidget* parent, InteractiveViewer* s3D) : QFrame(parent), myInteractiveViewer(s3D) {} @@ -140,7 +138,7 @@ protected: * */ -class INTERACTIVEVIEWER_API InteractiveViewer : public camitk::Viewer { +class CAMITK_API InteractiveViewer : public Viewer { Q_OBJECT Q_ENUMS(HighlightMode RendererWidget::ControlMode RendererWidget::CameraOrientation) // so that it can be used in property editor @@ -172,7 +170,7 @@ public: SELECTION_ONLY ///< the selected Components are in default mode, the non-selected are hidden }; - InteractiveViewer(camitk::ViewerExtension * extension, QString & name, ViewerType type=SLICE_VIEWER); + InteractiveViewer(ViewerExtension * extension, QString & name, ViewerType type); /** Destructor */ ~InteractiveViewer() override; @@ -188,7 +186,7 @@ public: unsigned int numberOfViewedComponent() override; /// Refresh the display. - void refresh(camitk::Viewer* whoIsAsking = nullptr) override; + void refresh(Viewer* whoIsAsking = nullptr) override; /// get the InteractiveViewer widget (QTreeWidget). @param parent the parent widget for the viewer widget QWidget* getWidget(QWidget* parent) override; @@ -365,16 +363,16 @@ protected: void toggleInterpolation(); /// Update the display of the given Component, according to its selection state and the current HighlightMode. - void updateSelectionDisplay(camitk::Component*); + void updateSelectionDisplay(Component*); /// the map containing all the actors in the InteractiveViewer - QMultiMap > actorMap; + QMultiMap > actorMap; /// add the given actor of the given Component to the renderer and insert it in the map - void addActor(camitk::Component*, vtkSmartPointer); + void addActor(Component*, vtkSmartPointer); /// remove all the given Component actors from the renderer and delete comp from the map - void removeAllActors(camitk::Component*); + void removeAllActors(Component*); /// number of top-level component that are currently displayed unsigned int displayedTopLevelComponents; @@ -391,7 +389,7 @@ protected: /** Slider used to control the slice index in a InteractiveViewer. This slider is visible only when * the scene a 2D viewer (see constructor). */ - camitk::SliderSpinBoxWidget* sliceSlider; + SliderSpinBoxWidget* sliceSlider; /// the InteractiveViewer frame InteractiveViewerFrame* frame; @@ -414,7 +412,7 @@ protected: /// the ComboBox for mesh scalar data QComboBox* scalarDataComboBox; - camitk::MeshDataFilterModel* scalarDataModel; + MeshDataFilterModel* scalarDataModel; /// init all the actions (called only once in the getWidget() method) void initActions(); @@ -487,7 +485,7 @@ protected: * but for speed optimization that are not yet selected in the explorer. * They will all be selected in the explorer when the user release the mouse button. */ - std::vector pickedComponent; + std::vector pickedComponent; /** Current picking mode, NO_PICKING be default. */ PickingMode pickingMode; @@ -537,42 +535,42 @@ protected: /** * The property object that holds the properties of this viewer */ - camitk::PropertyObject* propertyObject; + PropertyObject* propertyObject; /** * The property that stands for the type of highlight mode of the 3D viewer. */ - camitk::Property* highlightModeProperty; + Property* highlightModeProperty; /** * The property that stands for the background color of the viewer. */ - camitk::Property* backgroundColorProperty; + Property* backgroundColorProperty; /** * Property that tells whether the viewer use a gradient background color or not. */ - camitk::Property* backgroundGradientColorProperty; + Property* backgroundGradientColorProperty; /** * Property that tells whether the viewer uses lines as tubes or not. */ - camitk::Property* linesAsTubesProperty; + Property* linesAsTubesProperty; /** * Property that tells whether the viewer uses the backface culling option or not. */ - camitk::Property* backfaceCullingProperty; + Property* backfaceCullingProperty; /** * Property that tells whether the screenshot action is visible or not. */ - camitk::Property* screenshotActionProperty; + Property* screenshotActionProperty; /** * Property which defines the point size of each point in the 3D viewer. */ - camitk::Property* pointSizeProperty; + Property* pointSizeProperty; /** * Create and handle the CamiTK properties of this viewer. @@ -626,7 +624,9 @@ protected slots: }; -Q_DECLARE_METATYPE(InteractiveViewer::HighlightMode) +} + +Q_DECLARE_METATYPE(camitk::InteractiveViewer::HighlightMode) #endif diff --git a/sdk/viewers/interactiveviewer/RendererWidget.cpp b/sdk/libraries/core/viewer/RendererWidget.cpp similarity index 99% rename from sdk/viewers/interactiveviewer/RendererWidget.cpp rename to sdk/libraries/core/viewer/RendererWidget.cpp index 9c6e4015..2c926927 100644 --- a/sdk/viewers/interactiveviewer/RendererWidget.cpp +++ b/sdk/libraries/core/viewer/RendererWidget.cpp @@ -122,6 +122,8 @@ Q_COREAPP_STARTUP_FUNCTION(initialize) #endif +namespace camitk { + // static instantiation (global variable, global only for this file) QMap screenshotMap; @@ -1473,4 +1475,7 @@ void RendererWidget::setPicker(vtkSmartPointer woodyWood) // I know, it is really Woody Wood Pecker, but you know, with a french accent... GetInteractor()->SetPicker(woodyWood); } +} + + } \ No newline at end of file diff --git a/sdk/viewers/interactiveviewer/RendererWidget.h b/sdk/libraries/core/viewer/RendererWidget.h similarity index 99% rename from sdk/viewers/interactiveviewer/RendererWidget.h rename to sdk/libraries/core/viewer/RendererWidget.h index 46da9929..6a394bcb 100644 --- a/sdk/viewers/interactiveviewer/RendererWidget.h +++ b/sdk/libraries/core/viewer/RendererWidget.h @@ -31,7 +31,7 @@ #endif // -- Core stuff -#include "InteractiveViewerAPI.h" +#include "CamiTKAPI.h" // -- VTK stuff #include @@ -73,6 +73,8 @@ class vtkScalarBarWidget; class vtkTextMapper; class vtkAbstractPropPicker; +namespace camitk { + class vtkInteractorStylePick; /** @@ -94,7 +96,7 @@ class vtkInteractorStylePick; * **/ #if VTK_MAJOR_VERSION == 6 -class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget2 { +class CAMITK_API RendererWidget : public QVTKWidget2 { #elif VTK_MAJOR_VERSION == 7 class INTERACTIVEVIEWER_API RendererWidget : public QVTKWidget { @@ -523,5 +525,7 @@ protected : }; +} + #endif //RENDERERWIDGET_H diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index 2bd8a5f5..d347b341 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -68,4 +68,9 @@ bool Viewer::getToolBarVisibility() { return toolbarVisibility; } +ViewerExtension * Viewer::getExtension() +{ + return extension; +} + } diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index 4ea77b39..e2d2a7c7 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -110,6 +110,8 @@ public: /// Is actually useful (and defined) in Explorer. virtual void refreshInterfaceNode(Component* comp) {}; + ViewerExtension* getExtension(); + signals: /// this signal is emitted when the current selection was changed by the viewer diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index 07cce4b3..ec88e17c 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -30,6 +30,7 @@ #include "Log.h" #include +#include namespace camitk { @@ -54,6 +55,11 @@ void ViewerExtension::initResources() { } } +QString ViewerExtension::getViewerClassName() +{ + return viewerClassName; +} + // -------------------- destructor -------------------- ViewerExtension::~ViewerExtension() { while (!viewers.empty()) { @@ -74,6 +80,14 @@ void ViewerExtension::registerViewer(Viewer* viewer) { viewers.append(viewer); } +Viewer* ViewerExtension::getNewInstance(QString name) { + int typeId = QMetaType::type(name.toStdString().c_str()); + const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId); + QObject *o = metaObject->newInstance(); + Viewer* viewer = qobject_cast(o); + return viewer; +} + // -------------------- getActions -------------------- const ViewerList& ViewerExtension::getViewers() { return viewers; diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index 775c5a5c..4a7449b7 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -65,6 +65,10 @@ public: /// Load, for the selected langage (asked to the Application), the associated .qm file void initResources(); + QString getViewerClassName(); + + Viewer * getNewInstance(QString name); + protected: /// register an viewer instance void registerViewer(Viewer*); @@ -78,6 +82,8 @@ private: /// Provide internationalization support for text output. QTranslator* translator{ nullptr }; + + QString viewerClassName; }; } diff --git a/sdk/viewers/interactiveviewer/vtkInteractorStylePick.cpp b/sdk/libraries/core/viewer/vtkInteractorStylePick.cpp similarity index 99% rename from sdk/viewers/interactiveviewer/vtkInteractorStylePick.cpp rename to sdk/libraries/core/viewer/vtkInteractorStylePick.cpp index 2337c473..d3ff2ece 100644 --- a/sdk/viewers/interactiveviewer/vtkInteractorStylePick.cpp +++ b/sdk/libraries/core/viewer/vtkInteractorStylePick.cpp @@ -35,6 +35,8 @@ #include #include +namespace camitk { + //----------------------- Picking Interactor ----------------------- #if VTK_MAJOR_VERSION < 8 vtkInstantiatorNewMacro(vtkInteractorStylePick); @@ -300,4 +302,7 @@ void vtkInteractorStylePick::Pick() { // ------------------------------- PrintSelf ------------------------------- void vtkInteractorStylePick::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); +} + + } \ No newline at end of file diff --git a/sdk/viewers/interactiveviewer/vtkInteractorStylePick.h b/sdk/libraries/core/viewer/vtkInteractorStylePick.h similarity index 94% rename from sdk/viewers/interactiveviewer/vtkInteractorStylePick.h rename to sdk/libraries/core/viewer/vtkInteractorStylePick.h index 21550110..e564b05d 100644 --- a/sdk/viewers/interactiveviewer/vtkInteractorStylePick.h +++ b/sdk/libraries/core/viewer/vtkInteractorStylePick.h @@ -27,17 +27,19 @@ #ifndef VTKINTERACTORSTYLEPICK_H #define VTKINTERACTORSTYLEPICK_H -#include "InteractiveViewerAPI.h" +#include "CamiTKAPI.h" #include #include class vtkUnsignedCharArray; +namespace camitk { + /// Specific backward compatible interactor for CamiTK RendererWidget /// Interactor used when we are in picking mode /// -class INTERACTIVEVIEWER_API vtkInteractorStylePick : public vtkInteractorStyle { +class CAMITK_API vtkInteractorStylePick : public vtkInteractorStyle { public: @@ -73,4 +75,6 @@ protected: bool areaPicking; }; +} + #endif //VTKINTERACTORSTYLEPICK_H diff --git a/sdk/viewers/interactivegeometryviewer/CMakeLists.txt b/sdk/viewers/interactivegeometryviewer/CMakeLists.txt new file mode 100644 index 00000000..79072986 --- /dev/null +++ b/sdk/viewers/interactivegeometryviewer/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_INTERACTIVEGEOMETRYVIEWER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp new file mode 100644 index 00000000..c0beb8b7 --- /dev/null +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp @@ -0,0 +1,39 @@ +/***************************************************************************** + * $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$ + ****************************************************************************/ + + // -- Core stuff +#include "InteractiveGeometryViewer.h" +#include + +using namespace camitk; + +// -------------------- Constructor -------------------- +InteractiveGeometryViewer::InteractiveGeometryViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::GEOMETRY_VIEWER) { +} + + +// -------------------- Destructor -------------------- +InteractiveGeometryViewer::~InteractiveGeometryViewer() { +} \ No newline at end of file diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h new file mode 100644 index 00000000..e3cb29ed --- /dev/null +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h @@ -0,0 +1,71 @@ +/***************************************************************************** + * $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 INTERACTIVEGEOMETRYVIEWER_H +#define INTERACTIVEGEOMETRYVIEWER_H + + // -- Core stuff +#include "InteractiveGeometryViewerAPI.h" +#include "ViewerExtension.h" +#include "InteractiveViewer.h" + +// -- QT stuff +#include +#include +#include +#include + +/** + * @ingroup group_sdk_libraries_core_viewer + * + * @brief + * The views manager. + * + * MedicalImageViewer is a viewer that can display from 1 to 4 InteractiveViewer that represents + * the axial, coronal, sagittal and 3D view of the same medical image. + * The views used the default InteractiveViewers singletons. + * + * This class follow the "singleton" design pattern, see getInstance(). + * Singleton is enforced/recommanded so that actions can directly use the show*Viewer() methods + * + * \image html libraries/medicalimageviewer.png "The medical image viewer" + * + */ +class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewer : public camitk::InteractiveViewer { + Q_OBJECT + +public: + + InteractiveGeometryViewer(camitk::ViewerExtension*, QString); + + /** destructor */ + ~InteractiveGeometryViewer() override; + +}; + + +#endif + diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h new file mode 100644 index 00000000..76ec4de6 --- /dev/null +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h @@ -0,0 +1,59 @@ +/***************************************************************************** +* $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$ +****************************************************************************/ + +// ----- MEDICALIMAGEVIEWER_API_H.h +#ifndef INTERACTIVEGEOMETRYVIEWER_API_H +#define INTERACTIVEGEOMETRYVIEWER_API_H + +// ----------------------------------------------------------------------- +// +// MEDICALIMAGEVIEWER_API +// +// ----------------------------------------------------------------------- + +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_INTERACTIVEGEOMETRYVIEWER_API +// flag defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// INTERACTIVEGEOMETRYVIEWER_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. + +#if defined(_WIN32) // MSVC and mingw + +#ifdef COMPILE_INTERACTIVEGEOMETRYVIEWER_API +#define INTERACTIVEGEOMETRYVIEWER_API __declspec(dllexport) +#else +#define INTERACTIVEGEOMETRYVIEWER_API __declspec(dllimport) +#endif // COMPILE_INTERACTIVEGEOMETRYVIEWER_API + +#else // for all other platforms INTERACTIVEGEOMETRYVIEWER_API is defined to be "nothing" + +#ifndef INTERACTIVEGEOMETRYVIEWER_API +#define INTERACTIVEGEOMETRYVIEWER_API +#endif // INTERACTIVEGEOMETRYVIEWER_API + +#endif // MSVC and mingw + +#endif // INTERACTIVEGEOMETRYVIEWER_API_H \ No newline at end of file diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp new file mode 100644 index 00000000..56355cd7 --- /dev/null +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp @@ -0,0 +1,36 @@ +/***************************************************************************** + * $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 "InteractiveGeometryViewerExtension.h" + + // include generated actions headers +#include "InteractiveGeometryViewer.h" + +// --------------- getViewers ------------------- +void InteractiveGeometryViewerExtension::init() { + registerNewViewer(InteractiveGeometryViewer, "3DViewer"); +} + diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h new file mode 100644 index 00000000..c926295e --- /dev/null +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h @@ -0,0 +1,63 @@ +/***************************************************************************** + * $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 INTERACTIVEGEOMETRYVIEWEREXTENSION_H +#define INTERACTIVEGEOMETRYVIEWEREXTENSION_H + +#include "InteractiveGeometryViewerAPI.h" + +#include "ViewerExtension.h" + +class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewerExtension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.interactivegeometryviewerextension.viewer.interactivegeometryviewerextension") + +public: + /// Constructor + InteractiveGeometryViewerExtension() : ViewerExtension() {}; + + /// Destructor + virtual ~InteractiveGeometryViewerExtension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Interactive Geometry Viewer Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the interactive geometry viewer"; + }; + + /// initialize all the actions + virtual void init(); + +}; + +#endif // INTERACTIVEGEOMETRYVIEWEREXTENSION_H + + diff --git a/sdk/viewers/interactiveviewer/CMakeLists.txt b/sdk/viewers/interactivesliceviewer/CMakeLists.txt similarity index 79% rename from sdk/viewers/interactiveviewer/CMakeLists.txt rename to sdk/viewers/interactivesliceviewer/CMakeLists.txt index d834e577..39328f7a 100644 --- a/sdk/viewers/interactiveviewer/CMakeLists.txt +++ b/sdk/viewers/interactivesliceviewer/CMakeLists.txt @@ -1,7 +1,7 @@ # Call CamiTK CMake Macro to define the action camitk_extension(VIEWER_EXTENSION CEP_NAME SDK - DEFINES COMPILE_INTERACTIVEVIEWER_API + DEFINES COMPILE_INTERACTIVESLICEVIEWER_API DESCRIPTION "An extension for the viewer that display GUI action" INSTALL_ALL_HEADERS ) diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp new file mode 100644 index 00000000..0dbf5b44 --- /dev/null +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp @@ -0,0 +1,39 @@ +/***************************************************************************** + * $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$ + ****************************************************************************/ + +// -- Core stuff +#include "InteractiveSliceViewer.h" +#include + +using namespace camitk; + +// -------------------- Constructor -------------------- +InteractiveSliceViewer::InteractiveSliceViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::SLICE_VIEWER) { +} + + +// -------------------- Destructor -------------------- +InteractiveSliceViewer::~InteractiveSliceViewer() { +} \ No newline at end of file diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h new file mode 100644 index 00000000..c2b57731 --- /dev/null +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h @@ -0,0 +1,71 @@ +/***************************************************************************** + * $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 INTERACTIVESLICEVIEWER_H +#define INTERACTIVESLICEVIEWER_H + +// -- Core stuff +#include "InteractiveSliceViewerAPI.h" +#include "ViewerExtension.h" +#include "InteractiveViewer.h" + +// -- QT stuff +#include +#include +#include +#include + +/** + * @ingroup group_sdk_libraries_core_viewer + * + * @brief + * The views manager. + * + * MedicalImageViewer is a viewer that can display from 1 to 4 InteractiveViewer that represents + * the axial, coronal, sagittal and 3D view of the same medical image. + * The views used the default InteractiveViewers singletons. + * + * This class follow the "singleton" design pattern, see getInstance(). + * Singleton is enforced/recommanded so that actions can directly use the show*Viewer() methods + * + * \image html libraries/medicalimageviewer.png "The medical image viewer" + * + */ +class INTERACTIVESLICEVIEWER_API InteractiveSliceViewer : public camitk::InteractiveViewer { + Q_OBJECT + +public: + + InteractiveSliceViewer(camitk::ViewerExtension*, QString); + + /** destructor */ + ~InteractiveSliceViewer() override; + +}; + + +#endif + diff --git a/sdk/viewers/interactiveviewer/InteractiveViewerAPI.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h similarity index 70% rename from sdk/viewers/interactiveviewer/InteractiveViewerAPI.h rename to sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h index b08c2179..56b4b9e2 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewerAPI.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h @@ -23,37 +23,37 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ -// ----- INTERACTIVEVIEWER_API_H.h -#ifndef INTERACTIVEVIEWER_API_H -#define INTERACTIVEVIEWER_API_H +// ----- MEDICALIMAGEVIEWER_API_H.h +#ifndef INTERACTIVESLICEVIEWER_API_H +#define INTERACTIVESLICEVIEWER_API_H // ----------------------------------------------------------------------- // -// INTERACTIVEVIEWER_API +// MEDICALIMAGEVIEWER_API // // ----------------------------------------------------------------------- // The following ifdef block is the standard way of creating macros which make exporting -// from a DLL simpler. All files within this DLL are compiled with the COMPILE_INTERACTIVEVIEWER_API +// from a DLL simpler. All files within this DLL are compiled with the COMPILE_INTERACTIVESLICEVIEWER_API // flag defined on the command line. this symbol should not be defined on any project // that uses this DLL. This way any other project whose source files include this file see -// INTERACTIVEVIEWER_API functions as being imported from a DLL, wheras this DLL sees symbols +// INTERACTIVESLICEVIEWER_API functions as being imported from a DLL, wheras this DLL sees symbols // defined with this macro as being exported. #if defined(_WIN32) // MSVC and mingw -#ifdef COMPILE_INTERACTIVEVIEWER_API -#define INTERACTIVEVIEWER_API __declspec(dllexport) +#ifdef COMPILE_INTERACTIVESLICEVIEWER_API +#define INTERACTIVESLICEVIEWER_API __declspec(dllexport) #else -#define INTERACTIVEVIEWER_API __declspec(dllimport) -#endif // COMPILE_INTERACTIVEVIEWER_API +#define INTERACTIVESLICEVIEWER_API __declspec(dllimport) +#endif // COMPILE_INTERACTIVESLICEVIEWER_API -#else // for all other platforms INTERACTIVEVIEWER_API is defined to be "nothing" +#else // for all other platforms INTERACTIVESLICEVIEWER_API is defined to be "nothing" -#ifndef INTERACTIVEVIEWER_API -#define INTERACTIVEVIEWER_API -#endif // INTERACTIVEVIEWER_API +#ifndef InteractiveSliceViewer_API +#define InteractiveSliceViewer_API +#endif // InteractiveSliceViewer_API #endif // MSVC and mingw -#endif // INTERACTIVEVIEWER_API_H \ No newline at end of file +#endif // INTERACTIVESLICEVIEWER_API_H \ No newline at end of file diff --git a/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.cpp similarity index 65% rename from sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp rename to sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.cpp index 3e8626f0..d09f8da7 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewerExtension.cpp +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.cpp @@ -24,17 +24,16 @@ ****************************************************************************/ -#include "InteractiveViewerExtension.h" +#include "InteractiveSliceViewerExtension.h" // include generated actions headers -#include "InteractiveViewer.h" +#include "InteractiveSliceViewer.h" // --------------- getViewers ------------------- -void InteractiveViewerExtension::init() { - registerNewInteractiveViewer(InteractiveViewer, "3DViewer", InteractiveViewer::GEOMETRY_VIEWER); - registerNewInteractiveViewer(InteractiveViewer, "axialViewer", InteractiveViewer::SLICE_VIEWER); - registerNewInteractiveViewer(InteractiveViewer, "coronalViewer", InteractiveViewer::SLICE_VIEWER); - registerNewInteractiveViewer(InteractiveViewer, "sagittalViewer", InteractiveViewer::SLICE_VIEWER); - registerNewInteractiveViewer(InteractiveViewer, "arbitraryViewer", InteractiveViewer::SLICE_VIEWER); +void InteractiveSliceViewerExtension::init() { + registerNewViewer(InteractiveSliceViewer, "axialViewer"); + registerNewViewer(InteractiveSliceViewer, "coronalViewer"); + registerNewViewer(InteractiveSliceViewer, "sagittalViewer"); + registerNewViewer(InteractiveSliceViewer, "arbitraryViewer"); } diff --git a/sdk/viewers/interactiveviewer/InteractiveViewerExtension.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h similarity index 70% rename from sdk/viewers/interactiveviewer/InteractiveViewerExtension.h rename to sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h index cc1a38e1..204f6028 100644 --- a/sdk/viewers/interactiveviewer/InteractiveViewerExtension.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h @@ -24,33 +24,33 @@ ****************************************************************************/ -#ifndef INTERACTIVEVIEWEREXTENSION_H -#define INTERACTIVEVIEWEREXTENSION_H +#ifndef INTERACTIVESLICEVIEWEREXTENSION_H +#define INTERACTIVESLICEVIEWEREXTENSION_H -#include "InteractiveViewerAPI.h" +#include "InteractiveSliceViewerAPI.h" #include "ViewerExtension.h" -class INTERACTIVEVIEWER_API InteractiveViewerExtension : public camitk::ViewerExtension { +class INTERACTIVESLICEVIEWER_API InteractiveSliceViewerExtension : public camitk::ViewerExtension { Q_OBJECT Q_INTERFACES(camitk::ViewerExtension); - Q_PLUGIN_METADATA(IID "fr.imag.camitk.interactiveviewerextension.viewer.interactiveviewerextension") + Q_PLUGIN_METADATA(IID "fr.imag.camitk.interactivesliceviewerextension.viewer.interactivesliceviewerextension") public: /// Constructor - InteractiveViewerExtension() : ViewerExtension() {}; + InteractiveSliceViewerExtension() : ViewerExtension() {}; /// Destructor - virtual ~InteractiveViewerExtension() = default; + virtual ~InteractiveSliceViewerExtension() = default; /// Method returning the action extension name virtual QString getName() { - return "Interactive Viewer Extension"; + return "Interactive Slice Viewer Extension"; }; /// Method returning the action extension descrption virtual QString getDescription() { - return "An extension for the interactive viewer"; + return "An extension for the interactive slice viewer"; }; /// initialize all the actions @@ -58,6 +58,6 @@ public: }; -#endif // INTERACTIVEVIEWEREXTENSION_H +#endif // INTERACTIVESLICEVIEWEREXTENSION_H -- GitLab From c3072f1cca40797591ad9b947a81c38a0c08fa7b Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Mon, 27 Jan 2020 17:22:02 +0100 Subject: [PATCH 11/26] Correct some bugs with interactive viewer --- sdk/actions/application/CMakeLists.txt | 2 +- sdk/actions/frame/editframes/CMakeLists.txt | 1 - sdk/actions/frame/editframes/FrameEditor.cpp | 1 - sdk/actions/frame/editframes/FrameEditor.h | 1 + sdk/actions/image/pixelcolorchanger/CMakeLists.txt | 1 - sdk/actions/image/showin3d/CMakeLists.txt | 1 - sdk/actions/image/volumerendering/CMakeLists.txt | 1 - sdk/actions/image/volumerendering/VolumeRenderingAction.cpp | 1 - sdk/actions/image/volumerendering/VolumeRenderingAction.h | 1 + sdk/actions/mesh/basicmesh/CMakeLists.txt | 1 - sdk/actions/mesh/meshprocessing/CMakeLists.txt | 1 - sdk/components/msh/CMakeLists.txt | 1 - sdk/components/off/CMakeLists.txt | 1 - sdk/components/stl/CMakeLists.txt | 1 - sdk/components/vrml/CMakeLists.txt | 1 - sdk/libraries/core/application/Application.cpp | 2 ++ sdk/libraries/core/viewer/ViewerExtension.cpp | 2 ++ sdk/libraries/core/viewer/ViewerExtension.h | 1 - .../interactivegeometryviewer/InteractiveGeometryViewer.cpp | 3 ++- sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp | 3 ++- sdk/viewers/medicalimageviewer/CMakeLists.txt | 1 - 21 files changed, 11 insertions(+), 17 deletions(-) diff --git a/sdk/actions/application/CMakeLists.txt b/sdk/actions/application/CMakeLists.txt index 85029ba0..894ed42e 100644 --- a/sdk/actions/application/CMakeLists.txt +++ b/sdk/actions/application/CMakeLists.txt @@ -1,7 +1,7 @@ camitk_extension(ACTION_EXTENSION DEFINES COMPILE_APPLICATION_ACTION_API CEP_NAME SDK - NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer + NEEDS_VIEWER_EXTENSION medicalimageviewer DESCRIPTION "Features actions used at aplication level (these actions are mandatory for any CamiTK appliction to work)" ) diff --git a/sdk/actions/frame/editframes/CMakeLists.txt b/sdk/actions/frame/editframes/CMakeLists.txt index d975d7c7..a0db214f 100644 --- a/sdk/actions/frame/editframes/CMakeLists.txt +++ b/sdk/actions/frame/editframes/CMakeLists.txt @@ -2,7 +2,6 @@ camitk_extension(ACTION_EXTENSION DESCRIPTION "Manipulating Frames." ENABLE_AUTO_TEST - NEEDS_VIEWER_EXTENSION interactiveviewer TEST_FILES brain.mha structured.vtk ) diff --git a/sdk/actions/frame/editframes/FrameEditor.cpp b/sdk/actions/frame/editframes/FrameEditor.cpp index 384a41e4..961d3f28 100644 --- a/sdk/actions/frame/editframes/FrameEditor.cpp +++ b/sdk/actions/frame/editframes/FrameEditor.cpp @@ -27,7 +27,6 @@ #include "FrameEditor.h" // CamiTK -#include #include using namespace camitk; diff --git a/sdk/actions/frame/editframes/FrameEditor.h b/sdk/actions/frame/editframes/FrameEditor.h index f260b7e8..a0c29d85 100644 --- a/sdk/actions/frame/editframes/FrameEditor.h +++ b/sdk/actions/frame/editframes/FrameEditor.h @@ -28,6 +28,7 @@ #include "Action.h" #include "Component.h" +#include "Viewer.h" #include #include diff --git a/sdk/actions/image/pixelcolorchanger/CMakeLists.txt b/sdk/actions/image/pixelcolorchanger/CMakeLists.txt index 26c2f6c5..5d27e4d5 100644 --- a/sdk/actions/image/pixelcolorchanger/CMakeLists.txt +++ b/sdk/actions/image/pixelcolorchanger/CMakeLists.txt @@ -1,6 +1,5 @@ # Call CamiTK CMake Macro to define the action camitk_extension(ACTION_EXTENSION - NEEDS_VIEWER_EXTENSION interactiveviewer DEFINES COMPILE_PIXELCOLORCHANGER_ACTION_API CEP_NAME SDK DESCRIPTION "Allows changing the color of the image pixels" diff --git a/sdk/actions/image/showin3d/CMakeLists.txt b/sdk/actions/image/showin3d/CMakeLists.txt index b65d93a0..20477a4c 100644 --- a/sdk/actions/image/showin3d/CMakeLists.txt +++ b/sdk/actions/image/showin3d/CMakeLists.txt @@ -1,5 +1,4 @@ camitk_extension(ACTION_EXTENSION - NEEDS_VIEWER_EXTENSION interactiveviewer CEP_NAME SDK DESCRIPTION "Display in 3D the component" ENABLE_AUTO_TEST diff --git a/sdk/actions/image/volumerendering/CMakeLists.txt b/sdk/actions/image/volumerendering/CMakeLists.txt index 67dd4f10..6fd90a6c 100644 --- a/sdk/actions/image/volumerendering/CMakeLists.txt +++ b/sdk/actions/image/volumerendering/CMakeLists.txt @@ -1,6 +1,5 @@ camitk_extension(ACTION_EXTENSION NEEDS_QTXML - NEEDS_VIEWER_EXTENSION interactiveviewer DEFINES COMPILE_VOLUME_RENDERING_ACTION_API CEP_NAME SDK DESCRIPTION "Use ray tracing to produce a 3D reprensation of the image" diff --git a/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp b/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp index e1f64a39..277c0c5f 100644 --- a/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp +++ b/sdk/actions/image/volumerendering/VolumeRenderingAction.cpp @@ -52,7 +52,6 @@ // -- Application -- #include #include -#include #include #include diff --git a/sdk/actions/image/volumerendering/VolumeRenderingAction.h b/sdk/actions/image/volumerendering/VolumeRenderingAction.h index 59001719..88430220 100644 --- a/sdk/actions/image/volumerendering/VolumeRenderingAction.h +++ b/sdk/actions/image/volumerendering/VolumeRenderingAction.h @@ -27,6 +27,7 @@ #include #include +#include #include diff --git a/sdk/actions/mesh/basicmesh/CMakeLists.txt b/sdk/actions/mesh/basicmesh/CMakeLists.txt index 5883c65f..89b936f9 100644 --- a/sdk/actions/mesh/basicmesh/CMakeLists.txt +++ b/sdk/actions/mesh/basicmesh/CMakeLists.txt @@ -2,7 +2,6 @@ camitk_extension(ACTION_EXTENSION DEFINES COMPILE_BASIC_MESH_ACTION_API CEP_NAME SDK DESCRIPTION "Provides basic actions on meshes" - NEEDS_VIEWER_EXTENSION interactiveviewer ENABLE_AUTO_TEST TEST_FILES brain.mha bassin.msh liver-smooth.obj Mesh.off robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk cube-with-point-and-cell-data.vtk fieldfile.vtk check-with-color-pointdata.vtk plate-with-data.vtk female.vtk brainImageSmooth.vtk structuredgrid-with-data.vtk male.vtk cube-with-tensors.vtk imageBoundingBox.vtk binary-mesh-with-pointdata.vtk unstructured_binary_with_celldata.vtk ) diff --git a/sdk/actions/mesh/meshprocessing/CMakeLists.txt b/sdk/actions/mesh/meshprocessing/CMakeLists.txt index 16bc7c13..bbd49baa 100644 --- a/sdk/actions/mesh/meshprocessing/CMakeLists.txt +++ b/sdk/actions/mesh/meshprocessing/CMakeLists.txt @@ -1,6 +1,5 @@ camitk_extension(ACTION_EXTENSION NEEDS_COMPONENT_EXTENSION vtkmesh - NEEDS_VIEWER_EXTENSION interactiveviewer DEFINES COMPILE_MESHPROCESSING_ACTION_API CEP_NAME SDK DESCRIPTION "Features some nice algorithms for mesh processing" diff --git a/sdk/components/msh/CMakeLists.txt b/sdk/components/msh/CMakeLists.txt index bea9a279..8d0f49c4 100644 --- a/sdk/components/msh/CMakeLists.txt +++ b/sdk/components/msh/CMakeLists.txt @@ -5,7 +5,6 @@ camitk_extension(COMPONENT_EXTENSION DEFINES COMPILE_MSH_COMPONENT_API HEADERS_TO_INSTALL MshComponent.h MshExtension.h MshComponentAPI.h ENABLE_AUTO_TEST - NEEDS_VIEWER_EXTENSION interactiveviewer ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/components/off/CMakeLists.txt b/sdk/components/off/CMakeLists.txt index b6b0a7a7..b9dfe5c6 100644 --- a/sdk/components/off/CMakeLists.txt +++ b/sdk/components/off/CMakeLists.txt @@ -3,7 +3,6 @@ camitk_extension(COMPONENT_EXTENSION CEP_NAME SDK DESCRIPTION "Support for .off files" ENABLE_AUTO_TEST - NEEDS_VIEWER_EXTENSION interactiveviewer ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/components/stl/CMakeLists.txt b/sdk/components/stl/CMakeLists.txt index 925f1f5a..59a94651 100644 --- a/sdk/components/stl/CMakeLists.txt +++ b/sdk/components/stl/CMakeLists.txt @@ -4,5 +4,4 @@ camitk_extension(COMPONENT_EXTENSION DESCRIPTION "Support for STL 3D mesh format" ENABLE_AUTO_TEST TEST_FILES head1.STL skull1.stl - NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/sdk/components/vrml/CMakeLists.txt b/sdk/components/vrml/CMakeLists.txt index 0e8483ba..6963a34a 100644 --- a/sdk/components/vrml/CMakeLists.txt +++ b/sdk/components/vrml/CMakeLists.txt @@ -5,7 +5,6 @@ camitk_extension(COMPONENT_EXTENSION ENABLE_AUTO_TEST # vrml save cannot save VRML -> level 1 is the best we can do AUTO_TEST_LEVEL 1 - NEEDS_VIEWER_EXTENSION interactiveviewer ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index d8540c1b..15d652f0 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -838,6 +838,8 @@ int Application::registerAllViewers(ViewerExtension* ext) { int registered = 0; foreach(Viewer* viewer, ext->getViewers()) { + cout << ext->getName().toStdString() << endl; + cout << viewer->getName().toStdString() << endl; // check if an action with same name was not already registered if (getViewerMap().contains(viewer->getName())) { CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index ec88e17c..c537eacf 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -31,6 +31,7 @@ #include #include +#include namespace camitk { @@ -85,6 +86,7 @@ Viewer* ViewerExtension::getNewInstance(QString name) { const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId); QObject *o = metaObject->newInstance(); Viewer* viewer = qobject_cast(o); + registerViewer(viewer); return viewer; } diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index 4a7449b7..a4e3e371 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -13,7 +13,6 @@ namespace camitk { class Viewer; #define registerNewViewer(X, Y) registerViewer(new X(this, QString(Y))) -#define registerNewInteractiveViewer(X, Y, Z) registerViewer(new X(this, QString(Y), Z)) /** * @ingroup group_sdk_libraries_core_action diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp index c0beb8b7..e3bae5fa 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp @@ -30,7 +30,8 @@ using namespace camitk; // -------------------- Constructor -------------------- -InteractiveGeometryViewer::InteractiveGeometryViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::GEOMETRY_VIEWER) { +InteractiveGeometryViewer::InteractiveGeometryViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::GEOMETRY_VIEWER) +{ } diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp index 0dbf5b44..e93e700e 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp @@ -30,7 +30,8 @@ using namespace camitk; // -------------------- Constructor -------------------- -InteractiveSliceViewer::InteractiveSliceViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::SLICE_VIEWER) { +InteractiveSliceViewer::InteractiveSliceViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::SLICE_VIEWER) +{ } diff --git a/sdk/viewers/medicalimageviewer/CMakeLists.txt b/sdk/viewers/medicalimageviewer/CMakeLists.txt index c9f22b35..670aec8d 100644 --- a/sdk/viewers/medicalimageviewer/CMakeLists.txt +++ b/sdk/viewers/medicalimageviewer/CMakeLists.txt @@ -4,6 +4,5 @@ camitk_extension(VIEWER_EXTENSION DEFINES COMPILE_MEDICALIMAGEVIEWER_API DESCRIPTION "An extension for the viewer that display GUI action" INSTALL_ALL_HEADERS - NEEDS_VIEWER_EXTENSION interactiveviewer ) -- GitLab From 100f20d970457561e91af5fbf45eb5faa305fd8d Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Thu, 30 Jan 2020 16:16:59 +0100 Subject: [PATCH 12/26] Functionnality register viewer and get viewer. Add explorer for viewer --- .../image/reorientimage/ReorientImage.cpp | 2 +- .../actionstatemachine/ActionStateViewer.cpp | 2 +- .../actionstatemachine/ActionStateViewer.h | 2 +- sdk/libraries/core/CamiTKAPI.h | 3 + sdk/libraries/core/ExtensionManager.cpp | 30 +- sdk/libraries/core/action/Action.cpp | 6 +- .../core/application/Application.cpp | 102 +++++- sdk/libraries/core/application/Application.h | 18 +- sdk/libraries/core/component/Component.cpp | 9 + .../core/viewer/InteractiveViewer.cpp | 2 +- sdk/libraries/core/viewer/InteractiveViewer.h | 16 +- sdk/libraries/core/viewer/Viewer.cpp | 46 ++- sdk/libraries/core/viewer/Viewer.h | 29 +- sdk/libraries/core/viewer/ViewerExtension.cpp | 11 +- sdk/libraries/core/viewer/ViewerExtension.h | 4 +- sdk/viewers/actionviewer/ActionViewer.cpp | 6 +- sdk/viewers/actionviewer/ActionViewer.h | 2 +- sdk/viewers/actionviewer2/ActionViewer.cpp | 342 ++++++++++++++++++ sdk/viewers/actionviewer2/ActionViewer.h | 142 ++++++++ .../actionviewer2/ActionViewer2Extension.cpp | 35 ++ .../actionviewer2/ActionViewer2Extension.h | 62 ++++ sdk/viewers/actionviewer2/CMakeLists.txt | 8 + sdk/viewers/explorer/Explorer.cpp | 2 +- sdk/viewers/explorer/Explorer.h | 2 +- sdk/viewers/frameexplorer/FrameExplorer.cpp | 2 +- sdk/viewers/frameexplorer/FrameExplorer.h | 2 +- .../InteractiveGeometryViewer.cpp | 5 +- .../InteractiveGeometryViewer.h | 9 +- .../InteractiveGeometryViewerExtension.cpp | 3 +- .../InteractiveGeometryViewerExtension.h | 2 +- .../InteractiveSliceViewer.cpp | 2 +- .../InteractiveSliceViewer.h | 2 +- .../medicalimageviewer/MedicalImageViewer.cpp | 7 +- .../medicalimageviewer/MedicalImageViewer.h | 2 +- .../propertyexplorer/PropertyExplorer.cpp | 8 +- .../propertyexplorer/PropertyExplorer.h | 2 +- 36 files changed, 854 insertions(+), 75 deletions(-) create mode 100644 sdk/viewers/actionviewer2/ActionViewer.cpp create mode 100644 sdk/viewers/actionviewer2/ActionViewer.h create mode 100644 sdk/viewers/actionviewer2/ActionViewer2Extension.cpp create mode 100644 sdk/viewers/actionviewer2/ActionViewer2Extension.h create mode 100644 sdk/viewers/actionviewer2/CMakeLists.txt diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index db4def1e..66547eaf 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -192,7 +192,7 @@ void ReorientImage::initInternalViewer() { buildGeometries(); // Set up the 3D viewer to visualize actual origin/orientation locations - internalViewer = dynamic_cast(Application::getNewViewer("Image Orientation Viewer", "InteractiveGeometryViewer")); + internalViewer = dynamic_cast(Application::getNewViewer("Image Orientation Viewer", "InteractiveGeometryViewer")); internalViewer->setHighlightMode(InteractiveViewer::OFF); internalViewer->toggleCopyright(false); internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.cpp b/sdk/applications/actionstatemachine/ActionStateViewer.cpp index ae2c247f..9f648a8a 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewer.cpp @@ -34,7 +34,7 @@ #include "ActionStateViewer.h" // ---------------- constructor ---------------- -ActionStateViewer::ActionStateViewer(camitk::ViewerExtension* extension, QString name) : Viewer(extension, name) { +ActionStateViewer::ActionStateViewer(QString name) : Viewer(name) { myWidget = nullptr; } diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.h b/sdk/applications/actionstatemachine/ActionStateViewer.h index de9cb04e..c4e45308 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.h +++ b/sdk/applications/actionstatemachine/ActionStateViewer.h @@ -49,7 +49,7 @@ class ActionStateViewer : public camitk::Viewer { public: - ActionStateViewer(camitk::ViewerExtension* extension, QString name); + ActionStateViewer(QString name); /// get the viewer widget. @param parent the parent widget for the viewer widget virtual QWidget* getWidget(QWidget* parent = nullptr); diff --git a/sdk/libraries/core/CamiTKAPI.h b/sdk/libraries/core/CamiTKAPI.h index fbfcc4bf..424b03c6 100644 --- a/sdk/libraries/core/CamiTKAPI.h +++ b/sdk/libraries/core/CamiTKAPI.h @@ -92,6 +92,9 @@ using ComponentList = QList; /// A set of Action using ActionSet = QSet; +/// A set of Viewer +using ViewerSet = QSet; + /// A list of Action using ActionList = QList; diff --git a/sdk/libraries/core/ExtensionManager.cpp b/sdk/libraries/core/ExtensionManager.cpp index 066aa6b3..75a16bd2 100644 --- a/sdk/libraries/core/ExtensionManager.cpp +++ b/sdk/libraries/core/ExtensionManager.cpp @@ -201,14 +201,30 @@ bool ExtensionManager::loadExtension(ExtensionManager::ExtensionType type, QStri if (ext) { ext->setLocation(fileName); ext->initResources(); - - //-- register the filename - getViewerExtensionMap().insert(fileName, ext); - // initialize all actions + // initialize all viewers ext->init(); - //-- register all actions - Application::registerAllViewers(ext); - returnValue = true; + + int i = 0; + while (i < getViewerExtensionMap().size() && getViewerExtensionsList().at(i)->getViewerClassName() != ext->getViewerClassName()) { + i++; + } + + if (returnValue = (i >= getViewerExtensionMap().size())) { + //-- register the filename + getViewerExtensionMap().insert(fileName, ext); + //-- register all viewers + Application::registerAllViewers(ext); + } + else { + CAMITK_INFO_ALT(tr("Extension Manager: duplicate extension management: viewer extension \"%1\" (in file \"%2\") declares management of \"%3\" while \"%4\" extension (loaded from file \"%5\") is already managing \"%6\".\nUsing extension in \"%7\" instead (higher priority) as only one viewer extension can manage an instance of viewer.") + .arg(ext->getName(), + fileName, + ext->getViewerClassName(), + getViewerExtensionsList().at(i)->getName(), + getViewerExtensionsList().at(i)->getLocation(), + ext->getViewerClassName(), + getViewerExtensionsList().at(i)->getLocation())) + } } } break; diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index ec79a67e..e30cc7cd 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -24,6 +24,7 @@ ****************************************************************************/ #include "Action.h" +#include "Viewer.h" #include "ActionExtension.h" //#include "ActionViewer.h" #include "Application.h" @@ -186,9 +187,10 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { //-- if there are some valid targets or if the action is generic if (targetComponents.size() > 0 || getComponent().isEmpty()) { if (isEmbedded) { - // if there are no parents to use use the action viewer + // if there are no parents to use the action viewer if (parent == nullptr) { - //Application::getViewer("ActionViewer")->embedActionWidget(this); + Application::setSelectedAction(this); + Application::getViewer("ActionViewer")->refresh(); } else { getWidget()->setParent(parent); diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index 15d652f0..b29fc691 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -67,6 +67,7 @@ int Application::argc = 0; char** Application::argv = nullptr; QTranslator* Application::translator = nullptr; PropertyObject* Application::propertyObject = nullptr; +Action* Application::currentAction = nullptr; // ----------------- constructor -------------------- Application::Application(QString name, int& theArgc, char** theArgv, bool autoloadExtensions, bool registerFileExtension) : QApplication(theArgc, theArgv) { @@ -751,6 +752,13 @@ bool actionLessThan(const camitk::Action* a1, const camitk::Action* a2) { return a1->getName() < a2->getName(); } +// ---------------- viewerLessThan ---------------- +bool viewerLessThan(const camitk::Viewer* v1, const camitk::Viewer* v2) { + // This method is needed by qsort in the sort method to sort viewer by name + return v1->getName() < v2->getName(); +} + + // ---------------- sort ---------------- ActionList Application::sort(ActionSet actionSet) { // sort actions by name @@ -760,6 +768,16 @@ ActionList Application::sort(ActionSet actionSet) { return actionList; } +ViewerList Application::sort(ViewerSet viewerSet) +{ + // sort actions by name + ViewerList viewerList = viewerSet.toList(); + qSort(viewerList.begin(), viewerList.end(), viewerLessThan); + + return viewerList; +} + + // ---------------- getAction ---------------- Action* Application::getAction(QString name) { return getActionMap().value(name); @@ -833,18 +851,29 @@ QMap& Application::getViewerMap() { return viewerMap; } +Viewer* Application::getViewer(QString name) +{ + return getViewerMap().value(name); +} + // -------------------- registerAllViewers -------------------- int Application::registerAllViewers(ViewerExtension* ext) { int registered = 0; - foreach(Viewer* viewer, ext->getViewers()) { - cout << ext->getName().toStdString() << endl; - cout << viewer->getName().toStdString() << endl; + for(Viewer* viewer : ext->getViewers()) { // check if an action with same name was not already registered if (getViewerMap().contains(viewer->getName())) { + + ViewerExtension* extension = getViewerExtension(viewer); + + QString extensionName = ""; + if (extension != nullptr) { + extensionName = extension->getName(); + } + CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" - "extension of same name already registered") - .arg(viewer->getName(), viewer->getDescription())) + "viewer of same name already registered in extension %3") + .arg(viewer->getName(), viewer->getDescription(), extensionName)) } else { getViewerMap().insert(viewer->getName(), viewer); @@ -855,10 +884,34 @@ int Application::registerAllViewers(ViewerExtension* ext) { return registered; } -Viewer* Application::getViewer(QString name) -{ - return getViewerMap().value(name); -} +ViewerList Application::getViewers(Component *component) +{ + ViewerSet viewers; + + if (component) { + QStringList componentHierarchy = component->getHierarchy(); + + foreach(Viewer* currentViewer, Application::getViewers()) { + foreach(QString compType, currentViewer->getComponents()) { + if (componentHierarchy.contains(compType)) { + viewers.insert(currentViewer); + } + } + } + } + else { + foreach(Viewer* currentViewer, Application::getViewers()) { + foreach(QString compType, currentViewer->getComponents()) { + if (compType.isEmpty()) { + viewers.insert(currentViewer); + } + } + } + } + + return sort(viewers); +} + Viewer* Application::getNewViewer(QString name, QString className) { @@ -896,6 +949,27 @@ int Application::unregisterAllViewers(ViewerExtension* ext) { return unregistered; } +ViewerExtension* Application::getViewerExtension(Viewer* viewer) { + + int i = 0; + bool found = false; + ViewerExtension* extension = nullptr; + while (i < ExtensionManager::getViewerExtensionsList().size() && !found) { + int j = 0; + while (j < ExtensionManager::getViewerExtensionsList().at(i)->getViewers().size() && !found) { + found = (ExtensionManager::getViewerExtensionsList().at(i)->getViewers().at(j)->getName() == viewer->getName()); + j++; + } + i++; + } + + if (found) { + extension = ExtensionManager::getViewerExtensionsList().at(i-1); + } + + return extension; +} + // ---------- isAlive ---------- bool Application::isAlive(Component* comp) { return getAllComponents().contains(comp); @@ -967,6 +1041,16 @@ const ComponentList& Application::getSelectedComponents() { return getSelectedComponentList(); } +void Application::setSelectedAction(Action * action) +{ + currentAction = action; +} + +Action* Application::getSelectedAction() +{ + return currentAction; +} + // -------------------- setSelected -------------------- void Application::setSelected(Component* component, bool isSelected) { // in case the component is selected again, put it in the end diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index 24771c66..a727a641 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -205,7 +205,7 @@ public: */ static const ComponentList& getAllComponents(); - /// does this Component still exists? + /// does this Component still exists? static bool isAlive(Component*); /// Return true if at least one of the opened components has been modified, false otherwise. @@ -227,9 +227,12 @@ public: * all the previously selected components and clear the list. */ static void clearSelectedComponents(); - ///@} + static void setSelectedAction(Action* action); + + static Action* getSelectedAction(); + /// @name Action instances management ///@{ @@ -267,6 +270,9 @@ public: /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); + /// get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) + static ViewerList getViewers(Component*); + /** register all viewers from the given ViewerExtension * @return the number of viewers effectively registered (in case a viewer's name is already registered by another viewer extension, it won't be registered a second time) */ @@ -392,7 +398,7 @@ private: /// argv given from command line static char** argv; - static QMap viewerExtensionMap; + static Action* currentAction; /// @name Recent document management ///@{ @@ -514,6 +520,10 @@ private: /// sort an ActionSet by action's name static ActionList sort(ActionSet); ///@} + + /// sort an ViewerSet by viewer's name + static ViewerList sort(ViewerSet); + ///@} /// @name viewer management ///@{ @@ -531,6 +541,8 @@ private: */ static QMap& getViewerMap(); + static ViewerExtension* getViewerExtension(Viewer* viewer); + ///@} /// @name Property management diff --git a/sdk/libraries/core/component/Component.cpp b/sdk/libraries/core/component/Component.cpp index 44faba92..5b36f3a7 100644 --- a/sdk/libraries/core/component/Component.cpp +++ b/sdk/libraries/core/component/Component.cpp @@ -373,6 +373,15 @@ QMenu* Component::getActionMenu() { } } + ViewerList viewerList = Application::getViewers(this); + if (viewerList.size() > 0) { + QMenu* familyMenu = actionsMenu->addMenu(QString("Viewers")); + foreach(Viewer* viewer, viewerList) { + familyMenu->addAction(viewer->getQAction()); + } + } + + // no menu if no action if (actionsMenu->actions().size() == 0) { delete actionsMenu; diff --git a/sdk/libraries/core/viewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/InteractiveViewer.cpp index 1d3c0312..52920d1e 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/InteractiveViewer.cpp @@ -85,7 +85,7 @@ namespace camitk { std::array InteractiveViewer::defaultNames = { QString("3DViewer"), QString("axialViewer"), QString("coronalViewer"), QString("sagittalViewer"), QString("arbitraryViewer") }; // ---------------------- constructor ---------------------------- -InteractiveViewer::InteractiveViewer(ViewerExtension* extension, QString& name, ViewerType type) : Viewer(extension, name) { +InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(name) { myType = type; diff --git a/sdk/libraries/core/viewer/InteractiveViewer.h b/sdk/libraries/core/viewer/InteractiveViewer.h index a117fe39..dcef8af1 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/InteractiveViewer.h @@ -170,7 +170,12 @@ public: SELECTION_ONLY ///< the selected Components are in default mode, the non-selected are hidden }; - InteractiveViewer(ViewerExtension * extension, QString & name, ViewerType type); + /// @{ + /** Construtor. + * @param name the name of the scene is mandatory, it is used as an identifier (e.g. in MedicalImageViewer) + * @param type type of the InteractiveViewer, depending on which it will behave as slice viewer, i.e. with no rotation interactions are possible, or 3D viewer + */ + InteractiveViewer(QString& name, ViewerType type); /** Destructor */ ~InteractiveViewer() override; @@ -326,15 +331,6 @@ public slots: void toggleCopyright(bool); protected: - /** @name General/Singleton - */ - /// @{ - /** Construtor. - * @param name the name of the scene is mandatory, it is used as an identifier (e.g. in MedicalImageViewer) - * @param type type of the InteractiveViewer, depending on which it will behave as slice viewer, i.e. with no rotation interactions are possible, or 3D viewer - */ - InteractiveViewer(QString& name, ViewerType type); - /// the QString array containing all InteractiveViewer instance default names static std::array defaultNames; diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index d347b341..2c15dc29 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -27,15 +27,18 @@ #include "ViewerExtension.h" #include "Component.h" #include "Application.h" +#include "MainWindow.h" + namespace camitk { //---------------------- constructor ------------------------ -Viewer::Viewer(ViewerExtension* extension, QString name): QObject() { +Viewer::Viewer(QString name): QObject() { this->name = name; - this->extension = extension; setObjectName(name); toolbarVisibility = true; + qAction = nullptr; + components << ""; } //---------------------- selectionChanged ------------------------ @@ -68,9 +71,44 @@ bool Viewer::getToolBarVisibility() { return toolbarVisibility; } -ViewerExtension * Viewer::getExtension() +QAction* Viewer::getQAction() { + if (!qAction) { + // create the corresponding QAction (using the icon, name and descriptions) + qAction = new QAction(getIcon(), getName(), this); + qAction->setStatusTip(getDescription()); + qAction->setWhatsThis(getName() + "\n" + getDescription()); + // connect it to the trigger slot + connect(qAction, SIGNAL(triggered()), this, SLOT(openViewer())); + } + + return qAction; +} + +// -------------------- setIcon -------------------- +void Viewer::setIcon(QPixmap icon) { + this->icon = icon; +} + +// -------------------- getIcon -------------------- +QPixmap Viewer::getIcon() { + return icon; +} + +void Viewer::setComponents(QStringList components) { - return extension; + this->components = components; } +QStringList Viewer::getComponents() +{ + return components; +} + +void Viewer::openViewer() +{ + Application::getMainWindow()->setCentralViewer(Application::getViewer(this->getName())); + refresh(this); +} + + } diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index e2d2a7c7..1fd90625 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -31,10 +31,13 @@ // -- QT stuff #include +#include // -- QT stuff classes class QToolBar; class QMenu; +class QAction; +class QPixMap; namespace camitk { class Component; @@ -59,7 +62,7 @@ class CAMITK_API Viewer : public QObject { public: /// default constructor - Viewer(ViewerExtension*, QString name); + Viewer(QString name); /// default destructor ~Viewer() override = default; @@ -105,18 +108,26 @@ public: /// get the current value of the toolbar visibility bool getToolBarVisibility(); + + QAction* getQAction(); + + virtual QPixmap getIcon(); /// Update the whole tree of the representation of the Component. /// Is actually useful (and defined) in Explorer. virtual void refreshInterfaceNode(Component* comp) {}; - ViewerExtension* getExtension(); + QStringList getComponents(); signals: /// this signal is emitted when the current selection was changed by the viewer void selectionChanged(); +public slots: + + void openViewer(); + protected: /** The selection has changed to the given ComponentList. @@ -131,16 +142,26 @@ protected: /// clear the selection void clearSelection(); + void setIcon(QPixmap icon); + + void setComponents(QStringList); + + private: QString name; QString description; - ViewerExtension* extension; - /// the current toolbar visibility bool toolbarVisibility; + + QAction* qAction; + + /// the Viewer pixmap icon + QPixmap icon; + + QStringList components; }; } diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index c537eacf..3ded3ac7 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -35,6 +35,10 @@ namespace camitk { +ViewerExtension::ViewerExtension() { + viewerClassName = nullptr; +} + // -------------------- initResources -------------------- void ViewerExtension::initResources() { // Get the selected language @@ -78,13 +82,16 @@ ViewerExtension::~ViewerExtension() { // -------------------- registerAction -------------------- void ViewerExtension::registerViewer(Viewer* viewer) { // simply add the viewer in the list + if (viewerClassName == nullptr) { + viewerClassName = viewer->metaObject()->className(); + } viewers.append(viewer); } Viewer* ViewerExtension::getNewInstance(QString name) { - int typeId = QMetaType::type(name.toStdString().c_str()); + int typeId = QMetaType::type(viewerClassName.toStdString().c_str()); const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId); - QObject *o = metaObject->newInstance(); + QObject *o = metaObject->newInstance(Q_ARG(QString, name)); Viewer* viewer = qobject_cast(o); registerViewer(viewer); return viewer; diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index a4e3e371..a8ec3f66 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -12,7 +12,7 @@ namespace camitk { class Viewer; -#define registerNewViewer(X, Y) registerViewer(new X(this, QString(Y))) +#define registerNewViewer(X, Y) registerViewer(new X(QString(Y))) /** * @ingroup group_sdk_libraries_core_action @@ -33,7 +33,7 @@ class CAMITK_API ViewerExtension : public QObject { protected: /// constructor - ViewerExtension() {}; + ViewerExtension(); public: /// destructor diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index 3430b09c..3ea2390c 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -41,7 +41,7 @@ using namespace camitk; // ---------------- constructor ---------------- -ActionViewer::ActionViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +ActionViewer::ActionViewer(QString name) : Viewer(name) { myWidget = nullptr; familyComboBox = nullptr; nameComboBox = nullptr; @@ -54,6 +54,10 @@ ActionViewer::~ActionViewer() { // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer* whoIsAsking) { + if (Application::getSelectedAction() != nullptr) { + action = Application::getSelectedAction(); + embedActionWidget(action); + } updateActionViewer(ViewerRefresh); } diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index dcac6a0c..8ab4eb9c 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -64,7 +64,7 @@ public: */ ///@{ /// constructor - ActionViewer(camitk::ViewerExtension* extension, QString name); + ActionViewer(QString name); /// destructor virtual ~ActionViewer(); diff --git a/sdk/viewers/actionviewer2/ActionViewer.cpp b/sdk/viewers/actionviewer2/ActionViewer.cpp new file mode 100644 index 00000000..3ea2390c --- /dev/null +++ b/sdk/viewers/actionviewer2/ActionViewer.cpp @@ -0,0 +1,342 @@ +/***************************************************************************** + * $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 "ActionViewer.h" + +#include "Application.h" +#include "Component.h" +#include "Action.h" + +#include +#include +#include +#include +#include +#include +// Deprecated. Use Application.h to handle logger interface +//#include "Log.h" + +using namespace camitk; + +// ---------------- constructor ---------------- +ActionViewer::ActionViewer(QString name) : Viewer(name) { + myWidget = nullptr; + familyComboBox = nullptr; + nameComboBox = nullptr; + actionWidgetStack = nullptr; + searchFramePanel = nullptr; +} + +ActionViewer::~ActionViewer() { +} + +// -------------------- refresh -------------------- +void ActionViewer::refresh(Viewer* whoIsAsking) { + if (Application::getSelectedAction() != nullptr) { + action = Application::getSelectedAction(); + embedActionWidget(action); + } + updateActionViewer(ViewerRefresh); +} + +// -------------------- getWidget -------------------- +QWidget* ActionViewer::getWidget(QWidget* parent) { + // lazy instantiation + if (!myWidget) { + // if no parent then put this in a dialog + if (!parent) { + // put it in a dialog, this is the case for default MainWindow, who does not add the ActionViewer in a dock + QDialog* myWidgetIsADialog = new QDialog(nullptr); + myWidgetIsADialog->setWindowTitle(objectName()); + myWidget = myWidgetIsADialog; + } + else { + myWidget = new QWidget(); + } + + auto* actionWidgetLayout = new QVBoxLayout(); + + //-- build the search frame widget + searchFramePanel = new QFrame(); + searchFramePanel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + searchFramePanel->setLineWidth(3); + + auto* searchFrameLayout = new QGridLayout(); + searchFrameLayout->addWidget(new QLabel("Family:"), 0, 0); + familyComboBox = new QComboBox(); + searchFrameLayout->addWidget(familyComboBox, 0, 1); + searchFrameLayout->addWidget(new QLabel("Action:"), 1, 0); + nameComboBox = new QComboBox(); + searchFrameLayout->addWidget(nameComboBox, 1, 1); + searchFrameLayout->addWidget(new QLabel("Tag:"), 2, 0); + tagLineEdit = new QLineEdit(); + searchFrameLayout->addWidget(tagLineEdit, 2, 1); + + // add everything to the research frame + searchFramePanel->setLayout(searchFrameLayout); + actionWidgetLayout->addWidget(searchFramePanel); + // no search panel by default + searchFramePanel->setVisible(false); + + //-- build the stackedWidget to the action widget layout + actionWidgetStack = new QStackedWidget(); + actionWidgetStack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); + actionWidgetStack->setLineWidth(3); + // insert empty widget to fill the space by default + emptyActionWidgetIndex = actionWidgetStack->addWidget(new QWidget()); + // init history insert new index in history for empty selection + ComponentList emptySelection; + widgetHistory.insert(emptySelection, NULL); + actionWidgetLayout->addWidget(actionWidgetStack); + + // set the action widget layout + myWidget->setLayout(actionWidgetLayout); + } + + // limit the width + myWidget->setMaximumWidth(450); + return myWidget; +} + +// -------------------- setSearchPanelVisible -------------------- +void ActionViewer::setSearchPanelVisible(bool visibility) { + if (searchFramePanel) { + searchFramePanel->setVisible(visibility); + + if (visibility) { + // Connect buttons + QObject::connect(familyComboBox, SIGNAL(activated(int)), this, SLOT(changeFamily())); + QObject::connect(nameComboBox, SIGNAL(activated(int)), this, SLOT(changeName())); + QObject::connect(tagLineEdit, SIGNAL(editingFinished()), this, SLOT(changeTag())); + } + else { + // disconnect buttons + QObject::disconnect(familyComboBox, SIGNAL(activated(int)), this, SLOT(changeFamily())); + QObject::disconnect(nameComboBox, SIGNAL(activated(int)), this, SLOT(changeName())); + QObject::disconnect(tagLineEdit, SIGNAL(editingFinished()), this, SLOT(changeTag())); + } + } +} + +// -------------------- changeActionNameComboBox -------------------- +void ActionViewer::changeName() { + action = Application::getAction(nameComboBox->currentText()); + updateActionViewer(ActionNameChanged); +} + +// -------------------- changeTag -------------------- +void ActionViewer::changeTag() { + updateActionViewer(ActionTagChanged); +} + +// -------------------- changeFamilyComboBox -------------------- +void ActionViewer::changeFamily() { + updateActionViewer(ActionFamilyChanged); +} + +// ---------------- componentListLessThan ---------------- +bool operator<(const ComponentList& l1, const ComponentList& l2) { + // This method is needed by the QMap for history + if (l1.size() < l2.size()) { + return true; + } + else { + int i = 0; + + while (i < l1.size() && l1.value(i) == l2.value(i)) { + i++; + } + + if (i == l1.size()) { + return false; + } + else { + return (l1.value(i) < l2.value(i)); + } + } +} + +// -------------------- updateActionViewer -------------------- +void ActionViewer::updateActionViewer(UpdateReason reason) { + familyComboBox->blockSignals(true); + nameComboBox->blockSignals(true); + tagLineEdit->blockSignals(true); + + ActionList possibleActions; + + switch (reason) { + case ActionFamilyChanged: + //-- family was changed, fill the name combo box with this family actions + nameComboBox->clear(); + nameComboBox->addItem("-- Select Action --"); + + if (Application::getSelectedComponents().size() > 0) { + possibleActions = Application::getActions(Application::getSelectedComponents()); + } + else + // no selection => select only empty component actions + { + possibleActions = Application::getActions(nullptr); + } + + foreach (Action* action, possibleActions) { + if (action->getFamily() == familyComboBox->currentText() || familyComboBox->currentText() == QString("-- Select Family --")) { + nameComboBox->addItem(action->getName()); + } + } + nameComboBox->model()->sort(0); + break; + + case ActionNameChanged: + + //-- action name whas changed -> trigger the corresponding action + if (action) { + familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); + action->trigger(); + } + + break; + + case ActionTagChanged: { + //-- tag field was changed, fill the name combo box with the corresponding actions + ActionList actionset = Application::getActions(Application::getSelectedComponents(), tagLineEdit->text()); + + if (!actionset.isEmpty()) { + if (actionset.size() == 1) { + action = *(actionset.begin()); + nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); + updateActionViewer(ActionNameChanged); + } + else { + nameComboBox->clear(); + nameComboBox->addItem("-- Select Action --"); + foreach (Action* action, actionset) { + nameComboBox->addItem(action->getName()); + } + } + + nameComboBox->model()->sort(0); + } + } + break; + + case ViewerRefresh: + default: { + + //-- selection was changed, update combo boxes and tag list, and then check history + // copy selected component list (so that references are not used for comparison) + ComponentList selected(Application::getSelectedComponents()); + // if selection did not change between two updates, no need to refresh the widget + if (currentlySelected != selected) { + currentlySelected = selected; + //-- update the search panel + familyComboBox->clear(); + nameComboBox->clear(); + QStringList wordList; + familyComboBox->addItem("-- Select Family --"); + nameComboBox->addItem("-- Select Action --"); + if (selected.size() > 0) { + possibleActions = Application::getActions(selected.last()); + } + else { // no selection => select only empty component actions + possibleActions = Application::getActions(nullptr); + } // Complete family and action lists depending of the last selected component + foreach (Action* action, possibleActions) { + if (familyComboBox->findText(action->getFamily()) == -1) { + familyComboBox->addItem(action->getFamily()); + } + if (nameComboBox->findText(action->getName()) == -1) { + nameComboBox->addItem(action->getName()); + } + foreach (QString tag, action->getTag()) { + if (!wordList.contains(tag)) { + wordList.append(tag); + } + } + } + nameComboBox->model()->sort(0); + familyComboBox->model()->sort(0); + auto* completer = new QCompleter(wordList, myWidget); + completer->setCaseSensitivity(Qt::CaseInsensitive); + tagLineEdit->setCompleter(completer); + + //-- check history + // check if the same list of Component* was already used + QMap::const_iterator it = widgetHistory.find(selected); + if (it != widgetHistory.end()) { + // show the previously used widget + if (it.value() == NULL) { + actionWidgetStack->setCurrentIndex(emptyActionWidgetIndex); + } + else { // update search panel + familyComboBox->setCurrentIndex(familyComboBox->findText(it.value()->getFamily())); + nameComboBox->setCurrentIndex(nameComboBox->findText(it.value()->getName())); + it.value()->trigger(); + } + } + else { + // insert new index in history (NULL action, with empty widget) + widgetHistory.insert(selected, NULL); + actionWidgetStack->setCurrentIndex(emptyActionWidgetIndex); + } + } + } + } + + familyComboBox->blockSignals(false); + nameComboBox->blockSignals(false); + tagLineEdit->blockSignals(false); +} + +// -------------------- embedActionWidget -------------------- +void ActionViewer::embedActionWidget(Action* action) { + // make sure the action viewer is visible (even if in a dockwidget) + if (getWidget()->parentWidget()) { + getWidget()->parentWidget()->setVisible(true); + getWidget()->setVisible(true); + } + + //-- check history + QWidget* actionWidget = action->getWidget(); + int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); + + if (actionWidgetIndex == -1 && actionWidget) { + // add the widget (beware that actionWidgetStack then takes ownership of the widget!) + actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); + } + + // insert new index in history + ComponentList selected(Application::getSelectedComponents()); + widgetHistory.insert(selected, action); + actionWidgetStack->setCurrentIndex(actionWidgetIndex); + actionWidgetStack->update(); + // ignore size policy of widget so that it can be resized + actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + + // update search panel + familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); + updateActionViewer(ActionFamilyChanged); // to have only the actions of the same family + nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); +} diff --git a/sdk/viewers/actionviewer2/ActionViewer.h b/sdk/viewers/actionviewer2/ActionViewer.h new file mode 100644 index 00000000..8d96d3cf --- /dev/null +++ b/sdk/viewers/actionviewer2/ActionViewer.h @@ -0,0 +1,142 @@ +/***************************************************************************** + * $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 ACTIONVIEWER_H +#define ACTIONVIEWER_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * @ingroup group_sdk_libraries_core_viewer + * + * @brief + * ActionViewer is the viewer used to manage the actions. + * + * By default all action widgets are displayed in this viewer widget (in the stackedWidget). + * There is also a search panel to find an action to apply to the currently selected component. + * The search panel is not not shown by default. Use setSearchPanelVisible(true) to show it. + * + * This viewer also manages a singleton (THE CamiTK action viewer). See getInstance() for more information. + * You do not have to use it, but it is convienent (and sometimes preferable) to use this instance + * instead of creating your own one. + */ +class ActionViewer : public camitk::Viewer { + Q_OBJECT + +public: + /** @name General + */ + ///@{ + /// constructor + ActionViewer(QString name); + + /// destructor + virtual ~ActionViewer(); + + /// @name Inherited from Viewer + //@{ + /// returns the number of Component that are displayed by this viewer + unsigned int numberOfViewedComponent() { + return 0; + }; + + /// refresh the view (can be interesting to know which other viewer is calling this) + virtual void refresh(Viewer* whoIsAsking = nullptr); + + /// get the viewer widget. @param parent the parent widget for the viewer widget + virtual QWidget* getWidget(QWidget* parent = nullptr); + //@} + + /// @name Specific to the Action viewer + //@{ + /// embed an action widget in the stacked widget + virtual void embedActionWidget(camitk::Action*); + + /// show/hide the search panel (hidden by default) + virtual void setSearchPanelVisible(bool); + //@} + +protected slots : + /// Method used to change the action selected + void changeName(); + + /// Method used to change the action family selected + void changeFamily(); + + /// Method used to change the tag + void changeTag(); + +private: + /// Enum the different fields of the action viewwer + enum UpdateReason {ActionFamilyChanged, ActionNameChanged, ActionTagChanged, ViewerRefresh}; + + /// method used to update the viewer for a given update field + void updateActionViewer(UpdateReason); + + /// Main action widget of the viewer + QWidget* myWidget; + + /// Family combo box + QComboBox* familyComboBox; + + /// Action name combo box + QComboBox* nameComboBox; + + /// Current action + camitk::Action* action; + + /// action tags line edit + QLineEdit* tagLineEdit; + + /// actions stacked widget of the viewer + QStackedWidget* actionWidgetStack; + + /// the search panel + QFrame* searchFramePanel; + + /// index of the empty widget, used when no action is active or when no action has been used for the currently selected components + int emptyActionWidgetIndex; + + /// this map stores the list of selected component and the corresponding stack index of their embedded action + QMap widgetHistory; + + /// Used to evaluate modification of the list while execution + camitk::ComponentList currentlySelected; +}; + + +#endif // ACTIONVIEWER_H diff --git a/sdk/viewers/actionviewer2/ActionViewer2Extension.cpp b/sdk/viewers/actionviewer2/ActionViewer2Extension.cpp new file mode 100644 index 00000000..78bf547b --- /dev/null +++ b/sdk/viewers/actionviewer2/ActionViewer2Extension.cpp @@ -0,0 +1,35 @@ +/***************************************************************************** + * $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 "ActionViewer2Extension.h" + +// include generated actions headers +#include "ActionViewer.h" + +// --------------- getViewers ------------------- +void ActionViewer2Extension::init() { +} + diff --git a/sdk/viewers/actionviewer2/ActionViewer2Extension.h b/sdk/viewers/actionviewer2/ActionViewer2Extension.h new file mode 100644 index 00000000..661cf057 --- /dev/null +++ b/sdk/viewers/actionviewer2/ActionViewer2Extension.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 ACTIONVIEWER2EXTENSION_H +#define ACTIONVIEWER2EXTENSION_H + + +#include "ViewerExtension.h" + +class ActionViewer2Extension : public camitk::ViewerExtension { + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionviewer2extension.viewer.actionviewer2extension") + +public: + /// Constructor + ActionViewer2Extension() : ViewerExtension() {}; + + /// Destructor + virtual ~ActionViewer2Extension() = default; + + /// Method returning the action extension name + virtual QString getName() { + return "Action Viewer 2 Extension"; + }; + + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the viewer that display GUI action"; + }; + + /// initialize all the actions + virtual void init(); + +}; + +#endif // ACTIONVIEWEREXTENSION_H + + diff --git a/sdk/viewers/actionviewer2/CMakeLists.txt b/sdk/viewers/actionviewer2/CMakeLists.txt new file mode 100644 index 00000000..e3b83fcb --- /dev/null +++ b/sdk/viewers/actionviewer2/CMakeLists.txt @@ -0,0 +1,8 @@ +# Call CamiTK CMake Macro to define the action +camitk_extension(VIEWER_EXTENSION + CEP_NAME SDK + DEFINES COMPILE_ACTIONVIEWER_API + DESCRIPTION "An extension for the viewer that display GUI action" + INSTALL_ALL_HEADERS +) + diff --git a/sdk/viewers/explorer/Explorer.cpp b/sdk/viewers/explorer/Explorer.cpp index 4a90701c..08d591c6 100644 --- a/sdk/viewers/explorer/Explorer.cpp +++ b/sdk/viewers/explorer/Explorer.cpp @@ -43,7 +43,7 @@ using namespace camitk; //----------------------- constructor ------------------------ -Explorer::Explorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +Explorer::Explorer(QString name) : Viewer(name) { explorerTree = nullptr; explorerMenu = nullptr; } diff --git a/sdk/viewers/explorer/Explorer.h b/sdk/viewers/explorer/Explorer.h index 101e35db..2778d309 100644 --- a/sdk/viewers/explorer/Explorer.h +++ b/sdk/viewers/explorer/Explorer.h @@ -66,7 +66,7 @@ public: */ ///@{ /** Construtor */ - Explorer(camitk::ViewerExtension*, QString); + Explorer(QString); /** Destructor */ ~Explorer() override; diff --git a/sdk/viewers/frameexplorer/FrameExplorer.cpp b/sdk/viewers/frameexplorer/FrameExplorer.cpp index 7d88bb7a..92979d59 100644 --- a/sdk/viewers/frameexplorer/FrameExplorer.cpp +++ b/sdk/viewers/frameexplorer/FrameExplorer.cpp @@ -34,7 +34,7 @@ using namespace camitk; //----------------------- constructor ------------------------ -FrameExplorer::FrameExplorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +FrameExplorer::FrameExplorer(QString name) : Viewer( name) { explorerTree = nullptr; } diff --git a/sdk/viewers/frameexplorer/FrameExplorer.h b/sdk/viewers/frameexplorer/FrameExplorer.h index 68100a85..d813eae8 100644 --- a/sdk/viewers/frameexplorer/FrameExplorer.h +++ b/sdk/viewers/frameexplorer/FrameExplorer.h @@ -64,7 +64,7 @@ public: */ ///@{ /** Construtor */ - FrameExplorer(camitk::ViewerExtension*, QString); + FrameExplorer(QString); /** Destructor */ ~FrameExplorer() override = default; diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp index e3bae5fa..c23b59a6 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp @@ -24,14 +24,15 @@ ****************************************************************************/ // -- Core stuff +#include #include "InteractiveGeometryViewer.h" #include using namespace camitk; // -------------------- Constructor -------------------- -InteractiveGeometryViewer::InteractiveGeometryViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::GEOMETRY_VIEWER) -{ +InteractiveGeometryViewer::InteractiveGeometryViewer(QString name) : InteractiveViewer(name, InteractiveViewer::GEOMETRY_VIEWER) +{ } diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h index e3cb29ed..4dedc1b5 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h @@ -33,10 +33,8 @@ #include "InteractiveViewer.h" // -- QT stuff -#include -#include -#include -#include +#include +#include /** * @ingroup group_sdk_libraries_core_viewer @@ -59,13 +57,12 @@ class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewer : public camitk::I public: - InteractiveGeometryViewer(camitk::ViewerExtension*, QString); + Q_INVOKABLE InteractiveGeometryViewer(QString name); /** destructor */ ~InteractiveGeometryViewer() override; }; - #endif diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp index 56355cd7..d2c0bd8d 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp @@ -29,8 +29,9 @@ // include generated actions headers #include "InteractiveGeometryViewer.h" -// --------------- getViewers ------------------- + // --------------- getViewers ------------------- void InteractiveGeometryViewerExtension::init() { + qRegisterMetaType("InteractiveGeometryViewer"); registerNewViewer(InteractiveGeometryViewer, "3DViewer"); } diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h index c926295e..73ea030d 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h @@ -38,7 +38,7 @@ class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewerExtension : public public: /// Constructor - InteractiveGeometryViewerExtension() : ViewerExtension() {}; + InteractiveGeometryViewerExtension() : camitk::ViewerExtension() {}; /// Destructor virtual ~InteractiveGeometryViewerExtension() = default; diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp index e93e700e..9751f4d6 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp @@ -30,7 +30,7 @@ using namespace camitk; // -------------------- Constructor -------------------- -InteractiveSliceViewer::InteractiveSliceViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::SLICE_VIEWER) +InteractiveSliceViewer::InteractiveSliceViewer(QString name) : InteractiveViewer(name, InteractiveViewer::SLICE_VIEWER) { } diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h index c2b57731..447c6a8a 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h @@ -59,7 +59,7 @@ class INTERACTIVESLICEVIEWER_API InteractiveSliceViewer : public camitk::Interac public: - InteractiveSliceViewer(camitk::ViewerExtension*, QString); + InteractiveSliceViewer(QString); /** destructor */ ~InteractiveSliceViewer() override; diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp index a45319de..ed2d0274 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp @@ -39,7 +39,7 @@ using namespace camitk; // -------------------- Constructor -------------------- -MedicalImageViewer::MedicalImageViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +MedicalImageViewer::MedicalImageViewer(QString name) : Viewer(name) { // init view members frame = nullptr; frameLayout = nullptr; @@ -51,14 +51,13 @@ MedicalImageViewer::MedicalImageViewer(ViewerExtension* extension, QString name) displayedTopLevelComponents = 0; autoUpdateToolbarVisibility = true; + + setComponents(QStringList() << "ImageComponent"); } // -------------------- Destructor -------------------- MedicalImageViewer::~MedicalImageViewer() { - if (frame) { - delete frame; - } } diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h index d00b0f66..a6075bee 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h @@ -68,7 +68,7 @@ public: VIEWER_ARBITRARY ///< Only the arbitrary InteractiveViewer are visible }; - MedicalImageViewer(camitk::ViewerExtension*, QString); + MedicalImageViewer(QString); /** destructor */ ~MedicalImageViewer() override; diff --git a/sdk/viewers/propertyexplorer/PropertyExplorer.cpp b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp index 502671f1..e3508b3a 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorer.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp @@ -38,7 +38,7 @@ using namespace camitk; // ---------------- constructor ---------------- -PropertyExplorer::PropertyExplorer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +PropertyExplorer::PropertyExplorer(QString name) : Viewer(name) { theController = nullptr; tabWidget = nullptr; revertButton = nullptr; @@ -51,12 +51,12 @@ PropertyExplorer::PropertyExplorer(ViewerExtension* extension, QString name) : V // ---------------- destructor ---------------- PropertyExplorer::~PropertyExplorer() { clear(); - if (propertyObject) { + /*if (propertyObject != nullptr) { delete propertyObject; } - if (viewModeProperty) { + if (viewModeProperty != nullptr) { delete viewModeProperty; - } + }*/ } // ---------------- numberOfViewedComponent ---------------- diff --git a/sdk/viewers/propertyexplorer/PropertyExplorer.h b/sdk/viewers/propertyexplorer/PropertyExplorer.h index 0daef108..a8383202 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorer.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.h @@ -91,7 +91,7 @@ public: */ ///@{ /// constructor - PropertyExplorer(camitk::ViewerExtension * extension, QString name); + PropertyExplorer(QString name); /// destructor ~PropertyExplorer() override; -- GitLab From 021865812375759b1f975204111f70bf92980964 Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Thu, 30 Jan 2020 17:38:40 +0100 Subject: [PATCH 13/26] FIXED linux compilation --- .../ActionStateViewerExtension.cpp | 2 +- sdk/libraries/core/viewer/Viewer.h | 26 +++++++++---------- .../InteractiveSliceViewerAPI.h | 12 ++++----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp b/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp index 41e03ff1..07cfd243 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getActions ------------------- void ActionStateViewerExtension::init() { - registerNewViewer(ActionStateViewer); + registerNewViewer(ActionStateViewer, "ActionStateViewer"); } diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index 1fd90625..f6d06a42 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -31,12 +31,12 @@ // -- QT stuff #include -#include +#include // -- QT stuff classes class QToolBar; class QMenu; -class QAction; +class QAction; class QPixMap; namespace camitk { @@ -109,8 +109,8 @@ public: /// get the current value of the toolbar visibility bool getToolBarVisibility(); - QAction* getQAction(); - + QAction* getQAction(); + virtual QPixmap getIcon(); /// Update the whole tree of the representation of the Component. @@ -124,7 +124,7 @@ signals: /// this signal is emitted when the current selection was changed by the viewer void selectionChanged(); -public slots: +public slots: void openViewer(); @@ -142,9 +142,9 @@ protected: /// clear the selection void clearSelection(); - void setIcon(QPixmap icon); - - void setComponents(QStringList); + void setIcon(QPixmap icon); + + void setComponents(QStringList); private: @@ -156,11 +156,11 @@ private: /// the current toolbar visibility bool toolbarVisibility; - QAction* qAction; - - /// the Viewer pixmap icon - QPixmap icon; - + QAction* qAction; + + /// the Viewer pixmap icon + QPixmap icon; + QStringList components; }; diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h index 56b4b9e2..55ac68ab 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerAPI.h @@ -26,10 +26,10 @@ // ----- MEDICALIMAGEVIEWER_API_H.h #ifndef INTERACTIVESLICEVIEWER_API_H #define INTERACTIVESLICEVIEWER_API_H - + // ----------------------------------------------------------------------- // -// MEDICALIMAGEVIEWER_API +// INTERACTIVESLICEVIEWER_API_API // // ----------------------------------------------------------------------- @@ -50,10 +50,10 @@ #else // for all other platforms INTERACTIVESLICEVIEWER_API is defined to be "nothing" -#ifndef InteractiveSliceViewer_API -#define InteractiveSliceViewer_API -#endif // InteractiveSliceViewer_API +#ifndef INTERACTIVESLICEVIEWER_API +#define INTERACTIVESLICEVIEWER_API +#endif // INTERACTIVESLICEVIEWER_API #endif // MSVC and mingw -#endif // INTERACTIVESLICEVIEWER_API_H \ No newline at end of file +#endif // INTERACTIVESLICEVIEWER_API_H -- GitLab From 98418304502f484d13b3b4aba85bdb4db602f681 Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Thu, 30 Jan 2020 17:39:18 +0100 Subject: [PATCH 14/26] FIXED tentative to update action viewer when appropriate --- sdk/libraries/core/action/Action.cpp | 2 +- sdk/viewers/actionviewer/ActionViewer.cpp | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index e30cc7cd..20dca4e4 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -187,7 +187,7 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { //-- if there are some valid targets or if the action is generic if (targetComponents.size() > 0 || getComponent().isEmpty()) { if (isEmbedded) { - // if there are no parents to use the action viewer + // if there are no parents, use the action viewer if (parent == nullptr) { Application::setSelectedAction(this); Application::getViewer("ActionViewer")->refresh(); diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index 3ea2390c..7657525e 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -54,9 +54,12 @@ ActionViewer::~ActionViewer() { // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer* whoIsAsking) { - if (Application::getSelectedAction() != nullptr) { - action = Application::getSelectedAction(); - embedActionWidget(action); + // no need to update if there is no selected action or there is no selected component + if (Application::getSelectedAction() != nullptr && Application::getSelectedComponents().size() > 0) { + if (action != Application::getSelectedAction()) { + action = Application::getSelectedAction(); + embedActionWidget(action); + } } updateActionViewer(ViewerRefresh); } -- GitLab From 42e38c24becdfa6df4d4049c42a8ed6e4918e840 Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Fri, 31 Jan 2020 14:21:43 +0100 Subject: [PATCH 15/26] Update ActionViewer --- sdk/viewers/actionviewer/ActionViewer.cpp | 77 ++++++++++++----------- sdk/viewers/actionviewer/ActionViewer.h | 1 + 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index 7657525e..6cae2bde 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -54,14 +54,9 @@ ActionViewer::~ActionViewer() { // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer* whoIsAsking) { - // no need to update if there is no selected action or there is no selected component - if (Application::getSelectedAction() != nullptr && Application::getSelectedComponents().size() > 0) { - if (action != Application::getSelectedAction()) { - action = Application::getSelectedAction(); - embedActionWidget(action); - } - } - updateActionViewer(ViewerRefresh); + // no need to update if there is no selected action or there is no selected component + embedActionWidget(Application::getSelectedAction()); + updateActionViewer(ViewerRefresh); } // -------------------- getWidget -------------------- @@ -217,7 +212,8 @@ void ActionViewer::updateActionViewer(UpdateReason reason) { //-- action name whas changed -> trigger the corresponding action if (action) { familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - action->trigger(); + lastSelected = ComponentList(); + action->trigger(); } break; @@ -296,7 +292,7 @@ void ActionViewer::updateActionViewer(UpdateReason reason) { else { // update search panel familyComboBox->setCurrentIndex(familyComboBox->findText(it.value()->getFamily())); nameComboBox->setCurrentIndex(nameComboBox->findText(it.value()->getName())); - it.value()->trigger(); + it.value()->trigger(); } } else { @@ -315,31 +311,38 @@ void ActionViewer::updateActionViewer(UpdateReason reason) { // -------------------- embedActionWidget -------------------- void ActionViewer::embedActionWidget(Action* action) { - // make sure the action viewer is visible (even if in a dockwidget) - if (getWidget()->parentWidget()) { - getWidget()->parentWidget()->setVisible(true); - getWidget()->setVisible(true); - } - - //-- check history - QWidget* actionWidget = action->getWidget(); - int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); - - if (actionWidgetIndex == -1 && actionWidget) { - // add the widget (beware that actionWidgetStack then takes ownership of the widget!) - actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); - } - - // insert new index in history - ComponentList selected(Application::getSelectedComponents()); - widgetHistory.insert(selected, action); - actionWidgetStack->setCurrentIndex(actionWidgetIndex); - actionWidgetStack->update(); - // ignore size policy of widget so that it can be resized - actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); - - // update search panel - familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - updateActionViewer(ActionFamilyChanged); // to have only the actions of the same family - nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); + if (action != nullptr && currentlySelected.size() > 0) { + if (this->action != action || lastSelected.isEmpty() || lastSelected != currentlySelected) { + this->action = Application::getSelectedAction(); + this->lastSelected = Application::getSelectedComponents(); + // make sure the action viewer is visible (even if in a dockwidget) + if (getWidget()->parentWidget()) { + getWidget()->parentWidget()->setVisible(true); + getWidget()->setVisible(true); + } + + //-- check history + QWidget* actionWidget = action->getWidget(); + int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); + + if (actionWidgetIndex == -1 && actionWidget) { + // add the widget (beware that actionWidgetStack then takes ownership of the widget!) + actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); + } + + // insert new index in history + ComponentList selected(Application::getSelectedComponents()); + widgetHistory.insert(selected, action); + actionWidgetStack->setCurrentIndex(actionWidgetIndex); + actionWidgetStack->update(); + // ignore size policy of widget so that it can be resized + actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + + + // update search panel + familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); + updateActionViewer(ActionFamilyChanged); // to have only the actions of the same family + nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); + } + } } diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index 8ab4eb9c..fd41d853 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -138,6 +138,7 @@ private: /// Used to evaluate modification of the list while execution camitk::ComponentList currentlySelected; + camitk::ComponentList lastSelected; }; -- GitLab From c348d6588566746cfe0ed056830d4e13f4dca19a Mon Sep 17 00:00:00 2001 From: CALKA Maxime Date: Fri, 31 Jan 2020 15:44:36 +0100 Subject: [PATCH 16/26] Update Tutorials, PML, MML --- .../components/pmlcomponent/PMLComponent.cpp | 4 +- sdk/libraries/core/viewer/Viewer.cpp | 1 + sdk/viewers/actionviewer/ActionViewer.cpp | 18 +- sdk/viewers/actionviewer/ActionViewer.h | 12 +- sdk/viewers/actionviewer2/ActionViewer.cpp | 342 ------------------ sdk/viewers/actionviewer2/ActionViewer.h | 142 -------- .../actionviewer2/ActionViewer2Extension.cpp | 35 -- .../actionviewer2/ActionViewer2Extension.h | 62 ---- sdk/viewers/actionviewer2/CMakeLists.txt | 8 - tutorials/actions/basicpicking/CMakeLists.txt | 1 - tutorials/actions/bitmapviewer/CMakeLists.txt | 2 +- .../shakerextension/CMakeLists.txt | 1 - .../actions/meshpointdata/CMakeLists.txt | 1 - .../sleepingwhileworking/CMakeLists.txt | 2 +- tutorials/actions/vtkwidget/CMakeLists.txt | 2 +- tutorials/applications/basic/CMakeLists.txt | 4 +- tutorials/applications/fancy/CMakeLists.txt | 2 +- .../applications/fancy/FancyMainWindow.h | 4 +- tutorials/applications/menubar/CMakeLists.txt | 4 +- .../applications/menubar/MyAppMainWindow.cpp | 1 - tutorials/applications/simple/CMakeLists.txt | 4 +- .../applications/simple/SimpleMainWindow.cpp | 1 - tutorials/viewers/bitmap/BitmapViewer.cpp | 6 +- tutorials/viewers/bitmap/BitmapViewer.h | 4 +- tutorials/viewers/bitmap/CMakeLists.txt | 1 - tutorials/viewers/textviewer/CMakeLists.txt | 1 - tutorials/viewers/textviewer/TextViewer.cpp | 25 +- tutorials/viewers/textviewer/TextViewer.h | 4 +- 28 files changed, 35 insertions(+), 659 deletions(-) delete mode 100644 sdk/viewers/actionviewer2/ActionViewer.cpp delete mode 100644 sdk/viewers/actionviewer2/ActionViewer.h delete mode 100644 sdk/viewers/actionviewer2/ActionViewer2Extension.cpp delete mode 100644 sdk/viewers/actionviewer2/ActionViewer2Extension.h delete mode 100644 sdk/viewers/actionviewer2/CMakeLists.txt diff --git a/modeling/components/pmlcomponent/PMLComponent.cpp b/modeling/components/pmlcomponent/PMLComponent.cpp index a0b9536b..eb611743 100644 --- a/modeling/components/pmlcomponent/PMLComponent.cpp +++ b/modeling/components/pmlcomponent/PMLComponent.cpp @@ -224,7 +224,7 @@ void PMLComponent::create3DStructure() { initRepresentation(mainGrid); // Tell this component is visible in the 3D viewer, otherwise we won't see it! - setVisibility(InteractiveViewer::get3DViewer(), true); + setVisibility(Application::getViewer("3DViewer"), true); } //-------------------- parseMultiComponent ------------------- @@ -343,7 +343,7 @@ void PMLComponent::refreshDisplay() { // for instance in a MML monitor) in order to obtain a real refresh getPointSet()->Modified(); // This is a forced/active refresh (breaking CamiTK programming guidelines) - InteractiveViewer::get3DViewer()->refresh(); + Application::getViewer("3DViewer")->refresh(); // shade the current selected component in order to see the selected item (SC, MC, Atoms or Cells) myGeometry->setEnhancedModes(InterfaceGeometry::Shaded); } diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index 2c15dc29..a3c2ffbc 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -78,6 +78,7 @@ QAction* Viewer::getQAction() { qAction->setStatusTip(getDescription()); qAction->setWhatsThis(getName() + "\n" + getDescription()); // connect it to the trigger slot + connect(qAction, SIGNAL(triggered()), this, SLOT(openViewer())); } diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index 6cae2bde..f1c9ebe3 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -55,8 +55,8 @@ ActionViewer::~ActionViewer() { // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer* whoIsAsking) { // no need to update if there is no selected action or there is no selected component - embedActionWidget(Application::getSelectedAction()); - updateActionViewer(ViewerRefresh); + updateActionWidget(Application::getSelectedAction()); + updateSearchPanel(ViewerRefresh); } // -------------------- getWidget -------------------- @@ -141,17 +141,17 @@ void ActionViewer::setSearchPanelVisible(bool visibility) { // -------------------- changeActionNameComboBox -------------------- void ActionViewer::changeName() { action = Application::getAction(nameComboBox->currentText()); - updateActionViewer(ActionNameChanged); + updateSearchPanel(ActionNameChanged); } // -------------------- changeTag -------------------- void ActionViewer::changeTag() { - updateActionViewer(ActionTagChanged); + updateSearchPanel(ActionTagChanged); } // -------------------- changeFamilyComboBox -------------------- void ActionViewer::changeFamily() { - updateActionViewer(ActionFamilyChanged); + updateSearchPanel(ActionFamilyChanged); } // ---------------- componentListLessThan ---------------- @@ -177,7 +177,7 @@ bool operator<(const ComponentList& l1, const ComponentList& l2) { } // -------------------- updateActionViewer -------------------- -void ActionViewer::updateActionViewer(UpdateReason reason) { +void ActionViewer::updateSearchPanel(UpdateReason reason) { familyComboBox->blockSignals(true); nameComboBox->blockSignals(true); tagLineEdit->blockSignals(true); @@ -226,7 +226,7 @@ void ActionViewer::updateActionViewer(UpdateReason reason) { if (actionset.size() == 1) { action = *(actionset.begin()); nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); - updateActionViewer(ActionNameChanged); + updateSearchPanel(ActionNameChanged); } else { nameComboBox->clear(); @@ -310,7 +310,7 @@ void ActionViewer::updateActionViewer(UpdateReason reason) { } // -------------------- embedActionWidget -------------------- -void ActionViewer::embedActionWidget(Action* action) { +void ActionViewer::updateActionWidget(Action* action) { if (action != nullptr && currentlySelected.size() > 0) { if (this->action != action || lastSelected.isEmpty() || lastSelected != currentlySelected) { this->action = Application::getSelectedAction(); @@ -341,7 +341,7 @@ void ActionViewer::embedActionWidget(Action* action) { // update search panel familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - updateActionViewer(ActionFamilyChanged); // to have only the actions of the same family + updateSearchPanel(ActionFamilyChanged); // to have only the actions of the same family nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); } } diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index fd41d853..d5d7be77 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -83,11 +83,6 @@ public: virtual QWidget* getWidget(QWidget* parent = nullptr); //@} - /// @name Specific to the Action viewer - //@{ - /// embed an action widget in the stacked widget - virtual void embedActionWidget(camitk::Action*); - /// show/hide the search panel (hidden by default) virtual void setSearchPanelVisible(bool); //@} @@ -106,8 +101,13 @@ private: /// Enum the different fields of the action viewwer enum UpdateReason {ActionFamilyChanged, ActionNameChanged, ActionTagChanged, ViewerRefresh}; + /// @name Specific to the Action viewer + //@{ + /// embed an action widget in the stacked widget + virtual void updateActionWidget(camitk::Action*); + /// method used to update the viewer for a given update field - void updateActionViewer(UpdateReason); + void updateSearchPanel(UpdateReason); /// Main action widget of the viewer QWidget* myWidget; diff --git a/sdk/viewers/actionviewer2/ActionViewer.cpp b/sdk/viewers/actionviewer2/ActionViewer.cpp deleted file mode 100644 index 3ea2390c..00000000 --- a/sdk/viewers/actionviewer2/ActionViewer.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/***************************************************************************** - * $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 "ActionViewer.h" - -#include "Application.h" -#include "Component.h" -#include "Action.h" - -#include -#include -#include -#include -#include -#include -// Deprecated. Use Application.h to handle logger interface -//#include "Log.h" - -using namespace camitk; - -// ---------------- constructor ---------------- -ActionViewer::ActionViewer(QString name) : Viewer(name) { - myWidget = nullptr; - familyComboBox = nullptr; - nameComboBox = nullptr; - actionWidgetStack = nullptr; - searchFramePanel = nullptr; -} - -ActionViewer::~ActionViewer() { -} - -// -------------------- refresh -------------------- -void ActionViewer::refresh(Viewer* whoIsAsking) { - if (Application::getSelectedAction() != nullptr) { - action = Application::getSelectedAction(); - embedActionWidget(action); - } - updateActionViewer(ViewerRefresh); -} - -// -------------------- getWidget -------------------- -QWidget* ActionViewer::getWidget(QWidget* parent) { - // lazy instantiation - if (!myWidget) { - // if no parent then put this in a dialog - if (!parent) { - // put it in a dialog, this is the case for default MainWindow, who does not add the ActionViewer in a dock - QDialog* myWidgetIsADialog = new QDialog(nullptr); - myWidgetIsADialog->setWindowTitle(objectName()); - myWidget = myWidgetIsADialog; - } - else { - myWidget = new QWidget(); - } - - auto* actionWidgetLayout = new QVBoxLayout(); - - //-- build the search frame widget - searchFramePanel = new QFrame(); - searchFramePanel->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); - searchFramePanel->setLineWidth(3); - - auto* searchFrameLayout = new QGridLayout(); - searchFrameLayout->addWidget(new QLabel("Family:"), 0, 0); - familyComboBox = new QComboBox(); - searchFrameLayout->addWidget(familyComboBox, 0, 1); - searchFrameLayout->addWidget(new QLabel("Action:"), 1, 0); - nameComboBox = new QComboBox(); - searchFrameLayout->addWidget(nameComboBox, 1, 1); - searchFrameLayout->addWidget(new QLabel("Tag:"), 2, 0); - tagLineEdit = new QLineEdit(); - searchFrameLayout->addWidget(tagLineEdit, 2, 1); - - // add everything to the research frame - searchFramePanel->setLayout(searchFrameLayout); - actionWidgetLayout->addWidget(searchFramePanel); - // no search panel by default - searchFramePanel->setVisible(false); - - //-- build the stackedWidget to the action widget layout - actionWidgetStack = new QStackedWidget(); - actionWidgetStack->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken); - actionWidgetStack->setLineWidth(3); - // insert empty widget to fill the space by default - emptyActionWidgetIndex = actionWidgetStack->addWidget(new QWidget()); - // init history insert new index in history for empty selection - ComponentList emptySelection; - widgetHistory.insert(emptySelection, NULL); - actionWidgetLayout->addWidget(actionWidgetStack); - - // set the action widget layout - myWidget->setLayout(actionWidgetLayout); - } - - // limit the width - myWidget->setMaximumWidth(450); - return myWidget; -} - -// -------------------- setSearchPanelVisible -------------------- -void ActionViewer::setSearchPanelVisible(bool visibility) { - if (searchFramePanel) { - searchFramePanel->setVisible(visibility); - - if (visibility) { - // Connect buttons - QObject::connect(familyComboBox, SIGNAL(activated(int)), this, SLOT(changeFamily())); - QObject::connect(nameComboBox, SIGNAL(activated(int)), this, SLOT(changeName())); - QObject::connect(tagLineEdit, SIGNAL(editingFinished()), this, SLOT(changeTag())); - } - else { - // disconnect buttons - QObject::disconnect(familyComboBox, SIGNAL(activated(int)), this, SLOT(changeFamily())); - QObject::disconnect(nameComboBox, SIGNAL(activated(int)), this, SLOT(changeName())); - QObject::disconnect(tagLineEdit, SIGNAL(editingFinished()), this, SLOT(changeTag())); - } - } -} - -// -------------------- changeActionNameComboBox -------------------- -void ActionViewer::changeName() { - action = Application::getAction(nameComboBox->currentText()); - updateActionViewer(ActionNameChanged); -} - -// -------------------- changeTag -------------------- -void ActionViewer::changeTag() { - updateActionViewer(ActionTagChanged); -} - -// -------------------- changeFamilyComboBox -------------------- -void ActionViewer::changeFamily() { - updateActionViewer(ActionFamilyChanged); -} - -// ---------------- componentListLessThan ---------------- -bool operator<(const ComponentList& l1, const ComponentList& l2) { - // This method is needed by the QMap for history - if (l1.size() < l2.size()) { - return true; - } - else { - int i = 0; - - while (i < l1.size() && l1.value(i) == l2.value(i)) { - i++; - } - - if (i == l1.size()) { - return false; - } - else { - return (l1.value(i) < l2.value(i)); - } - } -} - -// -------------------- updateActionViewer -------------------- -void ActionViewer::updateActionViewer(UpdateReason reason) { - familyComboBox->blockSignals(true); - nameComboBox->blockSignals(true); - tagLineEdit->blockSignals(true); - - ActionList possibleActions; - - switch (reason) { - case ActionFamilyChanged: - //-- family was changed, fill the name combo box with this family actions - nameComboBox->clear(); - nameComboBox->addItem("-- Select Action --"); - - if (Application::getSelectedComponents().size() > 0) { - possibleActions = Application::getActions(Application::getSelectedComponents()); - } - else - // no selection => select only empty component actions - { - possibleActions = Application::getActions(nullptr); - } - - foreach (Action* action, possibleActions) { - if (action->getFamily() == familyComboBox->currentText() || familyComboBox->currentText() == QString("-- Select Family --")) { - nameComboBox->addItem(action->getName()); - } - } - nameComboBox->model()->sort(0); - break; - - case ActionNameChanged: - - //-- action name whas changed -> trigger the corresponding action - if (action) { - familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - action->trigger(); - } - - break; - - case ActionTagChanged: { - //-- tag field was changed, fill the name combo box with the corresponding actions - ActionList actionset = Application::getActions(Application::getSelectedComponents(), tagLineEdit->text()); - - if (!actionset.isEmpty()) { - if (actionset.size() == 1) { - action = *(actionset.begin()); - nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); - updateActionViewer(ActionNameChanged); - } - else { - nameComboBox->clear(); - nameComboBox->addItem("-- Select Action --"); - foreach (Action* action, actionset) { - nameComboBox->addItem(action->getName()); - } - } - - nameComboBox->model()->sort(0); - } - } - break; - - case ViewerRefresh: - default: { - - //-- selection was changed, update combo boxes and tag list, and then check history - // copy selected component list (so that references are not used for comparison) - ComponentList selected(Application::getSelectedComponents()); - // if selection did not change between two updates, no need to refresh the widget - if (currentlySelected != selected) { - currentlySelected = selected; - //-- update the search panel - familyComboBox->clear(); - nameComboBox->clear(); - QStringList wordList; - familyComboBox->addItem("-- Select Family --"); - nameComboBox->addItem("-- Select Action --"); - if (selected.size() > 0) { - possibleActions = Application::getActions(selected.last()); - } - else { // no selection => select only empty component actions - possibleActions = Application::getActions(nullptr); - } // Complete family and action lists depending of the last selected component - foreach (Action* action, possibleActions) { - if (familyComboBox->findText(action->getFamily()) == -1) { - familyComboBox->addItem(action->getFamily()); - } - if (nameComboBox->findText(action->getName()) == -1) { - nameComboBox->addItem(action->getName()); - } - foreach (QString tag, action->getTag()) { - if (!wordList.contains(tag)) { - wordList.append(tag); - } - } - } - nameComboBox->model()->sort(0); - familyComboBox->model()->sort(0); - auto* completer = new QCompleter(wordList, myWidget); - completer->setCaseSensitivity(Qt::CaseInsensitive); - tagLineEdit->setCompleter(completer); - - //-- check history - // check if the same list of Component* was already used - QMap::const_iterator it = widgetHistory.find(selected); - if (it != widgetHistory.end()) { - // show the previously used widget - if (it.value() == NULL) { - actionWidgetStack->setCurrentIndex(emptyActionWidgetIndex); - } - else { // update search panel - familyComboBox->setCurrentIndex(familyComboBox->findText(it.value()->getFamily())); - nameComboBox->setCurrentIndex(nameComboBox->findText(it.value()->getName())); - it.value()->trigger(); - } - } - else { - // insert new index in history (NULL action, with empty widget) - widgetHistory.insert(selected, NULL); - actionWidgetStack->setCurrentIndex(emptyActionWidgetIndex); - } - } - } - } - - familyComboBox->blockSignals(false); - nameComboBox->blockSignals(false); - tagLineEdit->blockSignals(false); -} - -// -------------------- embedActionWidget -------------------- -void ActionViewer::embedActionWidget(Action* action) { - // make sure the action viewer is visible (even if in a dockwidget) - if (getWidget()->parentWidget()) { - getWidget()->parentWidget()->setVisible(true); - getWidget()->setVisible(true); - } - - //-- check history - QWidget* actionWidget = action->getWidget(); - int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); - - if (actionWidgetIndex == -1 && actionWidget) { - // add the widget (beware that actionWidgetStack then takes ownership of the widget!) - actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); - } - - // insert new index in history - ComponentList selected(Application::getSelectedComponents()); - widgetHistory.insert(selected, action); - actionWidgetStack->setCurrentIndex(actionWidgetIndex); - actionWidgetStack->update(); - // ignore size policy of widget so that it can be resized - actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); - - // update search panel - familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - updateActionViewer(ActionFamilyChanged); // to have only the actions of the same family - nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); -} diff --git a/sdk/viewers/actionviewer2/ActionViewer.h b/sdk/viewers/actionviewer2/ActionViewer.h deleted file mode 100644 index 8d96d3cf..00000000 --- a/sdk/viewers/actionviewer2/ActionViewer.h +++ /dev/null @@ -1,142 +0,0 @@ -/***************************************************************************** - * $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 ACTIONVIEWER_H -#define ACTIONVIEWER_H - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -/** - * @ingroup group_sdk_libraries_core_viewer - * - * @brief - * ActionViewer is the viewer used to manage the actions. - * - * By default all action widgets are displayed in this viewer widget (in the stackedWidget). - * There is also a search panel to find an action to apply to the currently selected component. - * The search panel is not not shown by default. Use setSearchPanelVisible(true) to show it. - * - * This viewer also manages a singleton (THE CamiTK action viewer). See getInstance() for more information. - * You do not have to use it, but it is convienent (and sometimes preferable) to use this instance - * instead of creating your own one. - */ -class ActionViewer : public camitk::Viewer { - Q_OBJECT - -public: - /** @name General - */ - ///@{ - /// constructor - ActionViewer(QString name); - - /// destructor - virtual ~ActionViewer(); - - /// @name Inherited from Viewer - //@{ - /// returns the number of Component that are displayed by this viewer - unsigned int numberOfViewedComponent() { - return 0; - }; - - /// refresh the view (can be interesting to know which other viewer is calling this) - virtual void refresh(Viewer* whoIsAsking = nullptr); - - /// get the viewer widget. @param parent the parent widget for the viewer widget - virtual QWidget* getWidget(QWidget* parent = nullptr); - //@} - - /// @name Specific to the Action viewer - //@{ - /// embed an action widget in the stacked widget - virtual void embedActionWidget(camitk::Action*); - - /// show/hide the search panel (hidden by default) - virtual void setSearchPanelVisible(bool); - //@} - -protected slots : - /// Method used to change the action selected - void changeName(); - - /// Method used to change the action family selected - void changeFamily(); - - /// Method used to change the tag - void changeTag(); - -private: - /// Enum the different fields of the action viewwer - enum UpdateReason {ActionFamilyChanged, ActionNameChanged, ActionTagChanged, ViewerRefresh}; - - /// method used to update the viewer for a given update field - void updateActionViewer(UpdateReason); - - /// Main action widget of the viewer - QWidget* myWidget; - - /// Family combo box - QComboBox* familyComboBox; - - /// Action name combo box - QComboBox* nameComboBox; - - /// Current action - camitk::Action* action; - - /// action tags line edit - QLineEdit* tagLineEdit; - - /// actions stacked widget of the viewer - QStackedWidget* actionWidgetStack; - - /// the search panel - QFrame* searchFramePanel; - - /// index of the empty widget, used when no action is active or when no action has been used for the currently selected components - int emptyActionWidgetIndex; - - /// this map stores the list of selected component and the corresponding stack index of their embedded action - QMap widgetHistory; - - /// Used to evaluate modification of the list while execution - camitk::ComponentList currentlySelected; -}; - - -#endif // ACTIONVIEWER_H diff --git a/sdk/viewers/actionviewer2/ActionViewer2Extension.cpp b/sdk/viewers/actionviewer2/ActionViewer2Extension.cpp deleted file mode 100644 index 78bf547b..00000000 --- a/sdk/viewers/actionviewer2/ActionViewer2Extension.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/***************************************************************************** - * $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 "ActionViewer2Extension.h" - -// include generated actions headers -#include "ActionViewer.h" - -// --------------- getViewers ------------------- -void ActionViewer2Extension::init() { -} - diff --git a/sdk/viewers/actionviewer2/ActionViewer2Extension.h b/sdk/viewers/actionviewer2/ActionViewer2Extension.h deleted file mode 100644 index 661cf057..00000000 --- a/sdk/viewers/actionviewer2/ActionViewer2Extension.h +++ /dev/null @@ -1,62 +0,0 @@ -/***************************************************************************** - * $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 ACTIONVIEWER2EXTENSION_H -#define ACTIONVIEWER2EXTENSION_H - - -#include "ViewerExtension.h" - -class ActionViewer2Extension : public camitk::ViewerExtension { - Q_OBJECT - Q_INTERFACES(camitk::ViewerExtension); - Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionviewer2extension.viewer.actionviewer2extension") - -public: - /// Constructor - ActionViewer2Extension() : ViewerExtension() {}; - - /// Destructor - virtual ~ActionViewer2Extension() = default; - - /// Method returning the action extension name - virtual QString getName() { - return "Action Viewer 2 Extension"; - }; - - /// Method returning the action extension descrption - virtual QString getDescription() { - return "An extension for the viewer that display GUI action"; - }; - - /// initialize all the actions - virtual void init(); - -}; - -#endif // ACTIONVIEWEREXTENSION_H - - diff --git a/sdk/viewers/actionviewer2/CMakeLists.txt b/sdk/viewers/actionviewer2/CMakeLists.txt deleted file mode 100644 index e3b83fcb..00000000 --- a/sdk/viewers/actionviewer2/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Call CamiTK CMake Macro to define the action -camitk_extension(VIEWER_EXTENSION - CEP_NAME SDK - DEFINES COMPILE_ACTIONVIEWER_API - DESCRIPTION "An extension for the viewer that display GUI action" - INSTALL_ALL_HEADERS -) - diff --git a/tutorials/actions/basicpicking/CMakeLists.txt b/tutorials/actions/basicpicking/CMakeLists.txt index c2e21bb1..32e74695 100644 --- a/tutorials/actions/basicpicking/CMakeLists.txt +++ b/tutorials/actions/basicpicking/CMakeLists.txt @@ -1,5 +1,4 @@ camitk_extension(ACTION_EXTENSION ENABLE_AUTO_TEST TEST_FILES bassin.msh brain.mha sinus.mhd - NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/tutorials/actions/bitmapviewer/CMakeLists.txt b/tutorials/actions/bitmapviewer/CMakeLists.txt index 0520470c..8f3993e8 100644 --- a/tutorials/actions/bitmapviewer/CMakeLists.txt +++ b/tutorials/actions/bitmapviewer/CMakeLists.txt @@ -1,3 +1,3 @@ camitk_extension(ACTION_EXTENSION - NEEDS_VIEWER_EXTENSION bitmap interactiveviewer + NEEDS_VIEWER_EXTENSION bitmap ) diff --git a/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt b/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt index 6fe6ac1a..62fd9d30 100644 --- a/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt +++ b/tutorials/actions/meshanimation/shakerextension/CMakeLists.txt @@ -3,5 +3,4 @@ camitk_extension(ACTION_EXTENSION NEEDS_CEP_LIBRARIES shakerlib ENABLE_AUTO_TEST TEST_FILES brain.mha bassin.msh head1.STL liver-smooth.obj Mesh.off mixed_3D_beam.msh robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk - NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/tutorials/actions/meshpointdata/CMakeLists.txt b/tutorials/actions/meshpointdata/CMakeLists.txt index 408b60ad..5b32c7ad 100644 --- a/tutorials/actions/meshpointdata/CMakeLists.txt +++ b/tutorials/actions/meshpointdata/CMakeLists.txt @@ -2,7 +2,6 @@ camitk_extension(ACTION_EXTENSION DESCRIPTION "This extension shows how to show/hide mesh point data using a color scale" ENABLE_AUTO_TEST - NEEDS_VIEWER_EXTENSION interactiveviewer TEST_FILES brain.mha bassin.msh head1.STL liver-smooth.obj Mesh.off robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk cube-with-point-and-cell-data.vtk fieldfile.vtk check-with-color-pointdata.vtk plate-with-data.vtk female.vtk brainImageSmooth.vtk structuredgrid-with-data.vtk male.vtk cube-with-tensors.vtk imageBoundingBox.vtk binary-mesh-with-pointdata.vtk unstructured_binary_with_celldata.vtk ) diff --git a/tutorials/actions/sleepingwhileworking/CMakeLists.txt b/tutorials/actions/sleepingwhileworking/CMakeLists.txt index d585c8b3..e306a7a9 100644 --- a/tutorials/actions/sleepingwhileworking/CMakeLists.txt +++ b/tutorials/actions/sleepingwhileworking/CMakeLists.txt @@ -2,5 +2,5 @@ camitk_extension(ACTION_EXTENSION ENABLE_AUTO_TEST TEST_FILES Mesh.off BigEndian.hdr BigEndian.img BigEndianCompressed1.hdr BigEndianCompressed1.img biorad.pic brain.mha cthead1.lsm LittleEndian1.hdr LittleEndian1.img LittleEndianCompressed1.hdr LittleEndianCompressed1.img LittleEndianZ1.hdr mini-complex-slow1.nrrd mini-ten-nomask-slow1.nrrd mini-vector-slow1.nrrd ramp1.gipl - NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer + NEEDS_VIEWER_EXTENSION medicalimageviewer ) diff --git a/tutorials/actions/vtkwidget/CMakeLists.txt b/tutorials/actions/vtkwidget/CMakeLists.txt index 25fb18d7..9874b77d 100644 --- a/tutorials/actions/vtkwidget/CMakeLists.txt +++ b/tutorials/actions/vtkwidget/CMakeLists.txt @@ -1,5 +1,5 @@ camitk_extension(ACTION_EXTENSION ENABLE_AUTO_TEST TEST_FILES bassin.msh brain.mha sinus.mhd head1.STL liver-smooth.obj Mesh.off robot.wrl scissors.obj simple.vtk sinus_skin.vtk sinus_skull.vtk skull1.stl structured.vtk pointcloud-with-data.vtk polydata-with-data.vtk cube-with-point-and-cell-data.vtk fieldfile.vtk check-with-color-pointdata.vtk plate-with-data.vtk female.vtk brainImageSmooth.vtk structuredgrid-with-data.vtk male.vtk cube-with-tensors.vtk imageBoundingBox.vtk binary-mesh-with-pointdata.vtk unstructured_binary_with_celldata.vtk - NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer + NEEDS_VIEWER_EXTENSION medicalimageviewer ) diff --git a/tutorials/applications/basic/CMakeLists.txt b/tutorials/applications/basic/CMakeLists.txt index 37ec6f1a..306ee0ba 100644 --- a/tutorials/applications/basic/CMakeLists.txt +++ b/tutorials/applications/basic/CMakeLists.txt @@ -1,3 +1 @@ -camitk_application( - NEEDS_VIEWER_EXTENSION interactiveviewer -) +camitk_application() diff --git a/tutorials/applications/fancy/CMakeLists.txt b/tutorials/applications/fancy/CMakeLists.txt index 5d615d50..63bb1501 100644 --- a/tutorials/applications/fancy/CMakeLists.txt +++ b/tutorials/applications/fancy/CMakeLists.txt @@ -1,3 +1,3 @@ camitk_application( - NEEDS_VIEWER_EXTENSION interactiveviewer medicalimageviewer + NEEDS_VIEWER_EXTENSION medicalimageviewer ) diff --git a/tutorials/applications/fancy/FancyMainWindow.h b/tutorials/applications/fancy/FancyMainWindow.h index d72733f2..546e8513 100644 --- a/tutorials/applications/fancy/FancyMainWindow.h +++ b/tutorials/applications/fancy/FancyMainWindow.h @@ -92,10 +92,10 @@ private: QWidget* mainWidget; /// get the currently visible viewer (axial, sagittal, coronal or arbitrary) - InteractiveViewer* getVisibleViewer(); + camitk::InteractiveViewer* getVisibleViewer(); /// specific 3D viewer for fancy - InteractiveViewer* viewer3D; + camitk::InteractiveViewer* viewer3D; }; #endif // FANCYAPP_H diff --git a/tutorials/applications/menubar/CMakeLists.txt b/tutorials/applications/menubar/CMakeLists.txt index 40168868..306ee0ba 100644 --- a/tutorials/applications/menubar/CMakeLists.txt +++ b/tutorials/applications/menubar/CMakeLists.txt @@ -1,3 +1 @@ -camitk_application( - NEEDS_VIEWER_EXTENSION explorer interactiveviewer -) +camitk_application() diff --git a/tutorials/applications/menubar/MyAppMainWindow.cpp b/tutorials/applications/menubar/MyAppMainWindow.cpp index cc8d068a..78033db3 100644 --- a/tutorials/applications/menubar/MyAppMainWindow.cpp +++ b/tutorials/applications/menubar/MyAppMainWindow.cpp @@ -29,7 +29,6 @@ // -- CamiTK Core stuff #include #include -#include #include #include #include diff --git a/tutorials/applications/simple/CMakeLists.txt b/tutorials/applications/simple/CMakeLists.txt index 777ce434..306ee0ba 100644 --- a/tutorials/applications/simple/CMakeLists.txt +++ b/tutorials/applications/simple/CMakeLists.txt @@ -1,3 +1 @@ -camitk_application( - NEEDS_VIEWER_EXTENSION medicalimageviewer interactiveviewer -) +camitk_application() diff --git a/tutorials/applications/simple/SimpleMainWindow.cpp b/tutorials/applications/simple/SimpleMainWindow.cpp index 122f271f..3f416e45 100644 --- a/tutorials/applications/simple/SimpleMainWindow.cpp +++ b/tutorials/applications/simple/SimpleMainWindow.cpp @@ -28,7 +28,6 @@ // -- Core stuff #include -#include #include #include diff --git a/tutorials/viewers/bitmap/BitmapViewer.cpp b/tutorials/viewers/bitmap/BitmapViewer.cpp index 9bbe2ab4..fd248782 100644 --- a/tutorials/viewers/bitmap/BitmapViewer.cpp +++ b/tutorials/viewers/bitmap/BitmapViewer.cpp @@ -36,9 +36,9 @@ using namespace camitk; // -------------------- Constructor -------------------- -BitmapViewer::BitmapViewer(ViewerExtension* extension, QString name) : InteractiveViewer(extension, name, InteractiveViewer::SLICE_VIEWER) { +BitmapViewer::BitmapViewer(QString name) : InteractiveViewer(name, InteractiveViewer::SLICE_VIEWER) { // 2D images need x right, y up, z front - getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_UP); + getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); // no decoration and grey background getRendererWidget()->toggleOrientationDecorations(false); getRendererWidget()->setGradientBackground(false); @@ -46,6 +46,8 @@ BitmapViewer::BitmapViewer(ViewerExtension* extension, QString name) : Interacti // parallel projection getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + setComponents(QStringList() << "ImageComponent"); + myToolbar = nullptr; } diff --git a/tutorials/viewers/bitmap/BitmapViewer.h b/tutorials/viewers/bitmap/BitmapViewer.h index 02a86437..10ab8296 100644 --- a/tutorials/viewers/bitmap/BitmapViewer.h +++ b/tutorials/viewers/bitmap/BitmapViewer.h @@ -38,11 +38,11 @@ class QToolBar; * @brief * InteractiveViewer specialized in 2D bitmap (images in jpeg, png...) */ -class BITMAP_VIEWER_API BitmapViewer : public InteractiveViewer { +class BITMAP_VIEWER_API BitmapViewer : public camitk::InteractiveViewer { Q_OBJECT public: - BitmapViewer(camitk::ViewerExtension* extension, QString name); + BitmapViewer(QString name); virtual ~BitmapViewer() override; diff --git a/tutorials/viewers/bitmap/CMakeLists.txt b/tutorials/viewers/bitmap/CMakeLists.txt index b57f43cc..58c4805a 100644 --- a/tutorials/viewers/bitmap/CMakeLists.txt +++ b/tutorials/viewers/bitmap/CMakeLists.txt @@ -4,6 +4,5 @@ camitk_extension(VIEWER_EXTENSION DEFINES COMPILE_BITMAP_VIEWER_API DESCRIPTION "This extension provides a simple 2D image viewer" INSTALL_ALL_HEADERS - NEEDS_VIEWER_EXTENSION interactiveviewer ) diff --git a/tutorials/viewers/textviewer/CMakeLists.txt b/tutorials/viewers/textviewer/CMakeLists.txt index a1b1c4be..c47130cc 100644 --- a/tutorials/viewers/textviewer/CMakeLists.txt +++ b/tutorials/viewers/textviewer/CMakeLists.txt @@ -4,6 +4,5 @@ camitk_extension(VIEWER_EXTENSION DEFINES COMPILE_TEXT_VIEWER_API DESCRIPTION "An extension to add TextViewer (a pure simple text viewer)" INSTALL_ALL_HEADERS - NEEDS_VIEWER_EXTENSION medicalimageviewer ) diff --git a/tutorials/viewers/textviewer/TextViewer.cpp b/tutorials/viewers/textviewer/TextViewer.cpp index 185f3606..a1f26b1f 100644 --- a/tutorials/viewers/textviewer/TextViewer.cpp +++ b/tutorials/viewers/textviewer/TextViewer.cpp @@ -28,7 +28,6 @@ // -- Core stuff #include #include -#include #include //-- Qt stuff @@ -39,7 +38,7 @@ using namespace camitk; // -------------------- Constructor -------------------- -TextViewer::TextViewer(ViewerExtension* extension, QString name) : Viewer(extension, name) { +TextViewer::TextViewer(QString name) : Viewer(name) { inverse = nullptr; myMenu = nullptr; myWidget = nullptr; @@ -47,28 +46,6 @@ TextViewer::TextViewer(ViewerExtension* extension, QString name) : Viewer(extens displayedTopLevelComponents = 0; } -// -------------------- switchCentralViewer -------------------- -void TextViewer::switchCentralViewer() { - // if the central viewer is the medical image viewer switch to my2DBitmapViewer (if it is not switch back to the medical image viewer) - if (isVisible) { - // switch back to the default MedicalImageViewer - //DualViewer::getInstance()->getToolBar()->setVisible(false); - Application::getMainWindow()->setCentralViewer(Application::getViewer("MedicalImageViewer")); - disconnect(Application::getViewer("Explorer"), SIGNAL(selectionChanged()), this, SLOT(switchCentralViewer())); - Application::refresh(); - } - else { - // switch to the custom viewer - //DualViewer::getInstance()->getToolBar()->setVisible(true); - Application::getMainWindow()->setCentralViewer(Application::getViewer("TextViewer")); - connect(Application::getViewer("Explorer"), SIGNAL(selectionChanged()), this, SLOT(switchCentralViewer())); - // force refresh - refresh(this); - } - - isVisible = !isVisible; -} - // -------------------- Destructor -------------------- TextViewer::~TextViewer() { } diff --git a/tutorials/viewers/textviewer/TextViewer.h b/tutorials/viewers/textviewer/TextViewer.h index c6f34b6e..2a15d3e0 100644 --- a/tutorials/viewers/textviewer/TextViewer.h +++ b/tutorials/viewers/textviewer/TextViewer.h @@ -59,7 +59,7 @@ public: */ /// @{ /** construtor. */ - TextViewer(camitk::ViewerExtension* extension, QString name); + TextViewer(QString name); /** destructor */ virtual ~TextViewer(); @@ -94,8 +94,6 @@ public: /// @} public slots: - void switchCentralViewer(); - /// inverse background/forground colors void inverseColors(bool); -- GitLab From 78ae262888ddc957aaa31ef77168ce58c51137e2 Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Tue, 4 Feb 2020 09:48:26 +0100 Subject: [PATCH 17/26] NEW Viewer widget is either docked/embedded/stacked + bug fix and code cleaning --- .../ImageReconstructionAction.cpp | 7 +- .../image/reorientimage/ReorientImage.cpp | 3 +- sdk/actions/mesh/basicmesh/CenterMesh.h | 2 +- sdk/actions/mesh/basicmesh/RigidTransform.h | 4 +- .../MeshProcessingExtension.cpp | 3 +- .../actionstatemachine/ActionState.cpp | 2 +- .../actionstatemachine/ActionStateViewer.cpp | 15 +- .../actionstatemachine/ActionStateViewer.h | 17 +- .../ActionStateViewerExtension.cpp | 2 +- .../actionstatemachine/ActionStateWidget.cpp | 16 +- sdk/applications/imp/CMakeLists.txt | 4 +- sdk/applications/imp/ImpMainWindow.cpp | 81 ++++-- sdk/applications/imp/main.cpp | 3 +- sdk/libraries/core/ExtensionManager.cpp | 213 ++++++++------ sdk/libraries/core/action/Action.cpp | 23 +- sdk/libraries/core/action/ActionExtension.cpp | 49 ++-- sdk/libraries/core/action/ActionExtension.h | 12 +- .../core/application/Application.cpp | 264 ++++++++++-------- sdk/libraries/core/application/Application.h | 7 +- sdk/libraries/core/application/MainWindow.cpp | 96 ++++--- sdk/libraries/core/application/MainWindow.h | 7 +- sdk/libraries/core/component/Component.cpp | 48 +++- sdk/libraries/core/utils/CamiTKLogger.cpp | 7 + .../core/viewer/InteractiveViewer.cpp | 103 ++++--- sdk/libraries/core/viewer/InteractiveViewer.h | 53 ++-- sdk/libraries/core/viewer/Viewer.cpp | 192 +++++++++++-- sdk/libraries/core/viewer/Viewer.h | 121 +++++--- sdk/libraries/core/viewer/ViewerExtension.cpp | 139 +++++---- sdk/libraries/core/viewer/ViewerExtension.h | 77 ++--- sdk/viewers/actionviewer/ActionViewer.cpp | 123 ++++---- sdk/viewers/actionviewer/ActionViewer.h | 5 +- .../actionviewer/ActionViewerExtension.cpp | 2 +- .../actionviewer/ActionViewerExtension.h | 5 +- sdk/viewers/actionviewer/CMakeLists.txt | 2 +- .../viewers/bitmap/BitmapViewer.cpp | 4 +- .../viewers/bitmap/BitmapViewer.h | 4 +- .../viewers/bitmap/BitmapViewerAPI.h | 0 .../viewers/bitmap/BitmapViewerExtension.cpp | 2 +- .../viewers/bitmap/BitmapViewerExtension.h | 1 + .../viewers/bitmap/CMakeLists.txt | 0 sdk/viewers/explorer/Explorer.cpp | 15 +- sdk/viewers/explorer/Explorer.h | 7 +- sdk/viewers/explorer/ExplorerExtension.cpp | 2 +- sdk/viewers/explorer/ExplorerExtension.h | 3 +- sdk/viewers/frameexplorer/FrameExplorer.cpp | 14 +- sdk/viewers/frameexplorer/FrameExplorer.h | 23 +- .../frameexplorer/FrameExplorerExtension.cpp | 2 +- .../frameexplorer/FrameExplorerExtension.h | 3 +- .../InteractiveGeometryViewer.cpp | 13 +- .../InteractiveGeometryViewer.h | 6 +- .../InteractiveGeometryViewerExtension.cpp | 1 - .../InteractiveGeometryViewerExtension.h | 3 +- .../InteractiveSliceViewer.cpp | 44 ++- .../InteractiveSliceViewer.h | 6 +- .../InteractiveSliceViewerExtension.h | 3 +- sdk/viewers/medicalimageviewer/CMakeLists.txt | 1 + .../medicalimageviewer/MedicalImageViewer.cpp | 42 +-- .../medicalimageviewer/MedicalImageViewer.h | 13 +- .../MedicalImageViewerExtension.cpp | 2 +- .../MedicalImageViewerExtension.h | 3 +- .../propertyexplorer/PropertyExplorer.cpp | 48 ++-- .../propertyexplorer/PropertyExplorer.h | 28 +- .../PropertyExplorerExtension.cpp | 2 +- .../PropertyExplorerExtension.h | 3 +- tutorials/applications/fancy/main.cpp | 3 +- tutorials/applications/menubar/main.cpp | 3 +- tutorials/applications/simple/main.cpp | 5 +- tutorials/viewers/textviewer/TextViewer.cpp | 8 +- tutorials/viewers/textviewer/TextViewer.h | 4 +- .../textviewer/TextViewerExtension.cpp | 2 +- 70 files changed, 1252 insertions(+), 778 deletions(-) rename {tutorials => sdk}/viewers/bitmap/BitmapViewer.cpp (97%) rename {tutorials => sdk}/viewers/bitmap/BitmapViewer.h (95%) rename {tutorials => sdk}/viewers/bitmap/BitmapViewerAPI.h (100%) rename {tutorials => sdk}/viewers/bitmap/BitmapViewerExtension.cpp (95%) rename {tutorials => sdk}/viewers/bitmap/BitmapViewerExtension.h (99%) rename {tutorials => sdk}/viewers/bitmap/CMakeLists.txt (100%) diff --git a/sdk/actions/image/reconstruction/ImageReconstructionAction.cpp b/sdk/actions/image/reconstruction/ImageReconstructionAction.cpp index f1a4a9ed..8f92a7ee 100644 --- a/sdk/actions/image/reconstruction/ImageReconstructionAction.cpp +++ b/sdk/actions/image/reconstruction/ImageReconstructionAction.cpp @@ -23,18 +23,13 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ -// -- Core image component stuff classes #include "ImageReconstructionAction.h" -#include "ImageComponent.h" -#include "MeshComponent.h" // -- Core stuff classes #include #include #include - -// -- stl stuff -#include +#include // -- vtk filters stuff #include diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index 66547eaf..782d1603 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -138,7 +138,7 @@ void ReorientImage::initDialog() { //-- add the internal viewer initInternalViewer(); - ui.illustrationLayout->addWidget(internalViewer->getWidget(dialog)); + internalViewer->embedIn(ui.illustrationLayout); ui.xDirection->setTextFormat(Qt::RichText); ui.yDirection->setTextFormat(Qt::RichText); @@ -193,6 +193,7 @@ void ReorientImage::initInternalViewer() { // Set up the 3D viewer to visualize actual origin/orientation locations internalViewer = dynamic_cast(Application::getNewViewer("Image Orientation Viewer", "InteractiveGeometryViewer")); + internalViewer->setLayout(Viewer::EMBEDDED); internalViewer->setHighlightMode(InteractiveViewer::OFF); internalViewer->toggleCopyright(false); internalViewer->getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); diff --git a/sdk/actions/mesh/basicmesh/CenterMesh.h b/sdk/actions/mesh/basicmesh/CenterMesh.h index e70b8bee..c648c677 100644 --- a/sdk/actions/mesh/basicmesh/CenterMesh.h +++ b/sdk/actions/mesh/basicmesh/CenterMesh.h @@ -26,7 +26,7 @@ #ifndef CENTERMESH_H #define CENTERMESH_H -#include "Action.h" +#include /** * @ingroup group_sdk_actions_mesh_basicmesh diff --git a/sdk/actions/mesh/basicmesh/RigidTransform.h b/sdk/actions/mesh/basicmesh/RigidTransform.h index e83cd1a6..21df0ba5 100644 --- a/sdk/actions/mesh/basicmesh/RigidTransform.h +++ b/sdk/actions/mesh/basicmesh/RigidTransform.h @@ -26,8 +26,8 @@ #ifndef RIGID_TRANSFORM_H #define RIGID_TRANSFORM_H -#include "Action.h" -#include "Component.h" +#include +#include #include #include diff --git a/sdk/actions/mesh/meshprocessing/MeshProcessingExtension.cpp b/sdk/actions/mesh/meshprocessing/MeshProcessingExtension.cpp index 09d3357f..8156aee6 100644 --- a/sdk/actions/mesh/meshprocessing/MeshProcessingExtension.cpp +++ b/sdk/actions/mesh/meshprocessing/MeshProcessingExtension.cpp @@ -22,6 +22,7 @@ * * $CAMITK_LICENCE_END$ ****************************************************************************/ + #include "MeshProcessingExtension.h" #include "Decimation.h" #include "CleanPolyData.h" @@ -41,8 +42,6 @@ #include "SaveDisplacementFromTransformation.h" #include "AppendMeshes.h" -#include "Application.h" - // -------------------- init -------------------- void MeshProcessingExtension::init() { registerNewAction(Decimation); diff --git a/sdk/applications/actionstatemachine/ActionState.cpp b/sdk/applications/actionstatemachine/ActionState.cpp index 6d4dedf1..c041c3e5 100644 --- a/sdk/applications/actionstatemachine/ActionState.cpp +++ b/sdk/applications/actionstatemachine/ActionState.cpp @@ -22,8 +22,8 @@ * * $CAMITK_LICENCE_END$ ****************************************************************************/ + #include "ActionState.h" -//FIXME #include "ActionStateViewer.h" // -- CamiTK Core stuff #include diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.cpp b/sdk/applications/actionstatemachine/ActionStateViewer.cpp index 9f648a8a..0d278edf 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewer.cpp @@ -36,21 +36,14 @@ // ---------------- constructor ---------------- ActionStateViewer::ActionStateViewer(QString name) : Viewer(name) { myWidget = nullptr; + // empty the list as this is a state viewer, it has nothing to do with Components + setComponents(QStringList()); } // ---------------- getWidget ---------------- -QWidget* ActionStateViewer::getWidget(QWidget* parent) { +QWidget* ActionStateViewer::getWidget() { if (myWidget == nullptr) { - // if no parent then put this in a dialog - if (!parent) { - // put it in a dialog, this is the case for default MainWindow, who does not add the ActionViewer in a dock - QDialog* myWidgetIsADialog = new QDialog(nullptr); - myWidgetIsADialog->setWindowTitle(objectName()); - myWidget = myWidgetIsADialog; - } - else { - myWidget = new QWidget(); - } + myWidget = new QWidget(); auto* actionStateWidgetLayout = new QVBoxLayout(); diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.h b/sdk/applications/actionstatemachine/ActionStateViewer.h index c4e45308..8d972ac1 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.h +++ b/sdk/applications/actionstatemachine/ActionStateViewer.h @@ -25,14 +25,12 @@ #ifndef ACTIONSTATEVIEWER_H #define ACTIONSTATEVIEWER_H -#include - // Qt stuff #include #include // CamiTK stuff -#include "Viewer.h" +#include // Local includes #include "ActionState.h" @@ -48,11 +46,11 @@ class ActionStateViewer : public camitk::Viewer { Q_OBJECT public: + + ActionStateViewer(QString name); - ActionStateViewer(QString name); - - /// get the viewer widget. @param parent the parent widget for the viewer widget - virtual QWidget* getWidget(QWidget* parent = nullptr); + /// get the viewer widget. + virtual QWidget* getWidget(); /// returns the number of Component that are displayed by this viewer virtual unsigned int numberOfViewedComponent() { @@ -62,12 +60,15 @@ public: /// refresh the view (can be interesting to know which other viewer is calling this) virtual void refresh(Viewer* whoIsAsking = nullptr) {}; - + /// set the current state void setState(ActionState* actionState); private: + /// the viewer's widget QWidget* myWidget; + + /// the viewer's name QString name; /// actions stacked widget of the viewer diff --git a/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp b/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp index 07cfd243..19632d93 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getActions ------------------- void ActionStateViewerExtension::init() { - registerNewViewer(ActionStateViewer, "ActionStateViewer"); + registerDefaultViewer(ActionStateViewer); } diff --git a/sdk/applications/actionstatemachine/ActionStateWidget.cpp b/sdk/applications/actionstatemachine/ActionStateWidget.cpp index 50f2155a..aa8e0383 100644 --- a/sdk/applications/actionstatemachine/ActionStateWidget.cpp +++ b/sdk/applications/actionstatemachine/ActionStateWidget.cpp @@ -23,9 +23,10 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ #include "ActionStateWidget.h" -#include "Action.h" #include "ActionState.h" +#include + ActionStateWidget::ActionStateWidget(ActionState* actionState) { ui.setupUi(this); myActionState = actionState; @@ -51,16 +52,3 @@ void ActionStateWidget::setActionWidget(QWidget* widget) { void ActionStateWidget::setDescription(QString description) { ui.stateDescriptionLabel->setText(description); } - - -//QPushButton * ActionStateWidget::setFinal() { -// const QPalette pal(Qt::red); // enumeration is Qt::GlobalColor -// QPushButton * button = new QPushButton("Quit", this); -// button->setAutoFillBackground(true); //this must be set for palette to work -// button->setPalette(pal); // assign color palette to button -// -// ui.buttonsLayout->addWidget(button); -// -// return button; -// -//} \ No newline at end of file diff --git a/sdk/applications/imp/CMakeLists.txt b/sdk/applications/imp/CMakeLists.txt index d3c3e9f7..8dc0fcb7 100644 --- a/sdk/applications/imp/CMakeLists.txt +++ b/sdk/applications/imp/CMakeLists.txt @@ -1,8 +1,8 @@ camitk_application( ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx CEP_NAME SDK - NEEDS_VIEWER_EXTENSION actionviewer + NEEDS_VIEWER_EXTENSION actionviewer medicalimageviewer explorer frameexplorer propertyexplorer DESCRIPTION "All-in-one application to load actions and components and interact with them" ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure -set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") \ No newline at end of file +set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 0d410356..420a7dc2 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -69,6 +69,7 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { updateOpenDirectoryMenu(); // now add the different viewers + setCentralViewer(Application::getViewer("BitmapViewer")); setCentralViewer(Application::getViewer("MedicalImageViewer")); addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("FrameExplorer")); @@ -76,9 +77,10 @@ ImpMainWindow::ImpMainWindow() : MainWindow("imp") { addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionViewer")); //Merge Explorer and FrameExplorer viewers in one layout - QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); - QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); - if (dockWidgetExplorer && dockWidgetFrameExplorer) { + QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), nullptr); + QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), nullptr); + + if (dockWidgetExplorer != nullptr && dockWidgetFrameExplorer != nullptr) { tabifyDockWidget(dockWidgetExplorer, dockWidgetFrameExplorer); dockWidgetExplorer->raise(); } @@ -136,12 +138,15 @@ void ImpMainWindow::initActions() { //-- Check for action applications ActionExtension* applicationActionExtension = NULL; QListIterator it(ExtensionManager::getActionExtensionsList()); + while (it.hasNext() && applicationActionExtension == NULL) { ActionExtension* current = it.next(); + if (current->getName() == "Application Level Actions") { applicationActionExtension = current; } } + if (applicationActionExtension == NULL) { CAMITK_ERROR(tr("Application error: the \"Application Level Actions\" extension is required by this application but could not be found\nIn any of the following extension directories:\n - %1\nPlease check your CamiTK configuration and/or installation using \"camitk-config --config\"").arg(Core::getActionDirectories().join("\n - "))) exit(EXIT_FAILURE); @@ -334,6 +339,7 @@ void ImpMainWindow::updateActionStates() { else { // add all generic actions ActionList allActions = Application::getActions(NULL); + foreach (Action* action, allActions) { actionMenu->addAction(action->getQAction()); actionMenu->setEnabled(true); @@ -380,33 +386,38 @@ void ImpMainWindow::showStatusBar(bool b) { // ------------------------ resetWindows ---------------------------- void ImpMainWindow::resetWindows() { for (QMap::iterator it = dockWidgetMap.begin(); it != dockWidgetMap.end(); it++) { - if (it.value()->widget() == Application::getViewer("Explorer")->getWidget(NULL)) { + if (it.key()->getName() == "Explorer") { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } - else - if (it.value()->widget() == Application::getViewer("FrameExplorer")->getWidget(NULL)) { + else { + if (it.key()->getName() == "FrameExplorer") { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } - else - if (it.value()->widget() == Application::getViewer("PropertyExplorer")->getWidget()) { + else { + if (it.key()->getName() == "PropertyExplorer") { removeDockWidget(it.value()); addDockWidget(Qt::LeftDockWidgetArea, it.value()); it.value()->show(); } - else - if (it.value()->widget() == Application::getViewer("ActionViewer")->getWidget()) { + else { + if (it.key()->getName() == "ActionViewer") { removeDockWidget(it.value()); addDockWidget(Qt::RightDockWidgetArea, it.value()); it.value()->show(); } + } + } + } } - //Merge Explorer and FrameExplorer viewers in one layout + + // Merge Explorer and FrameExplorer viewers in one layout QDockWidget* dockWidgetExplorer = dockWidgetMap.value(Application::getViewer("Explorer"), NULL); QDockWidget* dockWidgetFrameExplorer = dockWidgetMap.value(Application::getViewer("FrameExplorer"), NULL); + if (dockWidgetExplorer && dockWidgetFrameExplorer) { tabifyDockWidget(dockWidgetExplorer, dockWidgetFrameExplorer); dockWidgetExplorer->raise(); @@ -481,8 +492,7 @@ void ImpMainWindow::openDirectory(QAction* emitter) { 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 + // this will therefore automatically delete the toggle central viewer's action viewMenu->clear(); // insert viewers menu @@ -494,43 +504,66 @@ void ImpMainWindow::updateViewMenu() { } } + viewMenu->addSeparator(); + + QMenu* toggleCentralWidgetMenu = viewMenu->addMenu(tr("Toggle Central Viewer")); + + // add an action for each viewer of layout "stacked" + foreach (Viewer* viewer, viewers) { + // only add viewer that are not docked + if (viewer->getLayout() == Viewer::STACKED) { + // viewerAction is own by viewMenu, viewMenu->clear() will delete it + QAction* viewerAction = toggleCentralWidgetMenu->addAction(viewer->getName()); + viewerAction->setCheckable(true); + viewerAction->setChecked(viewer == centralViewer); + QString tipString = "Hide/show the " + viewer->objectName() + " in the 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(viewer); + }); + } + } + + + /* // 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; + return v->getWidget() == cWidget; }); Viewer* cViewer = (*it); // viewerAction is own by viewMenu, viewMenu->clear() will delete it - QAction *viewerAction = viewMenu->addAction(cViewer->objectName()); + 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); + connect(viewerAction, &QAction::toggled, [ = ](bool) { + setCentralViewer(cViewer); }); } } + */ // insert viewers on/off actions - viewMenu->addSeparator()->setText(tr("Toggle Viewers")); - viewMenu->addAction(viewResetWindows); + QMenu* toggleDockedMenu = viewMenu->addMenu(tr("Toggle Docked Viewers")); + + toggleDockedMenu->addAction(viewResetWindows); for (QMap::iterator it = dockWidgetMap.begin(); it != dockWidgetMap.end(); it++) { - viewMenu->addAction(it.value()->toggleViewAction()); + toggleDockedMenu->addAction(it.value()->toggleViewAction()); } // insert generic on/off actions diff --git a/sdk/applications/imp/main.cpp b/sdk/applications/imp/main.cpp index 8da9c0a2..43aa03ff 100644 --- a/sdk/applications/imp/main.cpp +++ b/sdk/applications/imp/main.cpp @@ -109,7 +109,8 @@ int main(int argc, char* argv[]) { Application a("camitk-imp", argc, argv, true, true); // set the ImpMainWindow as the main window - a.setMainWindow(new ImpMainWindow()); + ImpMainWindow* impMainWindow = new ImpMainWindow(); + a.setMainWindow(impMainWindow); if (o.no_console()) { // force no redirection to console (to see error message if they occur) diff --git a/sdk/libraries/core/ExtensionManager.cpp b/sdk/libraries/core/ExtensionManager.cpp index 75a16bd2..36ca3cb3 100644 --- a/sdk/libraries/core/ExtensionManager.cpp +++ b/sdk/libraries/core/ExtensionManager.cpp @@ -45,21 +45,25 @@ namespace camitk { void ExtensionManager::autoload() { autoload(COMPONENT); autoload(ACTION); - autoload(VIEWER); + autoload(VIEWER); } void ExtensionManager::autoload(ExtensionManager::ExtensionType type) { QStringList extensionDir; + switch (type) { case ACTION: extensionDir = Core::getActionDirectories(); break; + case COMPONENT: extensionDir = Core::getComponentDirectories(); break; - case VIEWER: + + case VIEWER: extensionDir = Core::getViewerDirectories(); break; + default: CAMITK_TRACE_ALT(tr("autoload of unknown type: type should be either ACTION or COMPONENT or VIEWER, other extensions are not implemented yet")) break; @@ -69,11 +73,14 @@ void ExtensionManager::autoload(ExtensionManager::ExtensionType type) { QStringList extensionFileNames; QStringList extensionAbsoluteFileNames; QMap extensionUniqueDir; + foreach (QString dirName, extensionDir) { QDir dir(dirName); QStringList pluginFileNames = getPluginFileNames(dir); + foreach (QString pluginFile, pluginFileNames) { QString pluginAbsoluteFileName = dir.absoluteFilePath(pluginFile); + if (!extensionFileNames.contains(pluginFile)) { extensionFileNames.append(pluginFile); extensionUniqueDir.insert(pluginFile, dir); @@ -115,6 +122,7 @@ void ExtensionManager::autoload(ExtensionManager::ExtensionType type) { if (extensionAbsoluteFileNames.size() > 0) { // get the messages from Qt QStringList errorStrings; + foreach (QString fileName, extensionAbsoluteFileNames) { QPluginLoader pluginLoader(fileName); QObject* plugin = pluginLoader.instance(); @@ -146,19 +154,24 @@ void ExtensionManager::autoload(ExtensionManager::ExtensionType type) { QSettings& settings = Application::getSettings(); settings.beginGroup("UserExtensions"); QStringList userRegisteredExtensions; + switch (type) { case ACTION: userRegisteredExtensions = settings.value("actions", QVariant(QStringList())).toStringList(); break; + case COMPONENT: userRegisteredExtensions = settings.value("components", QVariant(QStringList())).toStringList(); break; - case VIEWER: - userRegisteredExtensions = settings.value("viewers", QVariant(QStringList())).toStringList(); - break; + + case VIEWER: + userRegisteredExtensions = settings.value("viewers", QVariant(QStringList())).toStringList(); + break; + default: break; } + settings.endGroup(); foreach (QString userRegisteredExtensionFile, userRegisteredExtensions) { @@ -180,6 +193,7 @@ bool ExtensionManager::loadExtension(ExtensionManager::ExtensionType type, QStri switch (type) { case ACTION: { ActionExtension* ext = qobject_cast (extension); + if (ext) { ext->setLocation(fileName); ext->initResources(); @@ -195,39 +209,40 @@ bool ExtensionManager::loadExtension(ExtensionManager::ExtensionType type, QStri } break; - case VIEWER: { - ViewerExtension* ext = qobject_cast (extension); - - if (ext) { - ext->setLocation(fileName); - ext->initResources(); - // initialize all viewers - ext->init(); - - int i = 0; - while (i < getViewerExtensionMap().size() && getViewerExtensionsList().at(i)->getViewerClassName() != ext->getViewerClassName()) { - i++; - } - - if (returnValue = (i >= getViewerExtensionMap().size())) { - //-- register the filename - getViewerExtensionMap().insert(fileName, ext); - //-- register all viewers - Application::registerAllViewers(ext); - } - else { - CAMITK_INFO_ALT(tr("Extension Manager: duplicate extension management: viewer extension \"%1\" (in file \"%2\") declares management of \"%3\" while \"%4\" extension (loaded from file \"%5\") is already managing \"%6\".\nUsing extension in \"%7\" instead (higher priority) as only one viewer extension can manage an instance of viewer.") - .arg(ext->getName(), - fileName, - ext->getViewerClassName(), - getViewerExtensionsList().at(i)->getName(), - getViewerExtensionsList().at(i)->getLocation(), - ext->getViewerClassName(), - getViewerExtensionsList().at(i)->getLocation())) - } - } - } - break; + case VIEWER: { + ViewerExtension* ext = qobject_cast (extension); + + if (ext) { + ext->setLocation(fileName); + ext->initResources(); + // initialize all viewers + ext->init(); + + int i = 0; + + while (i < getViewerExtensionMap().size() && getViewerExtensionsList().at(i)->getViewerClassName() != ext->getViewerClassName()) { + i++; + } + + if (returnValue = (i >= getViewerExtensionMap().size())) { + //-- register the filename + getViewerExtensionMap().insert(fileName, ext); + //-- register all viewers + Application::registerAllViewers(ext); + } + else { + CAMITK_INFO_ALT(tr("Extension Manager: duplicate extension management: viewer extension \"%1\" (in file \"%2\") declares management of \"%3\" while \"%4\" extension (loaded from file \"%5\") is already managing \"%6\".\nUsing extension in \"%7\" instead (higher priority) as only one viewer extension can manage an instance of viewer.") + .arg(ext->getName(), + fileName, + ext->getViewerClassName(), + getViewerExtensionsList().at(i)->getName(), + getViewerExtensionsList().at(i)->getLocation(), + ext->getViewerClassName(), + getViewerExtensionsList().at(i)->getLocation())) + } + } + } + break; case COMPONENT: { ComponentExtension* cp = qobject_cast (extension); @@ -248,6 +263,7 @@ bool ExtensionManager::loadExtension(ExtensionManager::ExtensionType type, QStri // (cannot do that in the constructor because the virtual symbol table seems to be confused!) foreach (QString ext, cp->getFileExtensions()) { ComponentExtension* existingComponentExtension = getComponentExtensionMap().value(ext); + if (existingComponentExtension != nullptr) { CAMITK_INFO_ALT(tr("Extension Manager: duplicate extension management: component extension \"%1\" (in file \"%2\") declares management of \"%3\" file extension while \"%4\" extension (loaded from file \"%5\") is already managing \"%6\".\nUsing extension in \"%7\" instead (higher priority) as only one component extension can manage a give file extension.") .arg(cp->getName(), @@ -285,6 +301,7 @@ bool ExtensionManager::loadExtension(ExtensionManager::ExtensionType type, QStri // try to load the missing shared object directly from private dir (give absolute path) QRegExp libname("\\((lib.*): cannot open shared object file"); + if (libname.indexIn(pluginLoader.errorString(), 0) != -1) { QString privateLibToLoad = Core::getGlobalInstallDir() + "/lib/" + QString(Core::shortVersion) + "/" + libname.cap(1); QLibrary privateLib(privateLibToLoad); @@ -307,18 +324,22 @@ QString ExtensionManager::getInstallationString(QString file, const QString& glo dir.cdUp(); QString absolutePath = dir.absolutePath(); + if (absolutePath == currentWorkingDir) { whichInstallDir = "[W]"; } - else if (absolutePath == userInstallDir) { - whichInstallDir = "[L]"; - } - else if (absolutePath == globalInstallDir) { - whichInstallDir = "[G]"; - } - else { - whichInstallDir = "[U]"; - } + else + if (absolutePath == userInstallDir) { + whichInstallDir = "[L]"; + } + else + if (absolutePath == globalInstallDir) { + whichInstallDir = "[G]"; + } + else { + whichInstallDir = "[U]"; + } + return whichInstallDir; } @@ -422,55 +443,53 @@ void ExtensionManager::unloadAllActionExtensions() { } // -------------------- getViewerExtensionMap -------------------- -QMap& camitk::ExtensionManager::getViewerExtensionMap() -{ - static QMap viewerExtensionMap; +QMap& camitk::ExtensionManager::getViewerExtensionMap() { + static QMap viewerExtensionMap; - return viewerExtensionMap; + return viewerExtensionMap; } // -------------------- unloadAllViewerExtensions -------------------- -void camitk::ExtensionManager::unloadAllViewerExtensions() -{ - QList allExtensions = getViewerExtensionMap().keys(); +void camitk::ExtensionManager::unloadAllViewerExtensions() { + QList allExtensions = getViewerExtensionMap().keys(); - while (!allExtensions.isEmpty()) { - unloadViewerExtension(allExtensions.takeFirst()); - } + while (!allExtensions.isEmpty()) { + unloadViewerExtension(allExtensions.takeFirst()); + } } -const QList camitk::ExtensionManager::getViewerExtensionsList() -{ - QList< ViewerExtension* > sortedList = getViewerExtensionMap().values().toSet().toList(); // to remove duplicates - qSort(sortedList.begin(), sortedList.end(), ExtensionManager::viewerExtensionLessThan); +const QList camitk::ExtensionManager::getViewerExtensionsList() { + QList< ViewerExtension* > sortedList = getViewerExtensionMap().values().toSet().toList(); // to remove duplicates + qSort(sortedList.begin(), sortedList.end(), ExtensionManager::viewerExtensionLessThan); - return sortedList; + return sortedList; } -ViewerExtension * camitk::ExtensionManager::getViewerExtension(QString file) -{ - return getViewerExtensionMap().value(file); +ViewerExtension* camitk::ExtensionManager::getViewerExtension(QString file) { + return getViewerExtensionMap().value(file); } // -------------------- unloadViewerExtension -------------------- bool ExtensionManager::unloadViewerExtension(QString fileName) { - if (getViewerExtensionMap().contains(fileName)) { - ViewerExtension* ext = getViewerExtensionMap().value(fileName); - //-- unregister all actions - foreach(Viewer* viewer, ext->getViewers()) { - getViewerExtensionMap().remove(viewer->getName()); - } - //-- unregister extension - getViewerExtensionMap().remove(fileName); - // -- unregister actions from application - Application::unregisterAllViewers(ext); - //-- delete extensions (and all its actions) - delete ext; - return true; - } - else { - return false; - } + if (getViewerExtensionMap().contains(fileName)) { + ViewerExtension* ext = getViewerExtensionMap().value(fileName); + + //-- unregister all actions + foreach (Viewer* viewer, ext->getViewers()) { + getViewerExtensionMap().remove(viewer->getName()); + } + + //-- unregister extension + getViewerExtensionMap().remove(fileName); + // -- unregister actions from application + Application::unregisterAllViewers(ext); + //-- delete extensions (and all its actions) + delete ext; + return true; + } + else { + return false; + } } // -------------------- registerFileExtension -------------------- @@ -509,12 +528,14 @@ QStringList ExtensionManager::getExtensionFilter() { QStringList pluginFilter; // linux: .so, windows: .dll, macOs: .dylib pluginFilter << "*.so." + QString(Core::soVersion) << "*." + QString(Core::soVersion) + ".dylib"; + if (Core::isDebugBuild()) { pluginFilter << "*" + QString(Core::debugPostfix) + ".dll"; } else { pluginFilter << "*.dll"; } + return pluginFilter; } @@ -536,8 +557,10 @@ QStringList ExtensionManager::getPluginFileNames(QDir extensionsDir) { foreach (QString debugDLL, pluginFileNamesDebugMSVC) { pluginFileNames.removeAll(debugDLL); } + return pluginFileNames; } + #endif return pluginFileNames; @@ -548,10 +571,12 @@ QStringList ExtensionManager::getPluginFileNames(QDir extensionsDir) { bool ExtensionManager::unloadActionExtension(QString fileName) { if (getActionExtensionMap().contains(fileName)) { ActionExtension* ext = getActionExtensionMap().value(fileName); + //-- unregister all actions foreach (Action* action, ext->getActions()) { getActionExtensionMap().remove(action->getName()); } + //-- unregister extension getActionExtensionMap().remove(fileName); // -- unregister actions from application @@ -628,6 +653,7 @@ void ExtensionManager::initPrivateLibDirs() { if (!alreadyInitialized) { // Build directory QDir privateBuildLibDir(Core::getCurrentWorkingDir()); + if (privateBuildLibDir.cd("lib/" + QString(Core::shortVersion))) { QByteArray privateBuildLibDirPath = privateBuildLibDir.canonicalPath().toUtf8(); #ifdef WIN32 // for Windows @@ -638,19 +664,20 @@ void ExtensionManager::initPrivateLibDirs() { path.append(privateBuildLibDirPath + "/actions"); path.append(";"); path.append(privateBuildLibDirPath + "/components"); - path.append(";"); - path.append(privateBuildLibDirPath + "/viewers"); + path.append(";"); + path.append(privateBuildLibDirPath + "/viewers"); qputenv("PATH", path); #endif // update the application / qt plugins library path Application::instance()->addLibraryPath(privateBuildLibDirPath); Application::instance()->addLibraryPath(privateBuildLibDirPath + "/actions"); Application::instance()->addLibraryPath(privateBuildLibDirPath + "/components"); - Application::instance()->addLibraryPath(privateBuildLibDirPath + "/viewers"); + Application::instance()->addLibraryPath(privateBuildLibDirPath + "/viewers"); } // Local install directory QDir privateLocalLibDir(Core::getUserInstallDir()); + if (privateLocalLibDir.cd("lib/" + QString(Core::shortVersion))) { QByteArray privateLocalLibDirPath = privateLocalLibDir.canonicalPath().toUtf8(); #ifdef WIN32 // for Windows @@ -661,19 +688,20 @@ void ExtensionManager::initPrivateLibDirs() { path.append(privateLocalLibDirPath + "/actions"); path.append(";"); path.append(privateLocalLibDirPath + "/components"); - path.append(";"); - path.append(privateLocalLibDirPath + "/viewers"); + path.append(";"); + path.append(privateLocalLibDirPath + "/viewers"); qputenv("PATH", path); #endif // update the application / qt plugins library path Application::instance()->addLibraryPath(privateLocalLibDirPath); Application::instance()->addLibraryPath(privateLocalLibDirPath + "/actions"); Application::instance()->addLibraryPath(privateLocalLibDirPath + "/components"); - Application::instance()->addLibraryPath(privateLocalLibDirPath + "/viewers"); + Application::instance()->addLibraryPath(privateLocalLibDirPath + "/viewers"); } // Global install directory QDir privateGlobalLibDir(Core::getGlobalInstallDir()); + if (privateGlobalLibDir.cd("lib/" + QString(Core::shortVersion))) { QByteArray privateGlobalLibDirPath = privateGlobalLibDir.canonicalPath().toUtf8(); #ifdef WIN32 // for Windows @@ -684,16 +712,17 @@ void ExtensionManager::initPrivateLibDirs() { path.append(privateGlobalLibDirPath + "/actions"); path.append(";"); path.append(privateGlobalLibDirPath + "/components"); - path.append(";"); - path.append(privateGlobalLibDirPath + "/viewers"); + path.append(";"); + path.append(privateGlobalLibDirPath + "/viewers"); qputenv("PATH", path); #endif // update the application / qt plugins library path Application::instance()->addLibraryPath(privateGlobalLibDirPath); Application::instance()->addLibraryPath(privateGlobalLibDirPath + "/actions"); Application::instance()->addLibraryPath(privateGlobalLibDirPath + "/components"); - Application::instance()->addLibraryPath(privateGlobalLibDirPath + "/viewers"); + Application::instance()->addLibraryPath(privateGlobalLibDirPath + "/viewers"); } + alreadyInitialized = true; } } @@ -710,7 +739,7 @@ bool ExtensionManager::actionExtensionLessThan(ActionExtension* left, ActionExte // -------------------- viewerExtensionLessThan -------------------- bool ExtensionManager::viewerExtensionLessThan(ViewerExtension* left, ViewerExtension* right) { - return left->getName() < right->getName(); + return left->getName() < right->getName(); } } diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index 20dca4e4..d0877809 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -53,6 +53,7 @@ Action::~Action() { foreach (Property* prop, parameterMap.values()) { delete prop; } + parameterMap.clear(); //delete History item @@ -64,26 +65,33 @@ Action::~Action() { // -------------------- getStatusAsString -------------------- QString Action::getStatusAsString(ApplyStatus status) { QString statusStr; + switch (status) { case Action::ABORTED: statusStr = "ABORTED"; break; + case Action::ERROR: statusStr = "ERROR"; break; + case Action::SUCCESS: statusStr = "SUCCESS"; break; + case Action::TRIGGERED: statusStr = "TRIGGERED"; break; + case Action::WARNING: statusStr = "WARNING"; break; + default: statusStr = "UNKNOWN"; break; } + return statusStr; } @@ -187,10 +195,10 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { //-- if there are some valid targets or if the action is generic if (targetComponents.size() > 0 || getComponent().isEmpty()) { if (isEmbedded) { - // if there are no parents, use the action viewer if (parent == nullptr) { - Application::setSelectedAction(this); - Application::getViewer("ActionViewer")->refresh(); + // tell the application this action is ready to show its widget, so that + // any viewer that wants to show something about it is refreshed + Application::setSelectedAction(this); } else { getWidget()->setParent(parent); @@ -268,6 +276,7 @@ Action::ApplyStatus Action::applyInPipeline() { void Action::setInputComponents(ComponentList inputs) { //-- build the list of valid targets targetComponents.clear(); + foreach (Component* comp, inputs) { // check compatibility if (comp->isInstanceOf(this->getComponent())) { @@ -316,6 +325,7 @@ void Action::preProcess() { // We will select the one selected as input of the current action this->topLevelSelectedComponents.clear(); QList topLevelSelectedHistoryComponents; + foreach (Component* comp, this->aliveBeforeComponents) { if (comp->isSelected()) { this->topLevelSelectedComponents.append(comp); @@ -342,6 +352,7 @@ void Action::postProcess() { ComponentList topLevelComponentCreated; QList topLevelHistoryComponentCreated; topLevelHistoryComponentCreated.clear(); + foreach (Component* comp, Application::getTopLevelComponents()) { if (!this->aliveBeforeComponents.contains(comp)) { topLevelComponentCreated.append(comp); @@ -367,6 +378,7 @@ void Action::postProcess() { void Action::postProcessInPipeline() { outputComponents.clear(); ComponentList allComp = Application::getAllComponents(); + foreach (Component* comp, allComp) { if (!aliveBeforeComponents.contains(comp) || comp->getModified()) { outputComponents.append(comp); @@ -382,6 +394,7 @@ bool Action::getAutoUpdateProperties() const { // -------------------- setAutoUpdateProperties -------------------- void Action::setAutoUpdateProperties(bool autoUpdateProperties) { this->autoUpdateProperties = autoUpdateProperties; + if (actionWidget) { dynamic_cast(actionWidget)->setAutoUpdateProperty(autoUpdateProperties); } @@ -413,10 +426,12 @@ void Action::applyTargetPosition(Component* input, Component* target, Applicatio case Application::NO_TRANSFORMATION: target->setParentFrame(nullptr); break; + case Application::SUBFRAME: target->setParentFrame(nullptr); // reset the frame transform to Identity target->setParentFrame(input); break; + case Application::SAME_TRANSFORMATION: default: target->setParentFrame(nullptr); @@ -440,3 +455,5 @@ void Action::applyTargetPosition(Component* input, Component* target, Applicatio + + diff --git a/sdk/libraries/core/action/ActionExtension.cpp b/sdk/libraries/core/action/ActionExtension.cpp index e257f8c0..1875c6d4 100644 --- a/sdk/libraries/core/action/ActionExtension.cpp +++ b/sdk/libraries/core/action/ActionExtension.cpp @@ -35,6 +35,38 @@ namespace camitk { +// -------------------- constructor -------------------- +ActionExtension::ActionExtension() { + translator = nullptr; +} + +// -------------------- destructor -------------------- +ActionExtension::~ActionExtension() { + while (!actions.empty()) { + Action* toDelete = actions.takeFirst(); + + // do not delete the "Quit" action: it is the action that triggers this delete! + if (toDelete->getName() != "Quit") { + delete toDelete; + } + } + + //delete internationalization instance + if (translator) { + delete translator; + } +} + +// -------------------- setLocation -------------------- +void ActionExtension::setLocation(const QString loc) { + dynamicLibraryFileName = loc; +} + +// -------------------- getLocation -------------------- +QString ActionExtension::getLocation() const { + return dynamicLibraryFileName; +} + // -------------------- initResources -------------------- void ActionExtension::initResources() { // Get the selected language @@ -47,6 +79,7 @@ void ActionExtension::initResources() { actionExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib"); QString languageFile = ":/translate_" + actionExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm"; translator = new QTranslator(); + if (translator->load(languageFile)) { QCoreApplication::installTranslator(translator); } @@ -56,22 +89,6 @@ void ActionExtension::initResources() { } } -// -------------------- destructor -------------------- -ActionExtension::~ActionExtension() { - while (!actions.empty()) { - Action* toDelete = actions.takeFirst(); - // do not delete the "Quit" action: it is the action that triggers this delete! - if (toDelete->getName() != "Quit") { - delete toDelete; - } - } - - //delete internationalization instance - if (translator) { - delete translator; - } -} - // -------------------- registerAction -------------------- void ActionExtension::registerAction(Action* action) { // simply add the action in the list diff --git a/sdk/libraries/core/action/ActionExtension.h b/sdk/libraries/core/action/ActionExtension.h index f3703595..40ba10d2 100644 --- a/sdk/libraries/core/action/ActionExtension.h +++ b/sdk/libraries/core/action/ActionExtension.h @@ -60,7 +60,7 @@ class CAMITK_API ActionExtension : public QObject { protected : /// constructor - ActionExtension() {}; + ActionExtension(); public : /// destructor @@ -79,14 +79,10 @@ public : const ActionList& getActions(); /// set the file path (once loaded as a dynamic library) - void setLocation(const QString loc) { - dynamicLibraryFileName = loc; - } + void setLocation(const QString loc); /// get the file path (location of the .dll/.so/.dylib) of this plugin - QString getLocation() const { - return dynamicLibraryFileName; - } + QString getLocation() const; /// Load, for the selected langage (asked to the Application), the associated .qm file void initResources(); @@ -103,7 +99,7 @@ private: QString dynamicLibraryFileName; /// Provide internationalization support for text output. - QTranslator* translator{nullptr}; + QTranslator* translator; }; } diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index b29fc691..b00d2edf 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -222,6 +222,7 @@ void Application::quitting() { bool Application::notify(QObject* receiver, QEvent* event) { bool done = true; std::exception_ptr otherException; + try { done = QApplication::notify(receiver, event); } @@ -231,6 +232,7 @@ bool Application::notify(QObject* receiver, QEvent* event) { catch (...) { CAMITK_ERROR(tr("Caught an unknown exception")) otherException = std::current_exception(); + try { if (otherException) { std::rethrow_exception(otherException); @@ -292,8 +294,11 @@ void Application::setMainWindow(MainWindow* mw) { // ----------------- getMainWindow -------------------- MainWindow* Application::getMainWindow() { - if (!mainWindow) { + if (mainWindow == nullptr) { + // this is the first time getMainWindow() is called and no MainWindow were created + // In this case, force the creation of a default MainWindow by sending nullptr dynamic_cast(qApp)->setMainWindow(nullptr); + // and then returns it } return mainWindow; @@ -512,6 +517,7 @@ Component* Application::open(const QString& fileName) { // try harder otherException = std::current_exception(); + try { if (otherException) { std::rethrow_exception(otherException); @@ -541,6 +547,7 @@ Component* Application::openDirectory(const QString& dirName, const QString& plu if (cp != nullptr) { std::exception_ptr otherException; + // Ask the plugin instance to create the Component instance try { comp = cp->open(QDir(dirName).absolutePath()); @@ -573,6 +580,7 @@ Component* Application::openDirectory(const QString& dirName, const QString& plu // try harder otherException = std::current_exception(); + try { if (otherException) { std::rethrow_exception(otherException); @@ -752,11 +760,11 @@ bool actionLessThan(const camitk::Action* a1, const camitk::Action* a2) { return a1->getName() < a2->getName(); } -// ---------------- viewerLessThan ---------------- -bool viewerLessThan(const camitk::Viewer* v1, const camitk::Viewer* v2) { - // This method is needed by qsort in the sort method to sort viewer by name - return v1->getName() < v2->getName(); -} +// ---------------- viewerLessThan ---------------- +bool viewerLessThan(const camitk::Viewer* v1, const camitk::Viewer* v2) { + // This method is needed by qsort in the sort method to sort viewer by name + return v1->getName() < v2->getName(); +} // ---------------- sort ---------------- @@ -768,14 +776,13 @@ ActionList Application::sort(ActionSet actionSet) { return actionList; } -ViewerList Application::sort(ViewerSet viewerSet) -{ - // sort actions by name - ViewerList viewerList = viewerSet.toList(); - qSort(viewerList.begin(), viewerList.end(), viewerLessThan); - - return viewerList; -} +ViewerList Application::sort(ViewerSet viewerSet) { + // sort actions by name + ViewerList viewerList = viewerSet.toList(); + qSort(viewerList.begin(), viewerList.end(), viewerLessThan); + + return viewerList; +} // ---------------- getAction ---------------- @@ -846,90 +853,98 @@ ActionList Application::getActions(ComponentList selComp, QString tag) { // -------------------- getViewerMap -------------------- QMap& Application::getViewerMap() { - static QMap viewerMap; + static QMap viewerMap; - return viewerMap; + return viewerMap; } -Viewer* Application::getViewer(QString name) -{ - return getViewerMap().value(name); +// -------------------- getViewer -------------------- +Viewer* Application::getViewer(QString name) { + return getViewerMap().value(name); } // -------------------- registerAllViewers -------------------- int Application::registerAllViewers(ViewerExtension* ext) { - int registered = 0; - - for(Viewer* viewer : ext->getViewers()) { - // check if an action with same name was not already registered - if (getViewerMap().contains(viewer->getName())) { - - ViewerExtension* extension = getViewerExtension(viewer); - - QString extensionName = ""; - if (extension != nullptr) { - extensionName = extension->getName(); - } - - CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" - "viewer of same name already registered in extension %3") - .arg(viewer->getName(), viewer->getDescription(), extensionName)) - } - else { - getViewerMap().insert(viewer->getName(), viewer); - registered++; - } - } - - return registered; -} - -ViewerList Application::getViewers(Component *component) -{ - ViewerSet viewers; - - if (component) { - QStringList componentHierarchy = component->getHierarchy(); - - foreach(Viewer* currentViewer, Application::getViewers()) { - foreach(QString compType, currentViewer->getComponents()) { - if (componentHierarchy.contains(compType)) { - viewers.insert(currentViewer); - } - } - } - } - else { - foreach(Viewer* currentViewer, Application::getViewers()) { - foreach(QString compType, currentViewer->getComponents()) { - if (compType.isEmpty()) { - viewers.insert(currentViewer); - } - } - } - } - - return sort(viewers); -} + int registered = 0; + // register all the viewer instances in this extension + for (Viewer* viewer : ext->getViewers()) { + // first check if a viewer with the same name is not already registered + if (getViewerMap().contains(viewer->getName())) { + // if it is register, find out more information about the viewer extension + // that manages the already registered viewer + QString extensionName = ""; + ViewerExtension* extension = getViewerExtension(viewer); + + if (extension != nullptr) { + extensionName = extension->getName(); + CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" + "viewer of same name already registered in extension %3") + .arg(viewer->getName(), viewer->getDescription(), extensionName)) + } + else { + // should never happen + CAMITK_ERROR_ALT(tr("Cannot register viewer: %1 (description: \"%2\")\n" + "viewer of same name already registered in an unknown extension...") + .arg(viewer->getName(), viewer->getDescription())) + } + } + else { + // everythis is alright register the viewer + getViewerMap().insert(viewer->getName(), viewer); + registered++; + } + } + + return registered; +} + +// -------------------- getViewers -------------------- +ViewerList Application::getViewers(Component* component) { + ViewerSet viewers; + + if (component) { + QStringList componentHierarchy = component->getHierarchy(); + foreach (Viewer* currentViewer, Application::getViewers()) { + foreach (QString compType, currentViewer->getComponents()) { + if (componentHierarchy.contains(compType)) { + viewers.insert(currentViewer); + } + } + } + } + else { + foreach (Viewer* currentViewer, Application::getViewers()) { + foreach (QString compType, currentViewer->getComponents()) { + if (compType.isEmpty()) { + viewers.insert(currentViewer); + } + } + } + } + + return sort(viewers); +} + +// -------------------- getNewViewer -------------------- Viewer* Application::getNewViewer(QString name, QString className) { - int i = 0; - QList vl = ExtensionManager::getViewerExtensionsList(); + int i = 0; + QList vl = ExtensionManager::getViewerExtensionsList(); - while (i < vl.size() && vl.at(i)->getViewerClassName() != className) { - i++; - } + while (i < vl.size() && vl.at(i)->getViewerClassName() != className) { + i++; + } - if (i < vl.size()) { - ViewerExtension* ve = vl.at(i); - return ve->getNewInstance(name); - } - else { - CAMITK_ERROR_ALT(tr("No extension manage viewer of type %1\n").arg(className)) - return nullptr; - } + if (i < vl.size()) { + ViewerExtension* ve = vl.at(i); + return ve->getNewInstance(name); + } + else { + CAMITK_ERROR_ALT(tr("No extension manage viewer manages the viewers of type \"%1\"\n").arg(className)) + return nullptr; + } } // -------------------- getViewers -------------------- @@ -939,35 +954,39 @@ const ViewerList Application::getViewers() { // -------------------- unregisterAllViewers -------------------- int Application::unregisterAllViewers(ViewerExtension* ext) { - int unregistered = 0; + int unregistered = 0; - foreach(Viewer* viewer, ext->getViewers()) { - getViewerMap().remove(viewer->getName()); - unregistered++; - } + foreach (Viewer* viewer, ext->getViewers()) { + getViewerMap().remove(viewer->getName()); + unregistered++; + } - return unregistered; + return unregistered; } +// -------------------- getViewerExtension -------------------- ViewerExtension* Application::getViewerExtension(Viewer* viewer) { - int i = 0; - bool found = false; - ViewerExtension* extension = nullptr; - while (i < ExtensionManager::getViewerExtensionsList().size() && !found) { - int j = 0; - while (j < ExtensionManager::getViewerExtensionsList().at(i)->getViewers().size() && !found) { - found = (ExtensionManager::getViewerExtensionsList().at(i)->getViewers().at(j)->getName() == viewer->getName()); - j++; - } - i++; - } + int i = 0; + bool found = false; + ViewerExtension* extension = nullptr; + + while (i < ExtensionManager::getViewerExtensionsList().size() && !found) { + int j = 0; + + while (j < ExtensionManager::getViewerExtensionsList().at(i)->getViewers().size() && !found) { + found = (ExtensionManager::getViewerExtensionsList().at(i)->getViewers().at(j)->getName() == viewer->getName()); + j++; + } - if (found) { - extension = ExtensionManager::getViewerExtensionsList().at(i-1); - } + i++; + } + + if (found) { + extension = ExtensionManager::getViewerExtensionsList().at(i - 1); + } - return extension; + return extension; } // ---------- isAlive ---------- @@ -1041,16 +1060,6 @@ const ComponentList& Application::getSelectedComponents() { return getSelectedComponentList(); } -void Application::setSelectedAction(Action * action) -{ - currentAction = action; -} - -Action* Application::getSelectedAction() -{ - return currentAction; -} - // -------------------- setSelected -------------------- void Application::setSelected(Component* component, bool isSelected) { // in case the component is selected again, put it in the end @@ -1073,6 +1082,25 @@ void Application::clearSelectedComponents() { getSelectedComponentList().clear(); } +// -------------------- setSelectedAction -------------------- +void Application::setSelectedAction(Action* action) { + currentAction = action; + // check all the registered viewers and refresh all the viewers + // that do not act on Components... (if they do not visualize component + // they might be interested by a change of the currently selected action + foreach (Viewer* v, getViewers()) { + if (v->getComponents().isEmpty()) { + CAMITK_INFO_ALT(tr("Refreshing \"%1\"").arg(v->getName())) + v->refresh(); + } + } +} + +// -------------------- getSelectedAction -------------------- +Action* Application::getSelectedAction() { + return currentAction; +} + // -------------------- getHistory -------------------- QStack& Application::getHistory() { // static singleton declaration @@ -1170,6 +1198,7 @@ void Application::saveHistoryAsSXML() { // action parameters QDomElement parametersElement = doc.createElement("camitk:parameters"); actionElement.appendChild(parametersElement); + if (!action->dynamicPropertyNames().isEmpty()) { foreach (QByteArray actionParameter, action->dynamicPropertyNames()) { @@ -1444,8 +1473,9 @@ void Application::createProperties() { property->setEnumTypeName("LogLevel"); // Set a custom list of GUI names QStringList enumGuiText; + for (const InterfaceLogger::LogLevel l : { - InterfaceLogger::NONE, InterfaceLogger::ERROR, InterfaceLogger::WARNING, InterfaceLogger::INFO, InterfaceLogger::TRACE + InterfaceLogger::NONE, InterfaceLogger::ERROR, InterfaceLogger::WARNING, InterfaceLogger::INFO, InterfaceLogger::TRACE }) { enumGuiText << Log::getLevelAsString(l); } diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index a727a641..b7238344 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -270,7 +270,7 @@ public: /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); - /// get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) + /// get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) static ViewerList getViewers(Component*); /** register all viewers from the given ViewerExtension @@ -301,6 +301,9 @@ public: void setMainWindow(MainWindow* mw); /// get the main window + /// \note if there is no MainWindow when this method is first called, + /// then this method makes sure there is a MainWindow by and force the creation of + /// a default MainWindow (direct instance of the MainWindow class) static MainWindow* getMainWindow(); /// refresh the main window (this will call the refresh method of all viewers) @@ -522,7 +525,7 @@ private: ///@} /// sort an ViewerSet by viewer's name - static ViewerList sort(ViewerSet); + static ViewerList sort(ViewerSet); ///@} /// @name viewer management diff --git a/sdk/libraries/core/application/MainWindow.cpp b/sdk/libraries/core/application/MainWindow.cpp index fc0bf12b..add81e0e 100644 --- a/sdk/libraries/core/application/MainWindow.cpp +++ b/sdk/libraries/core/application/MainWindow.cpp @@ -57,7 +57,6 @@ MainWindow::MainWindow(QString title) { setWindowIcon(QIcon(":/camiTKIcon")); // prepare GUI - centralViewer = nullptr; showStatusBar(false); // add permanent widget to the status bar (toggle console and progress bar) @@ -67,6 +66,7 @@ MainWindow::MainWindow(QString title) { // if actions are available, add a toggle console Action* toggleAction = Application::getAction("Toggle Log Console"); + if (toggleAction) { auto* toggleConsole = new QToolBar(); @@ -88,23 +88,29 @@ MainWindow::MainWindow(QString title) { Ui::ui_Console ui; ui.setupUi(consoleWindow); + switch (Log::getLogger()->getLogLevel()) { case InterfaceLogger::ERROR: ui.errorLogLevelButton->setChecked(true); break; + case InterfaceLogger::WARNING: ui.warningLogLevelButton->setChecked(true); break; + case InterfaceLogger::INFO: ui.infoLogLevelButton->setChecked(true); break; + case InterfaceLogger::TRACE: ui.traceLogLevelButton->setChecked(true); break; + default: ui.noneLogLevelButton->setChecked(true); break; } + ui.toggleDebug->setChecked(Log::getLogger()->getDebugInformation()); ui.toggleTimestamp->setChecked(Log::getLogger()->getTimeStampInformation()); @@ -155,6 +161,12 @@ MainWindow::MainWindow(QString title) { consoleWindow->hide(); addDockWidget(Qt::BottomDockWidgetArea, consoleWindow); + // create the default (empty) central widget inside which the central viewers can be added + centralWidget = new QStackedWidget(this); + centralWidget->setObjectName("MainWindow Central Widget"); + setCentralWidget(centralWidget); + centralViewer = nullptr; + // accept drag and drop events setAcceptDrops(true); @@ -221,8 +233,9 @@ void MainWindow::showViewer(Viewer* theViewer, bool visible) { void MainWindow::showViewerToolbar(Viewer* theViewer, bool visible) { if (theViewer == nullptr) return; - + QToolBar* viewerToolBar = theViewer->getToolBar(); + if (viewerToolBar != nullptr) { if (visible && theViewer->getToolBarVisibility()) { addToolBar(viewerToolBar); @@ -240,6 +253,7 @@ void MainWindow::refreshViewers() { foreach (Viewer* v, viewers) { v->refresh(); } + // update the central viewer toolbar visibility showViewerToolbar(centralViewer, true); } @@ -248,19 +262,18 @@ void MainWindow::refreshViewers() { void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer) { if (addViewer(theViewer)) { // 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); + QDockWidget* viewerDock = theViewer->dockIn(); + + if (viewerDock) { + // add the dock addDockWidget(dockingArea, viewerDock); - + // update the map dockWidgetMap.insert(theViewer, viewerDock); } } + // show the viewer anyway showDockViewer(theViewer, true); } @@ -268,44 +281,48 @@ void MainWindow::addDockViewer(Qt::DockWidgetArea dockingArea, Viewer* theViewer // ------------- setCentralViewer ----------------- void MainWindow::setCentralViewer(Viewer* theViewer) { - // 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)); - } - 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); + addViewer(theViewer); + + // unstack the previous widget + if (centralViewer != nullptr) { + // hide the previous toolbar + showViewerToolbar(centralViewer, false); } + + // update the pointer + centralViewer = theViewer; + + // stack the viewer inside the central viewer + centralViewer->stackIn(centralWidget); + + // show its toolbar + showViewerToolbar(centralViewer, true); + + // save current central viewer in the settings (only if the central widget is visible + if (centralWidget->isVisible()) { + QSettings& settings = Application::getSettings(); + settings.beginGroup(Application::getName() + ".MainWindow"); + settings.setValue("centralViewer", centralViewer->getName()); + settings.endGroup(); + } + } // ------------- getCentralViewer ----------------- -const Viewer& MainWindow::getCentralViewer() const { - return *centralViewer; +Viewer* MainWindow::getCentralViewer() const { + return centralViewer; } // ------------- refresh ----------------- void MainWindow::refresh() { Viewer* whoIsAsking = qobject_cast (sender()); + foreach (Viewer* v, viewers) { if (v != whoIsAsking) { v->refresh(); } } + // update the central viewer toolbar visibility showViewerToolbar(centralViewer, true); } @@ -359,6 +376,7 @@ void MainWindow::show() { // update the log console toggle state (if actions are available) Action* toggleAction = Application::getAction("Toggle Log Console"); + if (toggleAction) { toggleAction->getQAction()->setChecked(consoleWindow->isVisible()); } @@ -375,14 +393,26 @@ void MainWindow::initSettings() { settings.beginGroup(Application::getName() + ".MainWindow"); restoreState(settings.value("windowState").toByteArray()); QRect geom = settings.value("geometry", QRect(8, 30, 1024, 768)).toRect(); + // ensure ok size for non-compliant window managers if (geom.width() <= 0) { geom.setWidth(1024); } + if (geom.height() <= 0) { geom.setHeight(768); } + setGeometry(geom); + + // get central viewer + QString centralViewerName = settings.value("centralViewer", "").toString(); + CAMITK_INFO(tr("Found %1").arg(centralViewerName)) + + if (centralViewerName != "") { + setCentralViewer(Application::getViewer(centralViewerName)); + } + settings.endGroup(); } diff --git a/sdk/libraries/core/application/MainWindow.h b/sdk/libraries/core/application/MainWindow.h index ae70e888..a58ae44c 100644 --- a/sdk/libraries/core/application/MainWindow.h +++ b/sdk/libraries/core/application/MainWindow.h @@ -38,7 +38,7 @@ #include #include #include - +#include namespace camitk { @@ -167,7 +167,7 @@ public: /** * @return the current central viewer. */ - virtual const Viewer& getCentralViewer() const; + virtual Viewer* getCentralViewer() const; /** Set the visibility of a viewer's toolbar. * This method respect the toolbar visibility property of the viewer. @@ -268,6 +268,9 @@ private: /// the main part of the title QString mainTitle; + /// the central widget is a QStackedWidget + QStackedWidget* centralWidget; + }; } diff --git a/sdk/libraries/core/component/Component.cpp b/sdk/libraries/core/component/Component.cpp index 5b36f3a7..87d4b25f 100644 --- a/sdk/libraries/core/component/Component.cpp +++ b/sdk/libraries/core/component/Component.cpp @@ -54,6 +54,7 @@ Component::Component(Component* parentComponent, const QString& n, Representatio if (myParentNode == nullptr) { throw AbortException(tr("Inconsistency: cannot instantiate a sub component with a null parent, please use the parent component pointer as the first parameter of the constructor or use the top-level Component constructor.").toStdString()); } + init(); myFileName = n; // register as a parent child @@ -80,17 +81,20 @@ Component::~Component() { if (myGeometry) { delete myGeometry; } + myGeometry = nullptr; if (mySlice) { delete mySlice; } + mySlice = nullptr; // delete Frame if (myFrame) { delete myFrame; } + myFrame = nullptr; // remove from selection @@ -102,6 +106,7 @@ Component::~Component() { foreach (Property* prop, propertyMap.values()) { delete prop; } + propertyMap.clear(); CAMITK_TRACE(tr("Deleted")) @@ -151,12 +156,15 @@ bool Component::isInstanceOf(QString className) const { QStringList Component::getHierarchy() const { const QMetaObject* qmetaObject = metaObject(); QStringList classnameList; + while (qmetaObject && !QString(qmetaObject->className()).contains("InterfaceProperty")) { classnameList.append(QString(qmetaObject->className()).remove(0, QString(qmetaObject->className()).lastIndexOf(':') + 1)); + if (qmetaObject->superClass()) { qmetaObject = qmetaObject->superClass(); } } + return classnameList; } @@ -252,6 +260,7 @@ Component* Component::getTopLevelComponent() { // -------------------- setVisibility -------------------- void Component::setVisibility(Viewer* v, bool b) { QMap::iterator it = myViewers.find(v); + if (it == myViewers.end()) { // insert the new viewer with the corresponding boolean myViewers.insert(v, b); @@ -264,6 +273,7 @@ void Component::setVisibility(Viewer* v, bool b) { // -------------------- getVisibility -------------------- bool Component::getVisibility(Viewer* v) const { QMap::const_iterator it = myViewers.constFind(v); + if (it == myViewers.end()) { return false; } @@ -295,6 +305,7 @@ void Component::refreshInterfaceNode() { // -------------------- getService -------------------- Component::Representation Component::getRepresentation() const { static bool checked = false; // only check once for each Component + if (!checked) { checked = true; QString representationString; @@ -309,19 +320,23 @@ Component::Representation Component::getRepresentation() const { shouldInstantiateMember = "myGeometry"; instantiationError = (myGeometry == nullptr); break; + case SLICE: representationString = "SLICE"; shouldInstantiateMember = "mySlice"; instantiationError = (mySlice == nullptr); break; + case NO_REPRESENTATION: instantiatedMember = (myGeometry != nullptr) ? "myGeometry" : (mySlice != nullptr) ? "mySlice" : "<>"; instantiationError = (mySlice != nullptr || myGeometry != nullptr); break; } + if (instantiationError) { const QMetaObject* qmetaObject = metaObject(); QString classname = qmetaObject->className(); + if (myService != NO_REPRESENTATION) { // the Component has to instantiate CAMITK_ERROR(tr("Component class \"%1\" implements service %2 but does not instantiate it!\n" @@ -333,6 +348,7 @@ Component::Representation Component::getRepresentation() const { } } } + return myService; } @@ -348,12 +364,15 @@ QMenu* Component::getActionMenu() { //-- add all actions sorted by family ActionList allActions = Application::getActions(this); QMap familyMap; + foreach (Action* action, allActions) { ActionSet* familySet = familyMap.value(action->getFamily().toLower()); + if (!familySet) { familySet = new ActionSet; familyMap.insert(action->getFamily().toLower(), familySet); } + familySet->insert(action); } @@ -362,8 +381,10 @@ QMenu* Component::getActionMenu() { // sort actions by name ActionList familyList = familySet->toList(); qSort(familyList.begin(), familyList.end(), actionLessThan); + if (familyList.size() >= 1) { QMenu* familyMenu = actionsMenu->addMenu(familyList.first()->getFamily()); + foreach (Action* action, familyList) { familyMenu->addAction(action->getQAction()); } @@ -373,21 +394,13 @@ QMenu* Component::getActionMenu() { } } - ViewerList viewerList = Application::getViewers(this); - if (viewerList.size() > 0) { - QMenu* familyMenu = actionsMenu->addMenu(QString("Viewers")); - foreach(Viewer* viewer, viewerList) { - familyMenu->addAction(viewer->getQAction()); - } - } - - // no menu if no action if (actionsMenu->actions().size() == 0) { delete actionsMenu; actionsMenu = nullptr; } } + return actionsMenu; } @@ -410,9 +423,11 @@ const InterfaceGeometry::RenderingModes Component::getRenderingModes() const { // else return the added rendering mode of all children if (childrenComponent.size() > 0) { InterfaceGeometry::RenderingModes m = InterfaceGeometry::None; + foreach (Component* childComponent, childrenComponent) { m |= childComponent->getRenderingModes(); } + return m; } } @@ -431,11 +446,13 @@ void Component::getActorColor(InterfaceGeometry::RenderingModes m, double d[4]) // return the firts existing Color in my children int i = 0; bool found = false; + while (i < childrenComponent.size() && !found) { childrenComponent[i]->getActorColor(m, d); found = (d[0] != 0.0 || d[1] != 0.0 || d[2] != 0.0 || d[3] != 0.0); i++; } + if (!found) { for (unsigned int j = 0; j < 4; j++) { d[j] = 0.0; @@ -450,17 +467,20 @@ void Component::getBounds(double* bounds) { else { bounds[0] = bounds[2] = bounds[4] = 0.0; bounds[1] = bounds[3] = bounds[5] = 1.0; + // compute bounds using the children's foreach (Component* childComponent, childrenComponent) { double childBounds[6]; //xmin,xmax, ymin,ymax, zmin,zmax // get child bounds childComponent->getBounds(childBounds); + // check compared to global bound for (int i = 0; i < 3; i++) { // compare min if (bounds[i * 2] > childBounds[i * 2]) { bounds[i * 2] = childBounds[i * 2]; } + // compare max if (bounds[i * 2 + 1] < childBounds[i * 2 + 1]) { bounds[i * 2 + 1] = childBounds[i * 2 + 1]; @@ -479,12 +499,15 @@ double Component::getBoundingRadius() { else { // compute bounding radius using the children's double radius = 0.0; + foreach (Component* childComponent, childrenComponent) { double childRadius = childComponent->getBoundingRadius(); + if (childRadius > radius) { radius = childRadius; } } + return radius; } } @@ -524,6 +547,7 @@ int Component::getSlice() const { // -------------------- attachChild -------------------- void Component::attachChild(InterfaceNode* childNode) { auto* comp = dynamic_cast(childNode); + if (comp != nullptr) { // add a sub item if (!childrenComponent.contains(comp)) { @@ -543,6 +567,7 @@ void Component::addChild(InterfaceNode* childNode) { // -------------------- setSelected -------------------- void Component::setSelected(const bool b, const bool recursive) { isSelectedFlag = b; + // maintain the children selection state as well if (recursive) { foreach (Component* child, childrenComponent) { @@ -582,6 +607,7 @@ void Component::deleteChildren() { delete childComp; } } + childrenComponent.clear(); } @@ -636,6 +662,7 @@ const QVector& Component::getChildrenFrame() const { CAMITK_ERROR(tr("myFrame is not instantiated.")) // error / undefined behaviour } + return myFrame->getChildrenFrame(); } @@ -645,6 +672,7 @@ const vtkSmartPointer Component::getTransformFromWorld() const { CAMITK_ERROR(tr("myFrame is not instantiated.")) return nullptr; } + return myFrame->getTransformFromWorld(); } @@ -654,6 +682,7 @@ const vtkSmartPointer Component::getTransform() const { CAMITK_ERROR(tr("myFrame is not instantiated.")) return nullptr; } + return myFrame->getTransform(); } @@ -663,6 +692,7 @@ const vtkSmartPointer Component::getTransformFromFrame(InterfaceFr CAMITK_ERROR(tr("myFrame is not instantiated.")) return nullptr; } + return myFrame->getTransformFromFrame(frame); } diff --git a/sdk/libraries/core/utils/CamiTKLogger.cpp b/sdk/libraries/core/utils/CamiTKLogger.cpp index 57f89a09..f20bd46b 100644 --- a/sdk/libraries/core/utils/CamiTKLogger.cpp +++ b/sdk/libraries/core/utils/CamiTKLogger.cpp @@ -32,6 +32,7 @@ #include "MainWindow.h" #include "ActionExtension.h" #include "ComponentExtension.h" +#include "ViewerExtension.h" #include "Log.h" #include @@ -346,6 +347,12 @@ QString CamiTKLogger::getCamiTKAPIInformation(const QObject* sender) { return QString("Component Extension \"") + camitkComponentExt->getName() + "\" - "; } + // sender is a ComponentExtension + auto* camitkViewerExt = dynamic_cast(nonConstSender); + if (camitkViewerExt != nullptr) { + return QString("Viewer Extension \"") + camitkViewerExt->getName() + "\" - "; + } + // sender is an application const auto* camitkApplication = dynamic_cast(sender); if (camitkApplication != nullptr) { diff --git a/sdk/libraries/core/viewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/InteractiveViewer.cpp index 52920d1e..7c523a96 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/InteractiveViewer.cpp @@ -82,8 +82,6 @@ namespace camitk { -std::array InteractiveViewer::defaultNames = { QString("3DViewer"), QString("axialViewer"), QString("coronalViewer"), QString("sagittalViewer"), QString("arbitraryViewer") }; - // ---------------------- constructor ---------------------------- InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(name) { @@ -127,36 +125,6 @@ InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(na initPicking(InteractiveViewer::NO_PICKING); } - - if (myType == SLICE_VIEWER) { - if (name == defaultNames[1]) { // Axial Viewer - getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); - QString letters[4] = { QString("R"), QString("L"), QString("A"), QString("P") }; - getRendererWidget()->setOrientationDecorationsLetters(letters); - toggleOrientationDecorations(true); - getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); - } - else if (name == defaultNames[2]) { // Coronal Viewer - getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK); - QString letters[4] = { QString("R"), QString("L"), QString("S"), QString("I") }; - getRendererWidget()->setOrientationDecorationsLetters(letters); - toggleOrientationDecorations(true); - getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); - } - else if (name == defaultNames[3]) { // Sagittal Viewer - getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN); - QString letters[4] = { QString("A"), QString("P"), QString("S"), QString("I") }; - getRendererWidget()->setOrientationDecorationsLetters(letters); - toggleOrientationDecorations(true); - getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); - } - else if (name == defaultNames[4]) { // Arbitrary Viewer - //singletonInstance->getRendererWidget()->setCameraOrientation ( RendererWidget::RIGHT_DOWN ); - toggleOrientationDecorations(false); - //singletonInstance->getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); - } - } - //-- current interaction is not changing slice isChangingSlice = false; @@ -181,7 +149,8 @@ InteractiveViewer::~InteractiveViewer() { delete viewerToolbar; viewerToolbar = nullptr; - delete frame; + if (frame != nullptr) + delete frame; frame = nullptr; } @@ -192,6 +161,7 @@ void InteractiveViewer::initSettings() { // the background color QColor bg; + if (myType == GEOMETRY_VIEWER) { // default is white bg.setNamedColor(settings.value("backgroundColor", QColor::fromRgbF(1.0, 1.0, 1.0)).toString()); @@ -278,14 +248,14 @@ void InteractiveViewer::initSettings() { } // ---------------------- getWidget ---------------------------- -QWidget* InteractiveViewer::getWidget(QWidget* parent) { +QWidget* InteractiveViewer::getWidget() { if (!frame) { //-- create the actions initActions(); //-- build the frame - frame = new InteractiveViewerFrame(parent, this); + frame = new InteractiveViewerFrame(nullptr, this); frame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); //-- handle layout @@ -403,13 +373,6 @@ QWidget* InteractiveViewer::getWidget(QWidget* parent) { // add the text as whatsThis frame->setWhatsThis(whatsThis); } - else { - if (frame->parentWidget() != parent) { - bool isVisible = frame->isVisible(); - frame->setParent(parent); - frame->setVisible(isVisible); - } - } return frame; } @@ -446,6 +409,7 @@ void InteractiveViewer::refresh(Viewer* v) { if (v != this) { //-- check all present QList compRendered = actorMap.keys(); + foreach (Component* comp, compRendered) { if (!Application::isAlive(comp)) { // remove from the renderer and map @@ -459,6 +423,7 @@ void InteractiveViewer::refresh(Viewer* v) { switch (myType) { case GEOMETRY_VIEWER: + // check all Components foreach (Component* comp, allComponents) { // remove from the renderer and map @@ -472,6 +437,7 @@ void InteractiveViewer::refresh(Viewer* v) { //-- check the line as tube representation bool linesAsTubes = propertyObject->property(linesAsTubesProperty->getName().toStdString().c_str()).toBool(); + if (linesAsTubes) { comp->setLinesAsTubes(linesAsTubes); } @@ -495,6 +461,7 @@ void InteractiveViewer::refresh(Viewer* v) { } } } + if (comp->getFrameVisibility(this)) { addActor(comp, comp->getFrameAxisActor()); } @@ -506,6 +473,7 @@ void InteractiveViewer::refresh(Viewer* v) { case SLICE_VIEWER: // remove all from the renderer and map QList compRendered = actorMap.keys(); + foreach (Component* comp, compRendered) { removeAllActors(comp); } @@ -581,9 +549,11 @@ void InteractiveViewer::refresh(Viewer* v) { { rendererWidget->resetClippingPlanes(); } + // TODO add a boolean "Reset camera when picking" that can be set on or off // and saved as a setting } + rendererWidget->refresh(); } else { @@ -605,9 +575,11 @@ void InteractiveViewer::refreshRenderer() { // ---------------------- removeAllActors ---------------------------- void InteractiveViewer::removeAllActors(Component* comp) { QList > actorRendered = actorMap.values(comp); + foreach (vtkSmartPointer a, actorRendered) { rendererWidget->removeProp(a); } + // remove from the list actorMap.remove(comp); } @@ -632,6 +604,7 @@ QMenu* InteractiveViewer::getMenu() { options->addAction(backgroundColorAction); options->addAction(toggleCopyrightAction); options->addAction(toggleAxesAction); + if (myType == SLICE_VIEWER) { options->addAction(toggleOrientationDecorationsAction); options->addAction(toggleScreenshotAction); @@ -709,9 +682,11 @@ QToolBar* InteractiveViewer::getToolBar() { viewerToolbar->addAction(surfaceAction); viewerToolbar->addAction(wireframeAction); viewerToolbar->addAction(pointsAction); + if (colorAction) { viewerToolbar->addAction(colorAction); } + viewerToolbar->addAction(glyphAction); viewerToolbar->addAction(toggleLabelAction); @@ -724,6 +699,7 @@ QToolBar* InteractiveViewer::getToolBar() { viewerToolbar->addAction(scalarDataColorAction); } + /* if (myType == SLICE_VIEWER) { viewerToolBar->addAction(toggleOrientationDecorationsAction); } @@ -1012,6 +988,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_C: + // addWhatsThisItem("C", "Toggle color scale"); if (e->modifiers() == Qt::NoModifier) { @@ -1022,6 +999,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_F: + // addWhatsThisItem("F", "Toggle backface culling"); if (e->modifiers() == Qt::NoModifier) { @@ -1031,6 +1009,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_I: + // addWhatsThisItem("I", "Toggle image interpolation on slices"); if (e->modifiers() == Qt::NoModifier) { @@ -1049,6 +1028,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_L: + // addWhatsThisItem("L", "Toggle view labels"); if (e->modifiers() == Qt::NoModifier && myType == GEOMETRY_VIEWER) { @@ -1066,6 +1046,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_P: + // addWhatsThisItem("Alt+P", "Toggle point rendering"); if (e->modifiers() == Qt::AltModifier) { @@ -1118,6 +1099,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_W: + // addWhatsThisItem("Alt+W", "Toggle wireframe rendering"); if (e->modifiers() == Qt::AltModifier) { @@ -1215,6 +1197,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { break; case Qt::Key_Plus: + // addWhatsThisItem("+", "Move slider a step above"); if (myType == SLICE_VIEWER) { @@ -1304,6 +1287,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { debugStream << endl; debugStream << "== Component vtkProp ==" << endl; + foreach (Component* c, actorMap.keys().toSet()) { debugStream << "- Component: \"" << c->getName() << "\" of type \"" << c->metaObject()->className() @@ -1311,9 +1295,11 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { std::list > allActors = actorMap.values(c).toStdList(); allActors.sort(); allActors.unique(); + foreach (vtkSmartPointer p, allActors) { // get more information by comparing with the getActor/getProp method of c bool found = false; + switch (myType) { case GEOMETRY_VIEWER: if (c->getActor(InterfaceGeometry::Surface) == p) { @@ -1330,7 +1316,9 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { found = true; debugStream << "\t- Points Actor" << endl; } + break; + case SLICE_VIEWER: if (c->getPixelActor() == p) { found = true; @@ -1351,16 +1339,20 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { } break; + default: // no other thing is possible break; } + // check additional prop if (!found) { unsigned int i = 0; + while (i < c->getNumberOfProp() && c->getProp(i) != p) { i++; } + if (i == c->getNumberOfProp()) { debugStream << "\t- Unknown Prop" << endl; } @@ -1371,6 +1363,7 @@ void InteractiveViewer::keyPressEvent(QKeyEvent* e) { } } + debugStream << "=== (end of debug information) ===" << endl; CAMITK_INFO(tr("InteractiveViewer Debug Information: ").arg(debugString)) } @@ -1649,6 +1642,7 @@ void InteractiveViewer::initPicking(PickingMode pickingMode) { rendererWidget->setPicker(picker); break; } + case POINT_PICKING: { vtkSmartPointer< vtkPointPicker > picker = vtkSmartPointer< vtkPointPicker >::New(); picker->SetTolerance(0.01); @@ -1656,6 +1650,7 @@ void InteractiveViewer::initPicking(PickingMode pickingMode) { this->rendererWidget->setAreaPicking(false); break; } + case CELL_PICKING: { vtkSmartPointer< vtkCellPicker > picker = vtkSmartPointer< vtkCellPicker >::New(); picker->SetTolerance(0.0001); @@ -1663,18 +1658,21 @@ void InteractiveViewer::initPicking(PickingMode pickingMode) { this->rendererWidget->setAreaPicking(false); break; } + case AREA_CELL_PICKING: { vtkSmartPointer< vtkRenderedAreaPicker > picker = vtkSmartPointer< vtkRenderedAreaPicker >::New(); this->rendererWidget->setPicker(picker); this->rendererWidget->setAreaPicking(true); break; } + case AREA_POINT_PICKING: { vtkSmartPointer< vtkRenderedAreaPicker > picker = vtkSmartPointer< vtkRenderedAreaPicker >::New(); this->rendererWidget->setPicker(picker); this->rendererWidget->setAreaPicking(true); break; } + default: case NO_PICKING: rendererWidget->setPicker(nullptr); @@ -1787,6 +1785,7 @@ void InteractiveViewer::updateActions() { toggleLabelAction->setChecked(Application::getSelectedComponents().first()->getProp("label")->GetVisibility()); auto* mesh = dynamic_cast< MeshComponent* >(first); + if (mesh) { // active scalar data colors and populate combobox with scalar data from the component scalarDataColorAction->setEnabled(true); @@ -2022,6 +2021,7 @@ void InteractiveViewer::setBackfaceCulling(bool b) { // -------------- setScreenshotAction -------------- void InteractiveViewer::setScreenshotAction(bool b) { propertyObject->setProperty(screenshotActionProperty->getName().toStdString().c_str(), b); + if (screenshotActionMenu) { screenshotActionMenu->setVisible(b); } @@ -2065,6 +2065,7 @@ void InteractiveViewer::picked() { } vtkSmartPointer itemPicker; + if (!pickingEffectUpdated && (itemPicker = vtkPicker::SafeDownCast(picker))) { pickingEffectUpdated = true; // decide of the state: if one of the possible picked is selected, then try unselect @@ -2110,10 +2111,13 @@ void InteractiveViewer::picked() { } } break; + case POINT_PICKING: { vtkSmartPointer pointPicker = vtkPointPicker::SafeDownCast(picker); + if (pointPicker) { vtkIdType currentId = pointPicker->GetPointId(); + if (currentId != -1) { vtkSmartPointer ids = vtkSmartPointer::New(); ids->InsertNextValue(currentId); @@ -2128,20 +2132,25 @@ void InteractiveViewer::picked() { // pointPicked can have changed something auto* mesh = dynamic_cast(comp); + if (mesh) { mesh->addToSelectedSelection(vtkSelectionNode::POINT, vtkSelectionNode::INDICES, ids); } + refresh(this); emit selectionChanged(); } } } break; + case CELL_PICKING : { vtkSmartPointer cellPicker = vtkCellPicker::SafeDownCast(this->rendererWidget->GetInteractor()->GetPicker()); auto* mesh = dynamic_cast(comp); + if (cellPicker && mesh) { vtkIdType currentId = cellPicker->GetCellId(); + if (currentId != -1) { vtkSmartPointer ids = vtkSmartPointer::New(); ids->InsertNextValue(currentId); @@ -2158,9 +2167,11 @@ void InteractiveViewer::picked() { } } break; + case AREA_CELL_PICKING : { vtkSmartPointer areaPicker = vtkRenderedAreaPicker::SafeDownCast(this->rendererWidget->GetInteractor()->GetPicker()); auto* mesh = dynamic_cast(comp); + if (areaPicker && mesh) { vtkSmartPointer extractor = vtkSmartPointer::New(); extractor->SetInputData(mesh->getPointSet()); @@ -2168,6 +2179,7 @@ void InteractiveViewer::picked() { extractor->SetFrustum(areaPicker->GetFrustum()); extractor->Update(); vtkDataSet* dataSet = vtkDataSet::SafeDownCast(extractor->GetOutput()); + if (dataSet) { Application::showStatusBarMessage("Picked : " + comp->getName() + " (" + QString::number(dataSet->GetCellData()->GetArray(0)->GetNumberOfTuples()) + " cells )"); mesh->addToSelectedSelection(vtkSelectionNode::CELL, vtkSelectionNode::INDICES, dataSet->GetCellData()->GetArray(0)); @@ -2177,9 +2189,11 @@ void InteractiveViewer::picked() { } } break; + case AREA_POINT_PICKING : { vtkSmartPointer areaPicker = vtkRenderedAreaPicker::SafeDownCast(this->rendererWidget->GetInteractor()->GetPicker()); auto* mesh = dynamic_cast(comp); + if (areaPicker && mesh) { vtkSmartPointer extractor = vtkSmartPointer::New(); extractor->SetInputData(mesh->getPointSet()); @@ -2188,6 +2202,7 @@ void InteractiveViewer::picked() { extractor->SetFieldType(vtkSelection::POINT); extractor->Update(); vtkDataSet* dataSet = vtkDataSet::SafeDownCast(extractor->GetOutput()); + if (dataSet) { Application::showStatusBarMessage("Picked : " + comp->getName() + " (" + QString::number(dataSet->GetPointData()->GetArray(0)->GetNumberOfTuples()) + " points )"); mesh->addToSelectedSelection(vtkSelectionNode::POINT, vtkSelectionNode::INDICES, dataSet->GetPointData()->GetArray(0)); @@ -2197,10 +2212,12 @@ void InteractiveViewer::picked() { } } break; + case NO_PICKING : default : break; } + isPicking = false; comp = nullptr; } @@ -2339,4 +2356,4 @@ void InteractiveViewerFrame::keyPressEvent(QKeyEvent* e) { // By including it, the file kept out library-camitkcore_automoc.cpp #include "moc_InteractiveViewer.cpp" -} \ No newline at end of file +} diff --git a/sdk/libraries/core/viewer/InteractiveViewer.h b/sdk/libraries/core/viewer/InteractiveViewer.h index dcef8af1..5b2f7def 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/InteractiveViewer.h @@ -30,7 +30,6 @@ // -- Core stuff #include "CamiTKAPI.h" #include "Component.h" -#include "ViewerExtension.h" #include "Viewer.h" #include "RendererWidget.h" @@ -72,6 +71,8 @@ public: /// default constructor InteractiveViewerFrame(QWidget* parent, InteractiveViewer* s3D) : QFrame(parent), myInteractiveViewer(s3D) {} + ~InteractiveViewerFrame() override = default; + /// Handle keyboard events in the scene frame, just send everything to InteractiveViewer! void keyPressEvent(QKeyEvent*) override; @@ -170,12 +171,12 @@ public: SELECTION_ONLY ///< the selected Components are in default mode, the non-selected are hidden }; - /// @{ - /** Construtor. - * @param name the name of the scene is mandatory, it is used as an identifier (e.g. in MedicalImageViewer) - * @param type type of the InteractiveViewer, depending on which it will behave as slice viewer, i.e. with no rotation interactions are possible, or 3D viewer - */ - InteractiveViewer(QString& name, ViewerType type); + /// @{ + /** Construtor. + * @param name the name of the scene is mandatory, it is used as an identifier (e.g. in MedicalImageViewer) + * @param type type of the InteractiveViewer, depending on which it will behave as slice viewer, i.e. with no rotation interactions are possible, or 3D viewer + */ + InteractiveViewer(QString& name, ViewerType type); /** Destructor */ ~InteractiveViewer() override; @@ -194,7 +195,7 @@ public: void refresh(Viewer* whoIsAsking = nullptr) override; /// get the InteractiveViewer widget (QTreeWidget). @param parent the parent widget for the viewer widget - QWidget* getWidget(QWidget* parent) override; + QWidget* getWidget() override; /// get the InteractiveViewer propertyObject (only non-null for GEOMETRY_VIEWER) QObject* getPropertyObject() override; @@ -278,8 +279,7 @@ public: ///@} - /** @name Misc - */ + /// @name Misc /// @{ /// set the color scale in the viewport, use setColorScaleMinMax / setColorScaleTitle to change the displayed values. void setColorScale(bool); @@ -314,6 +314,8 @@ public: public slots: + /// @name public slots + /// @{ /** Slot called when the InteractiveViewer slider has been changed. If there is a InterfaceBitMap in the scene, * set the slice index with the new slider value. */ void sliderChanged(int); @@ -329,13 +331,9 @@ public slots: /// show/hide the copyright in 3D void toggleCopyright(bool); - -protected: - /// the QString array containing all InteractiveViewer instance default names - static std::array defaultNames; - /// @} +protected: /** @name Display properties * @@ -377,15 +375,14 @@ protected: QMap cameraMap; ///@} - /** @name Widget/Action management - */ + /// @name Widget/Action management /// @{ /// The 3D scene itself, wrapping VTK render window, renderer and interactor in a single Qt widget - RendererWidget* rendererWidget; + RendererWidget* rendererWidget; /** Slider used to control the slice index in a InteractiveViewer. This slider is visible only when * the scene a 2D viewer (see constructor). */ - SliderSpinBoxWidget* sliceSlider; + SliderSpinBoxWidget* sliceSlider; /// the InteractiveViewer frame InteractiveViewerFrame* frame; @@ -408,7 +405,7 @@ protected: /// the ComboBox for mesh scalar data QComboBox* scalarDataComboBox; - MeshDataFilterModel* scalarDataModel; + MeshDataFilterModel* scalarDataModel; /// init all the actions (called only once in the getWidget() method) void initActions(); @@ -531,42 +528,42 @@ protected: /** * The property object that holds the properties of this viewer */ - PropertyObject* propertyObject; + PropertyObject* propertyObject; /** * The property that stands for the type of highlight mode of the 3D viewer. */ - Property* highlightModeProperty; + Property* highlightModeProperty; /** * The property that stands for the background color of the viewer. */ - Property* backgroundColorProperty; + Property* backgroundColorProperty; /** * Property that tells whether the viewer use a gradient background color or not. */ - Property* backgroundGradientColorProperty; + Property* backgroundGradientColorProperty; /** * Property that tells whether the viewer uses lines as tubes or not. */ - Property* linesAsTubesProperty; + Property* linesAsTubesProperty; /** * Property that tells whether the viewer uses the backface culling option or not. */ - Property* backfaceCullingProperty; + Property* backfaceCullingProperty; /** * Property that tells whether the screenshot action is visible or not. */ - Property* screenshotActionProperty; + Property* screenshotActionProperty; /** * Property which defines the point size of each point in the 3D viewer. */ - Property* pointSizeProperty; + Property* pointSizeProperty; /** * Create and handle the CamiTK properties of this viewer. diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index a3c2ffbc..77a13d5a 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -24,21 +24,56 @@ ****************************************************************************/ #include "Viewer.h" -#include "ViewerExtension.h" #include "Component.h" #include "Application.h" #include "MainWindow.h" +#include "Log.h" + +#include +#include +#include namespace camitk { //---------------------- constructor ------------------------ Viewer::Viewer(QString name): QObject() { - this->name = name; + this->name = name; setObjectName(name); + + layout = STACKED; + dockedWidget = nullptr; + stackedWidget = nullptr; + embeddedLayout = nullptr; + toolbarVisibility = true; - qAction = nullptr; - components << ""; + + components << "Component"; +} + +//---------------------- destructor ------------------------ +Viewer::~Viewer() { + delete dockedWidget; +} + +// -------------------- setIcon -------------------- +void Viewer::setIcon(QPixmap icon) { + this->icon = icon; +} + +// -------------------- getIcon -------------------- +QPixmap Viewer::getIcon() { + return icon; +} + +// -------------------- setComponents -------------------- +void Viewer::setComponents(QStringList components) { + this->components = components; +} + +// -------------------- getComponents -------------------- +QStringList Viewer::getComponents() { + return components; } //---------------------- selectionChanged ------------------------ @@ -46,6 +81,7 @@ void Viewer::selectionChanged(camitk::ComponentList& compSet) { foreach (Component* comp, compSet) { comp->setSelected(true); } + emit selectionChanged(); } @@ -71,45 +107,141 @@ bool Viewer::getToolBarVisibility() { return toolbarVisibility; } -QAction* Viewer::getQAction() { - if (!qAction) { - // create the corresponding QAction (using the icon, name and descriptions) - qAction = new QAction(getIcon(), getName(), this); - qAction->setStatusTip(getDescription()); - qAction->setWhatsThis(getName() + "\n" + getDescription()); - // connect it to the trigger slot +/* TODO CLEANUP +//---------------------- setAsCentralViewerAction ------------------------ +QAction* Viewer::setAsCentralViewerAction() { + if (setAsCentralViewerQAction == nullptr) { + // create the corresponding QAction (using the icon, name and descriptions) + setAsCentralViewerQAction = new QAction(getIcon(), getName(), this); + setAsCentralViewerQAction->setStatusTip(getDescription()); + setAsCentralViewerQAction->setWhatsThis(getName() + "\n" + getDescription()); + // connect it to the trigger slot + connect(setAsCentralViewerQAction, SIGNAL(triggered), this, SLOT(setAsCentralViewer())); + } - connect(qAction, SIGNAL(triggered()), this, SLOT(openViewer())); - } + //updateDisplayInCentralViewerQAction(); - return qAction; + return setAsCentralViewerQAction; +} +*/ +/* +// -------------------- updateDisplayInCentralViewerQAction -------------------- +void Viewer::updateDisplayInCentralViewerQAction() { + if (displayInCentralViewerQAction != nullptr) { + // update QAction state: check if the current viewer is the central viewer + displayInCentralViewerQAction->blockSignals(true); + //bug: this cannot be called before the main window is completely defined + //otherwise another default window will be create and capture all output + //displayInCentralViewerQAction->setChecked(Application::getMainWindow()->getCentralViewer() == this); + displayInCentralViewerQAction->blockSignals(false); + } } +*/ +/* +// -------------------- setAsCentralViewer -------------------- +void Viewer::setAsCentralViewer() { + Application::getMainWindow()->setCentralViewer(this); + refresh(this); +} +*/ -// -------------------- setIcon -------------------- -void Viewer::setIcon(QPixmap icon) { - this->icon = icon; +/* +// -------------------- setDefaultParentWidget -------------------- +void Viewer::setDefaultParentWidget(QWidget* parent) { + defaultParentWidget = parent; } -// -------------------- getIcon -------------------- -QPixmap Viewer::getIcon() { - return icon; +// -------------------- switchParentWidget -------------------- +void Viewer::switchParentWidget(QWidget* parent) { + if (defaultParentWidget == nullptr) { + // this method was called before setDefaultParentWidget: parent is the default parent widget + setDefaultParentWidget(parent); + } + + if (getWidget()->parentWidget() != parent) { + bool isVisible = getWidget()->isVisible(); + getWidget()->setParent(parent); + getWidget()->setVisible(isVisible); + } + + updateDisplayInCentralViewerQAction(); +} + +// -------------------- resetParentWidget -------------------- +void Viewer::resetParentWidget() { + switchParentWidget(defaultParentWidget); +} +*/ + +// -------------------- getLayout -------------------- +Viewer::ViewerLayout Viewer::getLayout() { + return layout; +} + +// -------------------- setLayout -------------------- +void Viewer::setLayout(Viewer::ViewerLayout layout) { + this->layout = layout; } -void Viewer::setComponents(QStringList components) -{ - this->components = components; +// -------------------- dockIn -------------------- +QDockWidget* Viewer::dockIn() { + if (layout != DOCKED) { + CAMITK_ERROR(tr("Cannot dock \"%1\": it does not have a DOCKED layout").arg(name)) + return nullptr; + } + + // create the dock widget and insert it only if the viewer has a widget + if (getWidget() != nullptr && dockedWidget == nullptr) { + // create the dock + dockedWidget = new QDockWidget(name); + dockedWidget->setObjectName(name); + // add the widget + dockedWidget->setWidget(getWidget()); + } + + return dockedWidget; } -QStringList Viewer::getComponents() -{ - return components; +// -------------------- stackIn -------------------- +void Viewer::stackIn(QStackedWidget* stackedWidget) { + if (layout != STACKED) { + CAMITK_ERROR(tr("Cannot stack \"%1\": it does not have a STACKED layout").arg(name)) + return; + } + + // check all conditions are met + if (getWidget() != nullptr && this->stackedWidget == nullptr) { + // add the viewer's widget inside the stack + stackedWidget->addWidget(getWidget()); + // keep the pointer + this->stackedWidget = stackedWidget; + } + + // refresh the widget + if (this->stackedWidget != nullptr) { + this->stackedWidget->setCurrentWidget(getWidget()); + } } -void Viewer::openViewer() -{ - Application::getMainWindow()->setCentralViewer(Application::getViewer(this->getName())); - refresh(this); +// -------------------- embedIn -------------------- +void Viewer::embedIn(QLayout* embeddedLayout) { + if (layout != EMBEDDED) { + CAMITK_ERROR(tr("Cannot embed \"%1\": it does not have a EMBEDDED layout").arg(name)) + return; + } + + // check all conditions are met + if (getWidget() != nullptr && this->embeddedLayout == nullptr) { + embeddedLayout->addWidget(getWidget()); + //getWidget()->setParent(embeddedLayout->parentWidget()); + // keep the pointer + this->embeddedLayout = embeddedLayout; + } } +// -------------------- setVisible -------------------- +void Viewer::setVisible(bool visible) { + getWidget()->setVisible(visible); +} } diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index f6d06a42..e5c9e867 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -36,8 +36,11 @@ // -- QT stuff classes class QToolBar; class QMenu; -class QAction; class QPixMap; +class QWidget; +class QDockWidget; +class QStackedWidget; +class QLayout; namespace camitk { class Component; @@ -54,7 +57,6 @@ class Property; * A viewer can be added to MainWindow, MainWindow will include its menu in the "View" menu and its toolbar in * the application toolbar. * - * Use QObject method getObjectName to get the viewer's name. */ class CAMITK_API Viewer : public QObject { @@ -65,17 +67,40 @@ public: Viewer(QString name); /// default destructor - ~Viewer() override = default; - - /// get the name of the viewer - QString getName() const { - return name; - }; - - /// get the name of the viewer - QString getDescription() const { - return description; - }; + ~Viewer() override; + + /// \enum ViewerLayout describes where this viewer should appear + enum ViewerLayout { + DOCKED, ///< this viewer is meant to be docked, use dockIn() to get the dock widget + STACKED, ///< this viewer is meant to be inside a stacked widget (for instance the central viewer), use stackIn() to set the stacked widget it is in + EMBEDDED, ///< this viewer is meant to be embedded inside a layout (of another viewer or widget), use embedIn(..) to set the layout it is embedded in + }; + + /// get the name of the viewer + QString getName() const { + return name; + }; + + /// get the name of the viewer + QString getDescription() const { + return description; + }; + + /// set the viewer layout + void setLayout(ViewerLayout); + + /// get the viewer layout + ViewerLayout getLayout(); + + /// Create the dock widget and dock the viewer widget in it (return nullptr if this viewer has not a DOCKED layout) + QDockWidget* dockIn(); + + /// show the viewer's widget in the stack + /// If it is the first call, add the viewer widget in the given stack (once done, it cannot change stack) + void stackIn(QStackedWidget*); + + /// Add the viewer widget in the given layout (once done, the layout cannot be changed) + void embedIn(QLayout*); /// returns the number of Component that are displayed by this viewer virtual unsigned int numberOfViewedComponent() = 0; @@ -83,9 +108,6 @@ public: /// refresh the view (can be interesting to know which other viewer is calling this) virtual void refresh(Viewer* whoIsAsking = nullptr) = 0; - /// get the viewer widget. @param parent the parent widget for the viewer widget - virtual QWidget* getWidget(QWidget* parent = nullptr) = 0; - /// get the viewer property object (returns NULL by default, i.e. there are no property to edit) virtual QObject* getPropertyObject() { return nullptr; @@ -101,34 +123,39 @@ public: return nullptr; }; + /// set the visibility of the viewer (show or hide its widget) + void setVisible(bool); + /** 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 + * 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(); - QAction* getQAction(); + /// get the viewer icon + virtual QPixmap getIcon(); - virtual QPixmap getIcon(); - /// Update the whole tree of the representation of the Component. /// Is actually useful (and defined) in Explorer. - virtual void refreshInterfaceNode(Component* comp) {}; + virtual void refreshInterfaceNode(Component*) {}; - QStringList getComponents(); + /// get the list of Component class manages by this viewer + /// (default is set to "Component", i.e. all type of Component) + QStringList getComponents(); signals: /// this signal is emitted when the current selection was changed by the viewer void selectionChanged(); -public slots: - - void openViewer(); - protected: + /// get the viewer widget. + /// this method is protected and to be redefined in the inheriting class. + /// \note to show the viewer's widget in the GUI, use dockIn(), stackIn(..) or embedIn(...) + /// to set where the viewer is displayed + virtual QWidget* getWidget() = 0; /** The selection has changed to the given ComponentList. * This method updates the Component::selection and emit the modified signal. @@ -142,26 +169,46 @@ protected: /// clear the selection void clearSelection(); - void setIcon(QPixmap icon); - - void setComponents(QStringList); + /// set the default icon for the viewer extension + void setIcon(QPixmap icon); + /// set the list of component class names managed by this viewer + /// \note Default is set to "Component" (all type of components) + /// If your viewer does not view components (for instance it views action) + /// then you need to call this method with an empty list. + /// An empty list means that this viewer is + /// going to be notified/refreshed for every changes that are not linked with + /// any components. + void setComponents(QStringList); private: + /// current viewer's name + QString name; - QString name; - - QString description; + /// description of the viewer + QString description; /// the current toolbar visibility bool toolbarVisibility; - QAction* qAction; + /// the Viewer pixmap icon + QPixmap icon; + + /// list of Component class name managed by this viewer + QStringList components; + + /// this viewer's layout + ViewerLayout layout; + + /// if layout is DOCKED, then this is the dock widget + QDockWidget* dockedWidget; + + /// if layout is embedded, then this is the QLayout it is embedded in + QLayout* embeddedLayout; - /// the Viewer pixmap icon - QPixmap icon; + /// the QAction that will allow it to be set as the central viewer + QStackedWidget* stackedWidget; - QStringList components; }; } diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index 3ded3ac7..413cb79e 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -35,72 +35,115 @@ namespace camitk { +// -------------------- constructor -------------------- ViewerExtension::ViewerExtension() { - viewerClassName = nullptr; + viewerClassName = nullptr; + translator = nullptr; +} + +// -------------------- destructor -------------------- +ViewerExtension::~ViewerExtension() { + while (!viewers.empty()) { + Viewer* toDelete = viewers.takeFirst(); + // do not delete the "Quit" action: it is the action that triggers this delete! + delete toDelete; + } + + //delete internationalization instance + if (translator) { + delete translator; + } } // -------------------- initResources -------------------- void ViewerExtension::initResources() { - // Get the selected language - QString selectedLanguage = Application::getSelectedLanguage(); - - // if a language is defined, then try to load the translation file - if (!selectedLanguage.isEmpty()) { - QString viewerExtensionDirName = QDir(this->getLocation()).dirName(); - // remove any occurence of "-debug.dll" or ".so" or ".dylib" on the extension file name - viewerExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib"); - QString languageFile = ":/translate_" + viewerExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm"; - translator = new QTranslator(); - if (translator->load(languageFile)) { - QCoreApplication::installTranslator(translator); - } - else { - CAMITK_INFO(tr("Cannot load resource file: %1").arg(languageFile)) - } - } + // Get the selected language + QString selectedLanguage = Application::getSelectedLanguage(); + + // if a language is defined, then try to load the translation file + if (!selectedLanguage.isEmpty()) { + QString viewerExtensionDirName = QDir(this->getLocation()).dirName(); + // remove any occurence of "-debug.dll" or ".so" or ".dylib" on the extension file name + viewerExtensionDirName.remove("-debug.dll").remove(".so").remove(".dylib"); + QString languageFile = ":/translate_" + viewerExtensionDirName + "/translate/translate_" + selectedLanguage + ".qm"; + translator = new QTranslator(); + + if (translator->load(languageFile)) { + QCoreApplication::installTranslator(translator); + } + else { + CAMITK_INFO(tr("Cannot load resource file: %1").arg(languageFile)) + } + } } -QString ViewerExtension::getViewerClassName() -{ - return viewerClassName; +// -------------------- setLocation -------------------- +void ViewerExtension::setLocation(const QString loc) { + dynamicLibraryFileName = loc; } -// -------------------- destructor -------------------- -ViewerExtension::~ViewerExtension() { - while (!viewers.empty()) { - Viewer* toDelete = viewers.takeFirst(); - // do not delete the "Quit" action: it is the action that triggers this delete! - delete toDelete; - } - - //delete internationalization instance - if (translator) { - delete translator; - } +// -------------------- getLocation -------------------- +QString ViewerExtension::getLocation() const { + return dynamicLibraryFileName; +} + +// -------------------- getViewerClassName -------------------- +QString ViewerExtension::getViewerClassName() { + return viewerClassName; } -// -------------------- registerAction -------------------- +// -------------------- registerViewer -------------------- void ViewerExtension::registerViewer(Viewer* viewer) { - // simply add the viewer in the list - if (viewerClassName == nullptr) { - viewerClassName = viewer->metaObject()->className(); - } - viewers.append(viewer); + // first call, get the viewer class name + if (viewerClassName == nullptr) { + viewerClassName = viewer->metaObject()->className(); + } + else { + // only one type of viewer is managed by a viewer extension + if (viewerClassName != viewer->metaObject()->className()) { + CAMITK_ERROR(tr("Cannot register viewer \"%1\" as it is an instance of \"%2\" (extension \"%3\" only manages the \"%4\" viewer class)").arg(viewer->getName()).arg(viewer->metaObject()->className()).arg(getName()).arg(viewerClassName)) + return; + } + } + + // simply add the viewer in the list + viewers.append(viewer); + } +// -------------------- getNewInstance -------------------- Viewer* ViewerExtension::getNewInstance(QString name) { - int typeId = QMetaType::type(viewerClassName.toStdString().c_str()); - const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId); - QObject *o = metaObject->newInstance(Q_ARG(QString, name)); - Viewer* viewer = qobject_cast(o); - registerViewer(viewer); - return viewer; + // check if a viewer of the same name exists + int i = 0; + + while (i < viewers.size() && viewers.at(i)->getName() != name) { + i++; + } + + if (i != viewers.size()) { + CAMITK_INFO(tr("No new instance created, returning already instanciated and registered \"%1\" viewer.\nViewer instance names should be unique.\n").arg(name)) + return viewers.at(i); + } + + // if the viewer does not already exist, instanciate it + // get the pointer to the viewer's class meta object + int typeId = QMetaType::type(viewerClassName.toStdString().c_str()); + const QMetaObject* metaObject = QMetaType::metaObjectForType(typeId); + + // instanciate a new viewer of the managed class + QObject* o = metaObject->newInstance(Q_ARG(QString, name)); + Viewer* viewer = qobject_cast(o); + + // register it in the list + registerViewer(viewer); + + return viewer; } -// -------------------- getActions -------------------- +// -------------------- getViewers -------------------- const ViewerList& ViewerExtension::getViewers() { - return viewers; + return viewers; } -} \ No newline at end of file +} diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index a8ec3f66..8eef2b77 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -12,7 +12,12 @@ namespace camitk { class Viewer; -#define registerNewViewer(X, Y) registerViewer(new X(QString(Y))) +/// register default viewer will use the class name to create a new viewer of the same name +/// .replace(0, 1, QString(#__VA_ARGS__).at(0).toLower()) +#define registerDefaultViewer(...) registerViewer(new __VA_ARGS__(QString(#__VA_ARGS__))) + +/// register a new viewer, instance of X, its name is Y +#define registerNewViewer(X, Y) registerViewer(new X(QString(Y))) /** * @ingroup group_sdk_libraries_core_action @@ -32,61 +37,61 @@ class Viewer; class CAMITK_API ViewerExtension : public QObject { protected: - /// constructor - ViewerExtension(); + /// constructor + ViewerExtension(); public: - /// destructor - ~ViewerExtension() override; + /// destructor + ~ViewerExtension() override; - /// returns the action extension name (to be overriden in your ActionExtension) - virtual QString getName() = 0; + /// returns the viewer extension name (to be overriden in the derived class) + virtual QString getName() = 0; - /// returns the action extension small description (to be overriden in your ActionExtension) - virtual QString getDescription() = 0; + /// returns the viewer extension small description (to be overriden in the derived class) + virtual QString getDescription() = 0; - /// this method should just call registerNewViewer(MyViewer) for any MyViewer class you need to register by this extension - virtual void init() = 0; + /// this method should just call registerNewViewer(MyViewer) for any MyViewer class you need to register by this extension + virtual void init() = 0; - /// get the list of actions registered y this extension - const ViewerList& getViewers(); + /// get the list of viewer instances registered by this extension + const ViewerList& getViewers(); - /// set the file path (once loaded as a dynamic library) - void setLocation(const QString loc) { - dynamicLibraryFileName = loc; - } + /// set the file path (once loaded as a dynamic library) = where this extension was loaded + void setLocation(const QString loc); - /// get the file path (location of the .dll/.so/.dylib) of this plugin - QString getLocation() const { - return dynamicLibraryFileName; - } + /// get the file path (location of the .dll/.so/.dylib) of this plugin + QString getLocation() const; - /// Load, for the selected langage (asked to the Application), the associated .qm file - void initResources(); + /// Load, for the selected langage (asked to the Application), the associated .qm file + void initResources(); - QString getViewerClassName(); + /// get the class name of the viewer managed by this extension + QString getViewerClassName(); - Viewer * getNewInstance(QString name); + /// factory: create a new viewer instance and register it + /// @return a new instance of the given name, or the previously registered instance if it already exist + Viewer* getNewInstance(QString name); protected: - /// register an viewer instance - void registerViewer(Viewer*); + /// register an viewer instance + void registerViewer(Viewer*); - /// the list of viewers - ViewerList viewers; + /// the list of viewers + ViewerList viewers; private: - /// the shared lib (.so, .dll or .dylib) used to instantiate the ComponentExtension subclass instance - QString dynamicLibraryFileName; + /// the shared lib (.so, .dll or .dylib) used to instantiate the ComponentExtension subclass instance + QString dynamicLibraryFileName; - /// Provide internationalization support for text output. - QTranslator* translator{ nullptr }; + /// Provide internationalization support for text output. + QTranslator* translator; - QString viewerClassName; + /// name of the viewer class managed by this extension + QString viewerClassName; }; } // -------------------- declare the interface for QPluginLoader -------------------- -Q_DECLARE_INTERFACE(camitk::ViewerExtension, "TIMC-IMAG. Viewer Extension/2.1") //TODO use variable from CMake? +Q_DECLARE_INTERFACE(camitk::ViewerExtension, "TIMC-IMAG. Viewer Extension/2.1") //TODO use variable from CMake? -#endif //VIEWER_EXTENSION_H \ No newline at end of file +#endif //VIEWER_EXTENSION_H diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index f1c9ebe3..d6127e41 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -25,9 +25,10 @@ #include "ActionViewer.h" -#include "Application.h" -#include "Component.h" -#include "Action.h" +//-- Core +#include +#include +#include #include #include @@ -35,44 +36,38 @@ #include #include #include -// Deprecated. Use Application.h to handle logger interface -//#include "Log.h" using namespace camitk; // ---------------- constructor ---------------- ActionViewer::ActionViewer(QString name) : Viewer(name) { + setLayout(Viewer::DOCKED); myWidget = nullptr; familyComboBox = nullptr; nameComboBox = nullptr; actionWidgetStack = nullptr; searchFramePanel = nullptr; + + // empty the list as this is an action viewer, it has nothing to do with Components + setComponents(QStringList()); } +// ---------------- destructor ---------------- ActionViewer::~ActionViewer() { } // -------------------- refresh -------------------- -void ActionViewer::refresh(Viewer* whoIsAsking) { - // no need to update if there is no selected action or there is no selected component +void ActionViewer::refresh(Viewer*) { + // no need to update if there is no selected action or there is no selected component updateActionWidget(Application::getSelectedAction()); - updateSearchPanel(ViewerRefresh); + updateSearchPanel(ViewerRefresh); } // -------------------- getWidget -------------------- -QWidget* ActionViewer::getWidget(QWidget* parent) { +QWidget* ActionViewer::getWidget() { // lazy instantiation if (!myWidget) { - // if no parent then put this in a dialog - if (!parent) { - // put it in a dialog, this is the case for default MainWindow, who does not add the ActionViewer in a dock - QDialog* myWidgetIsADialog = new QDialog(nullptr); - myWidgetIsADialog->setWindowTitle(objectName()); - myWidget = myWidgetIsADialog; - } - else { - myWidget = new QWidget(); - } + myWidget = new QWidget(); auto* actionWidgetLayout = new QVBoxLayout(); @@ -146,12 +141,12 @@ void ActionViewer::changeName() { // -------------------- changeTag -------------------- void ActionViewer::changeTag() { - updateSearchPanel(ActionTagChanged); + updateSearchPanel(ActionTagChanged); } // -------------------- changeFamilyComboBox -------------------- void ActionViewer::changeFamily() { - updateSearchPanel(ActionFamilyChanged); + updateSearchPanel(ActionFamilyChanged); } // ---------------- componentListLessThan ---------------- @@ -204,6 +199,7 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { nameComboBox->addItem(action->getName()); } } + nameComboBox->model()->sort(0); break; @@ -212,8 +208,8 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { //-- action name whas changed -> trigger the corresponding action if (action) { familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - lastSelected = ComponentList(); - action->trigger(); + lastSelected = ComponentList(); + action->trigger(); } break; @@ -226,11 +222,12 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { if (actionset.size() == 1) { action = *(actionset.begin()); nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); - updateSearchPanel(ActionNameChanged); + updateSearchPanel(ActionNameChanged); } else { nameComboBox->clear(); nameComboBox->addItem("-- Select Action --"); + foreach (Action* action, actionset) { nameComboBox->addItem(action->getName()); } @@ -247,6 +244,7 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { //-- selection was changed, update combo boxes and tag list, and then check history // copy selected component list (so that references are not used for comparison) ComponentList selected(Application::getSelectedComponents()); + // if selection did not change between two updates, no need to refresh the widget if (currentlySelected != selected) { currentlySelected = selected; @@ -256,25 +254,30 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { QStringList wordList; familyComboBox->addItem("-- Select Family --"); nameComboBox->addItem("-- Select Action --"); + if (selected.size() > 0) { possibleActions = Application::getActions(selected.last()); } else { // no selection => select only empty component actions possibleActions = Application::getActions(nullptr); } // Complete family and action lists depending of the last selected component + foreach (Action* action, possibleActions) { if (familyComboBox->findText(action->getFamily()) == -1) { familyComboBox->addItem(action->getFamily()); } + if (nameComboBox->findText(action->getName()) == -1) { nameComboBox->addItem(action->getName()); } + foreach (QString tag, action->getTag()) { if (!wordList.contains(tag)) { wordList.append(tag); } } } + nameComboBox->model()->sort(0); familyComboBox->model()->sort(0); auto* completer = new QCompleter(wordList, myWidget); @@ -284,6 +287,7 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { //-- check history // check if the same list of Component* was already used QMap::const_iterator it = widgetHistory.find(selected); + if (it != widgetHistory.end()) { // show the previously used widget if (it.value() == NULL) { @@ -292,7 +296,7 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { else { // update search panel familyComboBox->setCurrentIndex(familyComboBox->findText(it.value()->getFamily())); nameComboBox->setCurrentIndex(nameComboBox->findText(it.value()->getName())); - it.value()->trigger(); + it.value()->trigger(); } } else { @@ -311,38 +315,39 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { // -------------------- embedActionWidget -------------------- void ActionViewer::updateActionWidget(Action* action) { - if (action != nullptr && currentlySelected.size() > 0) { - if (this->action != action || lastSelected.isEmpty() || lastSelected != currentlySelected) { - this->action = Application::getSelectedAction(); - this->lastSelected = Application::getSelectedComponents(); - // make sure the action viewer is visible (even if in a dockwidget) - if (getWidget()->parentWidget()) { - getWidget()->parentWidget()->setVisible(true); - getWidget()->setVisible(true); - } - - //-- check history - QWidget* actionWidget = action->getWidget(); - int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); - - if (actionWidgetIndex == -1 && actionWidget) { - // add the widget (beware that actionWidgetStack then takes ownership of the widget!) - actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); - } - - // insert new index in history - ComponentList selected(Application::getSelectedComponents()); - widgetHistory.insert(selected, action); - actionWidgetStack->setCurrentIndex(actionWidgetIndex); - actionWidgetStack->update(); - // ignore size policy of widget so that it can be resized - actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); - - - // update search panel - familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - updateSearchPanel(ActionFamilyChanged); // to have only the actions of the same family - nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); - } - } + if (action != nullptr && currentlySelected.size() > 0) { + if (this->action != action || lastSelected.isEmpty() || lastSelected != currentlySelected) { + this->action = Application::getSelectedAction(); + this->lastSelected = Application::getSelectedComponents(); + + // make sure the action viewer is visible (even if in a dockwidget) + if (getWidget()->parentWidget()) { + getWidget()->parentWidget()->setVisible(true); + getWidget()->setVisible(true); + } + + //-- check history + QWidget* actionWidget = action->getWidget(); + int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); + + if (actionWidgetIndex == -1 && actionWidget) { + // add the widget (beware that actionWidgetStack then takes ownership of the widget!) + actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); + } + + // insert new index in history + ComponentList selected(Application::getSelectedComponents()); + widgetHistory.insert(selected, action); + actionWidgetStack->setCurrentIndex(actionWidgetIndex); + actionWidgetStack->update(); + // ignore size policy of widget so that it can be resized + actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + + + // update search panel + familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); + updateSearchPanel(ActionFamilyChanged); // to have only the actions of the same family + nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); + } + } } diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index d5d7be77..8ede4795 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -28,7 +28,6 @@ #include "ActionViewerAPI.h" -#include #include #include #include @@ -79,8 +78,8 @@ public: /// refresh the view (can be interesting to know which other viewer is calling this) virtual void refresh(Viewer* whoIsAsking = nullptr); - /// get the viewer widget. @param parent the parent widget for the viewer widget - virtual QWidget* getWidget(QWidget* parent = nullptr); + /// get the viewer widget + virtual QWidget* getWidget(); //@} /// show/hide the search panel (hidden by default) diff --git a/sdk/viewers/actionviewer/ActionViewerExtension.cpp b/sdk/viewers/actionviewer/ActionViewerExtension.cpp index 9506bdfc..f3ca8f37 100644 --- a/sdk/viewers/actionviewer/ActionViewerExtension.cpp +++ b/sdk/viewers/actionviewer/ActionViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void ActionViewerExtension::init() { - registerNewViewer(ActionViewer, "ActionViewer"); + registerDefaultViewer(ActionViewer); } diff --git a/sdk/viewers/actionviewer/ActionViewerExtension.h b/sdk/viewers/actionviewer/ActionViewerExtension.h index 6ccd6d42..fe67b40b 100644 --- a/sdk/viewers/actionviewer/ActionViewerExtension.h +++ b/sdk/viewers/actionviewer/ActionViewerExtension.h @@ -29,7 +29,8 @@ #include "ActionViewerAPI.h" -#include "ViewerExtension.h" +//-- from CamiTK Core +#include class ACTIONVIEWER_API ActionViewerExtension : public camitk::ViewerExtension { Q_OBJECT @@ -50,7 +51,7 @@ public: /// Method returning the action extension descrption virtual QString getDescription() { - return "An extension for the viewer that display GUI action"; + return "actionViewer displays the currently selected action's GUI as well as a action selector"; }; /// initialize all the actions diff --git a/sdk/viewers/actionviewer/CMakeLists.txt b/sdk/viewers/actionviewer/CMakeLists.txt index e3b83fcb..5e9869de 100644 --- a/sdk/viewers/actionviewer/CMakeLists.txt +++ b/sdk/viewers/actionviewer/CMakeLists.txt @@ -2,7 +2,7 @@ camitk_extension(VIEWER_EXTENSION CEP_NAME SDK DEFINES COMPILE_ACTIONVIEWER_API - DESCRIPTION "An extension for the viewer that display GUI action" + DESCRIPTION "A viewer to display the currently selected action's GUI as well as a action selector" INSTALL_ALL_HEADERS ) diff --git a/tutorials/viewers/bitmap/BitmapViewer.cpp b/sdk/viewers/bitmap/BitmapViewer.cpp similarity index 97% rename from tutorials/viewers/bitmap/BitmapViewer.cpp rename to sdk/viewers/bitmap/BitmapViewer.cpp index fd248782..aaab0207 100644 --- a/tutorials/viewers/bitmap/BitmapViewer.cpp +++ b/sdk/viewers/bitmap/BitmapViewer.cpp @@ -62,8 +62,8 @@ void BitmapViewer::refresh(Viewer* whoIsAsking) { } // -------------------- getWidget -------------------- -QWidget* BitmapViewer::getWidget(QWidget* parent) { - QWidget* myWidget = InteractiveViewer::getWidget(parent); +QWidget* BitmapViewer::getWidget() { + QWidget* myWidget = InteractiveViewer::getWidget(); // hide slice slider sideFrame->hide(); updateVisibility(); diff --git a/tutorials/viewers/bitmap/BitmapViewer.h b/sdk/viewers/bitmap/BitmapViewer.h similarity index 95% rename from tutorials/viewers/bitmap/BitmapViewer.h rename to sdk/viewers/bitmap/BitmapViewer.h index 10ab8296..57b08647 100644 --- a/tutorials/viewers/bitmap/BitmapViewer.h +++ b/sdk/viewers/bitmap/BitmapViewer.h @@ -29,7 +29,7 @@ #include "BitmapViewerAPI.h" -#include +//-- Core #include class QToolBar; @@ -48,7 +48,7 @@ public: void refresh(camitk::Viewer* whoIsAsking = nullptr) override; - QWidget* getWidget(QWidget* parent = nullptr) override; + QWidget* getWidget() override; QToolBar* getToolBar() override; diff --git a/tutorials/viewers/bitmap/BitmapViewerAPI.h b/sdk/viewers/bitmap/BitmapViewerAPI.h similarity index 100% rename from tutorials/viewers/bitmap/BitmapViewerAPI.h rename to sdk/viewers/bitmap/BitmapViewerAPI.h diff --git a/tutorials/viewers/bitmap/BitmapViewerExtension.cpp b/sdk/viewers/bitmap/BitmapViewerExtension.cpp similarity index 95% rename from tutorials/viewers/bitmap/BitmapViewerExtension.cpp rename to sdk/viewers/bitmap/BitmapViewerExtension.cpp index 92f734c1..01a3369a 100644 --- a/tutorials/viewers/bitmap/BitmapViewerExtension.cpp +++ b/sdk/viewers/bitmap/BitmapViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getActions ------------------- void BitmapViewerExtension::init() { - registerNewViewer(BitmapViewer, "BitmapViewer"); + registerDefaultViewer(BitmapViewer); } diff --git a/tutorials/viewers/bitmap/BitmapViewerExtension.h b/sdk/viewers/bitmap/BitmapViewerExtension.h similarity index 99% rename from tutorials/viewers/bitmap/BitmapViewerExtension.h rename to sdk/viewers/bitmap/BitmapViewerExtension.h index 23575710..7f2bfd3e 100644 --- a/tutorials/viewers/bitmap/BitmapViewerExtension.h +++ b/sdk/viewers/bitmap/BitmapViewerExtension.h @@ -27,6 +27,7 @@ #ifndef BITMAP_VIEWER_EXTENSION_H #define BITMAP_VIEWER_EXTENSION_H +//-- Core #include class BitmapViewerExtension : public camitk::ViewerExtension { diff --git a/tutorials/viewers/bitmap/CMakeLists.txt b/sdk/viewers/bitmap/CMakeLists.txt similarity index 100% rename from tutorials/viewers/bitmap/CMakeLists.txt rename to sdk/viewers/bitmap/CMakeLists.txt diff --git a/sdk/viewers/explorer/Explorer.cpp b/sdk/viewers/explorer/Explorer.cpp index 08d591c6..0c88864b 100644 --- a/sdk/viewers/explorer/Explorer.cpp +++ b/sdk/viewers/explorer/Explorer.cpp @@ -23,18 +23,18 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ -//-- camiTK stuff #include "Explorer.h" -#include "Application.h" -#include "Component.h" -#include "Log.h" +//-- CamiTK Core stuff +#include +#include +#include //-- Qt stuff #include #include -//-- to stretch th first column to entirely show the names +//-- to stretch the first column to entirely show the names #include //-- stl stuff @@ -44,6 +44,7 @@ using namespace camitk; //----------------------- constructor ------------------------ Explorer::Explorer(QString name) : Viewer(name) { + setLayout(Viewer::DOCKED); explorerTree = nullptr; explorerMenu = nullptr; } @@ -58,10 +59,10 @@ Explorer::~Explorer() { } //----------------------- getWidget ------------------------ -QWidget* Explorer::getWidget(QWidget* parent) { +QWidget* Explorer::getWidget() { if (explorerTree == nullptr) { //-- create the explorer tree - explorerTree = new QTreeWidget(parent); + explorerTree = new QTreeWidget(); // For explorerTree to emit the customMenu.. signal explorerTree->setContextMenuPolicy(Qt::CustomContextMenu); // headers diff --git a/sdk/viewers/explorer/Explorer.h b/sdk/viewers/explorer/Explorer.h index 2778d309..ad3461cf 100644 --- a/sdk/viewers/explorer/Explorer.h +++ b/sdk/viewers/explorer/Explorer.h @@ -29,9 +29,8 @@ #include "ExplorerAPI.h" -#include "ViewerExtension.h" // -- Core stuff -#include "Viewer.h" +#include // -- QT stuff #include @@ -80,8 +79,8 @@ public: /// refresh the explorer (can be interesting to know which other viewer is calling this) void refresh(camitk::Viewer* whoIsAsking = nullptr) override; - /// get the explorer widget (QTreeWidget). @param parent the parent widget for the viewer widget - QWidget* getWidget(QWidget* parent) override; + /// get the explorer widget (QTreeWidget) + QWidget* getWidget() override; /// get the explorer menu QMenu* getMenu() override; diff --git a/sdk/viewers/explorer/ExplorerExtension.cpp b/sdk/viewers/explorer/ExplorerExtension.cpp index a748c533..72fddb63 100644 --- a/sdk/viewers/explorer/ExplorerExtension.cpp +++ b/sdk/viewers/explorer/ExplorerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void ExplorerExtension::init() { - registerNewViewer(Explorer, "Explorer"); + registerDefaultViewer(Explorer); } diff --git a/sdk/viewers/explorer/ExplorerExtension.h b/sdk/viewers/explorer/ExplorerExtension.h index f228ff6a..e72cada3 100644 --- a/sdk/viewers/explorer/ExplorerExtension.h +++ b/sdk/viewers/explorer/ExplorerExtension.h @@ -29,7 +29,8 @@ #include "ExplorerAPI.h" -#include "ViewerExtension.h" +//-- from CamiTK Core +#include class EXPLORER_API ExplorerExtension : public camitk::ViewerExtension { Q_OBJECT diff --git a/sdk/viewers/frameexplorer/FrameExplorer.cpp b/sdk/viewers/frameexplorer/FrameExplorer.cpp index 92979d59..3a481b19 100644 --- a/sdk/viewers/frameexplorer/FrameExplorer.cpp +++ b/sdk/viewers/frameexplorer/FrameExplorer.cpp @@ -23,10 +23,11 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ -//-- camiTK stuff #include "FrameExplorer.h" -#include "Component.h" -#include "Application.h" + +//-- CamiTK stuff +#include +#include //-- to stretch th first column to entirely show the names #include @@ -35,14 +36,15 @@ using namespace camitk; //----------------------- constructor ------------------------ FrameExplorer::FrameExplorer(QString name) : Viewer( name) { + setLayout(Viewer::DOCKED); explorerTree = nullptr; } //----------------------- getWidget ------------------------ -QWidget* FrameExplorer::getWidget(QWidget* parent) { +QWidget* FrameExplorer::getWidget() { if (explorerTree == nullptr) { //-- create the explorer tree - explorerTree = new QTreeWidget(parent); + explorerTree = new QTreeWidget(); // For explorerTree to emit the customMenu.. signal explorerTree->setContextMenuPolicy(Qt::CustomContextMenu); // headers @@ -164,4 +166,4 @@ void FrameExplorer::remove() { void FrameExplorer::selectionChanged() { // refresh! refresh(this); -} \ No newline at end of file +} diff --git a/sdk/viewers/frameexplorer/FrameExplorer.h b/sdk/viewers/frameexplorer/FrameExplorer.h index d813eae8..09cbac5c 100644 --- a/sdk/viewers/frameexplorer/FrameExplorer.h +++ b/sdk/viewers/frameexplorer/FrameExplorer.h @@ -29,9 +29,8 @@ #include "FrameExplorerAPI.h" -#include "ViewerExtension.h" // -- Core stuff -#include "Viewer.h" +#include // -- QT stuff #include @@ -46,15 +45,9 @@ namespace camitk { * @ingroup group_sdk_libraries_core_viewer * * @brief - * Explorer window, display the list of all data currently opened in the application. - * All objects are displayed in a QListView widget and can be selected + * Frame Explorer window, display the hierachy of the frames of all the data currently opened in the application. + * All frames are displayed in a QListView widget and can be selected * (single/multiple selection is available). - * - * \image html libraries/explorer.png "The component explorer viewer." - * - * This viewer also manages a singleton (THE CamiTK explorer). See getInstance() for more information. - * You do not have to use it, but it is convienent (and sometimes preferable) to use this instance - * instead of creating your own one. */ class FRAMEEXPLORER_API FrameExplorer : public camitk::Viewer { Q_OBJECT @@ -75,17 +68,15 @@ public: /// returns the number of Component that are displayed by this viewer unsigned int numberOfViewedComponent() override; - /// refresh the explorer (can be interesting to know which other viewer is calling this) + /// refresh the frame explorer (can be interesting to know which other viewer is calling this) void refresh(Viewer* whoIsAsking = nullptr) override; - /// get the explorer widget (QTreeWidget). @param parent the parent widget for the viewer widget - QWidget* getWidget(QWidget* parent) override; + /// get the frame explorer widget (QTreeWidget) + QWidget* getWidget() override; - /// get the explorer preference widget (widget where all preferences can be modified). @param parent the parent widget for the preference widget + /// get the frame explorer preference widget (widget where all preferences can be modified). @param parent the parent widget for the preference widget virtual QWidget* getPreferenceWidget(QWidget* parent); -public slots : - private slots : /// slot called whenever the selection changed in the explorer diff --git a/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp b/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp index 4806ac4e..6865b7aa 100644 --- a/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp +++ b/sdk/viewers/frameexplorer/FrameExplorerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void FrameExplorerExtension::init() { - registerNewViewer(FrameExplorer, "FrameExplorer"); + registerDefaultViewer(FrameExplorer); } diff --git a/sdk/viewers/frameexplorer/FrameExplorerExtension.h b/sdk/viewers/frameexplorer/FrameExplorerExtension.h index 3b50c36c..2462ced5 100644 --- a/sdk/viewers/frameexplorer/FrameExplorerExtension.h +++ b/sdk/viewers/frameexplorer/FrameExplorerExtension.h @@ -29,7 +29,8 @@ #include "FrameExplorerAPI.h" -#include "ViewerExtension.h" +//-- from CamiTK Core +#include class FRAMEEXPLORER_API FrameExplorerExtension : public camitk::ViewerExtension { Q_OBJECT diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp index c23b59a6..6cc57edc 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp @@ -23,19 +23,20 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ - // -- Core stuff -#include +// -- Core stuff #include "InteractiveGeometryViewer.h" -#include using namespace camitk; // -------------------- Constructor -------------------- -InteractiveGeometryViewer::InteractiveGeometryViewer(QString name) : InteractiveViewer(name, InteractiveViewer::GEOMETRY_VIEWER) -{ +InteractiveGeometryViewer::InteractiveGeometryViewer(QString name) : InteractiveViewer(name, InteractiveViewer::GEOMETRY_VIEWER) { + if (name == "3DViewer") { + // Axial Viewer + setLayout(Viewer::EMBEDDED); + } } // -------------------- Destructor -------------------- InteractiveGeometryViewer::~InteractiveGeometryViewer() { -} \ No newline at end of file +} diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h index 4dedc1b5..c9a6e554 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h @@ -27,10 +27,10 @@ #ifndef INTERACTIVEGEOMETRYVIEWER_H #define INTERACTIVEGEOMETRYVIEWER_H - // -- Core stuff #include "InteractiveGeometryViewerAPI.h" -#include "ViewerExtension.h" -#include "InteractiveViewer.h" + +// -- Core stuff +#include // -- QT stuff #include diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp index d2c0bd8d..60596439 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp @@ -31,7 +31,6 @@ // --------------- getViewers ------------------- void InteractiveGeometryViewerExtension::init() { - qRegisterMetaType("InteractiveGeometryViewer"); registerNewViewer(InteractiveGeometryViewer, "3DViewer"); } diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h index 73ea030d..b189ace7 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.h @@ -29,7 +29,8 @@ #include "InteractiveGeometryViewerAPI.h" -#include "ViewerExtension.h" +//-- from CamiTK Core +#include class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewerExtension : public camitk::ViewerExtension { Q_OBJECT diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp index 9751f4d6..f3c0115b 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.cpp @@ -26,15 +26,53 @@ // -- Core stuff #include "InteractiveSliceViewer.h" #include +#include using namespace camitk; // -------------------- Constructor -------------------- -InteractiveSliceViewer::InteractiveSliceViewer(QString name) : InteractiveViewer(name, InteractiveViewer::SLICE_VIEWER) -{ +InteractiveSliceViewer::InteractiveSliceViewer(QString name) : InteractiveViewer(name, InteractiveViewer::SLICE_VIEWER) { + if (name == "axialViewer") { + // Axial Viewer + setLayout(Viewer::EMBEDDED); + getRendererWidget()->setCameraOrientation(RendererWidget::RIGHT_DOWN); + QString letters[4] = { QString("R"), QString("L"), QString("A"), QString("P") }; + getRendererWidget()->setOrientationDecorationsLetters(letters); + toggleOrientationDecorations(true); + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else { + if (name == "coronalViewer") { + // Coronal Viewer + setLayout(Viewer::EMBEDDED); + getRendererWidget()->setCameraOrientation(RendererWidget::LEFT_BACK); + QString letters[4] = { QString("R"), QString("L"), QString("S"), QString("I") }; + getRendererWidget()->setOrientationDecorationsLetters(letters); + toggleOrientationDecorations(true); + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else { + if (name == "sagittalViewer") { + // Sagittal Viewer + setLayout(Viewer::EMBEDDED); + getRendererWidget()->setCameraOrientation(RendererWidget::BACK_DOWN); + QString letters[4] = { QString("A"), QString("P"), QString("S"), QString("I") }; + getRendererWidget()->setOrientationDecorationsLetters(letters); + toggleOrientationDecorations(true); + getRendererWidget()->getActiveCamera()->ParallelProjectionOn(); + } + else { + if (name == "arbitraryViewer") { + // Arbitrary Viewer + setLayout(Viewer::EMBEDDED); + toggleOrientationDecorations(false); + } + } + } + } } // -------------------- Destructor -------------------- InteractiveSliceViewer::~InteractiveSliceViewer() { -} \ No newline at end of file +} diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h index 447c6a8a..c059a5db 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h @@ -27,10 +27,10 @@ #ifndef INTERACTIVESLICEVIEWER_H #define INTERACTIVESLICEVIEWER_H -// -- Core stuff #include "InteractiveSliceViewerAPI.h" -#include "ViewerExtension.h" -#include "InteractiveViewer.h" + +// -- Core stuff +#include // -- QT stuff #include diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h index 204f6028..f08f5667 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewerExtension.h @@ -29,7 +29,8 @@ #include "InteractiveSliceViewerAPI.h" -#include "ViewerExtension.h" +//-- from CamiTK Core +#include class INTERACTIVESLICEVIEWER_API InteractiveSliceViewerExtension : public camitk::ViewerExtension { Q_OBJECT diff --git a/sdk/viewers/medicalimageviewer/CMakeLists.txt b/sdk/viewers/medicalimageviewer/CMakeLists.txt index 670aec8d..eb96dc84 100644 --- a/sdk/viewers/medicalimageviewer/CMakeLists.txt +++ b/sdk/viewers/medicalimageviewer/CMakeLists.txt @@ -2,6 +2,7 @@ camitk_extension(VIEWER_EXTENSION CEP_NAME SDK DEFINES COMPILE_MEDICALIMAGEVIEWER_API + NEEDS_VIEWER_EXTENSION interactivesliceviewer interactivegeometryviewer DESCRIPTION "An extension for the viewer that display GUI action" INSTALL_ALL_HEADERS ) diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp index ed2d0274..0054bcbe 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.cpp @@ -52,7 +52,9 @@ MedicalImageViewer::MedicalImageViewer(QString name) : Viewer(name) { autoUpdateToolbarVisibility = true; - setComponents(QStringList() << "ImageComponent"); + /* + setComponents(QStringList() << "ImageComponent" << "MeshComponent"); + */ } @@ -100,9 +102,10 @@ void MedicalImageViewer::refresh(Viewer* whoIsAsking) { } // -------------------- getWidget -------------------- -QWidget* MedicalImageViewer::getWidget(QWidget* parent) { +QWidget* MedicalImageViewer::getWidget() { if (!frame) { - frame = new QFrame(parent); + frame = new QFrame(); + frame->setObjectName("MedicalImageViewer Frame"); frame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); //-- init layout @@ -125,12 +128,19 @@ QWidget* MedicalImageViewer::getWidget(QWidget* parent) { viewers.insert(VIEWER_CORONAL, Application::getViewer("coronalViewer")); viewers.insert(VIEWER_SAGITTAL, Application::getViewer("sagittalViewer")); - topLeftLayout = new QVBoxLayout(); - frameLayout->addLayout(topLeftLayout, 0, 0); - topLeftLayout->addWidget(Application::getViewer("axialViewer")->getWidget(frame)); // equivalent of addWidget(Application::getViewer("axialViewer")->getWidget(frame), 0, 0) = north-west - frameLayout->addWidget(Application::getViewer("coronalViewer")->getWidget(frame), 1, 0); // north-east - frameLayout->addWidget(Application::getViewer("sagittalViewer")->getWidget(frame), 1, 1); // south-west - frameLayout->addWidget(Application::getViewer("3DViewer")->getWidget(frame), 0, 1); // south-east + /// the layout for the arbitrary/axial at the top left position of frameLayout + QVBoxLayout* innerLayout = new QVBoxLayout(); + frameLayout->addLayout(innerLayout, 0, 0); // north-west + Application::getViewer("axialViewer")->embedIn(innerLayout); + innerLayout = new QVBoxLayout(); + frameLayout->addLayout(innerLayout, 1, 0); // south-west + Application::getViewer("coronalViewer")->embedIn(innerLayout); + innerLayout = new QVBoxLayout(); + frameLayout->addLayout(innerLayout, 1, 1); // south-east + Application::getViewer("sagittalViewer")->embedIn(innerLayout); + innerLayout = new QVBoxLayout(); + frameLayout->addLayout(innerLayout, 0, 1); // north-east + Application::getViewer("3DViewer")->embedIn(innerLayout); //-- connect foreach (LayoutVisibility v, viewerVisibility) { @@ -211,18 +221,18 @@ void MedicalImageViewer::updateLayout() { } if (visibleLayout == VIEWER_ALL) { - viewers.value(VIEWER_3D)->getWidget(frame)->show(); - viewers.value(VIEWER_AXIAL)->getWidget(frame)->show(); - viewers.value(VIEWER_CORONAL)->getWidget(frame)->show(); - viewers.value(VIEWER_SAGITTAL)->getWidget(frame)->show(); - viewers.value(VIEWER_ARBITRARY)->getWidget(frame)->hide(); + viewers.value(VIEWER_3D)->setVisible(true); + viewers.value(VIEWER_AXIAL)->setVisible(true); + viewers.value(VIEWER_CORONAL)->setVisible(true); + viewers.value(VIEWER_SAGITTAL)->setVisible(true); + viewers.value(VIEWER_ARBITRARY)->setVisible(false); } else { for (unsigned int i = 0; viewerVisibility[i] != VIEWER_ALL; i++) { - viewers.value(viewerVisibility[i])->getWidget(frame)->hide(); + viewers.value(viewerVisibility[i])->setVisible(false); } - viewers.value(visibleLayout)->getWidget(frame)->show(); + viewers.value(visibleLayout)->setVisible(true); } if (autoUpdateToolbarVisibility) { diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h index a6075bee..ecf11192 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h @@ -27,10 +27,10 @@ #ifndef MEDICAL_IMAGE_VIEWER_H #define MEDICAL_IMAGE_VIEWER_H -// -- Core stuff #include "MedicalImageViewerAPI.h" -#include "ViewerExtension.h" -#include "Viewer.h" + +// -- Core stuff +#include // -- QT stuff #include @@ -82,8 +82,8 @@ public: /// refresh the view (can be interesting to know which other viewer is calling this) void refresh(Viewer* whoIsAsking = nullptr) override; - /// get the viewer widget. @param parent the parent widget for the viewer widget - QWidget* getWidget(QWidget* parent = nullptr) override; + /// get the viewer widget. + QWidget* getWidget() override; /// get the propertyObject (only the 3D Scene one) QObject* getPropertyObject() override; @@ -118,9 +118,6 @@ private: /// The main layout QGridLayout* frameLayout; - /// the layout for the arbitrary/axial at the top left position of frameLayout - QVBoxLayout* topLeftLayout; - /// the main widget QFrame* frame; diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp index 31c915f8..2be66e45 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void MedicalImageViewerExtension::init() { - registerNewViewer(MedicalImageViewer, "MedicalImageViewer"); + registerDefaultViewer(MedicalImageViewer); } diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h index 208b7a94..5cb0a9e5 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewerExtension.h @@ -29,7 +29,8 @@ #include "MedicalImageViewerAPI.h" -#include "ViewerExtension.h" +// -- from CamiTK Core +#include class MEDICALIMAGEVIEWER_API MedicalImageViewerExtension : public camitk::ViewerExtension { Q_OBJECT diff --git a/sdk/viewers/propertyexplorer/PropertyExplorer.cpp b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp index e3508b3a..76960efd 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorer.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.cpp @@ -23,10 +23,11 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ -// -- Core stuff -#include "Application.h" #include "PropertyExplorer.h" -#include "Component.h" + +// -- Core stuff +#include +#include // -- QT stuff #include @@ -39,6 +40,7 @@ using namespace camitk; // ---------------- constructor ---------------- PropertyExplorer::PropertyExplorer(QString name) : Viewer(name) { + setLayout(Viewer::DOCKED); theController = nullptr; tabWidget = nullptr; revertButton = nullptr; @@ -51,12 +53,10 @@ PropertyExplorer::PropertyExplorer(QString name) : Viewer(name) { // ---------------- destructor ---------------- PropertyExplorer::~PropertyExplorer() { clear(); - /*if (propertyObject != nullptr) { - delete propertyObject; + + if (propertyObject != nullptr) { + delete propertyObject; // this will also delete viewModeProperty } - if (viewModeProperty != nullptr) { - delete viewModeProperty; - }*/ } // ---------------- numberOfViewedComponent ---------------- @@ -82,13 +82,16 @@ void PropertyExplorer::refresh(Viewer* whoIsAsking) { currentComponent->setVisibility(this, true); //-- get the property widgets QWidget* customWidget; + for (unsigned int i = 0; i < currentComponent->getNumberOfPropertyWidget(); i++) { customWidget = currentComponent->getPropertyWidgetAt(i); + if (customWidget) { tabWidget->addTab(customWidget, customWidget->objectName()); } } } + //-- update the property editor // first clear all (otherwise if a new dynamic properties was added, it won't show) theController->setObject(nullptr); @@ -113,13 +116,13 @@ void PropertyExplorer::refresh(Viewer* whoIsAsking) { } // ---------------- getWidget ---------------- -QWidget* PropertyExplorer::getWidget(QWidget* parent) { +QWidget* PropertyExplorer::getWidget() { if (tabWidget == nullptr) { - tabWidget = new QTabWidget(parent); + tabWidget = new QTabWidget(); tabWidget->setWindowTitle(tr("Property Tabs")); // create the property editor tab itself - auto* propertyFrame = new QFrame; + auto* propertyFrame = new QFrame(); auto* propertyTabLayout = new QVBoxLayout; propertyTabLayout->setSpacing(2); propertyTabLayout->setMargin(2); @@ -135,8 +138,8 @@ QWidget* PropertyExplorer::getWidget(QWidget* parent) { propertyTabLayout->addWidget(theController); // then the buttons - auto* buttonFrame = new QFrame(parent); - auto* buttonLayout = new QHBoxLayout; + auto* buttonFrame = new QFrame(); + auto* buttonLayout = new QHBoxLayout(); applyButton = new QPushButton("Apply"); buttonLayout->addWidget(applyButton); @@ -174,14 +177,17 @@ QObject* PropertyExplorer::getPropertyObject() { // ---------------- clear ---------------- void PropertyExplorer::clear() { - // page #0 is the property widget (not be counted) - for (int i = tabWidget->count() - 1; i > 0; i--) { - tabWidget->removeTab(i); - } - - if (currentComponent && Application::isAlive(currentComponent)) { + if (tabWidget != nullptr) { + // page #0 is the property widget (not to be counted) + for (int i = tabWidget->count() - 1; i > 0; i--) { + tabWidget->removeTab(i); + } + } + + if (currentComponent != nullptr && Application::isAlive(currentComponent)) { currentComponent->setVisibility(this, false); } + currentComponent = nullptr; } @@ -189,8 +195,10 @@ void PropertyExplorer::clear() { void PropertyExplorer::selectWidget(QWidget* widget) { // get the last component tab widgets QWidget* customWidget; + for (int i = 0; i < this->tabWidget->count(); i++) { customWidget = this->tabWidget->widget(i); + if (customWidget && (customWidget == widget)) { this->tabWidget->setCurrentWidget(widget); return; @@ -260,4 +268,4 @@ void PropertyExplorer::createProperties() { // ---------------- createProperties ---------------- void PropertyExplorer::refreshAll() { Application::refresh(); -} \ No newline at end of file +} diff --git a/sdk/viewers/propertyexplorer/PropertyExplorer.h b/sdk/viewers/propertyexplorer/PropertyExplorer.h index a8383202..1a5d9866 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorer.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.h @@ -28,13 +28,11 @@ #include "PropertyExplorerAPI.h" // -- Core stuff -#include "ViewerExtension.h" -#include "Viewer.h" -#include "ObjectController.h" -#include "PropertyObject.h" +#include +#include +#include // -- QT stuff -#include #include #include #include @@ -45,7 +43,7 @@ class QPushButton; class QWidget; namespace camitk { - class ObjectController; +class ObjectController; } /** @@ -91,10 +89,10 @@ public: */ ///@{ /// constructor - PropertyExplorer(QString name); + PropertyExplorer(QString name); - /// destructor - ~PropertyExplorer() override; + /// destructor + ~PropertyExplorer() override; /** @name Inherited from Viewer */ @@ -105,8 +103,8 @@ public: /// refresh the property editor void refresh(camitk::Viewer* whoIsAsking = nullptr) override; - /// get the viewer widget. @param parent the parent widget for the viewer widget - QWidget* getWidget(QWidget* parent = nullptr) override; + /// get the viewer widget. + QWidget* getWidget() override; /// add a property to change the ObjectController representation at run-time (user choice) QObject* getPropertyObject() override; @@ -131,13 +129,13 @@ public: private: /// the widgets - camitk::ObjectController* theController; + camitk::ObjectController* theController; QTabWidget* tabWidget; QPushButton* revertButton; QPushButton* applyButton; /// the viewed Component - camitk::Component* currentComponent; + camitk::Component* currentComponent; /** * @name CamiTK Properties of this viewer @@ -146,12 +144,12 @@ private: /** * The property object that holds the properties of this viewer */ - camitk::PropertyObject* propertyObject; + camitk::PropertyObject* propertyObject; /** * The CamiTK property that stands for the ObjectController view mode. */ - camitk::Property* viewModeProperty; + camitk::Property* viewModeProperty; /** * Event filter of this class instance to watch its properties instances. diff --git a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp index f833a9aa..bed2a8ca 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp +++ b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getViewers ------------------- void PropertyExplorerExtension::init() { - registerNewViewer(PropertyExplorer, "PropertyExplorer"); + registerDefaultViewer(PropertyExplorer); } diff --git a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h index af20bb84..d69aa3bd 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorerExtension.h @@ -29,7 +29,8 @@ #include "PropertyExplorerAPI.h" -#include "ViewerExtension.h" +//-- Core +#include class PROPERTYEXPLORER_API PropertyExplorerExtension : public camitk::ViewerExtension { Q_OBJECT diff --git a/tutorials/applications/fancy/main.cpp b/tutorials/applications/fancy/main.cpp index e5d7b176..bb02152f 100644 --- a/tutorials/applications/fancy/main.cpp +++ b/tutorials/applications/fancy/main.cpp @@ -40,7 +40,8 @@ int main(int argc, char* argv[]) { a.setStyleSheet(style); // set the main window using the Fancy class - a.setMainWindow(new FancyMainWindow()); + FancyMainWindow* fancyMainWindow = new FancyMainWindow(); + a.setMainWindow(fancyMainWindow); // start by opening a mha Application::open(Core::getTestDataDir() + "/brain.mha"); diff --git a/tutorials/applications/menubar/main.cpp b/tutorials/applications/menubar/main.cpp index 0d1d7a8b..8568be5d 100644 --- a/tutorials/applications/menubar/main.cpp +++ b/tutorials/applications/menubar/main.cpp @@ -35,7 +35,8 @@ using namespace camitk; int main(int argc, char* argv[]) { Application a("menubar-tutorial", argc, argv); - a.setMainWindow(new MyAppMainWindow()); + MyAppMainWindow* myAppMainWindow = new MyAppMainWindow() + a.setMainWindow(myAppMainWindow); Application::open(Core::getTestDataDir() + "/brain.mha"); diff --git a/tutorials/applications/simple/main.cpp b/tutorials/applications/simple/main.cpp index 44fd1134..c9bd3533 100644 --- a/tutorials/applications/simple/main.cpp +++ b/tutorials/applications/simple/main.cpp @@ -34,8 +34,9 @@ using namespace camitk; int main(int argc, char* argv[]) { Application a("simple", argc, argv); - - a.setMainWindow(new SimpleMainWindow()); + + SimpleMainWindow* simpleMainWindow = new SimpleMainWindow(); + a.setMainWindow(simpleMainWindow); Application::open(Core::getTestDataDir() + "/brain.mha"); diff --git a/tutorials/viewers/textviewer/TextViewer.cpp b/tutorials/viewers/textviewer/TextViewer.cpp index a1f26b1f..c149fafe 100644 --- a/tutorials/viewers/textviewer/TextViewer.cpp +++ b/tutorials/viewers/textviewer/TextViewer.cpp @@ -73,16 +73,16 @@ void TextViewer::refresh(Viewer* whoIsAsking) { } // -------------------- getWidget -------------------- -QWidget* TextViewer::getWidget(QWidget* parent) { +QWidget* TextViewer::getWidget() { if (!myWidget) { - myWidget = new QWidget(parent); - output = new QTextEdit; + myWidget = new QWidget(); + output = new QTextEdit(); textColor = Qt::blue; bgColor = Qt::white; updateColors(); //-- init layout - auto* myWidgetLayout = new QHBoxLayout; + auto* myWidgetLayout = new QHBoxLayout(); myWidgetLayout->setSpacing(0); myWidgetLayout->setMargin(0); diff --git a/tutorials/viewers/textviewer/TextViewer.h b/tutorials/viewers/textviewer/TextViewer.h index 2a15d3e0..4e68eb28 100644 --- a/tutorials/viewers/textviewer/TextViewer.h +++ b/tutorials/viewers/textviewer/TextViewer.h @@ -74,8 +74,8 @@ public: /// refresh the view (can be interesting to know which other viewer is calling this) virtual void refresh(Viewer* whoIsAsking = nullptr); - /// get the viewer widget. @param parent the parent widget for the viewer widget - virtual QWidget* getWidget(QWidget* parent = nullptr); + /// get the viewer widget. + virtual QWidget* getWidget(); /// get the propertyObject (only the 3D Scene one) virtual QObject* getPropertyObject(); diff --git a/tutorials/viewers/textviewer/TextViewerExtension.cpp b/tutorials/viewers/textviewer/TextViewerExtension.cpp index 25954ef3..7572ce49 100644 --- a/tutorials/viewers/textviewer/TextViewerExtension.cpp +++ b/tutorials/viewers/textviewer/TextViewerExtension.cpp @@ -31,6 +31,6 @@ // --------------- getActions ------------------- void TextViewerExtension::init() { - registerNewViewer(TextViewer, "TextViewer"); + registerDefaultViewer(TextViewer); } -- GitLab From 42fcadc930f7da94287b796c1be774255da5be6d Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Tue, 4 Feb 2020 10:06:03 +0100 Subject: [PATCH 18/26] FIXED manage viewer icon (first example with explorer) --- sdk/applications/imp/ImpMainWindow.cpp | 36 +--------- sdk/libraries/core/viewer/Viewer.cpp | 66 ------------------ sdk/viewers/explorer/Explorer.cpp | 1 + sdk/viewers/explorer/ExplorerExtension.cpp | 6 ++ sdk/viewers/explorer/ExplorerExtension.h | 34 ++++----- .../explorer/ExplorerExtensionIcons.qrc | 5 ++ .../explorer/resources/folder-orange.png | Bin 0 -> 5026 bytes 7 files changed, 32 insertions(+), 116 deletions(-) create mode 100644 sdk/viewers/explorer/ExplorerExtensionIcons.qrc create mode 100644 sdk/viewers/explorer/resources/folder-orange.png diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 420a7dc2..59fe7030 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -225,8 +225,7 @@ void ImpMainWindow::initActions() { } -//************************************************************************** - +// ------------- initMenuBar ----------------- void ImpMainWindow::initMenuBar() { // -- file fileMenu = new QMenu(tr("&File")); @@ -516,6 +515,7 @@ void ImpMainWindow::updateViewMenu() { QAction* viewerAction = toggleCentralWidgetMenu->addAction(viewer->getName()); viewerAction->setCheckable(true); viewerAction->setChecked(viewer == centralViewer); + viewerAction->setIcon(viewer->getIcon()); QString tipString = "Hide/show the " + viewer->objectName() + " in the central viewer"; viewerAction->setStatusTip(tr(tipString.toStdString().c_str())); viewerAction->setWhatsThis(tr(tipString.toStdString().c_str())); @@ -525,37 +525,6 @@ 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. - auto it = std::find_if(viewers.begin(), viewers.end(), [&](Viewer * v) { - return v->getWidget() == 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 QMenu* toggleDockedMenu = viewMenu->addMenu(tr("Toggle Docked Viewers")); @@ -563,6 +532,7 @@ void ImpMainWindow::updateViewMenu() { toggleDockedMenu->addAction(viewResetWindows); for (QMap::iterator it = dockWidgetMap.begin(); it != dockWidgetMap.end(); it++) { + it.value()->toggleViewAction()->setIcon(it.key()->getIcon()); toggleDockedMenu->addAction(it.value()->toggleViewAction()); } diff --git a/sdk/libraries/core/viewer/Viewer.cpp b/sdk/libraries/core/viewer/Viewer.cpp index 77a13d5a..c4fae204 100644 --- a/sdk/libraries/core/viewer/Viewer.cpp +++ b/sdk/libraries/core/viewer/Viewer.cpp @@ -107,72 +107,6 @@ bool Viewer::getToolBarVisibility() { return toolbarVisibility; } -/* TODO CLEANUP -//---------------------- setAsCentralViewerAction ------------------------ -QAction* Viewer::setAsCentralViewerAction() { - if (setAsCentralViewerQAction == nullptr) { - // create the corresponding QAction (using the icon, name and descriptions) - setAsCentralViewerQAction = new QAction(getIcon(), getName(), this); - setAsCentralViewerQAction->setStatusTip(getDescription()); - setAsCentralViewerQAction->setWhatsThis(getName() + "\n" + getDescription()); - // connect it to the trigger slot - connect(setAsCentralViewerQAction, SIGNAL(triggered), this, SLOT(setAsCentralViewer())); - } - - //updateDisplayInCentralViewerQAction(); - - return setAsCentralViewerQAction; -} -*/ -/* -// -------------------- updateDisplayInCentralViewerQAction -------------------- -void Viewer::updateDisplayInCentralViewerQAction() { - if (displayInCentralViewerQAction != nullptr) { - // update QAction state: check if the current viewer is the central viewer - displayInCentralViewerQAction->blockSignals(true); - //bug: this cannot be called before the main window is completely defined - //otherwise another default window will be create and capture all output - //displayInCentralViewerQAction->setChecked(Application::getMainWindow()->getCentralViewer() == this); - displayInCentralViewerQAction->blockSignals(false); - } -} -*/ -/* -// -------------------- setAsCentralViewer -------------------- -void Viewer::setAsCentralViewer() { - Application::getMainWindow()->setCentralViewer(this); - refresh(this); -} -*/ - -/* -// -------------------- setDefaultParentWidget -------------------- -void Viewer::setDefaultParentWidget(QWidget* parent) { - defaultParentWidget = parent; -} - -// -------------------- switchParentWidget -------------------- -void Viewer::switchParentWidget(QWidget* parent) { - if (defaultParentWidget == nullptr) { - // this method was called before setDefaultParentWidget: parent is the default parent widget - setDefaultParentWidget(parent); - } - - if (getWidget()->parentWidget() != parent) { - bool isVisible = getWidget()->isVisible(); - getWidget()->setParent(parent); - getWidget()->setVisible(isVisible); - } - - updateDisplayInCentralViewerQAction(); -} - -// -------------------- resetParentWidget -------------------- -void Viewer::resetParentWidget() { - switchParentWidget(defaultParentWidget); -} -*/ - // -------------------- getLayout -------------------- Viewer::ViewerLayout Viewer::getLayout() { return layout; diff --git a/sdk/viewers/explorer/Explorer.cpp b/sdk/viewers/explorer/Explorer.cpp index 0c88864b..a6cb347c 100644 --- a/sdk/viewers/explorer/Explorer.cpp +++ b/sdk/viewers/explorer/Explorer.cpp @@ -45,6 +45,7 @@ using namespace camitk; //----------------------- constructor ------------------------ Explorer::Explorer(QString name) : Viewer(name) { setLayout(Viewer::DOCKED); + setIcon(QPixmap(":/explorer")); explorerTree = nullptr; explorerMenu = nullptr; } diff --git a/sdk/viewers/explorer/ExplorerExtension.cpp b/sdk/viewers/explorer/ExplorerExtension.cpp index 72fddb63..ad55d2ab 100644 --- a/sdk/viewers/explorer/ExplorerExtension.cpp +++ b/sdk/viewers/explorer/ExplorerExtension.cpp @@ -29,6 +29,12 @@ // include generated actions headers #include "Explorer.h" +// --------------- constructor ------------------- +ExplorerExtension::ExplorerExtension() : ViewerExtension() { + // initialize the icon resources + Q_INIT_RESOURCE(ExplorerExtensionIcons); +} + // --------------- getViewers ------------------- void ExplorerExtension::init() { registerDefaultViewer(Explorer); diff --git a/sdk/viewers/explorer/ExplorerExtension.h b/sdk/viewers/explorer/ExplorerExtension.h index e72cada3..175837ba 100644 --- a/sdk/viewers/explorer/ExplorerExtension.h +++ b/sdk/viewers/explorer/ExplorerExtension.h @@ -33,29 +33,29 @@ #include class EXPLORER_API ExplorerExtension : public camitk::ViewerExtension { - Q_OBJECT - Q_INTERFACES(camitk::ViewerExtension); - Q_PLUGIN_METADATA(IID "fr.imag.camitk.explorerextension.viewer.explorerextension") + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.explorerextension.viewer.explorerextension") public: - /// Constructor - ExplorerExtension() : ViewerExtension() {}; + /// Constructor + ExplorerExtension(); - /// Destructor - virtual ~ExplorerExtension() = default; + /// Destructor + virtual ~ExplorerExtension() = default; - /// Method returning the action extension name - virtual QString getName() { - return "Explorer Extension"; - }; + /// Method returning the action extension name + virtual QString getName() { + return "Explorer Extension"; + }; - /// Method returning the action extension descrption - virtual QString getDescription() { - return "An extension for the explorer"; - }; + /// Method returning the action extension descrption + virtual QString getDescription() { + return "An extension for the explorer"; + }; - /// initialize all the actions - virtual void init(); + /// initialize all the actions + virtual void init(); }; diff --git a/sdk/viewers/explorer/ExplorerExtensionIcons.qrc b/sdk/viewers/explorer/ExplorerExtensionIcons.qrc new file mode 100644 index 00000000..926bcbe0 --- /dev/null +++ b/sdk/viewers/explorer/ExplorerExtensionIcons.qrc @@ -0,0 +1,5 @@ + + + resources/folder-orange.png + + diff --git a/sdk/viewers/explorer/resources/folder-orange.png b/sdk/viewers/explorer/resources/folder-orange.png new file mode 100644 index 0000000000000000000000000000000000000000..f0e2b7a83fa5e209ea3dcbe73e474fbd310c2df3 GIT binary patch literal 5026 zcmWkydpr~B8}EGT*EnN}+FU1vaop1}nUQ-4rA{b!D~e-oP3E$b%Vf)4;$ZGMMcAT{ zal~RJb19j-O>DWfHrFM`-skf?f4uMWJn!>7@Ava&Ty}Mk{#EhULx&DYJ6^PP z7xN4Mk;GB)`utAhteE{0?e1WGsBuV{D;6XpE_y{DIuzdVAN?{uONNM*fEY&?JHXTt zNwC4M+FD(cS6J(D`RA1=3A)G@`hB5}V`rCV z5O*wYOcjm0x8hIK{FVx8;5Kky`<^h@br6GuDN3CcYZPtmmkJ=9=`@LbvWMdbcQB1jOwIi}cAq38FDe z;qt+vCBH6V=gonfWMTGEHKk`07n=v{+YcL z^+l9hE~Gc4O&>?+m8E&BYe49lRwiM2c|bMhz-gsI^{_V*%z->z$}ycDd$5&>>f^#J zl3SO#fu#U=(2Luh6AHR_p5O*!*Sc8u_eKXlmwHgfnb3_ig=h7*%Ok zZ^MV#uDVhLIhp%gBlt>~0)=^frcqV6hfWytSnCR$3m;;q6w}Pd@+xB&?QOvPM=J0m zZ?-;>hKxz&yFYsK`}=$OtwZ^*KE=`;QltT3Xk=jjDXm6%)z1#RDX@kALLZ)o45hu| zZEo|NyLT4rF@EH;S?mZXjF6_{CZ7rp&@t8upEPBRZNAzS5=+pDE6ms3qSc$-ydM7V zlgF(bkEu$7ootR0K{`^`i}IvlJ`HDm3y#$K7U-(}L35g!K__vxr*|z6ntJQ^N4w8h z?nC-Kgph+J%gJ&f+wz;KD9O~q3&~3D)i%kaY55hfWO0H8{HdIsg%);9!IK!ylL zW)0HtC2JCyL*KdpU&_7LuY5#0G}xk9zX5P(z`7WL#!?LZoK%Y#kpY!Tn9`WeI|Gh3 z@0Aykd|Q)LtdTr@$eW9YX*QH;gM9`U+CJCM5XILUI`aX08lsDxC+RH$xM!GL`}bRa z(Yi+D?3lB;Y5BV7r>J95409F;-U)+iN`!l&M)F3jxbLw3P_OM6jxmP9NrTQVWEfU@*y%eB7YWZ1Dce&Nh;-?NZJ? zgF-2*q2sw0M7RGb1k#m9uimc7HcJY za_yXn^B@niQOeq&BecjtdE#QRl73sj@s|4)051U^xXH>&%1Ap*Jbzhg`SEJ0$B9}v znpGX%mKTo=!n~qA^7ue((ZbxIjPagwRQL)|j+M-GwcvQqX+&@cClg-)y~NE*3k*sg zhOG)}e2>(sHV0HAUUD2E(Xs~C=m~OAr-Hyf#SkDTTTtq|HhXRDsfX@fY9{u|cpCE| zM2+Zu9zO2su!TU9=qh@R6UAy9MFw!i?nQ?sud`?CCInkbflt~A zHXRuy1%jMSUs<}o{f*Bf?U2N5#%a%;5EOJz9vSSuVSR+(iYv*0Z zVuub++IelP2GL5tG`mHhj#z#yDNU^gG-^p-Ra{aC=#)T4vaE@fDfxjQ!Wfa38ut{i zlEtopFF6qr?})>}lq)Bqhbv(wH*R-MQnk!}m$qwc<3B}Qy@G`Fc+-bUDOGG*6`cGj zl*>&RG?-~S;J9&27H#&o#)?-wEN3!J!y!C%>y<&sh9J$RdCTd}#?()@=XOQu&! z^U8c{5g7ve@H`*q>Au5M?8(}bFt**D@0T_tmK^_NeSZp$Xh3{Zzud}$UC@f$ zQjPDY`mcX*Uj=A&7-z>UC)_5*SmXdP;_#Pjy-jG0?#&8uo96g?2K;FTqfMLI$cXLv zd_-n2he%RwDT3*G(_xc3pfFTRFLu7uh|w02P|>@qVq$=wU6~$uYCJhs|J6l7b+d2Y z+QtdPoHfcG%rrOj_;D)kQ|A+1Bu>t`GstxusrNFbF;AKp7Sl=3a#=!=BI}l|FkVW9 z9e0R?c(cW~aRe8J1I2Trh^MLKb*V_ngxunpG9%u)2-Y#?RuqhF21omwHpP&^d<`VW zuw+oq-u%9?hZO%&3WdInkVbS@LRBUVf)u=0gM0H4NoTf~vjZ=D<#O#QUwAY|9803yk&xyaWM4&)9 znc<#hzEZAe+0I}PD;s1A=dM@^hOH3d3s7nE~H;e28rgz?%<8oFFQo zJBnbpbAd>OyCIQoPLLTRK?Onu9n~MlQ6Q|FiX~zdOs-6>x1*Yq0pzFlq#Y$r8)?0O zAdq*OLyGgS$N$5-8~2BSxFgqQH=HFZC@%Hcqgz`3cADiXUn(xsj;`KrDP^Fl5z#EK zYf8$4Rj?G&xt6=?v8BDKcs!rrX6iN+995|lO?zfMY6$NzW?bT0ZCs|Ojn{vTSEO*P z=0^NIfozxFj-YUPZWF;v3-G#8Bki)I{+?H0D{@gZ z`*M2PJvX$VLJ31oh-n@sDvrYh#p`Aa6#wq_^INVT)A0V`Z9zUo3{KjbT$aQ5;pj6S ztEF{tzAc8ZIw(h_%;x5drhul>W{dLjJA**ub_}&!_}Sd6KUJa}oULV+-eVoWDtoE1 zH8DjgtEd)u$ASXH%y-SVq1Af}kR_wu;1)uE`XX#2!XdpimzH`j8z}nAB^rjDpte;A zBXS_ld~H}VF2+Pt(Q6*;a2E+%Wshs_fBRW7`B)-8+sZqvQpyW^L3M3 zSEs0nQ{qzI`Fim4i||W1t~XAqeOO6y(+2@!*>!SHX*mt&1gd=^=7;?Q*OS}~3=o1O z^$4;C1ZlgFhY;9|BsS-(OD>QqtNOco%Q$#$FVlcJNxi?lf7SAbO{A3BA{CyfiSRL{ zJI02Yb~-l4jpY}d?h37j@v6ioUue!x0qI*PvS?K{7%a^d5AyO9oC1n*qaKrUIDCSR zPkA?4xLhaBhR@F-VqIoC3)1X_{BX0BMN7gh43F z?TO+1Dr#Uj&5Cmp2=h9jopP^M33yfZ28HuL1%^@XBS!hs1H-k>b57fFjhUU?oJ^3H z;9q|mI=*K|%hQw_P!d_fySvSj5#{3g%6BqUF^C-Cc?AQfDh<#_YTJm59`DjR$Hj)= zEi5E0+CxkzhB3zt8U?;8fiT$2r;D9h)MxSZ2l3O*V=!68RdxA}0cj$st^cuij4OR& z-GbMBAe`%AOi_1OO5Llw+jHKGvbfteR0;e&hPm_lXX%m#8wSFgZujG##0rgAfwQhu zoP*4gzuu8s_{4nZB+#pkJ}J;;a$bhL8JZ_SO%)n?4mVz6nha40IVv6@cp`_0IOkDSoY|a(WCZJgWJ(kLI;Rk{5H zYFZ->*K+`y##y_$m^`wsE=YlEQ|Iy0#MY6X!-UM!h}XfZW{ipAkyL$(5i#jOrUeTb z-HcI8J|CH$pI~iW{~DG+2o6^rpzd8zmB1PTW_Xw8a#?S!JDJoF%bo?;PtK87nd_it{!QY1y5#BJG zDc#?^UaV$0u=_|(X{MPy@4ZNBH$trZg5VEsX)gyW!?yrOLyc@8q02iLOx%|$HawN0 z+1_Crrd?^WQoF z#VnYT1HLS9??;W7%n(uhUG@k$?omQg9ZGIU7y=HvN)B*9;w#t(F@P#J4w-24vGQPr}Rq?_Wim-;CY(7@5DO z!hqXK^8#PKh^3Y-S3}-FaBOrUe@TT#OJQ`IiaZWJzz+g{s_|H=!k@T#88p4z=jQ%}JnGup=c(b7 zE#T3IH(s2QNFM%#&VXO()<{aXr#|l^-qo;5JYk?nd;Z&1NxJQCf4>^FKbjv>eA#`( z(DaGW>D6ZWeiLp*35Ph?aT8W_@AK!jR7D?f!u5ll)|Icjx@FVh!Huu!Yx4a}<^IJY zdgQoKe(`PlNwdkp9@J?5-z`;_O2!YIY1@4pCt9z6tG- Date: Tue, 4 Feb 2020 19:53:11 +0100 Subject: [PATCH 19/26] FIXED ViewerExtension factory --- .../core/viewer/InteractiveViewer.cpp | 38 +++++++++++-------- sdk/libraries/core/viewer/InteractiveViewer.h | 17 ++++----- sdk/libraries/core/viewer/ViewerExtension.cpp | 33 ++++++++++++---- sdk/libraries/core/viewer/ViewerExtension.h | 4 +- .../InteractiveGeometryViewer.cpp | 4 +- .../InteractiveGeometryViewer.h | 20 +++++----- .../InteractiveGeometryViewerAPI.h | 6 +-- .../InteractiveGeometryViewerExtension.cpp | 1 + 8 files changed, 76 insertions(+), 47 deletions(-) diff --git a/sdk/libraries/core/viewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/InteractiveViewer.cpp index 7c523a96..e1dcb2ae 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/InteractiveViewer.cpp @@ -83,10 +83,32 @@ namespace camitk { // ---------------------- constructor ---------------------------- -InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(name) { +InteractiveViewer::InteractiveViewer() : Viewer("default") { + myType = GEOMETRY_VIEWER; + init(); +} +InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(name) { myType = type; + init(); +} + +// ---------------------- destructor ---------------------------- +InteractiveViewer::~InteractiveViewer() { + + delete viewerMenu; + viewerMenu = nullptr; + + delete viewerToolbar; + viewerToolbar = nullptr; + + if (frame != nullptr) + delete frame; + frame = nullptr; +} +// ---------------------- init ---------------------------- +void InteractiveViewer::init() { // frame is NULL, but the rendererWidget and sliceSlider have to be instantiated // (even if the InteractiveViewer is not visible yet, it can still do some actions) frame = nullptr; @@ -140,20 +162,6 @@ InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(na } -// ---------------------- destructor ---------------------------- -InteractiveViewer::~InteractiveViewer() { - - delete viewerMenu; - viewerMenu = nullptr; - - delete viewerToolbar; - viewerToolbar = nullptr; - - if (frame != nullptr) - delete frame; - frame = nullptr; -} - // ---------------------- initSettings ---------------------------- void InteractiveViewer::initSettings() { QSettings& settings = Application::getSettings(); diff --git a/sdk/libraries/core/viewer/InteractiveViewer.h b/sdk/libraries/core/viewer/InteractiveViewer.h index 5b2f7def..df550cae 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/InteractiveViewer.h @@ -177,9 +177,11 @@ public: * @param type type of the InteractiveViewer, depending on which it will behave as slice viewer, i.e. with no rotation interactions are possible, or 3D viewer */ InteractiveViewer(QString& name, ViewerType type); - + + InteractiveViewer(); + /** Destructor */ - ~InteractiveViewer() override; + virtual ~InteractiveViewer() override; /// get the scene name QString getName() const; @@ -240,21 +242,16 @@ public: /// set background color virtual void setBackgroundColor(QColor); +public slots: /** @name Viewing/Interaction Property */ ///@{ -public slots: /// set the backface culling mode (default is true). void setBackfaceCulling(bool); /// visibility of the screenshot in slice viewers void setScreenshotAction(bool); -public: - /// get the backface current culling mode. - // bool getBackfaceCulling() const; - -public slots: /** Update the visualization of lines (for all the InterfaceGeometry of the scene). * * \note it is only possible to transform lines to tubes if @@ -276,7 +273,6 @@ public: return rendererWidget; } - ///@} /// @name Misc @@ -335,6 +331,9 @@ public slots: protected: + /// used by both constructors + void init(); + /** @name Display properties * * Properties that can be managed without the knowledge/intervention of the InterfaceGeometry: diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index 413cb79e..617ae786 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -126,16 +126,35 @@ Viewer* ViewerExtension::getNewInstance(QString name) { } // if the viewer does not already exist, instanciate it - // get the pointer to the viewer's class meta object + Viewer* viewer = nullptr; int typeId = QMetaType::type(viewerClassName.toStdString().c_str()); - const QMetaObject* metaObject = QMetaType::metaObjectForType(typeId); - // instanciate a new viewer of the managed class - QObject* o = metaObject->newInstance(Q_ARG(QString, name)); - Viewer* viewer = qobject_cast(o); + if (typeId != QMetaType::UnknownType) { + // get the pointer to the viewer's class meta object + const QMetaObject* metaObject = QMetaType::metaObjectForType(typeId); + + if (metaObject == nullptr) { + // If not working try the meta type create method + void* instance = QMetaType::create(typeId); + // this pointer is bad and uninitialized + viewer = static_cast(instance); + if (viewer == nullptr) { + CAMITK_ERROR(tr("Cannot get %1 metaObject nor use the QMetaType create method").arg(viewerClassName)); + } + } + else { + // instanciate a new viewer of the managed class + QObject* o = metaObject->newInstance(Q_ARG(QString, name)); + viewer = qobject_cast(o); + + // register it in the list + registerViewer(viewer); + } + } + else { + CAMITK_ERROR(tr("Cannot create new instance of %1: type not registered by Qt").arg(viewerClassName)); + } - // register it in the list - registerViewer(viewer); return viewer; } diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index 8eef2b77..d97fd6a1 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -14,10 +14,10 @@ class Viewer; /// register default viewer will use the class name to create a new viewer of the same name /// .replace(0, 1, QString(#__VA_ARGS__).at(0).toLower()) -#define registerDefaultViewer(...) registerViewer(new __VA_ARGS__(QString(#__VA_ARGS__))) +#define registerDefaultViewer(...) /*qRegisterMetaType<__VA_ARGS__>();*/registerViewer(new __VA_ARGS__(QString(#__VA_ARGS__))) /// register a new viewer, instance of X, its name is Y -#define registerNewViewer(X, Y) registerViewer(new X(QString(Y))) +#define registerNewViewer(X, Y) /*qRegisterMetaType();*/registerViewer(new X(QString(Y))) /** * @ingroup group_sdk_libraries_core_action diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp index 6cc57edc..314a6f56 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.cpp @@ -35,8 +35,8 @@ InteractiveGeometryViewer::InteractiveGeometryViewer(QString name) : Interactive setLayout(Viewer::EMBEDDED); } } - +/* CLEANUP // -------------------- Destructor -------------------- InteractiveGeometryViewer::~InteractiveGeometryViewer() { -} +}*/ diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h index c9a6e554..84d6e2f7 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h @@ -32,10 +32,6 @@ // -- Core stuff #include -// -- QT stuff -#include -#include - /** * @ingroup group_sdk_libraries_core_viewer * @@ -53,16 +49,22 @@ * */ class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewer : public camitk::InteractiveViewer { - Q_OBJECT + Q_OBJECT public: - Q_INVOKABLE InteractiveGeometryViewer(QString name); + InteractiveGeometryViewer() = default; + + Q_INVOKABLE InteractiveGeometryViewer(QString name); - /** destructor */ - ~InteractiveGeometryViewer() override; + InteractiveGeometryViewer(const InteractiveGeometryViewer & ) {}; + + /** destructor */ + ~InteractiveGeometryViewer() = default; }; -#endif +Q_DECLARE_METATYPE(InteractiveGeometryViewer); + +#endif // INTERACTIVEGEOMETRYVIEWER_H diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h index 76ec4de6..dfbfe450 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerAPI.h @@ -23,13 +23,13 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ -// ----- MEDICALIMAGEVIEWER_API_H.h +// ----- INTERACTIVEGEOMETRYVIEWER_API_H #ifndef INTERACTIVEGEOMETRYVIEWER_API_H #define INTERACTIVEGEOMETRYVIEWER_API_H // ----------------------------------------------------------------------- // -// MEDICALIMAGEVIEWER_API +// INTERACTIVEGEOMETRYVIEWER_API // // ----------------------------------------------------------------------- @@ -56,4 +56,4 @@ #endif // MSVC and mingw -#endif // INTERACTIVEGEOMETRYVIEWER_API_H \ No newline at end of file +#endif // INTERACTIVEGEOMETRYVIEWER_API_H diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp index 60596439..03d6eb3a 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp @@ -32,5 +32,6 @@ // --------------- getViewers ------------------- void InteractiveGeometryViewerExtension::init() { registerNewViewer(InteractiveGeometryViewer, "3DViewer"); + qRegisterMetaType(); } -- GitLab From 121c8e641aa3ab4c185cafc30f0b0cfdde4f6125 Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Tue, 4 Feb 2020 20:50:18 +0100 Subject: [PATCH 20/26] NEW Improve ViewerExtension factory + bug fix (double viewer delete) --- sdk/libraries/core/application/MainWindow.cpp | 8 +-- .../core/viewer/InteractiveViewer.cpp | 5 -- sdk/libraries/core/viewer/InteractiveViewer.h | 4 +- sdk/libraries/core/viewer/Viewer.h | 2 +- sdk/libraries/core/viewer/ViewerExtension.cpp | 57 ++++++++++++------- sdk/libraries/core/viewer/ViewerExtension.h | 50 +++++++++++++--- .../actionviewer/ActionViewerExtension.h | 34 +++++------ .../InteractiveGeometryViewer.h | 5 -- .../InteractiveGeometryViewerExtension.cpp | 7 +-- 9 files changed, 104 insertions(+), 68 deletions(-) diff --git a/sdk/libraries/core/application/MainWindow.cpp b/sdk/libraries/core/application/MainWindow.cpp index add81e0e..8c7847f1 100644 --- a/sdk/libraries/core/application/MainWindow.cpp +++ b/sdk/libraries/core/application/MainWindow.cpp @@ -176,11 +176,6 @@ MainWindow::MainWindow(QString title) { // ------------- destructor ----------------- MainWindow::~MainWindow() { - // delete all the viewers - while (!viewers.isEmpty()) { - delete viewers.takeFirst(); - } - delete consoleWindow; consoleWindow = nullptr; } @@ -407,8 +402,7 @@ void MainWindow::initSettings() { // get central viewer QString centralViewerName = settings.value("centralViewer", "").toString(); - CAMITK_INFO(tr("Found %1").arg(centralViewerName)) - + // if no specific name is found, just do nothing will use the one alread set in the central viewer by default if (centralViewerName != "") { setCentralViewer(Application::getViewer(centralViewerName)); } diff --git a/sdk/libraries/core/viewer/InteractiveViewer.cpp b/sdk/libraries/core/viewer/InteractiveViewer.cpp index e1dcb2ae..a371001f 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.cpp +++ b/sdk/libraries/core/viewer/InteractiveViewer.cpp @@ -83,11 +83,6 @@ namespace camitk { // ---------------------- constructor ---------------------------- -InteractiveViewer::InteractiveViewer() : Viewer("default") { - myType = GEOMETRY_VIEWER; - init(); -} - InteractiveViewer::InteractiveViewer(QString& name, ViewerType type) : Viewer(name) { myType = type; init(); diff --git a/sdk/libraries/core/viewer/InteractiveViewer.h b/sdk/libraries/core/viewer/InteractiveViewer.h index df550cae..072062e5 100644 --- a/sdk/libraries/core/viewer/InteractiveViewer.h +++ b/sdk/libraries/core/viewer/InteractiveViewer.h @@ -176,9 +176,7 @@ public: * @param name the name of the scene is mandatory, it is used as an identifier (e.g. in MedicalImageViewer) * @param type type of the InteractiveViewer, depending on which it will behave as slice viewer, i.e. with no rotation interactions are possible, or 3D viewer */ - InteractiveViewer(QString& name, ViewerType type); - - InteractiveViewer(); + Q_INVOKABLE InteractiveViewer(QString& name, ViewerType type); /** Destructor */ virtual ~InteractiveViewer() override; diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index e5c9e867..98ca058d 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -67,7 +67,7 @@ public: Viewer(QString name); /// default destructor - ~Viewer() override; + virtual ~Viewer() override; /// \enum ViewerLayout describes where this viewer should appear enum ViewerLayout { diff --git a/sdk/libraries/core/viewer/ViewerExtension.cpp b/sdk/libraries/core/viewer/ViewerExtension.cpp index 617ae786..f1b11da2 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.cpp +++ b/sdk/libraries/core/viewer/ViewerExtension.cpp @@ -37,7 +37,7 @@ namespace camitk { // -------------------- constructor -------------------- ViewerExtension::ViewerExtension() { - viewerClassName = nullptr; + managedMetaObject = nullptr; translator = nullptr; } @@ -45,11 +45,10 @@ ViewerExtension::ViewerExtension() { ViewerExtension::~ViewerExtension() { while (!viewers.empty()) { Viewer* toDelete = viewers.takeFirst(); - // do not delete the "Quit" action: it is the action that triggers this delete! delete toDelete; } - //delete internationalization instance + // delete internationalization instance if (translator) { delete translator; } @@ -89,26 +88,35 @@ QString ViewerExtension::getLocation() const { // -------------------- getViewerClassName -------------------- QString ViewerExtension::getViewerClassName() { - return viewerClassName; + if (managedMetaObject == nullptr) { + return ""; + } + else { + return managedMetaObject->className(); + } } -// -------------------- registerViewer -------------------- -void ViewerExtension::registerViewer(Viewer* viewer) { - // first call, get the viewer class name - if (viewerClassName == nullptr) { - viewerClassName = viewer->metaObject()->className(); +// -------------------- setManagedMetaObject -------------------- +void ViewerExtension::setManagedMetaObject(const QMetaObject* metaObject) { + // first call, set the viewer class meta object + if (managedMetaObject == nullptr) { + managedMetaObject = metaObject; } - else { - // only one type of viewer is managed by a viewer extension - if (viewerClassName != viewer->metaObject()->className()) { - CAMITK_ERROR(tr("Cannot register viewer \"%1\" as it is an instance of \"%2\" (extension \"%3\" only manages the \"%4\" viewer class)").arg(viewer->getName()).arg(viewer->metaObject()->className()).arg(getName()).arg(viewerClassName)) - return; - } +} + +// -------------------- registerViewer -------------------- +bool ViewerExtension::registerViewer(Viewer* viewer) { + // only one type of viewer is managed by a viewer extension + if (getViewerClassName() != viewer->metaObject()->className()) { + CAMITK_ERROR(tr("Cannot register viewer \"%1\" as it is an instance of \"%2\" (extension \"%3\" only manages the \"%4\" viewer class)").arg(viewer->getName()).arg(viewer->metaObject()->className()).arg(getName()).arg(getViewerClassName())) + return false; } // simply add the viewer in the list viewers.append(viewer); + // all OK + return true; } // -------------------- getNewInstance -------------------- @@ -126,7 +134,17 @@ Viewer* ViewerExtension::getNewInstance(QString name) { } // if the viewer does not already exist, instanciate it - Viewer* viewer = nullptr; + QObject *instance = managedMetaObject->newInstance(Q_ARG(QString, name)); // add constructor arguments as needed + Viewer* viewerInstance = qobject_cast(instance); + + if (viewerInstance != nullptr) { + // register it in the list + registerViewer(viewerInstance); + } + else { + CAMITK_ERROR(tr("Cannot instanciate %1 from static meta object").arg(getViewerClassName())); + } +/*CLEANUP int typeId = QMetaType::type(viewerClassName.toStdString().c_str()); if (typeId != QMetaType::UnknownType) { @@ -138,9 +156,10 @@ Viewer* ViewerExtension::getNewInstance(QString name) { void* instance = QMetaType::create(typeId); // this pointer is bad and uninitialized viewer = static_cast(instance); + if (viewer == nullptr) { CAMITK_ERROR(tr("Cannot get %1 metaObject nor use the QMetaType create method").arg(viewerClassName)); - } + } } else { // instanciate a new viewer of the managed class @@ -154,9 +173,9 @@ Viewer* ViewerExtension::getNewInstance(QString name) { else { CAMITK_ERROR(tr("Cannot create new instance of %1: type not registered by Qt").arg(viewerClassName)); } +*/ - - return viewer; + return viewerInstance; } // -------------------- getViewers -------------------- diff --git a/sdk/libraries/core/viewer/ViewerExtension.h b/sdk/libraries/core/viewer/ViewerExtension.h index d97fd6a1..e7b7c616 100644 --- a/sdk/libraries/core/viewer/ViewerExtension.h +++ b/sdk/libraries/core/viewer/ViewerExtension.h @@ -1,3 +1,28 @@ +/***************************************************************************** +* $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 VIEWER_EXTENSION_H #define VIEWER_EXTENSION_H @@ -12,12 +37,17 @@ namespace camitk { class Viewer; +/// ViewerExtension implements a specific Factory pattern (@see getNewInstance) +/// Each time a viewer is registered, call setManagedMetaObject (the fist registered viewer will +/// register the managed class meta object that can be reused later on to instanciate new viewer) /// register default viewer will use the class name to create a new viewer of the same name -/// .replace(0, 1, QString(#__VA_ARGS__).at(0).toLower()) -#define registerDefaultViewer(...) /*qRegisterMetaType<__VA_ARGS__>();*/registerViewer(new __VA_ARGS__(QString(#__VA_ARGS__))) +/// \note #className surrounds macro argument with double quotes converting it to string +#define registerDefaultViewer(className) setManagedMetaObject(&className::staticMetaObject); \ + registerViewer(new className(QString(#className))) /// register a new viewer, instance of X, its name is Y -#define registerNewViewer(X, Y) /*qRegisterMetaType();*/registerViewer(new X(QString(Y))) +#define registerNewViewer(className, instanceName) setManagedMetaObject(&className::staticMetaObject); \ + registerViewer(new className(QString(instanceName))) /** * @ingroup group_sdk_libraries_core_action @@ -71,13 +101,18 @@ public: /// factory: create a new viewer instance and register it /// @return a new instance of the given name, or the previously registered instance if it already exist Viewer* getNewInstance(QString name); - + protected: /// register an viewer instance - void registerViewer(Viewer*); + /// The first call will also register the managed viewer class name in viewerClassName + /// and its static meta object in + bool registerViewer(Viewer*); /// the list of viewers ViewerList viewers; + + /// The first time this method is called, it sets the static meta object + void setManagedMetaObject(const QMetaObject*); private: /// the shared lib (.so, .dll or .dylib) used to instantiate the ComponentExtension subclass instance @@ -86,8 +121,8 @@ private: /// Provide internationalization support for text output. QTranslator* translator; - /// name of the viewer class managed by this extension - QString viewerClassName; + /// static meta object of the viewer class managed by this extension + const QMetaObject* managedMetaObject; }; } @@ -95,3 +130,4 @@ private: Q_DECLARE_INTERFACE(camitk::ViewerExtension, "TIMC-IMAG. Viewer Extension/2.1") //TODO use variable from CMake? #endif //VIEWER_EXTENSION_H + diff --git a/sdk/viewers/actionviewer/ActionViewerExtension.h b/sdk/viewers/actionviewer/ActionViewerExtension.h index fe67b40b..c8561c9c 100644 --- a/sdk/viewers/actionviewer/ActionViewerExtension.h +++ b/sdk/viewers/actionviewer/ActionViewerExtension.h @@ -33,29 +33,29 @@ #include class ACTIONVIEWER_API ActionViewerExtension : public camitk::ViewerExtension { - Q_OBJECT - Q_INTERFACES(camitk::ViewerExtension); - Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionviewerextension.viewer.actionviewerextension") + Q_OBJECT + Q_INTERFACES(camitk::ViewerExtension); + Q_PLUGIN_METADATA(IID "fr.imag.camitk.actionviewerextension.viewer.actionviewerextension") public: - /// Constructor - ActionViewerExtension() : ViewerExtension() {}; + /// Constructor + ActionViewerExtension() : ViewerExtension() {}; - /// Destructor - virtual ~ActionViewerExtension() = default; + /// Destructor + virtual ~ActionViewerExtension() = default; - /// Method returning the action extension name - virtual QString getName() { - return "Action Viewer Extension"; - }; + /// Method returning the action extension name + virtual QString getName() { + return "Action Viewer Extension"; + }; - /// Method returning the action extension descrption - virtual QString getDescription() { - return "actionViewer displays the currently selected action's GUI as well as a action selector"; - }; + /// Method returning the action extension descrption + virtual QString getDescription() { + return "actionViewer displays the currently selected action's GUI as well as a action selector"; + }; - /// initialize all the actions - virtual void init(); + /// initialize all the actions + virtual void init(); }; diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h index 84d6e2f7..0f434b71 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewer.h @@ -52,19 +52,14 @@ class INTERACTIVEGEOMETRYVIEWER_API InteractiveGeometryViewer : public camitk::I Q_OBJECT public: - - InteractiveGeometryViewer() = default; Q_INVOKABLE InteractiveGeometryViewer(QString name); - InteractiveGeometryViewer(const InteractiveGeometryViewer & ) {}; - /** destructor */ ~InteractiveGeometryViewer() = default; }; -Q_DECLARE_METATYPE(InteractiveGeometryViewer); #endif // INTERACTIVEGEOMETRYVIEWER_H diff --git a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp index 03d6eb3a..5b295e49 100644 --- a/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp +++ b/sdk/viewers/interactivegeometryviewer/InteractiveGeometryViewerExtension.cpp @@ -26,12 +26,11 @@ #include "InteractiveGeometryViewerExtension.h" - // include generated actions headers +// include generated actions headers #include "InteractiveGeometryViewer.h" - // --------------- getViewers ------------------- +// --------------- getViewers ------------------- void InteractiveGeometryViewerExtension::init() { - registerNewViewer(InteractiveGeometryViewer, "3DViewer"); - qRegisterMetaType(); + registerNewViewer(InteractiveGeometryViewer, "3DViewer"); } -- GitLab From df8120a3b50271f1c90d8dd41ff58d49ef94328b Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Tue, 4 Feb 2020 21:12:07 +0100 Subject: [PATCH 21/26] FIXED reorient image double delete + viewers cstor can be created from class static meta object --- sdk/actions/image/reorientimage/ReorientImage.cpp | 4 +--- sdk/actions/image/reorientimage/ReorientImage.h | 4 +--- sdk/actions/image/reorientimage/ReorientImage.ui | 12 ++++++------ .../actionstatemachine/ActionStateViewer.h | 2 +- sdk/viewers/actionviewer/ActionViewer.h | 2 +- sdk/viewers/bitmap/BitmapViewer.h | 2 +- sdk/viewers/explorer/Explorer.h | 2 +- sdk/viewers/frameexplorer/FrameExplorer.h | 2 +- .../interactivesliceviewer/InteractiveSliceViewer.h | 4 ++-- sdk/viewers/medicalimageviewer/MedicalImageViewer.h | 2 +- sdk/viewers/propertyexplorer/PropertyExplorer.h | 2 +- tutorials/viewers/textviewer/TextViewer.h | 2 +- 12 files changed, 18 insertions(+), 22 deletions(-) diff --git a/sdk/actions/image/reorientimage/ReorientImage.cpp b/sdk/actions/image/reorientimage/ReorientImage.cpp index 782d1603..a2fb0b30 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.cpp +++ b/sdk/actions/image/reorientimage/ReorientImage.cpp @@ -125,13 +125,11 @@ ReorientImage::~ReorientImage() { femaleModel = NULL; delete maleModel; maleModel = NULL; - delete dialog; - dialog = NULL; } // --------------- initDialog ------------------- void ReorientImage::initDialog() { - dialog = new QDialog(); + dialog = new QFrame(); //-- init user interface ui.setupUi(dialog); diff --git a/sdk/actions/image/reorientimage/ReorientImage.h b/sdk/actions/image/reorientimage/ReorientImage.h index 51c02872..dcd9de1e 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.h +++ b/sdk/actions/image/reorientimage/ReorientImage.h @@ -87,7 +87,7 @@ private: Ui::ReorientImage ui; /// the dialog - QDialog* dialog; + QFrame* dialog; /// axes actor vtkSmartPointer axes; @@ -109,8 +109,6 @@ private: QMap lettersMeaning; -// camitk::ImageComponent * img; - }; #endif // REORIENTIMAGE_H diff --git a/sdk/actions/image/reorientimage/ReorientImage.ui b/sdk/actions/image/reorientimage/ReorientImage.ui index 4371a993..b5c087d7 100644 --- a/sdk/actions/image/reorientimage/ReorientImage.ui +++ b/sdk/actions/image/reorientimage/ReorientImage.ui @@ -1,7 +1,7 @@ ReorientImage - + true @@ -9,7 +9,7 @@ 0 0 - 530 + 584 458 @@ -25,7 +25,7 @@ TransformDialog - + true @@ -86,7 +86,7 @@ - How was your image acquired ? + How was your image acquired? @@ -177,7 +177,7 @@ - Male + Ma&le @@ -196,7 +196,7 @@ - Reset Image Origin + Rese&t Image Origin diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.h b/sdk/applications/actionstatemachine/ActionStateViewer.h index 8d972ac1..6842232d 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.h +++ b/sdk/applications/actionstatemachine/ActionStateViewer.h @@ -47,7 +47,7 @@ class ActionStateViewer : public camitk::Viewer { public: - ActionStateViewer(QString name); + Q_INVOKABLE ActionStateViewer(QString name); /// get the viewer widget. virtual QWidget* getWidget(); diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index 8ede4795..e3d37653 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -63,7 +63,7 @@ public: */ ///@{ /// constructor - ActionViewer(QString name); + Q_INVOKABLE ActionViewer(QString name); /// destructor virtual ~ActionViewer(); diff --git a/sdk/viewers/bitmap/BitmapViewer.h b/sdk/viewers/bitmap/BitmapViewer.h index 57b08647..33f67971 100644 --- a/sdk/viewers/bitmap/BitmapViewer.h +++ b/sdk/viewers/bitmap/BitmapViewer.h @@ -42,7 +42,7 @@ class BITMAP_VIEWER_API BitmapViewer : public camitk::InteractiveViewer { Q_OBJECT public: - BitmapViewer(QString name); + Q_INVOKABLE BitmapViewer(QString name); virtual ~BitmapViewer() override; diff --git a/sdk/viewers/explorer/Explorer.h b/sdk/viewers/explorer/Explorer.h index ad3461cf..a337bac0 100644 --- a/sdk/viewers/explorer/Explorer.h +++ b/sdk/viewers/explorer/Explorer.h @@ -65,7 +65,7 @@ public: */ ///@{ /** Construtor */ - Explorer(QString); + Q_INVOKABLE Explorer(QString); /** Destructor */ ~Explorer() override; diff --git a/sdk/viewers/frameexplorer/FrameExplorer.h b/sdk/viewers/frameexplorer/FrameExplorer.h index 09cbac5c..f0e292b2 100644 --- a/sdk/viewers/frameexplorer/FrameExplorer.h +++ b/sdk/viewers/frameexplorer/FrameExplorer.h @@ -57,7 +57,7 @@ public: */ ///@{ /** Construtor */ - FrameExplorer(QString); + Q_INVOKABLE FrameExplorer(QString); /** Destructor */ ~FrameExplorer() override = default; diff --git a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h index c059a5db..bf0a5625 100644 --- a/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h +++ b/sdk/viewers/interactivesliceviewer/InteractiveSliceViewer.h @@ -59,7 +59,7 @@ class INTERACTIVESLICEVIEWER_API InteractiveSliceViewer : public camitk::Interac public: - InteractiveSliceViewer(QString); + Q_INVOKABLE InteractiveSliceViewer(QString); /** destructor */ ~InteractiveSliceViewer() override; @@ -67,5 +67,5 @@ public: }; -#endif +#endif // INTERACTIVESLICEVIEWER_H diff --git a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h index ecf11192..09a9efa4 100644 --- a/sdk/viewers/medicalimageviewer/MedicalImageViewer.h +++ b/sdk/viewers/medicalimageviewer/MedicalImageViewer.h @@ -68,7 +68,7 @@ public: VIEWER_ARBITRARY ///< Only the arbitrary InteractiveViewer are visible }; - MedicalImageViewer(QString); + Q_INVOKABLE MedicalImageViewer(QString); /** destructor */ ~MedicalImageViewer() override; diff --git a/sdk/viewers/propertyexplorer/PropertyExplorer.h b/sdk/viewers/propertyexplorer/PropertyExplorer.h index 1a5d9866..73a18394 100644 --- a/sdk/viewers/propertyexplorer/PropertyExplorer.h +++ b/sdk/viewers/propertyexplorer/PropertyExplorer.h @@ -89,7 +89,7 @@ public: */ ///@{ /// constructor - PropertyExplorer(QString name); + Q_INVOKABLE PropertyExplorer(QString name); /// destructor ~PropertyExplorer() override; diff --git a/tutorials/viewers/textviewer/TextViewer.h b/tutorials/viewers/textviewer/TextViewer.h index 4e68eb28..1b864c7b 100644 --- a/tutorials/viewers/textviewer/TextViewer.h +++ b/tutorials/viewers/textviewer/TextViewer.h @@ -59,7 +59,7 @@ public: */ /// @{ /** construtor. */ - TextViewer(QString name); + Q_INVOKABLE TextViewer(QString name); /** destructor */ virtual ~TextViewer(); -- GitLab From 386ea53ea6976915b0efad418fdf044e370d9fd4 Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Tue, 4 Feb 2020 21:20:44 +0100 Subject: [PATCH 22/26] FIXED imp menu bar can be set visible again (small annoying bug fixed) --- sdk/applications/imp/ImpMainWindow.cpp | 37 ++++++++++++-------------- sdk/applications/imp/ImpMainWindow.h | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/sdk/applications/imp/ImpMainWindow.cpp b/sdk/applications/imp/ImpMainWindow.cpp index 59fe7030..59130393 100644 --- a/sdk/applications/imp/ImpMainWindow.cpp +++ b/sdk/applications/imp/ImpMainWindow.cpp @@ -198,7 +198,7 @@ void ImpMainWindow::initActions() { // global shortcut, NOTE: the action should also be added as an ImpMainWindow action, otherwise the shortcut will not work when // the menu bar is hidden! (see initMenuBar() method) viewMenuBar->setShortcutContext(Qt::ApplicationShortcut); - connect(viewMenuBar, SIGNAL(triggered(bool)), this, SLOT(showMenuBar(bool))); + connect(viewMenuBar, SIGNAL(triggered()), this, SLOT(toggleMenuBar())); // NOTE: viewMenuBar can be used to hide the menu bar, if the menu bar is not visible, // since Qt4, it does not receive any event (and thus there is no way to set the menu // visible again! Which is quite annoying). @@ -359,22 +359,19 @@ void ImpMainWindow::showToolbar(bool b) { mainToolbar->setVisible(b); } -// ------------- showMenuBar ----------------- -void ImpMainWindow::showMenuBar(bool b) { - if (!b) { +// ------------- toggleMenuBar ----------------- +void ImpMainWindow::toggleMenuBar() { + bool menuBarVisible = menuBar()->isVisible(); + + if (menuBarVisible) { // warn the user first CAMITK_WARNING(tr("Hide menu: the menu is going to be hidden. There is only one way to make it reappear: you need to press CTRL+M again.")) - viewMenuBar->blockSignals(true); - viewMenuBar->setChecked(true); - viewMenuBar->blockSignals(false); - } - else { - menuBar()->setVisible(b); - viewMenuBar->blockSignals(true); - viewMenuBar->setChecked(b); - viewMenuBar->blockSignals(false); - showStatusBar(b); } + + menuBar()->setVisible(!menuBarVisible); + viewMenuBar->blockSignals(true); + viewMenuBar->setChecked(!menuBarVisible); + viewMenuBar->blockSignals(false); } // ------------- showStatusBar ----------------- @@ -423,7 +420,7 @@ void ImpMainWindow::resetWindows() { } showStatusBar(true); - showMenuBar(true); + menuBar()->setVisible(true); showToolbar(true); // reset geometry to default @@ -528,7 +525,7 @@ void ImpMainWindow::updateViewMenu() { // insert viewers on/off actions QMenu* toggleDockedMenu = viewMenu->addMenu(tr("Toggle Docked Viewers")); - + toggleDockedMenu->addAction(viewResetWindows); for (QMap::iterator it = dockWidgetMap.begin(); it != dockWidgetMap.end(); it++) { @@ -537,10 +534,10 @@ void ImpMainWindow::updateViewMenu() { } // insert generic on/off actions - viewMenu->addSeparator()->setText(tr("Other Toggle")); - viewMenu->addAction(viewMenuBar); - viewMenu->addAction(viewStatusBar); - viewMenu->addAction(mainToolbar->toggleViewAction()); + QMenu* otherToggleMenu = viewMenu->addMenu(tr("Other Toggle")); + otherToggleMenu->addAction(viewMenuBar); + otherToggleMenu->addAction(viewStatusBar); + otherToggleMenu->addAction(mainToolbar->toggleViewAction()); } // ------------------------------ slotEditSettings ------------------------------- diff --git a/sdk/applications/imp/ImpMainWindow.h b/sdk/applications/imp/ImpMainWindow.h index 4cb294d3..6a50c9e8 100644 --- a/sdk/applications/imp/ImpMainWindow.h +++ b/sdk/applications/imp/ImpMainWindow.h @@ -98,7 +98,7 @@ public slots: void showToolbar(bool); /// show or hide the menu bar - void showMenuBar(bool); + void toggleMenuBar(); /// reset all windows in their initial state void resetWindows(); -- GitLab From ceca5ca77b6f397d0501b3dd9babf8ab80d4e12d Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Tue, 4 Feb 2020 22:17:04 +0100 Subject: [PATCH 23/26] FIXED action-state-machine and its viewer is back Show how to register a viewer extension and its viewers manually --- .../actionstatemachine/ActionStateMachine.cpp | 7 +++ .../actionstatemachine/ActionStateViewer.cpp | 1 + .../actionstatemachine/CMakeLists.txt | 4 +- .../testdata/asmSimpleImageFilter.xml | 58 +++++++++++-------- .../testdata/asmSimpleMeshProcessing.xml | 22 +++---- 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/sdk/applications/actionstatemachine/ActionStateMachine.cpp b/sdk/applications/actionstatemachine/ActionStateMachine.cpp index 67ac0cba..a35029e6 100644 --- a/sdk/applications/actionstatemachine/ActionStateMachine.cpp +++ b/sdk/applications/actionstatemachine/ActionStateMachine.cpp @@ -44,6 +44,7 @@ using namespace camitk; // -- CamiTK Application Local stuff #include "ActionStateMachine.h" #include "ActionStateViewer.h" +#include "ActionStateViewerExtension.h" #include "ActionTransition.h" // ---------------------- constructor ---------------------------- @@ -53,6 +54,12 @@ ActionStateMachine::ActionStateMachine(int& argc, char** argv, QString inputFile setProperty("Log to File", true); setProperty("Logger Level", InterfaceLogger::TRACE); + // load the specific viewer extension + ActionStateViewerExtension* ext = new ActionStateViewerExtension(); + ext->initResources(); + ext->init(); + registerAllViewers(ext); + statesMap = new QMap(); // Atributes initialization diff --git a/sdk/applications/actionstatemachine/ActionStateViewer.cpp b/sdk/applications/actionstatemachine/ActionStateViewer.cpp index 0d278edf..dbceb697 100644 --- a/sdk/applications/actionstatemachine/ActionStateViewer.cpp +++ b/sdk/applications/actionstatemachine/ActionStateViewer.cpp @@ -35,6 +35,7 @@ // ---------------- constructor ---------------- ActionStateViewer::ActionStateViewer(QString name) : Viewer(name) { + setLayout(Viewer::DOCKED); myWidget = nullptr; // empty the list as this is a state viewer, it has nothing to do with Components setComponents(QStringList()); diff --git a/sdk/applications/actionstatemachine/CMakeLists.txt b/sdk/applications/actionstatemachine/CMakeLists.txt index 40f57dc7..8de42b80 100644 --- a/sdk/applications/actionstatemachine/CMakeLists.txt +++ b/sdk/applications/actionstatemachine/CMakeLists.txt @@ -2,11 +2,11 @@ camitk_application(NEEDS_QT_MODULES #we use QtXML ADDITIONAL_SOURCES CommandLineOptions.cxx CommandLineOptions.hxx CommandLineOptions.ixx CEP_NAME SDK - NEEDS_VIEWER_EXTENSION explorer medicalimageviewer + NEEDS_VIEWER_EXTENSION explorer medicalimageviewer DESCRIPTION "Simple action state machine to pipeline actions from an XML file" ) # Recursively update the shiboken path variable containing the CamiTK SDK tree structure set(SHIBOKEN_CAMITK_SDK_PATH ${SHIBOKEN_CAMITK_SDK_PATH}:${CMAKE_CURRENT_SOURCE_DIR} CACHE INTERNAL "") - +# TODO add two automatic test using the testdata scxml diff --git a/sdk/applications/actionstatemachine/testdata/asmSimpleImageFilter.xml b/sdk/applications/actionstatemachine/testdata/asmSimpleImageFilter.xml index bfca68fb..83a88000 100644 --- a/sdk/applications/actionstatemachine/testdata/asmSimpleImageFilter.xml +++ b/sdk/applications/actionstatemachine/testdata/asmSimpleImageFilter.xml @@ -1,14 +1,14 @@
  • with low threshold to arbitrary set to 58
  • with high threshold arbitrary set to 153
  • -
  • Name the output image thresholdImage
  • +
  • Name the output image resampledImage
  • Save this output image in the same directory as the input image.
  • Quit the application
  • ]]> + + Set Path To Test Data + - + Open a new volume image and display it. - Open + Open File + + + @@ -53,7 +59,7 @@ This Action State Machine performs a very simple image processing pipeline:
    - +
    @@ -74,31 +80,33 @@ Please check that this image is the right image. - + - + - + - Image Processing Step + Resample Image - Manual Threshold Filter + Resample - - + + + + - + @@ -114,15 +122,15 @@ Please check that this image is the right image. Save - + - + - + @@ -145,7 +153,7 @@ to re-run the application from the beginning. - + diff --git a/sdk/applications/actionstatemachine/testdata/asmSimpleMeshProcessing.xml b/sdk/applications/actionstatemachine/testdata/asmSimpleMeshProcessing.xml index 51941959..9a5faa86 100644 --- a/sdk/applications/actionstatemachine/testdata/asmSimpleMeshProcessing.xml +++ b/sdk/applications/actionstatemachine/testdata/asmSimpleMeshProcessing.xml @@ -1,14 +1,14 @@ - + @@ -84,7 +84,7 @@ to the testdata directory before running.
    - + -- GitLab From 875d019404d8f38efb8ffc2edb83e0d709235a4f Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Wed, 5 Feb 2020 08:55:08 +0100 Subject: [PATCH 24/26] FIXED action viewer and relationship with Application and Action --- sdk/actions/mesh/basicmesh/ChangeColor.cpp | 2 +- sdk/actions/mesh/basicmesh/RigidTransform.cpp | 4 +- sdk/libraries/core/action/Action.cpp | 18 ++-- .../core/application/Application.cpp | 13 +-- sdk/libraries/core/application/Application.h | 54 ++++++------ sdk/libraries/core/viewer/Viewer.h | 11 +-- sdk/viewers/actionviewer/ActionViewer.cpp | 88 +++++++++---------- sdk/viewers/actionviewer/ActionViewer.h | 13 ++- 8 files changed, 98 insertions(+), 105 deletions(-) diff --git a/sdk/actions/mesh/basicmesh/ChangeColor.cpp b/sdk/actions/mesh/basicmesh/ChangeColor.cpp index 2f72b489..0d51ff5b 100644 --- a/sdk/actions/mesh/basicmesh/ChangeColor.cpp +++ b/sdk/actions/mesh/basicmesh/ChangeColor.cpp @@ -52,7 +52,7 @@ Action::ApplyStatus ChangeColor::apply() { QColor currentColor; currentColor.setRgbF(actorColor[0], actorColor[1], actorColor[2], actorColor[3]); - QColor newColor = QColorDialog::getColor(currentColor, NULL, QString("Change color of ") + getTargets().size() + QString(" components"), QColorDialog::ShowAlphaChannel); + QColor newColor = QColorDialog::getColor(currentColor, nullptr, QString("Change color of ") + getTargets().size() + QString(" components"), QColorDialog::ShowAlphaChannel); if (newColor.isValid()) { actorColor[0] = newColor.redF(); diff --git a/sdk/actions/mesh/basicmesh/RigidTransform.cpp b/sdk/actions/mesh/basicmesh/RigidTransform.cpp index 6ab1bdba..561088f1 100644 --- a/sdk/actions/mesh/basicmesh/RigidTransform.cpp +++ b/sdk/actions/mesh/basicmesh/RigidTransform.cpp @@ -51,7 +51,7 @@ RigidTransform::RigidTransform(ActionExtension* extension) : Action(extension) { addTag("Rotate"); addTag("Scale"); - dialog = NULL; + dialog = nullptr; } @@ -217,7 +217,7 @@ Action::ApplyStatus RigidTransform::apply() { void RigidTransform::close() { //--disconnect the selected Component foreach (Component* comp, getTargets()) { - comp->setDataConnection(NULL); + comp->setDataConnection(nullptr); } // hide the dialog dialog->hide(); diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index d0877809..f868f9c9 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -195,12 +195,8 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { //-- if there are some valid targets or if the action is generic if (targetComponents.size() > 0 || getComponent().isEmpty()) { if (isEmbedded) { - if (parent == nullptr) { - // tell the application this action is ready to show its widget, so that - // any viewer that wants to show something about it is refreshed - Application::setSelectedAction(this); - } - else { + if (parent != nullptr) { + // set the widget in the given parent getWidget()->setParent(parent); getWidget()->show(); } @@ -218,6 +214,16 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { } } + // tell the application this action is ready to show its widget + Application::setTriggeredAction(this); + // make sure that any viewer that wants to show something about it is refreshed + Application::refresh(); + CAMITK_INFO("→ refresh()") + // now that everyone that wanted to be notified about this change of action selection, + // there is no need to do more, just empty the current selection + Application::setTriggeredAction(nullptr); + + return TRIGGERED; } else { diff --git a/sdk/libraries/core/application/Application.cpp b/sdk/libraries/core/application/Application.cpp index b00d2edf..c62dfac2 100644 --- a/sdk/libraries/core/application/Application.cpp +++ b/sdk/libraries/core/application/Application.cpp @@ -1083,21 +1083,12 @@ void Application::clearSelectedComponents() { } // -------------------- setSelectedAction -------------------- -void Application::setSelectedAction(Action* action) { +void Application::setTriggeredAction(Action* action) { currentAction = action; - // check all the registered viewers and refresh all the viewers - // that do not act on Components... (if they do not visualize component - // they might be interested by a change of the currently selected action - foreach (Viewer* v, getViewers()) { - if (v->getComponents().isEmpty()) { - CAMITK_INFO_ALT(tr("Refreshing \"%1\"").arg(v->getName())) - v->refresh(); - } - } } // -------------------- getSelectedAction -------------------- -Action* Application::getSelectedAction() { +Action* Application::getTriggeredAction() { return currentAction; } diff --git a/sdk/libraries/core/application/Application.h b/sdk/libraries/core/application/Application.h index b7238344..ae6f7c87 100644 --- a/sdk/libraries/core/application/Application.h +++ b/sdk/libraries/core/application/Application.h @@ -205,7 +205,7 @@ public: */ static const ComponentList& getAllComponents(); - /// does this Component still exists? + /// does this Component still exists? static bool isAlive(Component*); /// Return true if at least one of the opened components has been modified, false otherwise. @@ -229,10 +229,6 @@ public: static void clearSelectedComponents(); ///@} - static void setSelectedAction(Action* action); - - static Action* getSelectedAction(); - /// @name Action instances management ///@{ @@ -260,18 +256,26 @@ public: * @return the number of actions effectively unregistered */ static int unregisterAllActions(ActionExtension*); + + /// set the currently triggered action + /// This is used by Action::trigger(..) to refresh all the viewer (the viewers + /// interested by the fact an action was triggered can then update what they need to) + static void setTriggeredAction(Action* action); + + /// get the currently triggered action + static Action* getTriggeredAction(); ///@} /// get a registered viewer given its name - static Viewer* getViewer(QString name); + static Viewer* getViewer(QString name); - static Viewer * getNewViewer(QString name, QString className); + static Viewer* getNewViewer(QString name, QString className); /// get all the viewers registered in the application (note: the returned ViewerList is garanteed to be sorted by viewer name and to not contain any duplicate) static const ViewerList getViewers(); - /// get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) - static ViewerList getViewers(Component*); + /// get all the actions that can be applied on a given component (note: the returned ActionList is garanteed to be sorted by action name and to contain no duplicates) + static ViewerList getViewers(Component*); /** register all viewers from the given ViewerExtension * @return the number of viewers effectively registered (in case a viewer's name is already registered by another viewer extension, it won't be registered a second time) @@ -302,7 +306,7 @@ public: /// get the main window /// \note if there is no MainWindow when this method is first called, - /// then this method makes sure there is a MainWindow by and force the creation of + /// then this method makes sure there is a MainWindow by and force the creation of /// a default MainWindow (direct instance of the MainWindow class) static MainWindow* getMainWindow(); @@ -401,7 +405,7 @@ private: /// argv given from command line static char** argv; - static Action* currentAction; + static Action* currentAction; /// @name Recent document management ///@{ @@ -492,10 +496,10 @@ private: ///@name Actions pipeline history ///@{ /** get the history of actions stored. - * + * * This methods returns the singleton stack of actions stored in a pipeline as * their are applied during the execution of the application. - * + * * This is the private (intern) method. * This history is updated (push(), pop()) by addHistoryItem() and removeHistoryItem() * This method follows the "construct on first use" idiom/design-pattern. @@ -511,9 +515,9 @@ private: /** As actions are mainly sort/compared/process by name, an internal QMap * associates all the contains all the registered actions with their name (key) * This is the private (intern) method. - * + * * The action extension map is updated by loadExtension, unloadExtension and autoloadExtensions. - * + * * This method follows the "construct on first use" idiom/design-pattern. * It therefore avoids the infamous "static initialization order fiasco", * see http://www.parashift.com/c++-faq/ctors.html @@ -523,28 +527,28 @@ private: /// sort an ActionSet by action's name static ActionList sort(ActionSet); ///@} - - /// sort an ViewerSet by viewer's name - static ViewerList sort(ViewerSet); - ///@} - + + /// sort an ViewerSet by viewer's name + static ViewerList sort(ViewerSet); + ///@} + /// @name viewer management ///@{ /** As viewers are mainly sort/compared/process by name, an internal QMap * associates all the registered viewers with their name (key). * This is the private (intern) method. - * + * * This is the private (intern) method. - * + * * The viewer extension map is updated by loadExtension, unloadExtension and autoloadExtensions. - * + * * This method follows the "construct on first use" idiom/design-pattern. * It therefore avoids the infamous "static initialization order fiasco", * see http://www.parashift.com/c++-faq/ctors.html */ static QMap& getViewerMap(); - static ViewerExtension* getViewerExtension(Viewer* viewer); + static ViewerExtension* getViewerExtension(Viewer* viewer); ///@} @@ -569,7 +573,7 @@ private: /// Init the application resources by loading the language associated .qml file static void initResources(); - + protected: /** * Event filter of this class instance to watch its properties instances. diff --git a/sdk/libraries/core/viewer/Viewer.h b/sdk/libraries/core/viewer/Viewer.h index 98ca058d..5eeb70a4 100644 --- a/sdk/libraries/core/viewer/Viewer.h +++ b/sdk/libraries/core/viewer/Viewer.h @@ -57,6 +57,12 @@ class Property; * A viewer can be added to MainWindow, MainWindow will include its menu in the "View" menu and its toolbar in * the application toolbar. * + * The default viewed component are set so that the viewer is updated every time the current component selection + * is modified. + * If your viewer does not view components (for instance, in the very rare/special case it views actions) + * then you need to call the setComponents(...) method with an empty list. + * An empty list means that this viewer is going to be notified/refreshed for every changes in the + * current action selection as well (i.e., anytime an action is triggered) */ class CAMITK_API Viewer : public QObject { @@ -174,11 +180,6 @@ protected: /// set the list of component class names managed by this viewer /// \note Default is set to "Component" (all type of components) - /// If your viewer does not view components (for instance it views action) - /// then you need to call this method with an empty list. - /// An empty list means that this viewer is - /// going to be notified/refreshed for every changes that are not linked with - /// any components. void setComponents(QStringList); private: diff --git a/sdk/viewers/actionviewer/ActionViewer.cpp b/sdk/viewers/actionviewer/ActionViewer.cpp index d6127e41..8e800ce5 100644 --- a/sdk/viewers/actionviewer/ActionViewer.cpp +++ b/sdk/viewers/actionviewer/ActionViewer.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using namespace camitk; @@ -47,9 +48,9 @@ ActionViewer::ActionViewer(QString name) : Viewer(name) { nameComboBox = nullptr; actionWidgetStack = nullptr; searchFramePanel = nullptr; - + // empty the list as this is an action viewer, it has nothing to do with Components - setComponents(QStringList()); + setComponents(QStringList()); } // ---------------- destructor ---------------- @@ -58,8 +59,7 @@ ActionViewer::~ActionViewer() { // -------------------- refresh -------------------- void ActionViewer::refresh(Viewer*) { - // no need to update if there is no selected action or there is no selected component - updateActionWidget(Application::getSelectedAction()); + updateActionWidget(Application::getTriggeredAction()); updateSearchPanel(ViewerRefresh); } @@ -101,7 +101,7 @@ QWidget* ActionViewer::getWidget() { emptyActionWidgetIndex = actionWidgetStack->addWidget(new QWidget()); // init history insert new index in history for empty selection ComponentList emptySelection; - widgetHistory.insert(emptySelection, NULL); + widgetHistory.insert(emptySelection, nullptr); actionWidgetLayout->addWidget(actionWidgetStack); // set the action widget layout @@ -171,7 +171,7 @@ bool operator<(const ComponentList& l1, const ComponentList& l2) { } } -// -------------------- updateActionViewer -------------------- +// -------------------- updateSearchPanel -------------------- void ActionViewer::updateSearchPanel(UpdateReason reason) { familyComboBox->blockSignals(true); nameComboBox->blockSignals(true); @@ -188,9 +188,8 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { if (Application::getSelectedComponents().size() > 0) { possibleActions = Application::getActions(Application::getSelectedComponents()); } - else + else { // no selection => select only empty component actions - { possibleActions = Application::getActions(nullptr); } @@ -208,7 +207,6 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { //-- action name whas changed -> trigger the corresponding action if (action) { familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - lastSelected = ComponentList(); action->trigger(); } @@ -237,7 +235,6 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { } } break; - case ViewerRefresh: default: { @@ -290,21 +287,20 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { if (it != widgetHistory.end()) { // show the previously used widget - if (it.value() == NULL) { + if (it.value() == nullptr) { actionWidgetStack->setCurrentIndex(emptyActionWidgetIndex); } - else { // update search panel - familyComboBox->setCurrentIndex(familyComboBox->findText(it.value()->getFamily())); - nameComboBox->setCurrentIndex(nameComboBox->findText(it.value()->getName())); - it.value()->trigger(); + else { + updateActionWidget(it.value()); } } else { - // insert new index in history (NULL action, with empty widget) - widgetHistory.insert(selected, NULL); + // insert new index in history (nullptr action, with empty widget) + widgetHistory.insert(selected, nullptr); actionWidgetStack->setCurrentIndex(emptyActionWidgetIndex); } } + } } @@ -313,41 +309,37 @@ void ActionViewer::updateSearchPanel(UpdateReason reason) { tagLineEdit->blockSignals(false); } -// -------------------- embedActionWidget -------------------- +// -------------------- updateActionWidget -------------------- void ActionViewer::updateActionWidget(Action* action) { - if (action != nullptr && currentlySelected.size() > 0) { - if (this->action != action || lastSelected.isEmpty() || lastSelected != currentlySelected) { - this->action = Application::getSelectedAction(); - this->lastSelected = Application::getSelectedComponents(); - - // make sure the action viewer is visible (even if in a dockwidget) - if (getWidget()->parentWidget()) { - getWidget()->parentWidget()->setVisible(true); - getWidget()->setVisible(true); - } - - //-- check history - QWidget* actionWidget = action->getWidget(); - int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); + // no need to update if there is no currently selected action or the current action is not to embed + if (action != nullptr && action->getEmbedded()) { - if (actionWidgetIndex == -1 && actionWidget) { - // add the widget (beware that actionWidgetStack then takes ownership of the widget!) - actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); - } - - // insert new index in history - ComponentList selected(Application::getSelectedComponents()); - widgetHistory.insert(selected, action); - actionWidgetStack->setCurrentIndex(actionWidgetIndex); - actionWidgetStack->update(); - // ignore size policy of widget so that it can be resized - actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + // make sure the action viewer is visible (even if in a dockwidget) + if (getWidget()->parentWidget()) { + getWidget()->parentWidget()->setVisible(true); + getWidget()->setVisible(true); + } + //-- check history + QWidget* actionWidget = action->getWidget(); + int actionWidgetIndex = actionWidgetStack->indexOf(actionWidget); - // update search panel - familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); - updateSearchPanel(ActionFamilyChanged); // to have only the actions of the same family - nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); + if (actionWidgetIndex == -1 && actionWidget) { + // add the widget (beware that actionWidgetStack then takes ownership of the widget!) + actionWidgetIndex = actionWidgetStack->addWidget(actionWidget); } + + // insert new index in history + ComponentList selected(Application::getSelectedComponents()); + widgetHistory.insert(selected, action); + actionWidgetStack->setCurrentIndex(actionWidgetIndex); + actionWidgetStack->update(); + // ignore size policy of widget so that it can be resized + actionWidgetStack->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + + // update search panel + familyComboBox->setCurrentIndex(familyComboBox->findText(action->getFamily())); + updateSearchPanel(ActionFamilyChanged); // to have only the actions of the same family + nameComboBox->setCurrentIndex(nameComboBox->findText(action->getName())); } } diff --git a/sdk/viewers/actionviewer/ActionViewer.h b/sdk/viewers/actionviewer/ActionViewer.h index e3d37653..5483b384 100644 --- a/sdk/viewers/actionviewer/ActionViewer.h +++ b/sdk/viewers/actionviewer/ActionViewer.h @@ -100,10 +100,10 @@ private: /// Enum the different fields of the action viewwer enum UpdateReason {ActionFamilyChanged, ActionNameChanged, ActionTagChanged, ViewerRefresh}; - /// @name Specific to the Action viewer - //@{ - /// embed an action widget in the stacked widget - virtual void updateActionWidget(camitk::Action*); + /// @name Specific to the Action viewer + //@{ + /// embed an action widget in the stacked widget if needed + virtual void updateActionWidget(camitk::Action*); /// method used to update the viewer for a given update field void updateSearchPanel(UpdateReason); @@ -118,7 +118,7 @@ private: QComboBox* nameComboBox; /// Current action - camitk::Action* action; + camitk::Action* action; /// action tags line edit QLineEdit* tagLineEdit; @@ -136,8 +136,7 @@ private: QMap widgetHistory; /// Used to evaluate modification of the list while execution - camitk::ComponentList currentlySelected; - camitk::ComponentList lastSelected; + camitk::ComponentList currentlySelected; }; -- GitLab From eaee25fbde7c9625d5ba8bfaddc338c7b805c67b Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Wed, 5 Feb 2020 08:55:35 +0100 Subject: [PATCH 25/26] FIXED cleanup --- sdk/libraries/core/action/Action.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/libraries/core/action/Action.cpp b/sdk/libraries/core/action/Action.cpp index f868f9c9..c26f2616 100644 --- a/sdk/libraries/core/action/Action.cpp +++ b/sdk/libraries/core/action/Action.cpp @@ -218,7 +218,6 @@ Action::ApplyStatus Action::trigger(QWidget* parent) { Application::setTriggeredAction(this); // make sure that any viewer that wants to show something about it is refreshed Application::refresh(); - CAMITK_INFO("→ refresh()") // now that everyone that wanted to be notified about this change of action selection, // there is no need to do more, just empty the current selection Application::setTriggeredAction(nullptr); -- GitLab From b3b85c5332c89a5f46f28cc39dc785168c67f842 Mon Sep 17 00:00:00 2001 From: Emmanuel Promayon Date: Wed, 5 Feb 2020 09:55:36 +0100 Subject: [PATCH 26/26] FIXED tutorial applications and viewers --- sdk/applications/imp/main.cpp | 3 +- tutorials/applications/basic/main.cpp | 9 +- tutorials/applications/fancy/CMakeLists.txt | 2 +- .../applications/fancy/FancyMainWindow.cpp | 122 +++++++++++------- .../applications/fancy/FancyMainWindow.h | 10 +- tutorials/applications/fancy/main.cpp | 3 +- .../applications/menubar/MyAppMainWindow.cpp | 6 +- tutorials/applications/menubar/main.cpp | 3 +- tutorials/applications/simple/main.cpp | 3 +- 9 files changed, 92 insertions(+), 69 deletions(-) diff --git a/sdk/applications/imp/main.cpp b/sdk/applications/imp/main.cpp index 43aa03ff..8da9c0a2 100644 --- a/sdk/applications/imp/main.cpp +++ b/sdk/applications/imp/main.cpp @@ -109,8 +109,7 @@ int main(int argc, char* argv[]) { Application a("camitk-imp", argc, argv, true, true); // set the ImpMainWindow as the main window - ImpMainWindow* impMainWindow = new ImpMainWindow(); - a.setMainWindow(impMainWindow); + a.setMainWindow(new ImpMainWindow()); if (o.no_console()) { // force no redirection to console (to see error message if they occur) diff --git a/tutorials/applications/basic/main.cpp b/tutorials/applications/basic/main.cpp index 2e370b06..6333cb1c 100644 --- a/tutorials/applications/basic/main.cpp +++ b/tutorials/applications/basic/main.cpp @@ -24,10 +24,10 @@ ****************************************************************************/ // -- Core stuff +#include #include #include -#include -#include +#include using namespace camitk; @@ -35,7 +35,10 @@ int main(int argc, char* argv[]) { // create a camitk application Application a("basic", argc, argv); - // add an axial viewer to the default main window + // add an axial viewer to the default main window + // in order to add it to the main window, we need to extract it first from the medical viewer + // (that's what setLayout is doing) + Application::getViewer("axialViewer")->setLayout(Viewer::STACKED); a.getMainWindow()->setCentralViewer(Application::getViewer("axialViewer")); // open an image volume diff --git a/tutorials/applications/fancy/CMakeLists.txt b/tutorials/applications/fancy/CMakeLists.txt index 63bb1501..edcaad46 100644 --- a/tutorials/applications/fancy/CMakeLists.txt +++ b/tutorials/applications/fancy/CMakeLists.txt @@ -1,3 +1,3 @@ camitk_application( - NEEDS_VIEWER_EXTENSION medicalimageviewer + NEEDS_VIEWER_EXTENSION interactivegeometryviewer interactivesliceviewer medicalimageviewer ) diff --git a/tutorials/applications/fancy/FancyMainWindow.cpp b/tutorials/applications/fancy/FancyMainWindow.cpp index f2c180a8..548b6aca 100644 --- a/tutorials/applications/fancy/FancyMainWindow.cpp +++ b/tutorials/applications/fancy/FancyMainWindow.cpp @@ -51,25 +51,30 @@ FancyMainWindow::FancyMainWindow() : MainWindow("Fancy") { // add the medical image viewer visibility = MedicalImageViewer::VIEWER_AXIAL; - ui.viewer->addWidget(Application::getViewer("MedicalImageViewer")->getWidget(this)); + // for this application, force the medical image viewer to be embedded + Application::getViewer("MedicalImageViewer")->setLayout(Viewer::EMBEDDED); + Application::getViewer("MedicalImageViewer")->embedIn(ui.viewer); + // hide slide bar and modify the color and background dynamic_cast(Application::getViewer("axialViewer"))->setSideFrameVisible(false); - dynamic_cast(Application::getViewer("axialViewer"))->setGradientBackground(false); - dynamic_cast(Application::getViewer("axialViewer"))->setBackgroundColor(ui.dial->palette().background().color()); - dynamic_cast(Application::getViewer("sagittalViewer"))->setSideFrameVisible(false); - dynamic_cast(Application::getViewer("sagittalViewer"))->setGradientBackground(false); - dynamic_cast(Application::getViewer("sagittalViewer"))->setBackgroundColor(ui.dial->palette().background().color()); - dynamic_cast(Application::getViewer("coronalViewer"))->setSideFrameVisible(false); - dynamic_cast(Application::getViewer("coronalViewer"))->setGradientBackground(false); - dynamic_cast(Application::getViewer("coronalViewer"))->setBackgroundColor(ui.dial->palette().background().color()); - dynamic_cast(Application::getViewer("arbitraryViewer"))->setSideFrameVisible(false); - dynamic_cast(Application::getViewer("arbitraryViewer"))->setGradientBackground(false); - dynamic_cast(Application::getViewer("arbitraryViewer"))->setBackgroundColor(ui.dial->palette().background().color()); - - // add the 3D small little viewer - //viewer3D = InteractiveViewer::getNewViewer("Fancy 3D Viewer", camitk::InteractiveViewer::GEOMETRY_VIEWER); - viewer3D = dynamic_cast(Application::getViewer("3DViewer")); - ui.viewer3DLayout->addWidget(viewer3D->getWidget(this)); + dynamic_cast(Application::getViewer("axialViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("axialViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("sagittalViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("sagittalViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("sagittalViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("coronalViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("coronalViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("coronalViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + dynamic_cast(Application::getViewer("arbitraryViewer"))->setSideFrameVisible(false); + dynamic_cast(Application::getViewer("arbitraryViewer"))->setGradientBackground(false); + dynamic_cast(Application::getViewer("arbitraryViewer"))->setBackgroundColor(ui.dial->palette().background().color()); + + // add a 3D small little viewer (note that we need to set the visibility of this viewer + // to true during refresh, as by default, the component does not know about it + // and its visibility is false) + viewer3D = dynamic_cast(Application::getNewViewer("small3DViewer", "InteractiveGeometryViewer")); + viewer3D->setLayout(Viewer::EMBEDDED); + viewer3D->embedIn(ui.viewer3DLayout); viewer3D->setSideFrameVisible(false); viewer3D->setGradientBackground(false); viewer3D->setBackgroundColor(ui.dial->palette().background().color()); @@ -117,12 +122,14 @@ void FancyMainWindow::updateAngleSlider(QDial* dial, QLabel* label) { if (label == ui.xAngleValue) { label->setText("X : " + QString("%1").arg(dial->value(), 3) + "" + 0x00B0); } - else if (label == ui.yAngleValue) { - label->setText("Y : " + QString("%1").arg(dial->value(), 3) + "" + 0x00B0); - } - else if (label == ui.zAngleValue) { - label->setText("Z : " + QString("%1").arg(dial->value(), 3) + "" + 0x00B0); - } + else + if (label == ui.yAngleValue) { + label->setText("Y : " + QString("%1").arg(dial->value(), 3) + "" + 0x00B0); + } + else + if (label == ui.zAngleValue) { + label->setText("Z : " + QString("%1").arg(dial->value(), 3) + "" + 0x00B0); + } label->update(); } @@ -138,7 +145,7 @@ void FancyMainWindow::updateDialSlider() { maxSliceId = 360; } else { - Component* comp = NULL; + Component* comp = nullptr; if (Application::getTopLevelComponents().size() > 0) { ImageComponent* comp = dynamic_cast(Application::getTopLevelComponents().last()); @@ -148,14 +155,15 @@ void FancyMainWindow::updateDialSlider() { currentSliceId = comp->getAxialSlices()->getSlice(); maxSliceId = comp->getAxialSlices()->getNumberOfSlices(); } - else if (visibility == MedicalImageViewer::VIEWER_CORONAL) { - currentSliceId = comp->getCoronalSlices()->getSlice(); - maxSliceId = comp->getCoronalSlices()->getNumberOfSlices(); - } - else { - currentSliceId = comp->getSagittalSlices()->getSlice(); - maxSliceId = comp->getSagittalSlices()->getNumberOfSlices(); - } + else + if (visibility == MedicalImageViewer::VIEWER_CORONAL) { + currentSliceId = comp->getCoronalSlices()->getSlice(); + maxSliceId = comp->getCoronalSlices()->getNumberOfSlices(); + } + else { + currentSliceId = comp->getSagittalSlices()->getSlice(); + maxSliceId = comp->getSagittalSlices()->getNumberOfSlices(); + } } } } @@ -185,42 +193,46 @@ void FancyMainWindow::layoutChanged() { if (ui.axial->isChecked()) { visibility = MedicalImageViewer::VIEWER_AXIAL; } - else if (ui.saggital->isChecked()) { - visibility = MedicalImageViewer::VIEWER_SAGITTAL; - } - else if (ui.coronal->isChecked()) { - visibility = MedicalImageViewer::VIEWER_CORONAL; - } - else { - visibility = MedicalImageViewer::VIEWER_ARBITRARY; - } + else + if (ui.saggital->isChecked()) { + visibility = MedicalImageViewer::VIEWER_SAGITTAL; + } + else + if (ui.coronal->isChecked()) { + visibility = MedicalImageViewer::VIEWER_CORONAL; + } + else { + visibility = MedicalImageViewer::VIEWER_ARBITRARY; + } dynamic_cast(Application::getViewer("MedicalImageViewer"))->setVisibleViewer(visibility); ui.dial->show(); + ui.slideValue->show(); showAngleDials(visibility == MedicalImageViewer::VIEWER_ARBITRARY); + refresh(); } // -------------------- xAngleDialValueChanged -------------------- void FancyMainWindow::xAngleDialValueChanged(int value) { - dynamic_cast(Application::getViewer("arbitraryViewer"))->xAngleChanged(value); + dynamic_cast(Application::getViewer("arbitraryViewer"))->xAngleChanged(value); updateAngleSlider(ui.xAngledial, ui.xAngleValue); refresh(); } // -------------------- yAngleDialValueChanged -------------------- void FancyMainWindow::yAngleDialValueChanged(int value) { - dynamic_cast(Application::getViewer("arbitraryViewer"))->yAngleChanged(value); + dynamic_cast(Application::getViewer("arbitraryViewer"))->yAngleChanged(value); updateAngleSlider(ui.yAngledial, ui.yAngleValue); refresh(); } // -------------------- zAngleDialValueChanged -------------------- void FancyMainWindow::zAngleDialValueChanged(int value) { - dynamic_cast(Application::getViewer("arbitraryViewer"))->zAngleChanged(value); + dynamic_cast(Application::getViewer("arbitraryViewer"))->zAngleChanged(value); updateAngleSlider(ui.zAngledial, ui.zAngleValue); refresh(); } @@ -237,18 +249,23 @@ void FancyMainWindow::refresh() { getVisibleViewer()->refresh(); // force visualization of arbitrary slice in 3D + // We need to set the visibility of this viewer to true during as by default + // the component does not know about it and the visibility in viewer3D is false if (Application::getTopLevelComponents().size() > 0) { ImageComponent* comp = dynamic_cast(Application::getTopLevelComponents().last()); if (comp != nullptr && comp->getAxialSlices() != nullptr) { comp->getAxialSlices()->setVisibility(viewer3D, true); } + if (comp != nullptr && comp->getSagittalSlices() != nullptr) { comp->getSagittalSlices()->setVisibility(viewer3D, true); } + if (comp != nullptr && comp->getCoronalSlices() != nullptr) { comp->getCoronalSlices()->setVisibility(viewer3D, true); } + if (comp != nullptr && comp->getArbitrarySlices() != nullptr) { comp->getArbitrarySlices()->setVisibility(viewer3D, true); } @@ -259,21 +276,26 @@ void FancyMainWindow::refresh() { } // -------------------- getVisibleViewer -------------------- -InteractiveViewer* FancyMainWindow::getVisibleViewer() { - InteractiveViewer* visibleViewer = NULL; +InteractiveSliceViewer* FancyMainWindow::getVisibleViewer() { + InteractiveSliceViewer* visibleViewer = NULL; + switch (visibility) { case MedicalImageViewer::VIEWER_AXIAL: - visibleViewer = dynamic_cast(Application::getViewer("axialViewer")); + visibleViewer = dynamic_cast(Application::getViewer("axialViewer")); break; + case MedicalImageViewer::VIEWER_CORONAL: - visibleViewer = dynamic_cast(Application::getViewer("coronalViewer")); + visibleViewer = dynamic_cast(Application::getViewer("coronalViewer")); break; + case MedicalImageViewer::VIEWER_SAGITTAL: - visibleViewer = dynamic_cast(Application::getViewer("sagittalViewer")); + visibleViewer = dynamic_cast(Application::getViewer("sagittalViewer")); break; + default: // arbitrary (and... 3D!) - visibleViewer = dynamic_cast(Application::getViewer("arbitraryViewer")); + visibleViewer = dynamic_cast(Application::getViewer("arbitraryViewer")); break; } + return visibleViewer; } diff --git a/tutorials/applications/fancy/FancyMainWindow.h b/tutorials/applications/fancy/FancyMainWindow.h index 546e8513..c4e32a10 100644 --- a/tutorials/applications/fancy/FancyMainWindow.h +++ b/tutorials/applications/fancy/FancyMainWindow.h @@ -23,9 +23,6 @@ * $CAMITK_LICENCE_END$ ****************************************************************************/ - - - #ifndef FANCYAPP_H #define FANCYAPP_H @@ -35,7 +32,8 @@ // -- Core stuff #include #include -#include +#include +#include /** * This Class describes the fancy bare application. It sets up the main @@ -92,10 +90,10 @@ private: QWidget* mainWidget; /// get the currently visible viewer (axial, sagittal, coronal or arbitrary) - camitk::InteractiveViewer* getVisibleViewer(); + InteractiveSliceViewer* getVisibleViewer(); /// specific 3D viewer for fancy - camitk::InteractiveViewer* viewer3D; + InteractiveGeometryViewer* viewer3D; }; #endif // FANCYAPP_H diff --git a/tutorials/applications/fancy/main.cpp b/tutorials/applications/fancy/main.cpp index bb02152f..e5d7b176 100644 --- a/tutorials/applications/fancy/main.cpp +++ b/tutorials/applications/fancy/main.cpp @@ -40,8 +40,7 @@ int main(int argc, char* argv[]) { a.setStyleSheet(style); // set the main window using the Fancy class - FancyMainWindow* fancyMainWindow = new FancyMainWindow(); - a.setMainWindow(fancyMainWindow); + a.setMainWindow(new FancyMainWindow()); // start by opening a mha Application::open(Core::getTestDataDir() + "/brain.mha"); diff --git a/tutorials/applications/menubar/MyAppMainWindow.cpp b/tutorials/applications/menubar/MyAppMainWindow.cpp index 78033db3..1062832f 100644 --- a/tutorials/applications/menubar/MyAppMainWindow.cpp +++ b/tutorials/applications/menubar/MyAppMainWindow.cpp @@ -71,7 +71,11 @@ MyAppMainWindow::MyAppMainWindow() : MainWindow("MyApp - " + tr(Core::version)) // now add the different viewers addDockViewer(Qt::LeftDockWidgetArea, Application::getViewer("Explorer")); - addDockViewer(Qt::RightDockWidgetArea, dynamic_cast(Application::getViewer("3DViewer"))); + // get the default 3D viewer out of the MedicalImageViewer and put it directly in the central viewer + Application::getViewer("3DViewer")->setLayout(Viewer::STACKED); + setCentralViewer(Application::getViewer("3DViewer")); + addDockViewer(Qt::RightDockWidgetArea, Application::getViewer("ActionViewer")); + showDockViewer(Application::getViewer("ActionViewer"), false); showStatusBar(true); } diff --git a/tutorials/applications/menubar/main.cpp b/tutorials/applications/menubar/main.cpp index 8568be5d..0d1d7a8b 100644 --- a/tutorials/applications/menubar/main.cpp +++ b/tutorials/applications/menubar/main.cpp @@ -35,8 +35,7 @@ using namespace camitk; int main(int argc, char* argv[]) { Application a("menubar-tutorial", argc, argv); - MyAppMainWindow* myAppMainWindow = new MyAppMainWindow() - a.setMainWindow(myAppMainWindow); + a.setMainWindow(new MyAppMainWindow()); Application::open(Core::getTestDataDir() + "/brain.mha"); diff --git a/tutorials/applications/simple/main.cpp b/tutorials/applications/simple/main.cpp index c9bd3533..b63c68b0 100644 --- a/tutorials/applications/simple/main.cpp +++ b/tutorials/applications/simple/main.cpp @@ -35,8 +35,7 @@ using namespace camitk; int main(int argc, char* argv[]) { Application a("simple", argc, argv); - SimpleMainWindow* simpleMainWindow = new SimpleMainWindow(); - a.setMainWindow(simpleMainWindow); + a.setMainWindow(new SimpleMainWindow()); Application::open(Core::getTestDataDir() + "/brain.mha"); -- GitLab