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