Commit 7445518b authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Updated JigsawWorkOrder for work order redesign, setup dialog now pops up...

Updated JigsawWorkOrder for work order redesign, setup dialog now pops up first. Abort button fixed. Fixes #4748.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce_FY17-Sprint1@7577 41f8697f-d340-4b68-9986-7bafba869bb8
parent 375aa0ee
Loading
Loading
Loading
Loading
+118 −117
Original line number Diff line number Diff line
@@ -919,6 +919,7 @@ namespace Isis {
      throw IException(e, e.errorType(), msg, _FILEINFO_);
    }

    emit finished();
    return true;
  }

+63 −53
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <QtDebug>

#include <QDialog>
#include <QDockWidget>
#include <QFileDialog>
#include <QInputDialog>
@@ -32,27 +33,40 @@
#include "Control.h"
#include "Directory.h"
#include "JigsawDialog.h"
#include "JigsawSetupDialog.h"
#include "Project.h"

namespace Isis {

  /**
   * This method sets the text of the work order.
   * @brief Constructs a JigsawWorkOrder.
   *
   * This creates a work order to run bundle adjustments. Note that right now,
   * the design implemented means that this work order finishes after a JigsawDialog
   * is shown. This work order is synchronous and not undoable. Note is is synchronous
   * in that it simply displays a dialog. The actual bundle adjust is threaded.
   *
   * @see JigsawDialog
   *
   * @param project The Project that we are going to Bundle Adjust
   *
   */
  JigsawWorkOrder::JigsawWorkOrder(Project *project) :
      WorkOrder(project) {
    // This work order is synchronous and not undoable
    m_isUndoable = false;
    QAction::setText(tr("&Bundle Adjustment..."));
    QUndoCommand::setText("&Bundle Adjustment...");
  }

  /**
   * As of 06/06/2016 this method is not implemented.
   * @brief Copy constructor.
   *
   * Copies the state of another JigsawWorkOrder.
   */
  JigsawWorkOrder::JigsawWorkOrder(const JigsawWorkOrder &other) :
      WorkOrder(other) {
    m_bundleSettings = other.m_bundleSettings;
  }

