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