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