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