Computer Assited Medical Intervention Tool Kit  version 5.0
ViewerExtension.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * $CAMITK_LICENCE_BEGIN$
3 *
4 * CamiTK - Computer Assisted Medical Intervention ToolKit
5 * (c) 2001-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, TIMC, 38000 Grenoble, France
6 *
7 * Visit http://camitk.imag.fr for more information
8 *
9 * This file is part of CamiTK.
10 *
11 * CamiTK is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * CamiTK is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22 *
23 * $CAMITK_LICENCE_END$
24 ****************************************************************************/
25 
26 #ifndef VIEWER_EXTENSION_H
27 #define VIEWER_EXTENSION_H
28 
29 #include "CamiTKAPI.h"
30 
31 // -- QT stuff
32 #include <QRegularExpression>
33 #include <QTranslator>
34 
35 namespace camitk {
36 class Viewer;
37 
43 #define registerDefaultViewer(className) setManagedMetaObject(&className::staticMetaObject); \
44  registerViewer(new className(QString(#className).replace(QRegularExpression("([^A-Z\\s])([A-Z])"),"\\1 \\2").replace(QRegularExpression("([A-Z]+)([A-Z][a-z])"),"\\1 \\2")));
45 
47 #define registerNewViewer(className, instanceName) setManagedMetaObject(&className::staticMetaObject); \
48  registerViewer(new className(QString(instanceName)))
49 
85 class CAMITK_API ViewerExtension : public QObject {
86 
87 protected:
89  ViewerExtension();
90 
91 public:
93  ~ViewerExtension() override;
94 
96  virtual QString getName() = 0;
97 
99  virtual QString getDescription() = 0;
100 
102  virtual void init() = 0;
103 
105  const ViewerList& getViewers();
106 
108  void setLocation(const QString loc);
109 
111  QString getLocation() const;
112 
114  void initResources();
115 
117  QString getViewerClassName();
118 
121  Viewer* getNewInstance(QString name);
122 
123 protected:
127  bool registerViewer(Viewer*);
128 
130  ViewerList viewers;
131 
133  void setManagedMetaObject(const QMetaObject*);
134 
135 private:
137  QString dynamicLibraryFileName;
138 
140  QTranslator* translator;
141 
143  const QMetaObject* managedMetaObject;
144 };
145 
146 }
147 // -------------------- declare the interface for QPluginLoader --------------------
148 Q_DECLARE_INTERFACE(camitk::ViewerExtension, "TIMC-IMAG. Viewer Extension/2.1") //TODO use variable from CMake?
149 
150 #endif //VIEWER_EXTENSION_H
151 
camitk::ViewerExtension::setManagedMetaObject
void setManagedMetaObject(const QMetaObject *)
The first time this method is called, it sets the static meta object.
Definition: ViewerExtension.cpp:122
CamiTKAPI.h
camitk::Application::getSelectedLanguage
static QString getSelectedLanguage()
Returns for the current CamiTK application, the selected language (stored in its ....
Definition: Application.cpp:1437
camitk::ViewerExtension::getViewerClassName
QString getViewerClassName()
get the class name of the viewer managed by this extension
Definition: ViewerExtension.cpp:112
CAMITK_INFO
#define CAMITK_INFO(MSG)
Log for info verbosity (the second most verbose one) The msg will appear only if the user asked for I...
Definition: Log.h:261
camitk::ViewerExtension::managedMetaObject
const QMetaObject * managedMetaObject
static meta object of the viewer class managed by this extension
Definition: ViewerExtension.h:166
camitk::ViewerExtension::getViewers
const ViewerList & getViewers()
get the list of viewer instances registered by this extension
Definition: ViewerExtension.cpp:190
camitk::ViewerExtension::~ViewerExtension
~ViewerExtension() override
destructor
Definition: ViewerExtension.cpp:67
camitk::ViewerExtension::getLocation
QString getLocation() const
get the file path (location of the .dll/.so/.dylib) of this plugin
Definition: ViewerExtension.cpp:107
camitk::ViewerExtension::setLocation
void setLocation(const QString loc)
set the file path (once loaded as a dynamic library) = where this extension was loaded
Definition: ViewerExtension.cpp:102
camitk::ViewerExtension::ViewerExtension
ViewerExtension()
constructor
Definition: ViewerExtension.cpp:61
Log.h
camitk::Viewer::getName
QString getName() const
get the name of the viewer
Definition: Viewer.h:200
camitk::ViewerExtension::getName
virtual QString getName()=0
returns the viewer extension name (to be overriden in the derived class)
CAMITK_ERROR
#define CAMITK_ERROR(MSG)
Log for error verbosity (the minimum verbosity) Will always appear.
Definition: Log.h:276
camitk::ViewerExtension::initResources
void initResources()
Load, for the selected langage (asked to the Application), the associated .qm file.
Definition: ViewerExtension.cpp:80
camitk::ViewerExtension::viewers
ViewerList viewers
the list of viewers
Definition: ViewerExtension.h:153
ViewerExtension.h
camitk::ViewerExtension::getNewInstance
Viewer * getNewInstance(QString name)
factory: create a new viewer instance and register it
Definition: ViewerExtension.cpp:161
camitk::ViewerExtension::translator
QTranslator * translator
Provide internationalization support for text output.
Definition: ViewerExtension.h:163
camitk::Viewer
Viewer is an abstract class that is the base class for all viewers.
Definition: Viewer.h:180
camitk::ViewerExtension::dynamicLibraryFileName
QString dynamicLibraryFileName
the shared lib (.so, .dll or .dylib) used to instantiate the ComponentExtension subclass instance
Definition: ViewerExtension.h:160
camitk::ViewerList
QList< Viewer * > ViewerList
A list of Viewer.
Definition: CamiTKAPI.h:139
camitk::ViewerExtension::registerViewer
bool registerViewer(Viewer *)
register an viewer instance The first call will also register the managed viewer class name in viewer...
Definition: ViewerExtension.cpp:130
Viewer.h
camitk::ViewerExtension
This class describes what is a generic Action extension. To add a ActionExtension to CamiTK core,...
Definition: ViewerExtension.h:108
Core.h
Application.h
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:49
camitk
Definition: Action.cpp:35