]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/buttonContainerSettings.cxx
2413 creaMaracasVisu Feature New Normal New blackBox BitmapButtonIcon and fix the...
[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                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
66                             != this->m_GroupNameList.end( ); ++it )
67                         {
68                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
69                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
70                                 {
71                                         if ( ( *it1 )->first->first.compare( buttonName ) == 0 )
72                                         {
73                                                 return ( ( *it1 )->second->second );
74                                         }//fi
75                                 }//rof
76                         }//rof
77                 }//yrt
78                 catch ( std::exception& e )
79                 {
80                         std::cerr
81                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
82                             << "exception: " << e.what( ) << std::endl;
83                 }//hctac
84                 return ( NULL );
85         }
86         // ----------------------------------------------------------------------------------
87         ButtonContainerSettings::ButtonGroupSettings*
88         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
89         {
90                 ButtonGroupSettings* settings = NULL;
91                 try
92                 {
93                         settings = new ButtonGroupSettings( );
94                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
95                             != this->m_GroupNameList.end( ); ++it )
96                         {
97                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
98                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
99                                 {
100                                         settings->AddButton( ( *it ), ( *it1 )->first->first, ( *it1 )->first->second, ( *it1 )->second->first, functor );
101                                 }//rof
102                         }//rof
103                 }//yrt
104                 catch ( std::exception& e )
105                 {
106                         std::cerr
107                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
108                             << "exception: " << e.what( ) << std::endl;
109                 }//hctac
110                 return ( settings );
111         }
112         // ----------------------------------------------------------------------------------
113         void
114         ButtonContainerSettings::SetButtonGroupContainer(
115             ButtonGroupMap m_ButtonGroupContainer )
116         {
117                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
118         }
119         // ----------------------------------------------------------------------------------
120         void
121         ButtonContainerSettings::SetGroupNameList( KeyMapList m_GroupNameList )
122         {
123                 this->m_GroupNameList = m_GroupNameList;
124         }
125         
126         // ----------------------------------------------------------------------------------
127         void
128         ButtonContainerSettings::AddButton( const StringType & groupName,
129             const StringType &buttonName, const wxBitmap &icon,
130             const StringType &buttonDescription, PanelButton panel )
131         {
132                 try
133                 {
134                         //builds the button information
135                         //I don't know the try catch doesn't work!!
136                         if ( panel == NULL )
137                         {
138                                 std::cerr << "ButtonContainerSettings::AddButton"
139                                     << "exception: NULL Pointer in panel " << std::endl;
140                                 exit( 1 );
141                         }
142                         panel->Show( false );
143                         ButtonPair* pair = new ButtonPair(
144                             new ButtonInfo( buttonName, icon ),
145                             new ActionButton( buttonDescription, panel ) );
146                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
147                             != this->m_GroupNameList.end( ); ++it )
148                         {
149                                 if ( ( *it ).compare( groupName ) == 0 )
150                                 {
151                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
152                                         return;
153                                 }//fi
154                         }//rof
155                         this->m_GroupNameList.push_back( groupName );
156                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
157                 }//yrt
158                 catch ( const std::exception& e )
159                 {
160                         std::cerr
161                             << "ButtonContainerSettings::AddButton( const StringType & groupName,"
162                             << "const StringType &buttonName, const StringType &iconpath,"
163                             << "const StringType &buttonDescription, PanelButton panel ) "
164                             << "exception: " << e.what( ) << std::endl;
165                 }//hctac
166         }
167         
168         // ----------------------------------------------------------------------------------
169         void
170         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
171         {
172                 try
173                 {
174                         //builds the button information
175                         //I don't know the try catch doesn't work!!
176                         if ( info->panel == NULL )
177                         {
178                                 std::cerr << "ButtonContainerSettings::AddButton"
179                                     << "exception: NULL Pointer in panel " << std::endl;
180                                 exit( 1 );
181                         }
182                         info->panel->Show( false );
183                         ButtonPair* pair = new ButtonPair(
184                             new ButtonInfo( info->buttonName, info->icon ),
185                             new ActionButton( info->buttonDescription, info->panel ) );
186                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
187                             != this->m_GroupNameList.end( ); ++it )
188                         {
189                                 if ( ( *it ).compare( info->groupName ) == 0 )
190                                 {
191                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
192                                         return;
193                                 }//fi
194                         }//rof
195                         this->m_GroupNameList.push_back( info->groupName );
196                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
197                 }//yrt
198                 catch ( const std::exception& e )
199                 {
200                         std::cerr
201                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
202                             << "exception: " << e.what( ) << std::endl;
203                         exit( 1 );
204                 }//hctac
205         }
206         
207         // ----------------------------------------------------------------------------------
208         void
209         ButtonContainerSettings::AddButtons( BCStructVectorType infoList )
210         {
211                 try
212                 {
213                         for( BCStructVectorType::iterator it = infoList.begin( ); it
214                             != infoList.end( ); ++it )
215                         {
216                                 this->AddButton( *it );
217                         }//rof
218                 }//yrt
219                 catch ( std::exception& e )
220                 {
221                         std::cerr
222                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
223                             << "exception: " << e.what( ) << std::endl;
224                 }//hctac
225         }
226 // ----------------------------------------------------------------------------------
227 }//ecapseman
228