Commit 2e52ace8 authored by Makayla Shepherd's avatar Makayla Shepherd
Browse files

Fixed a crash that occurs when a failed import is undone. Fixes #5043.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/branches/ipce@7881 41f8697f-d340-4b68-9986-7bafba869bb8
parent 1e36e509
Loading
Loading
Loading
Loading
+27 −7
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ namespace Isis {
   */
  void ImportControlNetWorkOrder::undoExecution() {
    if (m_watcher->isFinished()) {
      if (project()->controls().size() > 0) {
        ControlList *list = project()->controls().last();
        // Remove the controls from disk.
        list->deleteFromDisk( project() );
@@ -216,8 +217,15 @@ namespace Isis {
        project()->directory()->model()->removeItem(currentItem);
      }
    }
  }


  /**
   * CreateControlsFunctor constructor
   * 
   * @param project The project
   * @param destinationFolder The directory to copy to
   */
  ImportControlNetWorkOrder::CreateControlsFunctor::CreateControlsFunctor(
      Project *project, QDir destinationFolder) {
    m_project = project;
@@ -225,6 +233,13 @@ namespace Isis {
  }


  /**
   * Reads and writes the control network(s) asynchronously
   *
   * @param &cnetFileNameAndProgress QPair of control net filenames, and the progress
   *
   * @return Control Pointer to the Control created from the import 
   */
  Control *ImportControlNetWorkOrder::CreateControlsFunctor::operator()(
      const QPair<FileName, Progress *> &cnetFileNameAndProgress) {

@@ -243,6 +258,11 @@ namespace Isis {
  }


  /**
   * Adds the control net to the project
   * 
   * @param ready Index of the control net that is ready
   */
  void ImportControlNetWorkOrder::cnetReady(int ready) {

    Control *control = m_watcher->resultAt(ready);
+6 −4
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ namespace Isis {
   *   @history 2017-07-25 Cole Neubauer - Added project()->setClean call #4969
   *   @history 2017-07-13 Makayla Shepherd - Added isExecutable(ProjectItem) to allow for importing
   *                           in the context menu. Fixes #4968.
   *   @history 2017-07-26 Makayla Shepherd - Fixed a crash that occurs when a failed image import
   *                           is undone. Fixes #5043.
   */
  class ImportControlNetWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -90,13 +92,13 @@ namespace Isis {
          Control *operator()(const QPair<FileName, Progress *> &cnetFilename);

        private:
          Project *m_project;
          QDir m_destinationFolder;
          Project *m_project; //!< The project to import to
          QDir m_destinationFolder; //!< The directory to copy the control net too
      };

    private:
      QFutureWatcher<Control *> *m_watcher;
      QList<Progress *> m_readProgresses;
      QFutureWatcher<Control *> *m_watcher; //!< QFutureWatcher, allows for asynchronous import
      QList<Progress *> m_readProgresses; //!< Keeps track of import progress
  };
}
#endif // ImportControlNetWorkOrder_H
+15 −11
Original line number Diff line number Diff line
@@ -207,6 +207,7 @@ namespace Isis {
   */
  void ImportImagesWorkOrder::undoExecution() {
    project()->waitForImageReaderFinished();
    if (project()->images().size() > 0) {
      ImageList *list = project()->images().last();
      // Remove the images from disk.
      list->deleteFromDisk( project() );
@@ -215,6 +216,7 @@ namespace Isis {
          project()->directory()->model()->findItemData( QVariant::fromValue(list) );
      project()->directory()->model()->removeItem(currentItem);
    }
  }


  /**
@@ -227,6 +229,7 @@ namespace Isis {
   * @see WorkOrder::postUndoExecution()
   */
  void ImportImagesWorkOrder::postUndoExecution() {
    if (project()->images().size() > 0) {
      QPointer<ImageList> imagesWeAdded = project()->images().last();

      foreach (Image *image, *imagesWeAdded) {
@@ -234,6 +237,7 @@ namespace Isis {
      }
      delete imagesWeAdded;
    }
  }


  /**
+10 −8
Original line number Diff line number Diff line
@@ -74,6 +74,8 @@ namespace Isis {
   *   @history 2017-07-17 Makayla Shepherd - Added isExecutable(ProjectItem) to allow for importing
   *                           in the context menu. Fixes #4968.
   *   @history 2017-07-25 Cole Neubauer - Added project()->setClean call #4969
   *   @history 2017-07-26 Makayla Shepherd - Fixed a crash that occurs when a failed image import
   *                           is undone. Fixes #5043.
   */
  class ImportImagesWorkOrder : public WorkOrder {
      Q_OBJECT
@@ -121,21 +123,21 @@ namespace Isis {
          //! Not implemented
          OriginalFileToProjectCubeFunctor &operator=(const OriginalFileToProjectCubeFunctor &rhs);

          QDir m_destinationFolder; //! Directory where to import the images to.
          bool m_copyDnData; //! Indicates whether the cube data will be copied to the project.
          QThread *m_guiThread; //! Pointer to the GUI thread. Not used?
          QDir m_destinationFolder; //!< Directory where to import the images to.
          bool m_copyDnData; //!< Indicates whether the cube data will be copied to the project.
          QThread *m_guiThread; //!< Pointer to the GUI thread. Not used?

          QMutex m_errorsLock; //! Mutex lock for appending errors and incrementing error count.
          QSharedPointer<IException> m_errors; //! Stores any errors that occur during import.
          QSharedPointer<int> m_numErrors; //! Number of errors that occur during import.
          QMutex m_errorsLock; //!< Mutex lock for appending errors and incrementing error count.
          QSharedPointer<IException> m_errors; //!< Stores any errors that occur during import.
          QSharedPointer<int> m_numErrors; //!< Number of errors that occur during import.
      };

    private:
      void importConfirmedImages(QStringList confirmedImages, bool copyDnData);

    private:
      ImageList *m_newImages; //! List of images that are being imported in this work order.
      QString m_warning; //! String of any errors/warnings that occurred during import.
      ImageList *m_newImages; //!< List of images that are being imported in this work order.
      QString m_warning; //!< String of any errors/warnings that occurred during import.
  };
}
#endif // ImportImagesWorkOrder_H
+42 −11
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ namespace Isis {
    */
  void ImportShapesWorkOrder::undoExecution() {
    project()->waitForShapeReaderFinished();
    if (project()->shapes().size() > 0) {
      ShapeList *list = project()->shapes().last();
      // Remove the shapes from disk.
      list->deleteFromDisk( project() );
@@ -182,11 +183,13 @@ namespace Isis {
          project()->directory()->model()->findItemData( QVariant::fromValue(list) );
      project()->directory()->model()->removeItem(currentItem);
    }
  }

  /**
    * @brief delete the imported shapes from the project.
    */
  void ImportShapesWorkOrder::postUndoExecution() {
    if (project()->shapes().size() > 0) {
      QPointer<ShapeList> shapesWeAdded = project()->shapes().last();

      foreach (Shape *shape, *shapesWeAdded) {
@@ -194,6 +197,7 @@ namespace Isis {
      }
      delete shapesWeAdded;
    }
  }

  /**
    * @brief Creates a project shape folder and copies the shape cubes into it. This will create
@@ -225,6 +229,13 @@ namespace Isis {
  }


  /**
   * OriginalFileToProjectFunctor constructor
   * 
   * @param *guiThread The thread for the gui
   * @param destinationFolder The folder to copy the DN data to
   * @param copyDnData Determines if the DN data will be copied to the project
   */
  ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::OriginalFileToProjectCubeFunctor(
      QThread *guiThread, QDir destinationFolder, bool copyDnData) : m_errors(new IException),
      m_numErrors(new int(0)) {
@@ -234,6 +245,11 @@ namespace Isis {
  }


  /**
   * Copy constructor
   * 
   * @param &other OriginalFileToProjectCubeFunctor to copy
   */
  ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::OriginalFileToProjectCubeFunctor(
      const OriginalFileToProjectCubeFunctor &other) : m_errors(other.m_errors),
      m_numErrors(other.m_numErrors) {
@@ -243,6 +259,9 @@ namespace Isis {
  }


  /**
   * Destructor
   */
  ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::~OriginalFileToProjectCubeFunctor() {
    m_destinationFolder = QDir();
    m_copyDnData = false;
@@ -250,6 +269,13 @@ namespace Isis {
  }


  /**
   * Creates ecubs and copies the DN data of the cubes, if m_copyDnData is true.
   *
   * @param &original Imported shape cube
   * 
   * @return Cube Copy of the imported shape cube
   */
  Cube *ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::operator()(
      const FileName &original) {
    Cube *result = NULL;
@@ -294,6 +320,11 @@ namespace Isis {
  }


  /**
   * Returns the errors from importing
   * 
   * @return IException The import errors
   */
  IException ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::errors() const {
    IException result;

Loading