]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/buttonContainerSettings.cxx
Support #1768 CREATIS Licence insertion
[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         ButtonContainerSettings::ButtonGroupMap
47         ButtonContainerSettings::GetButtonGroupContainer( )
48         {
49                 return m_ButtonGroupContainer;
50         }
51         // ----------------------------------------------------------------------------------
52         ButtonContainerSettings::KeyMapList
53         ButtonContainerSettings::GetGroupNameList( )
54         {
55                 return m_GroupNameList;
56         }
57         // ----------------------------------------------------------------------------------
58         //GetButtonPanel returns the panel associated to the buttonAction
59         ButtonContainerSettings::PanelButton
60         ButtonContainerSettings::GetPanelButton( const StringType &buttonName )
61         {
62                 try
63                 {
64                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
65                             != this->m_GroupNameList.end( ); ++it )
66                         {
67                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
68                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
69                                 {
70                                         if ( ( *it1 )->first->first.compare( buttonName ) == 0 )
71                                         {
72                                                 return ( ( *it1 )->second->second );
73                                         }//fi
74                                 }//rof
75                         }//rof
76                 }//yrt
77                 catch ( std::exception& e )
78                 {
79                         std::cerr
80                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
81                             << "exception: " << e.what( ) << std::endl;
82                 }//hctac
83                 return ( NULL );
84         }
85         // ----------------------------------------------------------------------------------
86         ButtonContainerSettings::ButtonGroupSettings*
87         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
88         {
89                 ButtonGroupSettings* settings = NULL;
90                 try
91                 {
92                         settings = new ButtonGroupSettings( );
93                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
94                             != this->m_GroupNameList.end( ); ++it )
95                         {
96                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
97                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
98                                 {
99                                         settings->AddButton( ( *it ), ( *it1 )->first->first,
100                                             ( *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         void
127         ButtonContainerSettings::AddButton( const StringType & groupName,
128             const StringType &buttonName, const StringType &iconpath,
129             const StringType &buttonDescription, PanelButton panel )
130         {
131                 try
132                 {
133                         //builds the button information
134                         //I don't know the try catch doesn't work!!
135                         if ( panel == NULL )
136                         {
137                                 std::cerr << "ButtonContainerSettings::AddButton"
138                                     << "exception: NULL Pointer in panel " << std::endl;
139                                 exit( 1 );
140                         }
141                         panel->Show( false );
142                         ButtonPair* pair = new ButtonPair(
143                             new ButtonInfo( buttonName, iconpath ),
144                             new ActionButton( buttonDescription, panel ) );
145                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
146                             != this->m_GroupNameList.end( ); ++it )
147                         {
148                                 if ( ( *it ).compare( groupName ) == 0 )
149                                 {
150                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
151                                         return;
152                                 }//fi
153                         }//rof
154                         this->m_GroupNameList.push_back( groupName );
155                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
156                 }//yrt
157                 catch ( const std::exception& e )
158                 {
159                         std::cerr
160                             << "ButtonContainerSettings::AddButton( const StringType & groupName,"
161                             << "const StringType &buttonName, const StringType &iconpath,"
162                             << "const StringType &buttonDescription, PanelButton panel ) "
163                             << "exception: " << e.what( ) << std::endl;
164                 }//hctac
165         }
166         // ----------------------------------------------------------------------------------
167         void
168         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
169         {
170                 try
171                 {
172                         //builds the button information
173                         //I don't know the try catch doesn't work!!
174                         if ( info->panel == NULL )
175                         {
176                                 std::cerr << "ButtonContainerSettings::AddButton"
177                                     << "exception: NULL Pointer in panel " << std::endl;
178                                 exit( 1 );
179                         }
180                         info->panel->Show( false );
181                         ButtonPair* pair = new ButtonPair(
182                             new ButtonInfo( info->buttonName, info->iconpath ),
183                             new ActionButton( info->buttonDescription, info->panel ) );
184                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
185                             != this->m_GroupNameList.end( ); ++it )
186                         {
187                                 if ( ( *it ).compare( info->groupName ) == 0 )
188                                 {
189                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
190                                         return;
191                                 }//fi
192                         }//rof
193                         this->m_GroupNameList.push_back( info->groupName );
194                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
195                 }//yrt
196                 catch ( const std::exception& e )
197                 {
198                         std::cerr
199                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
200                             << "exception: " << e.what( ) << std::endl;
201                         exit( 1 );
202                 }//hctac
203         }
204         // ----------------------------------------------------------------------------------
205         void
206         ButtonContainerSettings::AddButtons( BCStructVectorType infoList )
207         {
208                 try
209                 {
210                         for( BCStructVectorType::iterator it = infoList.begin( ); it
211                             != infoList.end( ); ++it )
212                         {
213                                 this->AddButton( *it );
214                         }//rof
215                 }//yrt
216                 catch ( std::exception& e )
217                 {
218                         std::cerr
219                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
220                             << "exception: " << e.what( ) << std::endl;
221                 }//hctac
222         }
223 // ----------------------------------------------------------------------------------
224 }//ecapseman
225