]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxGimmickView.h
Added synchronization
[creaImageIO.git] / src2 / creaImageIOWxGimmickView.h
1 #ifndef __creaImageIOWxGimmickView_h_INCLUDED__
2 #define __creaImageIOWxGimmickView_h_INCLUDED__
3
4 #ifdef USE_WXWIDGETS
5
6 #include <creaImageIOGimmickView.h>
7 #include <creaImageIOWxViewer.h>
8 #include <creaWx.h>
9
10 #include <wx/splitter.h>
11 #include <wx/toolbar.h> 
12 #include <wx/tbarbase.h> 
13 #include <wx/notebook.h>
14
15 namespace creaImageIO
16 {
17   /**
18    * \ingroup View
19    */
20   //=====================================================================
21   
22   //=====================================================================
23   /// Concrete derivative of GimmickView which implements a wxWidgets-based view
24
25   class WxGimmickView : public wxPanel, virtual public GimmickView
26   {
27   public:
28     
29     typedef int EventType;
30     
31     /// Ctor
32     WxGimmickView(Gimmick*, 
33                   wxWindow *parent, 
34                   const wxWindowID id,
35                   const wxPoint& pos, const wxSize& size,
36                   int min_dim = GIMMICK_2D_IMAGE_SELECTION,
37                   int max_dim = GIMMICK_3D_IMAGE_SELECTION,
38                   int number_of_threads = 0);
39     /// Virtual destructor
40     virtual ~WxGimmickView();
41     
42     /// Returns the selected files
43     ///(overloaded from GimmickView)
44     void GetSelectedFiles(std::vector<std::string>& s);
45     
46     /// Returns the selected Images so that they comply with the 
47     /// given parameter(4D) (overloaded from GimmickView)
48     void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
49
50     /// Returns the images indicated by the filenames in the vector 
51     /// so that they comply with the given parameter(dim)
52     //(overloaded from GimmickView) 
53     void GetImages(int dim, const std::vector<std::string>& files, 
54                    std::vector<vtkImageData*>& s);
55     
56     /// Callback called when a selection from a TreeView has changed 
57     //(overloaded from GimmickView)
58     void OnSelectionChange(const std::vector<tree::Node*>& s, 
59                            bool isSelection, int selection, bool mProcess);
60     ///Stops the player
61     void StopPlayer(){mViewer->StopPlayer();}
62         ///Adds a file to ignore
63         void AddIgnoreFile(const tree::Node* & toRemove);
64     ///Resets the default image
65     void ClearSelection();
66     
67     
68     ///Sends a request to read the currently selected node and the ones that surround it.
69     void ReadImageThreaded(const std::vector<tree::Node*>& sel);
70     
71     
72   protected:
73     /// Creates the tool bar
74     void CreateToolBar(); 
75     
76     /// Create the tree view for TreeHandler provided 
77     /// (overloaded from GimmickView)
78     void CreateTreeView( TreeHandler* );
79     
80     
81   private:
82     /// Is set to true at the end of constructor 
83     /// (in order to lock callbacks from threaded objects or event 
84     /// before everything is ok)
85     bool mConstructed;
86     /// The ToolBar and the tools
87     wxToolBar*         mToolBar;
88     wxToolBarToolBase* mToolAddFile;
89     wxToolBarToolBase* mToolAddDir;
90     wxToolBarToolBase* mToolRemove;
91     wxToolBarToolBase* mToolAddDatabase;
92     wxToolBarToolBase* mToolHelp;
93         wxToolBarToolBase* mToolSynchronize;
94     
95     wxSplitterWindow* mSplitter;
96     wxPanel*          mBottomPanel;
97     wxStaticText *    mText;
98     wxNotebook*       mNotebook;
99     
100     /// The list of icons 
101     wxImageList *    mIcon;
102     void CreateIconList();
103     
104     Gimmick * mGimmick;
105     /// Callback for adding files
106     void OnAddFiles(wxCommandEvent& event);
107     /// Callback for adding dir
108     void OnAddDir(wxCommandEvent& event);
109     /// Callback for removing files
110     void OnRemove(wxCommandEvent& event);
111         /// Callback for removing files
112     void OnSynchronize(wxCommandEvent& event);
113     
114     /// Display a message box with the last addition statistics
115     void DisplayAddSummary();
116
117         /// Test a directory to know if contains sub-directory to analyze
118         bool isNeedRecursive(std::string i_name);
119     
120     /// AddProgress Gimmick callback
121     void OnAddProgress( Gimmick::AddProgress& );
122     /// Called upon to refresh the viewer once there are no actions to be done
123     void OnInternalIdle();
124
125         // callback to add a database
126         void OnAddDB(wxCommandEvent& event);
127     
128     /// Progress dialog
129     wxProgressDialog* mProgressDialog;
130     ///The selection's maximum dimension
131     int mSelectionMaxDimension;
132     ///The selection's minimum dimension
133     int mSelectionMinDimension;
134     ///Image previewer
135     WxViewer* mViewer;
136     ///Currently Displayed Node
137     tree::Node* mCurImageItemToShow;
138     //Pointer holders for images to be shown
139     std::vector<ImagePointerHolder*> pointers;
140     
141     
142     wxString mCurrentDirectory;
143     
144     DECLARE_EVENT_TABLE()
145       };
146   // EO class WxGimmickView
147   //=====================================================================
148   
149   
150   /*
151
152
153
154
155
156
157
158
159         //====================================================================
160         // General
161         //====================================================================
162
163     /// Returns the size of the current selection
164     virtual int GetSelectionSize() { return 0; } 
165     /// Returns true if there is a valid selection
166     virtual bool IsSelectionValid(){ return false; }
167     /// Returns the vector of full filenames of selected images
168     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
169     /// Returns the vector of images corresponding to selection
170     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
171     /// Returns the vector of DicomNode corresponding to selection
172     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
173    /// Returns the DicomNode corresponding to the tree item
174     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
175
176         
177         /// Type of list of DicomDatabase
178     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
179     /// Returns the list of DicomDatabase open
180     virtual DicomDatabaseListType& GetDicomDatabaseList() 
181     { return null; }
182     /// Returns the list of DicomDatabase open (const)
183     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
184     { return null; }
185
186         protected:
187         ///Opens an existing database, or else, creates a local database.
188     virtual void OpenOrNewDatabase(bool open){ return; }
189         ///Shows the help
190         virtual void ShowHelp();
191
192         private:
193         ///Gets the extension of the database
194         const std::string& GetDatabaseExtension() { return null; }
195         ///Sets the extension of the database
196     virtual void SetDatabaseExtension(const std::string& ext){ return; }
197
198
199         //====================================================================
200     // Preview Display Related
201         //====================================================================
202
203
204     ///Shows the image sent as a parameter
205         private:
206          virtual void ShowImage(vtkImageData* image){ return; }
207
208         //====================================================================
209     // Favorites Related
210         //====================================================================
211
212
213         public:
214         ///Loads or creates a favorites database
215     virtual void LoadOrCreateFavoritesDatabase(){ return; }
216         private:
217         ///Creates the user settings directory
218     void CreateUserSettingsDirectory(){ return; }
219         ///Obtains the user settings directory
220         const std::string& GetUserSettingsDirectory(){ return null; }
221
222         //====================================================================  
223         // Attribute Display Related
224         //====================================================================
225
226
227         ///Shows the Information regarding the node sent as a parameter
228         private:
229      virtual void ShowInformation(DicomNode*){ return; }
230    
231         //====================================================================
232     // Tree Display Related
233     //====================================================================
234
235         protected:
236     /// Completely rebuilds the view with 
237     /// current DicomDatabaseList
238     virtual void RebuildView(){ return; }
239         /// Recursively updates the part of the view corresponding 
240     /// to the DicomDatabase passed
241     /// i.e. creates items for the DicomNode which do not have
242     ///      deletes obsolete items (whose DicomNode has been deleted)
243     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
244     /// Recursively updates the part of the view corresponding 
245     /// to the DicomNode provided.
246     /// parent is its parent in the tree (where to insert / remove it)
247         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
248     
249         private:
250         ///Type definition of the data regarding the tree
251     typedef WxGimmickTreeItemData TreeItemData;
252         ///Gets the item data of the tree item passed as a parameter
253     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
254     ///Type definition of the data insid a node of the tree
255     typedef WxGimmickDicomNodeData NodeData;
256
257
258         //====================================================================
259     // Class Attributes
260     //====================================================================
261
262         
263         int mSelectionType;
264     int mSelectionMaxImageDimension;
265     int mCurrentSelectionImageSize[4];
266
267         ///Existent Database List
268     DicomDatabaseListType mDicomDatabaseList;
269         ///Favorites database
270     DicomDatabase* mFavoriteDatabase;
271
272         ///Path to the database list file
273     std::string mDatabaseListFile;
274         ///Extension of the database
275     std::string mDatabaseExtension;
276
277     bool mJustStarted;
278
279     int  mFirstDicomDatabaseIconIndex;
280
281    // Previewer
282     vtkImageViewer2* mViewer;
283     
284     int mx1,mx2,my1,my2,mz1,mz2;
285     double mspx,mspy,mspz;
286   
287     // Image preview :
288     // Multi-thread image reader
289     MultiThreadImageReader mReader;
290     // map of images name to node
291     std::map<std::string,DicomNode*> mImageFileNameToNode;
292   */
293  
294 } // EO namespace creaImageIO
295
296 #endif // USE_WIDGETS
297 // EOF
298 #endif