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