]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxGimmickView.h
thread bug correction
[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
115   protected:
116     /// Creates the tool bar
117     void CreateToolBar(); 
118     
119     /// Create the tree view for TreeHandler provided 
120     /// (overloaded from GimmickView)
121     void CreateTreeView( TreeHandler* );
122     
123     
124   private:
125           wxBoxSizer *mbottom_sizer;
126           wxBoxSizer    *msizer;
127     /// Is set to true at the end of constructor 
128     /// (in order to lock callbacks from threaded objects or event 
129     /// before everything is ok)
130     bool mConstructed;
131     /// The ToolBar and the tools
132     wxToolBar*         mToolBar;
133     wxToolBarToolBase* mToolAddFile;
134     wxToolBarToolBase* mToolAddDir;
135     wxToolBarToolBase* mToolRemove;
136     wxToolBarToolBase* mToolAddDatabase;
137     wxToolBarToolBase* mToolHelp;
138         wxToolBarToolBase* mToolSynchronize;
139         wxToolBarToolBase* mToolSettings;
140         wxToolBarToolBase* mToolTools;
141     
142     wxSplitterWindow* mSplitter;
143     wxPanel*          mBottomPanel;
144     wxStaticText *    mText;
145     wxNotebook*       mNotebook;
146     
147     /// The list of icons 
148     wxImageList *    mIcon;
149     void CreateIconList();
150     
151     boost::shared_ptr<Gimmick> mGimmick;
152                 
153         Listener* mListener;
154
155     /// Callback for adding files
156     void OnAddFiles(wxCommandEvent& event);
157
158     /// Callback for adding dir
159     void OnAddDir(wxCommandEvent& event);
160
161     /// Callback for removing files
162     void OnRemove(wxCommandEvent& event);
163
164         /// Callback for synchronization
165     void OnSynchronize(wxCommandEvent& event);
166
167         /// Callback for settings edition
168     void OnSettings(wxCommandEvent& event);
169
170         /// Callback for settings edition
171     void OnTools(wxCommandEvent& event);
172
173         /// Callback for Import/Export images
174     void OnImportExport(wxCommandEvent& event);
175
176         // Import Images from an archive
177         void ImportImages();
178
179         //Export Images to an archive
180         void ExportImages();
181
182         ///Creates the settings dialog (the pages inside and the information)
183         void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
184     
185     /// Display a message box with the last addition statistics
186     void DisplayAddSummary();
187         time_t  mstart;
188         /// Test a directory to know if contains sub-directory to analyze
189         bool isNeedRecursive(std::string i_name);
190
191         /// Determines number of files potentially to add to database
192         int NumberFilesToAdd(const std::string &dirpath, bool recursive);
193     
194     /// AddProgress Gimmick callback
195     void OnAddProgress( Gimmick::AddProgress& );
196
197 #if defined(WIN32)
198     /// Called upon to refresh the viewer once there are no actions to be done
199     void OnInternalIdle();
200 #else
201         void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
202 #endif
203         /// callback to add a database
204         void OnAddDB(wxCommandEvent& event);
205     
206         ///Create a DB from an Attributes Descriptor files 
207         void OnCreateDB(wxCommandEvent& event);
208
209         std::string ExtractName(const std::string &i_name);
210
211         ///Edits the fields of a given node
212         void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
213
214         
215         /// Display all Dicom Tags
216         void DumpTags(const std::string i_filename);
217  
218         /// Export from Storage to Storage
219         void ExportToStorage(const std::vector<std::string> i_filenames);
220  
221     /// Progress dialog
222     wxProgressDialog* mProgressDialog;
223
224     ///The selection's maximum dimension
225     int mSelectionMaxDimension;
226
227     ///The selection's minimum dimension
228     int mSelectionMinDimension;
229
230     ///Image previewer
231     WxViewer* mViewer;
232
233     ///Currently Displayed Node
234     tree::Node* mCurImageItemToShow;
235
236     //Pointer holders for images to be shown
237         std::vector< boost::shared_ptr<ImagePointerHolder> > pointers;
238
239         //kill Progress DialogBar
240         void killProgress();
241
242     wxString mCurrentDirectory;
243     
244     DECLARE_EVENT_TABLE()
245       };
246   // EO class WxGimmickView
247   //=====================================================================
248
249 } // EO namespace creaImageIO
250
251 #endif // USE_WIDGETS
252 // EOF
253 #endif