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