1 #ifndef __creaImageIOWxGimmickView_h_INCLUDED__
2 #define __creaImageIOWxGimmickView_h_INCLUDED__
6 #include <creaImageIOGimmickView.h>
7 #include <creaImageIOWxViewer.h>
8 #include <creaImageIOWxGimmickTools.h>
9 #include <creaImageIOListener.h>
12 #include <wx/splitter.h>
13 #include <wx/toolbar.h>
14 #include <wx/tbarbase.h>
15 #include <wx/notebook.h>
22 //=====================================================================
24 //=====================================================================
25 /// Concrete derivative of GimmickView which implements a wxWidgets-based view
27 class WxGimmickView : public wxPanel, virtual public GimmickView
31 typedef int EventType;
34 WxGimmickView(Gimmick*,
37 const wxPoint& pos, const wxSize& size,
38 int min_dim = GIMMICK_2D_IMAGE_SELECTION,
39 int max_dim = GIMMICK_3D_IMAGE_SELECTION,
40 int number_of_threads = 0);
41 /// Virtual destructor
42 virtual ~WxGimmickView();
44 /// Returns the selected files
45 ///(overloaded from GimmickView)
46 void GetSelectedFiles(std::vector<std::string>& s);
48 /// Returns the selected Images so that they comply with the
49 /// given parameter(4D) (overloaded from GimmickView)
50 void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
52 /// Returns the images indicated by the filenames in the vector
53 /// so that they comply with the given parameter(dim)
54 //(overloaded from GimmickView)
55 void GetImages(int dim, const std::vector<std::string>& files,
56 std::vector<vtkImageData*>& s);
58 /// Callback called when a selection from a TreeView has changed
59 //(overloaded from GimmickView)
60 void OnSelectionChange(const std::vector<tree::Node*>& s,
61 bool isSelection, int selection, bool mProcess);
63 void StopPlayer(){mViewer->StopPlayer();}
64 ///Adds a file to ignore
65 void AddIgnoreFile(tree::Node* toRemove);
66 ///Resets the default image
67 void ClearSelection();
68 ///Copies selected files
69 void CopyFiles(const std::vector<std::string>& filenames);
70 ///Add selected files to the Database
71 void AddDir(std::string dirName);
74 ///Sends a request to read the currently selected node and the ones that surround it.
75 void ReadImageThreaded(const std::vector<tree::Node*>& sel);
77 ///Saves the settings to the file
78 void OnSaveSettingsCallback(const std::string& copyPath,
79 const std::string& dbPath,
80 const std::string& syncEvent,
81 const std::string& syncFreq);
83 ///Changes listener state
84 void OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles);
86 ///Acts upon a drive mount
87 void OnDriveMount(bool mount);
89 ///Starts the listening thread on the CD/DVD drive
90 void StartListeningThread();
92 ///Stops the listening thread on the CD/DVD drive
93 void StopListeningThread();
95 ///Called upon when a field has been edited
96 void OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
98 ///Called upon to return the visible attributes of the current tab
99 void GetVisibleAttributes(std::vector<std::string>& shown,std::vector<std::string>& nShown, int level);
101 ///Called when there has been a change in the visible attributes of a tree view
102 void OnAttributesChanged(const std::vector<std::string>& nShown, int level);
105 /// Creates the tool bar
106 void CreateToolBar();
108 /// Create the tree view for TreeHandler provided
109 /// (overloaded from GimmickView)
110 void CreateTreeView( TreeHandler* );
114 /// Is set to true at the end of constructor
115 /// (in order to lock callbacks from threaded objects or event
116 /// before everything is ok)
118 /// The ToolBar and the tools
120 wxToolBarToolBase* mToolAddFile;
121 wxToolBarToolBase* mToolAddDir;
122 wxToolBarToolBase* mToolRemove;
123 wxToolBarToolBase* mToolAddDatabase;
124 wxToolBarToolBase* mToolHelp;
125 wxToolBarToolBase* mToolSynchronize;
126 wxToolBarToolBase* mToolSettings;
127 wxToolBarToolBase* mToolTools;
129 wxSplitterWindow* mSplitter;
130 wxPanel* mBottomPanel;
131 wxStaticText * mText;
132 wxNotebook* mNotebook;
134 /// The list of icons
136 void CreateIconList();
141 /// Callback for adding files
142 void OnAddFiles(wxCommandEvent& event);
143 /// Callback for adding dir
144 void OnAddDir(wxCommandEvent& event);
145 /// Callback for removing files
146 void OnRemove(wxCommandEvent& event);
147 /// Callback for synchronization
148 void OnSynchronize(wxCommandEvent& event);
149 /// Callback for settings edition
150 void OnSettings(wxCommandEvent& event);
151 /// Callback for settings edition
152 void OnTools(wxCommandEvent& event);
153 ///Creates the settings dialog (the pages inside and the information)
154 void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
156 /// Display a message box with the last addition statistics
157 void DisplayAddSummary();
159 /// Test a directory to know if contains sub-directory to analyze
160 bool isNeedRecursive(std::string i_name);
162 /// AddProgress Gimmick callback
163 void OnAddProgress( Gimmick::AddProgress& );
164 /// Called upon to refresh the viewer once there are no actions to be done
165 void OnInternalIdle();
167 /// callback to add a database
168 void OnAddDB(wxCommandEvent& event);
170 ///Create a DB from an Attributes Descriptor files
171 void OnCreateDB(wxCommandEvent& event);
173 ///Edits the fields of a given node
174 void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
177 wxProgressDialog* mProgressDialog;
178 ///The selection's maximum dimension
179 int mSelectionMaxDimension;
180 ///The selection's minimum dimension
181 int mSelectionMinDimension;
184 ///Currently Displayed Node
185 tree::Node* mCurImageItemToShow;
186 //Pointer holders for images to be shown
187 std::vector<ImagePointerHolder*> pointers;
190 wxString mCurrentDirectory;
192 DECLARE_EVENT_TABLE()
194 // EO class WxGimmickView
195 //=====================================================================
207 //====================================================================
209 //====================================================================
211 /// Returns the size of the current selection
212 virtual int GetSelectionSize() { return 0; }
213 /// Returns true if there is a valid selection
214 virtual bool IsSelectionValid(){ return false; }
215 /// Returns the vector of full filenames of selected images
216 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
217 /// Returns the vector of images corresponding to selection
218 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
219 /// Returns the vector of DicomNode corresponding to selection
220 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
221 /// Returns the DicomNode corresponding to the tree item
222 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
225 /// Type of list of DicomDatabase
226 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
227 /// Returns the list of DicomDatabase open
228 virtual DicomDatabaseListType& GetDicomDatabaseList()
230 /// Returns the list of DicomDatabase open (const)
231 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
235 ///Opens an existing database, or else, creates a local database.
236 virtual void OpenOrNewDatabase(bool open){ return; }
238 virtual void ShowHelp();
241 ///Gets the extension of the database
242 const std::string& GetDatabaseExtension() { return null; }
243 ///Sets the extension of the database
244 virtual void SetDatabaseExtension(const std::string& ext){ return; }
247 //====================================================================
248 // Preview Display Related
249 //====================================================================
252 ///Shows the image sent as a parameter
254 virtual void ShowImage(vtkImageData* image){ return; }
256 //====================================================================
258 //====================================================================
262 ///Loads or creates a favorites database
263 virtual void LoadOrCreateFavoritesDatabase(){ return; }
265 ///Creates the user settings directory
266 void CreateUserSettingsDirectory(){ return; }
267 ///Obtains the user settings directory
268 const std::string& GetUserSettingsDirectory(){ return null; }
270 //====================================================================
271 // Attribute Display Related
272 //====================================================================
275 ///Shows the Information regarding the node sent as a parameter
277 virtual void ShowInformation(DicomNode*){ return; }
279 //====================================================================
280 // Tree Display Related
281 //====================================================================
284 /// Completely rebuilds the view with
285 /// current DicomDatabaseList
286 virtual void RebuildView(){ return; }
287 /// Recursively updates the part of the view corresponding
288 /// to the DicomDatabase passed
289 /// i.e. creates items for the DicomNode which do not have
290 /// deletes obsolete items (whose DicomNode has been deleted)
291 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
292 /// Recursively updates the part of the view corresponding
293 /// to the DicomNode provided.
294 /// parent is its parent in the tree (where to insert / remove it)
295 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
298 ///Type definition of the data regarding the tree
299 typedef WxGimmickTreeItemData TreeItemData;
300 ///Gets the item data of the tree item passed as a parameter
301 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
302 ///Type definition of the data insid a node of the tree
303 typedef WxGimmickDicomNodeData NodeData;
306 //====================================================================
308 //====================================================================
312 int mSelectionMaxImageDimension;
313 int mCurrentSelectionImageSize[4];
315 ///Existent Database List
316 DicomDatabaseListType mDicomDatabaseList;
317 ///Favorites database
318 DicomDatabase* mFavoriteDatabase;
320 ///Path to the database list file
321 std::string mDatabaseListFile;
322 ///Extension of the database
323 std::string mDatabaseExtension;
327 int mFirstDicomDatabaseIconIndex;
330 vtkImageViewer2* mViewer;
332 int mx1,mx2,my1,my2,mz1,mz2;
333 double mspx,mspy,mspz;
336 // Multi-thread image reader
337 MultiThreadImageReader mReader;
338 // map of images name to node
339 std::map<std::string,DicomNode*> mImageFileNameToNode;
342 } // EO namespace creaImageIO
344 #endif // USE_WIDGETS