]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Workspace.h
MVC integration at 50%
[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     DataObject* GetOutput(
72       const std::string& filter, const std::string& output
73       );
74     const DataObject* GetOutput(
75       const std::string& filter, const std::string& output
76       ) const;
77     bool HasFilter( const std::string& name ) const;
78     ProcessObject* CreateFilter(
79       const std::string& category,
80       const std::string& filter,
81       const std::string& name
82       );
83     bool RenameFilter(
84       const std::string& old_name, const std::string& new_name
85       );
86     void RemoveFilter( const std::string& name );
87     void SetParameter( const std::string& name, const std::string& value );
88
89     void SetPrintExecution( bool b );
90     void PrintExecutionOn( );
91     void PrintExecutionOff( );
92
93     // Widgets management
94     vtkRenderWindowInteractor* GetSingleInteractor( );
95     const vtkRenderWindowInteractor* GetSingleInteractor( ) const;
96     void SetSingleInteractor( vtkRenderWindowInteractor* interactor );
97
98     TMPRWidget* GetMPRViewer( );
99     const TMPRWidget* GetMPRViewer( ) const;
100     void SetMPRViewer( TMPRWidget* wdg );
101
102     // Connection management
103     bool Connect(
104       const std::string& orig_filter, const std::string& dest_filter,
105       const std::string& output_name, const std::string& input_name
106       );
107     bool Connect( const OutputPort& port, const std::string& exposed_port );
108     void RemoveConnection(
109       const std::string& dest_filter, const std::string& input_name
110       );
111     void RemoveConnection( const std::string& exposed_port );
112     void RemoveConnections( const std::string& dest_filter );
113
114     // Graph reduction
115     bool Reduce( const std::string& name );
116     void ExposeInputPort(
117       const std::string& name,
118       const std::string& filter, const std::string& filter_input
119       );
120     void ExposeOutputPort(
121       const std::string& name,
122       const std::string& filter, const std::string& filter_output
123       );
124     void HideInputPort( const std::string& name );
125     void HideOutputPort( const std::string& name );
126
127     bool RenameExposedInputPort(
128       const std::string& old_name,
129       const std::string& new_name
130       );
131     bool RenameExposedOutputPort(
132       const std::string& old_name,
133       const std::string& new_name
134       );
135
136     const TExposedPorts& GetExposedInputPorts( ) const;
137     const TExposedPorts& GetExposedOutputPorts( ) const;
138
139     OutputPort& GetExposedOutput( const std::string& name );
140     const OutputPort& GetExposedOutput( const std::string& name ) const;
141
142     // Pipeline execution
143     void Execute( );
144     void Execute( const std::string& name );
145
146   protected:
147     // Plugins interface
148     Interface* m_Interface;
149     bool       m_PrintExecution;
150
151     // Processing graph
152     TGraph::Pointer m_Graph;
153     TExposedPorts m_ExposedInputPorts;
154     TExposedPorts m_ExposedOutputPorts;
155
156     vtkSmartPointer< vtkRenderWindowInteractor > m_SingleInteractor;
157     TMPRWidget*                                  m_MPRViewer;
158   };
159
160 } // ecapseman
161
162 #endif // __CPPLUGINS__WORKSPACE__H__
163
164 // eof - $RCSfile$