1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 * @file buttonContainerSettings.cxx
28 * @brief Implements the ButtonContainerSettings class.
29 * @author Diego CACERES (diego.caceres[AT]creatis.insa-lyon.fr)
33 #include "buttonContainerSettings.h"
35 namespace creaPanelButtonContainer
37 // ----------------------------------------------------------------------------------
38 ButtonContainerSettings::ButtonContainerSettings()
42 // ----------------------------------------------------------------------------------
43 ButtonContainerSettings::~ButtonContainerSettings()
47 // ----------------------------------------------------------------------------------
48 ButtonContainerSettings::ButtonGroupMap ButtonContainerSettings::GetButtonGroupContainer()
50 return m_ButtonGroupContainer;
52 // ----------------------------------------------------------------------------------
53 ButtonContainerSettings::KeyMapList ButtonContainerSettings::GetGroupNameList()
55 return m_GroupNameList;
57 // ----------------------------------------------------------------------------------
58 //GetButtonPanel returns the panel associated to the buttonAction
59 ButtonContainerSettings::PanelButton ButtonContainerSettings::GetPanelButton(
60 const StringType &buttonName)
64 for (KeyMapList::iterator it = this->m_GroupNameList.begin();
65 it != this->m_GroupNameList.end(); ++it)
67 ButtonList list = this->m_ButtonGroupContainer[(*it)];
68 for (ButtonList::iterator it1 = list.begin(); it1 != list.end(); ++it1)
70 if ((*it1)->first->first.compare(buttonName) == 0)
71 return ((*it1)->second->second);
75 catch (std::exception& e)
78 << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
79 << "exception: " << e.what() << std::endl;
84 // ----------------------------------------------------------------------------------
85 ButtonContainerSettings::ButtonGroupSettings*
86 ButtonContainerSettings::GetButtonGroupSettings(TFunctor* functor)
88 ButtonGroupSettings* settings = NULL;
92 settings = new ButtonGroupSettings();
94 for (KeyMapList::iterator it = this->m_GroupNameList.begin();
95 it != this->m_GroupNameList.end(); ++it)
97 ButtonList list = this->m_ButtonGroupContainer[(*it)];
99 for (ButtonList::iterator it1 = list.begin(); it1 != list.end(); ++it1)
102 settings->AddButton((*it), (*it1)->first->first,
103 (*it1)->first->second, (*it1)->second->first, functor);
107 catch (std::exception& e)
110 << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
111 << "exception: " << e.what() << std::endl;
115 // ----------------------------------------------------------------------------------
116 void ButtonContainerSettings::SetButtonGroupContainer(
117 ButtonGroupMap m_ButtonGroupContainer)
119 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
121 // ----------------------------------------------------------------------------------
122 void ButtonContainerSettings::SetGroupNameList(KeyMapList m_GroupNameList)
124 this->m_GroupNameList = m_GroupNameList;
127 // ----------------------------------------------------------------------------------
128 void ButtonContainerSettings::AddButton(const StringType & groupName,
129 const StringType &buttonName, const wxBitmap &icon,
130 const StringType &buttonDescription, PanelButton panel)
134 //builds the button information
135 //I don't know the try catch doesn't work!!
138 std::cerr << "ButtonContainerSettings::AddButton"
139 << "exception: NULL Pointer in panel " << std::endl;
145 ButtonPair* pair = new ButtonPair(new ButtonInfo(buttonName, icon),
146 new ActionButton(buttonDescription, panel));
148 for (KeyMapList::iterator it = this->m_GroupNameList.begin();
149 it != this->m_GroupNameList.end(); ++it)
151 if ((*it).compare(groupName) == 0)
153 this->m_ButtonGroupContainer[groupName].push_back(pair);
157 this->m_GroupNameList.push_back(groupName);
158 this->m_ButtonGroupContainer[groupName].push_back(pair);
160 catch (const std::exception& e)
163 << "ButtonContainerSettings::AddButton( const StringType & groupName,"
164 << "const StringType &buttonName, const StringType &iconpath,"
165 << "const StringType &buttonDescription, PanelButton panel ) "
166 << "exception: " << e.what() << std::endl;
170 // ----------------------------------------------------------------------------------
171 void ButtonContainerSettings::AddButton(BCPSettingsStruct* info)
175 //builds the button information
176 //I don't know the try catch doesn't work!!
177 if (info->panel == NULL)
179 std::cerr << "ButtonContainerSettings::AddButton"
180 << "exception: NULL Pointer in panel " << std::endl;
183 info->panel->Show(false);
184 ButtonPair* pair = new ButtonPair(
185 new ButtonInfo(info->buttonName, info->icon),
186 new ActionButton(info->buttonDescription, info->panel));
187 for (KeyMapList::iterator it = this->m_GroupNameList.begin();
188 it != this->m_GroupNameList.end(); ++it)
190 if ((*it).compare(info->groupName) == 0)
192 this->m_ButtonGroupContainer[info->groupName].push_back(pair);
196 this->m_GroupNameList.push_back(info->groupName);
197 this->m_ButtonGroupContainer[info->groupName].push_back(pair);
199 catch (const std::exception& e)
202 << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
203 << "exception: " << e.what() << std::endl;
208 // ----------------------------------------------------------------------------------
209 void ButtonContainerSettings::InitModel(BCStructVectorType infoList, int type)
213 for (BCStructVectorType::iterator it = infoList.begin();
214 it != infoList.end(); ++it)
217 this->AddButton(*it);
218 else if (type == 1 || type == 2)
223 catch (std::exception& e)
226 << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
227 << "exception: " << e.what() << std::endl;
231 // ----------------------------------------------------------------------------------
233 void ButtonContainerSettings::AddItems(BCPSettingsStruct* info)
237 //build the button information
238 //I don't know the try catch doesn't work!!
239 if (info->panel == NULL)
241 std::cerr << "ButtonContainerSettings::AddItems"
242 << "exception: NULL Pointer in panel " << std::endl;
245 info->panel->Show(false);
246 std::string key = info->groupName + ":" + info->buttonName;
247 m_ItemsVector.push_back(ListAction(key, info->panel));
250 catch (const std::exception& e)
253 << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
254 << "exception: " << e.what() << std::endl;
258 // ----------------------------------------------------------------------------------
259 ButtonContainerSettings::ItemsVector ButtonContainerSettings::GetItemsVector()
261 return this->m_ItemsVector;
264 // ----------------------------------------------------------------------------------
266 ButtonContainerSettings::GetPanelList(const StringType &buttonName)
270 for (ItemsVector::iterator it = this->m_ItemsVector.begin();
271 it != this->m_ItemsVector.end(); ++it)
273 if ((*it).first.compare(buttonName) == 0)
274 return ((*it).second);
278 } catch (std::exception& e)
281 << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
282 << "exception: " << e.what() << std::endl;
289 // ----------------------------------------------------------------------------------