Storage.cpp
Go to the documentation of this file.
1 #include "Storage.h"
2 
3 namespace armarx::RemoteGui
4 {
5 
6  bool
8  RemoteGui::ValueMap const& oldValues,
9  std::string const& name)
10  {
11  auto oldIter = oldValues.find(name);
12  if (oldIter == oldValues.end())
13  {
14  return false;
15  }
16 
17  auto newIter = newValues.find(name);
18  if (newIter == newValues.end())
19  {
20  throw LocalException("Could find value with name: ") << name;
21  }
22 
23  bool changed = false;
24  if (oldIter->second.type == VALUE_VARIANT_INT)
25  {
26  int oldValue = getSingleValue<int>(oldIter->second, oldIter->first);
27  int newValue = getSingleValue<int>(newIter->second, newIter->first);
28  changed = newValue > oldValue;
29  }
30  else if (oldIter->second.type == VALUE_VARIANT_BOOL)
31  {
32  bool oldValue = getSingleValue<bool>(oldIter->second, oldIter->first);
33  bool newValue = getSingleValue<bool>(newIter->second, newIter->first);
34  changed = newValue != oldValue;
35  }
36 
37  return changed;
38  }
39 
40  bool
41  operator==(const ValueVariant& left, const ValueVariant& right)
42  {
43  if (left.type != right.type)
44  {
45  return false;
46  }
47 
48  switch (left.type)
49  {
50  case VALUE_VARIANT_EMPTY:
51  return true;
52 
53  case VALUE_VARIANT_BOOL:
54  return (left.i != 0) == (right.i != 0);
55 
56  case VALUE_VARIANT_INT:
57  return left.i == right.i;
58 
59  case VALUE_VARIANT_FLOAT:
60  return left.f == right.f;
61 
62  case VALUE_VARIANT_STRING:
63  return left.s == right.s;
64 
65  case VALUE_VARIANT_VECTOR3:
66  case VALUE_VARIANT_MATRIX4:
67  return left.v == right.v;
68  }
69 
70  throw std::logic_error("Remote value type not handled");
71  }
72 
73  bool
74  operator!=(const ValueVariant& left, const ValueVariant& right)
75  {
76  return !(left == right);
77  }
78 
79  Vector3f
80  toIceF(Eigen::Vector3f v)
81  {
82  Vector3f result;
83  result.x = v.x();
84  result.y = v.y();
85  result.z = v.z();
86  return result;
87  }
88 
89  Vector3i
90  toIceI(Eigen::Vector3i v)
91  {
92  Vector3i result;
93  result.x = v.x();
94  result.y = v.y();
95  result.z = v.z();
96  return result;
97  }
98 
99  Eigen::Vector3f
100  fromIce(Vector3f v)
101  {
102  Eigen::Vector3f result;
103  result.x() = v.x;
104  result.y() = v.y;
105  result.z() = v.z;
106  return result;
107  }
108 
109  Eigen::Vector3i
110  fromIce(Vector3i v)
111  {
112  Eigen::Vector3i result;
113  result.x() = v.x;
114  result.y() = v.y;
115  result.z() = v.z;
116  return result;
117  }
118 
119  const char*
120  getVariantTypeName(ValueVariantType type)
121  {
122  switch (type)
123  {
124  case VALUE_VARIANT_EMPTY:
125  return "";
126  case VALUE_VARIANT_BOOL:
127  return "bool";
128  case VALUE_VARIANT_INT:
129  return "int";
130  case VALUE_VARIANT_FLOAT:
131  return "float";
132  case VALUE_VARIANT_STRING:
133  return "string";
134  case VALUE_VARIANT_VECTOR3:
135  return "vector3";
136  case VALUE_VARIANT_MATRIX4:
137  return "matrix4";
138  default:
139  throw LocalException("Unknown ValueVariantType: ") << (int)type;
140  }
141  }
142 
143  ValueVariant
145  {
146  ValueVariant result;
147  result.type = VALUE_VARIANT_BOOL;
148  result.i = value ? 1 : 0;
149  return result;
150  }
151 
152  ValueVariant
154  {
155  ValueVariant result;
156  result.type = VALUE_VARIANT_INT;
157  result.i = value;
158  return result;
159  }
160 
161  ValueVariant
163  {
164  ValueVariant result;
165  result.type = VALUE_VARIANT_FLOAT;
166  result.f = value;
167  return result;
168  }
169 
170  ValueVariant
171  makeValue(std::string value)
172  {
173  ValueVariant result;
174  result.type = VALUE_VARIANT_STRING;
175  result.s = value;
176  return result;
177  }
178 
179  ValueVariant
180  makeValue(const Eigen::Vector3f& value)
181  {
182  ValueVariant result;
183  result.type = VALUE_VARIANT_VECTOR3;
184  result.v.resize(3);
185  result.v[0] = value(0);
186  result.v[1] = value(1);
187  result.v[2] = value(2);
188  return result;
189  }
190 
191  ValueVariant
193  {
194  ValueVariant result;
195  result.type = VALUE_VARIANT_MATRIX4;
196  result.v.resize(16);
197  result.v[0] = value.row(0)[0];
198  result.v[1] = value.row(0)[1];
199  result.v[2] = value.row(0)[2];
200  result.v[3] = value.row(0)[3];
201  result.v[4] = value.row(1)[0];
202  result.v[5] = value.row(1)[1];
203  result.v[6] = value.row(1)[2];
204  result.v[7] = value.row(1)[3];
205  result.v[8] = value.row(2)[0];
206  result.v[9] = value.row(2)[1];
207  result.v[10] = value.row(2)[2];
208  result.v[11] = value.row(2)[3];
209  result.v[12] = value.row(3)[0];
210  result.v[13] = value.row(3)[1];
211  result.v[14] = value.row(3)[2];
212  result.v[15] = value.row(3)[3];
213  return result;
214  }
215 
216  void
217  getValueFromMap(bool& val, const ValueMap& values, const std::string& name)
218  {
219  val = getAndReturnValue<bool>(values, name);
220  }
221 
222  void
223  getValueFromMap(int& val, const ValueMap& values, const std::string& name)
224  {
225  val = getAndReturnValue<int>(values, name);
226  }
227 
228  void
229  getValueFromMap(float& val, const ValueMap& values, const std::string& name)
230  {
231  val = getAndReturnValue<float>(values, name);
232  }
233 
234  void
235  getValueFromMap(std::string& val, const ValueMap& values, const std::string& name)
236  {
237  val = getAndReturnValue<std::string>(values, name);
238  }
239 
240  void
241  getValueFromMap(Eigen::Vector3f& val, const ValueMap& values, const std::string& name)
242  {
243  val = getAndReturnValue<Eigen::Vector3f>(values, name);
244  }
245 
246  void
247  getValueFromMap(Eigen::Matrix4f& val, const ValueMap& values, const std::string& name)
248  {
249  val = getAndReturnValue<Eigen::Matrix4f>(values, name);
250  }
251 
252 
253 } // namespace armarx::RemoteGui
armarx::RemoteGui::toIceF
Vector3f toIceF(Eigen::Vector3f v)
Definition: Storage.cpp:80
armarx::RemoteGui
Definition: LightweightRemoteGuiComponentPlugin.h:30
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::RemoteGui::operator!=
bool operator!=(const ValueVariant &left, const ValueVariant &right)
Definition: Storage.cpp:74
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
Storage.h
armarx::RemoteGui::getSingleValue< int >
int getSingleValue< int >(ValueVariant const &value, const std::string &name)
Definition: Storage.h:103
armarx::RemoteGui::ValueMap
std::map< std::string, ValueVariant > ValueMap
Definition: RemoteGuiVisitors.h:41
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::RemoteGui::toIceI
Vector3i toIceI(Eigen::Vector3i v)
Definition: Storage.cpp:90
armarx::RemoteGui::operator==
bool operator==(const ValueVariant &left, const ValueVariant &right)
Definition: Storage.cpp:41
armarx::RemoteGui::getSingleValue< bool >
bool getSingleValue< bool >(ValueVariant const &value, const std::string &name)
Definition: Storage.h:89
armarx::RemoteGui::makeValue
ValueVariant makeValue(bool value)
Definition: Storage.cpp:144
armarx::RemoteGui::fromIce
Eigen::Vector3f fromIce(Vector3f v)
Definition: Storage.cpp:100
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::RemoteGui::getVariantTypeName
const char * getVariantTypeName(ValueVariantType type)
Definition: Storage.cpp:120
armarx::RemoteGui::buttonClicked
bool buttonClicked(RemoteGui::ValueMap const &newValues, RemoteGui::ValueMap const &oldValues, std::string const &name)
Definition: Storage.cpp:7
armarx::RemoteGui::getValueFromMap
std::enable_if_t< meta::cfg::gui_definition_enabled_v< T >, void > getValueFromMap(T &cfg, RemoteGui::ValueMap const &values, std::string const &name)
Definition: GetValue.h:12