MRPT
2.0.4
CWindowObserver.cpp
Go to the documentation of this file.
1
/* +------------------------------------------------------------------------+
2
| Mobile Robot Programming Toolkit (MRPT) |
3
| https://www.mrpt.org/ |
4
| |
5
| Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6
| See: https://www.mrpt.org/Authors - All rights reserved. |
7
| Released under BSD License. See: https://www.mrpt.org/License |
8
+------------------------------------------------------------------------+ */
9
10
// Implementation file for CWindowObserver class
11
#include "
graphslam-precomp.h
"
// Precompiled headers
12
13
#include <
mrpt/graphslam/misc/CWindowObserver.h
>
14
#include <
mrpt/gui/CBaseGUIWindow.h
>
15
#include <
mrpt/opengl/COpenGLViewport.h
>
16
17
using namespace
mrpt::graphslam
;
18
19
CWindowObserver::CWindowObserver
()
20
{
21
m_help_msg
=
22
"User options:\n"
23
" - h/H: Toggle help message\n"
24
" - Alt+Enter: Toggle fullscreen\n"
25
" - Mouse click: Set camera manually\n"
26
" - Ctrl+c: Halt program execution"
;
27
28
// register the default keystrokes
29
m_key_codes_to_pressed
[
"h"
] =
false
;
30
m_key_codes_to_pressed
[
"Alt+Enter"
] =
false
;
31
m_key_codes_to_pressed
[
"Ctrl+c"
] =
false
;
32
m_key_codes_to_pressed
[
"mouse_clicked"
] =
false
;
33
}
34
35
void
CWindowObserver::returnEventsStruct
(
36
std::map<std::string, bool>* codes_to_pressed,
37
bool
reset_keypresses
/*= true */
)
38
{
39
*codes_to_pressed =
m_key_codes_to_pressed
;
40
41
// reset the code flags
42
if
(reset_keypresses)
43
{
44
for
(
auto
& map_it :
m_key_codes_to_pressed
)
45
{
46
map_it.second =
false
;
47
}
48
}
49
}
50
51
void
CWindowObserver::registerKeystroke
(
52
const
std::string key_str,
const
std::string key_desc)
53
{
54
m_help_msg
+= std::string(
"\n"
) +
" - "
+ key_str +
"/"
+
55
mrpt::system::upperCase
(key_str) +
": "
+ key_desc;
56
57
m_key_codes_to_pressed
[key_str] =
false
;
58
}
59
60
void
CWindowObserver::OnEvent
(
const
mrpt::system::mrptEvent
& e)
61
{
62
if
(e.
isOfType
<
mrpt::system::mrptEventOnDestroy
>())
63
{
64
const
auto
& ev =
65
dynamic_cast<
const
mrpt::system::mrptEventOnDestroy
&
>
(e);
66
(void)ev;
67
std::cout <<
"Event received: mrptEventOnDestroy"
<< std::endl;
68
}
69
else
if
(e.
isOfType
<
mrpt::gui::mrptEventWindowResize
>())
70
{
71
const
auto
& ev =
72
static_cast<
const
mrpt::gui::mrptEventWindowResize
&
>
(e);
73
std::cout <<
"Resize event received from: "
<< ev.
source_object
74
<<
", new size: "
<< ev.new_width <<
" x "
<< ev.new_height
75
<< std::endl;
76
}
77
else
if
(e.
isOfType
<
mrpt::gui::mrptEventWindowChar
>())
78
{
79
const
auto
& ev =
dynamic_cast<
const
mrpt::gui::mrptEventWindowChar
&
>
(e);
80
std::cout <<
"Char event received from: "
<< ev.
source_object
81
<<
". Char code: "
<< ev.char_code
82
<<
" modif: "
<< ev.key_modifiers << std::endl;
83
;
84
85
switch
(ev.char_code)
86
{
87
case
'h'
:
88
case
'H'
:
89
m_key_codes_to_pressed
[
"h"
] =
true
;
90
break
;
91
case
'c'
:
92
case
'C'
:
93
// case 3: // <C-c>
94
if
(ev.key_modifiers == 8192)
95
{
96
std::cout <<
"Pressed C-c inside CDisplayWindow3D"
97
<< std::endl;
98
m_key_codes_to_pressed
[
"Ctrl+c"
] =
true
;
99
}
100
break
;
101
102
default
:
103
// just raise the corresponding flag. Let the class which
104
// actually
105
// cares translate the character to its corresponding meaning.
106
// Pressed letter is stored in lower case form only to make it
107
// easier
108
// to check afterwards
109
m_key_codes_to_pressed
[
mrpt::system::lowerCase
(
110
std::string(1, ev.char_code))] =
true
;
111
break
;
112
}
113
114
}
// end of e.isOftype<mrptEventWindowChar>
115
else
if
(e.
isOfType
<
mrpt::gui::mrptEventWindowClosed
>())
116
{
117
const
auto
& ev =
118
dynamic_cast<
const
mrpt::gui::mrptEventWindowClosed
&
>
(e);
119
std::cout <<
"Window closed event received from: "
<< ev.
source_object
120
<<
"\n"
;
121
}
122
else
if
(e.
isOfType
<
mrpt::gui::mrptEventMouseDown
>())
123
{
124
const
auto
& ev =
dynamic_cast<
const
mrpt::gui::mrptEventMouseDown
&
>
(e);
125
m_key_codes_to_pressed
[
"mouse_clicked"
] =
true
;
126
127
std::cout <<
"Mouse down event received from: "
<< ev.source_object
128
<<
"pt: "
<< ev.coords.x <<
","
<< ev.coords.y <<
"\n"
;
129
}
130
else
if
(e.
isOfType
<
mrpt::opengl::mrptEventGLPostRender
>())
131
{
132
/*
133
* An event sent by an mrpt::opengl::COpenGLViewport AFTER calling
134
* the
135
* SCENE OPENGL DRAWING PRIMITIVES and before doing a glSwapBuffers.
136
*/
137
138
// was: show m_help_msg.c_str()
139
}
140
}
mrpt::system::mrptEvent
The basic event type for the observer-observable pattern in MRPT.
Definition:
mrptEvent.h:31
COpenGLViewport.h
mrpt::graphslam::CWindowObserver::m_key_codes_to_pressed
std::map< std::string, bool > m_key_codes_to_pressed
Map from registered char_code (std::string to support <C-c>) to boolean true/false indicating whether...
Definition:
CWindowObserver.h:59
mrpt::graphslam::CWindowObserver::returnEventsStruct
void returnEventsStruct(std::map< std::string, bool > *codes_to_pressed, bool reset_keypresses=true)
Return a map of key code to a boolean indicating whether it was pressed since the previous time the c...
Definition:
CWindowObserver.cpp:35
mrpt::graphslam::CWindowObserver::m_help_msg
std::string m_help_msg
Definition:
CWindowObserver.h:52
mrpt::opengl::mrptEventGLPostRender
An event sent by an mrpt::opengl::COpenGLViewport after calling the scene OpenGL drawing primitives a...
Definition:
COpenGLViewport.h:482
mrpt::gui::mrptEventWindowClosed::source_object
CBaseGUIWindow * source_object
Definition:
CBaseGUIWindow.h:294
mrpt::gui::mrptEventWindowChar
An event sent by a window upon a char pressed by the user.
Definition:
CBaseGUIWindow.h:165
mrpt::gui::mrptEventWindowResize
An event sent by a window upon resize.
Definition:
CBaseGUIWindow.h:192
mrpt::system::mrptEvent::isOfType
bool isOfType() const
Definition:
mrptEvent.h:41
mrpt::system::lowerCase
std::string lowerCase(const std::string &str)
Returns an lower-case version of a string.
Definition:
string_utils.cpp:26
mrpt::graphslam::CWindowObserver::registerKeystroke
void registerKeystroke(const std::string key_str, const std::string key_desc)
Make new keystrokes available in the help message box.
Definition:
CWindowObserver.cpp:51
mrpt::graphslam::CWindowObserver::CWindowObserver
CWindowObserver()
Definition:
CWindowObserver.cpp:19
mrpt::graphslam
SLAM methods related to graphs of pose constraints.
Definition:
TUserOptionsChecker.h:30
mrpt::gui::mrptEventMouseDown
An event sent by a window upon a mouse click, giving the (x,y) pixel coordinates.
Definition:
CBaseGUIWindow.h:218
graphslam-precomp.h
mrpt::gui::mrptEventWindowResize::source_object
CBaseGUIWindow * source_object
Definition:
CBaseGUIWindow.h:205
mrpt::system::mrptEventOnDestroy
An event sent by any CObservable object (automatically) just before being destroyed and telling its o...
Definition:
mrptEvent.h:66
CWindowObserver.h
mrpt::system::upperCase
std::string upperCase(const std::string &str)
Returns a upper-case version of a string.
Definition:
string_utils.cpp:40
CBaseGUIWindow.h
mrpt::graphslam::CWindowObserver::OnEvent
void OnEvent(const mrpt::system::mrptEvent &e) override
This virtual function will be called upon receive of any event after starting listening at any CObser...
Definition:
CWindowObserver.cpp:60
mrpt::gui::mrptEventWindowClosed
An event sent by a window upon when it's about to be closed, either manually by the user or programma...
Definition:
CBaseGUIWindow.h:283
mrpt::gui::mrptEventWindowChar::source_object
CBaseGUIWindow * source_object
Definition:
CBaseGUIWindow.h:178
Page generated by
Doxygen 1.8.17
for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020