  /**
@@ -64,7 +78,7 @@ namespace Isis {
  /**
   * This method clones the JigsawViewWorkOrder
   *
   * @return @b JigsawWorkOrder Returns a clone of the JigsawWorkOrder
   * @return JigsawWorkOrder* Returns a clone of the JigsawWorkOrder
   */
  JigsawWorkOrder *JigsawWorkOrder::clone() const {
    return new JigsawWorkOrder(*this);
@@ -73,7 +87,7 @@ namespace Isis {
  /**
   * This check is used by Directory::supportedActions(DataType data).
   *
   * @return @b bool True if the number of project controls and the number of project images
   * @return bool True if the number of project controls and the number of project images
   *         is greater than 0.
   */
  bool JigsawWorkOrder::isExecutable() {
@@ -81,42 +95,47 @@ namespace Isis {
  }

  /**
   * If WorkOrder::execute() returns true, this method creates a JigsawDialog.
   * If WorkOrder:setupExecution() returns true, this creates a setup dialog.
   *
   * @return @b bool True if WorkOrder::execute() returns true.
   * When the setup is successful (i.e. the user does not cancel the dialog), this work order
   * will be read to execute.
   *
   * @return bool Returns True if setup dialog for the bundle adjustment is successful.
   */
  bool JigsawWorkOrder::setupExecution() {
    bool success = WorkOrder::setupExecution();
/*

    if (success) {
        JigsawDialog* bundledlg = new JigsawDialog(project());
        bundledlg->setAttribute(Qt::WA_DeleteOnClose);
        bundledlg->show();
//      QUndoCommand::setText(tr("&Bundle Adjustment")
//          .arg(controlList().first()->displayProperties()->displayName()));
      // Create a blocking setup dialog initially and check to make sure we get valid info
      JigsawSetupDialog setup(project());
      if (setup.exec() == QDialog::Accepted) {
        m_bundleSettings = setup.bundleSettings();
        if (setup.selectedControl()) {
          setInternalData(QStringList(setup.selectedControl()->id()));
        }
*/
    if (success) {
//      QDockWidget* dock = new QDockWidget();
//      dock->setMinimumWidth(525);
//      dock->setMinimumHeight(325);
//      dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
      JigsawDialog* bundledlg = new JigsawDialog(project());
      bundledlg->setAttribute(Qt::WA_DeleteOnClose);
      bundledlg->show();
//      dock->setWidget(bundledlg);
//      dock->show();
        // This else should not happen, the work order should be disabled if there are no controls.
        else {
          QString msg = "Cannot run a bundle adjustment without a selected control network.";
          QMessageBox::critical(qobject_cast<QWidget *>(parent()), "Error", msg);
          success = false;
        }
      }
      else {
        success = false;
      }
    }


    return success;
  }


 /**
  * This method returns true if other depends on a JigsawViewWorkOrder
  * This method returns true if other depends on a JigsawWorkOrder
  *
  * @param order the WorkOrder we want to check for dependancies
  *
  * @return @b bool True if WorkOrder depends on a JigsawViewWorkOrder
  * @return bool True if WorkOrder depends on a JigsawWorkOrder
  *
  */
  bool JigsawWorkOrder::dependsOn(WorkOrder *other) const {
@@ -124,27 +143,18 @@ namespace Isis {
    return dynamic_cast<JigsawWorkOrder *>(other);
  }

  /**
   * As of 06/06/2016 this method is not implemented as the contents are commented out.
   * 
   */
  void JigsawWorkOrder::execute() {
//    TargetInfoWidget *targetInfoWidget =
//        project()->directory()->addTargetInfoView(targetBody());


//    if (!targetInfoWidget) {
//      QString msg = "error displaying target info";
//      throw IException(IException::Programmer, msg, _FILEINFO_);
//    }
  }

  /**
   * As of 06/06/2016 this method is not implemented as the contents are commented out.
   * Executes the work order by creating a jigsaw dialog that allows the user to run or re-setup
   * the settings for a bundle adjustment.
   *
   * @see WorkOrder::execute()
   */
  void JigsawWorkOrder::undoExecution() {
    //delete project()->directory()->cnetEditorViews().last();
  void JigsawWorkOrder::execute() {
    // Get the selected control and bundle settings and give them to the JigsawDialog for now.
    Control *selectedControl = project()->control(internalData().first());
    JigsawDialog *runDialog = new JigsawDialog(project(), m_bundleSettings, selectedControl);
    runDialog->setAttribute(Qt::WA_DeleteOnClose);
    runDialog->show();
  }
}
+10 −5
Original line number Diff line number Diff line
@@ -24,7 +24,12 @@
 */
#include "WorkOrder.h"

template <class T>
class QSharedPointer;

namespace Isis {
  class BundleSettings;
  typedef QSharedPointer<BundleSettings> BundleSettingsQsp;
  /**
   * @brief This work order allows the user to run a bundle adjustment (jigsaw).
   * This workorder is synchronous and undoable.
@@ -35,7 +40,8 @@ namespace Isis {
   *   @history 2014-06-04 Jeannie Backer - Fixed JigsawWorkOrder error.
   *   @history 2015-09-05 Ken Edmundson - Added preliminary target body functionality to IPCE.
   *   @history 2016-06-06 Makayla Shepherd - Updated documentation. Fixes #3993.
   *   @history 2017-04-16 J Bonn - Updated to new workorder design #4764.
   *   @history 2017-04-17 Ian Humphrey - Updated documentation and methods for accommodating the
   *                           changes to work order. References #4748.
   */
  class JigsawWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -47,16 +53,15 @@ namespace Isis {
      virtual JigsawWorkOrder *clone() const;

      virtual bool isExecutable();
      bool setupExecution();
      virtual bool setupExecution();
      virtual void execute();

    protected:
      bool dependsOn(WorkOrder *other) const;
      void execute();
      void undoExecution();

    private:
      JigsawWorkOrder &operator=(const JigsawWorkOrder &rhs);
      BundleSettingsQsp m_bundleSettings; /**< BundleSettings shared betweeen setup and execute. */
  };
}
#endif
+77 −18
Original line number Diff line number Diff line
@@ -20,13 +20,53 @@

namespace Isis {

  /**
   * @brief Constructor.
   *
   * Creates a dialog for running a jigsaw (bundle adjustment) and changing the solve settings.
   *
   * @param Project *project Pointer to the project this dialog belongs to.
   * @param QWidget *parent Pointer to parent widget.
   */
  JigsawDialog::JigsawDialog(Project *project, QWidget *parent) :
      QDialog(parent), m_ui(new Ui::JigsawDialog) {
    m_project = project;
    m_selectedControl = NULL;
    init();
  }


  /**
   * @brief Constructor that takes bundle settings and a selected control.
   *
   * Creates a dialog after the jigsaw solve settings have been set up and a control has been
   * selected.
   *
   * @param Project *project Pointer to the project this dialog belongs to.
   * @param BundleSettingsQsp bundleSettings Settings to give to this dialog to use for a jigsaw.
   * @param Control *selectedControl Pointer to the selected control to adjust.
   * @param QWidget *parent Pointer to the parent widget.
   */
  JigsawDialog::JigsawDialog(Project *project,
                             BundleSettingsQsp bundleSettings,
                             Control *selectedControl,
                             QWidget *parent) : QDialog(parent), m_ui(new Ui::JigsawDialog) {
    m_project = project;
    m_bundleSettings = bundleSettings;
    m_selectedControl = selectedControl;
    init();
  }


  /**
   * @brief Constructor delegate.
   *
   * Delegate method that helps the constructors. This is used to reduce repeated code.
   */
  void JigsawDialog::init() {
    m_ui->setupUi(this);

    m_bundleAdjust = NULL;
    m_project = project;
    m_selectedControl = NULL;

    m_bRunning = false;

@@ -44,6 +84,9 @@ namespace Isis {
  }


  /**
   * Destructor.
   */
  JigsawDialog::~JigsawDialog() {
    if (m_ui) {
      delete m_ui;
@@ -157,34 +200,41 @@ namespace Isis {

       m_bundleAdjust->moveToThread(bundleThread);

       // Track the status updates bundle adjust gives and update the dialog.
       connect( m_bundleAdjust, SIGNAL( statusUpdate(QString) ),
                this, SLOT( outputBundleStatus(QString) ) );

       // Track any errors that may occur during the bundle adjust and update the dialog.
       connect( m_bundleAdjust, SIGNAL( error(QString) ),
                this, SLOT( errorString(QString) ) );

       connect( m_bundleAdjust, SIGNAL( bundleException(QString) ),
                this, SLOT( reportException(QString) ) );

       // Update the iteration dialog element when the bundle updates its iteration count.
       connect( m_bundleAdjust, SIGNAL( iterationUpdate(int, double) ),
                this, SLOT( updateIterationSigma0(int, double) ) );

       // When we start the bundle thread, run the bundle adjustment.
       connect( bundleThread, SIGNAL( started() ),
                m_bundleAdjust, SLOT( solveCholesky() ) );

       // When the bundle adjust says results are ready, we can allow the dialog to update the
       // project as necessary.
       connect( m_bundleAdjust, SIGNAL( resultsReady(BundleSolutionInfo *) ),
                this, SLOT( bundleFinished(BundleSolutionInfo *) ) );

       // Schedule the bundle thread for deletion when it finishes.
       connect( bundleThread, SIGNAL( finished() ),
                bundleThread, SLOT( deleteLater() ) );

       // ken testing
       // Notify the dialog that the bundle thread is finished, and update the gui elements.
       connect( bundleThread, SIGNAL( finished() ),
                this, SLOT( notifyThreadFinished() ) );

       // Tell the thread to quit (stop) when the bundle adjust finishes (successfully or not)
       connect( m_bundleAdjust, SIGNAL( finished() ),
                bundleThread, SLOT( quit() ) );

       // Schedule the bundle adjustment for deletion.
       connect( m_bundleAdjust, SIGNAL( finished() ),
                m_bundleAdjust, SLOT( deleteLater() ) );
       // ken testing
@@ -278,13 +328,22 @@ namespace Isis {
  }


  /**
   * @brief Notifies the dialog that the bundle thread has finished.
   *
   * This slot is used to notify the dialog that the bundle has finished. The bundle thread
   * finishes when the bundle adjust finishes (either successfully or unsuccessfully, or if the
   * user aborts the run).
   */
  void JigsawDialog::notifyThreadFinished() {
    QString str = "\nThread Finished signal received";
    m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(str) );
    //QString str = "\nThread Finished signal received";
    //m_ui->statusUpdatesLabel->setText( m_ui->statusUpdatesLabel->text().append(str) );

    // set Run button text back to "Run"
    m_ui->JigsawRunButton->setText("&Run...");

    m_ui->JigsawRunButton->setText("&Run");
    // Since this slot is invoked when the thread finishes, the bundle adjustment is no longer
    // running.
    m_bRunning = false;
    update();

    m_ui->statusUpdateScrollArea->verticalScrollBar()->setSliderPosition(
+16 −5
Original line number Diff line number Diff line
@@ -2,8 +2,10 @@
#define JigsawDialog_h

#include <QDialog>
#include <QPointer>
#include <QWidget>

#include "BundleAdjustWorkOrder.h"
#include "BundleSettings.h"
#include "IException.h"

@@ -36,13 +38,21 @@ namespace Isis {
   *                           value for the useLastSettings checkbox. When the Run button is
   *                           clicked, the run time will now be used to create a uniquely named
   *                           directory to contain the output files for the bundle solution.

   *   @history 2017-04-17 Ian Humphrey - Added second constructor that can be used when the
   *                           JigsawWorkOrder initially creates a setup dialog so it can pass
   *                           information to this dialog. Added init() delegate method for
   *                           constructors to use to reduce code duplication. Modified
   *                           notifyThreadFinished to update the Run button. References #4748.
   */
  class JigsawDialog : public QDialog {
    Q_OBJECT

  public:
    explicit JigsawDialog(Project *project, QWidget *parent = 0);
    explicit JigsawDialog(Project *project,
                          BundleSettingsQsp bundleSettings,
                          Control *selectedControl,
                          QWidget *parent = 0);

    ~JigsawDialog();

@@ -55,6 +65,7 @@ namespace Isis {
    void notifyThreadFinished();

  protected:
    void init();
    BundleAdjust *m_bundleAdjust;
    Project *m_project;
    Control *m_selectedControl;