26 #include <QFileDialog> 27 #include <QMessageBox> 28 #include <QtConcurrentMap> 55 QAction::setText(tr(
"Import &Images..."));
56 QUndoCommand::setText(tr(
"Import Images"));
110 return (item->text() ==
"Images");
136 QStringList fileNames = QFileDialog::getOpenFileNames(
137 qobject_cast<QWidget *>(parent()),
138 tr(
"Import Images"),
"",
139 tr(
"Isis cubes and list files (*.cub *.lis);;All Files (*)"));
143 if (!fileNames.isEmpty()) {
144 foreach (
FileName fileName, fileNames) {
147 QString path = fileName.
path();
148 QString lineOfListFile;
150 while (listFile.GetLine(lineOfListFile)) {
151 FileName relFileName(path +
"/" + lineOfListFile);
153 stateToSave->append(path +
"/" + lineOfListFile);
156 FileName absFileName(lineOfListFile);
157 if ( absFileName.
fileExists() && lineOfListFile.startsWith(
"/") ) {
158 stateToSave->append(lineOfListFile);
162 project()->warn(
"File " + lineOfListFile +
" not found");
168 stateToSave->append(fileName.
original());
172 QMessageBox::StandardButton saveProjectAnswer = QMessageBox::No;
174 saveProjectAnswer = QMessageBox::question(qobject_cast<QWidget *>(parent()),
175 tr(
"Save Project Before Importing Images"),
176 tr(
"Would you like to save your project <b>before</b> importing images? It can be " 177 "slow to save your project after these images have been loaded if you do not " 178 "save now. <br><br>IMPORTANT: WHEN IMPORTING LARGE DATA SETS, SAVING YOUR " 179 "PROJECT BEFORE IMPORTING IS HIGHLY RECOMMENDED."),
180 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
184 if (saveProjectAnswer == QMessageBox::Yes) {
186 saveWorkOrder.trigger();
189 QMessageBox::StandardButton copyImagesAnswer = QMessageBox::No;
190 if (!stateToSave->isEmpty() && saveProjectAnswer != QMessageBox::Cancel) {
191 copyImagesAnswer = QMessageBox::question(qobject_cast<QWidget *>(parent()),
192 tr(
"Copy Images into Project"),
193 tr(
"Should images (DN data) be copied into project?"),
194 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
198 bool copyDnData = (copyImagesAnswer == QMessageBox::Yes);
200 stateToSave->prepend(copyDnData?
"copy" :
"nocopy");
202 if (fileNames.count() > 1) {
203 QUndoCommand::setText(tr(
"Import %1 Images").arg(stateToSave->count() - 1));
205 else if (fileNames.count() == 1 && stateToSave->count() > 2) {
206 QUndoCommand::setText(tr(
"Import %1 Images from %2").arg(
207 QString::number(stateToSave->count() - 1), fileNames.first()));
210 QUndoCommand::setText(tr(
"Import %1").arg(fileNames.first()));
216 bool doImport = stateToSave->count() > 1 && saveProjectAnswer != QMessageBox::Cancel &&
217 copyImagesAnswer != QMessageBox::Cancel;
224 QMessageBox::critical(NULL, tr(
"Error"), tr(e.
what()));
293 QMessageBox::critical(NULL, tr(
"Error"), tr(e.
what()));
339 QThread *guiThread, QDir destinationFolder,
bool copyDnData) : m_errors(new
IException),
340 m_numErrors(new int(0)) {
354 m_numErrors(other.m_numErrors) {
367 m_destinationFolder = QDir();
368 m_copyDnData =
false;
393 if (*m_numErrors < 20) {
395 QString destination = QFileInfo(m_destinationFolder, original.
name())
397 Cube *input =
new Cube(original,
"r");
405 FileName externalLabelFile(destination);
406 externalLabelFile = externalLabelFile.
setExtension(
"ecub");
422 result = projectImage;
432 m_errorsLock.unlock();
454 if (*m_numErrors >= 20) {
457 tr(
"Aborted import images due to a high number of errors"),
484 if (!confirmedImages.isEmpty()) {
499 foreach (QString confirmedImage, confirmedImages) {
500 QStringList fileNameAndId = confirmedImage.split(
",");
501 confirmedImagesFileNames.append(fileNameAndId.first());
504 if (fileNameAndId.count() == 2) {
505 confirmedImagesIds.append(fileNameAndId.last());
508 confirmedImagesIds.append(QString());
514 QFuture<Cube *> future = QtConcurrent::mapped(confirmedImagesFileNames, functor);
524 QThreadPool::globalInstance()->releaseThread();
525 for (
int i = 0; i < confirmedImages.count(); i++) {
530 Cube *cube = future.resultAt(i);
538 PvlObject::FindOptions::Traverse).findKeyword(
"InstrumentId")[0];
540 PvlObject::FindOptions::Traverse).findKeyword(
"TargetName")[0];
541 if (!
project()->hasTarget(targetName)) {
546 if (!
project()->hasCamera(instrumentId)) {
550 else if (!
project()->hasCamera(instrumentId)) {
562 if (confirmedImagesIds[i].isEmpty()) {
563 confirmedImagesIds[i] = newImage->
id();
566 newImage->
setId(confirmedImagesIds[i]);
570 imageInternalData.append(confirmedImagesFileNames[i]);
571 imageInternalData.append(confirmedImagesIds[i]);
573 newInternalData.append(imageInternalData.join(
","));
580 newImage->moveToThread(thread());
587 QThreadPool::globalInstance()->reserveThread();
599 folder.removeRecursively();
606 QMessageBox::critical(NULL, tr(
"Error"), tr(e.
what()));
void waitForImageReaderFinished()
Locks program if another spot in code is still running and called this function.
QString path() const
Returns the path of the file name.
const char * what() const
Returns a string representation of this exception in its current state.
bool m_copyDnData
Indicates whether the cube data will be copied to the project.
Cube * operator()(const FileName &original)
Overloads the callable operator to invoke this functor.
QDir addImageFolder(QString prefix)
Create and return the name of a folder for placing images.
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
Internalizes a list of images and allows for operations on the entire list.
The main project for ipce.
IException errors() const
Indicates if any errors occurred during the import.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
File name manipulation and expansion.
Camera * camera()
Return a camera associated with the cube.
void addCamera(Camera *camera)
Adds a new camera to the project.
void deleteFromDisk(Project *project)
Delete all of the contained Images from disk.
virtual bool setupExecution()
This sets up the state for the work order.
void addTarget(Target *target)
Adds a new target to the project.
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
bool isTemporaryProject() const
Returns if the project is a temp project or not.
QThread * m_guiThread
Pointer to the GUI thread. Not used?
void setId(QString id)
Override the automatically generated ID with the given ID.
virtual void postUndoExecution()
Cleans up memory (images) after the undo execution occurs.
static QStringList images(QStringList)
Verify that the input fileNames are image files.
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
ProjectItem * findItemData(const QVariant &data, int role=Qt::UserRole+1)
Returns the first item found that contains the given data in the given role or a null pointer if no i...
virtual void postExecution()
Associates the imported images to the project.
Directory * directory() const
Returns the directory associated with this Project.
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
Provide Undo/redo abilities, serialization, and history for an operation.
~OriginalFileToProjectCubeFunctor()
Destructor.
Target * target() const
Returns a pointer to the target object.
#define _FILEINFO_
Macro for the filename and line number.
Manipulate and parse attributes of output cube filenames.
OriginalFileToProjectCubeFunctor(QThread *guiThread, QDir destinationFolder, bool copyDnData)
Creates the internal functor.
A type of error that cannot be classified as any of the other error types.
virtual void removeItem(ProjectItem *item)
Removes an item and its children from the model.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
QString original() const
Returns the full file name including the file path.
ImageList * m_list
List of images that was succesfully imported into project.
This represents a cube in a project-based GUI interface.
bool m_isSynchronous
This is defaulted to true.
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
void append(Image *const &value)
Appends an image to the image list.
void addImages(QStringList imageFiles)
Read the given cube file names as Images and add them to the project.
This class is used to create and store valid Isis3 targets.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Images"...
void importConfirmedImages(QStringList confirmedImages, bool copyDnData)
Imports the images.
void setModifiesDiskState(bool changesProjectOnDisk)
Provides access to sequential ASCII stream I/O.
QDir m_destinationFolder
Directory where to import the images to.
QString toString() const
Returns a string representation of this exception.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
QString id() const
Get a unique, identifying string associated with this image.
ImageList * m_newImages
List of images that are being imported in this work order.
~ImportImagesWorkOrder()
Destructor.
Represents an item of a ProjectItemModel in Qt's model-view framework.
void relocateDnData(FileName dnDataFile)
Relocates the DN data for a cube to an external cube label file.
FileName setExtension(const QString &extension) const
Sets all current file extensions to a new extension in the file name.
Namespace for ISIS/Bullet specific routines.
QString extension() const
Returns the last extension of the file name.
Saves a project to disk (File->Save Project...)
This is used for work orders that will not undo or redo (See createsCleanState()) ...
This copies the given cube(s) into the project.
Project * project() const
Returns the Project this WorkOrder is attached to.
QString m_warning
String of any errors/warnings that occurred during import.
virtual bool setupExecution()
Sets up this work order before being executed.
virtual void execute()
Executes the work order.
QStringList internalData() const
Gets the internal data for this WorkOrder.
bool fileExists() const
Returns true if the file exists; false otherwise.
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
void closeCube()
Cleans up the Cube pointer.
ImportImagesWorkOrder(Project *project)
Creates an asynchronous WorkOrder for importing images to the project.
virtual ImportImagesWorkOrder * clone() const
Creates a clone of this work order.
void setClean(bool value)
Function to change the clean state of the project.
IO Handler for Isis Cubes.
virtual void undoExecution()
Undoes the work order's execute.