]> 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       TFilter* CreateFilter(
74         const std::string& filter, const std::string& name
75         );
76       bool RenameFilter(
77         const std::string& old_name, const std::string& new_name
78         );
79       void RemoveFilter( const std::string& name );
80
81       // Widgets management
82       vtkRenderWindowInteractor* GetSingleInteractor( );
83       const vtkRenderWindowInteractor* GetSingleInteractor( ) const;
84       void SetSingleInteractor( vtkRenderWindowInteractor* interactor );
85
86       SimpleMPRWidget* GetMPRViewer( );
87       const SimpleMPRWidget* GetMPRViewer( ) const;
88       void SetMPRViewer( SimpleMPRWidget* wdg );
89
90       // Connection management
91       bool Connect(
92         const std::string& orig_filter, const std::string& dest_filter,
93         const std::string& output_name, const std::string& input_name
94         );
95       bool Connect(
96         TData::Pointer* input_object, const std::string& exposed_port
97         );
98       void RemoveConnection(
99         const std::string& dest_filter, const std::string& input_name
100         );
101       void RemoveConnection( const std::string& exposed_port );
102       void RemoveConnections( const std::string& dest_filter );
103
104       // Graph reduction
105       bool Reduce( const std::string& name );
106       void ExposeInputPort(
107         const std::string& name,
108         const std::string& filter, const std::string& filter_input
109         );
110       void ExposeOutputPort(
111         const std::string& name,
112         const std::string& filter, const std::string& filter_output
113         );
114       void HideInputPort( const std::string& name );
115       void HideOutputPort( const std::string& name );
116
117       bool RenameExposedInputPort(
118         const std::string& old_name,
119         const std::string& new_name
120         );
121       bool RenameExposedOutputPort(
122         const std::string& old_name,
123         const std::string& new_name
124         );
125
126       const TExposedPorts& GetExposedInputPorts( ) const;
127       const TExposedPorts& GetExposedOutputPorts( ) const;
128
129       TData* GetExposedInput( const std::string& name );
130       const TData* GetExposedInput( const std::string& name ) const;
131       TData* GetExposedOutput( const std::string& name );
132       const TData* GetExposedOutput( const std::string& name ) const;
133
134       // Pipeline execution
135       std::string Execute( );
136       std::string Execute( const std::string& name );
137
138     protected:
139       // Plugins interface
140       TPlugins* m_Plugins;
141
142       // Processing graph
143       TGraph::Pointer m_Graph;
144       TExposedPorts m_ExposedInputPorts;
145       TExposedPorts m_ExposedOutputPorts;
146
147       vtkSmartPointer< vtkRenderWindowInteractor > m_SingleInteractor;
148       SimpleMPRWidget*                             m_MPRViewer;
149     };
150
151   } // ecapseman
152
153 } // ecapseman
154
155 #endif // __CPPLUGINS__INTERFACE__WORKSPACE__H__
156
157 // eof - $RCSfile$