]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfMenuBar.h
Feature #1772 Add licence terms for all files.
[creaContours.git] / lib / Interface_Icons_NDimensions / interfMenuBar.h
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 #ifndef __interfMENUBARH__
27 #define __interfMENUBARH__
28
29 #include <string>
30 #include <wx/wx.h>
31 #include <vector>
32 #include <wx/image.h>
33 #include <wx/bitmap.h>
34 #include <wx/bmpbuttn.h>
35 #include <wx/stattext.h>
36 #include <wx/sizer.h>
37
38 //#include "interfMainPanel.h"
39 //#include "wxContourEventHandler.h"
40
41
42 class interfMenuBar :
43         public wxPanel
44 {
45 public:
46         interfMenuBar(wxWindow * parent, int sizex, int sizey)
47                 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN){
48                 //this initialice all the handlers to load any type of image, in this case the png handler is needed
49                 wxInitAllImageHandlers();
50                 
51                                 
52         }
53         //~interfMenuBar();
54
55         virtual void initButtons(wxEvtHandler* evtHandler) = 0;
56
57         /**
58         ** This method add a series of button in a line, it uses the method getbutton to create the button
59         ** and static text to create the text, it also initialice the flexgridsizer to add the buttons and
60         ** the text into the panel
61         ** @param vector path, this parameter contains the path of the images to include in the path
62         ** @param vector nom, this parameter contains the names corresponding to each path of image given
63         **/
64     virtual void addButtons(std::vector<std::string> vpath, std::vector<std::string> vnom){
65                 
66                 int sizex = 80;
67                 int sizey = 80;
68         
69                 //RaC 11-09
70                 //This constructor function as well but it is neccessary to change vpath.size() by 6
71                 //flexsizer = new wxFlexGridSizer(2,vpath.size(),2,2);
72                 flexsizer = new wxFlexGridSizer(6);
73                 this->SetSizer(flexsizer, true);
74                 this->SetAutoLayout( true );
75                 
76                 //first row of the sizer, the buttons are being added
77                 for(int i = 0; i < (int)(vpath.size());i++){
78                         std::string p = vpath[i];
79                         wxBitmapButton* bitmapbutton = this->getButton(p, sizex, sizey);
80                         flexsizer->Add(bitmapbutton,wxFIXED_MINSIZE);
81                         
82                 }
83                 //second row of the sizer, the names are being added
84                 
85                 for(int i = 0; i < (int)(vnom.size()); i++){
86                         //sizex = vectbutton[i]->GetSize().GetWidth();
87                         std::string n = vnom[i];
88                         vectbutton[i]->SetToolTip(wxString(n.c_str(),wxConvUTF8));
89                         //wxStaticText* statictext = getText(n, sizex, 15);
90                         //flexsizer->Add(statictext, wxEXPAND |wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTRE_HORIZONTAL|wxSHAPED);
91                 }
92                 this->Layout();
93         }
94
95         /**
96         **  This method creates the button with the given image and returns it
97         ** @param string imgpath is the string containing the path to the image of the button being created
98         ** @param int x indicates the x coordinate where the button should be located
99         ** @param int y indicates the y coordinate where the button should be located
100         **/
101
102         virtual wxBitmapButton* getButton(std::string imgpath, int sizex, int sizey){
103                 vectimgpath.push_back(imgpath);
104                                 
105                 
106                 wxBitmap* bitmap = new wxBitmap(wxString(imgpath.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
107
108                 //wxSize(sizex,sizey)
109                 wxBitmapButton* bitmapbutton = new wxBitmapButton(this, -1, *bitmap, wxDefaultPosition, wxDefaultSize,
110                                                                                         wxBU_AUTODRAW, wxDefaultValidator, wxString(_T("")));
111
112                 vectbutton.push_back(bitmapbutton);
113                 return bitmapbutton;
114         }
115
116         /**
117         **      This method create the static text with the given string and returns it, it also push it back into 
118         **      the vector nom
119         **      @param string nom  text wich will be added to the statictext
120         **      @param int sizex   size of the text
121         **      @param int sizey   size of the text
122         **/
123         virtual wxStaticText* getText(std::string nom, int sizex, int sizey){
124                 vectnom.push_back(nom);
125                 return new wxStaticText(this, -1, wxString(nom.c_str(),wxConvUTF8), wxDefaultPosition, 
126                                                                 wxSize(sizex,sizey), wxALIGN_CENTRE, wxString(nom.c_str(),wxConvUTF8));
127         }
128     /**
129         **      Sets the vector funcion, this vector must contain a function for each button created
130         **      they must be ordered in the same way as the vector that contains the image path
131         **      and name of the button. See addButton(<vect>, <vect>)
132         **/
133         virtual void setVectorFunction(std::vector<wxObjectEventFunction> vectf){
134                 for(int i = 0; i < (int)(vectf.size());i++){
135                         vectfunct.push_back(vectf[i]);
136                 }               
137         }
138
139         /**
140         **      This method connect the events seted in the vector vectfunct
141         **      each function must have a button to relate with, see function setVectorFunction()
142         **/
143         virtual void connectEvents(wxEvtHandler* evtHandler){   
144
145                 for(int i = 0; i < (int)(vectbutton.size());i++){
146                         Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,evtHandler);
147                 }
148         }
149
150         /**
151         **      This method connect the events seted in the vector vectfunct
152         **      each function must have a button to relate with, see function setVectorFunction()
153         **/
154         virtual void connectEvents(){   
155
156                 for(int i = 0; i < (int)(vectbutton.size());i++){
157                         Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,vecthand[i]);
158                 }
159         }
160
161         /**
162         **      Sets the name of the button, this is used to relate the name of the button to a specific command
163         **      @params int i   index in the array of buttons use fuction setVectorFuncion(<vect>) to set the vector
164         **                      first
165         **      @params const char      name of the button see wxContour_ActionCommandsID.h to view the commands
166         **/
167         virtual void setButtonName(int i, const char c){
168                 if(i < (int)(vectbutton.size())){
169                         std::string ac = c+"";
170                         vectbutton[i]->SetName(wxString(ac.c_str(),wxConvUTF8));
171                 }
172         }
173
174         /**
175         **      Responds to the events of the buttons, when the same panel is responsible for it. It gets the name
176         **      of the button corresponding to the method that has to be executed,
177         **      it uses attribute eventHandler to call the methods define by the application.
178         **      see setEventHandler(wxEventHandler*)
179         **/
180         void onActionButtonPressed( wxCommandEvent& event )
181         {
182                 if(true)//if(eventHandler!=NULL)
183                 {
184                         std::string theStr = std::string( ((wxButton *)event.GetEventObject())->GetName().ToAscii());
185                         const char * toolCommand = theStr.c_str();
186                         event.SetId( GetId() );
187                         event.SetEventObject( this );
188                         event.SetClientData( (void *) toolCommand);
189                         //eventHandler->ProcessEvent( event );
190                 }
191         }
192
193         virtual void setEventHandlers(std::vector<wxEvtHandler*> hand){
194
195                 for(int i = 0; i < (int)(hand.size());i++){
196                         vecthand.push_back(hand[i]);
197                 }
198         }
199         
200 private:
201         std::vector<std::string> vectimgpath;
202         std::vector<std::string> vectnom;
203         
204         std::vector<wxButton*> vectbutton;
205         std::vector<wxObjectEventFunction> vectfunct;
206         std::vector<wxEvtHandler*> vecthand;
207
208         wxFlexGridSizer* flexsizer;
209
210 protected:
211         //wxEvtHandler* eventHandler;
212         std::string datadir;
213
214         
215
216 };
217
218 #endif