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 # ------------------------------------------------------------------------ */
26 #ifndef __interfMENUBARH__
27 #define __interfMENUBARH__
33 #include <wx/bitmap.h>
34 #include <wx/bmpbuttn.h>
35 #include <wx/stattext.h>
38 //#include "interfMainPanel.h"
39 //#include "wxContourEventHandler.h"
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();
55 virtual void initButtons(wxEvtHandler* evtHandler) = 0;
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
64 virtual void addButtons(std::vector<std::string> vpath, std::vector<std::string> vnom){
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++)
78 std::string p = vpath[i];
79 wxBitmapButton* bitmapbutton = this->getButton(p, sizex, sizey);
80 flexsizer->Add(bitmapbutton,wxFIXED_MINSIZE);
83 //second row of the sizer, the names are being added
85 for(int i = 0; i < (int)(vnom.size()); i++)
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);
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
103 virtual wxBitmapButton* getButton(std::string imgpath, int sizex, int sizey)
105 vectimgpath.push_back(imgpath);
106 wxBitmap* bitmap = new wxBitmap(wxString(imgpath.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
108 //wxSize(sizex,sizey)
109 wxBitmapButton* bitmapbutton = new wxBitmapButton(this, -1, *bitmap, wxDefaultPosition, wxDefaultSize,
110 wxBU_AUTODRAW, wxDefaultValidator, wxString(_T("")));
112 vectbutton.push_back(bitmapbutton);
117 ** This method create the static text with the given string and returns it, it also push it back into
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
123 virtual wxStaticText* getText(std::string nom, int sizex, int sizey)
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));
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>)
134 virtual void setVectorFunction(std::vector<wxObjectEventFunction> vectf)
136 for(int i = 0; i < (int)(vectf.size());i++)
138 vectfunct.push_back(vectf[i]);
143 ** This method connect the events seted in the vector vectfunct
144 ** each function must have a button to relate with, see function setVectorFunction()
146 virtual void connectEvents(wxEvtHandler* evtHandler){
148 for(int i = 0; i < (int)(vectbutton.size());i++){
149 Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,evtHandler);
154 ** This method connect the events seted in the vector vectfunct
155 ** each function must have a button to relate with, see function setVectorFunction()
157 virtual void connectEvents(){
159 for(int i = 0; i < (int)(vectbutton.size());i++){
160 Connect(vectbutton[i]->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, vectfunct[i],NULL,vecthand[i]);
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
168 ** @params const char name of the button see wxContour_ActionCommandsID.h to view the commands
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));
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*)
183 void onActionButtonPressed( wxCommandEvent& event )
185 if(true)//if(eventHandler!=NULL)
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 );
196 virtual void setEventHandlers(std::vector<wxEvtHandler*> hand){
198 for(int i = 0; i < (int)(hand.size());i++){
199 vecthand.push_back(hand[i]);
204 std::vector<std::string> vectimgpath;
205 std::vector<std::string> vectnom;
207 std::vector<wxButton*> vectbutton;
208 std::vector<wxObjectEventFunction> vectfunct;
209 std::vector<wxEvtHandler*> vecthand;
211 wxFlexGridSizer* flexsizer;
214 //wxEvtHandler* eventHandler;