]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Workspace.h
e779b075a12b3980058292a0082be65404522c86
[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     // Widgets management
84     vtkRenderWindowInteractor* GetSingleInteractor( );
85     const vtkRenderWindowInteractor* GetSingleInteractor( ) const;
86     void SetSingleInteractor( vtkRenderWindowInteractor* interactor );
87
88     TMPRWidget* GetMPRViewer( );
89     const TMPRWidget* GetMPRViewer( ) const;
90     void SetMPRViewer( TMPRWidget* wdg );
91
92     // Connection management
93     bool Connect(
94       const std::string& orig_filter, const std::string& dest_filter,
95       const std::string& output_name, const std::string& input_name
96       );
97     bool Connect( const OutputPort& port, const std::string& exposed_port );
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     OutputPort& GetExposedOutput( const std::string& name );
130     const OutputPort& GetExposedOutput( const std::string& name ) const;
131
132     // Pipeline execution
133     void Execute( );
134     void Execute( const std::string& name );
135
136   protected:
137     // Plugins interface
138     Interface* m_Interface;
139
140     // Processing graph
141     TGraph::Pointer m_Graph;
142     TExposedPorts m_ExposedInputPorts;
143     TExposedPorts m_ExposedOutputPorts;
144
145     vtkSmartPointer< vtkRenderWindowInteractor > m_SingleInteractor;
146     TMPRWidget*                                  m_MPRViewer;
147   };
148
149 } // ecapseman
150
151 #endif // __CPPLUGINS__WORKSPACE__H__
152
153 // eof - $RCSfile$