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