Commit 61893054 authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Updated ExportControlNet and SaveProjectAs work orders for WorkOrder re-design. Fixes #4763.

parent 4934d011
Loading
Loading
Loading
Loading
+62 −16
Original line number Diff line number Diff line
@@ -36,46 +36,81 @@

namespace Isis {

  /**
   * Creates a work order for exporting a control network from the project. This work
   * order is asynchronous and is not undoable.
   *
   * @param Project *project Pointer to the project to export from (the project this work order
   * belongs to).
   */
  ExportControlNetWorkOrder::ExportControlNetWorkOrder(Project *project) :
      WorkOrder(project) {
    m_isSynchronous = false;
    m_isUndoable = false;
    QAction::setText(tr("&Export Control Network..."));
  }


  /**
   * @brief Copy constructor.
   *
   * Copies the work order.
   *
   * @param ExportControlNetWorkOrder &other The other work order to copy state from.
   */
  ExportControlNetWorkOrder::ExportControlNetWorkOrder(const ExportControlNetWorkOrder &other) :
      WorkOrder(other) {
  }


  /**
   * @brief Destructor.
   *
   * Default destructor to clean up any memory this work order might allocate.
   */
  ExportControlNetWorkOrder::~ExportControlNetWorkOrder() {

  }


  /**
   * @brief Clones this work order.
   *
   * Allocate a new work order using this work order's state.
   *
   * @return ExportControlNetWorkOrder* Returns a pointer to the newly cloned work order.
   */
  ExportControlNetWorkOrder *ExportControlNetWorkOrder::clone() const {
    return new ExportControlNetWorkOrder(*this);
  }


  /**
   * Currently, this work order only works with either no data (file menu) or with a single 
   *   control network.
   * @brief Determines if we can export a control net.
   *
   * Currently, this work order only works with either no data (file menu) or with a
   * single control network.
   *
   * @param controls The current context we're inquiring about
   * @param ControList *controls The current context we're inquiring about.
   *
   * @return bool True if this work order functions with the given control list
   * @return bool Returns true if this work order functions with the given control list. Right now,
   * true indicates that there is one control list in the project.
   */
  bool ExportControlNetWorkOrder::isExecutable(ControlList *controls) {
    // TODO: This shouldn't be executable (in the menu) if there are no imported control networks?
    return (controls->count() == 1);
  }


