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/opengl/opengl_fonts.h>
00032 #include <mrpt/utils/utils_defs.h>
00033 #include <mrpt/system/threads.h>
00034 #include <mrpt/config.h>
00035 #include <mrpt/synch.h>
00036 #include <mrpt/math/lightweight_geom_data.h>
00037
00038 #include <mrpt/gui/link_pragmas.h>
00039
00040 #include <queue>
00041
00042 #if MRPT_HAS_WXWIDGETS
00043
00044
00045
00046
00047
00048
00049
00050 #include <wx/sizer.h>
00051 #include <wx/statbmp.h>
00052 #include <wx/menu.h>
00053 #include <wx/toolbar.h>
00054 #include <wx/frame.h>
00055 #include <wx/timer.h>
00056 #include <wx/statusbr.h>
00057 #include <wx/msgdlg.h>
00058 #include <wx/artprov.h>
00059 #include <wx/bitmap.h>
00060 #include <wx/intl.h>
00061 #include <wx/image.h>
00062 #include <wx/string.h>
00063 #include <wx/msgdlg.h>
00064 #include <wx/filedlg.h>
00065 #include <wx/progdlg.h>
00066 #include <wx/imaglist.h>
00067 #include <wx/busyinfo.h>
00068 #include <wx/log.h>
00069 #include <wx/textdlg.h>
00070 #include <wx/dirdlg.h>
00071 #include <wx/colordlg.h>
00072 #include <wx/dcmemory.h>
00073 #include <wx/app.h>
00074 #include <wx/pen.h>
00075
00076
00077 #include <mrpt/otherlibs/mathplot/mathplot.h>
00078
00079 #if 0
00080
00081 #include <wx/chartpanel.h>
00082 #include <wx/bars/barplot.h>
00083
00084 #include <wx/axis/numberaxis.h>
00085 #include <wx/axis/categoryaxis.h>
00086 #include <wx/axis/dateaxis.h>
00087
00088 #include <wx/xy/xyhistorenderer.h>
00089 #include <wx/xy/xydataset.h>
00090 #include <wx/xy/xylinerenderer.h>
00091 #include <wx/xy/xyplot.h>
00092 #include <wx/xy/xysimpledataset.h>
00093
00094 #include <wx/xyz/xyzdataset.h>
00095 #include <wx/xyz/bubbleplot.h>
00096
00097 #include <wx/category/categorydataset.h>
00098 #include <wx/category/categorysimpledataset.h>
00099 #endif
00100
00101 #endif
00102
00103 namespace mrpt
00104 {
00105 namespace gui
00106 {
00107 using namespace mrpt::system;
00108
00109 class CDisplayWindow;
00110 class CDisplayWindow3D;
00111 class CDisplayWindowPlots;
00112 class CMyGLCanvas_DisplayWindow3D;
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 class GUI_IMPEXP WxSubsystem
00126 {
00127 #if MRPT_HAS_WXWIDGETS
00128
00129 public:
00130
00131
00132
00133 static void waitWxShutdownsIfNoWindows();
00134
00135
00136
00137
00138
00139
00140 static volatile bool isConsoleApp;
00141
00142
00143
00144 class CAuxWxSubsystemShutdowner
00145 {
00146 public:
00147 CAuxWxSubsystemShutdowner();
00148 ~CAuxWxSubsystemShutdowner();
00149 };
00150
00151 static CAuxWxSubsystemShutdowner global_wxsubsystem_shutdown;
00152
00153
00154
00155
00156 class CWXMainFrame: public wxFrame
00157 {
00158 friend void WxSubsystem::waitWxShutdownsIfNoWindows();
00159
00160 public:
00161 CWXMainFrame(wxWindow* parent,wxWindowID id = -1);
00162 virtual ~CWXMainFrame();
00163
00164
00165
00166
00167 static int notifyWindowCreation();
00168
00169
00170
00171
00172 static int notifyWindowDestruction();
00173
00174 static volatile CWXMainFrame* oneInstance;
00175
00176
00177 private:
00178
00179 static synch::CCriticalSection cs_windowCount;
00180 static int m_windowCount;
00181
00182 wxTimer *m_theTimer;
00183
00184 void OnTimerProcessRequests(wxTimerEvent& event);
00185
00186 DECLARE_EVENT_TABLE()
00187
00188 };
00189
00190 struct TWxMainThreadData
00191 {
00192 TWxMainThreadData();
00193
00194
00195
00196 TThreadHandle m_wxMainThreadId;
00197
00198
00199
00200 synch::CSemaphore m_semWxMainThreadReady;
00201
00202
00203
00204 synch::CCriticalSection m_csWxMainThreadId;
00205 };
00206
00207 static TWxMainThreadData& GetWxMainThreadInstance();
00208
00209
00210
00211
00212
00213 static void wxMainThread();
00214
00215
00216
00217 struct GUI_IMPEXP TRequestToWxMainThread
00218 {
00219 TRequestToWxMainThread() :
00220 source2D ( NULL ),
00221 source3D ( NULL ),
00222 sourcePlots ( NULL ),
00223 sourceCameraSelectDialog(false),
00224 voidPtr (NULL),
00225 voidPtr2 (NULL),
00226 x (400),
00227 y (400),
00228 boolVal (false)
00229 { }
00230
00231
00232 gui::CDisplayWindow *source2D;
00233
00234
00235 gui::CDisplayWindow3D *source3D;
00236
00237
00238 gui::CDisplayWindowPlots *sourcePlots;
00239
00240
00241 bool sourceCameraSelectDialog;
00242
00243
00244
00245 std::string str;
00246
00247
00248
00249 void *voidPtr, *voidPtr2;
00250 int x,y;
00251 bool boolVal;
00252 vector_float vector_x,vector_y;
00253 std::string plotName;
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
00287
00288
00289
00290
00291
00292 int OPCODE;
00293
00294 };
00295
00296
00297
00298 static TRequestToWxMainThread * popPendingWxRequest();
00299
00300
00301
00302 static void pushPendingWxRequest( TRequestToWxMainThread *data );
00303
00304
00305
00306 static bool createOneInstanceMainThread();
00307
00308
00309 static wxBitmap getMRPTDefaultIcon();
00310 private:
00311
00312
00313 static std::queue<TRequestToWxMainThread*> *listPendingWxRequests;
00314 static synch::CCriticalSection *cs_listPendingWxRequests;
00315 #endif
00316 };
00317
00318
00319 #if MRPT_HAS_WXWIDGETS
00320
00321
00322
00323 class CWindowDialog: public wxFrame
00324 {
00325 public:
00326
00327
00328 class wxMRPTImageControl : public wxPanel
00329 {
00330 protected:
00331 wxBitmap *m_img;
00332 mrpt::synch::CCriticalSection m_img_cs;
00333 CDisplayWindow *m_win2D;
00334
00335 wxPoint m_last_mouse_point, m_last_mouse_click;
00336 mrpt::synch::CCriticalSection m_mouse_cs;
00337
00338 public:
00339 wxMRPTImageControl( wxWindow *parent,wxWindowID winID,int x, int y, int width, int height);
00340 virtual ~wxMRPTImageControl();
00341
00342 void AssignImage(wxBitmap *img);
00343 void GetBitmap(wxBitmap &bmp);
00344
00345 void OnPaint(wxPaintEvent &ev);
00346 void OnMouseMove(wxMouseEvent& ev);
00347 void OnMouseClick(wxMouseEvent& ev);
00348 void OnChar(wxKeyEvent& ev);
00349
00350 void OnEraseBackground(wxEraseEvent &ev) { }
00351 };
00352
00353
00354
00355 public:
00356 CWindowDialog( CDisplayWindow *win2D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow]"), wxSize initialSize = wxDefaultSize );
00357 virtual ~CWindowDialog();
00358
00359 CDisplayWindow *m_win2D;
00360 WxSubsystem::CWXMainFrame *m_mainFrame;
00361
00362
00363 wxMRPTImageControl *m_image;
00364
00365 static const long ID_IMAGE_BITMAP;
00366
00367 private:
00368
00369 void OnClose (wxCloseEvent& event);
00370 void OnMenuClose(wxCommandEvent& event);
00371 void OnMenuAbout(wxCommandEvent& event);
00372 void OnMenuSave(wxCommandEvent& event);
00373 void OnChar(wxKeyEvent& event);
00374 void OnKeyDown(wxKeyEvent& event);
00375 void OnResize(wxSizeEvent& event);
00376
00377 DECLARE_EVENT_TABLE()
00378 };
00379
00380 class C3DWindowDialog: public wxFrame
00381 {
00382 friend class gui::CMyGLCanvas_DisplayWindow3D;
00383
00384 public:
00385
00386 C3DWindowDialog(CDisplayWindow3D *win3D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow3D]"), wxSize initialSize = wxDefaultSize );
00387 virtual ~C3DWindowDialog();
00388
00389 CDisplayWindow3D *m_win3D;
00390 WxSubsystem::CWXMainFrame *m_mainFrame;
00391
00392 CMyGLCanvas_DisplayWindow3D *m_canvas;
00393
00394 void clearTextMessages();
00395 void addTextMessage(
00396 const double x_frac,
00397 const double y_frac,
00398 const std::string &text,
00399 const mrpt::utils::TColorf &color,
00400 const size_t unique_index,
00401 const mrpt::opengl::TOpenGLFont font
00402 );
00403
00404 private:
00405
00406 void OnClose (wxCloseEvent& event);
00407 void OnMenuClose(wxCommandEvent& event);
00408 void OnMenuAbout(wxCommandEvent& event);
00409 void OnChar(wxKeyEvent& event);
00410 void OnResize(wxSizeEvent& event);
00411
00412 static const long ID_MENUITEM1;
00413 static const long ID_MENUITEM2;
00414
00415 DECLARE_EVENT_TABLE()
00416 };
00417
00418
00419
00420 class CWindowDialogPlots: public wxFrame
00421 {
00422 public:
00423 CWindowDialogPlots( CDisplayWindowPlots *winPlots, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindowPlots]"), wxSize initialSize = wxDefaultSize );
00424 virtual ~CWindowDialogPlots();
00425
00426 CDisplayWindowPlots *m_winPlots;
00427 WxSubsystem::CWXMainFrame *m_mainFrame;
00428
00429 mpWindow *m_plot;
00430
00431 static const long ID_PLOT;
00432 static const long ID_MENU_PRINT;
00433 bool m_firstSubmenu;
00434 std::map<long,long> m_ID2ID;
00435 mrpt::math::TPoint2D m_curCursorPos;
00436
00437 void OnMenuSelected(wxCommandEvent& ev);
00438 void OnMouseMove(wxMouseEvent& event);
00439
00440
00441
00442
00443 void plot(
00444 const vector_float &x,
00445 const vector_float &y,
00446 const std::string &lineFormat,
00447 const std::string &plotName);
00448
00449
00450
00451 void plotEllipse(
00452 const vector_float &x,
00453 const vector_float &y,
00454 const std::string &lineFormat,
00455 const std::string &plotName,
00456 bool showName = false);
00457
00458
00459
00460 void image(
00461 void *theWxImage,
00462 const float &x0,
00463 const float &y0,
00464 const float &w,
00465 const float &h,
00466 const std::string &plotName);
00467
00468 private:
00469
00470 void OnClose (wxCloseEvent& event);
00471 void OnMenuPrint(wxCommandEvent& event);
00472 void OnMenuClose(wxCommandEvent& event);
00473 void OnMenuAbout(wxCommandEvent& event);
00474 void OnChar(wxKeyEvent& event);
00475 void OnResize(wxSizeEvent& event);
00476
00477 DECLARE_EVENT_TABLE()
00478 };
00479
00480 #ifndef _U
00481 #ifdef wxUSE_UNICODE
00482 #define _U(x) wxString((x),wxConvUTF8)
00483 #define _UU(x,y) wxString((x),y)
00484 #else
00485 #define _U(x) (x)
00486 #define _UU(x,y) (x)
00487 #endif
00488 #endif
00489
00490
00491 #endif
00492
00493 }
00494 }
00495
00496 #endif