]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxGimmickView.h
63723f238f77c8d5b0e9ec0336d1ea0516d7fb67
[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
12 #include "wx/progdlg.h"
13
14 #include "wx/wx.h"
15 #include <wx/splitter.h>
16 #include <wx/toolbar.h> 
17 #include <wx/tbarbase.h> 
18 #include <wx/notebook.h>
19
20 namespace creaImageIO
21 {
22   /**
23    * \ingroup View
24    */
25   //=====================================================================
26   
27   //=====================================================================
28   /// Concrete derivative of GimmickView which implements a wxWidgets-based view
29
30   class WxGimmickView : public wxPanel, virtual public GimmickView
31   {
32   public:
33     
34     typedef int EventType;
35     
36     /// Ctor
37     WxGimmickView(boost::shared_ptr<Gimmick>, 
38                   wxWindow *parent, 
39                   const wxWindowID id,
40                   const wxPoint& pos, const wxSize& size,
41                   int min_dim = GIMMICK_2D_IMAGE_SELECTION,
42                   int max_dim = GIMMICK_3D_IMAGE_SELECTION,
43                   int number_of_threads = 0);
44     /// Virtual destructor
45     virtual ~WxGimmickView();
46     
47     /// Returns the selected files
48     ///(overloaded from GimmickView)
49     void GetSelectedFiles(std::vector<std::string>& s);
50     
51     /// Returns the selected Images so that they comply with the 
52     /// given parameter(4D) (overloaded from GimmickView)
53     void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
54     void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim);
55
56     /// Returns the images indicated by the filenames in the vector 
57     /// so that they comply with the given parameter(dim)
58     //(overloaded from GimmickView) 
59     void GetImages(int dim, const std::vector<std::string>& files, 
60                    std::vector<vtkImageData*>& s);
61     
62     /// Callback called when a selection from a TreeView has changed 
63     //(overloaded from GimmickView)
64     void OnSelectionChange(const std::vector<tree::Node*>& s, 
65                            bool isSelection, int selection, bool mProcess);
66     ///Stops the player
67     void StopPlayer(){mViewer->StopPlayer();}
68     ///Adds a file to ignore
69     void AddIgnoreFile(tree::Node* toRemove);
70     ///Resets the default image
71     void ClearSelection();
72         ///Copies selected files
73     void CopyFiles(const std::vector<std::string>& filenames);
74         ///Add selected files to the Database
75     void AddDir(std::string dirName);
76     
77     
78     ///Sends a request to read the currently selected node and the ones that surround it.
79     void ReadImageThreaded(const std::vector<tree::Node*>& sel);
80
81         ///Saves the settings to the file
82         void OnSaveSettingsCallback(const std::string& copyPath,
83           const std::string& dbPath,
84           const std::string& syncEvent,
85           const std::string& syncFreq);
86         
87         ///Changes listener state
88         void OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles);
89
90         ///Acts upon a drive mount
91         void OnDriveMount(bool mount);
92
93         ///Starts the listening thread on the CD/DVD drive
94         void StartListeningThread();
95
96         ///Stops the listening thread on the CD/DVD drive
97         void StopListeningThread();
98
99         ///Called upon when a field has been edited
100         void OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
101
102         ///Called upon to return the visible attributes of the current tab
103         void GetVisibleAttributes(std::vector<std::string>& shown,std::vector<std::string>& nShown, int level);
104
105         ///Called when there has been a change in the visible attributes of a tree view
106         void OnAttributesChanged(const std::vector<std::string>& nShown, int level);
107     
108   protected:
109     /// Creates the tool bar
110     void CreateToolBar(); 
111     
112     /// Create the tree view for TreeHandler provided 
113     /// (overloaded from GimmickView)
114     void CreateTreeView( TreeHandler* );
115     
116     
117   private:
118           wxBoxSizer *mbottom_sizer;
119           wxBoxSizer    *msizer;
120     /// Is set to true at the end of constructor 
121     /// (in order to lock callbacks from threaded objects or event 
122     /// before everything is ok)
123     bool mConstructed;
124     /// The ToolBar and the tools
125     wxToolBar*         mToolBar;
126     wxToolBarToolBase* mToolAddFile;
127     wxToolBarToolBase* mToolAddDir;
128     wxToolBarToolBase* mToolRemove;
129     wxToolBarToolBase* mToolAddDatabase;
130     wxToolBarToolBase* mToolHelp;
131         wxToolBarToolBase* mToolSynchronize;
132         wxToolBarToolBase* mToolSettings;
133         wxToolBarToolBase* mToolTools;
134     
135     wxSplitterWindow* mSplitter;
136     wxPanel*          mBottomPanel;
137     wxStaticText *    mText;
138     wxNotebook*       mNotebook;
139     
140     /// The list of icons 
141     wxImageList *    mIcon;
142     void CreateIconList();
143     
144     boost::shared_ptr<Gimmick> mGimmick;
145                 
146         Listener* mListener;
147
148     /// Callback for adding files
149     void OnAddFiles(wxCommandEvent& event);
150
151     /// Callback for adding dir
152     void OnAddDir(wxCommandEvent& event);
153
154     /// Callback for removing files
155     void OnRemove(wxCommandEvent& event);
156
157         /// Callback for synchronization
158     void OnSynchronize(wxCommandEvent& event);
159
160         /// Callback for settings edition
161     void OnSettings(wxCommandEvent& event);
162
163         /// Callback for settings edition
164     void OnTools(wxCommandEvent& event);
165
166         /// Callback for Import/Export images
167     void OnImportExport(wxCommandEvent& event);
168
169         // Import Images from an archive
170         void ImportImages();
171
172         //Export Images to an archive
173         void ExportImages();
174
175         ///Creates the settings dialog (the pages inside and the information)
176         void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
177     
178     /// Display a message box with the last addition statistics
179     void DisplayAddSummary();
180
181         /// Test a directory to know if contains sub-directory to analyze
182         bool isNeedRecursive(std::string i_name);
183
184         /// Determines number of files potentially to add to database
185         int NumberFilesToAdd(const std::string &dirpath, bool recursive);
186     
187     /// AddProgress Gimmick callback
188     void OnAddProgress( Gimmick::AddProgress& );
189     /// Called upon to refresh the viewer once there are no actions to be done
190     void OnInternalIdle();
191
192         void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
193         /// callback to add a database
194         void OnAddDB(wxCommandEvent& event);
195     
196         ///Create a DB from an Attributes Descriptor files 
197         void OnCreateDB(wxCommandEvent& event);
198
199         std::string ExtractName(const std::string &i_name);
200
201         ///Edits the fields of a given node
202         void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
203
204         /// Display all Dicom Tags
205         void DumpTags(const std::string i_filename);
206  
207         /// Export from Storage to Storage
208         void ExportToStorage(const std::vector<std::string> i_filenames);
209  
210     /// Progress dialog
211     wxProgressDialog* mProgressDialog;
212
213     ///The selection's maximum dimension
214     int mSelectionMaxDimension;
215
216     ///The selection's minimum dimension
217     int mSelectionMinDimension;
218
219     ///Image previewer
220     WxViewer* mViewer;
221
222     ///Currently Displayed Node
223     tree::Node* mCurImageItemToShow;
224
225     //Pointer holders for images to be shown
226         std::vector< boost::shared_ptr<ImagePointerHolder> > pointers;
227
228     wxString mCurrentDirectory;
229     
230     DECLARE_EVENT_TABLE()
231       };
232   // EO class WxGimmickView
233   //=====================================================================
234
235 } // EO namespace creaImageIO
236
237 #endif // USE_WIDGETS
238 // EOF
239 #endif