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
00036 #include <map>
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
00100 class WxSubsystem
00101 {
00102 #if MRPT_HAS_WXWIDGETS
00103
00104 public:
00105
00108 static void waitWxShutdownsIfNoWindows();
00109
00115 static bool isConsoleApp;
00116
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
00130 static int notifyWindowCreation();
00131
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
00155 static TThreadHandle m_wxMainThreadId;
00156
00159 static synch::CSemaphore m_semWxMainThreadReady;
00160
00163 static synch::CCriticalSection m_csWxMainThreadId;
00164
00168 static void wxMainThread(void *);
00169
00172 struct MRPTDLLIMPEXP TRequestToWxMainThread
00173 {
00174 TRequestToWxMainThread()
00175 {
00176 source2D=NULL;
00177 source3D=NULL;
00178 sourcePlots=NULL;
00179 }
00180
00183 gui::CDisplayWindow *source2D;
00184
00187 gui::CDisplayWindow3D *source3D;
00188
00191 gui::CDisplayWindowPlots *sourcePlots;
00192
00195 std::string str;
00196
00199 void *voidPtr, *voidPtr2;
00200 int x,y;
00201 bool boolVal;
00202 vector_float vector_x,vector_y;
00203 std::string plotName;
00204
00236 int OPCODE;
00237
00238 };
00239
00242 static TRequestToWxMainThread * popPendingWxRequest();
00243
00246 static void pushPendingWxRequest( TRequestToWxMainThread *data );
00247
00250 static bool createOneInstanceMainThread();
00251
00252 private:
00255 static std::queue<TRequestToWxMainThread*> listPendingWxRequests;
00256 static synch::CCriticalSection cs_listPendingWxRequests;
00257 #endif
00258 };
00259
00260
00261 #if MRPT_HAS_WXWIDGETS
00262
00265 class CWindowDialog: public wxFrame
00266 {
00267 public:
00268 CWindowDialog( CDisplayWindow *win2D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow]"));
00269 virtual ~CWindowDialog();
00270
00271 CDisplayWindow *m_win2D;
00272 WxSubsystem::CWXMainFrame *m_mainFrame;
00273
00274 wxStaticBitmap *m_image;
00275
00276 static const long ID_IMAGE_BITMAP;
00277
00278 private:
00279
00280 void OnClose (wxCloseEvent& event);
00281 void OnMenuClose(wxCommandEvent& event);
00282 void OnMenuAbout(wxCommandEvent& event);
00283 void OnMenuSave(wxCommandEvent& event);
00284 void OnChar(wxKeyEvent& event);
00285
00286 DECLARE_EVENT_TABLE()
00287 };
00288
00289 class C3DWindowDialog: public wxFrame
00290 {
00291 friend class gui::CMyGLCanvas_DisplayWindow3D;
00292
00293 public:
00294
00295 C3DWindowDialog(CDisplayWindow3D *win3D, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindow3D]"));
00296 virtual ~C3DWindowDialog();
00297
00298 CDisplayWindow3D *m_win3D;
00299 WxSubsystem::CWXMainFrame *m_mainFrame;
00300
00301 CMyGLCanvas_DisplayWindow3D *m_canvas;
00302 private:
00303
00304 void OnClose (wxCloseEvent& event);
00305 void OnMenuClose(wxCommandEvent& event);
00306 void OnMenuAbout(wxCommandEvent& event);
00307
00308 static const long ID_MENUITEM1;
00309 static const long ID_MENUITEM2;
00310
00311 DECLARE_EVENT_TABLE()
00312 };
00313
00316 class CWindowDialogPlots: public wxFrame
00317 {
00318 public:
00319 CWindowDialogPlots( CDisplayWindowPlots *winPlots, WxSubsystem::CWXMainFrame* parent,wxWindowID id = -1, const std::string &caption = std::string("[MRPT-CDisplayWindowPlots]"), wxSize initialSize = wxDefaultSize );
00320 virtual ~CWindowDialogPlots();
00321
00322 CDisplayWindowPlots *m_winPlots;
00323 WxSubsystem::CWXMainFrame *m_mainFrame;
00324
00325 mpWindow *m_plot;
00326 static const long ID_PLOT;
00327
00330 void plot(
00331 const vector_float &x,
00332 const vector_float &y,
00333 const std::string &lineFormat,
00334 const std::string &plotName);
00335
00338 void plotEllipse(
00339 const vector_float &x,
00340 const vector_float &y,
00341 const std::string &lineFormat,
00342 const std::string &plotName);
00343
00346 void image(
00347 void *theWxImage,
00348 const float &x0,
00349 const float &y0,
00350 const float &w,
00351 const float &h,
00352 const std::string &plotName);
00353
00354 private:
00355
00356 void OnClose (wxCloseEvent& event);
00357 void OnMenuClose(wxCommandEvent& event);
00358 void OnMenuAbout(wxCommandEvent& event);
00359 void OnChar(wxKeyEvent& event);
00360
00361 DECLARE_EVENT_TABLE()
00362 };
00363
00364 #ifdef wxUSE_UNICODE
00365 #define _U(x) wxString((x),wxConvUTF8)
00366 #define _UU(x,y) wxString((x),y)
00367 #else
00368 #define _U(x) (x)
00369 #define _UU(x,y) (x)
00370 #endif
00371
00372
00373 #endif
00374
00375 }
00376 }
00377
00378 #endif