]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxGimmickView.h
#3323 Bug with ToolBar (in wxFrame an not in wxPanel) in MacOs
[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 CREAIMAGEIO_EXPORT 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     wxPanel             *mToolBar;
162     wxToolBarToolBase   *mToolAddFile;
163     wxToolBarToolBase   *mToolAddDir;
164     wxToolBarToolBase   *mToolRemove;
165     wxToolBarToolBase   *mToolAddDatabase;
166     wxToolBarToolBase   *mToolHelp;
167         wxToolBarToolBase       *mToolSynchronize;
168         wxToolBarToolBase       *mToolSettings;
169         wxToolBarToolBase       *mToolTools;
170     
171     wxSplitterWindow    *mSplitter;
172     wxPanel                             *mBottomPanel;
173     wxStaticText                *mText;
174     wxNotebook                  *mNotebook;
175     
176     /// The list of icons 
177     wxImageList                 *mIcon;
178     void CreateIconList();
179     void AddBtnTool(wxPanel *panel, wxBoxSizer *sizerH, int id, wxString label, int idBitmap, wxString tooltip );
180
181     
182     boost::shared_ptr<Gimmick> mGimmick;
183                 
184         Listener                        *mListener;
185
186     /// Callback for adding files
187     void OnAddFiles(wxCommandEvent& event);
188
189     /// Callback for adding dir
190     void OnAddDir(wxCommandEvent& event);
191
192     /// Callback for removing files
193     void OnRemove(wxCommandEvent& event);
194
195         /// Callback for synchronization
196     void OnSynchronize(wxCommandEvent& event);
197
198         /// Callback for settings edition
199     void OnSettings(wxCommandEvent& event);
200
201         /// Callback for settings edition
202     void OnTools(wxCommandEvent& event);
203
204         /// Callback for Import/Export images
205     void OnImportExport(wxCommandEvent& event);
206
207         // Import Images from an archive
208         void ImportImages();
209
210         //Export Images to an archive
211         void ExportImages();
212
213         ///Creates the settings dialog (the pages inside and the information)
214         void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
215     
216     /// Display a message box with the last addition statistics
217     void DisplayAddSummary();
218         time_t  mstart;
219         /// Test a directory to know if contains sub-directory to analyze
220         bool isNeedRecursive(std::string i_name);
221
222         /// Determines number of files potentially to add to database
223         int NumberFilesToAdd(const std::string &dirpath, bool recursive);
224     
225     /// AddProgress Gimmick callback
226     void OnAddProgress( Gimmick::AddProgress& );
227
228 #if defined(WIN32)
229     /// Called upon to refresh the viewer once there are no actions to be done
230     void OnInternalIdle();
231 #else
232         void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
233 #endif
234         /// callback to add a database
235         void OnAddDB(wxCommandEvent& event);
236     
237         ///Create a DB from an Attributes Descriptor files 
238         void OnCreateDB(wxCommandEvent& event);
239
240         std::string ExtractName(const std::string &i_name);
241
242         ///Edits the fields of a given node
243         void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
244
245         
246         /// Display all Dicom Tags
247         void DumpTags(const std::string i_filename);
248  
249         /// Export from Storage to Storage
250         void ExportToStorage(const std::vector<std::string> i_filenames);
251  
252     /// Progress dialog
253     wxProgressDialog    *mProgressDialog;
254
255     ///The selection's maximum dimension
256     int mSelectionMaxDimension;
257
258     ///The selection's minimum dimension
259     int mSelectionMinDimension;
260
261     ///Image previewer
262     WxViewer                    *mViewer;
263
264     ///Currently Displayed Node
265     tree::Node                  *mCurImageItemToShow;
266
267     //Pointer holders for images to be shown
268         std::vector< boost::shared_ptr<ImagePointerHolder> > pointers;
269
270         //kill Progress DialogBar
271         void killProgress();
272
273     wxString mCurrentDirectory;
274     
275     DECLARE_EVENT_TABLE()
276       };
277   // EO class WxGimmickView
278   //=====================================================================
279
280 } // EO namespace creaImageIO
281
282 #endif // USE_WIDGETS
283 // EOF
284 #endif