Browse Source

imageconverter,sceneconverter: support option subgroups as well.

pull/441/head
Vladimír Vondruš 6 years ago
parent
commit
fb32dd4c0e
  1. 5
      src/Magnum/MeshTools/sceneconverter.cpp
  2. 20
      src/Magnum/Trade/Implementation/converterUtilities.h
  3. 5
      src/Magnum/Trade/imageconverter.cpp

5
src/Magnum/MeshTools/sceneconverter.cpp

@ -94,7 +94,8 @@ and images present in the file. **This option is currently mandatory.**
The `-i` / `--importer-options` and `-c` / `--converter-options` arguments
accept a comma-separated list of key/value pairs to set in the importer /
converter plugin configuration. If the `=` character is omitted, it's
equivalent to saying `key=true`.
equivalent to saying `key=true`; configuration subgroups are delimited with
`/`.
@see @ref magnum-imageconverter
*/
@ -147,7 +148,7 @@ images present in the file.
The -i / --importer-options and -c / --converter-options arguments accept a
comma-separated list of key/value pairs to set in the importer / converter
plugin configuration. If the = character is omitted, it's equivalent to saying
key=true.)")
key=true; configuration subgroups are delimited with /.)")
.parse(argc, argv);
PluginManager::Manager<Trade::AbstractImporter> importerManager{

20
src/Magnum/Trade/Implementation/converterUtilities.h

@ -46,20 +46,34 @@ void setOptions(PluginManager::AbstractPlugin& plugin, const std::string& option
Utility::String::trimInPlace(keyValue[0]);
Utility::String::trimInPlace(keyValue[2]);
std::vector<std::string> keyParts = Utility::String::split(keyValue[0], '/');
CORRADE_INTERNAL_ASSERT(!keyParts.empty());
Utility::ConfigurationGroup* group = &plugin.configuration();
bool groupNotRecognized = false;
for(std::size_t i = 0; i != keyParts.size() - 1; ++i) {
Utility::ConfigurationGroup* subgroup = group->group(keyParts[i]);
if(!subgroup) {
groupNotRecognized = true;
subgroup = group->addGroup(keyParts[i]);
}
group = subgroup;
}
/* Provide a warning message in case the plugin doesn't define given
option in its default config. The plugin is not *required* to have
those tho (could be backward compatibility entries, for example), so
not an error. */
if(!plugin.configuration().valueCount(keyValue[0]))
if(groupNotRecognized || !group->hasValue(keyParts.back())) {
Warning{} << "Option" << keyValue[0] << "not recognized by" << plugin.plugin();
}
/* If the option doesn't have an =, treat it as a boolean flag that's
set to true. While there's no similar way to do an inverse, it's
still nicer than causing a fatal error with those. */
if(keyValue[1].empty())
plugin.configuration().setValue(keyValue[0], true);
group->setValue(keyParts.back(), true);
else
plugin.configuration().setValue(keyValue[0], keyValue[2]);
group->setValue(keyParts.back(), keyValue[2]);
}
}

5
src/Magnum/Trade/imageconverter.cpp

@ -99,7 +99,8 @@ need to be specified.
The `-i` / `--importer-options` and `-c` / `--converter-options` arguments
accept a comma-separated list of key/value pairs to set in the importer /
converter plugin configuration. If the `=` character is omitted, it's
equivalent to saying `key=true`.
equivalent to saying `key=true`; configuration subgroups are delimited with
`/`.
@section magnum-imageconverter-example Example usage
@ -168,7 +169,7 @@ be specified.
The -i / --importer-options and -c / --converter-options arguments accept a
comma-separated list of key/value pairs to set in the importer / converter
plugin configuration. If the = character is omitted, it's equivalent to saying
key=true.)")
key=true; configuration subgroups are delimited with /.)")
.parse(argc, argv);
PluginManager::Manager<Trade::AbstractImporter> importerManager{

Loading…
Cancel
Save