From 535c5a5ff152e0c0352b077238ebf0effcdf4cdd Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Sat, 12 Nov 2022 20:45:01 +0000 Subject: [PATCH] Scenery data attribution - sources.xml Read a sources.xml file in Scenery directories and copy into the property tree under /scenery/sources Expected format: Corine Land Cover (CLC) 2018, Version 2020_20u1 http://web.archive.org/web/20221112175615/https://land.copernicus.eu/pan-european/corine-land-cover/clc2018?tab=metadata%2A GMES Open License NASADEM Merged DEM Global 1 arc second V001 https://www.earthdata.nasa.gov/ Public Domain OpenStreetMap https://www.openstreetmap.org/copyright Open Data Commons Open Database License --- src/Main/globals.cxx | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index d95acd6ef..445c76d36 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -402,7 +402,7 @@ void FGGlobals::append_fg_scenery (const SGPath &path) return; } - // tell the ResouceManager about the scenery path + // tell the ResourceManager about the scenery path // needed to load Models from this scenery path simgear::ResourceManager::instance()->addBasePath(abspath, simgear::ResourceManager::PRIORITY_DEFAULT); @@ -416,6 +416,35 @@ void FGGlobals::append_fg_scenery (const SGPath &path) // temporary fix so these values survive reset n->setAttribute(SGPropertyNode::PRESERVE, true); + + // Add any sources.xml file to the property tree so we can provide attribution through the GUI + SGPath sources = SGPath(abspath); + sources.append("sources.xml"); + SG_LOG(SG_TERRAIN, SG_DEBUG, "Looking for source file " << sources << ". Exists ? " << sources.exists()); + if (sources.exists()) { + // Determine the next free indice under /scenery/sources + SGPropertyNode* sourcesProp = fgGetNode("/scenery/sources", true); + int propIndex = 0; + while (sourcesProp->getChild("directory", propIndex) != NULL) { + ++propIndex; + } + + sourcesProp = sourcesProp->getChild("directory", propIndex++, true); + + // Add a reference to the path itself + sourcesProp->setStringValue("path", abspath.utf8Str()); + + // Now load the sources file into /scenery/sources/source[n] + if(!fgLoadProps(sources.utf8Str(), sourcesProp, false)) + { + SG_LOG(SG_TERRAIN, SG_ALERT, "Unable to load sources file " << sources.utf8Str()); + } + + // Ensure these properties cannot be over-ridden, and preserve them across a reset. + sourcesProp->setAttribute(SGPropertyNode::WRITE, false); + sourcesProp->setAttribute(SGPropertyNode::PRESERVE, true); + } + } void FGGlobals::append_read_allowed_paths(const SGPath &path)