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