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