]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxGimmickView.h
#3185 creaImageIO Feature New Normal - Clean code
[creaImageIO.git] / src / creaImageIOWxGimmickView.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28
29 #ifndef __creaImageIOWxGimmickView_h_INCLUDED__
30 #define __creaImageIOWxGimmickView_h_INCLUDED__
31
32 #ifdef USE_WXWIDGETS
33
34 #include <creaImageIOGimmickView.h>
35 #include <creaImageIOWxViewer.h>
36 #include <creaImageIOWxGimmickTools.h>
37 #include <creaImageIOListener.h>
38 #include <creaWx.h>
39 #include <time.h>
40
41 #include "wx/progdlg.h"
42
43 #include "wx/wx.h"
44 #include <wx/splitter.h>
45 #include <wx/toolbar.h> 
46 #include <wx/tbarbase.h> 
47 #include <wx/notebook.h>
48
49 namespace creaImageIO
50 {
51   /**
52    * \ingroup View
53    */
54   //=====================================================================
55   
56   //=====================================================================
57   /// Concrete derivative of GimmickView which implements a wxWidgets-based view
58
59   class WxGimmickView : public wxPanel, virtual public GimmickView
60   {
61   public:
62     
63     typedef int EventType;
64         OutStrGimmick m_out;
65     
66     /// Ctor
67     WxGimmickView(boost::shared_ptr<Gimmick>, 
68                   wxWindow *parent, 
69                   const wxWindowID id,
70                   const wxPoint& pos, const wxSize& size,
71                   int min_dim = GIMMICK_2D_IMAGE_SELECTION,
72                   int max_dim = GIMMICK_3D_IMAGE_SELECTION,
73                   int number_of_threads = 0);
74     /// Virtual destructor
75     virtual ~WxGimmickView();
76     
77     /// Returns the selected files
78     ///(overloaded from GimmickView)
79     void GetSelectedFiles(std::vector<std::string>& s);
80     
81          /// Returns the selected files in output structure
82         void getSelectedFiles(std::vector<OutStrGimmick> &outG, std::vector< std::string> out_infos, bool mult = false, const std::string out_model = "");
83
84     /// Returns the selected Images so that they comply with the 
85     /// given parameter(4D) (overloaded from GimmickView)
86     void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
87     void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim);
88
89
90     /// Returns the images indicated by the filenames in the vector 
91     /// so that they comply with the given parameter(dim)
92     //(overloaded from GimmickView) 
93     void GetImages(int dim, const std::vector<std::string>& files, 
94                    std::vector<vtkImageData*>& s);
95     
96     /// Callback called when a selection from a TreeView has changed 
97     //(overloaded from GimmickView)
98     void OnSelectionChange(const std::vector<tree::Node*>& s, 
99                            bool isSelection, int selection, bool mProcess);
100     ///Stops the player
101     void StopPlayer(){mViewer->StopPlayer();}
102     ///Adds a file to ignore
103     void AddIgnoreFile(tree::Node* toRemove);
104     ///Resets the default image
105     void ClearSelection();
106         ///Copies selected files
107     void CopyFiles(const std::vector<std::string>& filenames);
108         ///Add selected files to the Database
109     void AddDir(std::string dirName);
110     
111     
112     ///Sends a request to read the currently selected node and the ones that surround it.
113     void ReadImageThreaded(const std::vector<tree::Node*>& sel);
114
115         ///Saves the settings to the file
116         void OnSaveSettingsCallback(const std::string& copyPath,
117           const std::string& dbPath,
118           const std::string& syncEvent,
119           const std::string& syncFreq);
120         
121         ///Changes listener state
122         void OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles);
123
124         ///Acts upon a drive mount
125         void OnDriveMount(bool mount);
126
127         ///Starts the listening thread on the CD/DVD drive
128         void StartListeningThread();
129
130         ///Stops the listening thread on the CD/DVD drive
131         void StopListeningThread();
132
133         ///Called upon when a field has been edited
134         void OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
135
136         ///Called upon to return the visible attributes of the current tab
137         void GetVisibleAttributes(std::vector<std::string>& shown,std::vector<std::string>& nShown, int level);
138
139         ///Called when there has been a change in the visible attributes of a tree view
140         void OnAttributesChanged(const std::vector<std::string>& nShown, int level);
141
142
143   protected:
144     /// Creates the tool bar
145     void CreateToolBar(); 
146     
147     /// Create the tree view for TreeHandler provided 
148     /// (overloaded from GimmickView)
149     void CreateTreeView( TreeHandler* );
150     
151     
152   private:
153           wxBoxSizer *mbottom_sizer;
154           wxBoxSizer    *msizer;
155     /// Is set to true at the end of constructor 
156     /// (in order to lock callbacks from threaded objects or event 
157     /// before everything is ok)
158     bool mConstructed;
159     /// The ToolBar and the tools
160     wxToolBar*         mToolBar;
161     wxToolBarToolBase* mToolAddFile;
162     wxToolBarToolBase* mToolAddDir;
163     wxToolBarToolBase* mToolRemove;
164     wxToolBarToolBase* mToolAddDatabase;
165     wxToolBarToolBase* mToolHelp;
166         wxToolBarToolBase* mToolSynchronize;
167         wxToolBarToolBase* mToolSettings;
168         wxToolBarToolBase* mToolTools;
169     
170     wxSplitterWindow* mSplitter;
171     wxPanel*          mBottomPanel;
172     wxStaticText *    mText;
173     wxNotebook*       mNotebook;
174     
175     /// The list of icons 
176     wxImageList *    mIcon;
177     void CreateIconList();
178     
179     boost::shared_ptr<Gimmick> mGimmick;
180                 
181         Listener* mListener;
182
183     /// Callback for adding files
184     void OnAddFiles(wxCommandEvent& event);
185
186     /// Callback for adding dir
187     void OnAddDir(wxCommandEvent& event);
188
189     /// Callback for removing files
190     void OnRemove(wxCommandEvent& event);
191
192         /// Callback for synchronization
193     void OnSynchronize(wxCommandEvent& event);
194
195         /// Callback for settings edition
196     void OnSettings(wxCommandEvent& event);
197
198         /// Callback for settings edition
199     void OnTools(wxCommandEvent& event);
200
201         /// Callback for Import/Export images
202     void OnImportExport(wxCommandEvent& event);
203
204         // Import Images from an archive
205         void ImportImages();
206
207         //Export Images to an archive
208         void ExportImages();
209
210         ///Creates the settings dialog (the pages inside and the information)
211         void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
212     
213     /// Display a message box with the last addition statistics
214     void DisplayAddSummary();
215         time_t  mstart;
216         /// Test a directory to know if contains sub-directory to analyze
217         bool isNeedRecursive(std::string i_name);
218
219         /// Determines number of files potentially to add to database
220         int NumberFilesToAdd(const std::string &dirpath, bool recursive);
221     
222     /// AddProgress Gimmick callback
223     void OnAddProgress( Gimmick::AddProgress& );
224
225 #if defined(WIN32)
226     /// Called upon to refresh the viewer once there are no actions to be done
227     void OnInternalIdle();
228 #else
229         void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
230 #endif
231         /// callback to add a database
232         void OnAddDB(wxCommandEvent& event);
233     
234         ///Create a DB from an Attributes Descriptor files 
235         void OnCreateDB(wxCommandEvent& event);
236
237         std::string ExtractName(const std::string &i_name);
238
239         ///Edits the fields of a given node
240         void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
241
242         
243         /// Display all Dicom Tags
244         void DumpTags(const std::string i_filename);
245  
246         /// Export from Storage to Storage
247         void ExportToStorage(const std::vector<std::string> i_filenames);
248  
249     /// Progress dialog
250     wxProgressDialog* mProgressDialog;
251
252     ///The selection's maximum dimension
253     int mSelectionMaxDimension;
254
255     ///The selection's minimum dimension
256     int mSelectionMinDimension;
257
258     ///Image previewer
259     WxViewer* mViewer;
260
261     ///Currently Displayed Node
262     tree::Node* mCurImageItemToShow;
263
264     //Pointer holders for images to be shown
265         std::vector< boost::shared_ptr<ImagePointerHolder> > pointers;
266
267         //kill Progress DialogBar
268         void killProgress();
269
270     wxString mCurrentDirectory;
271     
272     DECLARE_EVENT_TABLE()
273       };
274   // EO class WxGimmickView
275   //=====================================================================
276
277 } // EO namespace creaImageIO
278
279 #endif // USE_WIDGETS
280 // EOF
281 #endif