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