]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/buttonContainerSettings.cxx
#2507 creaMaracasVisu Feature New Normal - creaPanelButtonContainer ListPanel
[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         // ----------------------------------------------------------------------------------
43         ButtonContainerSettings::~ButtonContainerSettings( )
44         {
45         }
46         
47         // ----------------------------------------------------------------------------------
48         ButtonContainerSettings::ButtonGroupMap
49         ButtonContainerSettings::GetButtonGroupContainer( )
50         {
51                 std::cout<< "MLER | ButtonContainerSettings:: GetButtonGroupContainer( ) " << std::endl;
52                 return m_ButtonGroupContainer;
53         }
54         // ----------------------------------------------------------------------------------
55         ButtonContainerSettings::KeyMapList
56         ButtonContainerSettings::GetGroupNameList( )
57         {
58                 std::cout<< "MLER | ButtonContainerSettings:: GetGroupNameList( ) " << std::endl;
59                 return m_GroupNameList;
60         }
61         // ----------------------------------------------------------------------------------
62         //GetButtonPanel returns the panel associated to the buttonAction
63         ButtonContainerSettings::PanelButton
64         ButtonContainerSettings::GetPanelButton( const StringType &buttonName )
65         {
66                 try
67                 {
68                         std::cout<< "MLER | ButtonContainerSettings:: GetPanelButton " << std::endl;
69
70                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
71                             != this->m_GroupNameList.end( ); ++it )
72                         {
73
74                                 //std::cout<< std::endl<<"MLER ButtonContainerSettings // GetPanelButton :: it "<< *it<<std::endl;
75
76                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
77                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
78                                 {
79                                         if ( ( *it1 )->first->first.compare( buttonName ) == 0 )
80                                         {
81                                                 return ( ( *it1 )->second->second );
82                                         }//fi
83                                 }//rof
84                         }//rof
85                 }//yrt
86                 catch ( std::exception& e )
87                 {
88                         std::cerr
89                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
90                             << "exception: " << e.what( ) << std::endl;
91                 }//hctac
92                 return ( NULL );
93         }
94         // ----------------------------------------------------------------------------------
95         ButtonContainerSettings::PanelButton
96         ButtonContainerSettings::GetPanelList( const StringType &buttonName )
97         {
98                 std::cout<< "MLER | ButtonContainerSettings:: GetPanelList " << std::endl;
99
100
101                 try {
102                         if(m_itemsMap.empty())
103                                 std::cout<< "no tengo nada "<< std::endl;
104
105                         for( ItemsMap::iterator it= this->m_itemsMap.begin(); it!=this->m_itemsMap.end(); ++it )
106                         {
107                                 if( (*it).first.compare(buttonName) == 0 )
108                                         return ( (*it).second );
109                         }
110
111
112                 }catch ( std::exception& e )
113                 {
114                         std::cerr
115                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
116                             << "exception: " << e.what( ) << std::endl;
117                 }//hctac
118                 return (NULL);
119
120         }
121
122
123         // ----------------------------------------------------------------------------------
124         ButtonContainerSettings::ButtonGroupSettings*
125         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
126         {
127                 ButtonGroupSettings* settings = NULL;
128                 try
129                 {
130                         std::cout<< "MLER | ButtonContainerSettings:: GetButtonGroupSettings() " << std::endl;
131
132                         settings = new ButtonGroupSettings( );
133
134                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
135                             != this->m_GroupNameList.end( ); ++it )
136                         {
137                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
138
139                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
140                                 {
141                                         std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: groupName "<< *it<<std::endl;
142                                         std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: buttonName "<< ( *it1 )->first->first <<std::endl;
143
144                                         settings->AddButton( ( *it ), ( *it1 )->first->first, ( *it1 )->first->second, ( *it1 )->second->first, functor );
145                                 }//rof
146                         }//rof
147                 }//yrt
148                 catch ( std::exception& e )
149                 {
150                         std::cerr
151                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
152                             << "exception: " << e.what( ) << std::endl;
153                 }//hctac
154                 return ( settings );
155         }
156         // ----------------------------------------------------------------------------------
157         void
158         ButtonContainerSettings::SetButtonGroupContainer(
159             ButtonGroupMap m_ButtonGroupContainer )
160         {
161                 std::cout<< "MLER | ButtonContainerSettings:: SetButtonGroupContainer() " << std::endl;
162                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
163         }
164         // ----------------------------------------------------------------------------------
165         void
166         ButtonContainerSettings::SetGroupNameList( KeyMapList m_GroupNameList )
167         {
168                 std::cout<< "MLER | ButtonContainerSettings:: SetGroupNameList() " << std::endl;
169                 this->m_GroupNameList = m_GroupNameList;
170         }
171         
172         // ----------------------------------------------------------------------------------
173         void
174         ButtonContainerSettings::AddButton( const StringType & groupName,
175             const StringType &buttonName, const wxBitmap &icon,
176             const StringType &buttonDescription, PanelButton panel )
177         {
178                 try
179                 {
180                         std::cout<< "MLER | ButtonContainerSettings:: AddButton( const StringType & groupName ..) " << std::endl;
181
182                         //builds the button information
183                         //I don't know the try catch doesn't work!!
184                         if ( panel == NULL )
185                         {
186                                 std::cerr << "ButtonContainerSettings::AddButton"
187                                     << "exception: NULL Pointer in panel " << std::endl;
188                                 exit( 1 );
189                         }
190
191                         panel->Show( false );
192
193                         ButtonPair* pair = new ButtonPair(
194                             new ButtonInfo( buttonName, icon ),
195                             new ActionButton( buttonDescription, panel ) );
196
197                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
198                             != this->m_GroupNameList.end( ); ++it )
199                         {
200                                 if ( ( *it ).compare( groupName ) == 0 )
201                                 {
202                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
203                                         return;
204                                 }//fi
205                         }//rof
206                         this->m_GroupNameList.push_back( groupName );
207                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
208                 }//yrt
209                 catch ( const std::exception& e )
210                 {
211                         std::cerr
212                             << "ButtonContainerSettings::AddButton( const StringType & groupName,"
213                             << "const StringType &buttonName, const StringType &iconpath,"
214                             << "const StringType &buttonDescription, PanelButton panel ) "
215                             << "exception: " << e.what( ) << std::endl;
216                 }//hctac
217         }
218         
219         // ----------------------------------------------------------------------------------
220         void
221         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
222         {
223                 try
224                 {
225                         std::cout<< "MLER | ButtonContainerSettings:: AddButton( BCPSettingsStruct* info )" << std::endl;
226
227                         //builds the button information
228                         //I don't know the try catch doesn't work!!
229                         if ( info->panel == NULL )
230                         {
231                                 std::cerr << "ButtonContainerSettings::AddButton"
232                                     << "exception: NULL Pointer in panel " << std::endl;
233                                 exit( 1 );
234                         }
235                         info->panel->Show( false );
236                         ButtonPair* pair = new ButtonPair(
237                             new ButtonInfo( info->buttonName, info->icon ),
238                             new ActionButton( info->buttonDescription, info->panel ) );
239                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
240                             != this->m_GroupNameList.end( ); ++it )
241                         {
242                                 if ( ( *it ).compare( info->groupName ) == 0 )
243                                 {
244                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
245                                         return;
246                                 }//fi
247                         }//rof
248                         this->m_GroupNameList.push_back( info->groupName );
249                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
250                 }//yrt
251                 catch ( const std::exception& e )
252                 {
253                         std::cerr
254                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
255                             << "exception: " << e.what( ) << std::endl;
256                         exit( 1 );
257                 }//hctac
258         }
259         
260         // ----------------------------------------------------------------------------------
261         void
262         ButtonContainerSettings::AddButtons( BCStructVectorType infoList, int type )
263         {
264                 std::cout<< "MLER | ButtonContainerSettings:: AddButtons( BCStructVectorType infoList, int type )" << std::endl;
265                 try
266                 {
267                         for( BCStructVectorType::iterator it = infoList.begin( ); it
268                             != infoList.end( ); ++it )
269                         {
270                                 if( type == 0 )
271                                         this->AddButton( *it );
272                                 else if( type == 1 )
273                                         this->AddItems(*it);
274                         }//rof
275                 }//yrt
276                 catch ( std::exception& e )
277                 {
278                         std::cerr
279                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
280                             << "exception: " << e.what( ) << std::endl;
281                 }//hctac
282         }
283
284
285 //EED-MLER
286 /*
287         void
288         ButtonContainerSettings::AddItems(BCPSettingsStruct* info)
289         {
290                 try
291                 {
292                         std::cout<< "MLER | ButtonContainerSettings:: AddItems(BCPSettingsStruct* info)" << std::endl;
293                         //builds the button information
294                         //I don't know the try catch doesn't work!!
295                         if ( info->panel == NULL )
296                         {
297                                 std::cerr << "ButtonContainerSettings::AddButton"
298                                     << "exception: NULL Pointer in panel " << std::endl;
299                                 exit( 1 );
300                         }
301
302                         info->panel->Show( false );
303
304                         std::string mapKey = info->groupName + ":" + info->buttonName;
305                         m_itemsMap[mapKey] = info->panel;
306
307                 }//yrt
308                 catch ( const std::exception& e )
309                 {
310 <<<<<<< HEAD
311                         try
312                         {
313                                 for( BCStructVectorType::iterator it = infoList.begin( ); it
314                                     != infoList.end( ); ++it )
315                                 {
316                                         this->AddItem(*it);
317                                 }//rof
318                         }//yrt
319                         catch ( const std::exception& e )
320                         {
321                                 std::cerr
322                             << "ContainerSettings::AddButtons( BCStructVectorType infoList ) "
323                             << "exception: " << e.what( ) << std::endl;
324                         }//hctac
325                 }
326 */
327 =======
328                         std::cerr
329                         << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
330                         << "exception: " << e.what( ) << std::endl;
331                         exit( 1 );
332                 }//hctac
333         }
334
335         ButtonContainerSettings::ItemsMap
336         ButtonContainerSettings::GetItemsMap()
337         {
338                 std::cout<< "MLER | ButtonContainerSettings:: GetItemsMap()" << std::endl;
339                 return m_itemsMap;
340         }
341
342 >>>>>>> b8c5a565c70ac0def1f21518afa2d847a9582d79
343
344 // ----------------------------------------------------------------------------------
345 }//ecapseman
346