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);
72 ///Sends a request to read the currently selected node and the ones that surround it.
73 void ReadImageThreaded(const std::vector<tree::Node*>& sel);
75 ///Saves the settings to the file
76 void OnSaveSettingsCallback(const std::string& copyPath,
77 const std::string& dbPath,
78 const std::string& syncEvent,
79 const std::string& syncFreq);
81 ///Changes listener state
82 void OnListenerCallback(const std::string& drive, bool addFiles, bool removeFiles);
84 ///Acts upon a drive mount
85 void OnDriveMount(bool mount);
87 ///Starts the listening thread on the CD/DVD drive
88 void StartListeningThread();
90 ///Stops the listening thread on the CD/DVD drive
91 void StopListeningThread();
93 ///Called upon when a field has been edited
94 void OnFieldsEdited(tree::Node* node, const std::string& name, const std::string& key, const std::string& val);
96 ///Called upon to return the visible attributes of the current tab
97 void GetVisibleAttributes(std::vector<std::string>& shown,std::vector<std::string>& nShown, int level);
99 ///Called when there has been a change in the visible attributes of a tree view
100 void OnAttributesChanged(const std::vector<std::string>& nShown, int level);
103 /// Creates the tool bar
104 void CreateToolBar();
106 /// Create the tree view for TreeHandler provided
107 /// (overloaded from GimmickView)
108 void CreateTreeView( TreeHandler* );
112 /// Is set to true at the end of constructor
113 /// (in order to lock callbacks from threaded objects or event
114 /// before everything is ok)
116 /// The ToolBar and the tools
118 wxToolBarToolBase* mToolAddFile;
119 wxToolBarToolBase* mToolAddDir;
120 wxToolBarToolBase* mToolRemove;
121 wxToolBarToolBase* mToolAddDatabase;
122 wxToolBarToolBase* mToolHelp;
123 wxToolBarToolBase* mToolSynchronize;
124 wxToolBarToolBase* mToolSettings;
125 wxToolBarToolBase* mToolTools;
127 wxSplitterWindow* mSplitter;
128 wxPanel* mBottomPanel;
129 wxStaticText * mText;
130 wxNotebook* mNotebook;
132 /// The list of icons
134 void CreateIconList();
139 /// Callback for adding files
140 void OnAddFiles(wxCommandEvent& event);
141 /// Callback for adding dir
142 void OnAddDir(wxCommandEvent& event);
143 /// Callback for removing files
144 void OnRemove(wxCommandEvent& event);
145 /// Callback for synchronization
146 void OnSynchronize(wxCommandEvent& event);
147 /// Callback for settings edition
148 void OnSettings(wxCommandEvent& event);
149 /// Callback for settings edition
150 void OnTools(wxCommandEvent& event);
151 ///Creates the settings dialog (the pages inside and the information)
152 void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
154 /// Display a message box with the last addition statistics
155 void DisplayAddSummary();
157 /// Test a directory to know if contains sub-directory to analyze
158 bool isNeedRecursive(std::string i_name);
160 /// AddProgress Gimmick callback
161 void OnAddProgress( Gimmick::AddProgress& );
162 /// Called upon to refresh the viewer once there are no actions to be done
163 void OnInternalIdle();
165 /// callback to add a database
166 void OnAddDB(wxCommandEvent& event);
168 ///Create a DB from an Attributes Descriptor files
169 void OnCreateDB(wxCommandEvent& event);
171 ///Edits the fields of a given node
172 void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
175 wxProgressDialog* mProgressDialog;
176 ///The selection's maximum dimension
177 int mSelectionMaxDimension;
178 ///The selection's minimum dimension
179 int mSelectionMinDimension;
182 ///Currently Displayed Node
183 tree::Node* mCurImageItemToShow;
184 //Pointer holders for images to be shown
185 std::vector<ImagePointerHolder*> pointers;
188 wxString mCurrentDirectory;
190 DECLARE_EVENT_TABLE()
192 // EO class WxGimmickView
193 //=====================================================================
205 //====================================================================
207 //====================================================================
209 /// Returns the size of the current selection
210 virtual int GetSelectionSize() { return 0; }
211 /// Returns true if there is a valid selection
212 virtual bool IsSelectionValid(){ return false; }
213 /// Returns the vector of full filenames of selected images
214 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
215 /// Returns the vector of images corresponding to selection
216 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
217 /// Returns the vector of DicomNode corresponding to selection
218 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
219 /// Returns the DicomNode corresponding to the tree item
220 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
223 /// Type of list of DicomDatabase
224 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
225 /// Returns the list of DicomDatabase open
226 virtual DicomDatabaseListType& GetDicomDatabaseList()
228 /// Returns the list of DicomDatabase open (const)
229 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
233 ///Opens an existing database, or else, creates a local database.
234 virtual void OpenOrNewDatabase(bool open){ return; }
236 virtual void ShowHelp();
239 ///Gets the extension of the database
240 const std::string& GetDatabaseExtension() { return null; }
241 ///Sets the extension of the database
242 virtual void SetDatabaseExtension(const std::string& ext){ return; }
245 //====================================================================
246 // Preview Display Related
247 //====================================================================
250 ///Shows the image sent as a parameter
252 virtual void ShowImage(vtkImageData* image){ return; }
254 //====================================================================
256 //====================================================================
260 ///Loads or creates a favorites database
261 virtual void LoadOrCreateFavoritesDatabase(){ return; }
263 ///Creates the user settings directory
264 void CreateUserSettingsDirectory(){ return; }
265 ///Obtains the user settings directory
266 const std::string& GetUserSettingsDirectory(){ return null; }
268 //====================================================================
269 // Attribute Display Related
270 //====================================================================
273 ///Shows the Information regarding the node sent as a parameter
275 virtual void ShowInformation(DicomNode*){ return; }
277 //====================================================================
278 // Tree Display Related
279 //====================================================================
282 /// Completely rebuilds the view with
283 /// current DicomDatabaseList
284 virtual void RebuildView(){ return; }
285 /// Recursively updates the part of the view corresponding
286 /// to the DicomDatabase passed
287 /// i.e. creates items for the DicomNode which do not have
288 /// deletes obsolete items (whose DicomNode has been deleted)
289 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
290 /// Recursively updates the part of the view corresponding
291 /// to the DicomNode provided.
292 /// parent is its parent in the tree (where to insert / remove it)
293 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
296 ///Type definition of the data regarding the tree
297 typedef WxGimmickTreeItemData TreeItemData;
298 ///Gets the item data of the tree item passed as a parameter
299 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
300 ///Type definition of the data insid a node of the tree
301 typedef WxGimmickDicomNodeData NodeData;
304 //====================================================================
306 //====================================================================
310 int mSelectionMaxImageDimension;
311 int mCurrentSelectionImageSize[4];
313 ///Existent Database List
314 DicomDatabaseListType mDicomDatabaseList;
315 ///Favorites database
316 DicomDatabase* mFavoriteDatabase;
318 ///Path to the database list file
319 std::string mDatabaseListFile;
320 ///Extension of the database
321 std::string mDatabaseExtension;
325 int mFirstDicomDatabaseIconIndex;
328 vtkImageViewer2* mViewer;
330 int mx1,mx2,my1,my2,mz1,mz2;
331 double mspx,mspy,mspz;
334 // Multi-thread image reader
335 MultiThreadImageReader mReader;
336 // map of images name to node
337 std::map<std::string,DicomNode*> mImageFileNameToNode;
340 } // EO namespace creaImageIO
342 #endif // USE_WIDGETS