]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxAttributeSelectionPanel.cpp
Added attribute selection functionality.
[creaImageIO.git] / src2 / creaImageIOWxAttributeSelectionPanel.cpp
1 #include <creaImageIOWxAttributeSelectionPanel.h>
2 #include <creaImageIOSystem.h>
3
4 namespace creaImageIO
5 {
6         const int  ID_COMBO             = 180;
7   // CTor
8   WxAttributeSelectionPanel::WxAttributeSelectionPanel(wxWindow *parent, 
9           wxDialog* dial, 
10           WxGimmickView* view,
11           std::vector<std::string> sAtts,
12           std::vector<std::string> nsAtts,
13           int numLev)
14  :   wxPanel( parent, 
15                   -1, wxDefaultPosition, 
16                   wxDefaultSize,
17                   wxRESIZE_BORDER | 
18               wxSYSTEM_MENU  |
19                   wxCLOSE_BOX |
20                   wxMAXIMIZE_BOX | 
21                   wxMINIMIZE_BOX | 
22                   wxCAPTION  
23                ),       
24                    dialog(dial),
25                    shownA(sAtts),
26                    notShownA(nsAtts),
27                    mView(view)
28   {
29     GimmickDebugMessage(1,"WxCustomizeConfigPanel::WxCustomizeConfigPanel"
30                         <<std::endl);
31         wxStaticText * aa=new wxStaticText(this,-1,_T(" Currently shown attributes for level: "), wxPoint(5,10));
32         wxArrayString as;
33         std::stringstream out;
34         for(int i=1;i<=numLev;i++)
35         {
36                 out<<i;
37                 as.Add(out.str());
38                 out.str("");
39         }
40         levels=new wxComboBox(this, ID_COMBO,"1",wxPoint(190, 5),wxDefaultSize,as);
41         wxStaticText * na=new wxStaticText(this,-1,_T(" Currently hidden attributes: "), wxPoint(255,10));
42
43     shownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(5,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
44
45         shownAtts->InsertColumn(0, 
46                                    crea::std2wx(""),
47                                    wxLIST_FORMAT_LEFT);
48         shownAtts->SetColumnWidth(0,155);
49         shownAtts->Show();
50
51         wxButton *add = new wxButton(this,wxID_ANY,_T(">>"), wxPoint(170,50) );
52         Connect( add->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnAdd ); 
53
54         wxButton *remove = new wxButton(this,wxID_ANY,_T("<<"), wxPoint(170,70) );
55         Connect( remove->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnRemove ); 
56         
57         notShownAtts=new wxListCtrl(this, wxID_ANY, wxPoint(255,30), wxSize(160,90), wxLC_REPORT | wxLC_NO_HEADER );
58
59         notShownAtts->InsertColumn(0, 
60                                    crea::std2wx(""),
61                                    wxLIST_FORMAT_LEFT);
62         notShownAtts->SetColumnWidth(0,155);
63         notShownAtts->Show();
64         LoadCtrls();
65
66         wxButton *save = new wxButton(this,wxID_ANY,_T("Save Changes"), wxPoint(5,130) );
67         Connect( save->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &WxAttributeSelectionPanel::OnSaveConfig ); 
68    
69     Layout(); 
70   }
71
72   /// Destructor
73   WxAttributeSelectionPanel::~WxAttributeSelectionPanel()
74   {
75     GimmickDebugMessage(1,"WxAttributeSelectionPanel::~WxAttributeSelectionPanel"
76                         <<std::endl);
77   }
78
79   void WxAttributeSelectionPanel::OnSaveConfig(wxCommandEvent& event)
80   {
81           int n=levels->GetSelection();
82           if(n<0){n=0;}
83           mView->OnAttributesChanged(notShownA,n);
84           dialog->Destroy();
85   }
86
87   void WxAttributeSelectionPanel::OnAdd(wxCommandEvent& event)
88   {
89         long item = -1;
90         for ( ;; )
91         {
92                 item = shownAtts->GetNextItem(item,
93                                                                                 wxLIST_NEXT_ALL,
94                                                                                 wxLIST_STATE_SELECTED);
95                 if ( item == -1 )
96                         break;
97         
98                         std::string change=shownAtts->GetItemText(item);
99                         std::vector<std::string>::iterator it;
100                         bool found=false;
101                         for(it=shownA.begin();it!=shownA.end()&&!found;++it)
102                         {
103                                 if((*it).compare(change)==0)
104                                 {
105                                         found=true;
106                                 }
107                         }
108                         shownA.erase(it-1);
109                         notShownA.push_back(change);
110         }
111         LoadCtrls();
112         
113   }
114
115   void WxAttributeSelectionPanel::OnRemove(wxCommandEvent& event)
116   {
117
118         long item = -1;
119         for ( ;; )
120         {
121                 item = notShownAtts->GetNextItem(item,
122                                                                                 wxLIST_NEXT_ALL,
123                                                                                 wxLIST_STATE_SELECTED);
124                 if ( item == -1 )
125                         break;
126         
127                         std::string change=notShownAtts->GetItemText(item);
128                         std::vector<std::string>::iterator it;
129                         bool found=false;
130                         for(it=notShownA.begin();it!=notShownA.end()&&!found;++it)
131                         {
132                                 if((*it).compare(change)==0)
133                                 {
134                                         found=true;
135                                 }
136                         }
137                         notShownA.erase(it-1);
138                         shownA.push_back(change);
139                 
140         }
141         LoadCtrls();    
142           
143   }
144   
145
146   void WxAttributeSelectionPanel::LoadCtrls()
147   {
148
149           wxListItem item;
150             item.SetMask(wxLIST_MASK_STATE | 
151                          wxLIST_MASK_TEXT |
152                          //                      wxLIST_MASK_IMAGE |
153                          wxLIST_MASK_DATA |
154                          //                      wxLIST_MASK_WIDTH |
155                          wxLIST_MASK_FORMAT
156                          );
157         std::vector<std::string>::iterator it;
158         shownAtts->DeleteAllItems();
159         notShownAtts->DeleteAllItems();
160         for(it=shownA.begin();it!=shownA.end();++it)
161         {
162                 item.SetText(crea::std2wx(*it));
163                 shownAtts->InsertItem(item);
164         }
165
166         
167         for(it=notShownA.begin();it!=notShownA.end();++it)
168         {
169                 item.SetText(crea::std2wx(*it));
170                 notShownAtts->InsertItem(item);
171         }
172
173   }
174   void WxAttributeSelectionPanel::OnComboChange(wxCommandEvent& event)
175   {
176       int n=levels->GetSelection()+1;
177           mView->GetVisibleAttributes(shownA,notShownA,n);
178           LoadCtrls();
179   }
180   
181 //======================================================================
182 BEGIN_EVENT_TABLE(WxAttributeSelectionPanel, wxPanel)
183 EVT_COMBOBOX  (ID_COMBO,WxAttributeSelectionPanel::OnComboChange)
184 END_EVENT_TABLE()
185 //======================================================================
186
187 } // EO namespace creaImageIO
188
189