]> Creatis software - creaMaracasVisu.git/blob
80dee9a41172b129d35786b893cc58862311e880
[creaMaracasVisu.git] /
1 /*!
2  * @file buttonContainerSettings.cxx
3  * @brief Implements the ButtonContainerSettings class.
4  * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
5  * @date  2011-06-02
6  */
7
8 #include "buttonContainerSettings.h"
9
10 namespace creaPanelButtonContainer
11 {
12         // ----------------------------------------------------------------------------------
13         ButtonContainerSettings::ButtonContainerSettings( )
14         {
15         }
16         // ----------------------------------------------------------------------------------
17         ButtonContainerSettings::~ButtonContainerSettings( )
18         {
19         }
20         // ----------------------------------------------------------------------------------
21         ButtonContainerSettings::ButtonGroupMap
22         ButtonContainerSettings::GetButtonGroupContainer( )
23         {
24                 return m_ButtonGroupContainer;
25         }
26         // ----------------------------------------------------------------------------------
27         ButtonContainerSettings::KeyMapList
28         ButtonContainerSettings::GetGroupNameList( )
29         {
30                 return m_GroupNameList;
31         }
32         // ----------------------------------------------------------------------------------
33         //GetButtonPanel returns the panel associated to the buttonAction
34         ButtonContainerSettings::PanelButton
35         ButtonContainerSettings::GetPanelButton( const StringType &buttonName )
36         {
37                 try
38                 {
39                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
40                             != this->m_GroupNameList.end( ); ++it )
41                         {
42                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
43                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
44                                 {
45                                         if ( ( *it1 )->first->first.compare( buttonName ) == 0 )
46                                         {
47                                                 return ( ( *it1 )->second->second );
48                                         }//fi
49                                 }//rof
50                         }//rof
51                 }//yrt
52                 catch ( std::exception& e )
53                 {
54                         std::cerr
55                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
56                             << "exception: " << e.what( ) << std::endl;
57                 }//hctac
58                 return ( NULL );
59         }
60         // ----------------------------------------------------------------------------------
61         ButtonContainerSettings::ButtonGroupSettings*
62         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
63         {
64                 try
65                 {
66                         ButtonGroupSettings* settings = new ButtonGroupSettings( );
67                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
68                             != this->m_GroupNameList.end( ); ++it )
69                         {
70                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
71                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
72                                 {
73                                         settings->AddButton( ( *it ), ( *it1 )->first->first,
74                                             ( *it1 )->first->second, ( *it1 )->second->first, functor );
75                                 }//rof
76                         }//rof
77                         return ( settings );
78                 }//yrt
79                 catch ( std::exception& e )
80                 {
81                         std::cerr
82                             << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
83                             << "exception: " << e.what( ) << std::endl;
84                 }//hctac
85         }
86         // ----------------------------------------------------------------------------------
87         void
88         ButtonContainerSettings::SetButtonGroupContainer(
89             ButtonGroupMap m_ButtonGroupContainer )
90         {
91                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
92         }
93         // ----------------------------------------------------------------------------------
94         void
95         ButtonContainerSettings::SetGroupNameList( KeyMapList m_GroupNameList )
96         {
97                 this->m_GroupNameList = m_GroupNameList;
98         }
99         // ----------------------------------------------------------------------------------
100         void
101         ButtonContainerSettings::AddButton( const StringType & groupName,
102             const StringType &buttonName, const StringType &iconpath,
103             const StringType &buttonDescription, PanelButton panel )
104         {
105                 try
106                 {
107                         //builds the button information
108                         //I don't know the try catch doesn't work!!
109                         if ( panel == NULL )
110                         {
111                                 std::cerr << "ButtonContainerSettings::AddButton"
112                                     << "exception: NULL Pointer in panel " << std::endl;
113                                 exit( 1 );
114                         }
115                         panel->Show( false );
116                         ButtonPair* pair = new ButtonPair(
117                             new ButtonInfo( buttonName, iconpath ),
118                             new ActionButton( buttonDescription, panel ) );
119                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
120                             != this->m_GroupNameList.end( ); ++it )
121                         {
122                                 if ( ( *it ).compare( groupName ) == 0 )
123                                 {
124                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
125                                         return;
126                                 }//fi
127                         }//rof
128                         this->m_GroupNameList.push_back( groupName );
129                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
130                 }//yrt
131                 catch ( const std::exception& e )
132                 {
133                         std::cerr
134                             << "ButtonContainerSettings::AddButton( const StringType & groupName,"
135                             << "const StringType &buttonName, const StringType &iconpath,"
136                             << "const StringType &buttonDescription, PanelButton panel ) "
137                             << "exception: " << e.what( ) << std::endl;
138                 }//hctac
139         }
140         // ----------------------------------------------------------------------------------
141         void
142         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
143         {
144                 try
145                 {
146                         //builds the button information
147                         //I don't know the try catch doesn't work!!
148                         if ( info->panel == NULL )
149                         {
150                                 std::cerr << "ButtonContainerSettings::AddButton"
151                                     << "exception: NULL Pointer in panel " << std::endl;
152                                 exit( 1 );
153                         }
154                         info->panel->Show( false );
155                         ButtonPair* pair = new ButtonPair(
156                             new ButtonInfo( info->buttonName, info->iconpath ),
157                             new ActionButton( info->buttonDescription, info->panel ) );
158                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
159                             != this->m_GroupNameList.end( ); ++it )
160                         {
161                                 if ( ( *it ).compare( info->groupName ) == 0 )
162                                 {
163                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
164                                         return;
165                                 }//fi
166                         }//rof
167                         this->m_GroupNameList.push_back( info->groupName );
168                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
169                 }//yrt
170                 catch ( const std::exception& e )
171                 {
172                         std::cerr
173                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
174                             << "exception: " << e.what( ) << std::endl;
175                         exit( 1 );
176                 }//hctac
177         }
178         // ----------------------------------------------------------------------------------
179         void
180         ButtonContainerSettings::AddButtons( BCStructVectorType infoList )
181         {
182                 try
183                 {
184                         for( BCStructVectorType::iterator it = infoList.begin( ); it
185                             != infoList.end( ); ++it )
186                         {
187                                 this->AddButton( *it );
188                         }//rof
189                 }//yrt
190                 catch ( std::exception& e )
191                 {
192                         std::cerr
193                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
194                             << "exception: " << e.what( ) << std::endl;
195                 }//hctac
196         }
197 // ----------------------------------------------------------------------------------
198 }//ecapseman
199