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