12 #include <mrpt/config.h> 35 #if MRPT_HAS_WXWIDGETS 64 #ifdef WXSUBSYSTEM_VERBOSE 65 printf(
"[~CAuxWxSubsystemShutdowner] Sending 999...\n");
80 #ifdef WXSUBSYSTEM_VERBOSE 81 printf(
"[~CAuxWxSubsystemShutdowner] Deleting static objects.\n");
101 CDialogAskUserForCamera() : wxDialog(NULL,wxID_ANY,wxT(
"Select image source"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, wxDialogNameStr)
103 wxFlexGridSizer *f1 =
new wxFlexGridSizer(2, 1, 0, 0);
105 f1->Add(panel, 1, wxALL|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
107 wxFlexGridSizer *f2 =
new wxFlexGridSizer(1, 2, 0, 0);
108 wxButton *btnOk =
new wxButton(
this,ID_BTN_OK,wxT(
"Ok"), wxDefaultPosition, wxDefaultSize);
109 wxButton *btnCancel =
new wxButton(
this,ID_BTN_CANCEL,wxT(
"Cancel"), wxDefaultPosition, wxDefaultSize);
110 f1->Add(f2, 1, wxALL|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
112 f2->Add(btnOk, 1, wxALL|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
113 f2->Add(btnCancel, 1, wxALL|wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
135 EndModal(wxID_CANCEL);
159 _(
"MRPT-dummy frame window"),
167 cerr <<
"[CWXMainFrame] More than one instance running!" << endl;
177 m_theTimer->Start( 10,
true );
182 #ifdef WXSUBSYSTEM_VERBOSE 183 cout <<
"[CWXMainFrame] Destructor." << endl;
190 while (NULL!=(msg= popPendingWxRequest()))
198 return ++m_windowCount;
206 ret = --m_windowCount;
214 #ifdef WXSHUTDOWN_DO_IT_CLEAN 219 #ifdef WXSUBSYSTEM_VERBOSE 220 cout <<
"[CWXMainFrame::notifyWindowDestruction] numWindows=0. me->Close() called." << endl;
232 if (!cs_listPendingWxRequests)
235 listPendingWxRequests =
new std::queue<TRequestToWxMainThread*>;
241 if (listPendingWxRequests->empty())
245 listPendingWxRequests->pop();
256 #ifdef WXSUBSYSTEM_VERBOSE 257 cout <<
"[WxSubsystem::pushPendingWxRequest] IGNORING request since app seems already closed.\n";
263 if (!cs_listPendingWxRequests)
266 listPendingWxRequests =
new std::queue<TRequestToWxMainThread*>;
270 listPendingWxRequests->push(
data );
279 bool app_closed =
false;
284 #ifdef WXSUBSYSTEM_VERBOSE 285 cout <<
"[OnTimerProcessRequests] Entering" << endl;
289 while ( NULL != (msg = popPendingWxRequest() ) )
301 * ((
void**)msg->
voidPtr) = (
void*)wnd;
320 if (wnd->
m_image->GetSize().GetX() !=
img->GetWidth() &&
321 wnd->
m_image->GetSize().GetY() !=
img->GetHeight() )
324 wnd->
m_image->SetMinSize( wxSize(
img->GetWidth(),
img->GetHeight() ));
325 wnd->
m_image->SetMaxSize( wxSize(
img->GetWidth(),
img->GetHeight() ));
339 wnd->SetSize( msg->
x, msg->
y, wxDefaultCoord, wxDefaultCoord );
348 wnd->SetClientSize( msg->
x, msg->
y );
357 wnd->SetTitle(
_U(msg->
str.c_str()) );
380 * ((
void**)msg->
voidPtr) = (
void*)wnd;
394 wnd->SetSize( msg->
x, msg->
y, wxDefaultCoord, wxDefaultCoord );
403 wnd->SetClientSize( msg->
x, msg->
y );
412 wnd->SetTitle(
_U(msg->
str.c_str()) );
496 * ((
void**)msg->
voidPtr) = (
void*)wnd;
510 wnd->SetSize( msg->
x, msg->
y, wxDefaultCoord, wxDefaultCoord );
519 wnd->SetClientSize( msg->
x, msg->
y );
528 wnd->SetTitle(
_U(msg->
str.c_str()) );
582 wnd->
m_plot->DelAllLayers(
true,
true);
583 wnd->
m_plot->AddLayer(
new mpScaleX() );
584 wnd->
m_plot->AddLayer(
new mpScaleY() );
632 const long MENUITEM_ID = wxNewId();
636 wxMenu *popupMnu = wnd->
m_plot->GetPopupMenu();
640 popupMnu->InsertSeparator(0);
642 wxMenuItem *mnuTarget =
new wxMenuItem(popupMnu, MENUITEM_ID,
_U(msg->
plotName.c_str()), wxEmptyString, wxITEM_NORMAL);
643 popupMnu->Insert(0,mnuTarget);
675 const bool wasOk = (dlg->ShowModal() == wxID_OK);
694 #ifdef WXSUBSYSTEM_VERBOSE 695 cout <<
"[WxSubsystem:999] Shutdown" << endl;
700 #ifdef WXSUBSYSTEM_VERBOSE 701 cout <<
"[WxSubsystem:999] Shutdown done" << endl;
717 m_theTimer->Start( 10,
true );
730 " ..... ..... ......... ",
731 " .... .... ... .... ",
732 " ..... .... ... ... ",
733 " . ... . ... ... ... ",
734 " . ... . ... ... ... ",
735 " . ... . ... ... ... ",
736 " . ... . ... ........ ",
737 " . ..... ... ... .... ",
738 " . ... ... ... .... ",
739 " . ... ... ... .... ",
740 " . .. ... ... .... ",
741 " ... . ..... ..... ..... ",
744 " ........ ........... ",
745 " ... .... .. ... .. ",
763 #ifdef MRPT_OS_WINDOWS 764 const wxSize iconsSize(::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
777 virtual bool OnInit();
778 virtual int OnExit();
786 wxSetlocale(LC_NUMERIC, wxString(wxT(
"C")) );
788 wxInitAllImageHandlers();
806 #ifdef WXSUBSYSTEM_VERBOSE 807 cout <<
"[wxApp::OnExit] wxApplication OnExit called." << endl;
823 #ifndef WXSHUTDOWN_DO_IT_CLEAN 825 #ifdef WXSUBSYSTEM_VERBOSE 826 cout <<
"[WxSubsystem::waitWxShutdownsIfNoWindows] Doing a quick sleep() and returning.\n";
836 nOpenWnds = CWXMainFrame::m_windowCount;
841 #ifdef WXSUBSYSTEM_VERBOSE 842 cout <<
"[WxSubsystem::waitWxShutdownsIfNoWindows] Waiting for WxWidgets thread to shutdown...\n";
854 while (!done && --maxTimeout >0)
864 cerr <<
"[WxSubsystem::waitWxShutdownsIfNoWindows] Timeout waiting for WxWidgets thread to shutdown!" << endl;
872 wxAppConsole::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE,
"your program");
885 if ( !wxEntryStart(argc, argv) )
889 delete wxLog::SetActiveTarget(NULL);
899 if ( ! wxTheApp->CallOnInit() )
903 int ret = wxTheApp->OnRun();
916 wxTheApp->OnUnhandledException();
935 static const char *dummy_prog_name =
"./MRPT";
936 char *argv[2] = {
const_cast<char*
>(dummy_prog_name), NULL };
938 #ifdef WXSUBSYSTEM_VERBOSE 939 cout <<
"[wxMainThread] Starting..." << endl;
943 wxAppConsole *app_gui = wxApp::GetInstance();
948 #ifdef WXSUBSYSTEM_VERBOSE 949 cout <<
"[wxMainThread] I am in a console app" << endl;
954 wxApp::SetInitializerFunction( (wxAppInitializerFunction)
mrpt_wxCreateApp );
957 #ifdef WXSUBSYSTEM_VERBOSE 958 cout <<
"[wxMainThread] Finished" << endl;
968 #ifdef WXSUBSYSTEM_VERBOSE 969 cout <<
"[wxMainThread] I am in a GUI app" << endl;
971 wxWindow *topWin =
static_cast<wxApp*
>(app_gui)->GetTopWindow();
977 #ifdef WXSUBSYSTEM_VERBOSE 978 cout <<
"[wxMainThread] Signaling semaphore." << endl;
992 static bool first_creat =
true;
999 m_semWxMainThreadReady(0,1),
1000 m_csWxMainThreadId(
"csWxMainThreadId")
1013 wxAppConsole *app_con = wxApp::GetInstance();
1022 wxWindow *topWin =
static_cast<wxApp*
>(app_con)->GetTopWindow();
1036 #ifdef WXSUBSYSTEM_VERBOSE 1037 printf(
"[WxSubsystem::createOneInstanceMainThread] Launching wxMainThread() thread...\n");
1050 const char *envVal = getenv(
"MRPT_WXSUBSYS_TIMEOUT_MS");
1052 maxTimeout = atoi(envVal);
1056 cerr <<
"[WxSubsystem::createOneInstanceMainThread] Timeout waiting wxApplication to start up!" << endl;
1066 #endif // MRPT_HAS_WXWIDGETS An auxiliary global object used just to launch a final request to the wxSubsystem for shutdown: ...
static void pushPendingWxRequest(TRequestToWxMainThread *data)
Thread-safe method to insert a new pending request (The memory must be dinamically allocated with "ne...
void * voidPtr
Parameters, depending on OPCODE.
This class provides simple critical sections functionality.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
void writeConfigFromVideoSourcePanel(const std::string §, mrpt::utils::CConfigFileBase *cfg) const
static const long ID_BTN_CANCEL
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
static TRequestToWxMainThread * popPendingWxRequest()
Thread-safe method to return the next pending request, or NULL if there is none (After usage...
mrpt::gui::CDisplayWindow3D * source3D
Only one of source* can be non-NULL, indicating the class that generated the request.
The data structure for each inter-thread request:
~CAuxWxSubsystemShutdowner()
static int notifyWindowCreation()
Atomically increments the number of windows created with the main frame as parent.
void AssignImage(wxBitmap *img)
Assigns this image. This object has the ownship of the image and will delete it when appropriate...
void OnTimerProcessRequests(wxTimerEvent &event)
This method processes the pending requests from the main MRPT application thread. ...
mrpt::gui::CPanelCameraSelection * panel
The wx dialog for gui::CDisplayWindowPlots.
mrpt::synch::CSemaphore m_semWxMainThreadReady
This is signaled when wxMainThread is ready.
static wxBitmap getMRPTDefaultIcon()
bool waitForSignal(unsigned int timeout_ms=0)
Blocks until the count of the semaphore to be non-zero.
const char * mrpt_default_icon_xpm[]
CDialogAskUserForCamera()
static volatile CWXMainFrame * oneInstance
static TWxMainThreadData & GetWxMainThreadInstance()
void OnBtnOk(wxCommandEvent &event)
int mrpt_wxEntryReal(int argc, char **argv)
TThreadHandle createThread(void(*func)(T), T param)
Creates a new thread from a function (or static method) with one generic parameter.
int OPCODE
Valid codes are: For CDisplayWindow:
const long ID_TIMER_WX_PROCESS_REQUESTS
static std::queue< TRequestToWxMainThread * > * listPendingWxRequests
Do not access directly to this, use the thread-safe functions.
wxMRPTImageControl * m_image
static const long ID_BTN_OK
void leave() const MRPT_OVERRIDE
Leave.
void OnMenuSelected(wxCommandEvent &ev)
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
static synch::CCriticalSection * cs_listPendingWxRequests
wxAppConsole * mrpt_wxCreateApp()
void addTextMessage(const double x_frac, const double y_frac, const std::string &text, const mrpt::utils::TColorf &color, const size_t unique_index, const mrpt::opengl::TOpenGLFont font)
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
TOpenGLFontStyle
Different style for vectorized font rendering.
void * getWxObject()
Read-only access to the wxDialog object.
void enter() const MRPT_OVERRIDE
Enter.
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName)
Redirected from CDisplayWindowPlots::plot.
mrpt::math::CVectorFloat vector_y
The main frame of the wxWidgets application.
void release(unsigned int increaseCount=1)
Increments the count of the semaphore by a given amount.
The wx dialog for gui::CDisplayWindow.
void OnBtnCancel(wxCommandEvent &event)
bool sourceCameraSelectDialog
Only one of source* can be non-NULL, indicating the class that generated the request.
bool isClear() const
Returns true if the handle is uninitialized.
This namespace provides multitask, synchronization utilities.
static void wxMainThread()
This will be the "MAIN" of wxWidgets: It starts an application object and does not end until all the ...
void clear()
Mark the handle as invalid.
virtual ~CDialogAskUserForCamera()
void image(void *theWxImage, const float &x0, const float &y0, const float &w, const float &h, const std::string &plotName)
Redirected from CDisplayWindowPlots::image.
static void waitWxShutdownsIfNoWindows()
This method must be called in the destructor of the user class FROM THE MAIN THREAD, in order to wait for the shutdown of the wx thread if this was the last open window.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This class implements the GUI thread required for the wxWidgets-based GUI.
CDisplayWindow_WXAPP & wxGetApp()
void plotEllipse(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName, bool showName=false)
Redirected from CDisplayWindowPlots::plotEllipse.
CAuxWxSubsystemShutdowner()
A RGB color - floats in the range [0,1].
static CAuxWxSubsystemShutdowner global_wxsubsystem_shutdown
A panel to select the camera input from all the formats supported by MRPT.
mrpt::gui::CDisplayWindowPlots * sourcePlots
Only one of source* can be non-NULL, indicating the class that generated the request.
mrpt::synch::CCriticalSection m_csWxMainThreadId
The critical section for accessing "m_wxMainThreadId".
mrpt::utils::CConfigFileMemory selectedConfig
Classes for creating GUI windows for 2D and 3D visualization.
std::map< long, long > m_ID2ID
wxIDs to user IDs for submenus.
mrpt::math::CVectorFloat vector_x
static synch::CCriticalSection cs_windowCount
static volatile bool isConsoleApp
Will be set to true at runtime if it's not detected a running wxApp instance.
mrpt::gui::CDisplayWindow * source2D
Only one of source* can be non-NULL, indicating the class that generated the request.
std::string str
Parameters, depending on OPCODE.
void notifySemThreadReady()
Called by wx main thread to signal the semaphore that the wx window is built and ready.
GLsizei GLsizei GLenum GLenum const GLvoid * data
mrpt::system::TThreadHandle m_wxMainThreadId
The thread ID of wxMainThread, or 0 if it is not running.
A semaphore for inter-thread synchronization.
static bool createOneInstanceMainThread()
Thread-safe method to create one single instance of the main wxWidgets thread: it will create the thr...
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.
bool m_firstSubmenu
to know whether to insert a separator the first time.