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