00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef MRPT_WX_SUBSYSTEM_H
00029 #define MRPT_WX_SUBSYSTEM_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/system/os.h>
00033 #include <mrpt/config.h>
00034 #include <mrpt/synch.h>
00035 #include <mrpt/math/lightweight_geom_data.h>
00036
00037 #include <queue>
00038
00039 #if MRPT_HAS_WXWIDGETS
00040
00041
00042
00043
00044
00045
00046
00047 #include <wx/sizer.h>
00048 #include <wx/statbmp.h>
00049 #include <wx/menu.h>
00050 #include <wx/toolbar.h>
00051 #include <wx/frame.h>
00052 #include <wx/timer.h>
00053 #include <wx/statusbr.h>
00054 #include <wx/msgdlg.h>
00055 #include <wx/artprov.h>
00056 #include <wx/bitmap.h>
00057 #include <wx/intl.h>
00058 #include <wx/image.h>
00059 #include <wx/string.h>
00060 #include <wx/msgdlg.h>
00061 #include <wx/filedlg.h>
00062 #include <wx/progdlg.h>
00063 #include <wx/imaglist.h>
00064 #include <wx/busyinfo.h>
00065 #include <wx/log.h>
00066 #include <wx/textdlg.h>
00067 #include <wx/dirdlg.h>
00068 #include <wx/colordlg.h>
00069 #include <wx/dcmemory.h>
00070 #include <wx/app.h>
00071 #include <wx/pen.h>
00072
00073
00074 #include <mrpt/otherlibs/mathplot/mathplot.h>
00075
00076 #endif
00077
00078 namespace mrpt
00079 {
00080 namespace gui
00081 {
00082 using namespace mrpt::system;
00083
00084 class CDisplayWindow;
00085 class CDisplayWindow3D;
00086 class CDisplayWindowPlots;
00087 class CMyGLCanvas_DisplayWindow3D;
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 class WxSubsystem
00101 {
00102 #if MRPT_HAS_WXWIDGETS
00103
00104 public:
00105
00106
00107
00108 static void waitWxShutdownsIfNoWindows();
00109
00110
00111
00112
00113
00114
00115 static bool isConsoleApp;
00116
00117
00118
00119 class CWXMainFrame: public wxFrame
00120 {
00121 friend void WxSubsystem::waitWxShutdownsIfNoWindows();
00122
00123 public:
00124 CWXMainFrame(wxWindow* parent,wxWindowID id = -1);
00125 virtual ~CWXMainFrame();
00126
00127
00128
00129
00130 static int notifyWindowCreation();
00131
00132
00133
00134
00135 static int notifyWindowDestruction();
00136
00137 static CWXMainFrame* oneInstance;
00138
00139
00140 private:
00141
00142 static synch::CCriticalSection cs_windowCount;
00143 static int m_windowCount;
00144
00145 wxTimer *m_theTimer;
00146
00147 void OnTimerProcessRequests(wxTimerEvent& event);
00148
00149 DECLARE_EVENT_TABLE()
00150
00151 };
00152
00153
00154
00155 static TThreadHandle m_wxMainThreadId;
00156
00157
00158
00159 static synch::CSemaphore m_semWxMainThreadReady;
00160
00161
00162
00163 static synch::CCriticalSection m_csWxMainThreadId;
00164
00165
00166
00167
00168 static void wxMainThread(void*);
00169
00170
00171
00172 struct MRPTDLLIMPEXP TRequestToWxMainThread
00173 {
00174 TRequestToWxMainThread()
00175 {
00176 source2D=NULL;
00177 source3D=NULL;
00178 sourcePlots=NULL;
00179 }
00180
00181
00182
00183 gui::CDisplayWindow *source2D;
00184
00185
00186
00187 gui::CDisplayWindow3D *source3D;
00188
00189
00190
00191 gui::CDisplayWindowPlots *sourcePlots;
00192
00193
00194
00195 std::string str;
00196
00197
00198
00199 void *voidPtr, *voidPtr2;
00200 int x,y;
00201 bool boolVal;
00202 vector_float vector_x,vector_y;
00203 std::string plotName;
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 int OPCODE;
00239
00240 };
00241
00242
00243
00244 static TRequestToWxMainThread * popPendingWxRequest();
00245
00246
00247
00248 static void pushPendingWxRequest( TRequestToWxMainThread *data );
00249
00250
00251
00252 static bool createOneInstanceMainThread();
00253
00254 private:
00255
00256
00257 static std::queue<TRequestToWxMainThread*> listPendingWxRequests;
00258 static synch::CCriticalSection cs_listPendingWxRequests;
00259 #endif
00260 };
00261
00262
00263 #if MRPT_HAS_WXWIDGETS
00264
00265
00266
00267 class CWindowDialog: public wxFrame
00268 {
00269 public:
00270
00271
00272 class wxMRPTImageControl : public wxPanel
00273 {
00274 protected:
00275 wxBitmap *m_img;
00276 mrpt::synch::CCriticalSection m_img_cs;
00277
00278 wxPoint m_last_mouse_point, m_last_mouse_click;
00279 mrpt::synch::CCriticalSection m_mouse_cs;
00280
00281 public:
00282 wxMRPTImageControl( wxWindow *parent,wxWindowID winID,int x, int y, int width, int height);
00283 virtual ~wxMRPTImageControl();
00284
00285 void AssignImage(wxBitmap *img);
00286 void GetBitmap(wxBitmap &bmp);
00287
00288 void OnPaint(wxPaintEvent &ev);
00289 void OnMouseMove(wxMouseEvent& ev);
00290 void OnMouseClick(wxMouseEvent& ev);
00291 void OnChar(wxKeyEvent& event);
00292
00293 void OnEraseBackground(wxEraseEvent &ev) { }
00294 };
00295
00296
00297
00298 public:
00299 CWindowDialog( CDisplayWindow *win2D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow]"));
00300 virtual ~CWindowDialog();
00301
00302 CDisplayWindow *m_win2D;
00303 WxSubsystem::CWXMainFrame *m_mainFrame;
00304
00305
00306 wxMRPTImageControl *m_image;
00307
00308 static const long ID_IMAGE_BITMAP;
00309
00310 private:
00311
00312 void OnClose (wxCloseEvent& event);
00313 void OnMenuClose(wxCommandEvent& event);
00314 void OnMenuAbout(wxCommandEvent& event);
00315 void OnMenuSave(wxCommandEvent& event);
00316 void OnChar(wxKeyEvent& event);
00317
00318 DECLARE_EVENT_TABLE()
00319 };
00320
00321 class C3DWindowDialog: public wxFrame
00322 {
00323 friend class gui::CMyGLCanvas_DisplayWindow3D;
00324
00325 public:
00326
00327 C3DWindowDialog(CDisplayWindow3D *win3D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow3D]"));
00328 virtual ~C3DWindowDialog();
00329
00330 CDisplayWindow3D *m_win3D;
00331 WxSubsystem::CWXMainFrame *m_mainFrame;
00332
00333 CMyGLCanvas_DisplayWindow3D *m_canvas;
00334 private:
00335
00336 void OnClose (wxCloseEvent& event);
00337 void OnMenuClose(wxCommandEvent& event);
00338 void OnMenuAbout(wxCommandEvent& event);
00339 void OnChar(wxKeyEvent& event);
00340
00341 static const long ID_MENUITEM1;
00342 static const long ID_MENUITEM2;
00343
00344 DECLARE_EVENT_TABLE()
00345 };
00346
00347
00348
00349 class CWindowDialogPlots: public wxFrame
00350 {
00351 public:
00352 CWindowDialogPlots( CDisplayWindowPlots *winPlots, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindowPlots]"), wxSize initialSize = wxDefaultSize );
00353 virtual ~CWindowDialogPlots();
00354
00355 CDisplayWindowPlots *m_winPlots;
00356 WxSubsystem::CWXMainFrame *m_mainFrame;
00357
00358 mpWindow *m_plot;
00359 static const long ID_PLOT;
00360 bool m_firstSubmenu;
00361 std::map<long,long> m_ID2ID;
00362 mrpt::math::TPoint2D m_curCursorPos;
00363
00364 void OnMenuSelected(wxCommandEvent& ev);
00365 void OnMouseMove(wxMouseEvent& event);
00366
00367
00368
00369
00370 void plot(
00371 const vector_float &x,
00372 const vector_float &y,
00373 const std::string &lineFormat,
00374 const std::string &plotName);
00375
00376
00377
00378 void plotEllipse(
00379 const vector_float &x,
00380 const vector_float &y,
00381 const std::string &lineFormat,
00382 const std::string &plotName,
00383 bool showName = false);
00384
00385
00386
00387 void image(
00388 void *theWxImage,
00389 const float &x0,
00390 const float &y0,
00391 const float &w,
00392 const float &h,
00393 const std::string &plotName);
00394
00395 private:
00396
00397 void OnClose (wxCloseEvent& event);
00398 void OnMenuClose(wxCommandEvent& event);
00399 void OnMenuAbout(wxCommandEvent& event);
00400 void OnChar(wxKeyEvent& event);
00401
00402 DECLARE_EVENT_TABLE()
00403 };
00404
00405 #ifdef wxUSE_UNICODE
00406 #define _U(x) wxString((x),wxConvUTF8)
00407 #define _UU(x,y) wxString((x),y)
00408 #else
00409 #define _U(x) (x)
00410 #define _UU(x,y) (x)
00411 #endif
00412
00413
00414 #endif
00415
00416 }
00417 }
00418
00419 #endif