Commit b3a72dfd authored by Marjorie Hahn's avatar Marjorie Hahn
Browse files

Prevented cneteditor from crashing when attempting to open nonexistent files...

Prevented cneteditor from crashing when attempting to open nonexistent files and added accompanying error messages. Fixes #2363

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6887 41f8697f-d340-4b68-9986-7bafba869bb8
parent b9ab5a64
Loading
Loading
Loading
Loading
+38 −10
Original line number Diff line number Diff line
@@ -41,7 +41,9 @@ using namespace boost::numeric::ublas;


namespace Isis {
  
  void ControlNet::nullify() {
    
    points = NULL;
    cubeGraphNodes = NULL;
    pointIds = NULL;
@@ -50,6 +52,7 @@ namespace Isis {

  //!Creates an empty ControlNet object
  ControlNet::ControlNet() {
    
    nullify();

    points = new QHash< QString, ControlPoint * >;
@@ -64,6 +67,7 @@ namespace Isis {


  ControlNet::ControlNet(const ControlNet &other) {
    
    nullify();

    points = new QHash< QString, ControlPoint * >;
@@ -97,6 +101,7 @@ namespace Isis {
   * @param progress A pointer to the progress of reading in the control points
   */
  ControlNet::ControlNet(const QString &ptfile, Progress *progress) {
    
    nullify();

    points = new QHash< QString, ControlPoint * >;
@@ -105,8 +110,14 @@ namespace Isis {

    p_invalid = false;
    m_ownPoints = true;
    
    try {
      ReadControl(ptfile, progress);
    }
    catch (IException &e) {
      p_invalid = true;
    }
  }


 /**
@@ -115,6 +126,7 @@ namespace Isis {
  * @author Kris Becker 
  */
  ControlNet::~ControlNet() {
    
    clear();

    delete points;
@@ -187,6 +199,7 @@ namespace Isis {
   * @return QList<ControlPoint*> Returns the list of all control points to caller
   */
    QList< ControlPoint * > ControlNet::take() {
      
      // First check to see if someone else has taken ownership
      if (!m_ownPoints) {
        throw IException(IException::Programmer, "Ownership has already been taken",
@@ -228,6 +241,7 @@ namespace Isis {
   *
   */
  void ControlNet::ReadControl(const QString &filename, Progress *progress) {
    
    LatestControlNetFile *fileData = ControlNetVersioner::Read(filename);

    ControlNetFileHeaderV0002 &header = fileData->GetNetworkHeader();
@@ -319,8 +333,8 @@ namespace Isis {
   *
   * @param point Control point to be added
   *
   * @throws Isis::IException::Programmer - "ControlPoint must
   *             have unique Id"
   * @throws IException::Programmer "Null pointer passed to ControlNet::AddPoint!"
   * @throws IException::Programmer "ControlPoint must have unique Id"
   */
  void ControlNet::AddPoint(ControlPoint *point) {
    if (!point) {
@@ -354,6 +368,11 @@ namespace Isis {
   * this measure as its first.
   *
   * @param measure The measure added to the network.
   * 
   * @throws IException::Programmer "NULL measure passed to ControlNet::AddControlCubeGraphNode!"
   * @throws IException::Programmer "Control measure with NULL parent passed to 
   *     ControlNet::AddControlCubeGraphNode!"
   * @throws IException::Programmer "ControlNet does not contain the point."
   */
  void ControlNet::measureAdded(ControlMeasure *measure) {
    if (!measure) {
@@ -412,6 +431,12 @@ namespace Isis {
   * measure's serial number to reflect the unignoration.
   *
   * @param measure The measure unignored from the network.
   * 
   * @throws IException::Programmer "NULL measure passed to ControlNet::AddControlCubeGraphNode!"
   * @throws IException::Programmer "Control measure with NULL parent passed to 
   *     ControlNet::AddControlCubeGraphNode!"
   * @throws IException::Programmer "ControlNet does not contain the point."
   * @throws IException::Programmer "Node does not exist for the cube serial number."
   */
  void ControlNet::measureUnIgnored(ControlMeasure *measure) {
    if (!measure) {
@@ -509,6 +534,7 @@ namespace Isis {
    }
  }

  
  void ControlNet::measureIgnored(ControlMeasure *measure) {
    if (!measure) {
      IString msg = "NULL measure passed to "
@@ -625,6 +651,7 @@ namespace Isis {
   *          second element is the number of critical edges.
   */
  QPair< int, int > ControlNet::CalcBWAndCE(QList< QString > serials) const {
    
    for (int i = 0; i < serials.size(); i++)
      ASSERT(cubeGraphNodes->contains(serials[i]));

@@ -679,6 +706,8 @@ namespace Isis {
   * Delete a ControlPoint from the network using the point's Id.
   *
   * @param pointId The Point Id of the ControlPoint to be deleted.
   * 
   * @throw IException::User "the point Id does not exist in the network"
   */
  int ControlNet::DeletePoint(QString pointId) {
    if (!points->contains(pointId)) {
@@ -984,7 +1013,6 @@ namespace Isis {
  }



  /**
   * Used for verifying graph intergrity
   *
@@ -1072,7 +1100,6 @@ namespace Isis {
  }



  /**
   * The () operator for the Control Measure less than functor
   * 
@@ -1086,6 +1113,7 @@ namespace Isis {

  }

  
  /**
   * Get a sorted list of all the measures that have values in a given ragen
   *
+152 −140
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
using namespace std;

namespace Isis {
  
  /**
   * Read the control network from disk. This will always return the network in
   *   its "latest version" binary form. Generally this will only be called by
@@ -36,8 +37,8 @@ namespace Isis {
   * @param networkFileName The filename of the cnet to be read
   *
   */
  LatestControlNetFile *ControlNetVersioner::Read(
      const FileName &networkFileName) {
  LatestControlNetFile *ControlNetVersioner::Read(const FileName &networkFileName) {
    
    try {
      Pvl network(networkFileName.expanded());

@@ -70,6 +71,7 @@ namespace Isis {
   */
  void ControlNetVersioner::Write(const FileName &file,
      const LatestControlNetFile &fileData, bool pvl) {
    
    if (pvl) {
      fileData.toPvl().write(file.expanded());
    }
@@ -96,6 +98,7 @@ namespace Isis {
   * @param pvl The pvl network obtained from Pvl::Read on the input filename
   */
  LatestControlNetFile *ControlNetVersioner::ReadPvlNetwork(Pvl pvl) {
    
    PvlObject &network = pvl.findObject("ControlNetwork");

    if (!network.hasKeyword("Version"))
@@ -150,8 +153,8 @@ namespace Isis {
   *
   * @param network The input PVL Control Network to convert
   */
  LatestControlNetFile *ControlNetVersioner::LatestPvlToBinary(
      PvlObject &network) {
  LatestControlNetFile *ControlNetVersioner::LatestPvlToBinary(PvlObject &network) {
    
    LatestControlNetFile *latest = new LatestControlNetFile;

    ControlNetFileHeaderV0002 &header = latest->GetNetworkHeader();
@@ -259,8 +262,7 @@ namespace Isis {
          point.set_aprioriradiussource(ControlPointFileEntryV0002::User);
        }
        else if (source == "AverageOfMeasures") {
          point.set_aprioriradiussource(
              ControlPointFileEntryV0002::AverageOfMeasures);
          point.set_aprioriradiussource(ControlPointFileEntryV0002::AverageOfMeasures);
        }
        else if (source == "Ellipsoid") {
          point.set_aprioriradiussource(ControlPointFileEntryV0002::Ellipsoid);
@@ -269,8 +271,7 @@ namespace Isis {
          point.set_aprioriradiussource(ControlPointFileEntryV0002::DEM);
        }
        else if (source == "BundleSolution") {
          point.set_aprioriradiussource(
              ControlPointFileEntryV0002::BundleSolution);
          point.set_aprioriradiussource(ControlPointFileEntryV0002::BundleSolution);
        }
        else {
          std::string msg = "Invalid AprioriRadiusSource, [" + source + "]";
@@ -349,11 +350,9 @@ namespace Isis {
        else if (type == "manual")
          measure.set_type(ControlPointFileEntryV0002::Measure::Manual);
        else if (type == "registeredpixel")
          measure.set_type(
              ControlPointFileEntryV0002::Measure::RegisteredPixel);
          measure.set_type(ControlPointFileEntryV0002::Measure::RegisteredPixel);
        else if (type == "registeredsubpixel")
          measure.set_type(
              ControlPointFileEntryV0002::Measure::RegisteredSubPixel);
          measure.set_type(ControlPointFileEntryV0002::Measure::RegisteredSubPixel);
        else
          throw IException(IException::Io,
                           "Unknown measure type [" + type + "]",
@@ -396,8 +395,9 @@ namespace Isis {
   * @param filename The file that contains the binary network
   * @return In-memory representation of the network
   */
  LatestControlNetFile *ControlNetVersioner::ReadBinaryNetwork(
      const Pvl &header, const FileName &filename) {
  LatestControlNetFile *ControlNetVersioner::ReadBinaryNetwork(const Pvl &header,
                                                               const FileName &filename) {
    
    // Find the binary cnet version by any means necessary
    int version = 1;

@@ -458,8 +458,8 @@ namespace Isis {
   *
   * @param network Input is Version 1, must be modified to conform to Version 2
   */
  void ControlNetVersioner::ConvertVersion1ToVersion2(
      PvlObject &network) {
  void ControlNetVersioner::ConvertVersion1ToVersion2(PvlObject &network) {
    
    network["Version"] = "2";

    // Really... Projection::TargetRadii should be making this call
@@ -616,12 +616,10 @@ namespace Isis {

        SurfacePoint tmp;
        tmp.SetRadii(equatorialRadius, equatorialRadius, polarRadius);
        tmp.SetRectangular(
            Displacement(cp["AdjustedX"], Displacement::Meters),
        tmp.SetRectangular(Displacement(cp["AdjustedX"], Displacement::Meters),
                           Displacement(cp["AdjustedY"], Displacement::Meters),
                           Displacement(cp["AdjustedZ"], Displacement::Meters));
        tmp.SetSphericalSigmasDistance(
          Distance(sigmaLat, Distance::Meters),
        tmp.SetSphericalSigmasDistance(Distance(sigmaLat, Distance::Meters),
                                       Distance(sigmaLon, Distance::Meters),
                                       Distance(sigmaRad, Distance::Meters));

@@ -695,12 +693,12 @@ namespace Isis {

            cm["MeasureType"] = "Candidate";
          }
          else if(type == "automatic" || type == "validatedmanual" ||
          else if (type == "automatic" || 
                   type == "validatedmanual" ||
                   type == "automaticpixel") {
            cm["MeasureType"] = "RegisteredPixel";
          }
          else if(type == "validatedautomatic" ||
                  type == "automaticsubpixel") {
          else if (type == "validatedautomatic" || type == "automaticsubpixel") {
            cm["MeasureType"] = "RegisteredSubPixel";
          }
        }
@@ -741,7 +739,6 @@ namespace Isis {
  }



  /**
   * This converts pvl networks from their version 2 to version 3.
   *
@@ -749,8 +746,8 @@ namespace Isis {
   *
   * @param network Input is Version 2, must be modified to conform to Version 3
   */
  void ControlNetVersioner::ConvertVersion2ToVersion3(
      PvlObject &network) {
  void ControlNetVersioner::ConvertVersion2ToVersion3(PvlObject &network) {
    
    network["Version"] = "3";

    for (int cpIndex = 0; cpIndex < network.objects(); cpIndex ++) {
@@ -770,8 +767,8 @@ namespace Isis {
   *
   * @param network Input is Version 3, must be modified to conform to Version 4
   */
  void ControlNetVersioner::ConvertVersion3ToVersion4(
      PvlObject &network) {
  void ControlNetVersioner::ConvertVersion3ToVersion4(PvlObject &network) {
    
    network["Version"] = "4";

    for (int cpIndex = 0; cpIndex < network.objects(); cpIndex ++) {
@@ -797,14 +794,17 @@ namespace Isis {
   * @param setter The protocol buffer setter method
   */
  void ControlNetVersioner::Copy(PvlContainer &container,
      QString keyName, ControlPointFileEntryV0002 &point,
                                 QString keyName, 
                                 ControlPointFileEntryV0002 &point,
                                 void (ControlPointFileEntryV0002::*setter)(bool)) {
    
    if (!container.hasKeyword(keyName))
      return;

    QString value = container[keyName][0];
    container.deleteKeyword(keyName);
    value = value.toLower();
    
    if (value == "true" || value == "yes")
      (point.*setter)(true);
  }
@@ -824,8 +824,10 @@ namespace Isis {
   * @param setter The protocol buffer setter method
   */
  void ControlNetVersioner::Copy(PvlContainer &container,
      QString keyName, ControlPointFileEntryV0002 &point,
                                 QString keyName, 
                                 ControlPointFileEntryV0002 &point,
                                 void (ControlPointFileEntryV0002::*setter)(double)) {
    
    if (!container.hasKeyword(keyName))
      return;

@@ -849,8 +851,10 @@ namespace Isis {
   * @param setter The protocol buffer setter method
   */
  void ControlNetVersioner::Copy(PvlContainer &container,
      QString keyName, ControlPointFileEntryV0002 &point,
                                 QString keyName, 
                                 ControlPointFileEntryV0002 &point,
                                 void (ControlPointFileEntryV0002::*setter)(const std::string&)) {
    
    if (!container.hasKeyword(keyName))
      return;

@@ -873,15 +877,18 @@ namespace Isis {
   * @param measure The protocol buffer point instance to set the value in
   * @param setter The protocol buffer setter method
   */
  void ControlNetVersioner::Copy(PvlContainer &container, QString keyName,
  void ControlNetVersioner::Copy(PvlContainer &container, 
                                 QString keyName,
                                 ControlPointFileEntryV0002::Measure &measure,
                                 void (ControlPointFileEntryV0002::Measure::*setter)(bool)) {
    
    if (!container.hasKeyword(keyName))
      return;

    QString value = container[keyName][0];
    container.deleteKeyword(keyName);
    value = value.toLower();
    
    if (value == "true" || value == "yes")
      (measure.*setter)(true);
  }
@@ -900,9 +907,11 @@ namespace Isis {
   * @param measure The protocol buffer point instance to set the value in
   * @param setter The protocol buffer setter method
   */
  void ControlNetVersioner::Copy(PvlContainer &container, QString keyName,
  void ControlNetVersioner::Copy(PvlContainer &container, 
                                 QString keyName,
                                 ControlPointFileEntryV0002::Measure &measure,
                                 void (ControlPointFileEntryV0002::Measure::*setter)(double)) {
    
    if (!container.hasKeyword(keyName))
      return;

@@ -925,9 +934,12 @@ namespace Isis {
   * @param measure The protocol buffer point instance to set the value in
   * @param set The protocol buffer setter method
   */
  void ControlNetVersioner::Copy(PvlContainer &container, QString keyName,
  void ControlNetVersioner::Copy(PvlContainer &container, 
                                 QString keyName,
                                 ControlPointFileEntryV0002::Measure &measure,
      void (ControlPointFileEntryV0002::Measure::*set)(const std::string &)) {
                                 void (ControlPointFileEntryV0002::Measure::*set)
                                      (const std::string &)) {
    
    if (!container.hasKeyword(keyName))
      return;

+65 −21
Original line number Diff line number Diff line
@@ -35,12 +35,13 @@
#include "CnetDisplayProperties.h"
#include "CnetEditorWidget.h"


using std::endl;

namespace Isis {
  
  CnetEditorFileDialog::CnetEditorFileDialog(QLayout *l,
      QWidget *parent) : QFileDialog(parent) {

    setAcceptMode(AcceptSave);
    setNameFilter("Control Network files (*.net *.bin);;All files (*)");
    QGridLayout *mainLayout = qobject_cast< QGridLayout * >(layout());
@@ -92,17 +93,40 @@ namespace Isis {
    QStringList args = QApplication::arguments();
    args.removeFirst();
    
    // Can only load two file at a time
    if (args.size() > 2) {
      QString msg = tr("Cannot open more than one .net file and one .lis file at a time.");
      std::cerr << msg << endl;
      QMessageBox::warning(this, tr("Unable to Open Files"), msg);
    }
    else {
      // Check for invalid file extensions
      foreach (QString arg, args) {
        QString extension = QFileInfo(arg).suffix(); 
        if (extension.compare("net") != 0 && extension.compare("lis") != 0) {
          args.removeAll(arg);
          QString msg = tr("Invalid file extension [%1]. "
                           "Expected .net or .lis.").arg(arg);
          std::cerr << msg << endl;
          QMessageBox::warning(this, tr("Invalid File Extension"), msg);
        }
      }
      // Prevent multiple files of the same type from loading
      if (args.size() == 2 && QFileInfo(args[0]).suffix() == QFileInfo(args[1]).suffix()) {
        QString msg = tr("Cannot open two [%1] files.").arg(args[0]);
        std::cerr << msg << endl;
        QMessageBox::warning(this, tr("Unable to Open Files"), msg);
      }
      // Load file(s)
      else if (args.size() != 0) {
        foreach (QString arg, args) {
          QString extension = QFileInfo(arg).suffix();

            if (extension == "net")
              load(arg);
            else if (extension == "lis")
              loadCubeList(arg);
      else
        QMessageBox::warning(this, tr("Unrecognized Argument"),
            tr("Could not determine the type of file [%1]. Expected .net or "
                ".lis.").arg(arg));
        }
      }
    }
  }

@@ -346,6 +370,7 @@ namespace Isis {


  void CnetEditorWindow::readSettings() {
    
    QSettings settings(FileName(
        "$HOME/.Isis/cneteditor/cneteditor.config").expanded(),
        QSettings::NativeFormat);
@@ -363,6 +388,7 @@ namespace Isis {


  void CnetEditorWindow::writeSettings() {
    
    QSettings settings(FileName(
        "$HOME/.Isis/cneteditor/cneteditor.config").expanded(),
        QSettings::NativeFormat);
@@ -431,6 +457,7 @@ namespace Isis {

  void CnetEditorWindow::setFileState(CnetEditorWindow::FileState state,
      QString filename) {
    
    switch (state) {
      case HasFile:
        centralWidget()->layout()->addWidget(editorWidget);
@@ -470,6 +497,7 @@ namespace Isis {


  void CnetEditorWindow::load(QString filename) {
        
    try {      
      cnetReader = new ConcurrentControlNetReader;

@@ -481,17 +509,22 @@ namespace Isis {
              this, SLOT(networkLoaded(QList<Control *>)));

      cnetReader->read(filename);
      
      setFileState(FileLoading, filename);
    }
    catch (IException &) {
      QMessageBox::critical(this, tr("cneteditor"),
          tr("Failed to open the file provided"));
    catch (IException &e) {
      QString msg = tr("Failed to open the file [%1].").arg(filename);
      std::cerr << msg << endl;
      QMessageBox::critical(this, tr("cneteditor"), msg);
      setFileState(NoFile, "");
    }
  }


  void CnetEditorWindow::loadCubeList(QString filename) {
    
    try {
 
    ASSERT(displayProperties);

    connect(displayProperties, SIGNAL(composeProgressRangeChanged(int, int)),
@@ -507,6 +540,13 @@ namespace Isis {
    displayProperties->setCubeList(filename);
    *cubeListFile = filename;
    }
    catch (IException &e) {
      QString msg = tr("Failed to open the file [%1].").arg(filename);
      std::cerr << msg << endl;
      QMessageBox::critical(this, tr("cneteditor"), msg);
      setFileState(NoFile, "");
    }
  }


  void CnetEditorWindow::save() {
@@ -657,6 +697,7 @@ namespace Isis {


  void CnetEditorWindow::networkLoaded(ControlNet *net) {
    
    cnet = net;
    editorWidget = new CnetEditorWidget(cnet, FileName(
        "$HOME/.Isis/cneteditor/cneteditor.config").expanded());
@@ -693,6 +734,7 @@ namespace Isis {


  void CnetEditorWindow::populateMenus() {
    
    QMap< QAction *, QList< QString > > actionMap;
    actionMap = editorWidget->menuActions();
    QMapIterator< QAction *, QList< QString > > i(actionMap);
@@ -741,6 +783,7 @@ namespace Isis {

  int CnetEditorWindow::indexOfActionList(QList< QAction * > actionList,
      QString actionText) {
    
    int index = -1;
    for (int i = 0; index == -1 && i < actionList.size(); i++)
      if (actionList[i]->text() == actionText)
@@ -787,6 +830,7 @@ namespace Isis {


  int CnetEditorWindow::indexOfToolBar(QString objName) {
    
    ASSERT(toolBars);

    int index = -1;
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ namespace Isis {
  class CnetEditorWidget;
  class ProgressBar;

  
  /**
   * This is the cneteditor program.
   *
+2 −2
Original line number Diff line number Diff line
@@ -203,14 +203,14 @@ namespace Isis {
    if (!imageListFile.exists()) {
      IString msg = "The file [";
      msg += (IString) fileName;
      msg += "does not exist.\n";
      msg += "] does not exist.\n";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

    if (!imageListFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
      IString msg = "The file [";
      msg += (IString) fileName;
      msg += "failed to open.\n";
      msg += "] failed to open.\n";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }

Loading