]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/creaPanelButtonContainer.cxx
c69fe01141febae79773729e7ff1a541762d339c
[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
36 namespace creaPanelButtonContainer
37 {
38         BEGIN_EVENT_TABLE(PanelButtonContainer,wxPanel)
39                 //EVT_LIST_ITEM_SELECTED(-1, ListWx::ListEvent)
40
41         //(*EventTable(ButtonContainerPanel)
42         //*)
43         END_EVENT_TABLE()
44         // ----------------------------------------------------------------------------------
45         typedef creaButtonContainer::model::TConcreteFunctor< PanelButtonContainer >   TConcreteFunctor;
46         // ----------------------------------------------------------------------------------
47         PanelButtonContainer::PanelButtonContainer( wxWindow* parent,  ButtonContainerSettings* bcSettings, int type )
48                 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("creaPanelButtonContainer") )
49         {
50                 std::cout<< "MLER | creaPanelButtonContainer:: PanelButtonContainer() " << std::endl;
51
52                 this->m_ButtonContainerSettings = bcSettings;
53
54
55                 //Class that manages the event!!!
56         //EED 20/01/2012
57                 TConcreteFunctor* functor = new TConcreteFunctor( this, &PanelButtonContainer::GenericButtonEvent );
58 //              TConcreteFunctor* functor = new TConcreteFunctor( this->m_ButtonPanel, &PanelButtonContainer::GenericButtonEvent );
59                 //end of the event definition
60
61                 TConcreteFunctor* lFunctor = new TConcreteFunctor( this, &PanelButtonContainer::GenericListEvent );
62                 //MLER
63
64                 //Using AuiManager to Manage the Panels
65                 this->m_AuiManager = new wxAuiManager( this, wxAUI_MGR_DEFAULT );
66
67
68                 if(type == 0)
69                 {
70                         this->m_ButtonPanel = new wxPanel( this );
71                         std::cout << "tipo 0; new ButtonContainerPanel"<<std::endl;
72                         this->m_ButtonContainerPanel = new ButtonContainerPanel( this, this->m_ButtonContainerSettings->GetButtonGroupSettings( functor ) );
73
74                         this->m_AuiManager->AddPane( this->m_ButtonContainerPanel,wxAuiPaneInfo( ).Name( _T("ButtonContainerPanel") ).Caption(_("ButtonContainerPanel") ). CaptionVisible( true ).CloseButton(false ).Center( ).Resizable( true ) );
75                         this->m_AuiManager->AddPane(this->m_ButtonPanel, wxAuiPaneInfo( ).Name( _T("ButtonPanel") ).Caption( _("ButtonPanel") ). CaptionVisible(true ).CloseButton( false ).Bottom( ).Resizable( true ) );
76                 }
77                 else if( type == 1)
78                 {
79                         this->m_ListPanel = new wxPanel(this);
80                         std::cout << "tipo 1; new LIstWx"<<std::endl;
81                         this->mylist = new ListWx(this, -1,this->m_ButtonContainerSettings->GetItemsMap(), lFunctor);
82
83                         this->m_AuiManager->AddPane( this->mylist,wxAuiPaneInfo( ).Name( _T("ListContainerPanel") ).Caption(_("ListContainerPanel") ). CaptionVisible( true ).CloseButton(false ).Center( ).Resizable( true ) );
84                         this->m_AuiManager->AddPane(this->m_ListPanel, wxAuiPaneInfo( ).Name( _T("ListPanel") ).Caption( _("ListPanel") ). CaptionVisible(true ).CloseButton( false ).Bottom( ).Resizable( true ) );
85                 }
86                 else if( type == 2)
87                 {
88                         /*this->m_ListPanel = new wxPanel(this);
89                         std::cout << "tipo 2; new LIstWx"<<std::endl;
90                         this->mylist = new ListWx(this, -1,this->m_ButtonContainerSettings->GetItemsMap(), lFunctor);
91                         this->mylist->Show(false);
92                         ItemsMap empty;
93                         this->myConfiglist = new ListWx(this,-1, empty,lFunctor);
94                         //wxButton
95                         wxPanel* panelButton = new wxPanel(this);
96                         wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
97                         button = new wxButton(panelButton, -1, _("Configurar"),
98                                                 wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Configurar"));
99                         buttonSizer->Add(button,0,wxEXPAND);
100                         panelButton->SetSizer(buttonSizer);
101
102                         this->m_AuiManager->AddPane( panelButton,wxAuiPaneInfo( ).Name( _T("ListConfigContainerPanel") ).Caption(_("ListConfigContainerPanel") ). CaptionVisible( true ).CloseButton(false ).Center( ).Resizable( true ) );
103
104                         this->m_AuiManager->AddPane( this->myConfiglist,wxAuiPaneInfo( ).Name( _T("ListContainerPanel") ).Caption(_("ListContainerPanel") ). CaptionVisible( true ).CloseButton(false ).Center( ).Resizable( true ) );
105
106                         this->m_AuiManager->AddPane(this->m_ListPanel, wxAuiPaneInfo( ).Name( _T("ListPanel") ).Caption( _("ListPanel") ). CaptionVisible(true ).CloseButton( false ).Bottom( ).Resizable( true ) );
107         */
108
109                         this->m_ListPanel = new wxPanel(this);
110
111                         panelUp = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ListConfigContainerPanel"));
112                         wxBoxSizer* mainSizer = new wxBoxSizer(wxHORIZONTAL);
113
114                 //=======
115                         wxBoxSizer* listSizer = new wxBoxSizer(wxVERTICAL);
116
117                         this->mylist = new ListWx(panelUp,-1,this->m_ButtonContainerSettings->GetItemsMap(),lFunctor);
118                         this->mylist->Show(false);
119                         ItemsMap empty;
120                         this->myConfiglist = new ListWx(panelUp,-1, empty,lFunctor);
121                         listSizer->Add(this->myConfiglist,0,wxEXPAND);
122                         listSizer->Add(this->mylist,0,wxEXPAND);
123                         mainSizer->Add(listSizer,0,wxEXPAND|wxALL,7);
124
125                 //=======
126                         wxBoxSizer* buttonSizer = new wxBoxSizer(wxVERTICAL);
127
128                         button = new wxButton(panelUp, -1, _("Configurar"),
129                                                                         wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Configurar"));
130
131                         buttonSizer->Add(button,0,wxEXPAND);
132                         mainSizer->Add(buttonSizer,0,wxEXPAND|wxALL,14);
133                 //=======
134
135                         panelUp->SetSizer(mainSizer);
136
137                         this->m_AuiManager->AddPane( panelUp,wxAuiPaneInfo( ).Name( _T("ListConfigContainerPanel") ).Caption(_("ListConfigContainerPanel") ). CaptionVisible( true ).CloseButton(false ).Center( ).Resizable( true ) );
138                         this->m_AuiManager->AddPane(this->m_ListPanel, wxAuiPaneInfo( ).Name( _T("ListConfigPanel") ).Caption( _("ListConfigPanel") ). CaptionVisible(true ).CloseButton( false ).Bottom( ).Resizable( true ) );
139                 }
140
141                 //MLER
142
143                 this->m_AuiManager->Update( );
144                 //m_listConfigPanel = new ListConfigPanel(this,1,_("Configuracion"),mylist);
145
146                 this->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
147                                                                 wxCommandEventHandler(PanelButtonContainer::ButtonEvent));
148
149         }
150         // ----------------------------------------------------------------------------------
151         PanelButtonContainer::~PanelButtonContainer( )
152         {
153         }
154         // ----------------------------------------------------------------------------------
155         void
156         PanelButtonContainer::UpdatePanel( const std::string &buttonName )
157         {
158                 try
159                 {
160                         std::cout<< "MLER | creaPanelButtonContainer:: UpdatePanel() " << std::endl;
161
162                         //Hiding the last CartoSettingsPanel
163                         this->m_ButtonPanel->Show( false );
164                         //Finding the CartoSettingsPanel of the ButtonClicket
165                         this->m_ButtonPanel = this->m_ButtonContainerSettings->GetPanelButton(buttonName );
166                         std::cout<< buttonName << "---testEvento 2 "<<std::endl;
167                         //changing the parent of the panel!
168                         if ( this->m_ButtonPanel->GetParent( ) != this )
169                         {
170                                 this->m_ButtonPanel->Reparent( this );
171                         }//fi
172                         //Panel Management
173                         this->m_AuiManager->GetPane( _T("ButtonPanel") ).window = this->m_ButtonPanel;
174                         //Updating the manager
175                         this->m_AuiManager->Update( );
176                 }//yrt
177                 catch ( const std::exception& e )
178                 {
179                         std::cerr
180                             << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
181                             << "exception: " << e.what( ) << std::endl;
182                         std::cout << "Maybe the panel of the button is NULL" << std::endl;
183                         exit( 1 );
184                 }//hctac
185         }
186         // ----------------------------------------------------------------------------------
187         void
188         PanelButtonContainer::GenericButtonEvent( const std::string &buttonName )
189         {
190                 std::cout<< "MLER | creaPanelButtonContainer:: GenericButtonEvent() " << std::endl;
191                 std::cout<< buttonName << "---testEvento 1 "<<std::endl;
192                 this->UpdatePanel( buttonName );
193         }
194 // ----------------------------------------------------------------------------------
195
196         void
197         PanelButtonContainer::UpdateListPanel( const std::string &buttonName )
198         {
199                 try{
200
201                         std::cout<< "MLER | creaPanelButtonContainer:: UpdateListPanel() " << std::endl;
202                         std::cout<< buttonName << " --- test 2 "<<std::endl;
203
204                         this->m_ListPanel->Show( false );
205
206                         this->m_ListPanel = this->m_ButtonContainerSettings->GetPanelList(buttonName );
207
208                         if ( this->m_ListPanel->GetParent( ) != this )
209                         {
210                                 this->m_ListPanel->Reparent( this );
211                         }//fi
212                                                 //Panel Management
213                         this->m_AuiManager->GetPane( _T("ListPanel") ).window = this->m_ListPanel;
214                                                 //Updating the manager
215                         this->m_AuiManager->Update( );
216
217                 }catch( const std::exception& e )
218                 {
219                         std::cerr
220                             << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
221                             << "exception: " << e.what( ) << std::endl;
222                         std::cout << "Maybe the panel of the list is NULL" << std::endl;
223                         exit( 1 );
224                 }//hctac
225         }
226
227         void
228         PanelButtonContainer::GenericListEvent( const std::string &buttonName )
229         {
230                 std::cout<< "MLER | creaPanelButtonContainer:: GenericListEvent() " << std::endl;
231                 std::cout<< buttonName << " --- test 3 "<<std::endl;
232                 this->UpdateListPanel( buttonName );
233         }
234
235         void
236         PanelButtonContainer::ButtonEvent ( wxCommandEvent& event )
237         {
238
239                 m_listConfigPanel = new ListConfigPanel(this,-1,_("Configuracion"), mylist, myConfiglist);
240
241                 std::cout<< "BUtton Event"<<std::endl;
242
243                 if ( m_listConfigPanel->ShowModal() == 1 )
244                 {
245                         this->myConfiglist->Reparent(panelUp);
246                         this->myConfiglist->Show(true);
247                         this->myConfiglist->SetFunctorEnabled(true);
248                         this->panelUp->Update();
249                         this->m_AuiManager->Update( );
250                 }
251         }
252
253
254
255
256 }//ecapseman
257
258