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
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::detail::MappingRemoteGuiParams::remoteGuiTabName
std::string remoteGuiTabName
Definition: MappingRemoteGui.h:49
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::MappingRemoteGui::shutdown
void shutdown()
Definition: MappingRemoteGui.cpp:104
StaticWidgets.h
armarx::RemoteGui::makeButton
detail::ButtonBuilder makeButton(std::string const &name)
Definition: IntegerWidgets.h:52
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::RemoteGuiCallee
Definition: MappingRemoteGui.h:33
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::WidgetDescription::makeHBoxLayout
HBoxLayoutPtr makeHBoxLayout(std::vector< WidgetPtr > elements)
Definition: DefaultWidgetDescriptions.cpp:31
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::RemoteGui::makeTextLabel
detail::LabelBuilder makeTextLabel(std::string const &text)
Definition: StaticWidgets.h:24
ParameterMapping.h
IntegerWidgets.h
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:36
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::MappingRemoteGui::enable
void enable()
Definition: MappingRemoteGui.cpp:117
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
armarx::RemoteGui::TabProxy::receiveUpdates
void receiveUpdates()
Definition: WidgetProxy.h:135
LayoutWidgets.h
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
MappingRemoteGui.h
armarx::RemoteGui::detail::ToolTipMixin::toolTip
Derived & toolTip(std::string const &toolTip)
Definition: Basic.h:228
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::RemoteGuiCallee::onCreateMapButtonClicked
virtual void onCreateMapButtonClicked(const ButtonClickContext &)=0
WidgetProxy.h
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:67
CycleUtil.h
armarx::RemoteGui::TabProxy::sendUpdates
void sendUpdates()
Definition: WidgetProxy.h:151
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::MappingRemoteGui::MappingRemoteGui
MappingRemoteGui(const RemoteGuiInterfacePrx &remoteGui, RemoteGuiCallee &callee, const Params &params)
Definition: MappingRemoteGui.cpp:19
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::MappingRemoteGui::disable
void disable()
Definition: MappingRemoteGui.cpp:123
armarx::WidgetDescription::makeLineEdit
LineEditPtr makeLineEdit(std::string name, std::string defaultValue)
Definition: DefaultWidgetDescriptions.cpp:272
armarx::localization_and_mapping::components::cartographer_localization_and_mapping
Definition: Component.cpp:109
armarx::WidgetDescription::makeVBoxLayout
VBoxLayoutPtr makeVBoxLayout(std::vector< WidgetPtr > elements)
Definition: DefaultWidgetDescriptions.cpp:39
StringWidgets.h
armarx::PackagePath
Definition: PackagePath.h:52
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::MappingRemoteGui
Definition: MappingRemoteGui.h:54
armarx::localization_and_mapping::components::cartographer_localization_and_mapping::detail::MappingRemoteGuiParams
Definition: MappingRemoteGui.h:47
PackagePath.h