diff --git a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp index 98a9587804881ac07f7290053704e26028c23002..9b5d425902f81c834ccca7126091142a7ec9bedb 100644 --- a/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp +++ b/source/RobotAPI/libraries/armem_objects/server/instance/Segment.cpp @@ -957,7 +957,6 @@ namespace armarx::armem::server::obj::instance { if (const std::optional<std::filesystem::path> path = resolveSceneFilepath(filename)) { - ARMARX_INFO << "Storing scene snapshot at: \n" << path.value(); try { @@ -1002,7 +1001,8 @@ namespace armarx::armem::server::obj::instance std::optional<std::filesystem::path> Segment::resolveSceneFilepath(const std::string& _filename) { - std::string filepath = _filename; + std::stringstream log; + std::filesystem::path filepath = _filename; filepath = simox::alg::replace_all( filepath, timestampPlaceholder, Time::Now().toString("%Y-%m-%d_%H-%M-%S")); @@ -1011,37 +1011,37 @@ namespace armarx::armem::server::obj::instance filepath += ".json"; } - // Try to interprete it as relative to 'Package/scenes/'. - if (!finder) + if (filepath.is_absolute()) { - finder.reset(new CMakePackageFinder(p.sceneSnapshotsPackage)); - if (not finder->packageFound()) - { - ARMARX_WARNING << "Could not find CMake package " << p.sceneSnapshotsPackage << "."; - } + return filepath; } - if (finder->packageFound()) + + armarx::PackagePath packagePath = [&filepath, this]() { - std::filesystem::path absDataDir = finder->getDataDir(); - std::filesystem::path absPath = - absDataDir / p.sceneSnapshotsPackage / p.sceneSnapshotsDirectory / filepath; - if (std::filesystem::is_regular_file(absPath)) + if (filepath.has_parent_path()) { - return absPath; + // Interpret the first component as package name. + std::string packageName = *filepath.begin(); + return PackagePath(packageName, std::filesystem::relative(filepath, packageName)); } - } - - // Try to interprete it as ArmarXDataPath. - { - std::string resolved = ArmarXDataPath::resolvePath(filepath); - if (resolved != filepath) + else { - return resolved; + // Only a filename => Interprete it as relative to 'Package/scenes/'. + return PackagePath(p.sceneSnapshotsPackage, p.sceneSnapshotsDirectory / filepath); } - } + }(); - // Else: Fail - return std::nullopt; + try + { + std::filesystem::path systemPath = packagePath.toSystemPath(); + return systemPath; + } + catch (const armarx::PackageNotFoundException& e) + { + ARMARX_INFO << "Could not interpret '" << packagePath.serialize().package + << "' as ArmarX package name (" << e.what() << ")."; + return std::nullopt; + } } armarx::objects::Scene @@ -1191,14 +1191,14 @@ namespace armarx::armem::server::obj::instance infiniteHistory.setValue(data.properties.maxHistorySize == -1); discardSnapshotsWhileAttached.setValue(data.p.discardSnapshotsWhileAttached); - storeLoadLine.setValue("Scene_" + timestampPlaceholder); + std::string storeLoadFilename = "Scene_" + timestampPlaceholder; + std::string storeLoadPath = data.p.sceneSnapshotsPackage + "/" + + data.p.sceneSnapshotsDirectory + "/" + storeLoadFilename; + storeLoadLine.setValue(storeLoadPath); loadButton.setLabel("Load Scene"); storeButton.setLabel("Store Scene"); - HBoxLayout storeLoadLineLayout( - {Label(data.p.sceneSnapshotsPackage + "/" + data.p.sceneSnapshotsDirectory + "/"), - storeLoadLine, - Label(".json")}); + HBoxLayout storeLoadLineLayout({storeLoadLine, Label(".json")}); HBoxLayout storeLoadButtonsLayout({loadButton, storeButton}); GridLayout grid;