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);
99 /// Creates the tool bar
100 void CreateToolBar();
102 /// Create the tree view for TreeHandler provided
103 /// (overloaded from GimmickView)
104 void CreateTreeView( TreeHandler* );
108 /// Is set to true at the end of constructor
109 /// (in order to lock callbacks from threaded objects or event
110 /// before everything is ok)
112 /// The ToolBar and the tools
114 wxToolBarToolBase* mToolAddFile;
115 wxToolBarToolBase* mToolAddDir;
116 wxToolBarToolBase* mToolRemove;
117 wxToolBarToolBase* mToolAddDatabase;
118 wxToolBarToolBase* mToolHelp;
119 wxToolBarToolBase* mToolSynchronize;
120 wxToolBarToolBase* mToolSettings;
121 wxToolBarToolBase* mToolTools;
123 wxSplitterWindow* mSplitter;
124 wxPanel* mBottomPanel;
125 wxStaticText * mText;
126 wxNotebook* mNotebook;
128 /// The list of icons
130 void CreateIconList();
135 /// Callback for adding files
136 void OnAddFiles(wxCommandEvent& event);
137 /// Callback for adding dir
138 void OnAddDir(wxCommandEvent& event);
139 /// Callback for removing files
140 void OnRemove(wxCommandEvent& event);
141 /// Callback for synchronization
142 void OnSynchronize(wxCommandEvent& event);
143 /// Callback for settings edition
144 void OnSettings(wxCommandEvent& event);
145 /// Callback for settings edition
146 void OnTools(wxCommandEvent& event);
147 ///Creates the settings dialog (the pages inside and the information)
148 void CreateSettingsDialog(wxNotebook* nb, wxDialog* dial);
150 /// Display a message box with the last addition statistics
151 void DisplayAddSummary();
153 /// Test a directory to know if contains sub-directory to analyze
154 bool isNeedRecursive(std::string i_name);
156 /// AddProgress Gimmick callback
157 void OnAddProgress( Gimmick::AddProgress& );
158 /// Called upon to refresh the viewer once there are no actions to be done
159 void OnInternalIdle();
161 /// callback to add a database
162 void OnAddDB(wxCommandEvent& event);
164 ///Create a DB from an Attributes Descriptor files
165 void OnCreateDB(wxCommandEvent& event);
167 ///Edits the fields of a given node
168 void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys);
171 wxProgressDialog* mProgressDialog;
172 ///The selection's maximum dimension
173 int mSelectionMaxDimension;
174 ///The selection's minimum dimension
175 int mSelectionMinDimension;
178 ///Currently Displayed Node
179 tree::Node* mCurImageItemToShow;
180 //Pointer holders for images to be shown
181 std::vector<ImagePointerHolder*> pointers;
184 wxString mCurrentDirectory;
186 DECLARE_EVENT_TABLE()
188 // EO class WxGimmickView
189 //=====================================================================
201 //====================================================================
203 //====================================================================
205 /// Returns the size of the current selection
206 virtual int GetSelectionSize() { return 0; }
207 /// Returns true if there is a valid selection
208 virtual bool IsSelectionValid(){ return false; }
209 /// Returns the vector of full filenames of selected images
210 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
211 /// Returns the vector of images corresponding to selection
212 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
213 /// Returns the vector of DicomNode corresponding to selection
214 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
215 /// Returns the DicomNode corresponding to the tree item
216 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
219 /// Type of list of DicomDatabase
220 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
221 /// Returns the list of DicomDatabase open
222 virtual DicomDatabaseListType& GetDicomDatabaseList()
224 /// Returns the list of DicomDatabase open (const)
225 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
229 ///Opens an existing database, or else, creates a local database.
230 virtual void OpenOrNewDatabase(bool open){ return; }
232 virtual void ShowHelp();
235 ///Gets the extension of the database
236 const std::string& GetDatabaseExtension() { return null; }
237 ///Sets the extension of the database
238 virtual void SetDatabaseExtension(const std::string& ext){ return; }
241 //====================================================================
242 // Preview Display Related
243 //====================================================================
246 ///Shows the image sent as a parameter
248 virtual void ShowImage(vtkImageData* image){ return; }
250 //====================================================================
252 //====================================================================
256 ///Loads or creates a favorites database
257 virtual void LoadOrCreateFavoritesDatabase(){ return; }
259 ///Creates the user settings directory
260 void CreateUserSettingsDirectory(){ return; }
261 ///Obtains the user settings directory
262 const std::string& GetUserSettingsDirectory(){ return null; }
264 //====================================================================
265 // Attribute Display Related
266 //====================================================================
269 ///Shows the Information regarding the node sent as a parameter
271 virtual void ShowInformation(DicomNode*){ return; }
273 //====================================================================
274 // Tree Display Related
275 //====================================================================
278 /// Completely rebuilds the view with
279 /// current DicomDatabaseList
280 virtual void RebuildView(){ return; }
281 /// Recursively updates the part of the view corresponding
282 /// to the DicomDatabase passed
283 /// i.e. creates items for the DicomNode which do not have
284 /// deletes obsolete items (whose DicomNode has been deleted)
285 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
286 /// Recursively updates the part of the view corresponding
287 /// to the DicomNode provided.
288 /// parent is its parent in the tree (where to insert / remove it)
289 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
292 ///Type definition of the data regarding the tree
293 typedef WxGimmickTreeItemData TreeItemData;
294 ///Gets the item data of the tree item passed as a parameter
295 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
296 ///Type definition of the data insid a node of the tree
297 typedef WxGimmickDicomNodeData NodeData;
300 //====================================================================
302 //====================================================================
306 int mSelectionMaxImageDimension;
307 int mCurrentSelectionImageSize[4];
309 ///Existent Database List
310 DicomDatabaseListType mDicomDatabaseList;
311 ///Favorites database
312 DicomDatabase* mFavoriteDatabase;
314 ///Path to the database list file
315 std::string mDatabaseListFile;
316 ///Extension of the database
317 std::string mDatabaseExtension;
321 int mFirstDicomDatabaseIconIndex;
324 vtkImageViewer2* mViewer;
326 int mx1,mx2,my1,my2,mz1,mz2;
327 double mspx,mspy,mspz;
330 // Multi-thread image reader
331 MultiThreadImageReader mReader;
332 // map of images name to node
333 std::map<std::string,DicomNode*> mImageFileNameToNode;
336 } // EO namespace creaImageIO
338 #endif // USE_WIDGETS