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