]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Plugins.h
...
[cpPlugins.git] / lib / cpPlugins / Interface / Plugins.h
1 #ifndef __CPPLUGINS__INTERFACE__PLUGINS__H__
2 #define __CPPLUGINS__INTERFACE__PLUGINS__H__
3
4 #include <cpPlugins/Interface/Interface.h>
5 #include <cpPlugins/Interface/DataObject.h>
6 #include <cpPlugins/Interface/ProcessObject.h>
7
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 // Some forward declarations
14 class vtkRenderWindowInteractor;
15 #ifdef cpPlugins_Interface_QT4
16 class QWidget;
17 #else
18 typedef char QWidget;
19 #endif // cpPlugins_Interface_QT4
20
21 namespace cpPlugins
22 {
23   namespace Interface
24   {
25     // Some forward declarations
26     class BaseApplication;
27
28     /**
29      */
30     class cpPlugins_Interface_EXPORT Plugins
31     {
32     public:
33       typedef cpPlugins::Interface::Interface     TInterface;
34       typedef cpPlugins::Interface::ProcessObject TProcessObject;
35       typedef cpPlugins::Interface::DataObject    TDataObject;
36       typedef TProcessObject::TParameters         TParameters;
37
38       typedef std::set< std::string > TStringContainer;
39
40     public:
41       Plugins( );
42       virtual ~Plugins( );
43
44       // Qt oriented methods
45       QWidget* GetWidget( );
46       const QWidget* GetWidget( ) const;
47       void SetWidget( QWidget* widget );
48       void BlockWidget( );
49       void UnblockWidget( );
50       void DialogLoadPlugins( );
51
52       // Connection to main application
53       BaseApplication* GetApplication( );
54       const BaseApplication* GetApplication( ) const;
55       void SetApplication( BaseApplication* a );
56
57       // Plugins management
58       bool LoadPluginsPath( const std::string& path, bool r = false );
59       bool LoadPlugins( const std::string& fname );
60       bool LoadPluginsConfigurationFile( const std::string& fname );
61       const TStringContainer& GetLoadedPlugins( ) const;
62       void GetLoadedCategories( TStringContainer& categories ) const;
63       void GetLoadedFilters( TStringContainer& filters ) const;
64       const TStringContainer& GetLoadedFilters(
65         const std::string& category
66         ) const;
67
68       // Interactors
69       void AddInteractor( vtkRenderWindowInteractor* interactor );
70       void RemoveInteractor( vtkRenderWindowInteractor* interactor );
71       void ClearInteractors( );
72
73       // Data IO
74       bool HasImageReader( ) const;
75       bool HasDicomSeriesReader( ) const;
76       bool HasMeshReader( ) const;
77       bool HasImageWriter( ) const;
78       bool HasMeshWriter( ) const;
79
80       std::string ReadImage(
81         const std::string& fname, const std::string& parent
82         );
83       std::string ReadImage(
84         const std::vector< std::string >& fnames, const std::string& parent
85         );
86       std::string ReadImage( const std::string& parent );
87       std::string ReadDicomSeries( const std::string& parent );
88       std::string ReadMesh(
89         const std::string& fname, const std::string& parent
90         );
91       std::string ReadMesh( const std::string& parent );
92
93       bool WriteDataObject(
94         const std::string& fname, const std::string& name
95         );
96       bool WriteDataObject( const std::string& name );
97
98       // Data objects
99       void ClearDataObjects( );
100       void DeleteDataObject( const std::string& name );
101       void GetDataObjects( TStringContainer& names );
102       std::string GetParent( const std::string& name ) const;
103       void GetChildren(
104         TStringContainer& names, const std::string& name
105         ) const;
106       void GetRoots( TStringContainer& names ) const;
107
108       template< class T >
109         inline T* GetData( const std::string& name );
110
111       template< class T >
112         inline const T* GetData( const std::string& name ) const;
113
114       // Filter acces
115       bool ActivateFilter( const std::string& name );
116       void DeactivateFilter( );
117       bool HasActiveFilter( ) const;
118       bool IsActiveFilterInteractive( ) const;
119       void GetActiveFilterInputsNames( TStringContainer& names ) const;
120       void GetActiveFilterOutputsNames( TStringContainer& names ) const;
121       bool ConnectInputInActiveFilter(
122         const std::string& object_name, const std::string& input_name
123         );
124       bool SetOutputNameInActiveFilter(
125         const std::string& new_object_name, const std::string& output_name
126         );
127       TParameters* GetActiveFilterParameters( );
128       const TParameters* GetActiveFilterParameters( ) const;
129       TProcessObject::DialogResult ConfigureActiveFilter( );
130       bool UpdateActiveFilter(
131         TStringContainer& outputs,
132         const std::string& parent
133         );
134
135     protected:
136       void _UpdateLoadedPluginsInformation( );
137       bool _ActivateIOFilter( const std::string& filter );
138       std::string _ReadData( const std::string& parent );
139       bool _WriteData( const std::string& name );
140       bool _InsertNewData( TDataObject* dobj, const std::string& parent );
141
142     protected:
143       // MVC objects
144       QWidget*         m_Widget;
145       BaseApplication* m_Application;
146
147       // Plugins interface
148       TInterface                                m_Interface;
149       TStringContainer                          m_LoadedPlugins;
150       std::string                               m_LastLoadedPlugin;
151       std::map< std::string, TStringContainer > m_LoadedFilters;
152
153       // Loaded filters
154       std::map< std::string, TProcessObject::Pointer > m_IOFilters;
155       TProcessObject::Pointer                       m_ActiveFilter;
156
157       // Loaded data objects
158       typedef std::pair< std::string, TDataObject::Pointer >  _TTreeNode;
159       std::map< std::string, _TTreeNode > m_DataObjects;
160
161       // Associated interactors
162       std::set< vtkRenderWindowInteractor* > m_Interactors;
163     };
164
165   } // ecapseman
166
167 } // ecapseman
168
169 #include <cpPlugins/Interface/Plugins.hxx>
170
171 #endif // __CPPLUGINS__INTERFACE__PLUGINS__H__
172
173 // eof - $RCSfile$