Skip to content

Commit

Permalink
Merge branch 'gml-read-try-pwd' into 'master'
Browse files Browse the repository at this point in the history
[ogs] -m switch: fallback to reading gml from prj-file directory

See merge request ogs/ogs!4997
  • Loading branch information
TomFischer committed May 8, 2024
2 parents f38c400 + e9deb7d commit be3515c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
36 changes: 25 additions & 11 deletions Applications/ApplicationsLib/ProjectData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,25 @@

namespace
{
void readGeometry(std::string const& fname, GeoLib::GEOObjects& geo_objects)
void readGeometry(std::string const& fname, GeoLib::GEOObjects& geo_objects,
std::string const& dir_first, std::string const& dir_second)
{
DBUG("Reading geometry file '{:s}'.", fname);
GeoLib::IO::BoostXmlGmlInterface gml_reader(geo_objects);
gml_reader.readFile(fname);
std::string geometry_file = BaseLib::copyPathToFileName(fname, dir_first);
if (!BaseLib::IsFileExisting(geometry_file))
{
// Fallback to reading gml from prj-file directory
geometry_file = BaseLib::copyPathToFileName(fname, dir_second);
WARN("File {:s} not found in {:s}! Trying reading from {:s}.", fname,
dir_first, dir_second);
if (!BaseLib::IsFileExisting(geometry_file))
{
OGS_FATAL("Could not read geometry file {:s} in {:s}.", fname,
dir_second);
}
}
gml_reader.readFile(geometry_file);
}

std::unique_ptr<MeshLib::Mesh> readSingleMesh(
Expand Down Expand Up @@ -192,7 +206,8 @@ std::unique_ptr<MeshLib::Mesh> readSingleMesh(
}

std::vector<std::unique_ptr<MeshLib::Mesh>> readMeshes(
BaseLib::ConfigTree const& config, std::string const& directory)
BaseLib::ConfigTree const& config, std::string const& directory,
std::string const& project_directory)
{
std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;

Expand All @@ -213,9 +228,8 @@ std::vector<std::unique_ptr<MeshLib::Mesh>> readMeshes(
//! \ogs_file_param{prj__geometry}
config.getConfigParameterOptional<std::string>("geometry"))
{
std::string const geometry_file =
BaseLib::copyPathToFileName(*geometry_file_name, directory);
readGeometry(geometry_file, geoObjects);
readGeometry(*geometry_file_name, geoObjects, directory,
project_directory);
}
}
else
Expand All @@ -224,11 +238,11 @@ std::vector<std::unique_ptr<MeshLib::Mesh>> readMeshes(
//! \ogs_file_param{prj__mesh}
readSingleMesh(config.getConfigParameter("mesh"), directory));

std::string const geometry_file = BaseLib::copyPathToFileName(
auto const geometry_file_name =
//! \ogs_file_param{prj__geometry}
config.getConfigParameter<std::string>("geometry"),
directory);
readGeometry(geometry_file, geoObjects);
config.getConfigParameter<std::string>("geometry");
readGeometry(geometry_file_name, geoObjects, directory,
project_directory);
}

{ // generate meshes from geometries
Expand Down Expand Up @@ -332,7 +346,7 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
std::string const& output_directory,
std::string const& mesh_directory,
[[maybe_unused]] std::string const& script_directory)
: _mesh_vec(readMeshes(project_config, mesh_directory)),
: _mesh_vec(readMeshes(project_config, mesh_directory, project_directory)),
_named_rasters(readRasters(project_config, project_directory,
GeoLib::AABB(_mesh_vec[0]->getNodes().begin(),
_mesh_vec[0]->getNodes().end())
Expand Down
1 change: 1 addition & 0 deletions Applications/CLI/ogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int main(int argc, char* argv[])
INFO("This is OpenGeoSys-6 version {:s}.",
GitInfoLib::GitInfo::ogs_version);

if (cli_arg.outdir.length() > 0)
{
std::error_code mkdir_err;
if (std::filesystem::create_directories(cli_arg.outdir, mkdir_err))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ int main(int argc, char* argv[])
});

const auto output_directory = output_directory_arg.getValue();
if (output_directory.length() > 0)
{
std::error_code mkdir_err;
if (std::filesystem::create_directories(output_directory, mkdir_err))
Expand Down

0 comments on commit be3515c

Please sign in to comment.