creaContours_lib
interfMenuBar.h
Go to the documentation of this file.
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 
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 
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 
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 
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  }
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 
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 
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 
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 
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