Unverified Commit b83b9af5 authored by ihumphrey's avatar ihumphrey Committed by GitHub
Browse files

Merge pull request #432 from AgoinsUSGS/qview_fix

Fixed qview to accept cubes and cube lists under any extension. Fixes m05439 and m05476.
parents 549b0d20 ba2d9656
Loading
Loading
Loading
Loading
+74 −40
Original line number Diff line number Diff line
@@ -330,44 +330,89 @@ namespace Isis {
   *  @history 2017-10-12 Kristin Berry - Reverted to using relative instead of full file paths,
   *                          as this caused errors when working with cubelists that contained
   *                          relative paths. Fixes # 5177
   *  @history 2018-09-12 Adam Goins - Modified logic to attempt to open the file as a cube or
   *                          detached label first, if that fails attempt to open it as a cube list
   *                          and if that fails, throw an error to the user. This allows cubes and
   *                          cube lists to be saved under any extension and opened. Fixes #5439,
   *                          Fixes #5476.
   */
  void Workspace::addCubeViewport(QString cubename) {
  void Workspace::addCubeViewport(QString filename) {

    QFileInfo cubeFileName(cubename);
    QFileInfo cubeFileName(filename);

    QList<QString> cubesToOpen;
    QString cubename = cubeFileName.filePath();

    try {
      Cube *cube = new Cube;

      // Read in the CubeAttribueInput from the cube name
      CubeAttributeInput inAtt(cubename);
      std::vector<QString> bands = inAtt.bands();

      // Set the virtual bands to the bands specified by the input
      cube->setVirtualBands(bands);
      cube->open(cubename);

      MdiCubeViewport *cvp = addCubeViewport(cube);

    // If the file is a cub file, we add the path to it to our list of cubes to open.
    if ( cubeFileName.suffix() == "cub" || cubeFileName.suffix() == "cube" || cubeFileName.suffix() == "lbl") {
      // cubesToOpen.append(cubeFileName.absoluteFilePath());
      cubesToOpen.append(cubeFileName.filePath());
      // Check for RGB format (#R,#G,#B)
      if(bands.size() == 3) {
        IString st = IString(bands.at(0));
        int index_red = st.ToInteger();
        st = IString(bands.at(1));
        int index_green = st.ToInteger();
        st = IString(bands.at(2));
        int index_blue = st.ToInteger();
        cvp->viewRGB(index_red, index_green, index_blue);
      }
    else {
      // If the file received isn't a cube or label, it has to be a cubelist. We read every cube in
      // the cubelist and append it to the cubesToOpen QList so that we can open them.
      QFile file(cubename);
    }

    catch (IException &e) {

      QString message("Error opening cube [" + cubename + "]...\n");
      message += "Attempting to open [" + cubename + "] as a cube list...\n";

      try {
        addCubeViewportFromList(cubename);
      }
      catch (IException &e) {
        message += e.toString();
        throw IException(e, IException::User, message, _FILEINFO_);
      }

    }
  }

  /**
   *  @history 2018-09-12 Adam Goins - Added this method to attempt to open a file as a cube list.
   *                          It's called by addCubeViewport() when that method attempts to open a
   *                          file as a cube but fails. Fixes #5439, Fixes #5476.
   */
  void Workspace::addCubeViewportFromList(QString cubelist) {

    QFileInfo cubeFileName(cubelist);

    QList<QString> cubesToOpen;

    QFile file(cubeFileName.filePath());
    file.open(QIODevice::ReadOnly);

    QTextStream in(&file);

    // Loop through every cube name in the cube list and add it to a list of cubes to open.
    while ( !file.atEnd() ) {
      QString line = file.readLine().replace("\n", "");
      cubesToOpen.append(line);
    }
      file.close();
    }

    if (cubesToOpen.size() == 0){
        QMessageBox::critical((QWidget *)parent(), "Error", "No cubes to open from [" + cubename + "]");
        return;
    }
    file.close();

    for (int i = 0; i < cubesToOpen.size(); i++) {

      QString cubename;
      try {
        Cube *cube = new Cube;
        cubename = cubesToOpen.value(i);
        cubename = cubesToOpen.at(i);

        // Read in the CubeAttribueInput from the cube name
        CubeAttributeInput inAtt(cubename);
@@ -391,20 +436,9 @@ namespace Isis {
        }
      }
      catch (IException &e) {
        QString title("Error opening cube from list...");
        QString message(e.toString() + "\n\nWould you like to continue?");
        
        int response = QMessageBox::critical((QWidget *)parent(), 
                                             title, 
                                             message, 
                                             QMessageBox::Yes|QMessageBox::No);
	       QString message("Error attempting to open [" + cubename + "] from list [" + cubelist + "]...\n");

        if (response == QMessageBox::Yes) { 
          continue;
        }
        else {
          return;
        }
	       throw IException(e, IException::User, message, _FILEINFO_);
      }
    }
  }
+41 −28
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ namespace Isis {
  *                           Fixes #5099.
  *   @history 2018-04-13 Christopher Combs - Added .lbl files to the list of single-cube file-extensions
  *                           to check before reading a cube list in addCubeViewport. Fixes #5350.
  *  @history 2018-09-12 Adam Goins - Modified logic to attempt to open the file as a cube or
  *                          detached label first, if that fails attempt to open it as a cube list
  *                          and if that fails, throw an error to the user. This allows cubes and
  *                          cube lists to be saved under any extension and opened. Fixes #5439,
  *                          Fixes #5476.
  */
  class Workspace : public QWidget {
      Q_OBJECT
@@ -173,6 +178,14 @@ namespace Isis {
       */
      void addCubeViewport(QString cubename);

      /**
       * Method adds cubes into Workspace as a CubeViewport from a list of cubes.
       *
       * @param cubename The name of the cube list file.
       */
      void addCubeViewportFromList(QString cubelist);


      /**
       * Method adds a cube into the Workspace as a CubeViewport.
       *