]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxGimmickView.h
Debugged the thread and added a deletion on exit
[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 <creaWx.h>
9
10 #include <wx/splitter.h>
11 #include <wx/toolbar.h> 
12 #include <wx/tbarbase.h> 
13 #include <wx/notebook.h>
14
15 namespace creaImageIO
16 {
17   /**
18    * \ingroup View
19    */
20   //=====================================================================
21   
22   //=====================================================================
23   /// Concrete derivative of GimmickView which implements a wxWidgets-based view
24   class WxGimmickView : public wxPanel, virtual public GimmickView
25     {
26     public:
27       typedef int EventType;
28
29       /// Ctor
30       WxGimmickView(Gimmick*, 
31                     wxWindow *parent, 
32                     const wxWindowID id,
33                     const wxPoint& pos, const wxSize& size,
34                     int min_dim = GIMMICK_2D_IMAGE_SELECTION,
35                         int max_dim = GIMMICK_3D_IMAGE_SELECTION,
36                     int number_of_threads = 0);
37       /// Virtual destructor
38       virtual ~WxGimmickView();
39       
40       /// Returns the selected files
41       ///(overloaded from GimmickView)
42       void GetSelectedFiles(std::vector<std::string>& s);
43       /// Returns the selected Images so that they comply with the given parameter(4D)
44       //(overloaded from GimmickView)
45       void GetSelectedImages(std::vector<vtkImageData*>& s, int dim);
46       /// Callback called when a selection from a TreeView has changed 
47       //(overloaded from GimmickView)
48       void OnSelectionChange(std::vector<tree::Node*>& s);
49
50
51
52       ///Sends a request to read the currently selected node and the ones that surround it.
53       void ReadImageThreaded(std::vector<tree::Node*> sel);
54       
55
56     protected:
57       /// Creates the tool bar
58       void CreateToolBar(); 
59
60       /// Create the tree view for TreeHandler provided 
61       /// (overloaded from GimmickView)
62       void CreateTreeView( TreeHandler* );
63
64
65     private:
66       /// Is set to true at the end of constructor 
67       /// (in order to lock callbacks from threaded objects or event 
68       /// before everything is ok)
69       bool mConstructed;
70       /// The ToolBar and the tools
71       wxToolBar*         mToolBar;
72       wxToolBarToolBase* mToolAddFile;
73       wxToolBarToolBase* mToolAddDir;
74       wxToolBarToolBase* mToolRemove;
75       wxToolBarToolBase* mToolAddDatabase;
76       wxToolBarToolBase* mToolHelp;
77
78       wxSplitterWindow* mSplitter;
79       wxPanel*          mBottomPanel;
80           wxStaticText *    mText;
81       wxNotebook*       mNotebook;
82
83       /// The list of icons 
84       wxImageList *    mIcon;
85       void CreateIconList();
86
87       Gimmick * mGimmick;
88       /// Callback for adding files
89       void OnAddFiles(wxCommandEvent& event);
90       /// Callback for adding dir
91       void OnAddDir(wxCommandEvent& event);
92           /// Callback for removing files
93       void OnRemove(wxCommandEvent& event);
94         
95           /// Display a message box with the last addition statistics
96       void DisplayAddSummary();
97
98
99       /// AddProgress Gimmick callback
100       void OnAddProgress( Gimmick::AddProgress& );
101           /// Processes the queue of image events 
102           /// Called in OnInternalIdle();
103       /// (locks the MultiThreadImageReaderEvent mutex)
104       void ProcessImageEvents();
105       /// Called upon to refresh the viewer once there are no actions to be done
106       void OnInternalIdle();
107      
108       /// Progress dialog
109       wxProgressDialog* mProgressDialog;
110           ///The selection's maximum dimension
111           int mSelectionMaxDimension;
112           ///The selection's minimum dimension
113           int mSelectionMinDimension;
114           ///Image previewer
115           WxViewer* mViewer;
116           ///Currently Displayed Node
117           tree::Node* mCurImageItemToShow;
118
119
120       wxString mCurrentDirectory;
121
122       DECLARE_EVENT_TABLE()
123    };
124     // EO class WxGimmickView
125     //=====================================================================
126   
127
128   /*
129
130
131
132
133
134
135
136
137         //====================================================================
138         // General
139         //====================================================================
140
141     /// Returns the size of the current selection
142     virtual int GetSelectionSize() { return 0; } 
143     /// Returns true if there is a valid selection
144     virtual bool IsSelectionValid(){ return false; }
145     /// Returns the vector of full filenames of selected images
146     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
147     /// Returns the vector of images corresponding to selection
148     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
149     /// Returns the vector of DicomNode corresponding to selection
150     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
151    /// Returns the DicomNode corresponding to the tree item
152     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
153
154         
155         /// Type of list of DicomDatabase
156     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
157     /// Returns the list of DicomDatabase open
158     virtual DicomDatabaseListType& GetDicomDatabaseList() 
159     { return null; }
160     /// Returns the list of DicomDatabase open (const)
161     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
162     { return null; }
163
164         protected:
165         ///Opens an existing database, or else, creates a local database.
166     virtual void OpenOrNewDatabase(bool open){ return; }
167         ///Shows the help
168         virtual void ShowHelp();
169
170         private:
171         ///Gets the extension of the database
172         const std::string& GetDatabaseExtension() { return null; }
173         ///Sets the extension of the database
174     virtual void SetDatabaseExtension(const std::string& ext){ return; }
175
176
177         //====================================================================
178     // Preview Display Related
179         //====================================================================
180
181
182     ///Shows the image sent as a parameter
183         private:
184          virtual void ShowImage(vtkImageData* image){ return; }
185
186         //====================================================================
187     // Favorites Related
188         //====================================================================
189
190
191         public:
192         ///Loads or creates a favorites database
193     virtual void LoadOrCreateFavoritesDatabase(){ return; }
194         private:
195         ///Creates the user settings directory
196     void CreateUserSettingsDirectory(){ return; }
197         ///Obtains the user settings directory
198         const std::string& GetUserSettingsDirectory(){ return null; }
199
200         //====================================================================  
201         // Attribute Display Related
202         //====================================================================
203
204
205         ///Shows the Information regarding the node sent as a parameter
206         private:
207      virtual void ShowInformation(DicomNode*){ return; }
208    
209         //====================================================================
210     // Tree Display Related
211     //====================================================================
212
213         protected:
214     /// Completely rebuilds the view with 
215     /// current DicomDatabaseList
216     virtual void RebuildView(){ return; }
217         /// Recursively updates the part of the view corresponding 
218     /// to the DicomDatabase passed
219     /// i.e. creates items for the DicomNode which do not have
220     ///      deletes obsolete items (whose DicomNode has been deleted)
221     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
222     /// Recursively updates the part of the view corresponding 
223     /// to the DicomNode provided.
224     /// parent is its parent in the tree (where to insert / remove it)
225         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
226     
227         private:
228         ///Type definition of the data regarding the tree
229     typedef WxGimmickTreeItemData TreeItemData;
230         ///Gets the item data of the tree item passed as a parameter
231     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
232     ///Type definition of the data insid a node of the tree
233     typedef WxGimmickDicomNodeData NodeData;
234
235
236         //====================================================================
237     // Class Attributes
238     //====================================================================
239
240         
241         int mSelectionType;
242     int mSelectionMaxImageDimension;
243     int mCurrentSelectionImageSize[4];
244
245         ///Existent Database List
246     DicomDatabaseListType mDicomDatabaseList;
247         ///Favorites database
248     DicomDatabase* mFavoriteDatabase;
249
250         ///Path to the database list file
251     std::string mDatabaseListFile;
252         ///Extension of the database
253     std::string mDatabaseExtension;
254
255     bool mJustStarted;
256
257     int  mFirstDicomDatabaseIconIndex;
258
259    // Previewer
260     vtkImageViewer2* mViewer;
261     
262     int mx1,mx2,my1,my2,mz1,mz2;
263     double mspx,mspy,mspz;
264   
265     // Image preview :
266     // Multi-thread image reader
267     MultiThreadImageReader mReader;
268     // map of images name to node
269     std::map<std::string,DicomNode*> mImageFileNameToNode;
270   */
271  
272 } // EO namespace creaImageIO
273
274 #endif // USE_WIDGETS
275 // EOF
276 #endif