]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/Workspace.h
...
[cpPlugins.git] / lib / cpPlugins / Interface / Workspace.h
1 #ifndef __CPPLUGINS__INTERFACE__WORKSPACE__H__
2 #define __CPPLUGINS__INTERFACE__WORKSPACE__H__
3
4 #include <cpExtensions/DataStructures/Graph.h>
5 #include <cpPlugins/Interface/Interface.h>
6 #include <cpPlugins/Interface/DataObject.h>
7 #include <cpPlugins/Interface/ProcessObject.h>
8
9 #include <set>
10 #include <string>
11
12 // Some forward declarations
13 class QWidget;
14 class vtkRenderWindowInteractor;
15
16 namespace cpPlugins
17 {
18   namespace Interface
19   {
20     // Some forward declarations
21 #ifdef cpPlugins_Interface_QT4
22     class SimpleMPRWidget;
23 #else // cpPlugins_Interface_QT4
24     typedef char SimpleMPRWidget;
25 #endif // cpPlugins_Interface_QT4
26
27     /** \brief A complex pipeline
28      */
29     class cpPlugins_Interface_EXPORT Workspace
30     {
31     public:
32       typedef cpPlugins::Interface::Interface     TPlugins;
33       typedef cpPlugins::Interface::Object        TObject;
34       typedef cpPlugins::Interface::ProcessObject TFilter;
35       typedef cpPlugins::Interface::DataObject    TData;
36       typedef TFilter::TParameters                TParameters;
37
38       // Various types
39       typedef std::set< std::string >               TStringContainer;
40       typedef std::pair< std::string, std::string > TExposedPort;
41       typedef std::map< std::string, TExposedPort > TExposedPorts;
42
43       // Graph type
44       typedef std::pair< std::string, std::string > TConnection;
45       typedef
46         cpExtensions::DataStructures::
47         Graph< TObject::Pointer, TConnection, std::string > TGraph;
48
49     public:
50       Workspace( );
51       virtual ~Workspace( );
52
53       // Plugins management
54       TPlugins* GetPlugins( );
55       const TPlugins* GetPlugins( ) const;
56       void SetPlugins( TPlugins* i );
57
58       // Workspace IO
59       std::string LoadWorkspace( const std::string& fname );
60       std::string SaveWorkspace( const std::string& fname ) const;
61
62       // Graph management
63       TGraph* GetGraph( );
64       const TGraph* GetGraph( ) const;
65
66       void Clear( );
67       void ClearConnections( );
68
69       // Filter management
70       TFilter* GetFilter( const std::string& name );
71       const TFilter* GetFilter( const std::string& name ) const;
72       bool HasFilter( const std::string& name ) const;
73       bool CreateFilter( const std::string& filter, const std::string& name );
74       bool RenameFilter(
75         const std::string& old_name, const std::string& new_name
76         );
77       void RemoveFilter( const std::string& name );
78
79       // Widgets management
80       vtkRenderWindowInteractor* GetSingleInteractor( );
81       const vtkRenderWindowInteractor* GetSingleInteractor( ) const;
82       void SetSingleInteractor( vtkRenderWindowInteractor* interactor );
83
84       SimpleMPRWidget* GetMPRViewer( );
85       const SimpleMPRWidget* GetMPRViewer( ) const;
86       void SetMPRViewer( SimpleMPRWidget* wdg );
87
88       // Connection management
89       bool Connect(
90         const std::string& orig_filter, const std::string& dest_filter,
91         const std::string& output_name, const std::string& input_name
92         );
93       bool Connect( TData* input_object, const std::string& exposed_port );
94       void RemoveConnection(
95         const std::string& dest_filter, const std::string& input_name
96         );
97       void RemoveConnection( const std::string& exposed_port );
98       void RemoveConnections( const std::string& dest_filter );
99
100       // Graph reduction
101       bool Reduce( const std::string& name );
102       void ExposeInputPort(
103         const std::string& name,
104         const std::string& filter, const std::string& filter_input
105         );
106       void ExposeOutputPort(
107         const std::string& name,
108         const std::string& filter, const std::string& filter_output
109         );
110       void HideInputPort( const std::string& name );
111       void HideOutputPort( const std::string& name );
112
113       bool RenameExposedInputPort(
114         const std::string& old_name,
115         const std::string& new_name
116         );
117       bool RenameExposedOutputPort(
118         const std::string& old_name,
119         const std::string& new_name
120         );
121
122       const TExposedPorts& GetExposedInputPorts( ) const;
123       const TExposedPorts& GetExposedOutputPorts( ) const;
124
125       TData* GetExposedInput( const std::string& name );
126       const TData* GetExposedInput( const std::string& name ) const;
127       TData* GetExposedOutput( const std::string& name );
128       const TData* GetExposedOutput( const std::string& name ) const;
129
130       // Pipeline execution
131       std::string Execute( );
132       std::string Execute( const std::string& name );
133
134     protected:
135       // Plugins interface
136       TPlugins* m_Plugins;
137
138       // Processing graph
139       typename TGraph::Pointer m_Graph;
140       TExposedPorts m_ExposedInputPorts;
141       TExposedPorts m_ExposedOutputPorts;
142
143       vtkSmartPointer< vtkRenderWindowInteractor > m_SingleInteractor;
144       SimpleMPRWidget*                             m_MPRViewer;
145     };
146
147   } // ecapseman
148
149 } // ecapseman
150
151 #endif // __CPPLUGINS__INTERFACE__WORKSPACE__H__
152
153 // eof - $RCSfile$