namespace mrpt::gui::WxSubsystem

Overview

This class implements the GUI thread required for the wxWidgets-based GUI.

This system is employed internally by gui::CDisplayWindow and gui::CDisplayWindow3D, and must be not used in any way directly by the MRPT user.

The system works by creating a invisible wxFrame that process timer events where it checks a queue of requests sent from the main MRPT thread. The requests include the creation, deletion,… of windows (2D/3D). In that way, just one thread is required for all the GUI windows, and the wxWidgets is initialized and clean-up correctly.

This header should be included just from the implementation files of CDisplayWindow and CDisplayWindow3D, since it uses wxWidgets classes.

See also:

gui::CDisplayWindow, gui::CDisplayWindow3D

namespace WxSubsystem {

// enums

enum OpCode;

// structs

struct TRequestToWxMainThread;
struct TWxMainThreadData;

// classes

class CAuxWxSubsystemShutdowner;
class CWXMainFrame;

// global functions

void waitWxShutdownsIfNoWindows();
bool isConsoleApp();
TWxMainThreadData& GetWxMainThreadInstance();
std::unique_ptr<TRequestToWxMainThread> PopPendingWxRequest();
void PushPendingWxRequest(std::unique_ptr<TRequestToWxMainThread>&& data);
bool CreateOneInstanceMainThread();
wxBitmap GetMRPTDefaultIcon();

} // namespace WxSubsystem

Global Functions

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.

bool isConsoleApp()

Will be set to true at runtime if it’s not detected a running wxApp instance.

For console apps, we’ll create a new thread and run wxEntry from there. For GUI apps (MRPT-based Windows are a part of a user wxWidget apps), we must leave the control of message dispatching to the current main loop, so we cannot create a different threads, making things a little different (hence this variable).

std::unique_ptr<TRequestToWxMainThread> PopPendingWxRequest()

Thread-safe method to return the next pending request, or nullptr if there is none.

The caller takes ownership and must delete the object.

void PushPendingWxRequest(std::unique_ptr<TRequestToWxMainThread>&& data)

Thread-safe method to insert a new pending request.

Ownership of data is transferred; it will be deleted by the receiver. data must have been allocated with new (single object).

bool CreateOneInstanceMainThread()

Thread-safe method to create one single instance of the main wxWidgets thread: it will create the thread only if it is not running yet.