]> Creatis software - creaMaracasVisu.git/blob
a7a0fc1c689e98f9c4c75330042c4836793ee391
[creaMaracasVisu.git] /
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, wxAUI_MGR_DEFAULT);
55
56                 if (type == 0)
57                 {
58                         //Class that manages the event!!!
59                         //EED 20/01/2012
60                         TConcreteFunctor* functor = new TConcreteFunctor(this,
61                                         &PanelButtonContainer::GenericButtonEvent);
62                         //end of the event definition
63                         this->m_EventPanel = new wxPanel(this);
64                         this->m_ButtonContainerPanel = new ButtonContainerPanel(this,
65                                         this->m_ButtonContainerSettings->GetButtonGroupSettings(functor));
66                         //Bottom Panel
67                         this->m_AuiManager->AddPane(this->m_EventPanel,
68                                         wxAuiPaneInfo().Name(_T("EventPanel")).Caption(_("EventPanel")).CaptionVisible(
69                                                         true).MinimizeButton().MaximizeButton().CloseButton(false).Center().Resizable(
70                                                         true));
71                         //Top Panel
72                         this->m_AuiManager->AddPane(this->m_ButtonContainerPanel,
73                                         wxAuiPaneInfo().Name(_T("ButtonContainerPanel")).DefaultPane().Caption(
74                                                         _("ButtonContainerPanel")).PinButton().CaptionVisible(true).CloseButton(
75                                                         false).Center().Resizable(true));
76                 }
77                 else if (type == 1)
78                 {
79                         TConcreteFunctor* lFunctor = new TConcreteFunctor(this,
80                                         &PanelButtonContainer::GenericListEvent);
81
82                         this->m_EventPanel = new wxPanel(this);
83                         std::cout << "tipo 1; new LIstWx" << std::endl;
84
85                         this->m_ListWxPanel = new ListWx(this, -1,
86                                         this->m_ButtonContainerSettings->GetItemsVector(), lFunctor);
87
88                         //Bottom Panel
89                         this->m_AuiManager->AddPane(this->m_EventPanel,
90                                         wxAuiPaneInfo().Name(_T("EventPanel")).Caption(_("EventPanel")).CaptionVisible(
91                                                         true).MinimizeButton().MaximizeButton().CloseButton(false).Center().Resizable(
92                                                         true));
93                         //Top Panel
94                         this->m_AuiManager->AddPane(this->m_ListWxPanel,
95                                         wxAuiPaneInfo().Name(_T("ListContainerPanel")).DefaultPane().Caption(
96                                                         _("ListContainerPanel")).PinButton().CaptionVisible(true).CloseButton(
97                                                         false).Center().Resizable(true));
98                 }
99                 else if (type == 2)
100                 {
101                         TConcreteFunctor* lFunctor = new TConcreteFunctor(this,
102                                         &PanelButtonContainer::GenericListEvent);
103
104                         this->m_EventPanel = new wxPanel(this);
105
106                         this->m_PanelUp = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize,
107                                         wxTAB_TRAVERSAL, _T("ListConfigContainerPanel"));
108                         wxBoxSizer* mainSizer = new wxBoxSizer(wxHORIZONTAL);
109
110                         //=======
111                         wxBoxSizer* listSizer = new wxBoxSizer(wxVERTICAL);
112
113                         //Original List
114                         this->m_ListWxPanel = new ListWx(this->m_PanelUp, -1,
115                                         this->m_ButtonContainerSettings->GetItemsVector(), lFunctor);
116                         this->m_ListWxPanel->Show(false);
117                         //Configurable list
118                         this->m_CurrentWxPanel = new ListWx(this->m_PanelUp, -1, lFunctor);
119                         listSizer->Add(this->m_CurrentWxPanel, 0, wxEXPAND);
120                         listSizer->Add(this->m_ListWxPanel, 0, wxEXPAND);
121                         mainSizer->Add(listSizer, 0, wxEXPAND | wxALL, 7);
122
123                         //=======
124                         //todo change button to bitmap
125                         wxBoxSizer* buttonSizer = new wxBoxSizer(wxVERTICAL);
126
127                         this->m_ConfigButton = new wxButton(this->m_PanelUp, -1, _("Configurar"), wxDefaultPosition,
128                                         wxDefaultSize, 0, wxDefaultValidator, _("Configurar"));
129
130                         buttonSizer->Add(this->m_ConfigButton, 0, wxEXPAND);
131                         mainSizer->Add(buttonSizer, 0, wxEXPAND | wxALL, 14);
132                         //=======
133
134                         this->m_PanelUp->SetSizer(mainSizer);
135
136                         //Bottom Panel
137                         this->m_AuiManager->AddPane(this->m_EventPanel,
138                                         wxAuiPaneInfo().Name(_T("EventPanel")).Caption(_("EventPanel")).CaptionVisible(
139                                                         true).MinimizeButton().MaximizeButton().CloseButton(false).Center().Resizable(
140                                                         true));
141                         //Top Panel
142                         this->m_AuiManager->AddPane(this->m_PanelUp,
143                                         wxAuiPaneInfo().Name(_T("ListContainerPanel")).DefaultPane().Caption(
144                                                         _("ListContainerPanel")).PinButton().CaptionVisible(true).CloseButton(
145                                                         false).Center().Resizable(true));
146
147                         this->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
148                                                                                         wxCommandEventHandler(PanelButtonContainer::OnConfigButton));
149
150                 }
151
152                 //MLER
153
154                 this->m_AuiManager->Update();
155         }
156 // ----------------------------------------------------------------------------------
157         PanelButtonContainer::~PanelButtonContainer()
158         {
159         }
160 // ----------------------------------------------------------------------------------
161         void PanelButtonContainer::UpdatePanel(const std::string &buttonName)
162         {
163                 try
164                 {
165                         //Hiding the last CartoSettingsPanel
166                         this->m_EventPanel->Show(false);
167                         //Finding the CartoSettingsPanel of the ButtonClicket
168                         this->m_EventPanel = this->m_ButtonContainerSettings->GetPanelButton(
169                                         buttonName);
170                         //changing the parent of the panel!
171                         if (this->m_EventPanel->GetParent() != this)
172                         {
173                                 this->m_EventPanel->Reparent(this);
174                         }       //fi
175                                 //Panel Management
176                         this->m_AuiManager->GetPane(_T("EventPanel")).window = this->m_EventPanel;
177                         //Updating the manager
178                         this->m_AuiManager->Update();
179                 }                       //yrt
180                 catch (const std::exception& e)
181                 {
182                         std::cerr
183                                         << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
184                                         << "exception: " << e.what() << std::endl;
185                         std::cout << "Maybe the panel of the button is NULL" << std::endl;
186                         exit(1);
187                 }                       //hctac
188         }
189 // ----------------------------------------------------------------------------------
190         void PanelButtonContainer::GenericButtonEvent(const std::string &buttonName)
191         {
192                 this->UpdatePanel(buttonName);
193         }
194
195         // ----------------------------------------------------------------------------------
196         //MLER
197         void PanelButtonContainer::GenericListEvent(const std::string &buttonName)
198         {
199                 this->UpdateListPanel(buttonName);
200         }
201
202         // ----------------------------------------------------------------------------------
203         void PanelButtonContainer::UpdateListPanel(const std::string &buttonName)
204         {
205                 try
206                 {
207                         this->m_EventPanel->Show(false);
208                         this->m_EventPanel = this->m_ButtonContainerSettings->GetPanelList(
209                                         buttonName);
210
211                         if (this->m_EventPanel->GetParent() != this)
212                         {
213                                 this->m_EventPanel->Reparent(this);
214                         }       //fi
215                                 //Panel Management
216                         this->m_AuiManager->GetPane(_T("EventPanel")).window = this->m_EventPanel;
217                         //Updating the manager
218                         this->m_AuiManager->Update();
219
220                 } catch (const std::exception& e)
221                 {
222                         std::cerr
223                                         << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
224                                         << "exception: " << e.what() << std::endl;
225                         std::cout << "Maybe the panel of the list is NULL" << std::endl;
226                         exit(1);
227                 }                                                       //hctac
228         }
229
230 // ----------------------------------------------------------------------------------
231         void
232                 PanelButtonContainer::OnConfigButton ( wxCommandEvent& event )
233                 {
234
235                         this->m_ListConfigDialog = new ListConfigDialog(this,-1,_("Config"), this->m_ListWxPanel, this->m_CurrentWxPanel);
236
237                         std::cout<< "Button Event"<<std::endl;
238
239                         this->m_ListConfigDialog->ShowModal();//Show Dialog
240                         this->m_CurrentWxPanel->Reparent(this->m_PanelUp);
241                         this->m_CurrentWxPanel->Show(true);
242                         this->m_CurrentWxPanel->SetFunctorEnabled(true);
243                         this->m_CurrentWxPanel->Update();
244                         this->m_AuiManager->Update( );
245                         this->m_EventPanel->Show(false);
246                 }
247         // ----------------------------------------------------------------------------------
248
249 }//ecapseman
250