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