9#include <nlohmann/json.hpp>
19 def->optional(properties.shortcutPath,
21 "Add path of predefined dashboards. Syntax: Package/folderName/fileName");
26 SkillDashboard::loadShortcuts(
const std::string& packagepath)
28 this->registeredShortcuts = std::vector<SkillShortcut>();
29 std::stringstream ss(packagepath);
31 std::vector<std::string> result;
32 while (std::getline(ss, item,
'/'))
34 result.push_back(item);
36 if (result.size() < 3)
41 this->packageName = result[0];
43 std::string absoluteFilepath;
45 armarx::CMakePackageFinder finder(result[0]);
46 if (finder.packageFound())
50 std::string packageDataDir = finder.getDataDir();
56 std::string relativeFilename;
57 for (
size_t i = 1; i < result.size() - 1; i++)
59 if (!relativeFilename.empty())
61 relativeFilename +=
"/";
63 relativeFilename += result[i];
66 this->pathToDashboard = relativeFilename;
67 this->dahsboardName = result[result.size() - 1];
71 ARMARX_INFO <<
"Located file at:" << absoluteFilepath;
72 filename = result[result.size() - 1] +
".json";
76 std::ifstream file(absoluteFilepath +
"/" + filename);
77 nlohmann::json jsonData;
86 for (
const auto& item : jsonData[
"shortcuts"])
88 SkillShortcut shortcut;
89 shortcut.skillArgs = item[
"skill_args"].dump(2);
90 shortcut.skillId = item[
"skill_id"];
91 shortcut.shortcutName = item[
"skill_shortcut_name"];
93 this->registeredShortcuts.push_back(shortcut);
109 if (not properties.shortcutPath.empty())
111 loadShortcuts(properties.shortcutPath);
123 return this->registeredShortcuts;
129 for (
const SkillShortcut& shortcut : this->registeredShortcuts)
131 if (shortcut.shortcutName == name)
137 return SkillShortcut();
143 if (newShortcut.shortcutName !=
"")
145 if (
getShortcut(newShortcut.shortcutName).shortcutName ==
"")
148 this->registeredShortcuts.push_back(newShortcut);
149 ARMARX_INFO <<
"Added shortcut " << newShortcut.shortcutName;
153 for (SkillShortcut& shortcut : this->registeredShortcuts)
155 if (shortcut.shortcutName == newShortcut.shortcutName)
157 shortcut.skillId = newShortcut.skillId;
158 shortcut.skillArgs = newShortcut.skillArgs;
169 for (
auto it = this->registeredShortcuts.begin(); it != this->registeredShortcuts.end();
172 if (it->shortcutName == name)
174 this->registeredShortcuts.erase(it);
184 this->shortcutOrder = order;
187 std::vector<std::string>
190 return std::vector<std::string>{
191 this->packageName, this->pathToDashboard, this->dahsboardName};
196 const std::string& folder,
197 const std::string& name,
198 const ::Ice::Current&)
200 std::string path =
package + "/" + folder + "/" + name;
201 return loadShortcuts(path);
206 const std::string& folder,
207 const std::string& name,
208 const ::Ice::Current&)
213 std::unordered_map<std::string, SkillShortcut> lookup;
214 lookup.reserve(registeredShortcuts.size());
215 for (
const auto& s : registeredShortcuts)
217 lookup[s.shortcutName] = s;
221 for (
const auto& name : this->shortcutOrder)
224 auto it = lookup.find(name);
225 if (it == lookup.end())
230 const auto& shortcut = it->second;
232 nlohmann::json skillArgs_json = nlohmann::json::parse(shortcut.skillArgs);
234 j[
"shortcuts"].push_back({{
"skill_shortcut_name", shortcut.shortcutName},
235 {
"skill_id", shortcut.skillId},
236 {
"skill_args", skillArgs_json}});
239 std::string absoluteFilename;
244 std::string packageDataDir = finder.
getDataDir();
248 std::filesystem::create_directories(packageDataDir +
"/" + folder);
250 std::string relativeFilename(folder);
254 ARMARX_INFO <<
"Located file at:" << absoluteFilename;
255 std::string filename = name +
".json";
256 std::ofstream outFile(absoluteFilename +
"/" + filename);
257 outFile << std::setw(4) << j << std::endl;
259 ARMARX_INFO <<
"Insert " <<
package << "/" << folder << "/" << name
260 << " into the component property.";
static bool getAbsolutePath(const std::string &relativeFilename, std::string &storeAbsoluteFilename, const std::vector< std::string > &additionalSearchPaths={}, bool verbose=true)
static void addDataPaths(const std::string &dataPathList)
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getDataDir() const
bool packageFound() const
Returns whether or not this package was found with cmake.
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void onInitComponent() override
bool importShortcuts(const std::string &package, const std::string &folder, const std::string &name, const ::Ice::Current &=::Ice::Current()) override
void deleteShortcut(const std::string &name, const ::Ice::Current &=::Ice::Current()) override
void addNewShortcut(const SkillShortcut &newShortcut, const ::Ice::Current &=::Ice::Current()) override
void onDisconnectComponent() override
SkillShortcut getShortcut(const std::string &name, const ::Ice::Current &=::Ice::Current()) override
SkillShortcutList getShortcuts(const ::Ice::Current &=::Ice::Current()) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void saveShortcutOrder(const std::vector< std::string > &order, const ::Ice::Current &=::Ice::Current()) override
void exportShortcuts(const std::string &package, const std::string &folder, const std::string &name, const ::Ice::Current &=::Ice::Current()) override
void onConnectComponent() override
std::vector< std::string > getPathStructure(const ::Ice::Current &=::Ice::Current()) override
void onExitComponent() override
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.