]> 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         ///Add selected files to the Database
71         void AddDir(std::string dirName);
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         ///Called upon when a field has been edited
96         void OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
97
98         ///Called upon to return the visible attributes of the current tab
99         void GetVisibleAttributes(std::vector<std::string>& shown,std::vector<std::string>& nShown, int level);
100
101         ///Called when there has been a change in the visible attributes of a tree view
102         void OnAttributesChanged(const std::vector<std::string>& nShown, int level);
103     
104   protected:
105     /// Creates the tool bar
106     void CreateToolBar(); 
107     
108     /// Create the tree view for TreeHandler provided 
109     /// (overloaded from GimmickView)
110     void CreateTreeView( TreeHandler* );
111     
112     
113   private:
114     /// Is set to true at the end of constructor 
115     /// (in order to lock callbacks from threaded objects or event 
116     /// before everything is ok)
117     bool mConstructed;
118     /// The ToolBar and the tools
119     wxToolBar*         mToolBar;
120     wxToolBarToolBase* mToolAddFile;
121     wxToolBarToolBase* mToolAddDir;
122     wxToolBarToolBase* mToolRemove;
123     wxToolBarToolBase* mToolAddDatabase;
124     wxToolBarToolBase* mToolHelp;
125         wxToolBarToolBase* mToolSynchronize;
126         wxToolBarToolBase* mToolSettings;
127         wxToolBarToolBase* mToolTools;
128     
129     wxSplitterWindow* mSplitter;
130     wxPanel*          mBottomPanel;
131     wxStaticText *    mText;
132     wxNotebook*       mNotebook;
133     
134     /// The list of icons 
135     wxImageList *    mIcon;
136     void CreateIconList();
137     
138     Gimmick * mGimmick;
139         
140         Listener* mListener;
141     /// Callback for adding files
142     void OnAddFiles(wxCommandEvent& event);
143     /// Callback for adding dir
144     void OnAddDir(wxCommandEvent& event);
145     /// Callback for removing files
146     void OnRemove(wxCommandEvent& event);
147         /// Callback for synchronization
148     void OnSynchronize(wxCommandEvent& event);
149         /// Callback for settings edition
150     void OnSettings(wxCommandEvent& event);
151         /// Callback for settings edition
152     void OnTools(wxCommandEvent& event);
153         ///Creates the settings dialog (the pages inside and the information)
154         void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
155     
156     /// Display a message box with the last addition statistics
157     void DisplayAddSummary();
158
159         /// Test a directory to know if contains sub-directory to analyze
160         bool isNeedRecursive(std::string i_name);
161     
162     /// AddProgress Gimmick callback
163     void OnAddProgress( Gimmick::AddProgress& );
164     /// Called upon to refresh the viewer once there are no actions to be done
165     void OnInternalIdle();
166
167         /// callback to add a database
168         void OnAddDB(wxCommandEvent& event);
169     
170         ///Create a DB from an Attributes Descriptor files 
171         void OnCreateDB(wxCommandEvent& event);
172
173         ///Edits the fields of a given node
174         void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
175  
176     /// Progress dialog
177     wxProgressDialog* mProgressDialog;
178     ///The selection's maximum dimension
179     int mSelectionMaxDimension;
180     ///The selection's minimum dimension
181     int mSelectionMinDimension;
182     ///Image previewer
183     WxViewer* mViewer;
184     ///Currently Displayed Node
185     tree::Node* mCurImageItemToShow;
186     //Pointer holders for images to be shown
187     std::vector<ImagePointerHolder*> pointers;
188     
189     
190     wxString mCurrentDirectory;
191     
192     DECLARE_EVENT_TABLE()
193       };
194   // EO class WxGimmickView
195   //=====================================================================
196   
197   
198   /*
199
200
201
202
203
204
205
206
207         //====================================================================
208         // General
209         //====================================================================
210
211     /// Returns the size of the current selection
212     virtual int GetSelectionSize() { return 0; } 
213     /// Returns true if there is a valid selection
214     virtual bool IsSelectionValid(){ return false; }
215     /// Returns the vector of full filenames of selected images
216     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
217     /// Returns the vector of images corresponding to selection
218     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
219     /// Returns the vector of DicomNode corresponding to selection
220     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
221    /// Returns the DicomNode corresponding to the tree item
222     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
223
224         
225         /// Type of list of DicomDatabase
226     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
227     /// Returns the list of DicomDatabase open
228     virtual DicomDatabaseListType& GetDicomDatabaseList() 
229     { return null; }
230     /// Returns the list of DicomDatabase open (const)
231     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
232     { return null; }
233
234         protected:
235         ///Opens an existing database, or else, creates a local database.
236     virtual void OpenOrNewDatabase(bool open){ return; }
237         ///Shows the help
238         virtual void ShowHelp();
239
240         private:
241         ///Gets the extension of the database
242         const std::string& GetDatabaseExtension() { return null; }
243         ///Sets the extension of the database
244     virtual void SetDatabaseExtension(const std::string& ext){ return; }
245
246
247         //====================================================================
248     // Preview Display Related
249         //====================================================================
250
251
252     ///Shows the image sent as a parameter
253         private:
254          virtual void ShowImage(vtkImageData* image){ return; }
255
256         //====================================================================
257     // Favorites Related
258         //====================================================================
259
260
261         public:
262         ///Loads or creates a favorites database
263     virtual void LoadOrCreateFavoritesDatabase(){ return; }
264         private:
265         ///Creates the user settings directory
266     void CreateUserSettingsDirectory(){ return; }
267         ///Obtains the user settings directory
268         const std::string& GetUserSettingsDirectory(){ return null; }
269
270         //====================================================================  
271         // Attribute Display Related
272         //====================================================================
273
274
275         ///Shows the Information regarding the node sent as a parameter
276         private:
277      virtual void ShowInformation(DicomNode*){ return; }
278    
279         //====================================================================
280     // Tree Display Related
281     //====================================================================
282
283         protected:
284     /// Completely rebuilds the view with 
285     /// current DicomDatabaseList
286     virtual void RebuildView(){ return; }
287         /// Recursively updates the part of the view corresponding 
288     /// to the DicomDatabase passed
289     /// i.e. creates items for the DicomNode which do not have
290     ///      deletes obsolete items (whose DicomNode has been deleted)
291     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
292     /// Recursively updates the part of the view corresponding 
293     /// to the DicomNode provided.
294     /// parent is its parent in the tree (where to insert / remove it)
295         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
296     
297         private:
298         ///Type definition of the data regarding the tree
299     typedef WxGimmickTreeItemData TreeItemData;
300         ///Gets the item data of the tree item passed as a parameter
301     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
302     ///Type definition of the data insid a node of the tree
303     typedef WxGimmickDicomNodeData NodeData;
304
305
306         //====================================================================
307     // Class Attributes
308     //====================================================================
309
310         
311         int mSelectionType;
312     int mSelectionMaxImageDimension;
313     int mCurrentSelectionImageSize[4];
314
315         ///Existent Database List
316     DicomDatabaseListType mDicomDatabaseList;
317         ///Favorites database
318     DicomDatabase* mFavoriteDatabase;
319
320         ///Path to the database list file
321     std::string mDatabaseListFile;
322         ///Extension of the database
323     std::string mDatabaseExtension;
324
325     bool mJustStarted;
326
327     int  mFirstDicomDatabaseIconIndex;
328
329    // Previewer
330     vtkImageViewer2* mViewer;
331     
332     int mx1,mx2,my1,my2,mz1,mz2;
333     double mspx,mspy,mspz;
334   
335     // Image preview :
336     // Multi-thread image reader
337     MultiThreadImageReader mReader;
338     // map of images name to node
339     std::map<std::string,DicomNode*> mImageFileNameToNode;
340   */
341  
342 } // EO namespace creaImageIO
343
344 #endif // USE_WIDGETS
345 // EOF
346 #endif