Commit 53ed07ee authored by Summer Stapleton's avatar Summer Stapleton
Browse files

Added functionality to find the most recent (last) version of the camera model. Fixes #386.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7880 41f8697f-d340-4b68-9986-7bafba869bb8
parent 7abcf647
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -141,7 +141,19 @@ namespace Isis {

      PvlGroup plugin;
      try {
        plugin = m_cameraPlugin.findGroup(group);
        bool found = false;
        // Find the most recent (last) version of the camera model
        for (int i = m_cameraPlugin.groups() - 1; i >= 0; i--) {
          if (m_cameraPlugin.group(i) == group) {
            plugin = m_cameraPlugin.group(i);
            found = true;
            break;
          }
        }
        if (!found) {
          QString msg = "Unable to find PVL group [" + group + "].";
          throw IException(IException::Unknown, msg, _FILEINFO_);
        }
      }
      catch(IException &e) {
        QString msg = "Unsupported camera model, unable to find plugin for ";
+3 −1
Original line number Diff line number Diff line
@@ -57,6 +57,8 @@ namespace Isis {
   *   @history 2012-09-06 Steven Lambright - Changed Create() to take
   *                           Cube instead of Pvl because cameras now require cubes to
   *                           construct. Please see Camera for more information.
   *   @history 2017-7-11 Summer Stapleton - Added functionality to find the most recent (last) 
   *                           version of the camera model
   */

  class CameraFactory {
+7 −0
Original line number Diff line number Diff line
@@ -30,3 +30,10 @@ Version: **ERROR** Unable to locate latest camera model version number from grou
**ERROR** Unsupported camera model, unable to find plugin for SpacecraftName [BOGUS SPACECRAFT] with InstrumentId [BOGUS INSTRUMENT].
**ERROR** Unable to find PVL group [BOGUSSPACECRAFT/BOGUSINSTRUMENT].

Testing that newest camera version is read from plugin ...
(Expecting Version 2)
Version: 2

**ERROR** Unable to initialize camera model from group [Instrument].
**ERROR** The camera model used to create a camera for this cube is out of date, please re-run spiceinit on the file or process with an old Isis version that has the correct camera model.
+30 −0
Original line number Diff line number Diff line
@@ -14,6 +14,21 @@ void doit(Cube &cube);
int main(int argc, char *argv[]) {
  Preference::Preferences(true);

  // Get system's Camera.plugin file and add two new cameras of the same name to the bottom of 
  // Camera.plugin with different version numbers
  Pvl pluginFile;
  FileName systemFile("$ISISROOT/lib/Camera.plugin");
  if (systemFile.fileExists()) {
    pluginFile.read(systemFile.expanded());
  }
  PvlGroup oldCamera = PvlGroup("BOGUS/BOGUS");
  PvlGroup newCamera = PvlGroup("BOGUS/BOGUS");
  oldCamera += PvlKeyword("Version", "1");
  newCamera += PvlKeyword("Version", "2");
  pluginFile.addGroup(oldCamera);
  pluginFile.addGroup(newCamera);
  pluginFile.write("Camera.plugin");
  
  cerr << "Unit test for CameraFactory" << endl;
  cerr << "Testing missing Instrument Group ..." << endl;
  Cube dummyCube("$base/testData/isisTruth.cub", "r");
@@ -34,6 +49,20 @@ int main(int argc, char *argv[]) {
  cerr << "Testing unsupported camera mode ..." << endl;
  inst += PvlKeyword("InstrumentId", "Bogus Instrument");
  doit(dummyCube);

  // Create a new label from the same cube and add keywords to match cameras added to the plugin
  // file above
  cerr << "Testing that newest camera version is read from plugin ..." << endl;
  Cube dummyCube2("$base/testData/isisTruth.cub", "r");
  Pvl &lab2 = *dummyCube2.label();
  lab2.addGroup(PvlGroup("Kernels"));
  lab2.addGroup(PvlGroup("Instrument"));
  PvlGroup &inst2 = lab2.findGroup("Instrument");
  inst2 += PvlKeyword("SpacecraftName", "Bogus");
  inst2 += PvlKeyword("InstrumentId", "Bogus");
  cout << "(Expecting Version 2)" << endl;
  doit(dummyCube2);
  remove("Camera.plugin");
}

void doit(Cube &cube) {
@@ -63,3 +92,4 @@ void doit(Cube &cube) {