]> 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
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                         mylist->FillList();
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
89                         this->m_ListPanel = new wxPanel(this);
90
91                         panelUp = new wxPanel(this, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("ListConfigContainerPanel"));
92                         wxBoxSizer* mainSizer = new wxBoxSizer(wxHORIZONTAL);
93
94                 //=======
95                         wxBoxSizer* listSizer = new wxBoxSizer(wxVERTICAL);
96
97                         this->mylist = new ListWx(panelUp,-1,this->m_ButtonContainerSettings->GetItemsMap(),lFunctor);
98                         this->mylist->Show(false);
99                         ItemsMap empty;
100                         this->myConfiglist = new ListWx(panelUp,-1, empty,lFunctor);
101                         listSizer->Add(this->myConfiglist,0,wxEXPAND);
102                         listSizer->Add(this->mylist,0,wxEXPAND);
103                         mainSizer->Add(listSizer,0,wxEXPAND|wxALL,7);
104
105                 //=======
106                         wxBoxSizer* buttonSizer = new wxBoxSizer(wxVERTICAL);
107
108                         button = new wxButton(panelUp, -1, _("Configurar"),
109                                                                         wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _("Configurar"));
110
111                         buttonSizer->Add(button,0,wxEXPAND);
112                         mainSizer->Add(buttonSizer,0,wxEXPAND|wxALL,14);
113                 //=======
114
115                         panelUp->SetSizer(mainSizer);
116
117                         this->m_AuiManager->AddPane( panelUp,wxAuiPaneInfo( ).Name( _T("ListConfigContainerPanel") ).Caption(_("ListConfigContainerPanel") ). CaptionVisible( true ).CloseButton(false ).Center( ).Resizable( true ) );
118                         this->m_AuiManager->AddPane(this->m_ListPanel, wxAuiPaneInfo( ).Name( _T("ListPanel") ).Caption( _("ListPanel") ). CaptionVisible(true ).CloseButton( false ).Bottom( ).Resizable( true ) );
119                 }
120
121
122                 //MLER
123
124                 this->m_AuiManager->Update( );
125                 //m_listConfigPanel = new ListConfigPanel(this,1,_("Configuracion"),mylist);
126
127                 this->Connect(wxEVT_COMMAND_BUTTON_CLICKED,
128                                                                 wxCommandEventHandler(PanelButtonContainer::ButtonEvent));
129
130         }
131         // ----------------------------------------------------------------------------------
132         PanelButtonContainer::~PanelButtonContainer( )
133         {
134         }
135         // ----------------------------------------------------------------------------------
136         void
137         PanelButtonContainer::UpdatePanel( const std::string &buttonName )
138         {
139                 try
140                 {
141                         std::cout<< "MLER | creaPanelButtonContainer:: UpdatePanel() " << std::endl;
142
143                         //Hiding the last CartoSettingsPanel
144                         this->m_ButtonPanel->Show( false );
145                         //Finding the CartoSettingsPanel of the ButtonClicket
146                         this->m_ButtonPanel = this->m_ButtonContainerSettings->GetPanelButton(buttonName );
147                         std::cout<< buttonName << "---testEvento 2 "<<std::endl;
148                         //changing the parent of the panel!
149                         if ( this->m_ButtonPanel->GetParent( ) != this )
150                         {
151                                 this->m_ButtonPanel->Reparent( this );
152                         }//fi
153                         //Panel Management
154                         this->m_AuiManager->GetPane( _T("ButtonPanel") ).window = this->m_ButtonPanel;
155                         //Updating the manager
156                         this->m_AuiManager->Update( );
157                 }//yrt
158                 catch ( const std::exception& e )
159                 {
160                         std::cerr
161                             << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
162                             << "exception: " << e.what( ) << std::endl;
163                         std::cout << "Maybe the panel of the button is NULL" << std::endl;
164                         exit( 1 );
165                 }//hctac
166         }
167         // ----------------------------------------------------------------------------------
168         void
169         PanelButtonContainer::GenericButtonEvent( const std::string &buttonName )
170         {
171                 std::cout<< "MLER | creaPanelButtonContainer:: GenericButtonEvent() " << std::endl;
172                 std::cout<< buttonName << "---testEvento 1 "<<std::endl;
173                 this->UpdatePanel( buttonName );
174         }
175 // ----------------------------------------------------------------------------------
176
177         void
178         PanelButtonContainer::UpdateListPanel( const std::string &buttonName )
179         {
180                 try{
181
182                         std::cout<< "MLER | creaPanelButtonContainer:: UpdateListPanel() " << std::endl;
183                         std::cout<< buttonName << " --- test 2 "<<std::endl;
184
185                         this->m_ListPanel->Show( false );
186
187                         this->m_ListPanel = this->m_ButtonContainerSettings->GetPanelList(buttonName );
188
189                         if ( this->m_ListPanel->GetParent( ) != this )
190                         {
191                                 this->m_ListPanel->Reparent( this );
192                         }//fi
193                                                 //Panel Management
194                         this->m_AuiManager->GetPane( _T("ListPanel") ).window = this->m_ListPanel;
195                                                 //Updating the manager
196                         this->m_AuiManager->Update( );
197
198                 }catch( const std::exception& e )
199                 {
200                         std::cerr
201                             << "PanelButtonContainer::UpdatePanel( const std::string &buttonName )"
202                             << "exception: " << e.what( ) << std::endl;
203                         std::cout << "Maybe the panel of the list is NULL" << std::endl;
204                         exit( 1 );
205                 }//hctac
206         }
207
208         void
209         PanelButtonContainer::GenericListEvent( const std::string &buttonName )
210         {
211                 std::cout<< "MLER | creaPanelButtonContainer:: GenericListEvent() " << std::endl;
212                 std::cout<< buttonName << " --- test 3 "<<std::endl;
213                 this->UpdateListPanel( buttonName );
214         }
215
216         void
217         PanelButtonContainer::ButtonEvent ( wxCommandEvent& event )
218         {
219
220                 m_listConfigPanel = new ListConfigPanel(this,-1,_("Configuracion"), mylist, myConfiglist);
221
222                 std::cout<< "BUtton Event"<<std::endl;
223
224                 m_listConfigPanel->ShowModal();
225                 this->myConfiglist->Reparent(panelUp);
226                 this->myConfiglist->Show(true);
227                 this->myConfiglist->SetFunctorEnabled(true);
228                 this->myConfiglist->Update();
229                 this->m_AuiManager->Update( );
230                 this->m_ListPanel->Show(false);
231         }
232
233
234
235
236 }//ecapseman
237
238