]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/creaPanelButtonContainer.cxx
#2516 creaMaracasVisu Feature New Normal - creaPanelButtonContainer ListPanel with...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaPanelButtonContainer / creaPanelButtonContainer.cxx
1 /*# ---------------------------------------------------------------------
2  #
3  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4  #                        pour la Sant�)
5  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8  #
9  #  This software is governed by the CeCILL-B license under French law and
10  #  abiding by the rules of distribution of free software. You can  use,
11  #  modify and/ or redistribute the software under the terms of the CeCILL-B
12  #  license as circulated by CEA, CNRS and INRIA at the following URL
13  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14  #  or in the file LICENSE.txt.
15  #
16  #  As a counterpart to the access to the source code and  rights to copy,
17  #  modify and redistribute granted by the license, users are provided only
18  #  with a limited warranty  and the software's author,  the holder of the
19  #  economic rights,  and the successive licensors  have only  limited
20  #  liability.
21  #
22  #  The fact that you are presently reading this means that you have had
23  #  knowledge of the CeCILL-B license and that you accept its terms.
24  # ------------------------------------------------------------------------ */
25
26 /*!
27  * @file creaPanelButtonContainer.h
28  * @brief implements PanelButtonContainer class
29  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
30  * @date  2011-06-02
31  */
32
33 #include "creaPanelButtonContainer.h"
34
35 namespace creaPanelButtonContainer
36 {
37         BEGIN_EVENT_TABLE(PanelButtonContainer,wxPanel)
38 //EVT_LIST_ITEM_SELECTED(-1, ListWx::ListEvent)
39
40 //(*EventTable(ButtonContainerPanel)
41 //*)
42         END_EVENT_TABLE ()
43 // ----------------------------------------------------------------------------------
44         typedef creaButtonContainer::model::TConcreteFunctor<PanelButtonContainer> TConcreteFunctor;
45 // ----------------------------------------------------------------------------------
46         PanelButtonContainer::PanelButtonContainer(wxWindow* parent,
47                         ButtonContainerSettings* bcSettings, int type)
48                         : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize,
49                                         wxDEFAULT_FRAME_STYLE, _T("creaPanelButtonContainer"))
50         {
51                 this->m_ButtonContainerSettings = bcSettings;
52
53                 //Using AuiManager to Manage the Panels
54                 this->m_AuiManager = new wxAuiManager(this,
55                                 wxAUI_MGR_DEFAULT | wxFULL_REPAINT_ON_RESIZE);
56
57                 if (type == 0)
58                 {
59                         //Class that manages the event!!!
60                         //EED 20/01/2012
61                         TConcreteFunctor* functor = new TConcreteFunctor(this,
62                                         &PanelButtonContainer::GenericButtonEvent);
63                         //end of the event definition
64                         this->m_EventPanel = new wxPanel(this);
65                         this->m_ButtonContainerPanel = new ButtonContainerPanel(this,
66                                         this->m_ButtonContainerSettings->GetButtonGroupSettings(functor));
67                         //Bottom Panel
68                         this->m_AuiManager->AddPane(this->m_EventPanel,
69                                         wxAuiPaneInfo().Name(_T("EventPanel")).Caption(_("EventPanel")).CaptionVisible(
70                                                         true).MinimizeButton().MaximizeButton().CloseButton(false).Center().Resizable(
71                                                         true));
72                         //Top Panel
73                         this->m_AuiManager->AddPane(this->m_ButtonContainerPanel,
74                                         wxAuiPaneInfo().Name(_T("ButtonContainerPanel")).DefaultPane().Caption(
75                                                         _("ButtonContainerPanel")).PinButton().CaptionVisible(true).CloseButton(
76                                                         false).Center().Resizable(true));
77                 }
78                 else if (type == 1)
79                 {
80                         //MLER
81                         TConcreteFunctor* lFunctor = new TConcreteFunctor(this,
82                                         &PanelButtonContainer::GenericListEvent);
83
84                         this->m_EventPanel = new wxPanel(this);
85                         std::cout << "tipo 1; new LIstWx" << std::endl;
86
87                         this->m_ListWxPanel = new ListWx(this, -1,
88                                         this->m_ButtonContainerSettings->GetItemsVector(), lFunctor);
89
90                         //Bottom Panel
91                         this->m_AuiManager->AddPane(this->m_EventPanel,
92                                         wxAuiPaneInfo().Name(_T("EventPanel")).Caption(_("EventPanel")).CaptionVisible(
93                                                         true).MinimizeButton().MaximizeButton().CloseButton(false).Center().Resizable(
94                                                         true));
95                         //Top Panel
96                         this->m_AuiManager->AddPane(this->m_ListWxPanel,
97                                         wxAuiPaneInfo().Name(_T("ListContainerPanel")).DefaultPane().Caption(
98                                                         _("ListContainerPanel")).PinButton().CaptionVisible(true).CloseButton(
99                                                         false).Center().Resizable(true));
100                 }
101                 else if (type == 2)
102                 {
103                         TConcreteFunctor* lFunctor = new TConcreteFunctor(this,
104                                         &PanelButtonContainer::GenericListEvent);
105
106                         this->m_EmptyPanel = new wxPanel(this);
107                         this->m_EventPanel = this->m_EmptyPanel;
108
109                         this->m_PanelUp = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
110                                         wxTAB_TRAVERSAL, _T("ListConfigContainerPanel"));
111                         wxGridBagSizer* mainSizer = new wxGridBagSizer(0, 0);
112                         mainSizer->AddGrowableCol(1);
113                         mainSizer->AddGrowableRow(0);
114
115                         //=======
116                         //Original List
117                         this->m_ListWxPanel = new ListWx(this->m_PanelUp, -1,
118                                         this->m_ButtonContainerSettings->GetItemsVector(), lFunctor);
119                         this->m_ListWxPanel->Show(false);
120                         //Configurable list
121                         this->m_CurrentWxPanel = new ListWx(this->m_PanelUp, -1, lFunctor);
122
123                         mainSizer->Add(this->m_ListWxPanel, wxGBPosition(0, 0), wxDefaultSpan,
124                                         wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL
125                                                         | wxALIGN_CENTER_VERTICAL, 5);
126                         mainSizer->Add(this->m_CurrentWxPanel, wxGBPosition(0, 1), wxDefaultSpan,
127                                         wxALL | wxEXPAND | wxALIGN_CENTER_HORIZONTAL
128                                                         | wxALIGN_CENTER_VERTICAL, 5);
129
130                         wxBitmap icon1(Edit_xpm);
131
132                         this->m_ConfigButton = new wxBitmapButton(this->m_PanelUp, -1,
133                                         icon1, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW,
134                                         wxDefaultValidator, _T("Config"));
135
136                         mainSizer->Add(this->m_ConfigButton, wxGBPosition(1, 2), wxDefaultSpan,
137                                         wxALL | wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL, 5);
138
139                         //=======
140
141                         this->m_PanelUp->SetSizer(mainSizer);
142                         mainSizer->Fit(this->m_PanelUp);
143                         mainSizer->SetSizeHints(this->m_PanelUp);
144
145                         //Bottom Panel
146                         this->m_AuiManager->AddPane(this->m_EventPanel,
147                                         wxAuiPaneInfo().Name(_T("EventPanel")).Caption(_("EventPanel")).CaptionVisible(
148                                                         true).MinimizeButton().MaximizeButton().CloseButton(false).Center().Resizable(
149                                                         true));
150                         //Top Panel
151                         this->m_AuiManager->AddPane(this->m_PanelUp,
152                                         wxAuiPaneInfo().Name(_T("ListContainerPanel")).DefaultPane().Caption(
153                                                         _("ListContainerPanel")).PinButton().CaptionVisible(true).CloseButton(
154                                                         false).Center().Resizable(true));
155
156                         this->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
157                                         wxCommandEventHandler(PanelButtonContainer::OnConfigButton));
158
159                 }
160
161                 //End MLER
162
163                 this->m_AuiManager->Update();
164         }
165 // ----------------------------------------------------------------------------------
166         PanelButtonContainer::~PanelButtonContainer()
167         {
168         }
169 // ----------------------------------------------------------------------------------
170         void PanelButtonContainer::UpdatePanel(const std::string &buttonName)
171         {
172                 try
173                 {
174                         //Hiding the last CartoSettingsPanel
175                         this->m_EventPanel->Show(false);
176                         //Finding the CartoSettingsPanel of the ButtonClicket
177                         this->m_EventPanel = this->m_ButtonContainerSettings->GetPanelButton(
178                                         buttonName);
179                         //changing the parent of the panel!
180                         if (this->m_EventPanel->GetParent() != this)
181                         {
182                                 this->m_EventPanel->Reparent(this);
183                         }       //fi
184                                 //Panel Management
185                         this->m_AuiManager->GetPane(_T("EventPanel")).window = this->m_EventPanel;
186                         //Updating the manager
187                         this->m_AuiManager->Update();
188                 }                       //yrt
189                 catch (const std::exception& e)
190                 {
191                         std::cerr
192                                         << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
193                                         << "exception: " << e.what() << std::endl;
194                         std::cout << "Maybe the panel of the button is NULL" << std::endl;
195                         exit(1);
196                 }                       //hctac
197         }
198 // ----------------------------------------------------------------------------------
199         void PanelButtonContainer::GenericButtonEvent(const std::string &buttonName)
200         {
201                 this->UpdatePanel(buttonName);
202         }
203
204         // ----------------------------------------------------------------------------------
205         //MLER
206         void PanelButtonContainer::GenericListEvent(const std::string &buttonName)
207         {
208                 this->UpdateListPanel(buttonName);
209         }
210
211         // ----------------------------------------------------------------------------------
212         void PanelButtonContainer::UpdateListPanel(const std::string &buttonName)
213         {
214                 try
215                 {
216                         this->m_EventPanel->Show(false);
217                         this->m_EventPanel = this->m_ButtonContainerSettings->GetPanelList(
218                                         buttonName);
219
220                         if (this->m_EventPanel->GetParent() != this)
221                         {
222                                 this->m_EventPanel->Reparent(this);
223                         }       //fi
224                                 //Panel Management
225                         this->m_AuiManager->GetPane(_T("EventPanel")).window = this->m_EventPanel;
226                         //Updating the manager
227                         this->m_AuiManager->Update();
228
229                 } catch (const std::exception& e)
230                 {
231                         std::cerr
232                                         << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
233                                         << "exception: " << e.what() << std::endl;
234                         std::cout << "Maybe the panel of the list is NULL" << std::endl;
235                         exit(1);
236                 }                                                       //hctac
237         }
238
239 // ----------------------------------------------------------------------------------
240         void PanelButtonContainer::OnConfigButton(wxCommandEvent& event)
241         {
242
243                 this->m_ListConfigDialog = new ListConfigDialog(this, -1, _("Config"),
244                                 this->m_ListWxPanel, this->m_CurrentWxPanel);
245
246                 std::cout << "Button Event" << std::endl;
247
248                 this->m_EventPanel->Show(false);
249
250                 this->m_ListConfigDialog->ShowModal();                                                  //Show Dialog
251                 this->m_CurrentWxPanel->Reparent(this->m_PanelUp);
252                 this->m_CurrentWxPanel->Show(true);
253                 this->m_CurrentWxPanel->SetFunctorEnabled(true);
254
255                 this->m_CurrentWxPanel->GetListBox()->Deselect(
256                                 this->m_CurrentWxPanel->GetListBox()->GetSelection()); //Deselected item
257                 this->m_CurrentWxPanel->Update();
258                 this->m_ListWxPanel->Show(false);
259                 this->m_EventPanel->Show(false);
260                 this->m_EventPanel = this->m_EmptyPanel; //Management Empty Panel
261
262                 this->m_AuiManager->GetPane(_T("EventPanel")).window = this->m_EventPanel;
263                 this->m_AuiManager->Update();
264
265         }
266         //End MLER
267 // ----------------------------------------------------------------------------------
268
269 }//ecapseman
270