]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/buttonContainerSettings.cxx
a0d1ff43e919da508fda06fae53fae68b48600dc
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / creaPanelButtonContainer / buttonContainerSettings.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 buttonContainerSettings.cxx
28  * @brief Implements the ButtonContainerSettings class.
29  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
30  * @date  2011-06-02
31  */
32
33 #include "buttonContainerSettings.h"
34
35 namespace creaPanelButtonContainer
36 {
37         // ----------------------------------------------------------------------------------
38         ButtonContainerSettings::ButtonContainerSettings( )
39         {
40         }
41         // ----------------------------------------------------------------------------------
42         ButtonContainerSettings::~ButtonContainerSettings( )
43         {
44         }
45         
46         // ----------------------------------------------------------------------------------
47         ButtonContainerSettings::ButtonGroupMap
48         ButtonContainerSettings::GetButtonGroupContainer( )
49         {
50                 return m_ButtonGroupContainer;
51         }
52         // ----------------------------------------------------------------------------------
53         ButtonContainerSettings::KeyMapList
54         ButtonContainerSettings::GetGroupNameList( )
55         {
56                 return m_GroupNameList;
57         }
58         // ----------------------------------------------------------------------------------
59         //GetButtonPanel returns the panel associated to the buttonAction
60         ButtonContainerSettings::PanelButton
61         ButtonContainerSettings::GetPanelButton( const StringType &buttonName )
62         {
63                 try
64                 {
65                         std::cout<<"MLER ButtonContainerSettings // GetPanelButton "<<std::endl;
66
67                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
68                             != this->m_GroupNameList.end( ); ++it )
69                         {
70
71                                 std::cout<< std::endl<<"MLER ButtonContainerSettings // GetPanelButton :: it "<< *it<<std::endl;
72
73                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
74                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
75                                 {
76                                         if ( ( *it1 )->first->first.compare( buttonName ) == 0 )
77                                         {
78                                                 return ( ( *it1 )->second->second );
79                                         }//fi
80                                 }//rof
81                         }//rof
82                 }//yrt
83                 catch ( std::exception& e )
84                 {
85                         std::cerr
86                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
87                             << "exception: " << e.what( ) << std::endl;
88                 }//hctac
89                 return ( NULL );
90         }
91         // ----------------------------------------------------------------------------------
92         ButtonContainerSettings::ButtonGroupSettings*
93         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
94         {
95                 ButtonGroupSettings* settings = NULL;
96                 try
97                 {
98                         std::cout<< std::endl<<"MLER CLASS : ButtonContainerSettings" << std::endl;
99                         std::cout<< std::endl<<"MLER ButtonContainerSettings // GetButtonGroupSettings "<<std::endl;
100
101                         settings = new ButtonGroupSettings( );
102
103                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
104                             != this->m_GroupNameList.end( ); ++it )
105                         {
106                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ]; //MLER : Hacer cambio de contenedor
107
108                                 std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: it "<< *it<<std::endl;
109
110                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
111                                 {
112                                         std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: groupName "<< *it<<std::endl;
113                                         std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: buttonName "<< ( *it1 )->first->first <<std::endl;
114
115                                         settings->AddButton( ( *it ), ( *it1 )->first->first, ( *it1 )->first->second, ( *it1 )->second->first, functor );
116                                 }//rof
117                         }//rof
118                 }//yrt
119                 catch ( std::exception& e )
120                 {
121                         std::cerr
122                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
123                             << "exception: " << e.what( ) << std::endl;
124                 }//hctac
125                 return ( settings );
126         }
127         // ----------------------------------------------------------------------------------
128         void
129         ButtonContainerSettings::SetButtonGroupContainer(
130             ButtonGroupMap m_ButtonGroupContainer )
131         {
132                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
133         }
134         // ----------------------------------------------------------------------------------
135         void
136         ButtonContainerSettings::SetGroupNameList( KeyMapList m_GroupNameList )
137         {
138                 this->m_GroupNameList = m_GroupNameList;
139         }
140         
141         // ----------------------------------------------------------------------------------
142         void
143         ButtonContainerSettings::AddButton( const StringType & groupName,
144             const StringType &buttonName, const wxBitmap &icon,
145             const StringType &buttonDescription, PanelButton panel )
146         {
147                 try
148                 {
149                         std::cout<< std::endl<<"MLER ButtonContainerSettings / AddButton(groupname...)"<<std::endl;
150
151                         //builds the button information
152                         //I don't know the try catch doesn't work!!
153                         if ( panel == NULL )
154                         {
155                                 std::cerr << "ButtonContainerSettings::AddButton"
156                                     << "exception: NULL Pointer in panel " << std::endl;
157                                 exit( 1 );
158                         }
159
160                         panel->Show( false );
161
162                         ButtonPair* pair = new ButtonPair(
163                             new ButtonInfo( buttonName, icon ),
164                             new ActionButton( buttonDescription, panel ) );
165
166                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
167                             != this->m_GroupNameList.end( ); ++it )
168                         {
169                                 if ( ( *it ).compare( groupName ) == 0 )
170                                 {
171                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
172                                         return;
173                                 }//fi
174                         }//rof
175                         this->m_GroupNameList.push_back( groupName );
176                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
177                 }//yrt
178                 catch ( const std::exception& e )
179                 {
180                         std::cerr
181                             << "ButtonContainerSettings::AddButton( const StringType & groupName,"
182                             << "const StringType &buttonName, const StringType &iconpath,"
183                             << "const StringType &buttonDescription, PanelButton panel ) "
184                             << "exception: " << e.what( ) << std::endl;
185                 }//hctac
186         }
187         
188         // ----------------------------------------------------------------------------------
189         void
190         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
191         {
192                 try
193                 {
194                         //builds the button information
195                         //I don't know the try catch doesn't work!!
196                         if ( info->panel == NULL )
197                         {
198                                 std::cerr << "ButtonContainerSettings::AddButton"
199                                     << "exception: NULL Pointer in panel " << std::endl;
200                                 exit( 1 );
201                         }
202                         info->panel->Show( false );
203                         ButtonPair* pair = new ButtonPair(
204                             new ButtonInfo( info->buttonName, info->icon ),
205                             new ActionButton( info->buttonDescription, info->panel ) );
206                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
207                             != this->m_GroupNameList.end( ); ++it )
208                         {
209                                 if ( ( *it ).compare( info->groupName ) == 0 )
210                                 {
211                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
212                                         return;
213                                 }//fi
214                         }//rof
215                         this->m_GroupNameList.push_back( info->groupName );
216                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
217                 }//yrt
218                 catch ( const std::exception& e )
219                 {
220                         std::cerr
221                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
222                             << "exception: " << e.what( ) << std::endl;
223                         exit( 1 );
224                 }//hctac
225         }
226         
227         // ----------------------------------------------------------------------------------
228         void
229         ButtonContainerSettings::AddButtons( BCStructVectorType infoList, int type )
230         {
231                 try
232                 {
233                         for( BCStructVectorType::iterator it = infoList.begin( ); it
234                             != infoList.end( ); ++it )
235                         {
236                                 if( type == 0 )
237                                         this->AddButton( *it );
238                                 else if( type == 1 )
239                                         this->AddItems(*it);
240                         }//rof
241                 }//yrt
242                 catch ( std::exception& e )
243                 {
244                         std::cerr
245                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
246                             << "exception: " << e.what( ) << std::endl;
247                 }//hctac
248         }
249
250         void
251         ButtonContainerSettings::AddItems(BCPSettingsStruct* info)
252         {
253                 try
254                 {
255                         //builds the button information
256                         //I don't know the try catch doesn't work!!
257                         if ( info->panel == NULL )
258                         {
259                                 std::cerr << "ButtonContainerSettings::AddButton"
260                                     << "exception: NULL Pointer in panel " << std::endl;
261                                 exit( 1 );
262                         }
263                         info->panel->Show( false );
264                         std::string mapKey = info->groupName + ":" + info->buttonName;
265                         m_itemsMap[mapKey] = info->panel;
266
267                 }//yrt
268                 catch ( const std::exception& e )
269                 {
270                         std::cerr
271                         << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
272                         << "exception: " << e.what( ) << std::endl;
273                         exit( 1 );
274                 }//hctac
275         }
276
277         ButtonContainerSettings::ItemsMap
278         ButtonContainerSettings::GetItemsMap()
279         {
280                 return m_itemsMap;
281         }
282
283
284 // ----------------------------------------------------------------------------------
285 }//ecapseman
286