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