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/threads.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 #if 0
00077
00078 #include <wx/chartpanel.h>
00079 #include <wx/bars/barplot.h>
00080
00081 #include <wx/axis/numberaxis.h>
00082 #include <wx/axis/categoryaxis.h>
00083 #include <wx/axis/dateaxis.h>
00084
00085 #include <wx/xy/xyhistorenderer.h>
00086 #include <wx/xy/xydataset.h>
00087 #include <wx/xy/xylinerenderer.h>
00088 #include <wx/xy/xyplot.h>
00089 #include <wx/xy/xysimpledataset.h>
00090
00091 #include <wx/xyz/xyzdataset.h>
00092 #include <wx/xyz/bubbleplot.h>
00093
00094 #include <wx/category/categorydataset.h>
00095 #include <wx/category/categorysimpledataset.h>
00096 #endif
00097
00098 #endif
00099
00100 namespace mrpt
00101 {
00102 namespace gui
00103 {
00104 using namespace mrpt::system;
00105
00106 class CDisplayWindow;
00107 class CDisplayWindow3D;
00108 class CDisplayWindowPlots;
00109 class CMyGLCanvas_DisplayWindow3D;
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 class MRPTDLLIMPEXP WxSubsystem
00123 {
00124 #if MRPT_HAS_WXWIDGETS
00125
00126 public:
00127
00128
00129
00130 static void waitWxShutdownsIfNoWindows();
00131
00132
00133
00134
00135
00136
00137 static volatile bool isConsoleApp;
00138
00139
00140
00141 class CWXMainFrame: public wxFrame
00142 {
00143 friend void WxSubsystem::waitWxShutdownsIfNoWindows();
00144
00145 public:
00146 CWXMainFrame(wxWindow* parent,wxWindowID id = -1);
00147 virtual ~CWXMainFrame();
00148
00149
00150
00151
00152 static int notifyWindowCreation();
00153
00154
00155
00156
00157 static int notifyWindowDestruction();
00158
00159 static volatile CWXMainFrame* oneInstance;
00160
00161
00162 private:
00163
00164 static synch::CCriticalSection cs_windowCount;
00165 static int m_windowCount;
00166
00167 wxTimer *m_theTimer;
00168
00169 void OnTimerProcessRequests(wxTimerEvent& event);
00170
00171 DECLARE_EVENT_TABLE()
00172
00173 };
00174
00175 struct TWxMainThreadData
00176 {
00177 TWxMainThreadData();
00178
00179
00180
00181 TThreadHandle m_wxMainThreadId;
00182
00183
00184
00185 synch::CSemaphore m_semWxMainThreadReady;
00186
00187
00188
00189 synch::CCriticalSection m_csWxMainThreadId;
00190 };
00191
00192 static TWxMainThreadData& GetWxMainThreadInstance();
00193
00194
00195
00196
00197
00198 static void wxMainThread();
00199
00200
00201
00202 struct MRPTDLLIMPEXP TRequestToWxMainThread
00203 {
00204 TRequestToWxMainThread() :
00205 source2D ( NULL ),
00206 source3D ( NULL ),
00207 sourcePlots ( NULL ),
00208 sourceCameraSelectDialog(false),
00209 voidPtr (NULL),
00210 voidPtr2 (NULL),
00211 x (400),
00212 y (400),
00213 boolVal (false)
00214 { }
00215
00216
00217 gui::CDisplayWindow *source2D;
00218
00219
00220 gui::CDisplayWindow3D *source3D;
00221
00222
00223 gui::CDisplayWindowPlots *sourcePlots;
00224
00225
00226 bool sourceCameraSelectDialog;
00227
00228
00229
00230 std::string str;
00231
00232
00233
00234 void *voidPtr, *voidPtr2;
00235 int x,y;
00236 bool boolVal;
00237 vector_float vector_x,vector_y;
00238 std::string plotName;
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 int OPCODE;
00275
00276 };
00277
00278
00279
00280 static TRequestToWxMainThread * popPendingWxRequest();
00281
00282
00283
00284 static void pushPendingWxRequest( TRequestToWxMainThread *data );
00285
00286
00287
00288 static bool createOneInstanceMainThread();
00289
00290 private:
00291
00292
00293 static std::queue<TRequestToWxMainThread*> listPendingWxRequests;
00294 static synch::CCriticalSection cs_listPendingWxRequests;
00295 #endif
00296 };
00297
00298
00299 #if MRPT_HAS_WXWIDGETS
00300
00301
00302
00303 class CWindowDialog: public wxFrame
00304 {
00305 public:
00306
00307
00308 class wxMRPTImageControl : public wxPanel
00309 {
00310 protected:
00311 wxBitmap *m_img;
00312 mrpt::synch::CCriticalSection m_img_cs;
00313 CDisplayWindow *m_win2D;
00314
00315 wxPoint m_last_mouse_point, m_last_mouse_click;
00316 mrpt::synch::CCriticalSection m_mouse_cs;
00317
00318 public:
00319 wxMRPTImageControl( wxWindow *parent,wxWindowID winID,int x, int y, int width, int height);
00320 virtual ~wxMRPTImageControl();
00321
00322 void AssignImage(wxBitmap *img);
00323 void GetBitmap(wxBitmap &bmp);
00324
00325 void OnPaint(wxPaintEvent &ev);
00326 void OnMouseMove(wxMouseEvent& ev);
00327 void OnMouseClick(wxMouseEvent& ev);
00328
00329 void OnEraseBackground(wxEraseEvent &ev) { }
00330 };
00331
00332
00333
00334 public:
00335 CWindowDialog( CDisplayWindow *win2D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow]"), wxSize initialSize = wxDefaultSize );
00336 virtual ~CWindowDialog();
00337
00338 CDisplayWindow *m_win2D;
00339 WxSubsystem::CWXMainFrame *m_mainFrame;
00340
00341
00342 wxMRPTImageControl *m_image;
00343
00344 static const long ID_IMAGE_BITMAP;
00345
00346 private:
00347
00348 void OnClose (wxCloseEvent& event);
00349 void OnMenuClose(wxCommandEvent& event);
00350 void OnMenuAbout(wxCommandEvent& event);
00351 void OnMenuSave(wxCommandEvent& event);
00352 void OnChar(wxKeyEvent& event);
00353 void OnKeyDown(wxKeyEvent& event);
00354
00355 DECLARE_EVENT_TABLE()
00356 };
00357
00358 class C3DWindowDialog: public wxFrame
00359 {
00360 friend class gui::CMyGLCanvas_DisplayWindow3D;
00361
00362 public:
00363
00364 C3DWindowDialog(CDisplayWindow3D *win3D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow3D]"), wxSize initialSize = wxDefaultSize );
00365 virtual ~C3DWindowDialog();
00366
00367 CDisplayWindow3D *m_win3D;
00368 WxSubsystem::CWXMainFrame *m_mainFrame;
00369
00370 CMyGLCanvas_DisplayWindow3D *m_canvas;
00371 private:
00372
00373 void OnClose (wxCloseEvent& event);
00374 void OnMenuClose(wxCommandEvent& event);
00375 void OnMenuAbout(wxCommandEvent& event);
00376 void OnChar(wxKeyEvent& event);
00377
00378 static const long ID_MENUITEM1;
00379 static const long ID_MENUITEM2;
00380
00381 DECLARE_EVENT_TABLE()
00382 };
00383
00384
00385
00386 class CWindowDialogPlots: public wxFrame
00387 {
00388 public:
00389 CWindowDialogPlots( CDisplayWindowPlots *winPlots, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindowPlots]"), wxSize initialSize = wxDefaultSize );
00390 virtual ~CWindowDialogPlots();
00391
00392 CDisplayWindowPlots *m_winPlots;
00393 WxSubsystem::CWXMainFrame *m_mainFrame;
00394
00395 mpWindow *m_plot;
00396
00397 static const long ID_PLOT;
00398 bool m_firstSubmenu;
00399 std::map<long,long> m_ID2ID;
00400 mrpt::math::TPoint2D m_curCursorPos;
00401
00402 void OnMenuSelected(wxCommandEvent& ev);
00403 void OnMouseMove(wxMouseEvent& event);
00404
00405
00406
00407
00408 void plot(
00409 const vector_float &x,
00410 const vector_float &y,
00411 const std::string &lineFormat,
00412 const std::string &plotName);
00413
00414
00415
00416 void plotEllipse(
00417 const vector_float &x,
00418 const vector_float &y,
00419 const std::string &lineFormat,
00420 const std::string &plotName,
00421 bool showName = false);
00422
00423
00424
00425 void image(
00426 void *theWxImage,
00427 const float &x0,
00428 const float &y0,
00429 const float &w,
00430 const float &h,
00431 const std::string &plotName);
00432
00433 private:
00434
00435 void OnClose (wxCloseEvent& event);
00436 void OnMenuClose(wxCommandEvent& event);
00437 void OnMenuAbout(wxCommandEvent& event);
00438 void OnChar(wxKeyEvent& event);
00439
00440 DECLARE_EVENT_TABLE()
00441 };
00442
00443 #ifndef _U
00444 #ifdef wxUSE_UNICODE
00445 #define _U(x) wxString((x),wxConvUTF8)
00446 #define _UU(x,y) wxString((x),y)
00447 #else
00448 #define _U(x) (x)
00449 #define _UU(x,y) (x)
00450 #endif
00451 #endif
00452
00453
00454 #endif
00455
00456 }
00457 }
00458
00459 #endif