10#include <Ice/Exception.h>
19#include <RobotAPI/interface/armem/actions.h>
20#include <RobotAPI/interface/armem/memory.h>
21#include <RobotAPI/interface/armem/mns/MemoryNameSystemInterface.h>
35 _statusLabel->clear();
36 _statusLabel->setContextMenuPolicy(Qt::CustomContextMenu);
38 &QLabel::customContextMenuRequested,
39 [
this](
const QPoint& pos)
41 QMenu menu(_statusLabel);
42 menu.addAction(
"Copy to clipboard",
44 { QApplication::clipboard()->setText(_statusLabel->text()); });
45 menu.addAction(
"Clear status", [
this]() { _statusLabel->clear(); });
46 menu.exec(_statusLabel->mapToGlobal(pos));
49 _model = std::make_shared<armem::gui::model::MemoryViewerModel>();
51 _diskIOController = std::make_unique<armem::gui::controller::DiskIOController>(
55 _periodicUpdateController = std::make_unique<armem::gui::controller::PeriodicUpdateController>(
59 connect(_periodicUpdateController
60 ->memoryGroupBoxController()
61 ->memoryGroupBoxView()
66 connect(_periodicUpdateController
67 ->memoryGroupBoxController()
68 ->instanceGroupBoxController()
69 ->instanceGroupBoxView()
76 std::make_unique<armem::gui::controller::LivePlotController>(_model);
77 _periodicUpdateController
78 ->memoryGroupBoxController()
79 ->instanceGroupBoxController()
80 ->instanceGroupBoxView()
82 ->setLivePlotController(_livePlotController.get());
94 if (_mnsName.size() > 0)
98 if (_debugObserverName.size() > 0)
100 component.usingProxy(_debugObserverName);
103 _model->setInitialized(
true);
110 if (not _mnsName.empty())
112 armem::mns::MemoryNameSystemInterfacePrx mnsProxy;
114 _model->setMns(std::make_unique<client::MemoryNameSystem>(mnsProxy));
116 const bool update =
true;
118 _model->setMemoryReaders(_model->mns().getAllReaders(update));
119 _model->setMemoryWriters(_model->mns().getAllWriters(update));
122 if (not _debugObserverName.empty())
125 component.getProxy(observer, _debugObserverName,
false,
"",
false);
126 _model->setDebugObserver(observer);
129 emit _periodicUpdateController->startPeriodicTimerSignal();
130 _periodicUpdateController->startAutoUpdateTimerIfEnabled();
132 _livePlotController->onConnect();
134 _model->setConnected(
true);
141 emit _periodicUpdateController->stopAutoUpdateTimerSignal();
142 emit _periodicUpdateController->stopPeriodicTimerSignal();
144 _livePlotController->onDisconnect();
146 _model->setConnected(
false);
158 auto showMenu = [menu, pos]()
171 mns::dto::MemoryServerInterfaces prx;
174 prx = _model->mns().resolveServer(memoryID);
178 _statusLabel->setText(
179 QString::fromStdString(e.
makeMsg(memoryID,
"Could not resolve memory server.")));
186 std::stringstream ss;
187 ss <<
"Memory server " << memoryID <<
" does not support actions or is offline.";
188 _statusLabel->setText(QString::fromStdString(ss.str()));
193 actions::GetActionsOutputSeq result;
198 catch (
const Ice::LocalException& e)
200 std::stringstream ss;
201 ss <<
"Could not get actions for " << memoryID <<
".";
202 _statusLabel->setText(QString::fromStdString(ss.str()));
207 if (result.size() == 0)
215 [
this, prx](
const MemoryID& memoryID,
const actions::ActionPath& path)
217 actions::data::ExecuteActionOutputSeq result;
220 result = prx.actions->executeActions(
223 catch (
const Ice::LocalException& e)
225 std::stringstream ss;
226 ss <<
"Failed to execute action: " << e.what();
227 _statusLabel->setText(QString::fromStdString(ss.str()));
230 for (
const auto& [
success, errorMessage] : result)
234 std::stringstream ss;
235 ss <<
"Failed to execute action: " << errorMessage;
236 _statusLabel->setText(QString::fromStdString(ss.str()));
245 actionsMenu->exec(pos);
249 menu->addMenu(actionsMenu);
254 const static std::string CONFIG_KEY_MEMORY =
"MemoryViewer.MemoryNameSystem";
255 const static std::string CONFIG_KEY_DEBUG_OBSERVER =
"MemoryViewer.DebugObserverName";
260 _mnsName = settings->value(QString::fromStdString(CONFIG_KEY_MEMORY),
"MemoryNameSystem")
264 settings->value(QString::fromStdString(CONFIG_KEY_DEBUG_OBSERVER),
"DebugObserver")
272 settings->setValue(QString::fromStdString(CONFIG_KEY_MEMORY),
273 QString::fromStdString(_mnsName));
274 settings->setValue(QString::fromStdString(CONFIG_KEY_DEBUG_OBSERVER),
275 QString::fromStdString(_debugObserverName));
281 dialog->
addProxyFinder<armarx::armem::mns::MemoryNameSystemInterfacePrx>(
282 {CONFIG_KEY_MEMORY,
"MemoryNameSystem",
"MemoryNameSystem"});
284 {CONFIG_KEY_DEBUG_OBSERVER,
"Debug Observer",
"DebugObserver"});
291 if (_mnsName.empty())
293 _mnsName =
"MemoryNameSystem";
296 _debugObserverName = dialog->
getProxyName(CONFIG_KEY_DEBUG_OBSERVER);
void setTag(const LogTag &tag)
The ManagedIceObject is the base class for all ArmarX objects.
A config-dialog containing one (or multiple) proxy finders.
void addProxyFinder(const std::vector< EntryData > &entryData)
std::string getProxyName(const std::string &entryName) const
Indicates that a query to the Memory Name System failed.
static std::string makeMsg(const MemoryID &memoryID, const std::string &errorMessage="")
void readConfigDialog(SimpleConfigDialog *dialog)
void setLogTag(const std::string &tag)
void showActionsMenu(const MemoryID &memoryID, QWidget *parent, const QPoint &pos, QMenu *menu)
void saveSettings(QSettings *settings)
void loadSettings(QSettings *settings)
void writeConfigDialog(SimpleConfigDialog *dialog)
MemoryViewer(MemoryViewerUIContext &uiContext)
void actionsMenuRequested(const MemoryID &memoryID, QWidget *parent, const QPoint &pos, QMenu *menu)
virtual void onDisconnect()
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
void toIce(std::map< IceKeyT, IceValueT > &iceMap, const boost::container::flat_map< CppKeyT, CppValueT > &cppMap)