Main MRPT website > C++ reference
MRPT logo
WxUtils.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef MRPT_WX_UTILS_H
29 #define MRPT_WX_UTILS_H
30 
31 #include <mrpt/utils/utils_defs.h>
32 #include <mrpt/utils/CImage.h>
35 #include <mrpt/synch.h>
36 #include <mrpt/gui/keycodes.h>
37 
38 #include <mrpt/gui/link_pragmas.h>
39 
40 #if MRPT_HAS_WXWIDGETS
41 
42 #include <wx/sizer.h>
43 #include <wx/statbmp.h>
44 #include <wx/menu.h>
45 #include <wx/toolbar.h>
46 #include <wx/frame.h>
47 #include <wx/timer.h>
48 #include <wx/statusbr.h>
49 #include <wx/msgdlg.h>
50 #include <wx/artprov.h>
51 #include <wx/bitmap.h>
52 #include <wx/intl.h>
53 #include <wx/image.h>
54 #include <wx/string.h>
55 #include <wx/msgdlg.h>
56 #include <wx/panel.h>
57 #include <wx/filedlg.h>
58 #include <wx/progdlg.h>
59 #include <wx/imaglist.h>
60 #include <wx/busyinfo.h>
61 #include <wx/log.h>
62 #include <wx/textdlg.h>
63 #include <wx/dirdlg.h>
64 #include <wx/colordlg.h>
65 #include <wx/dcmemory.h>
66 #include <wx/app.h>
67 #include <wx/pen.h>
68 #include <wx/spinctrl.h>
69 #include <wx/sizer.h>
70 #include <wx/notebook.h>
71 #include <wx/button.h>
72 #include <wx/panel.h>
73 #include <wx/stattext.h>
74 #include <wx/textctrl.h>
75 #include <wx/choice.h>
76 #include <wx/radiobox.h>
77 #include <wx/settings.h>
78 #include <wx/checkbox.h>
79 #include <wx/dc.h>
80 #include <wx/dcclient.h>
81 
82 #endif
83 
84 namespace mrpt
85 {
86  namespace gui
87  {
88 #if MRPT_HAS_WXWIDGETS
89 
90 
91 #ifndef _U
92 # ifdef wxUSE_UNICODE
93 # define _U(x) wxString::From8BitData(x)
94 # else
95 # define _U(x) (x)
96 # endif
97 #endif
98 
99 #ifndef WX_START_TRY
100 
101  #define WX_START_TRY \
102  try \
103  {
104 
105  #define WX_END_TRY \
106  } \
107  catch(std::exception &e) \
108  { \
109  wxMessageBox( wxString(e.what(),wxConvUTF8), wxT("Exception"), wxOK, this); \
110  } \
111  catch(...) \
112  { \
113  wxMessageBox( _("Untyped exception!"), _("Exception"), wxOK, this); \
114  }
115 
116 #endif
117 
118 
119  /** Create a wxImage from a MRPT image. The new object must be freed by the user when not required anymore.
120  * \sa MRPTImage2wxImage
121  */
122  wxImage GUI_IMPEXP * MRPTImage2wxImage( const mrpt::utils::CImage &img );
123 
124  /** Create a wxBitmap from a MRPT image. The new object must be freed by the user when not required anymore.
125  * \sa MRPTImage2wxImage
126  */
127  wxBitmap GUI_IMPEXP * MRPTImage2wxBitmap( const mrpt::utils::CImage &img );
128 
129 #if MRPT_HAS_OPENCV
130  /** Create a wxImage from a IPL image. The new object must be freed by the user when not required anymore.
131  * \sa IplImage2wxImage
132  */
133  wxImage GUI_IMPEXP * IplImage2wxImage( void* img );
134 #endif
135 
136  /** Create a MRPT image from a wxImage. The new object must be freed by the user when not required anymore.
137  * It is recommended to use wxImage2MRPTImagePtr instead since smart pointers are safer to manage.
138  * \sa wxImage2MRPTImage, wxImage2MRPTImagePtr
139  */
140  mrpt::utils::CImage GUI_IMPEXP * wxImage2MRPTImage( const wxImage &img );
141 
142  /** Create a MRPT image from a wxImage. The new object is returned as a smart pointer to a CImage object.
143  * \sa wxImage2MRPTImage
144  */
145  mrpt::utils::CImagePtr GUI_IMPEXP wxImage2MRPTImagePtr( const wxImage &img );
146 
147  /** Extracts the key modifiers from a wxKeyEvent */
148  mrptKeyModifier keyEventToMrptKeyModifier( const wxKeyEvent &ev );
149 
150  /** A custom control to display the bitmap and avoid flicker
151  */
152  class GUI_IMPEXP wxMRPTImageControl : public wxPanel
153  {
154  protected:
155  wxBitmap *m_img;
157 
158  wxPoint m_last_mouse_point, m_last_mouse_click;
160 
161  public:
162  wxMRPTImageControl( wxWindow *parent,wxWindowID winID,int x, int y, int width, int height);
163  virtual ~wxMRPTImageControl();
164 
165  void AssignImage(wxBitmap *img); //!< Assigns this image. This object has the ownship of the image and will delete it when appropriate. Remember to call Refresh to display the image.
166  void AssignImage(const mrpt::utils::CImage &img); //!< Assigns this image. Remember to call Refresh to display the image.
167  void GetBitmap(wxBitmap &bmp);
168 
169  void OnPaint(wxPaintEvent &ev);
170  void OnMouseMove(wxMouseEvent& ev);
171  void OnMouseClick(wxMouseEvent& ev);
172 
173  void OnEraseBackground(wxEraseEvent &ev) { /* Do nothing */ }
174  };
175  // end wxMRPTImageControl -----------
176 
177  /** A panel to select the camera input from all the formats supported by MRPT */
178  class GUI_IMPEXP CPanelCameraSelection: public wxPanel
179  {
180  public:
181 
182  CPanelCameraSelection(wxWindow* parent,wxWindowID id=wxID_ANY);
183  virtual ~CPanelCameraSelection();
184 
186  const std::string &sect,
187  const mrpt::utils::CConfigFileBase *cfg ) const;
188 
190  const std::string &sect,
191  mrpt::utils::CConfigFileBase *cfg ) const;
192 
193  //(*Declarations(CPanelCameraSelection)
194  wxTextCtrl* edRawlogLabel;
195  wxStaticText* StaticText10;
196  wxStaticText* StaticText9;
197  wxPanel* Panel5;
198  wxButton* btnBrowseRawlogDir;
199  wxRadioBox* rbBumblebeeSel;
200  wxButton* btnBrowseVideo;
201  wxStaticText* StaticText2;
202  wxPanel* Panel4;
203  wxCheckBox* cbKinect_3D;
204  wxRadioBox* rbKinect_int;
205  wxCheckBox* cbSR_chConf;
206  wxStaticText* StaticText6;
207  wxSpinCtrl* opencvCamIndex;
208  wxTextCtrl* edIPcamURL;
209  wxStaticText* StaticText8;
210  wxStaticText* StaticText11;
211  wxTextCtrl* edCustomCamConfig;
212  wxTextCtrl* edSR_IP;
213  wxPanel* Panel1;
214  wxChoice* cbOpencvCamType;
215  wxStaticText* StaticText1;
216  wxStaticText* StaticText3;
217  wxRadioBox* rbSR_usb;
218  wxPanel* Panel6;
219  wxButton* btnBrowseRawlog;
220  wxPanel* Panel3;
221  wxCheckBox* cbGrayscale;
222  wxCheckBox* cbSR_chRange;
223  wxStaticText* StaticText5;
224  wxStaticText* StaticText7;
225  wxPanel* pnKinect;
226  wxTextCtrl* edVideoFile;
227  wxCheckBox* cbBumblebeeRectif;
228  wxCheckBox* cbKinect_Int;
229  wxCheckBox* cbSR_chIntensity;
230  wxCheckBox* cbKinect_Depth;
231  wxNotebook* pagesCameras;
232  wxPanel* pnSwissRanger;
233  wxTextCtrl* edRawlogFile;
234  wxTextCtrl* edRawlogImgDir;
235  wxPanel* Panel2;
236  wxCheckBox* cbSR_ch3D;
237  wxStaticText* StaticText4;
238  wxChoice* cbOpencvResolution;
239  //*)
240 
241  protected:
242 
243  //(*Identifiers(CPanelCameraSelection)
244  static const long ID_STATICTEXT1;
245  static const long ID_SPINCTRL1;
246  static const long ID_STATICTEXT3;
247  static const long ID_CHOICE1;
248  static const long ID_STATICTEXT6;
249  static const long ID_CHOICE2;
250  static const long ID_PANEL2;
251  static const long ID_STATICTEXT7;
252  static const long ID_TEXTCTRL1;
253  static const long ID_PANEL3;
254  static const long ID_TEXTCTRL6;
255  static const long ID_PANEL4;
256  static const long ID_STATICTEXT8;
257  static const long ID_TEXTCTRL2;
258  static const long ID_BUTTON7;
259  static const long ID_PANEL5;
260  static const long ID_STATICTEXT9;
261  static const long ID_TEXTCTRL3;
262  static const long ID_BUTTON8;
263  static const long ID_STATICTEXT5;
264  static const long ID_TEXTCTRL7;
265  static const long ID_BUTTON9;
266  static const long ID_STATICTEXT10;
267  static const long ID_TEXTCTRL8;
268  static const long ID_STATICTEXT11;
269  static const long ID_PANEL6;
270  static const long ID_RADIOBOX1;
271  static const long ID_CHECKBOX1;
272  static const long ID_STATICTEXT2;
273  static const long ID_PANEL7;
274  static const long ID_RADIOBOX2;
275  static const long ID_STATICTEXT4;
276  static const long ID_TEXTCTRL4;
277  static const long ID_CHECKBOX3;
278  static const long ID_CHECKBOX4;
279  static const long ID_CHECKBOX5;
280  static const long ID_CHECKBOX6;
281  static const long ID_PANEL1;
282  static const long ID_CHECKBOX7;
283  static const long ID_CHECKBOX8;
284  static const long ID_CHECKBOX9;
285  static const long ID_RADIOBOX3;
286  static const long ID_PANEL8;
287  static const long ID_NOTEBOOK1;
288  static const long ID_CHECKBOX2;
289  //*)
290 
291  private:
292 
293  //(*Handlers(CPanelCameraSelection)
294  //*)
295  void OnbtnBrowseVideoClick(wxCommandEvent& event);
296  void OnbtnBrowseRawlogClick(wxCommandEvent& event);
297  void OnbtnBrowseRawlogDirClick(wxCommandEvent& event);
298 
299  DECLARE_EVENT_TABLE()
300  };
301  // end -----------
302 
303  /** Auxiliary structures used internally to mrpt */
304  namespace detail
305  {
306  struct TReturnAskUserOpenCamera
307  {
308  mrpt::utils::CConfigFileMemory selectedConfig;
309  bool accepted_by_user;
310  };
311  }
312 
313 #endif
314 
315  } // End of namespace
316 } // End of namespace
317 
318 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013