MemoryRemoteGui.cpp
Go to the documentation of this file.
1 #include "MemoryRemoteGui.h"
2 
4 
7 
9 
10 #include <SimoxUtility/meta/type_name.h>
11 
12 #include <mutex>
13 
14 
15 namespace armarx::armem::server
16 {
17 
18  template <class ...Args>
19  MemoryRemoteGui::GroupBox 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  {
30  group.addChild(this->makeGroupBox(coreSegment));
31  });
32  return group;
33  }
34 
35 
36  static std::string getTypeString(const armem::base::detail::AronTyped& typed)
37  {
38  std::stringstream type;
39  if (typed.aronType())
40  {
41  type << " (" << typed.aronType()->getFullName() << ")";
42  }
43  else
44  {
45  type << " (no Aron type)";
46  }
47  return type.str();
48  }
49 
50  template <class ...Args>
51  MemoryRemoteGui::GroupBox MemoryRemoteGui::_makeGroupBox(const armem::base::CoreSegmentBase<Args...>& coreSegment) const
52  {
53  GroupBox group;
54  group.setLabel(makeGroupLabel("Core Segment", coreSegment.name(), coreSegment.size())
55  + getTypeString(coreSegment));
56 
57  if (coreSegment.empty())
58  {
59  group.addChild(Label(makeNoItemsMessage("provider segments")));
60  }
61  coreSegment.forEachProviderSegment([this, &group](const auto & providerSegment)
62  {
63  group.addChild(this->makeGroupBox(providerSegment));
64  });
65  return group;
66  }
67 
68 
69  template <class ...Args>
70  MemoryRemoteGui::GroupBox MemoryRemoteGui::_makeGroupBox(const armem::base::ProviderSegmentBase<Args...>& providerSegment) const
71  {
72  GroupBox group;
73  group.setLabel(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  {
82  group.addChild(this->makeGroupBox(entity));
83  });
84  return group;
85  }
86 
87 
88  template <class ...Args>
89  MemoryRemoteGui::GroupBox MemoryRemoteGui::_makeGroupBox(const armem::base::EntityBase<Args...>& entity) const
90  {
91  GroupBox group;
92  group.setLabel(makeGroupLabel("Entity", entity.name(), entity.size()));
93 
94  if (entity.empty())
95  {
96  group.addChild(Label(makeNoItemsMessage("snapshots")));
97  }
98 
99  auto addChild = [this, &group](const armem::wm::EntitySnapshot & snapshot)
100  {
101  group.addChild(makeGroupBox(snapshot));
102  };
103 
104  if (int(entity.size()) <= maxHistorySize)
105  {
106  entity.forEachSnapshot(addChild);
107  }
108  else
109  {
110  const int margin = 2;
111  entity.forEachSnapshotInIndexRange(0, margin, addChild);
112  entity.forEachSnapshotInIndexRange(-margin, -1, addChild);
113  }
114  group.setCollapsed(true);
115 
116  return group;
117  }
118 
119 
121  {
122  return this->_makeGroupBox(memory);
123  }
124 
126  {
127  return this->_makeGroupBox(memory);
128  }
129 
130 
132  {
133  return coreSegment.doLocked([this, &coreSegment]()
134  {
135  return this->_makeGroupBox(coreSegment);
136  });
137  }
138 
139 
141  {
142  return this->_makeGroupBox(coreSegment);
143  }
144 
145 
147  {
148  return this->_makeGroupBox(providerSegment);
149  }
150 
151 
153  {
154  return this->_makeGroupBox(providerSegment);
155  }
156 
157 
159  {
160  return this->_makeGroupBox(entity);
161  }
162 
163 
165  {
166  return this->_makeGroupBox(entity);
167  }
168 
169 
171  {
172  GroupBox group;
174  snapshot.size(), " = ", ""));
175 
176  if (snapshot.empty())
177  {
178  group.addChild(Label(makeNoItemsMessage("instances")));
179  }
180  snapshot.forEachInstance([this, &group](const armem::wm::EntityInstance & instance)
181  {
182  group.addChild(makeGroupBox(instance));
183  return true;
184  });
185  group.setCollapsed(true);
186 
187  return group;
188  }
189 
190 
192  {
193  GroupBox group;
194 
195  if (instance.data())
196  {
198  aron::data::visitRecursive(v, instance.data());
199  group = v.result;
200  }
201  else
202  {
203  group.addChild(Label("(No data.)"));
204  }
205 
206  std::stringstream ss;
207  ss << "Instance #" << instance.index();
208  group.setLabel(ss.str());
209  group.setCollapsed(true);
210 
211  return group;
212  }
213 
214 
216  const std::string& term, const std::string& name, size_t size,
217  const std::string& namePrefix, const std::string& nameSuffix) const
218  {
219  std::stringstream ss;
220  ss << term << namePrefix << name << nameSuffix << " (" << size << ")";
221  return ss.str();
222  }
223 
224 
225  std::string MemoryRemoteGui::makeNoItemsMessage(const std::string& term) const
226  {
227  std::stringstream ss;
228  ss << "(no " << term << ")";
229  return ss.str();
230  }
231 
232 
233 
234 
235 }
armarx::armem::base::detail::MemoryContainerBase::empty
bool empty() const
Definition: MemoryContainerBase.h:44
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:125
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:17
armarx::armem::server::wm::Entity
Definition: memory_definitions.h:30
armarx::memory
Brief description of class memory.
Definition: memory.h:39
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:215
armarx::armem::base::detail::MemoryContainerBase::size
std::size_t size() const
Definition: MemoryContainerBase.h:48
Object.h
armarx::armem::server::wm::Memory
Definition: memory_definitions.h:128
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:401
armarx::armem::wm::EntitySnapshot
Client-side working memory entity snapshot.
Definition: memory_definitions.h:80
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::wm::CoreSegment::doLocked
auto doLocked(FunctionT &&function) const
Definition: memory_definitions.h:112
armarx::RemoteGui::Client::GroupBox::setLabel
void setLabel(std::string const &text)
Definition: Widgets.cpp:395
armarx::armem::server
Definition: GraspMemory.cpp:19
ExpressionException.h
RemoteGuiAronDataVisitor.h
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:86
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:65
armarx::armem::server::MemoryRemoteGui::makeNoItemsMessage
std::string makeNoItemsMessage(const std::string &term) const
Definition: MemoryRemoteGui.cpp:225
armarx::armem::base::EntitySnapshotBase::time
Time & time()
Definition: EntitySnapshotBase.h:59
armarx::armem::server::MemoryRemoteGui::maxHistorySize
int maxHistorySize
Definition: MemoryRemoteGui.h:40
armarx::aron::data::visitRecursive
requires isRecursiveVisitor< RecursiveVisitorImplementation, typename RecursiveVisitorImplementation::Input > void visitRecursive(RecursiveVisitorImplementation &v, typename RecursiveVisitorImplementation::Input &o)
Definition: RecursiveVisitor.h:146
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:18
armarx::armem::server::MemoryRemoteGui::GroupBox
armarx::RemoteGui::Client::GroupBox GroupBox
Definition: MemoryRemoteGui.h:17