MappingRemoteGui.cpp
Go to the documentation of this file.
1#include "MappingRemoteGui.h"
2
6
10#include <ArmarXGui/interface/RemoteGuiInterface.h>
13
15{
16
17 namespace gui = RemoteGui;
18
19 MappingRemoteGui::MappingRemoteGui(const RemoteGuiInterfacePrx& remoteGui,
20 RemoteGuiCallee& callee,
21 const Params& params) :
22 remoteGui(remoteGui),
23 runningTask(new RunningTask<MappingRemoteGui>(this, &MappingRemoteGui::run)),
24 callee(callee),
25 params(params)
26 {
27 createRemoteGuiTab();
28
29 tab = RemoteGui::TabProxy(remoteGui, params.remoteGuiTabName);
30
31 runningTask->start();
32 }
33
34 void
35 MappingRemoteGui::createRemoteGuiTab()
36 {
37 ARMARX_CHECK_NOT_NULL(remoteGui); // createRemoteGui() has to be called first
38
39 auto boxLayout = gui::makeVBoxLayout();
40
41 {
42 const gui::WidgetPtr label = gui::makeTextLabel(
43 "Use this button to create a map after you collected enough data:");
44 const gui::WidgetPtr button =
45 gui::makeButton(CREATE_MAP_BUTTON).toolTip("Create and save the map.");
46 const gui::WidgetPtr line = gui::makeHBoxLayout().children({label, button});
47 boxLayout.addChild(line);
48 }
49
50 // Package path where to store map
51 {
52 const gui::WidgetPtr label = gui::makeTextLabel("Output directory:");
53
54 const auto package = gui::makeLineEdit(outputDirPackageField)
55 .value(params.mapStorageDir.serialize().package);
56 const auto path =
57 gui::makeLineEdit(outputDirPathField).value(params.mapStorageDir.serialize().path);
58
59 const gui::WidgetPtr line = gui::makeHBoxLayout().children({label, package, path});
60 boxLayout.addChild(line);
61 }
62
63
64 remoteGui->createTab(params.remoteGuiTabName, boxLayout);
65 }
66
67 void
68 MappingRemoteGui::run()
69 {
70 constexpr int kCycleDurationMs = 100;
71
72 CycleUtil c(kCycleDurationMs);
73 while (!runningTask->isStopped())
74 {
75 tab.receiveUpdates();
76
77 handleEvents(tab);
78
79 tab.sendUpdates();
80
81 c.waitForCycleDuration();
82 }
83 }
84
85 void
86 MappingRemoteGui::handleEvents(RemoteGui::TabProxy& tab)
87 {
88 // Detect button clicks and update the counter accordingly
89 const RemoteGui::ButtonProxy createMapButton = tab.getButton(CREATE_MAP_BUTTON);
90
91
92 if (createMapButton.clicked())
93 {
94 const RemoteGuiCallee::ButtonClickContext ctx{
95 .mapStorageDir =
96 armarx::PackagePath{tab.getValue<std::string>(outputDirPackageField).get(),
97 tab.getValue<std::string>(outputDirPathField).get()}};
98
99 callee.onCreateMapButtonClicked(ctx);
100 }
101 }
102
103 void
105 {
106
107 if (!runningTask->isStopped())
108 {
109 runningTask->stop();
110 }
111
112 ARMARX_DEBUG << "Removing tab: " << params.remoteGuiTabName;
113 remoteGui->removeTab(params.remoteGuiTabName);
114 }
115
116 void
118 {
119 tab.internalSetDisabled(CREATE_MAP_BUTTON, false);
120 }
121
122 void
124 {
125 tab.internalSetDisabled(CREATE_MAP_BUTTON, true);
126 }
127
128} // namespace armarx::localization_and_mapping::components::cartographer_localization_and_mapping
constexpr T c
MappingRemoteGui(const RemoteGuiInterfacePrx &remoteGui, RemoteGuiCallee &callee, const Params &params)
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184