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