MemoryRemoteGui.cpp
Go to the documentation of this file.
1 #include "MemoryRemoteGui.h"
2 
3 #include <mutex>
4 
5 #include <SimoxUtility/meta/type_name.h>
6 
8 
11 
13 
14 namespace armarx::armem::server
15 {
16 
17  template <class... Args>
19  MemoryRemoteGui::_makeGroupBox(const armem::base::MemoryBase<Args...>& memory) const
20  {
21  GroupBox group;
22  group.setLabel(makeGroupLabel("Memory", memory.name(), memory.size()));
23 
24  if (memory.empty())
25  {
26  group.addChild(Label(makeNoItemsMessage("core segments")));
27  }
28  memory.forEachCoreSegment([this, &group](const auto& coreSegment)
29  { group.addChild(this->makeGroupBox(coreSegment)); });
30  return group;
31  }
32 
33  static std::string
34  getTypeString(const armem::base::detail::AronTyped& typed)
35  {
36  std::stringstream type;
37  if (typed.aronType())
38  {
39  type << " (" << typed.aronType()->getFullName() << ")";
40  }
41  else
42  {
43  type << " (no Aron type)";
44  }
45  return type.str();
46  }
47 
48  template <class... Args>
50  MemoryRemoteGui::_makeGroupBox(const armem::base::CoreSegmentBase<Args...>& coreSegment) const
51  {
52  GroupBox group;
53  group.setLabel(makeGroupLabel("Core Segment", coreSegment.name(), coreSegment.size()) +
54  getTypeString(coreSegment));
55 
56  if (coreSegment.empty())
57  {
58  group.addChild(Label(makeNoItemsMessage("provider segments")));
59  }
60  coreSegment.forEachProviderSegment(
61  [this, &group](const auto& providerSegment)
62  { group.addChild(this->makeGroupBox(providerSegment)); });
63  return group;
64  }
65 
66  template <class... Args>
68  MemoryRemoteGui::_makeGroupBox(
69  const armem::base::ProviderSegmentBase<Args...>& providerSegment) const
70  {
71  GroupBox group;
72  group.setLabel(
73  makeGroupLabel("Provider Segment", providerSegment.name(), providerSegment.size()) +
74  getTypeString(providerSegment));
75 
76  if (providerSegment.empty())
77  {
78  group.addChild(Label(makeNoItemsMessage("entities")));
79  }
80  providerSegment.forEachEntity([this, &group](const auto& entity)
81  { group.addChild(this->makeGroupBox(entity)); });
82  return group;
83  }
84 
85  template <class... Args>
87  MemoryRemoteGui::_makeGroupBox(const armem::base::EntityBase<Args...>& entity) const
88  {
89  GroupBox group;
90  group.setLabel(makeGroupLabel("Entity", entity.name(), entity.size()));
91 
92  if (entity.empty())
93  {
94  group.addChild(Label(makeNoItemsMessage("snapshots")));
95  }
96 
97  auto addChild = [this, &group](const armem::wm::EntitySnapshot& snapshot)
98  { group.addChild(makeGroupBox(snapshot)); };
99 
100  if (int(entity.size()) <= maxHistorySize)
101  {
102  entity.forEachSnapshot(addChild);
103  }
104  else
105  {
106  const int margin = 2;
107  entity.forEachSnapshotInIndexRange(0, margin, addChild);
108  entity.forEachSnapshotInIndexRange(-margin, -1, addChild);
109  }
110  group.setCollapsed(true);
111 
112  return group;
113  }
114 
117  {
118  return this->_makeGroupBox(memory);
119  }
120 
123  {
124  return this->_makeGroupBox(memory);
125  }
126 
129  {
130  return coreSegment.doLocked([this, &coreSegment]()
131  { return this->_makeGroupBox(coreSegment); });
132  }
133 
136  {
137  return this->_makeGroupBox(coreSegment);
138  }
139 
142  {
143  return this->_makeGroupBox(providerSegment);
144  }
145 
148  {
149  return this->_makeGroupBox(providerSegment);
150  }
151 
154  {
155  return this->_makeGroupBox(entity);
156  }
157 
160  {
161  return this->_makeGroupBox(entity);
162  }
163 
166  {
167  GroupBox group;
168  group.setLabel(makeGroupLabel(
169  "t", armem::toDateTimeMilliSeconds(snapshot.time()), snapshot.size(), " = ", ""));
170 
171  if (snapshot.empty())
172  {
173  group.addChild(Label(makeNoItemsMessage("instances")));
174  }
175  snapshot.forEachInstance(
176  [this, &group](const armem::wm::EntityInstance& instance)
177  {
178  group.addChild(makeGroupBox(instance));
179  return true;
180  });
181  group.setCollapsed(true);
182 
183  return group;
184  }
185 
188  {
189  GroupBox group;
190 
191  if (instance.data())
192  {
194  aron::data::visitRecursive(v, instance.data());
195  group = v.result;
196  }
197  else
198  {
199  group.addChild(Label("(No data.)"));
200  }
201 
202  std::stringstream ss;
203  ss << "Instance #" << instance.index();
204  group.setLabel(ss.str());
205  group.setCollapsed(true);
206 
207  return group;
208  }
209 
210  std::string
211  MemoryRemoteGui::makeGroupLabel(const std::string& term,
212  const std::string& name,
213  size_t size,
214  const std::string& namePrefix,
215  const std::string& nameSuffix) const
216  {
217  std::stringstream ss;
218  ss << term << namePrefix << name << nameSuffix << " (" << size << ")";
219  return ss.str();
220  }
221 
222  std::string
223  MemoryRemoteGui::makeNoItemsMessage(const std::string& term) const
224  {
225  std::stringstream ss;
226  ss << "(no " << term << ")";
227  return ss.str();
228  }
229 
230 
231 } // namespace armarx::armem::server
armarx::armem::base::detail::MemoryContainerBase::empty
bool empty() const
Definition: MemoryContainerBase.h:41
armarx::RemoteGui::Client::ContainerWidget::addChild
void addChild(Widget const &child)
Definition: Widgets.cpp:95
armarx::armem::wm::ProviderSegment
Client-side working memory provider segment.
Definition: memory_definitions.h:105
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::server::MemoryRemoteGui::makeGroupBox
GroupBox makeGroupBox(const armem::wm::Memory &memory) const
Definition: MemoryRemoteGui.cpp:122
armarx::armem::base::EntitySnapshotBase::forEachInstance
bool forEachInstance(InstanceFunctionT &&func)
Definition: EntitySnapshotBase.h:178
armarx::armem::base::EntityInstanceBase::index
int & index()
Definition: EntityInstanceBase.h:103
armarx::armem::server::RemoteGuiAronDataVisitor
Definition: RemoteGuiAronDataVisitor.h:16
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:27
armarx::memory
Brief description of class memory.
Definition: memory.h:38
armarx::armem::server::MemoryRemoteGui::makeGroupLabel
std::string makeGroupLabel(const std::string &term, const std::string &name, size_t size, const std::string &namePrefix=": '", const std::string &nameSuffix="'") const
Definition: MemoryRemoteGui.cpp:211
armarx::armem::base::detail::MemoryContainerBase::size
std::size_t size() const
Definition: MemoryContainerBase.h:47
Object.h
armarx::armem::server::wm::Memory
Definition: memory_definitions.h:122
armarx::armem::toDateTimeMilliSeconds
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
Definition: Time.cpp:35
MemoryRemoteGui.h
armarx::armem::wm::CoreSegment
Client-side working memory core segment.
Definition: memory_definitions.h:119
armarx::armem::wm::Memory
Client-side working memory.
Definition: memory_definitions.h:133
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
All.h
armarx::RemoteGui::Client::GroupBox::setCollapsed
void setCollapsed(bool collapsed)
Definition: Widgets.cpp:427
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:52
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:110
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:420
armarx::armem::server
Definition: GraspMemory.cpp:33
ExpressionException.h
RemoteGuiAronDataVisitor.h
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:75
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::armem::server::wm::EntitySnapshot
armem::wm::EntitySnapshot EntitySnapshot
Definition: forward_declarations.h:66
armarx::armem::server::MemoryRemoteGui::makeNoItemsMessage
std::string makeNoItemsMessage(const std::string &term) const
Definition: MemoryRemoteGui.cpp:223
armarx::armem::base::EntitySnapshotBase::time
Time & time()
Definition: EntitySnapshotBase.h:59
armarx::armem::server::MemoryRemoteGui::maxHistorySize
int maxHistorySize
Definition: MemoryRemoteGui.h:41
armarx::aron::data::visitRecursive
requires isRecursiveVisitor< RecursiveVisitorImplementation, typename RecursiveVisitorImplementation::Input > void visitRecursive(RecursiveVisitorImplementation &v, typename RecursiveVisitorImplementation::Input &o)
Definition: RecursiveVisitor.h:161
armarx::armem::wm::Entity
Client-side working memory entity.
Definition: memory_definitions.h:93
armarx::armem::base::EntityInstanceBase::data
const DataT & data() const
Definition: EntityInstanceBase.h:129
armarx::armem::server::MemoryRemoteGui::Label
armarx::RemoteGui::Client::Label Label
Definition: MemoryRemoteGui.h:17
armarx::armem::server::MemoryRemoteGui::GroupBox
armarx::RemoteGui::Client::GroupBox GroupBox
Definition: MemoryRemoteGui.h:16