]> Creatis software - creaImageIO.git/blob - src2/creaImageIOWxAttributeSelectionPanel.cpp
Added interface for attribute visualization selection.
[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 | wxLC_SINGLE_SEL );
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 | wxLC_SINGLE_SEL );
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           /*mView->OnSaveSettingsCallback(crea::wx2std(copyPath->GetValue()),
82                   crea::wx2std(dbPath->GetValue()),
83                   crea::wx2std(syncEvent->GetValue()),
84                   crea::wx2std(syncFrequency->GetValue()));
85           */
86           dialog->Destroy();
87   }
88
89   void WxAttributeSelectionPanel::OnAdd(wxCommandEvent& event)
90   {
91         long item = -1;
92         for ( ;; )
93         {
94                 item = shownAtts->GetNextItem(item,
95                                                                                 wxLIST_NEXT_ALL,
96                                                                                 wxLIST_STATE_SELECTED);
97                 if ( item == -1 )
98                         break;
99         
100                         std::string change=shownAtts->GetItemText(item);
101                         std::vector<std::string>::iterator it;
102                         bool found=false;
103                         for(it=shownA.begin();it!=shownA.end()&&!found;++it)
104                         {
105                                 if((*it).compare(change)==0)
106                                 {
107                                         found=true;
108                                 }
109                         }
110                         shownA.erase(it-1);
111                         notShownA.push_back(change);
112                         LoadCtrls();    
113                 
114         }
115         
116   }
117
118   void WxAttributeSelectionPanel::OnRemove(wxCommandEvent& event)
119   {
120
121         long item = -1;
122         for ( ;; )
123         {
124                 item = notShownAtts->GetNextItem(item,
125                                                                                 wxLIST_NEXT_ALL,
126                                                                                 wxLIST_STATE_SELECTED);
127                 if ( item == -1 )
128                         break;
129         
130                         std::string change=notShownAtts->GetItemText(item);
131                         std::vector<std::string>::iterator it;
132                         bool found=false;
133                         for(it=notShownA.begin();it!=notShownA.end()&&!found;++it)
134                         {
135                                 if((*it).compare(change)==0)
136                                 {
137                                         found=true;
138                                 }
139                         }
140                         notShownA.erase(it-1);
141                         shownA.push_back(change);
142                         LoadCtrls();    
143                 
144         }
145           
146   }
147   
148
149   void WxAttributeSelectionPanel::LoadCtrls()
150   {
151
152           wxListItem item;
153             item.SetMask(wxLIST_MASK_STATE | 
154                          wxLIST_MASK_TEXT |
155                          //                      wxLIST_MASK_IMAGE |
156                          wxLIST_MASK_DATA |
157                          //                      wxLIST_MASK_WIDTH |
158                          wxLIST_MASK_FORMAT
159                          );
160         std::vector<std::string>::iterator it;
161         shownAtts->DeleteAllItems();
162         notShownAtts->DeleteAllItems();
163         for(it=shownA.begin();it!=shownA.end();++it)
164         {
165                 item.SetText(crea::std2wx(*it));
166                 shownAtts->InsertItem(item);
167         }
168
169         
170         for(it=notShownA.begin();it!=notShownA.end();++it)
171         {
172                 item.SetText(crea::std2wx(*it));
173                 notShownAtts->InsertItem(item);
174         }
175
176   }
177   void WxAttributeSelectionPanel::OnComboChange(wxCommandEvent& event)
178   {
179       int n=levels->GetSelection()+1;
180           mView->GetVisibleAttributes(shownA,notShownA,n);
181           LoadCtrls();
182   }
183   
184 //======================================================================
185 BEGIN_EVENT_TABLE(WxAttributeSelectionPanel, wxPanel)
186 EVT_COMBOBOX  (ID_COMBO,WxAttributeSelectionPanel::OnComboChange)
187 END_EVENT_TABLE()
188 //======================================================================
189
190 } // EO namespace creaImageIO
191
192