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;
wxAppConsole * mrpt_wxCreateApp()
const long ID_TIMER_WX_PROCESS_REQUESTS
int mrpt_wxEntryReal(int argc, char **argv)
CDisplayWindow_WXAPP & wxGetApp()
const char * mrpt_default_icon_xpm[]
virtual ~CDialogAskUserForCamera()
mrpt::gui::CPanelCameraSelection * panel
CDialogAskUserForCamera()
void OnBtnOk(wxCommandEvent &event)
static const long ID_BTN_OK
static const long ID_BTN_CANCEL
void OnBtnCancel(wxCommandEvent &event)
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 * getWxObject()
Read-only access to the wxDialog object.
void notifySemThreadReady()
Called by wx main thread to signal the semaphore that the wx window is built and ready.
A panel to select the camera input from all the formats supported by MRPT.
void writeConfigFromVideoSourcePanel(const std::string §, mrpt::utils::CConfigFileBase *cfg) const
void AssignImage(wxBitmap *img)
Assigns this image. This object has the ownship of the image and will delete it when appropriate.
The wx dialog for gui::CDisplayWindow.
wxMRPTImageControl * m_image
The wx dialog for gui::CDisplayWindowPlots.
void image(void *theWxImage, const float &x0, const float &y0, const float &w, const float &h, const std::string &plotName)
Redirected from CDisplayWindowPlots::image.
std::map< long, long > m_ID2ID
wxIDs to user IDs for submenus.
void plot(const mrpt::math::CVectorFloat &x, const mrpt::math::CVectorFloat &y, const std::string &lineFormat, const std::string &plotName)
Redirected from CDisplayWindowPlots::plot.
bool m_firstSubmenu
to know whether to insert a separator the first time.
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.
void OnMenuSelected(wxCommandEvent &ev)
An auxiliary global object used just to launch a final request to the wxSubsystem for shutdown:
CAuxWxSubsystemShutdowner()
~CAuxWxSubsystemShutdowner()
The main frame of the wxWidgets application.
void OnTimerProcessRequests(wxTimerEvent &event)
This method processes the pending requests from the main MRPT application thread.
static synch::CCriticalSection cs_windowCount
static volatile CWXMainFrame * oneInstance
static int notifyWindowCreation()
Atomically increments the number of windows created with the main frame as parent.
static int notifyWindowDestruction()
Atomically decrements the number of windows created with the main frame as parent.
This class implements the GUI thread required for the wxWidgets-based GUI.
static bool createOneInstanceMainThread()
Thread-safe method to create one single instance of the main wxWidgets thread: it will create the thr...
static TWxMainThreadData & GetWxMainThreadInstance()
static void pushPendingWxRequest(TRequestToWxMainThread *data)
Thread-safe method to insert a new pending request (The memory must be dinamically allocated with "ne...
static synch::CCriticalSection * cs_listPendingWxRequests
static volatile bool isConsoleApp
Will be set to true at runtime if it's not detected a running wxApp instance.
static TRequestToWxMainThread * popPendingWxRequest()
Thread-safe method to return the next pending request, or NULL if there is none (After usage,...
static CAuxWxSubsystemShutdowner global_wxsubsystem_shutdown
static void waitWxShutdownsIfNoWindows()
This method must be called in the destructor of the user class FROM THE MAIN THREAD,...
static std::queue< TRequestToWxMainThread * > * listPendingWxRequests
Do not access directly to this, use the thread-safe functions.
static void wxMainThread()
This will be the "MAIN" of wxWidgets: It starts an application object and does not end until all the ...
static wxBitmap getMRPTDefaultIcon()
This class provides simple critical sections functionality.
void enter() const MRPT_OVERRIDE
Enter.
void leave() const MRPT_OVERRIDE
Leave.
A class acquiring a CCriticalSection at its constructor, and releasing it at destructor.
A semaphore for inter-thread synchronization.
bool waitForSignal(unsigned int timeout_ms=0)
Blocks until the count of the semaphore to be non-zero.
void release(unsigned int increaseCount=1)
Increments the count of the semaphore by a given amount.
GLsizei GLsizei GLenum GLenum const GLvoid * data
TOpenGLFont
Existing fonts for 2D texts in mrpt::opengl methods.
TThreadHandle createThread(void(*func)(T), T param)
Creates a new thread from a function (or static method) with one generic parameter.
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.
Classes for creating GUI windows for 2D and 3D visualization.
TOpenGLFontStyle
Different style for vectorized font rendering.
This namespace provides multitask, synchronization utilities.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
The data structure for each inter-thread request:
bool sourceCameraSelectDialog
Only one of source* can be non-NULL, indicating the class that generated the request.
int OPCODE
Valid codes are: For CDisplayWindow:
mrpt::math::CVectorFloat vector_x
mrpt::gui::CDisplayWindowPlots * sourcePlots
Only one of source* can be non-NULL, indicating the class that generated the request.
mrpt::math::CVectorFloat vector_y
mrpt::gui::CDisplayWindow3D * source3D
Only one of source* can be non-NULL, indicating the class that generated the request.
void * voidPtr
Parameters, depending on OPCODE.
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.
mrpt::synch::CSemaphore m_semWxMainThreadReady
This is signaled when wxMainThread is ready.
mrpt::system::TThreadHandle m_wxMainThreadId
The thread ID of wxMainThread, or 0 if it is not running.
mrpt::synch::CCriticalSection m_csWxMainThreadId
The critical section for accessing "m_wxMainThreadId".
mrpt::utils::CConfigFileMemory selectedConfig
void clear()
Mark the handle as invalid.
bool isClear() const
Returns true if the handle is uninitialized.
A RGB color - floats in the range [0,1].