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