diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp index a02b6bd1031836da23ce9617e7e5f55d7075d2d3..089bd030b541b0938f3d4f944fac4c3ce0b83440 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.cpp @@ -25,7 +25,7 @@ namespace armarx if (packageDataDir.empty()) { ARMARX_WARNING << "Could not find package '" << packageName << "'."; - throw LocalException() << "Could not find package '" << packageName << "'."; + // throw LocalException() << "Could not find package '" << packageName << "'."; } else { @@ -38,6 +38,10 @@ namespace armarx std::optional<ObjectInfo> ObjectFinder::findObject(const std::string& dataset, const std::string& name) const { init(); + if (!_ready()) + { + return std::nullopt; + } if (!dataset.empty()) { return ObjectInfo(packageName, packageDataDir, dataset, name); @@ -88,6 +92,10 @@ namespace armarx std::vector<ObjectFinder::path> ObjectFinder::getDatasetDirectories() const { init(); + if (!_ready()) + { + return {}; + } const bool local = false; std::vector<path> dirs = simox::fs::list_directory(_rootDirAbs(), local); std::vector<path> datasetDirs; @@ -104,6 +112,10 @@ namespace armarx std::vector<ObjectInfo> ObjectFinder::findAllObjects(bool checkPaths) const { init(); + if (!_ready()) + { + return {}; + } const bool local = true; std::vector<ObjectInfo> objects; for (const path& datasetDir : simox::fs::list_directory(_rootDirAbs(), local)) @@ -135,6 +147,10 @@ namespace armarx std::vector<ObjectInfo> ObjectFinder::findAllObjectsOfDataset(const std::string& dataset, bool checkPaths) const { init(); + if (!_ready()) + { + return {}; + } path datasetDir = _rootDirAbs() / dataset; if (!fs::is_directory(datasetDir)) { @@ -169,5 +185,10 @@ namespace armarx return packageName; } + bool ObjectFinder::_ready() const + { + return !packageDataDir.empty(); + } + } diff --git a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h index 3c56afba7a8bba669d95b3afd14438ebeaa00e9f..411edb339943cb7c2334ebfcfb6612009ee0274a 100644 --- a/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h +++ b/source/RobotAPI/libraries/ArmarXObjects/ObjectFinder.h @@ -44,13 +44,18 @@ namespace armarx path _rootDirAbs() const; path _rootDirRel() const; + bool _ready() const; + private: /// Name of package containing the object models (ArmarXObjects by default). mutable std::string packageName; - /// Absolute path to data directory (e.g. "/.../repos/ArmarXObjects/data"). + /** + * @brief Absolute path to data directory (e.g. "/.../repos/ArmarXObjects/data"). + * Empty if package could not be found. + */ mutable path packageDataDir; };