SkillDashboard.cpp
Go to the documentation of this file.
1 
2 #include "SkillDashboard.h"
3 
4 #include <fstream>
5 #include <iostream>
6 
7 #include <nlohmann/json.hpp>
8 
9 namespace armarx
10 {
11 
14  {
16  new ::armarx::ComponentPropertyDefinitions(getConfigIdentifier());
17  def->optional(properties.shortcutPath, "ShortcutPath", "");
18  return def;
19  }
20 
21  void
22  SkillDashboard::loadShortcuts(const std::string& filename)
23  {
24  std::ifstream file(filename);
25  nlohmann::json jsonData;
26 
27  if (!file.is_open())
28  {
29  ARMARX_WARNING << "Could not open file";
30  }
31 
32  file >> jsonData;
33 
34  for (const auto& item : jsonData["shortcuts"])
35  {
36  SkillShortcut shortcut;
37  shortcut.skillArgs = item["skill_args"].dump(2);
38  shortcut.skillId = item["skill_id"];
39  shortcut.shortcutName = item["skill_shortcut_name"];
40 
41  this->registeredShortcuts.push_back(shortcut);
42  }
43  }
44 
45  void
47  {
48 
49  this->registeredShortcuts = std::vector<SkillShortcut>();
50  this->properties.shortcutPath = getProperty<std::string>("ShortcutPath").getValue();
51 
52  if (not properties.shortcutPath.empty())
53  {
54  loadShortcuts(properties.shortcutPath);
55  }
56  }
57 
58  void
60  {
61  }
62 
63  SkillShortcutList
64  SkillDashboard::getShortcuts(const ::Ice::Current&)
65  {
66  return this->registeredShortcuts;
67  }
68 
69  SkillShortcut
70  SkillDashboard::getShortcut(const std::string& name, const ::Ice::Current&)
71  {
72  for (const SkillShortcut& shortcut : this->registeredShortcuts)
73  {
74  if (shortcut.shortcutName == name)
75  {
76  return shortcut;
77  }
78  }
79 
80  return SkillShortcut();
81  }
82 
83  void
84  SkillDashboard::addNewShortcut(const SkillShortcut& newShortcut, const ::Ice::Current&)
85  {
86  if (newShortcut.shortcutName != "")
87  {
88  if (getShortcut(newShortcut.shortcutName).shortcutName == "")
89  {
90 
91  this->registeredShortcuts.push_back(newShortcut);
92  ARMARX_INFO << "Added shortcut " << newShortcut.shortcutName;
93  }
94  else
95  {
96  for (SkillShortcut& shortcut : this->registeredShortcuts)
97  {
98  if (shortcut.shortcutName == newShortcut.shortcutName)
99  {
100  shortcut.skillId = newShortcut.skillId;
101  shortcut.skillArgs = newShortcut.skillArgs;
102  }
103  }
104  ARMARX_INFO << "changed shortcut";
105  }
106  }
107  }
108 
109  void
110  SkillDashboard::deleteShortcut(const std::string& name, const ::Ice::Current&)
111  {
112  for (auto it = this->registeredShortcuts.begin(); it != this->registeredShortcuts.end();
113  ++it)
114  {
115  if (it->shortcutName == name)
116  {
117  this->registeredShortcuts.erase(it);
118  break;
119  }
120  }
121  }
122 
123  void
125  {
126  }
127 
128  void
130  {
131  }
132 
133 
134 } // namespace armarx
armarx::SkillDashboard::getShortcut
SkillShortcut getShortcut(const std::string &name, const ::Ice::Current &=::Ice::Current()) override
Definition: SkillDashboard.cpp:70
armarx::SkillDashboard::onExitComponent
void onExitComponent() override
Definition: SkillDashboard.cpp:129
armarx::SkillDashboard::addNewShortcut
void addNewShortcut(const SkillShortcut &newShortcut, const ::Ice::Current &=::Ice::Current()) override
Definition: SkillDashboard.cpp:84
armarx::SkillDashboard::onConnectComponent
void onConnectComponent() override
Definition: SkillDashboard.cpp:59
armarx::SkillDashboard::onDisconnectComponent
void onDisconnectComponent() override
Definition: SkillDashboard.cpp:124
armarx::SkillDashboard::onInitComponent
void onInitComponent() override
Definition: SkillDashboard.cpp:46
armarx::SkillDashboard::deleteShortcut
void deleteShortcut(const std::string &name, const ::Ice::Current &=::Ice::Current()) override
Definition: SkillDashboard.cpp:110
armarx::SkillDashboard::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: SkillDashboard.cpp:13
armarx::SkillDashboard::getShortcuts
SkillShortcutList getShortcuts(const ::Ice::Current &=::Ice::Current()) override
Definition: SkillDashboard.cpp:64
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
SkillDashboard.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle
Definition: forward_declarations.h:30
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27