]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfMenuBar.h
#3140 creaContours Feature New Normal - branch vtk7itk4wx3
[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(5);
73                 this->SetSizer(flexsizer, true);
74                 this->SetAutoLayout( true );
75                 //first row of the sizer, the buttons are being added
76                 for(int i = 0; i < (int)(vpath.size());i++)
77                 {
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                 {
87                         //sizex = vectbutton[i]->GetSize().GetWidth();
88                         std::string n = vnom[i];
89                         vectbutton[i]->SetToolTip(wxString(n.c_str(),wxConvUTF8));
90                         //wxStaticText* statictext = getText(n, sizex, 15);
91                         //flexsizer->Add(statictext, wxEXPAND |wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTRE_HORIZONTAL|wxSHAPED);
92                 }
93                 this->Layout();
94         }
95
96         /**
97         **  This method creates the button with the given image and returns it
98         ** @param string imgpath is the string containing the path to the image of the button being created
99         ** @param int x indicates the x coordinate where the button should be located
100         ** @param int y indicates the y coordinate where the button should be located
101         **/
102
103         virtual wxBitmapButton* getButton(std::string imgpath, int sizex, int sizey)
104         {
105                 vectimgpath.push_back(imgpath);                         
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         {
125                 vectnom.push_back(nom);
126                 return new wxStaticText(this, -1, wxString(nom.c_str(),wxConvUTF8), wxDefaultPosition, 
127                                                                 wxSize(sizex,sizey), wxALIGN_CENTRE, wxString(nom.c_str(),wxConvUTF8));
128         }
129     /**
130         **      Sets the vector funcion, this vector must contain a function for each button created
131         **      they must be ordered in the same way as the vector that contains the image path
132         **      and name of the button. See addButton(<vect>, <vect>)
133         **/
134         virtual void setVectorFunction(std::vector<wxObjectEventFunction> vectf)
135         {
136                 for(int i = 0; i < (int)(vectf.size());i++)
137                 {
138                         vectfunct.push_back(vectf[i]);
139                 }               
140         }
141
142         /**
143         **      This method connect the events seted in the vector vectfunct
144         **      each function must have a button to relate with, see function setVectorFunction()
145         **/
146         virtual void connectEvents(wxEvtHandler* evtHandler){   
147
148                 for(int i = 0; i < (int)(vectbutton.size());i++){
149                         Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,evtHandler);
150                 }
151         }
152
153         /**
154         **      This method connect the events seted in the vector vectfunct
155         **      each function must have a button to relate with, see function setVectorFunction()
156         **/
157         virtual void connectEvents(){   
158
159                 for(int i = 0; i < (int)(vectbutton.size());i++){
160                         Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,vecthand[i]);
161                 }
162         }
163
164         /**
165         **      Sets the name of the button, this is used to relate the name of the button to a specific command
166         **      @params int i   index in the array of buttons use fuction setVectorFuncion(<vect>) to set the vector
167         **                      first
168         **      @params const char      name of the button see wxContour_ActionCommandsID.h to view the commands
169         **/
170         virtual void setButtonName(int i, const char c){
171                 if(i < (int)(vectbutton.size())){
172                         std::string ac = c+"";
173                         vectbutton[i]->SetName(wxString(ac.c_str(),wxConvUTF8));
174                 }
175         }
176
177         /**
178         **      Responds to the events of the buttons, when the same panel is responsible for it. It gets the name
179         **      of the button corresponding to the method that has to be executed,
180         **      it uses attribute eventHandler to call the methods define by the application.
181         **      see setEventHandler(wxEventHandler*)
182         **/
183         void onActionButtonPressed( wxCommandEvent& event )
184         {
185                 if(true)//if(eventHandler!=NULL)
186                 {
187                         std::string theStr = std::string( ((wxButton *)event.GetEventObject())->GetName().ToAscii());
188                         const char * toolCommand = theStr.c_str();
189                         event.SetId( GetId() );
190                         event.SetEventObject( this );
191                         event.SetClientData( (void *) toolCommand);
192                         //eventHandler->ProcessEvent( event );
193                 }
194         }
195
196         virtual void setEventHandlers(std::vector<wxEvtHandler*> hand){
197
198                 for(int i = 0; i < (int)(hand.size());i++){
199                         vecthand.push_back(hand[i]);
200                 }
201         }
202         
203 private:
204         std::vector<std::string> vectimgpath;
205         std::vector<std::string> vectnom;
206         
207         std::vector<wxButton*> vectbutton;
208         std::vector<wxObjectEventFunction> vectfunct;
209         std::vector<wxEvtHandler*> vecthand;
210
211         wxFlexGridSizer* flexsizer;
212
213 protected:
214         //wxEvtHandler* eventHandler;
215         std::string datadir;
216
217         
218
219 };
220
221 #endif