]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/creaPanelButtonContainer/buttonContainerSettings.cxx
creaButtonContainer: new structure to make easy the button settings
[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-05-24
6  */
7
8 #include "buttonContainerSettings.h"
9 #include <iostream>
10
11 namespace creaPanelButtonContainer
12 {
13         // ----------------------------------------------------------------------------------
14         ButtonContainerSettings::ButtonContainerSettings( )
15         {
16         }
17         // ----------------------------------------------------------------------------------
18         ButtonContainerSettings::~ButtonContainerSettings( )
19         {
20         }
21         // ----------------------------------------------------------------------------------
22         ButtonContainerSettings::ButtonGroupMap
23         ButtonContainerSettings::GetButtonGroupContainer( )
24         {
25                 return m_ButtonGroupContainer;
26         }
27         // ----------------------------------------------------------------------------------
28         ButtonContainerSettings::KeyMapList
29         ButtonContainerSettings::GetGroupNameList( )
30         {
31                 return m_GroupNameList;
32         }
33         // ----------------------------------------------------------------------------------
34         //GetButtonPanel returns the panel associated to the buttonAction
35         ButtonContainerSettings::PanelButton
36         ButtonContainerSettings::GetPanelButton( const std::string &buttonName )
37         {
38                 try
39                 {
40                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
41                             != this->m_GroupNameList.end( ); ++it )
42                         {
43                                 ButtonList list = this->m_ButtonGroupContainer[ ( *it ) ];
44                                 for( ButtonList::iterator it1 = list.begin( ); it1 != list.end( ); ++it1 )
45                                 {
46                                         if ( ( *it1 )->first->first.compare( buttonName ) == 0 )
47                                         {
48                                                 return ( ( *it1 )->second->second );
49                                         }//fi
50                                 }//rof
51                         }//rof
52                 }//yrt
53                 catch ( std::exception& e )
54                 {
55                         std::cerr
56                             << "ButtonContainerSettings::GetPanelButton( const std::string &buttonName ) "
57                             << "exception: " << e.what( ) << std::endl;
58                         return ( NULL );
59                 }//hctac
60         }
61         // ----------------------------------------------------------------------------------
62         ButtonContainerSettings::ButtonGroupSettings*
63         ButtonContainerSettings::GetButtonGroupSettings( TFunctor* functor )
64         {
65                 ButtonGroupSettings* settings = new ButtonGroupSettings( );
66                 try
67                 {
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                         return ( settings );
79                 }//yrt
80                 catch ( std::exception& e )
81                 {
82                         std::cerr
83                             << "ButtonContainerSettings::GetPanelButton( const std::string &buttonName ) "
84                             << "exception: " << e.what( ) << std::endl;
85                         return ( NULL );
86                 }//hctac
87         }
88         // ----------------------------------------------------------------------------------
89         void
90         ButtonContainerSettings::SetButtonGroupContainer(
91             ButtonGroupMap m_ButtonGroupContainer )
92         {
93                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
94         }
95         // ----------------------------------------------------------------------------------
96         void
97         ButtonContainerSettings::SetGroupNameList( KeyMapList m_GroupNameList )
98         {
99                 this->m_GroupNameList = m_GroupNameList;
100         }
101         // ----------------------------------------------------------------------------------
102         void
103         ButtonContainerSettings::AddButton( const std::string & groupName,
104             const std::string &buttonName, const std::string &iconpath,
105             const std::string &buttonDescription, PanelButton panel )
106         {
107                 try
108                 {
109                         //builds the button information
110                         panel->Show( false );
111                         ButtonPair* pair = new ButtonPair(
112                             new ButtonInfo( buttonName, iconpath ),
113                             new ActionButton( buttonDescription, panel ) );
114                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
115                             != this->m_GroupNameList.end( ); ++it )
116                         {
117                                 if ( ( *it ).compare( groupName ) == 0 )
118                                 {
119                                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
120                                         return;
121                                 }//fi
122                         }//rof
123                         this->m_GroupNameList.push_back( groupName );
124                         this->m_ButtonGroupContainer[ groupName ].push_back( pair );
125                 }//yrt
126                 catch ( std::exception& e )
127                 {
128                         std::cerr
129                             << "ButtonContainerSettings::AddButton( const std::string & groupName,"
130                             << "const std::string &buttonName, const std::string &iconpath,"
131                             << "const std::string &buttonDescription, PanelButton panel ) "
132                             << "exception: " << e.what( ) << std::endl;
133                 }//hctac
134         }
135         // ----------------------------------------------------------------------------------
136         void
137         ButtonContainerSettings::AddButton( BCPSettingsStruct* info )
138         {
139                 try
140                 {
141                         //builds the button information
142                         info->panel->Show( false );
143                         ButtonPair* pair = new ButtonPair(
144                             new ButtonInfo( info->buttonName, info->iconpath ),
145                             new ActionButton( info->buttonDescription, info->panel ) );
146                         for( KeyMapList::iterator it = this->m_GroupNameList.begin( ); it
147                             != this->m_GroupNameList.end( ); ++it )
148                         {
149                                 if ( ( *it ).compare( info->groupName ) == 0 )
150                                 {
151                                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
152                                         return;
153                                 }//fi
154                         }//rof
155                         this->m_GroupNameList.push_back( info->groupName );
156                         this->m_ButtonGroupContainer[ info->groupName ].push_back( pair );
157                 }
158                 catch ( std::exception& e )
159                 {
160                         std::cerr
161                             << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
162                             << "exception: " << e.what( ) << std::endl;
163                 }//hctac
164         }
165         // ----------------------------------------------------------------------------------
166         void
167         ButtonContainerSettings::AddButtons( BCStructVectorType infoList )
168         {
169                 try
170                 {
171                         for( BCStructVectorType::iterator it = infoList.begin( ); it
172                             != infoList.end( ); ++it )
173                         {
174                                 this->AddButton( *it );
175                         }//rof
176                 }
177                 catch ( std::exception& e )
178                 {
179                         std::cerr
180                             << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
181                             << "exception: " << e.what( ) << std::endl;
182                 }//hctac
183         }
184 // ----------------------------------------------------------------------------------
185 }//ecapseman
186