  /**
   * Prompts the user for input. If there is no context, we ask the user to select a control. Once 
   *   we have a control (via context or asking the user), we then ask for a output cnet file name.
   *   The relevant data is stored in internalData().
   * @brief Prepares for exporting a control net by soliciting information from the user.
   *
   * @return bool 
   * Prompts the user for input. If there is no context, we ask the user to select a
   * control. Once we have a control (via context or asking the user), we then ask for a output cnet
   * file name. The relevant data is stored in internalData(). The internal data will contain
   * the control net id and the destination to export to.
   *
   * @return bool Returns true if the setup is successful.
   */
  bool ExportControlNetWorkOrder::setupExecution() {
    bool success = WorkOrder::setupExecution();
@@ -84,6 +119,8 @@ namespace Isis {
      QStringList internalData;

      Control *control = NULL;
      // See if there are any other control lists in the project and give these to the user as
      // choices for control nets they can export.
      if (controlList()->isEmpty()) {
        QMap<Control *, QString> cnetChoices;
        foreach (ControlList *list, project()->controls()) {
@@ -102,6 +139,7 @@ namespace Isis {
        control = cnetChoices.key(choice);
        internalData.append(control->id());
      }
      // Otherwise, export the control net associated with this work order.
      else {
        control = controlList()->first();
      }
@@ -123,10 +161,14 @@ namespace Isis {


  /**
   * Use internalData() and write the control network into the output file. Stores errors in 
   *   m_warning which will be reported in postSyncRedo().
   * @brief Executes the work order.
   *
   * Uses internalData() and writes the control network into the output file. Stores
   * errors in m_warning which will be reported in postExecution().
   *
   * @see WorkOrder::execute()
   */
  void ExportControlNetWorkOrder::asyncRedo() {
  void ExportControlNetWorkOrder::execute() {
    QString destination;
    Control *control = NULL;

@@ -151,9 +193,13 @@ namespace Isis {


  /**
   * Display any warnings that occurred during the asynchronous computations.
   * @brief Display any warnings that occurred during the asynchronous computations.
   *
   * These warnings will be attached to the project.
   *
   * @see WorkOrder::postExecution()
   */
  void ExportControlNetWorkOrder::postSyncRedo() {
  void ExportControlNetWorkOrder::postExecution() {
    if (!m_warning.isEmpty()) {
      project()->warn(m_warning);
      m_warning.clear();
+15 −12
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ namespace Isis {
   * @author 2012-09-26 Tracie Sucharski
   *
   * @internal
   *   @history 2017-04-11 Ian Humphrey - Updated to match work order redesign. Replaced asyncRedo
   *                           and postSyncRedo with execute and postExecution. Separated
   *                           setup and action into setupExecution and execute. Fixes #4763.
   */
  class ExportControlNetWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -31,16 +34,16 @@ namespace Isis {

      bool isExecutable(ControlList *controls);

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

      bool setupExecution();

      void asyncRedo();
      void postSyncRedo();
    protected:
      virtual void postExecution();

    private:
      ExportControlNetWorkOrder &operator=(const ExportControlNetWorkOrder &rhs);

      QString m_warning;
      QString m_warning; //!< Stores any errors that may have occurred during export.
  };
}

+49 −2
Original line number Diff line number Diff line
@@ -34,28 +34,63 @@

namespace Isis {

  /**
   * Creates a work order to save the project to a new location. This work order is
   * synchronous and not undoable.
   *
   * @param Project *project Pointer to the project this work order belongs to.
   */
  SaveProjectAsWorkOrder::SaveProjectAsWorkOrder(Project *project) :
      WorkOrder(project) {
    // This work order is not undoable
    m_isUndoable = false;
    QAction::setText(tr("Save Project &As"));
    setCreatesCleanState(true);
  }


  /**
   * @brief Copy constructor.
   *
   * Creates a copy of the other SaveProjectAsWorkOrder.
   *
   * @param SaveProjectAsWorkOrder &other The other work order to copy state from.
   */
  SaveProjectAsWorkOrder::SaveProjectAsWorkOrder(const SaveProjectAsWorkOrder &other) :
      WorkOrder(other) {
  }


  /**
   * @brief Destructor.
   *
   * Destructor to clean up any memory that this work order allocates.
   */
  SaveProjectAsWorkOrder::~SaveProjectAsWorkOrder() {

  }


  /**
   * @brief Creates a clone of this work order.
   *
   * @return SaveProjectWorkOrder* Pointer to the newly cloned work order.
   */
  SaveProjectAsWorkOrder *SaveProjectAsWorkOrder::clone() const {
    return new SaveProjectAsWorkOrder(*this);
  }


  /**
   * @brief Sets up this work order prior to execution.
   *
   * This prompts the user for a location to save the project to and what name to save
   * the project as. If the user provides an empty name, then this setup fails.
   *
   * @see WorkOrder::setupExecution()
   *
   * @return bool Returns true if the provided project name is not empty, false otherwise.
   */
  bool SaveProjectAsWorkOrder::setupExecution() {
    bool success = WorkOrder::setupExecution();

@@ -66,8 +101,7 @@ namespace Isis {
      if (!newDestination.isEmpty()) {
        QUndoCommand::setText(tr("Save project to [%1]") .arg(newDestination));
        QString realPath = QFileInfo(newDestination + "/").absolutePath();
        project()->save(realPath);
//      project()->relocateProjectRoot(realPath);
        setInternalData(QStringList(realPath));
      }
      else {
        success = false;
@@ -76,4 +110,17 @@ namespace Isis {

    return success;
  }


  /**
   * @brief Executes the work order.
   *
   * Saves the project with the name and destination acquired in setupExecution.
   */
  void SaveProjectAsWorkOrder::execute() {
    QString destination = internalData().first();
    if (!destination.isEmpty()) {
      project()->save(destination);
    }
  }
}
+6 −2
Original line number Diff line number Diff line
@@ -34,11 +34,14 @@ namespace Isis {
  class FileName;

  /**
   * Saves a project to disk (File->Save Project As...)
   * @description Saves a project to disk (File->Save Project As...)
   *
   * @author 2012-??-?? ???
   *
   * @internal
   *   @history 2017-04-11 Ian Humphrey - Updated the work order according to the redesign of
   *                           WorkOrder. Separated setup and execution steps into setupExecution
   *                           and execution(). Fixes #4763.
   */
  class SaveProjectAsWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -49,7 +52,8 @@ namespace Isis {

      virtual SaveProjectAsWorkOrder *clone() const;

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

    private:
      SaveProjectAsWorkOrder &operator=(const SaveProjectAsWorkOrder &rhs);