Commit 057044a5 authored by Tyler Wilson's avatar Tyler Wilson
Browse files

TargetInfoWidget no longer triggers a segfault if the spice labels do no...

TargetInfoWidget no longer triggers a segfault if the spice labels do no contain proper target info.  Fixes #4954.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@7891 41f8697f-d340-4b68-9986-7bafba869bb8
parent 356e0ba6
Loading
Loading
Loading
Loading
+157 −70
Original line number Diff line number Diff line
#include "TargetInfoWidget.h"
#include "ui_TargetInfoWidget.h"

#include <QFont>
#include <QFontInfo>
#include <QPixmap>

#include "Directory.h"
@@ -92,11 +93,16 @@ namespace Isis {
   * @return @b QString The poleRightAscensionLabel text
   */
  QString TargetInfoWidget::formatPoleRaString() {

    QString poleRaString = "";

    if (m_target->frameType() != Isis::SpiceRotation::BPC &&
        m_target->frameType() != Isis::SpiceRotation::UNKNOWN ) {

      std::vector<Angle> poleRaCoefs = m_target->poleRaCoefs();
      std::vector<double> poleRaNutPrecCoefs = m_target->poleRaNutPrecCoefs();

      const QChar degChar(0260);
    QString poleRaString = "";
      QString coefLetter = m_target->naifPlanetSystemName().at(0);

      if (poleRaCoefs[1].degrees() < 0.0 ) {
@@ -124,6 +130,15 @@ namespace Isis {
      poleRaString.append(tmp);

      return poleRaString;

      }

    else {
         errorMsg();
         return poleRaString;
    }


  }


@@ -133,11 +148,17 @@ namespace Isis {
   * @return @b QString The poleDeclinationLabel text
   */
  QString TargetInfoWidget::formatPoleDecString() {

    QString poleDecString = "";

    if (m_target->frameType() != Isis::SpiceRotation::BPC &&
        m_target->frameType() != Isis::SpiceRotation::UNKNOWN ) {

      std::vector<Angle> poleDecCoefs = m_target->poleDecCoefs();
      std::vector<double> poleDecNutPrecCoefs = m_target->poleDecNutPrecCoefs();

      const QChar degChar(0260);
    QString poleDecString = "";

      QString coefLetter = m_target->naifPlanetSystemName().at(0);

      if (poleDecCoefs[1].degrees() < 0.0 ) {
@@ -150,7 +171,8 @@ namespace Isis {
      }

      QString tmp;
    int nCoefs = poleDecNutPrecCoefs.size();;
      int nCoefs = poleDecNutPrecCoefs.size();

      for (int i = 0; i < nCoefs; i++) {
        if (poleDecNutPrecCoefs[i] < 0.0 ) {
          tmp.append(tr(" - %1%2%3").arg(-poleDecNutPrecCoefs[i]).arg("cos %1").arg(coefLetter)
@@ -163,10 +185,17 @@ namespace Isis {
      }

      poleDecString.append(tmp);
      return poleDecString;

    }//end if

    else {
          errorMsg();
          return poleDecString;
    }

  }


  /**
   * Make the polePMOffsetLabel text using information from the target.
@@ -174,11 +203,18 @@ namespace Isis {
   * @return @b QString The polePMOffsetLabel text
   */
  QString TargetInfoWidget::formatPmString() {

    QString pmString = "";

    if (m_target->frameType() != Isis::SpiceRotation::BPC &&
        m_target->frameType() != Isis::SpiceRotation::UNKNOWN )
    {

      std::vector<Angle> pmCoefs = m_target->pmCoefs();
      std::vector<double> pmNutPrecCoefs = m_target->pmNutPrecCoefs();

      const QChar degChar(0260);
    QString pmString = "";

      QString coefLetter = m_target->naifPlanetSystemName().at(0);

      if (pmCoefs[1].degrees() < 0.0 ) {
@@ -197,9 +233,9 @@ namespace Isis {
        pmString.append(tr(" + %2d^2").arg(pmCoefs[2].degrees()));
      }


      QString tmp;
    int nCoefs = pmNutPrecCoefs.size();;
      int nCoefs = pmNutPrecCoefs.size();

      for (int i = 0; i < nCoefs; i++) {
        if (pmNutPrecCoefs[i] < 0.0 ) {
          tmp.append(tr(" - %1%2%3").arg(-pmNutPrecCoefs[i]).arg("sin %1").arg(coefLetter).arg(i+1));
@@ -207,10 +243,61 @@ namespace Isis {
        else if (pmNutPrecCoefs[i] > 0.0 ) {
          tmp.append(tr(" + %1%2%3").arg(pmNutPrecCoefs[i]).arg("sin %1").arg(coefLetter).arg(i+1));
        }
    }
      } //end-for

      pmString.append(tmp);
      return pmString;

    }//end outer-if
    else {
         errorMsg();
         return pmString;
    } //end outer else

  }



  /**
   * Displays an error message on the Prime Meridian/Pole Position tabs of the TargetInfoWidget
   * in the event that the target body parameters could not be retrieved from the cube.
   *
   */
  void TargetInfoWidget::errorMsg() {

    QFont font;
    font.setPointSize(9);
    font.setBold(true);
    font.setWeight(75);
    m_ui->label->setFont(font);
    m_ui->label_6->setFont(font);

    QString msg1="";
    QString msg2="";

    m_ui->label->setFont(font);
    m_ui->label_6->setFont(font);
    m_ui->label_2->clear();

    if (m_target->displayProperties()->displayName() == "MOON") {
      msg1 = "Target body parameters cannot be solved for the Moon.";
    }
    else {
              msg2 = "Target body information\n"
                       "is not on the cube labels.\n"
                       "This has no impact on most\n"
                       "operations.  However, to view\n"
                       "or bundle adjust the target body\n"
                       "parameters you will need to rerun\n"
                       "spiceinit.";

              m_ui->label->setText(
                    QApplication::translate("TargetInfoWidget",
                                            msg2.toLatin1().data(), 0));
              m_ui->label_6->setText(
                    QApplication::translate("TargetInfoWidget",
                                            msg2.toLatin1().data(), 0));
    } //end inner-else

  }
}
+6 −0
Original line number Diff line number Diff line
@@ -22,18 +22,24 @@ namespace Isis {
   * @internal
   *   @history 2015-06-13 Ken Edmundson - Original version.
   *   @history 2016-08-25 Adam Paquette - Updated documentation. Fixes #4299.
   *   @history 2017-07-27 Tyler Wilson and Summer Stapleton - IPCE no longer crashes in the event
   *                                   that the spice cube labels do not contain the proper
   *                                   target info.  Fixes #4954.
   *
   */

  class TargetInfoWidget : public QFrame {
    Q_OBJECT

    public:

      explicit TargetInfoWidget(TargetBody* target, Directory *directory, QWidget *parent = 0);
      ~TargetInfoWidget();

    private:
      Ui::TargetInfoWidget *m_ui; //!< The widget's ui

      void errorMsg();
      QString formatPoleRaString();
      QString formatPoleDecString();
      QString formatPmString();