1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
*
* 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 <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
#ifndef COMPONENT_EXTENSION_H
#define COMPONENT_EXTENSION_H
// -- Qt stuff
#include <QObject>
// -- CamiTK Core stuff
#include "CamiTKAPI.h"
namespace camitk {
class Component;
/**
* @ingroup group_sdk_libraries_core_component
*
* @brief
* This class describes what is a generic Component extension.
* To add a ComponentExtension to CamiTK core, write a new class that inherits from this class.
*
* There are two types of component extension: the classical one manages (mime type) file extension,
* the other one manages all files in a given directory (e.g. Dicom images). For the latter you have
* to redefine hasDataDirectory().
*
* The following methods HAVE to be redefined in your subclass:
* - getName
* - getDescription
* - getFileExtensions
* - open
*
* The following methods can be redefined:
* - save: saving from a Component to one of the managed format
* - hasDataDirectory: for directory type extension
*/
class CAMITK_API ComponentExtension : public QObject {
protected:
/// protected constructor, \note never directly instantiate a ComponentExtension, use loadExtension(...) instead!
ComponentExtension();
public:
/// protected destructor, \note never directly delete a ComponentExtension, use UnloadExtension(...) instead!
~ComponentExtension() override = default;
/// @name ComponentExtension plugin interface methods
/// @{
/// get the plugin name
virtual QString getName() const = 0;
/// get the plugin description
virtual QString getDescription() const = 0;
/// get the list of managed extensions (each file with an extension in the list can be loaded by this Component)
virtual QStringList getFileExtensions() const = 0;
/** get a new instance from data stored in a file (this is the most important method to redefine in your subclass)
*
* This method may throw an AbortException if a problem occurs.
*
* \note The parameter is a filename with an absolute path (from Qt's QFileInfo::absoluteFilePath method):
* On Unix (including Mac OS) this will always begin with the root, '/', directory.
* On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter,
* in which case the path will begin '//sharename/'
*/
virtual Component* open(const QString&) = 0;
/** save a given Component (does not have to be top-level) into one of the currently managed format (check
* the component QFileInfo(component->getFileName()).completeSuffix().
*
* Redefine this method to extract all needed data/information from the Geometry or BitMap representation
* in order to export a given component to one of the file extension managed by this component extension.
*
* \note this will enable to export to one of the managed filename extension at the CamiTK level (i.e. if
* you write this method, any compatible component can be saved to your managed format!
*
* \note this method is called by CamiTK only if the filename extension is managed by this component extension.
* There should be no need to check it in the method.
*
* The default behaviour is a "not implemented yet" message box.
*
* @return false if the operation was not performed properly or not performed at all.
*/
virtual bool save(Component* component) const;
/// return true if this component manages directory instead of individual files (e.g. Dicom series are stored in directories, not files)
virtual bool hasDataDirectory() const {
return false;
}
/// get the file path (location of the .dll/.so/.dylib) of this plugin
QString getLocation() const {
return dynamicLibraryFileName;
}
/// set the file path (once loaded as a dynamic library)
void setLocation(const QString loc) {
dynamicLibraryFileName = loc;
}
/// Load, for the selected langage (asked to the Application), the associated .qm file
void initResources();
/// @}
private:
/// the shared lib (.so, .dll or .dylib) used to instantiate the ComponentExtension subclass instance
QString dynamicLibraryFileName;
/// the autoload state
bool autoload;
};
}
// -------------------- declare the interface for QPluginLoader --------------------
Q_DECLARE_INTERFACE(camitk::ComponentExtension, "TIMC-IMAG.ComponentExtension/2.1") //TODO use variable from CMake?
#endif //COMPONENT_EXTENSION_H
|