File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
ExportImagesWorkOrder.cpp
Go to the documentation of this file.
1 
23 #include "ExportImagesWorkOrder.h"
24 
25 #include <QDebug>
26 #include <QFileDialog>
27 #include <QFuture>
28 #include <QInputDialog>
29 #include <QtConcurrentMap>
30 
31 #include "Cube.h"
32 #include "CubeAttribute.h"
33 #include "Image.h"
34 #include "ImageList.h"
35 #include "FileName.h"
36 #include "IException.h"
37 #include "IString.h"
38 #include "Project.h"
39 
40 namespace Isis {
41 
42  ExportImagesWorkOrder::ExportImagesWorkOrder(Project *project) :
43  WorkOrder(project) {
44 
45  // This is an asynchronous workorder and not undoable
46  m_isSynchronous = false;
47  m_isUndoable = false;
48 
49  QAction::setText(tr("Export I&mages..."));
50  }
51 
52 
53  ExportImagesWorkOrder::ExportImagesWorkOrder(const ExportImagesWorkOrder &other) :
54  WorkOrder(other) {
55  }
56 
57 
58  ExportImagesWorkOrder::~ExportImagesWorkOrder() {
59 
60  }
61 
62 
63  ExportImagesWorkOrder *ExportImagesWorkOrder::clone() const {
64  return new ExportImagesWorkOrder(*this);
65  }
66 
67 
77  if (images) {
78  return (!images->isEmpty());
79  }
80  return false;
81  }
82 
83 
92  bool success = WorkOrder::setupExecution();
93 
94  if (success) {
96 
97  if (imageList()->isEmpty()) {
98  QStringList imageListNames;
99  foreach (ImageList *list, project()->images()) {
100  imageListNames.append(list->name());
101  }
102 
103  qSort(imageListNames);
104 
105  QString choice = QInputDialog::getItem(NULL, tr("Select Image List"),
106  tr("Please choose a list of images to export."), imageListNames, 0, false, &success);
107 
108  internalData.append(choice);
109 
110  QUndoCommand::setText(tr("Export image list [%1]").arg(choice));
111  }
112  else {
113  QUndoCommand::setText(tr("Export [%1] images").arg(imageList()->count()));
114  }
115 
116  QString destination = QFileDialog::getExistingDirectory(NULL, tr("Export Images"), ".");
117 
118  if (destination.isEmpty()) {
119  success = false;
120  }
121  internalData.append(destination);
122 
124  }
125 
126  return success;
127  }
128 
129 
135  ImageList *list = imageList();
136 
137  if (list->isEmpty()) {
138  list = project()->imageList(internalData()[0]);
139  }
140 
141 
142  QString destination = internalData().last();
143  ProjectImageExportFunctor functor(destination);
144 
145  QFuture<void *> future = QtConcurrent::mapped(*list, functor);
146 
147  setProgressRange(0, list->count());
148 
149  QThreadPool::globalInstance()->releaseThread();
150  for (int i = 0; i < list->count(); i++) {
151  setProgressValue(i);
152 
153  // Wait for the result before updating the progress to the next value... it's still
154  // working on writing N images, just progress is going 1 by 1.
155  future.resultAt(i);
156  }
157  QThreadPool::globalInstance()->reserveThread();
158 
159  // Get the errors that occurred during the mapped in order to report them in postSyncRedo
160  m_warning = functor.errors().toString();
161  }
162 
163 
168  if (!m_warning.isEmpty()) {
169  project()->warn(m_warning);
170  m_warning.clear();
171  }
172  }
173 
174 
182  QString destination) : m_errors(new IException()), m_numErrors(new int(0)) {
183 
184  m_destination = destination;
185  }
186 
187 
195  const ProjectImageExportFunctor &other) : m_errors(other.m_errors),
196  m_numErrors(other.m_numErrors) {
197 
198  m_destination = other.m_destination;
199  }
200 
201 
206  }
207 
208 
217  try {
218  FileName outputFileName =
219  m_destination + "/" + FileName(imageToExport->fileName()).baseName();
220 
221  // Copy the image, free the copy from memory because we don't need it.
222  delete imageToExport->cube()->copy(outputFileName, CubeAttributeOutput());
223  // Avoid opening too many cubes
224  imageToExport->closeCube();
225  }
226  catch (IException &e) {
227  QMutexLocker locker(&m_errorsLock);
228  m_errors->append(e);
229  (*m_numErrors)++;
230  }
231 
232  return NULL;
233  }
234 
235 
243  IException result;
244 
245  result.append(*m_errors);
246 
247  if (*m_numErrors != 0) {
248  result.append(
250  tr("Failed to export [%1] images").arg(*m_numErrors),
251  _FILEINFO_));
252  }
253 
254  return result;
255  }
256 }
Isis::WorkOrder::setupExecution
virtual bool setupExecution()
This sets up the state for the work order.
Definition: WorkOrder.cpp:1261
Project.h
Isis::WorkOrder::imageList
ImageList * imageList()
Returns a pointer to the ImageList for this WorkOrder.
Definition: WorkOrder.cpp:631
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::ExportImagesWorkOrder::postExecution
void postExecution()
Display any warnings that occurred during the asynchronous computations.
Definition: ExportImagesWorkOrder.cpp:167
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::ExportImagesWorkOrder::ProjectImageExportFunctor::errors
IException errors() const
Get the accumulated error list from this functor's run.
Definition: ExportImagesWorkOrder.cpp:242
Isis::WorkOrder::setInternalData
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1318
Isis::Cube::copy
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
Definition: Cube.cpp:276
Isis::CubeAttributeOutput
Manipulate and parse attributes of output cube filenames.
Definition: CubeAttribute.h:473
Isis::Image::fileName
QString fileName() const
Get the file name of the cube that this image represents.
Definition: Image.cpp:340
Image.h
Isis::WorkOrder::m_isSynchronous
bool m_isSynchronous
This is defaulted to true.
Definition: WorkOrder.h:530
QStringList
Isis::IException::append
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
Definition: IException.cpp:409
Isis::ImageList
Internalizes a list of images and allows for operations on the entire list.
Definition: ImageList.h:55
Isis::FileName::baseName
QString baseName() const
Returns the name of the file without the path and without extensions.
Definition: FileName.cpp:145
Isis::ExportImagesWorkOrder::ProjectImageExportFunctor::ProjectImageExportFunctor
ProjectImageExportFunctor(QString destination)
Create an image export functor that will copy the image's cubes into the given destination directory.
Definition: ExportImagesWorkOrder.cpp:181
Isis::WorkOrder::m_isUndoable
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
Definition: WorkOrder.h:523
Isis::ExportImagesWorkOrder::ProjectImageExportFunctor::~ProjectImageExportFunctor
~ProjectImageExportFunctor()
Destroys the functor.
Definition: ExportImagesWorkOrder.cpp:205
Isis::IException::toString
QString toString() const
Returns a string representation of this exception.
Definition: IException.cpp:537
Isis::ExportImagesWorkOrder::ProjectImageExportFunctor::operator()
void * operator()(Image *const &imageToExport)
Write the given image's cube into the destination folder (preserves the base name).
Definition: ExportImagesWorkOrder.cpp:216
Isis::Image::cube
Cube * cube()
Get the Cube pointer associated with this display property.
Definition: Image.cpp:287
Isis::Image::closeCube
void closeCube()
Cleans up the Cube pointer.
Definition: Image.cpp:307
Isis::ImageList::name
QString name() const
Get the human-readable name of this image list.
Definition: ImageList.cpp:724
Isis::WorkOrder::project
Project * project() const
Returns the Project this WorkOrder is attached to.
Definition: WorkOrder.cpp:1300
Isis::Image
This represents a cube in a project-based GUI interface.
Definition: Image.h:107
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::WorkOrder::setProgressRange
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
Definition: WorkOrder.cpp:1358
Isis::ExportImagesWorkOrder::execute
void execute()
Use internalData() and write the images into the output directory.
Definition: ExportImagesWorkOrder.cpp:134
Isis::ExportImagesWorkOrder::isExecutable
bool isExecutable(ImageList *images)
Currently, this work order only works with either no data (file menu) or with any number of images.
Definition: ExportImagesWorkOrder.cpp:76
Isis::WorkOrder::setProgressValue
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
Definition: WorkOrder.cpp:1368
Isis::WorkOrder::internalData
QStringList internalData() const
Gets the internal data for this WorkOrder.
Definition: WorkOrder.cpp:1377
Isis::ExportImagesWorkOrder::ProjectImageExportFunctor
This functor is meant for QtConcurrentMap.
Definition: ExportImagesWorkOrder.h:61
Isis::Project::imageList
ImageList * imageList(QString name)
Return an imagelist given its name.
Definition: Project.cpp:1520
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::ExportImagesWorkOrder::setupExecution
bool setupExecution()
Prompts the user for input.
Definition: ExportImagesWorkOrder.cpp:91

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:26