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