MRPT  2.0.0
WxUtils.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
13 #include <mrpt/gui/keycodes.h>
14 #include <mrpt/img/CImage.h>
15 
16 #if MRPT_HAS_WXWIDGETS
17 
18 #include <wx/app.h>
19 #include <wx/artprov.h>
20 #include <wx/bitmap.h>
21 #include <wx/busyinfo.h>
22 #include <wx/button.h>
23 #include <wx/checkbox.h>
24 #include <wx/choice.h>
25 #include <wx/colordlg.h>
26 #include <wx/dc.h>
27 #include <wx/dcclient.h>
28 #include <wx/dcmemory.h>
29 #include <wx/dirdlg.h>
30 #include <wx/filedlg.h>
31 #include <wx/frame.h>
32 #include <wx/image.h>
33 #include <wx/imaglist.h>
34 #include <wx/intl.h>
35 #include <wx/log.h>
36 #include <wx/menu.h>
37 #include <wx/msgdlg.h>
38 #include <wx/notebook.h>
39 #include <wx/panel.h>
40 #include <wx/pen.h>
41 #include <wx/progdlg.h>
42 #include <wx/radiobox.h>
43 #include <wx/settings.h>
44 #include <wx/sizer.h>
45 #include <wx/spinctrl.h>
46 #include <wx/statbmp.h>
47 #include <wx/stattext.h>
48 #include <wx/statusbr.h>
49 #include <wx/string.h>
50 #include <wx/textctrl.h>
51 #include <wx/textdlg.h>
52 #include <wx/timer.h>
53 #include <wx/toolbar.h>
54 
55 #endif
56 
57 #include <mutex>
58 
59 namespace mrpt
60 {
61 namespace gui
62 {
63 /** \addtogroup mrpt_gui_wxutils Utilities for MRPT-wxWidgets interfacing (in
64  #include <mrpt/gui/WxUtils.h>)
65  * \ingroup mrpt_gui_grp
66 
67  * @{ */
68 #if MRPT_HAS_WXWIDGETS
69 
70 #ifndef WX_START_TRY
71 
72 #define WX_START_TRY \
73  try \
74  {
75 #define WX_END_TRY \
76  } \
77  catch (std::exception & e) \
78  { \
79  wxMessageBox( \
80  mrpt::exception_to_str(e), wxT("Exception"), wxOK, nullptr); \
81  } \
82  catch (...) \
83  { \
84  wxMessageBox(_("Untyped exception!"), _("Exception"), wxOK, nullptr); \
85  }
86 
87 #endif
88 
89 /** Create a wxImage from a MRPT image. The new object must be freed by the user
90  * when not required anymore.
91  * \sa MRPTImage2wxImage
92  */
93 wxImage* MRPTImage2wxImage(const mrpt::img::CImage& img);
94 
95 /** Create a wxBitmap from a MRPT image. The new object must be freed by the
96  * user when not required anymore.
97  * \sa MRPTImage2wxImage
98  */
99 wxBitmap* MRPTImage2wxBitmap(const mrpt::img::CImage& img);
100 
101 /** Create a MRPT image from a wxImage. The new object must be freed by the user
102  * when not required anymore.
103  * It is recommended to use wxImage2MRPTImagePtr instead since smart pointers
104  * are safer to manage.
105  * \sa wxImage2MRPTImage, wxImage2MRPTImagePtr
106  */
107 mrpt::img::CImage* wxImage2MRPTImage(const wxImage& img);
108 
109 /** Create a MRPT image from a wxImage. The new object is returned as a smart
110  * pointer to a CImage object.
111  * \sa wxImage2MRPTImage
112  */
113 mrpt::img::CImage::Ptr wxImage2MRPTImagePtr(const wxImage& img);
114 
115 /** Extracts the key modifiers from a wxKeyEvent */
116 mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent& ev);
117 
118 /** A custom control to display the bitmap and avoid flicker
119  */
120 class wxMRPTImageControl : public wxPanel
121 {
122  protected:
123  wxBitmap* m_img;
124  std::mutex m_img_cs;
125 
127  std::mutex m_mouse_cs;
128 
129  public:
131  wxWindow* parent, wxWindowID winID, int x, int y, int width,
132  int height);
133  ~wxMRPTImageControl() override;
134 
135  /** Assigns this image. This object has the ownship of the image and will
136  * delete it when appropriate. Remember to call Refresh to display the
137  * image. */
138  void AssignImage(wxBitmap* img);
139  /** Assigns this image. Remember to call Refresh to display the image. */
140  void AssignImage(const mrpt::img::CImage& img);
141  void GetBitmap(wxBitmap& bmp);
142 
143  void OnPaint(wxPaintEvent& ev);
144  void OnMouseMove(wxMouseEvent& ev);
145  void OnMouseClick(wxMouseEvent& ev);
146 
147  void OnEraseBackground(wxEraseEvent&)
148  { /* Do nothing */
149  }
150 };
151 // end wxMRPTImageControl -----------
152 
153 /** A panel to select the camera input from all the formats supported by MRPT */
154 class CPanelCameraSelection : public wxPanel
155 {
156  public:
157  CPanelCameraSelection(wxWindow* parent, wxWindowID id = wxID_ANY);
158  ~CPanelCameraSelection() override;
159 
161  const std::string& sect,
162  const mrpt::config::CConfigFileBase* cfg) const;
163 
165  const std::string& sect, mrpt::config::CConfigFileBase* cfg) const;
166 
167  //(*Declarations(CPanelCameraSelection)
168  wxTextCtrl* edRawlogLabel;
169  wxStaticText* StaticText10;
170  wxStaticText* StaticText9;
171  wxPanel* Panel5;
173  wxRadioBox* rbBumblebeeSel;
174  wxButton* btnBrowseVideo;
175  wxStaticText* StaticText2;
176  wxPanel* Panel4;
177  wxCheckBox* cbKinect_3D;
178  wxRadioBox* rbKinect_int;
179  wxCheckBox* cbSR_chConf;
180  wxStaticText* StaticText6;
181  wxSpinCtrl* opencvCamIndex;
182  wxTextCtrl* edIPcamURL;
183  wxStaticText* StaticText8;
184  wxStaticText* StaticText11;
185  wxTextCtrl* edCustomCamConfig;
186  wxTextCtrl* edSR_IP;
187  wxPanel* Panel1;
188  wxChoice* cbOpencvCamType;
189  wxStaticText* StaticText1;
190  wxStaticText* StaticText3;
191  wxRadioBox* rbSR_usb;
192  wxPanel* Panel6;
193  wxButton* btnBrowseRawlog;
194  wxPanel* Panel3;
195  wxCheckBox* cbGrayscale;
196  wxCheckBox* cbSR_chRange;
197  wxStaticText* StaticText5;
198  wxStaticText* StaticText7;
199  wxPanel* pnKinect;
200  wxTextCtrl* edVideoFile;
201  wxCheckBox* cbBumblebeeRectif;
202  wxCheckBox* cbKinect_Int;
203  wxCheckBox* cbSR_chIntensity;
204  wxCheckBox* cbKinect_Depth;
205  wxNotebook* pagesCameras;
206  wxPanel* pnSwissRanger;
207  wxTextCtrl* edRawlogFile;
208  wxTextCtrl* edRawlogImgDir;
209  wxPanel* Panel2;
210  wxCheckBox* cbSR_ch3D;
211  wxStaticText* StaticText4;
213  //*)
214 
215  protected:
216  //(*Identifiers(CPanelCameraSelection)
217  static const long ID_STATICTEXT1;
218  static const long ID_SPINCTRL1;
219  static const long ID_STATICTEXT3;
220  static const long ID_CHOICE1;
221  static const long ID_STATICTEXT6;
222  static const long ID_CHOICE2;
223  static const long ID_PANEL2;
224  static const long ID_STATICTEXT7;
225  static const long ID_TEXTCTRL1;
226  static const long ID_PANEL3;
227  static const long ID_TEXTCTRL6;
228  static const long ID_PANEL4;
229  static const long ID_STATICTEXT8;
230  static const long ID_TEXTCTRL2;
231  static const long ID_BUTTON7;
232  static const long ID_PANEL5;
233  static const long ID_STATICTEXT9;
234  static const long ID_TEXTCTRL3;
235  static const long ID_BUTTON8;
236  static const long ID_STATICTEXT5;
237  static const long ID_TEXTCTRL7;
238  static const long ID_BUTTON9;
239  static const long ID_STATICTEXT10;
240  static const long ID_TEXTCTRL8;
241  static const long ID_STATICTEXT11;
242  static const long ID_PANEL6;
243  static const long ID_RADIOBOX1;
244  static const long ID_CHECKBOX1;
245  static const long ID_STATICTEXT2;
246  static const long ID_PANEL7;
247  static const long ID_RADIOBOX2;
248  static const long ID_STATICTEXT4;
249  static const long ID_TEXTCTRL4;
250  static const long ID_CHECKBOX3;
251  static const long ID_CHECKBOX4;
252  static const long ID_CHECKBOX5;
253  static const long ID_CHECKBOX6;
254  static const long ID_PANEL1;
255  static const long ID_CHECKBOX7;
256  static const long ID_CHECKBOX8;
257  static const long ID_CHECKBOX9;
258  static const long ID_RADIOBOX3;
259  static const long ID_PANEL8;
260  static const long ID_NOTEBOOK1;
261  static const long ID_CHECKBOX2;
262  //*)
263 
264  private:
265  //(*Handlers(CPanelCameraSelection)
266  //*)
267  void OnbtnBrowseVideoClick(wxCommandEvent& event);
268  void OnbtnBrowseRawlogClick(wxCommandEvent& event);
269  void OnbtnBrowseRawlogDirClick(wxCommandEvent& event);
270 
271  DECLARE_EVENT_TABLE()
272 };
273 // end -----------
274 
275 /** Auxiliary structures used internally to mrpt */
276 namespace detail
277 {
279 {
280  std::string selectedConfig;
282 };
283 } // namespace detail
284 
285 #endif
286 /** @} */
287 } // namespace gui
288 } // namespace mrpt
static const long ID_BUTTON9
Definition: WxUtils.h:238
static const long ID_CHOICE1
Definition: WxUtils.h:220
static const long ID_PANEL3
Definition: WxUtils.h:226
void GetBitmap(wxBitmap &bmp)
Definition: WxUtils.cpp:186
void OnbtnBrowseRawlogDirClick(wxCommandEvent &event)
Definition: WxUtils.cpp:663
static const long ID_SPINCTRL1
Definition: WxUtils.h:218
static const long ID_STATICTEXT9
Definition: WxUtils.h:233
static const long ID_STATICTEXT1
Definition: WxUtils.h:217
static const long ID_CHECKBOX4
Definition: WxUtils.h:251
static const long ID_RADIOBOX3
Definition: WxUtils.h:258
static const long ID_RADIOBOX2
Definition: WxUtils.h:247
void OnMouseMove(wxMouseEvent &ev)
Definition: WxUtils.cpp:134
static const long ID_PANEL1
Definition: WxUtils.h:254
static const long ID_CHECKBOX1
Definition: WxUtils.h:244
static const long ID_TEXTCTRL6
Definition: WxUtils.h:227
mrptKeyModifier
Definition: keycodes.h:156
static const long ID_NOTEBOOK1
Definition: WxUtils.h:260
wxMRPTImageControl(wxWindow *parent, wxWindowID winID, int x, int y, int width, int height)
Definition: WxUtils.cpp:113
static const long ID_CHECKBOX6
Definition: WxUtils.h:253
static const long ID_CHECKBOX5
Definition: WxUtils.h:252
wxImage * MRPTImage2wxImage(const mrpt::img::CImage &img)
Create a wxImage from a MRPT image.
Definition: WxUtils.cpp:24
mrpt::img::CImage * wxImage2MRPTImage(const wxImage &img)
Create a MRPT image from a wxImage.
Definition: WxUtils.cpp:89
void OnEraseBackground(wxEraseEvent &)
Definition: WxUtils.h:147
static const long ID_CHECKBOX3
Definition: WxUtils.h:250
static const long ID_TEXTCTRL8
Definition: WxUtils.h:240
static const long ID_TEXTCTRL3
Definition: WxUtils.h:234
This class allows loading and storing values and vectors of different types from a configuration text...
static const long ID_TEXTCTRL1
Definition: WxUtils.h:225
void OnMouseClick(wxMouseEvent &ev)
Definition: WxUtils.cpp:140
static const long ID_CHECKBOX8
Definition: WxUtils.h:256
static const long ID_CHECKBOX7
Definition: WxUtils.h:255
void OnbtnBrowseVideoClick(wxCommandEvent &event)
Definition: WxUtils.cpp:629
void readConfigIntoVideoSourcePanel(const std::string &sect, const mrpt::config::CConfigFileBase *cfg) const
Definition: WxUtils.cpp:848
static const long ID_CHOICE2
Definition: WxUtils.h:222
constexpr auto sect
wxBitmap * MRPTImage2wxBitmap(const mrpt::img::CImage &img)
Create a wxBitmap from a MRPT image.
Definition: WxUtils.cpp:74
static const long ID_STATICTEXT6
Definition: WxUtils.h:221
static const long ID_TEXTCTRL2
Definition: WxUtils.h:230
static const long ID_CHECKBOX2
Definition: WxUtils.h:261
static const long ID_PANEL2
Definition: WxUtils.h:223
static const long ID_STATICTEXT3
Definition: WxUtils.h:219
void writeConfigFromVideoSourcePanel(const std::string &sect, mrpt::config::CConfigFileBase *cfg) const
Definition: WxUtils.cpp:682
static const long ID_PANEL5
Definition: WxUtils.h:232
mrptKeyModifier keyEventToMrptKeyModifier(const wxKeyEvent &ev)
Extracts the key modifiers from a wxKeyEvent.
Definition: WxUtils.cpp:939
static const long ID_STATICTEXT2
Definition: WxUtils.h:245
static const long ID_STATICTEXT11
Definition: WxUtils.h:241
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A custom control to display the bitmap and avoid flicker.
Definition: WxUtils.h:120
static const long ID_STATICTEXT10
Definition: WxUtils.h:239
static const long ID_TEXTCTRL7
Definition: WxUtils.h:237
static const long ID_TEXTCTRL4
Definition: WxUtils.h:249
static const long ID_STATICTEXT5
Definition: WxUtils.h:236
A panel to select the camera input from all the formats supported by MRPT.
Definition: WxUtils.h:154
void OnPaint(wxPaintEvent &ev)
Definition: WxUtils.cpp:172
static const long ID_CHECKBOX9
Definition: WxUtils.h:257
static const long ID_PANEL8
Definition: WxUtils.h:259
static const long ID_RADIOBOX1
Definition: WxUtils.h:243
static const long ID_PANEL4
Definition: WxUtils.h:228
static const long ID_PANEL7
Definition: WxUtils.h:246
void OnbtnBrowseRawlogClick(wxCommandEvent &event)
Definition: WxUtils.cpp:640
mrpt::img::CImage::Ptr wxImage2MRPTImagePtr(const wxImage &img)
Create a MRPT image from a wxImage.
Definition: WxUtils.cpp:105
CPanelCameraSelection(wxWindow *parent, wxWindowID id=wxID_ANY)
Definition: WxUtils.cpp:250
static const long ID_BUTTON7
Definition: WxUtils.h:231
static const long ID_STATICTEXT4
Definition: WxUtils.h:248
static const long ID_STATICTEXT7
Definition: WxUtils.h:224
void AssignImage(wxBitmap *img)
Assigns this image.
Definition: WxUtils.cpp:146
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:148
static const long ID_PANEL6
Definition: WxUtils.h:242
static const long ID_BUTTON8
Definition: WxUtils.h:235
static const long ID_STATICTEXT8
Definition: WxUtils.h:229



Page generated by Doxygen 1.8.14 for MRPT 2.0.0 Git: b38439d21 Tue Mar 31 19:58:06 2020 +0200 at miƩ abr 1 00:50:30 CEST 2020