Skip to content
Snippets Groups Projects
Unverified Commit 4d7ef35c authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

remove the need to specify model and plugin (#5729)

parent 75682c16
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ ctest FunctionalTestJigsawApollo to validate this output. [#5710](https://github ...@@ -42,6 +42,7 @@ ctest FunctionalTestJigsawApollo to validate this output. [#5710](https://github
- Added support for reading, writing, and viewing GeoTIFFs in ISIS. [#5618](https://github.com/DOI-USGS/ISIS3/pull/5618) - Added support for reading, writing, and viewing GeoTIFFs in ISIS. [#5618](https://github.com/DOI-USGS/ISIS3/pull/5618)
### Changed ### Changed
- Enhanced csminit by removing the need to specify model and plugin [#5585](https://github.com/DOI-USGS/ISIS3/issues/5585)
### Fixed ### Fixed
- Fixed kaguyatc2isis invalid BandBin values [#5629](https://github.com/DOI-USGS/ISIS3/issues/5629) - Fixed kaguyatc2isis invalid BandBin values [#5629](https://github.com/DOI-USGS/ISIS3/issues/5629)
......
...@@ -169,12 +169,62 @@ namespace Isis { ...@@ -169,12 +169,62 @@ namespace Isis {
buffer << file.rdbuf(); buffer << file.rdbuf();
QString stateString = QString::fromStdString(buffer.str()); QString stateString = QString::fromStdString(buffer.str());
if (!ui.WasEntered("PLUGINNAME") && !ui.WasEntered("MODELNAME")) { QList<QStringList> possibleModels;
QString message = "When using a State string, PLUGINNAME and MODELNAME must be specified"; for (const csm::Plugin * plugin : csm::Plugin::getList()) {
QString currentPluginName = QString::fromStdString(plugin->getPluginName());
if (ui.WasEntered("PLUGINNAME") && currentPluginName != ui.GetString("PLUGINNAME")) {
continue;
}
for (size_t modelIndex = 0; modelIndex < plugin->getNumModels(); modelIndex++) {
QString currentModelName = QString::fromStdString(plugin->getModelName(modelIndex));
if (ui.WasEntered("MODELNAME") && currentModelName != ui.GetString("MODELNAME")) {
continue;
}
if (plugin->canModelBeConstructedFromState(currentModelName.toStdString(), stateString.toStdString())){
QStringList modelSpec = {
currentPluginName,
currentModelName};
possibleModels.append(modelSpec);
continue;
}
}
}
if (possibleModels.size() > 1) {
QString message = "Multiple models can be created from the State [" + stateFilePath.toString() + "]. "
"Re-run with the PLUGINNAME and MODELNAME parameters. "
"Possible plugin & model names:\n";
for (const QStringList &modelSpec : possibleModels) {
message += "Plugin [" + modelSpec[0] + "], Model [" + modelSpec[1] + "]\n";
}
throw IException(IException::User, message, _FILEINFO_);
}
if (possibleModels.empty()) {
QString message = "No loaded model could be created from the State [" + stateFilePath.toString() + "]."
"Loaded plugin & model names:\n";
for (const csm::Plugin * plugin : csm::Plugin::getList()) {
QString currentPluginName = QString::fromStdString(plugin->getPluginName());
for (size_t modelIndex = 0; modelIndex < plugin->getNumModels(); modelIndex++) {
QString modelName = QString::fromStdString(plugin->getModelName(modelIndex));
message += "Plugin [" + currentPluginName + "], Model [" + modelName + "]\n";
}
}
throw IException(IException::User, message, _FILEINFO_);
}
// If we are here, then we have exactly 1 model
QStringList modelSpec = possibleModels.front();
if (modelSpec.size() != 2) {
QString message = "Model specification [" + modelSpec.join(" ") + "] has [" + modelSpec.size() + "] elements "
"when it should have 2 elements.";
throw IException(IException::Programmer, message, _FILEINFO_); throw IException(IException::Programmer, message, _FILEINFO_);
} }
pluginName = ui.GetString("PLUGINNAME"); pluginName = modelSpec[0];
modelName = ui.GetString("MODELNAME"); modelName = modelSpec[1];
const csm::Plugin *plugin = csm::Plugin::findPlugin(pluginName.toStdString()); const csm::Plugin *plugin = csm::Plugin::findPlugin(pluginName.toStdString());
if (plugin == NULL) { if (plugin == NULL) {
......
...@@ -428,31 +428,13 @@ TEST_F(CSMPluginFixture, CSMInitStateStringFails) { ...@@ -428,31 +428,13 @@ TEST_F(CSMPluginFixture, CSMInitStateStringFails) {
csminit(options); csminit(options);
} }
catch (IException &e) { catch (IException &e) {
EXPECT_THAT(e.what(), testing::HasSubstr("When using a State string, PLUGINNAME and MODELNAME must be specified")); EXPECT_THAT(e.what(), testing::HasSubstr("No loaded model could be created from the State"));
}
QVector<QString> argsWithModel = {
"from="+filename,
"state="+statePath,
"modelname=TestCsmModel",
"pluginname=TestCsmPlugin"};
UserInterface optionsWithModel(APP_XML, argsWithModel);
// Expect a failure due to a bad state string.
try {
csminit(optionsWithModel);
}
catch (IException &e) {
EXPECT_THAT(e.what(), testing::HasSubstr("Could not construct sensor model using STATE string and MODELNAME"));
} }
QVector<QString> argsWithIsdAndState = { QVector<QString> argsWithIsdAndState = {
"from="+filename, "from="+filename,
"isd=fakePath", "isd=fakePath",
"state="+statePath, "state="+statePath};
"modelname=TestCsmModel",
"pluginname=TestCsmPlugin"};
UserInterface optionsWithIsdAndState(APP_XML, argsWithIsdAndState); UserInterface optionsWithIsdAndState(APP_XML, argsWithIsdAndState);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment