]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxTreeView.h
no message
[creaImageIO.git] / src2 / 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           ///Callback when the user needs to edit a field
76       void OnEditField(wxCommandEvent& event);
77
78           ///Callback when the user needs to display alll dicom tags for a file
79           void OnDumpTags(wxCommandEvent &event);
80       
81           ///Callback when the user needs to transfer data from storage to storage
82           void OnExportToStorage(wxCommandEvent &event);
83       
84       ///Callback on mouse click
85       void OnMouseClick(wxMouseEvent& event);
86
87           /// Displays a menu for items
88           void OnItemMenu(wxListEvent &event);
89           
90           /// Gets the attributes that are being shown and the ones that have been blocked on a specific level
91           void GetAttributes(std::vector<std::string>& areShown, std::vector<std::string>& notShown, int level);
92
93           ///Sets the non visible attributes and refreshes the GUI
94           void SetNonVisibleAttributes(const std::vector<std::string>& notShown, int level);
95
96           ///Creates a new listctrl
97           void CreateCtrl(std::vector<std::string>& notShown, int nlevel);
98   
99           ///Returns true if the attribute passed as a parameter is visible or not
100           bool IsAttributeVisible(const std::string& val, int level);
101       
102       /// Actual processing of item selection/deselection 
103       /// Called by OnItemSelected and OnItemDeSelected
104       //      void ProcessItem
105     private:
106                 wxBoxSizer      *msizer;
107       /// The struct holding the data for one level
108       /// Holds the wx control and other data
109       /// such as the vector of attribute keys corresponding to the columns
110       struct LevelType
111       {
112         // The List Control
113         wxListCtrl* wxCtrl;
114         wxSplitterWindow* wxSplitter;
115         std::vector<std::string> key;
116         // The vector of currently selected nodes of the level
117         std::vector<tree::Node*> Selected;
118         // True iff the vector Selected is up to date
119         bool SelectedUpToDate;
120         // The column used for sorting
121         unsigned int SortColumn;
122         ///Boolean that defines the direction of the sort
123         ///True is ascending order and false is descending
124         bool SortAscending;
125         //The vector of not shown attributes
126         std::vector<std::string> notShownAtts; 
127       };
128       /// The vector of levels : one for each level of the tree      
129       std::vector<LevelType> mLevelList;
130       
131       /// return the wxListCtrl of one level
132       wxListCtrl* GetCtrl(int l) { return mLevelList[l].wxCtrl; }
133       /// return the wxSplitter of one level
134       wxSplitterWindow* GetSplitter(int l) { return mLevelList[l].wxSplitter; }
135       //Returns the maximum number of levels
136       int GetNumberOfLevels(){ return mLevelList.size(); }
137       /// Gets the user selected data from the level passed as a parameter
138       /// Updates the vector if necessary
139       const std::vector<tree::Node*>& GetSelected(int level);
140       /// Set the bool SelectedUpToDate for level l
141       void SetSelectedUpToDate(int l, bool v) { mLevelList[l].SelectedUpToDate = v; }
142       /// Get the bool SelectedUpToDate for level l
143       bool GetSelectedUpToDate(int l) { return mLevelList[l].SelectedUpToDate; }
144        ///Validates the selected images
145       void ValidateSelectedImages(bool isSelection);   
146       ///Gets selected filenames
147       void GetSelectedAsString(std::vector<std::string>&s);
148           ///Gets the filenames of the given nodes and returns them on the given vector. Is recursive.
149           void GetFilenamesAsString(const std::vector<tree::Node*>& nodes, std::vector<std::string>&s);
150       /// Gets the next nodes on the list, be it up(true) or down(false).
151       void GetNodes(std::vector<tree::Node*>& nodes, bool direction);
152       /// Updates the view of a level given the selected items of upper level
153       /// Recursive method
154       virtual void RecursiveUpdateLevel( int );
155       ///Selects all the elements of a level 
156       void SelectAll(int level);
157       ///UnSelects all the elements of a level 
158       void UnSelectAll(int level);
159
160           void OnKeyDown(wxListEvent &event);
161       /// Sorts the level
162       void SortLevel(int level);
163       
164       /// Currently Selected Column
165       int mColumnSelected;
166       ///The last selected item on the list (left click)
167       long mLastSelected;
168
169           ///The last selected item on the list (right click)
170           long mLastRightSelected;
171
172           ///The last selected level (by right click)
173           int mLastRightLevel;
174       ///The color map
175       typedef std::map<tree::Node*,wxColour> ColorMap;
176       typedef std::pair<tree::Node*,wxColour> NodeColorPair;
177       ColorMap mColorMap;
178       ///Initial color palette
179       std::vector<std::string> mColorPalette;
180
181       wxMenu* menu;
182           
183       wxObject* senderCtrl;
184       int mAscendingID;
185       int mDescendingID;
186       int mFilterID;
187       unsigned int mLastLevel;
188       
189           wxMenu* menuItem;
190           wxMenu *subExportMenu;
191           int mAnonymizingID;
192           int mLocalCopyID;
193           int mEditFieldID;
194           int mDumpID;
195           int mExportID;
196           int mExport2StorageID;
197           
198       // If set to true then OnSelectedChanged returns immediately.
199       // Used to do avoid useless process during multiple selections 
200       // or sorting
201       bool mIgnoreSelectedChanged;
202
203       DECLARE_EVENT_TABLE()
204     };
205     // EO class WxTreeView
206     //=====================================================================
207
208         class RemoveAlertDlg : public wxDialog
209         {
210         public:
211                 RemoveAlertDlg(wxWindow *parent, 
212                                                wxString title,    
213                                                    const wxSize& size);
214                 ~RemoveAlertDlg();
215
216                 bool isChecked();
217
218         private :
219                 void onCheck(wxCommandEvent &Event);
220                 bool mSave;
221                 wxCheckBox *mcheck;
222
223         };
224
225
226 } // EO namespace creaImageIO
227
228
229 #endif // USE_WIDGETS
230 // EOF
231 #endif