]> Creatis software - creaMaracasVisu.git/blob
66ba48e856ef1793cc52a7847dd5f49546d48cfa
[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 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
103                         for( ItemsMap::iterator it= this->m_itemsMap.begin(); it!=this->m_itemsMap.end(); ++it )
104                         {
105                                 if( (*it).first.compare(buttonName) == 0 )
106                                 {
107                                         std::cout<<"debe retornar" << std::endl;
108                                         return ( (*it).second );
109                                 }
110                         }
111
112
113                 }catch ( std::exception& e )
114                 {
115                         std::cerr
116                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
117                             << "exception: " << e.what( ) << std::endl;
118                 }//hctac
119                 return (NULL);
120
121         }
122
123
124         // ----------------------------------------------------------------------------------
125         ButtonContainerSettings::ButtonGroupSettings*
126         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
127         {
128                 ButtonGroupSettings* settings = NULL;
129                 try
130                 {
131                         std::cout<< "MLER | ButtonContainerSettings:: GetButtonGroupSettings() " << std::endl;
132
133                         settings = new ButtonGroupSettings( );
134
135                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
136                             != this->m_GroupNameList.end( ); ++it )
137                         {
138                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
139
140                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
141                                 {
142                                         std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: groupName "<< *it<<std::endl;
143                                         std::cout<<"MLER ButtonContainerSettings // GetButtonGroupSettings :: buttonName "<< ( *it1 )->first->first <<std::endl;
144
145                                         settings->AddButton( ( *it ), ( *it1 )->first->first, ( *it1 )->first->second, ( *it1 )->second->first, functor );
146                                 }//rof
147                         }//rof
148                 }//yrt
149                 catch ( std::exception& e )
150                 {
151                         std::cerr
152                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
153                             << "exception: " << e.what( ) << std::endl;
154                 }//hctac
155                 return ( settings );
156         }
157         // ----------------------------------------------------------------------------------
158         void
159         ButtonContainerSettings::SetButtonGroupContainer(
160             ButtonGroupMap m_ButtonGroupContainer )
161         {
162                 std::cout<< "MLER | ButtonContainerSettings:: SetButtonGroupContainer() " << std::endl;
163                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
164         }
165         // ----------------------------------------------------------------------------------
166         void
167         ButtonContainerSettings::SetGroupNameList( KeyMapList m_GroupNameList )
168         {
169                 std::cout<< "MLER | ButtonContainerSettings:: SetGroupNameList() " << std::endl;
170                 this->m_GroupNameList = m_GroupNameList;
171         }
172         
173         // ----------------------------------------------------------------------------------
174         void
175         ButtonContainerSettings::AddButton( const StringType & groupName,
176             const StringType &buttonName, const wxBitmap &icon,
177             const StringType &buttonDescription, PanelButton panel )
178         {
179                 try
180                 {
181                         std::cout<< "MLER | ButtonContainerSettings:: AddButton( const StringType & groupName ..) " << std::endl;
182
183                         //builds the button information
184                         //I don't know the try catch doesn't work!!
185                         if ( panel == NULL )
186                         {
187                                 std::cerr << "ButtonContainerSettings::AddButton"
188                                     << "exception: NULL Pointer in panel " << std::endl;
189                                 exit( 1 );
190                         }
191
192                         panel->Show( false );
193
194                         ButtonPair* pair = new ButtonPair(
195                             new ButtonInfo( buttonName, icon ),
196                             new ActionButton( buttonDescription, panel ) );
197
198                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
199                             != this->m_GroupNameList.end( ); ++it )
200                         {
201                                 if ( ( *it ).compare( groupName ) == 0 )
202                                 {
203                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
204                                         return;
205                                 }//fi
206                         }//rof
207                         this->m_GroupNameList.push_back( groupName );
208                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
209                 }//yrt
210                 catch ( const std::exception& e )
211                 {
212                         std::cerr
213                             << "ButtonContainerSettings::AddButton( const StringType & groupName,"
214                             << "const StringType &buttonName, const StringType &iconpath,"
215                             << "const StringType &buttonDescription, PanelButton panel ) "
216                             << "exception: " << e.what( ) << std::endl;
217                 }//hctac
218         }
219         
220         // ----------------------------------------------------------------------------------
221         void
222         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
223         {
224                 try
225                 {
226                         std::cout<< "MLER | ButtonContainerSettings:: AddButton( BCPSettingsStruct* info )" << std::endl;
227
228                         //builds the button information
229                         //I don't know the try catch doesn't work!!
230                         if ( info->panel == NULL )
231                         {
232                                 std::cerr << "ButtonContainerSettings::AddButton"
233                                     << "exception: NULL Pointer in panel " << std::endl;
234                                 exit( 1 );
235                         }
236                         info->panel->Show( false );
237                         ButtonPair* pair = new ButtonPair(
238                             new ButtonInfo( info->buttonName, info->icon ),
239                             new ActionButton( info->buttonDescription, info->panel ) );
240                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
241                             != this->m_GroupNameList.end( ); ++it )
242                         {
243                                 if ( ( *it ).compare( info->groupName ) == 0 )
244                                 {
245                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
246                                         return;
247                                 }//fi
248                         }//rof
249                         this->m_GroupNameList.push_back( info->groupName );
250                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
251                 }//yrt
252                 catch ( const std::exception& e )
253                 {
254                         std::cerr
255                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
256                             << "exception: " << e.what( ) << std::endl;
257                         exit( 1 );
258                 }//hctac
259         }
260         
261         // ----------------------------------------------------------------------------------
262         void
263         ButtonContainerSettings::AddButtons( BCStructVectorType infoList, int type )
264         {
265                 std::cout<< "MLER | ButtonContainerSettings:: AddButtons( BCStructVectorType infoList, int type )" << std::endl;
266                 try
267                 {
268                         for( BCStructVectorType::iterator it = infoList.begin( ); it
269                             != infoList.end( ); ++it )
270                         {
271                                 if( type == 0 )
272                                         this->AddButton( *it );
273                                 else if( type == 1 || type == 2)
274                                         this->AddItems(*it);
275
276                         }//rof
277                 }//yrt
278                 catch ( std::exception& e )
279                 {
280                         std::cerr
281                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
282                             << "exception: " << e.what( ) << std::endl;
283                 }//hctac
284         }
285
286         void
287         ButtonContainerSettings::AddItems(BCPSettingsStruct* info)
288         {
289                 try
290                 {
291                         std::cout<< "MLER | ButtonContainerSettings:: AddItems(BCPSettingsStruct* info)" << std::endl;
292                         //builds the button information
293                         //I don't know the try catch doesn't work!!
294                         if ( info->panel == NULL )
295                         {
296                                 std::cerr << "ButtonContainerSettings::AddItems"
297                                     << "exception: NULL Pointer in panel " << std::endl;
298                                 exit( 1 );
299                         }
300
301                         info->panel->Show( false );
302
303                         std::string mapKey = info->groupName + ":" + info->buttonName;
304                         m_itemsMap[mapKey] = info->panel;
305
306                 }//yrt
307                 catch ( const std::exception& e )
308                 {
309                         std::cerr
310                         << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
311                         << "exception: " << e.what( ) << std::endl;
312                         exit( 1 );
313                 }//hctac
314         }
315
316         ButtonContainerSettings::ItemsMap
317         ButtonContainerSettings::GetItemsMap()
318         {
319                 std::cout<< "MLER | ButtonContainerSettings:: GetItemsMap()" << std::endl;
320
321                 return m_itemsMap;
322         }
323
324
325 // ----------------------------------------------------------------------------------
326 }//ecapseman