]> Creatis software - creaImageIO.git/blob - src/creaImageIOWxTreeView.h
db62a0a3c8a52ca668365fb21d3fcabcff3f47be
[creaImageIO.git] / src / creaImageIOWxTreeView.h
1 #ifndef __creaImageIOWxTreeView_h_INCLUDED__
2 #define __creaImageIOWxTreeView_h_INCLUDED__
3
4 #ifdef USE_WXWIDGETS
5
6 #include <creaImageIOTreeView.h>
7 #include <creaWx.h>
8
9 #include <wx/listctrl.h>
10 #include <wx/splitter.h>
11 //#include <vector>
12 const std::string empty_string("");
13 namespace creaImageIO
14 {
15
16           //=====================================================================
17   /// Data stored by the list items
18   struct ItemData
19   {
20     ItemData() : node(0), id(-1), attr(&empty_string) {}
21     // The corresponding Node
22     tree::Node* node;
23     // The id ?
24     int id;
25     // The pointer on the current attribute string to sort on
26     const std::string* attr;
27     // Was the item previously selected ?
28     // Useful for reselecting the item after sort
29     bool selected;
30   };
31   /**
32    * \ingroup View
33    */
34   //=====================================================================
35   
36   //=====================================================================
37   /// Abstract class that handles the view of a Tree through its TreeHandler
38   class WxTreeView : public wxPanel, virtual public TreeView
39     {
40     public:
41       /// Ctor
42       WxTreeView(TreeHandler*, GimmickView*, 
43                  wxWindow* parent, const wxWindowID id);
44       /// Virtual destructor
45       virtual ~WxTreeView();
46
47       
48       /// Updates the view of a level given the selected items of upper level
49       virtual void UpdateLevel( int );
50
51       ///Removes selected nodes on given level
52           virtual void RemoveSelected(std::string &i_save);
53
54           ///Returns the last selected level
55           virtual unsigned int GetLastSelectedLevel(){return mLastLevel;}
56
57       /// Callback for item selection
58       void OnItemSelected(wxListEvent& event);
59
60       /// Callback for item deselection
61       void OnItemDeSelected(wxListEvent& event);
62       
63       /// Callback for column click
64       void OnColClick(wxListEvent& event);
65       
66       /// Callback when the user needs the items sorted
67       void OnPopupSort(wxCommandEvent& event);
68       
69       ///Callback when the user need the items filtered
70       void OnPopupFilter(wxCommandEvent& event);
71
72           ///Callback when the user needs the item copied to the local disk
73       void OnLocalCopy(wxCommandEvent& event);
74
75
76           ///Callback when the user needs the item copied to the local disk
77       void OnAnonymizer(wxCommandEvent& event);
78
79
80           ///Callback when the user needs to edit a field
81       void OnEditField(wxCommandEvent& event);
82
83           ///Callback when the user needs to display alll dicom tags for a file
84           void OnDumpTags(wxCommandEvent &event);
85       
86           ///Callback when the user needs to transfer data from storage to storage
87           void OnExportToStorage(wxCommandEvent &event);
88       
89       ///Callback on mouse click
90       void OnMouseClick(wxMouseEvent& event);
91
92           /// Displays a menu for items
93           void OnItemMenu(wxListEvent &event);
94           
95           /// Gets the attributes that are being shown and the ones that have been blocked on a specific level
96           void GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level);
97
98           ///Sets the non visible attributes and refreshes the GUI
99           void SetNonVisibleAttributes(const std::vector<std::string>& notShown, int level);
100
101           ///Creates a new listctrl
102           void CreateCtrl(std::vector<std::string>& notShown, int nlevel);
103   
104           ///Returns true if the attribute passed as a parameter is visible or not
105           bool IsAttributeVisible(const std::string& val, int level);
106       
107       /// Actual processing of item selection/deselection 
108       /// Called by OnItemSelected and OnItemDeSelected
109       //      void ProcessItem
110     private:
111                 wxBoxSizer      *msizer;
112       /// The struct holding the data for one level
113       /// Holds the wx control and other data
114       /// such as the vector of attribute keys corresponding to the columns
115       struct LevelType
116       {
117         // The List Control
118         wxListCtrl* wxCtrl;
119         wxSplitterWindow* wxSplitter;
120         std::vector<std::string> key;
121         // The vector of currently selected nodes of the level
122         std::vector<tree::Node*> Selected;
123         // True iff the vector Selected is up to date
124         bool SelectedUpToDate;
125         // The column used for sorting
126         unsigned int SortColumn;
127         ///Boolean that defines the direction of the sort
128         ///True is ascending order and false is descending
129         bool SortAscending;
130         //The vector of not shown attributes
131         std::vector<std::string> notShownAtts; 
132       };
133       /// The vector of levels : one for each level of the tree      
134       std::vector<LevelType> mLevelList;
135       
136       /// return the wxListCtrl of one level
137       wxListCtrl* GetCtrl(int l) { return mLevelList[l].wxCtrl; }
138       /// return the wxSplitter of one level
139       wxSplitterWindow* GetSplitter(int l) { return mLevelList[l].wxSplitter; }
140       //Returns the maximum number of levels
141       int GetNumberOfLevels(){ return mLevelList.size(); }
142       /// Gets the user selected data from the level passed as a parameter
143       /// Updates the vector if necessary
144       const std::vector<tree::Node*>& GetSelected(int level);
145       /// Set the bool SelectedUpToDate for level l
146       void SetSelectedUpToDate(int l, bool v) { mLevelList[l].SelectedUpToDate = v; }
147       /// Get the bool SelectedUpToDate for level l
148       bool GetSelectedUpToDate(int l) { return mLevelList[l].SelectedUpToDate; }
149        ///Validates the selected images
150       void ValidateSelectedImages(bool isSelection);   
151       ///Gets selected filenames
152       void GetSelectedAsString(std::vector<std::string>&s);
153           ///Gets the filenames of the given nodes and returns them on the given vector. Is recursive.
154           void GetFilenamesAsString(const std::vector<tree::Node*>& nodes, std::vector<std::string>&s);
155       /// Gets the next nodes on the list, be it up(true) or down(false).
156       void GetNodes(std::vector<tree::Node*>& nodes, bool direction);
157       /// Updates the view of a level given the selected items of upper level
158       /// Recursive method
159       virtual void RecursiveUpdateLevel( int );
160       ///Selects all the elements of a level 
161       void SelectAll(int level);
162       ///UnSelects all the elements of a level 
163       void UnSelectAll(int level);
164
165           void OnKeyDown(wxListEvent &event);
166       /// Sorts the level
167       void SortLevel(int level);
168       
169       /// Currently Selected Column
170       int mColumnSelected;
171       ///The last selected item on the list (left click)
172       long mLastSelected;
173
174           ///The last selected item on the list (right click)
175           long mLastRightSelected;
176
177           ///The last selected level (by right click)
178           int mLastRightLevel;
179       ///The color map
180       typedef std::map<tree::Node*,wxColour> ColorMap;
181       typedef std::pair<tree::Node*,wxColour> NodeColorPair;
182       ColorMap mColorMap;
183       ///Initial color palette
184       std::vector<std::string> mColorPalette;
185
186       wxMenu* menu;
187           
188       wxObject* senderCtrl;
189       int mAscendingID;
190       int mDescendingID;
191       int mFilterID;
192       unsigned int mLastLevel;
193       
194           wxMenu* menuItem;
195           wxMenu *subExportMenu;
196           int mAnonymizingID;
197           int mLocalCopyID;
198           int mEditFieldID;
199           int mDumpID;
200           int mExportID;
201           int mExport2StorageID;
202           
203       // If set to true then OnSelectedChanged returns immediately.
204       // Used to do avoid useless process during multiple selections 
205       // or sorting
206       bool mIgnoreSelectedChanged;
207
208       DECLARE_EVENT_TABLE()
209     };
210     // EO class WxTreeView
211     //=====================================================================
212
213         class RemoveAlertDlg : public wxDialog
214         {
215         public:
216                 RemoveAlertDlg(wxWindow *parent, 
217                                                wxString title,    
218                                                    const wxSize& size);
219                 ~RemoveAlertDlg();
220
221                 bool isChecked();
222
223         private :
224                 void onCheck(wxCommandEvent &Event);
225                 bool mSave;
226                 wxCheckBox *mcheck;
227
228         };
229
230
231 } // EO namespace creaImageIO
232
233
234 #endif // USE_WIDGETS
235 // EOF
236 #endif