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