Commit e7f9e87a authored by Adam Goins's avatar Adam Goins
Browse files

Modified workspace.cpp to attempt to open cube as cube, then as a cubelist, then fail

parent 2169ae05
Loading
Loading
Loading
Loading
+65 −40
Original line number Original line Diff line number Diff line
@@ -331,43 +331,79 @@ namespace Isis {
   *                          as this caused errors when working with cubelists that contained
   *                          as this caused errors when working with cubelists that contained
   *                          relative paths. Fixes # 5177
   *                          relative paths. Fixes # 5177
   */
   */
  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.
      // Check for RGB format (#R,#G,#B)
    if ( cubeFileName.suffix() == "cub" || cubeFileName.suffix() == "cube" || cubeFileName.suffix() == "lbl") {
      if(bands.size() == 3) {
      // cubesToOpen.append(cubeFileName.absoluteFilePath());
        IString st = IString(bands.at(0));
      cubesToOpen.append(cubeFileName.filePath());
        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.
    catch (IException &e) {

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

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

    }

  }

  void Workspace::addCubeViewportFromList(QString cubelist) {

    QFileInfo cubeFileName(cubelist);

    QList<QString> cubesToOpen;

    QFile file(cubename);
    QFile file(cubename);
    file.open(QIODevice::ReadOnly);
    file.open(QIODevice::ReadOnly);


    QTextStream in(&file);
    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() ) {
    while ( !file.atEnd() ) {
      QString line = file.readLine().replace("\n", "");
      QString line = file.readLine().replace("\n", "");
      cubesToOpen.append(line);
      cubesToOpen.append(line);
    }
    }
      file.close();
    }


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


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


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


        // Read in the CubeAttribueInput from the cube name
        // Read in the CubeAttribueInput from the cube name
        CubeAttributeInput inAtt(cubename);
        CubeAttributeInput inAtt(cubename);
@@ -391,20 +427,9 @@ namespace Isis {
        }
        }
      }
      }
      catch (IException &e) {
      catch (IException &e) {
        QString title("Error opening cube from list...");
        QString message("Error attempting to open [" + cubename + "] from list [" + cubelist + "]...\n");
        QString message(e.toString() + "\n\nWould you like to continue?");
        message += e.toString();
        
        throw IException(e, IException::Programmer, message, _FILEINFO_);
        int response = QMessageBox::critical((QWidget *)parent(), 
                                             title, 
                                             message, 
                                             QMessageBox::Yes|QMessageBox::No);
        
        if (response == QMessageBox::Yes) { 
          continue;
        }
        else {
          return;
        }
      }
      }
    }
    }
  }
  }
+32 −28
Original line number Original line Diff line number Diff line
@@ -173,6 +173,10 @@ namespace Isis {
       */
       */
      void addCubeViewport(QString cubename);
      void addCubeViewport(QString cubename);



      void addCubeViewportFromList(QString cubelist)


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