open-rmf / rmf_site

Experimental visualizer for dense buildings in RMF
32 stars 13 forks source link

Fix migrate relative paths computation #214

Closed luca-della-vedova closed 5 months ago

luca-della-vedova commented 5 months ago

Bug fix

Fixed bug

Mostly address #213. Mostly because there is still an issue when migrating between a relative and an absolute path that is not addressed by this PR but that is a bit of a hairier one.

Fix applied

When using the old file name as a path to migrate from, the path would have an additional ../. The previous logic would substitute the filename in the old path and calculate a diff which wouldn't exactly work, for example

# Asset source is Local://scan.png
# OLD PATH:
folder/map/map.building.yaml
# OLD with asset name
folder/map/scan.png
# NEW
folder/map/new_map.site.ron
# Going from NEW path to OLD with asset name through path_diff:
../scan.png

This is wrong and I believe what we should be doing instead is setting NEW to be the folder containing the file, so this PR changes to the following:

# OLD is unchanged
# NEW Is the parent of the passed file:
folder/map
# Diff between folder/map/scan.png and folder/map
scan.png

Test it!

Just run the site editor opening a legacy map then hit Ctrl-S to save it as a site to a new file:

cargo run --release -- ~/rmf_ws/src/demonstrations/rmf_demos/rmf_demos_maps/maps/hotel/hotel.building.yaml

Without this PR, a bunch of errors will be printed showing failure to load the drawings (and the new hotel.site.ron file will have wrong paths:

2024-04-05T04:23:33.918477Z ERROR librmf_site_editor::site::drawing: Failed loading drawing "file://../hotel_L1.png"
2024-04-05T04:23:33.918507Z ERROR librmf_site_editor::site::drawing: Failed loading drawing "file://../hotel_L2.png"
2024-04-05T04:23:33.918516Z ERROR librmf_site_editor::site::drawing: Failed loading drawing "file://../hotel_L3.png"

With this PR the errors will not be present and the file will be correctly exported.