28#include <QtConcurrentMap>
32#include "CubeAttribute.h"
35#include "ProjectItem.h"
36#include "ProjectItemModel.h"
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);
152 if (relFileName.fileExists() ) {
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;
173 if (stateToSave->count() >= 100 &&
project()->isTemporaryProject()) {
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");
418 projectImage->reopen();
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);
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()));
Manipulate and parse attributes of output cube filenames.
IO Handler for Isis Cubes.
void relocateDnData(FileName dnDataFile)
Relocates the DN data for a cube to an external cube label file.
Camera * camera()
Return a camera associated with the cube.
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
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.
QString extension() const
Returns the last extension of the file name.
@ Unknown
A type of error that cannot be classified as any of the other error types.
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
This represents a cube in a project-based GUI interface.
void setId(QString id)
Override the automatically generated ID with the given ID.
void closeCube()
Cleans up the Cube pointer.
ImageDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this image.
QString id() const
Get a unique, identifying string associated with this image.
Internalizes a list of images and allows for operations on the entire list.
void deleteFromDisk(Project *project)
Delete all of the contained Images from disk.
void append(Image *const &value)
Appends an image to the image list.
This copies the given cube(s) into the project.
IException errors() const
Indicates if any errors occurred during the import.
Cube * operator()(const FileName &original)
Overloads the callable operator to invoke this functor.
~OriginalFileToProjectCubeFunctor()
Destructor.
OriginalFileToProjectCubeFunctor(QThread *guiThread, QDir destinationFolder, bool copyDnData)
Creates the internal functor.
bool m_copyDnData
Indicates whether the cube data will be copied to the project.
QDir m_destinationFolder
Directory where to import the images to.
QThread * m_guiThread
Pointer to the GUI thread. Not used?
QString m_warning
String of any errors/warnings that occurred during import.
virtual void undoExecution()
Undoes the work order's execute.
~ImportImagesWorkOrder()
Destructor.
ImageList * m_list
List of images that was succesfully imported into project.
ImportImagesWorkOrder(Project *project)
Creates an asynchronous WorkOrder for importing images to the project.
virtual bool setupExecution()
Sets up this work order before being executed.
void importConfirmedImages(QStringList confirmedImages, bool copyDnData)
Imports the images.
virtual void execute()
Executes the work order.
virtual void postExecution()
Associates the imported images to the project.
ImageList * m_newImages
List of images that are being imported in this work order.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Images".
virtual ImportImagesWorkOrder * clone() const
Creates a clone of this work order.
virtual void postUndoExecution()
Cleans up memory (images) after the undo execution occurs.
The main project for ipce.
void waitForImageReaderFinished()
Locks program if another spot in code is still running and called this function.
void addTarget(Target *target)
Adds a new target to the project.
static QStringList images(QStringList)
Verify that the input fileNames are image files.
Directory * directory() const
Returns the directory associated with this Project.
void setClean(bool value)
Function to change the clean state of the project.
void addCamera(Camera *camera)
Adds a new camera to the project.
QDir addImageFolder(QString prefix)
Create and return the name of a folder for placing images.
void addImages(QStringList imageFiles)
Read the given cube file names as Images and add them to the project.
Represents an item of a ProjectItemModel in Qt's model-view framework.
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 removeItem(ProjectItem *item)
Removes an item and its children from the model.
@ Traverse
Search child objects.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Saves a project to disk (File->Save Project...)
virtual Target * target() const
Returns a pointer to the target object.
This class is used to create and store valid Isis targets.
Provides access to sequential ASCII stream I/O.
Provide Undo/redo abilities, serialization, and history for an operation.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
bool m_isSynchronous
This is defaulted to true.
@ WorkOrderFinished
This is used for work orders that will not undo or redo (See createsCleanState())
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
virtual bool setupExecution()
This sets up the state for the work order.
QStringList internalData() const
Gets the internal data for this WorkOrder.
void setModifiesDiskState(bool changesProjectOnDisk)
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
Project * project() const
Returns the Project this WorkOrder is attached to.
This is free and unencumbered software released into the public domain.