]> Creatis software - creaMaracasVisu.git/blob
f7cceccbc0cfd787a77303031e5d0abdb014f70b
[creaMaracasVisu.git] /
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         // ----------------------------------------------------------------------------------
43         ButtonContainerSettings::~ButtonContainerSettings()
44         {
45         }
46
47         // ----------------------------------------------------------------------------------
48         ButtonContainerSettings::ButtonGroupMap ButtonContainerSettings::GetButtonGroupContainer()
49         {
50                 return m_ButtonGroupContainer;
51         }
52         // ----------------------------------------------------------------------------------
53         ButtonContainerSettings::KeyMapList ButtonContainerSettings::GetGroupNameList()
54         {
55                 return m_GroupNameList;
56         }
57         // ----------------------------------------------------------------------------------
58         //GetButtonPanel returns the panel associated to the buttonAction
59         ButtonContainerSettings::PanelButton ButtonContainerSettings::GetPanelButton(
60                         const StringType &buttonName)
61         {
62                 try
63                 {
64                         for (KeyMapList::iterator it = this->m_GroupNameList.begin();
65                                         it != 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                                                 return ((*it1)->second->second);
72                                 }       //rof
73                         }       //rof
74                 }       //yrt
75                 catch (std::exception& e)
76                 {
77                         std::cerr
78                                         << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
79                                         << "exception: " << e.what() << std::endl;
80                 }       //hctac
81                 return (NULL);
82         }
83
84         // ----------------------------------------------------------------------------------
85         ButtonContainerSettings::ButtonGroupSettings*
86         ButtonContainerSettings::GetButtonGroupSettings(TFunctor* functor)
87         {
88                 ButtonGroupSettings* settings = NULL;
89                 try
90                 {
91
92                         settings = new ButtonGroupSettings();
93
94                         for (KeyMapList::iterator it = this->m_GroupNameList.begin();
95                                         it != this->m_GroupNameList.end(); ++it)
96                         {
97                                 ButtonList list = this->m_ButtonGroupContainer[(*it)];
98
99                                 for (ButtonList::iterator it1 = list.begin(); it1 != list.end(); ++it1)
100                                 {
101
102                                         settings->AddButton((*it), (*it1)->first->first,
103                                                         (*it1)->first->second, (*it1)->second->first, functor);
104                                 }       //rof
105                         }       //rof
106                 }       //yrt
107                 catch (std::exception& e)
108                 {
109                         std::cerr
110                                         << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
111                                         << "exception: " << e.what() << std::endl;
112                 }       //hctac
113                 return (settings);
114         }
115         // ----------------------------------------------------------------------------------
116         void ButtonContainerSettings::SetButtonGroupContainer(
117                         ButtonGroupMap m_ButtonGroupContainer)
118         {
119                 this->m_ButtonGroupContainer = m_ButtonGroupContainer;
120         }
121         // ----------------------------------------------------------------------------------
122         void ButtonContainerSettings::SetGroupNameList(KeyMapList m_GroupNameList)
123         {
124                 this->m_GroupNameList = m_GroupNameList;
125         }
126
127         // ----------------------------------------------------------------------------------
128         void ButtonContainerSettings::AddButton(const StringType & groupName,
129                         const StringType &buttonName, const wxBitmap &icon,
130                         const StringType &buttonDescription, PanelButton panel)
131         {
132                 try
133                 {
134                         //builds the button information
135                         //I don't know the try catch doesn't work!!
136                         if (panel == NULL)
137                         {
138                                 std::cerr << "ButtonContainerSettings::AddButton"
139                                                 << "exception: NULL Pointer in panel " << std::endl;
140                                 exit(1);
141                         }
142
143                         panel->Show(false);
144
145                         ButtonPair* pair = new ButtonPair(new ButtonInfo(buttonName, icon),
146                                         new ActionButton(buttonDescription, panel));
147
148                         for (KeyMapList::iterator it = this->m_GroupNameList.begin();
149                                         it != this->m_GroupNameList.end(); ++it)
150                         {
151                                 if ((*it).compare(groupName) == 0)
152                                 {
153                                         this->m_ButtonGroupContainer[groupName].push_back(pair);
154                                         return;
155                                 }                       //fi
156                         }                       //rof
157                         this->m_GroupNameList.push_back(groupName);
158                         this->m_ButtonGroupContainer[groupName].push_back(pair);
159                 }                       //yrt
160                 catch (const std::exception& e)
161                 {
162                         std::cerr
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;
167                 }                       //hctac
168         }
169
170         // ----------------------------------------------------------------------------------
171         void ButtonContainerSettings::AddButton(BCPSettingsStruct* info)
172         {
173                 try
174                 {
175                         //builds the button information
176                         //I don't know the try catch doesn't work!!
177                         if (info->panel == NULL)
178                         {
179                                 std::cerr << "ButtonContainerSettings::AddButton"
180                                                 << "exception: NULL Pointer in panel " << std::endl;
181                                 exit(1);
182                         }
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)
189                         {
190                                 if ((*it).compare(info->groupName) == 0)
191                                 {
192                                         this->m_ButtonGroupContainer[info->groupName].push_back(pair);
193                                         return;
194                                 }                       //fi
195                         }                       //rof
196                         this->m_GroupNameList.push_back(info->groupName);
197                         this->m_ButtonGroupContainer[info->groupName].push_back(pair);
198                 }                       //yrt
199                 catch (const std::exception& e)
200                 {
201                         std::cerr
202                                         << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
203                                         << "exception: " << e.what() << std::endl;
204                         exit(1);
205                 }                       //hctac
206         }
207
208         // ----------------------------------------------------------------------------------
209         void ButtonContainerSettings::InitModel(BCStructVectorType infoList, int type)
210         {
211                 try
212                 {
213                         for (BCStructVectorType::iterator it = infoList.begin();
214                                         it != infoList.end(); ++it)
215                         {
216                                 if (type == 0)
217                                         this->AddButton(*it);
218                                 else if (type == 1 || type == 2)
219                                         this->AddItems(*it);
220
221                         }                                       //rof
222                 }                                       //yrt
223                 catch (std::exception& e)
224                 {
225                         std::cerr
226                                         << "ButtonContainerSettings::AddButtons( BCStructVectorType infoList )"
227                                         << "exception: " << e.what() << std::endl;
228                 }                                       //hctac
229         }
230
231         // ----------------------------------------------------------------------------------
232         //MLER
233         void ButtonContainerSettings::AddItems(BCPSettingsStruct* info)
234         {
235                 try
236                 {
237                         //build the button information
238                         //I don't know the try catch doesn't work!!
239                         if (info->panel == NULL)
240                         {
241                                 std::cerr << "ButtonContainerSettings::AddItems"
242                                                 << "exception: NULL Pointer in panel " << std::endl;
243                                 exit(1);
244                         }
245                         info->panel->Show(false);
246                         std::string key = info->groupName + ":" + info->buttonName;
247                         m_ItemsVector.push_back(ListAction(key, info->panel));
248
249                 }                                       //yrt
250                 catch (const std::exception& e)
251                 {
252                         std::cerr
253                                         << "ButtonContainerSettings::AddButton( BCPSettingsStruct* info )"
254                                         << "exception: " << e.what() << std::endl;
255                         exit(1);
256                 }                                       //hctac
257         }
258         // ----------------------------------------------------------------------------------
259         ButtonContainerSettings::ItemsVector ButtonContainerSettings::GetItemsVector()
260         {
261                 return this->m_ItemsVector;
262         }
263
264         // ----------------------------------------------------------------------------------
265         wxPanel*
266         ButtonContainerSettings::GetPanelList(const StringType &buttonName)
267         {
268                 try
269                 {
270                         for (ItemsVector::iterator it = this->m_ItemsVector.begin();
271                                         it != this->m_ItemsVector.end(); ++it)
272                         {
273                                 if ((*it).first.compare(buttonName) == 0)
274                                         return ((*it).second);
275
276                         }
277
278                 } catch (std::exception& e)
279                 {
280                         std::cerr
281                                         << "ButtonContainerSettings::GetPanelButton( const StringType &buttonName ) "
282                                         << "exception: " << e.what() << std::endl;
283                 }                                       //hctac
284                 return (NULL);
285
286         }
287
288 //MLER
289 // ----------------------------------------------------------------------------------
290 }//ecapseman