26#include <QtConcurrentMap>
29#include "CubeAttribute.h"
31#include "IException.h"
33#include "ProjectItem.h"
34#include "ProjectItemModel.h"
53 QAction::setText(tr(
"Import &Shape Models and Ground source..."));
54 QUndoCommand::setText(tr(
"Import Shape Models and Ground source"));
104 return (item->text() ==
"Shapes");
129 QStringList fileNames = QFileDialog::getOpenFileNames(
130 qobject_cast<QWidget *>(parent()),
131 tr(
"Import Shape Model Images"),
"",
132 tr(
"Isis cubes and list files (*.cub *.lis);;All Files (*)"));
136 if (!fileNames.isEmpty()) {
137 foreach (
FileName fileName, fileNames) {
140 QString path = fileName.
path();
141 QString lineOfListFile;
143 while (listFile.GetLine(lineOfListFile)) {
144 if (lineOfListFile.contains(path)){
145 stateToSave.append(lineOfListFile);
148 stateToSave.append(path +
"/" + lineOfListFile);
153 stateToSave.append(fileName.
original());
158 QMessageBox::StandardButton copyImagesAnswer = QMessageBox::No;
159 if (!fileNames.isEmpty()) {
160 copyImagesAnswer = QMessageBox::question(qobject_cast<QWidget *>(parent()),
161 tr(
"Copy Shape Model Cubes into Project"),
162 tr(
"Should images (DN data) be copied into project?"),
163 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
167 bool copyDnData = (copyImagesAnswer == QMessageBox::Yes);
169 stateToSave.prepend(copyDnData?
"copy" :
"nocopy");
171 if (fileNames.count() > 1) {
172 QUndoCommand::setText(tr(
"Import %1 Shape Model Images").arg(stateToSave.count() - 1));
174 else if (fileNames.count() == 1) {
175 QUndoCommand::setText(tr(
"Import %1").arg(fileNames.first()));
180 bool doImport = fileNames.count() > 0 && copyImagesAnswer != QMessageBox::Cancel;
257 QThread *guiThread, QDir destinationFolder,
bool copyDnData) : m_errors(new
IException),
258 m_numErrors(new int(0)) {
272 m_numErrors(other.m_numErrors) {
283 m_destinationFolder = QDir();
284 m_copyDnData =
false;
300 if (*m_numErrors < 20) {
302 QString destination = QFileInfo(m_destinationFolder, original.
name())
304 Cube *input =
new Cube(original,
"r");
312 FileName externalLabelFile(destination);
313 externalLabelFile = externalLabelFile.setExtension(
"ecub");
325 projectShape->reopen();
329 result = projectShape;
337 m_errorsLock.unlock();
355 if (*m_numErrors >= 20) {
358 tr(
"Aborted import shapes due to a high number of errors"),
385 if (!confirmedShapes.isEmpty()) {
396 foreach (QString confirmedShape, confirmedShapes) {
397 QStringList fileNameAndId = confirmedShape.split(
",");
399 confirmedShapesFileNames.append(fileNameAndId.first());
401 if (fileNameAndId.count() == 2) {
402 confirmedShapesIds.append(fileNameAndId.last());
405 confirmedShapesIds.append(QString());
410 QFuture<Cube *> future = QtConcurrent::mapped(confirmedShapesFileNames, functor);
415 QThreadPool::globalInstance()->releaseThread();
416 for (
int i = 0; i < confirmedShapes.count(); i++) {
419 Cube *cube = future.resultAt(i);
422 Shape *newShape =
new Shape(future.resultAt(i));
424 if (confirmedShapesIds[i].isEmpty()) {
425 confirmedShapesIds[i] = newShape->id();
428 newShape->setId(confirmedShapesIds[i]);
432 ShapeInternalData.append(confirmedShapesFileNames[i]);
433 ShapeInternalData.append(confirmedShapesIds[i]);
435 newInternalData.append(ShapeInternalData.join(
","));
439 newShape->moveToThread(thread());
440 newShape->displayProperties()->moveToThread(thread());
442 newShape->closeCube();
445 QThreadPool::globalInstance()->reserveThread();
455 QMessageBox::critical(NULL, tr(
"Error"), tr(e.what()));
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
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.
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
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 copies the given shape model cube(s) into the project.
Cube * operator()(const FileName &original)
Creates ecubs and copies the DN data of the cubes, if m_copyDnData is true.
QDir m_destinationFolder
Directory where the DN data is going to be stored.
bool m_copyDnData
Stores if the user wants to copy the DN data or not.
IException errors() const
Returns the errors from importing.
~OriginalFileToProjectCubeFunctor()
Destructor.
QThread * m_guiThread
The GUI thread.
OriginalFileToProjectCubeFunctor(QThread *guiThread, QDir destinationFolder, bool copyDnData)
OriginalFileToProjectFunctor constructor.
Add shape model cubes to a project.
void postUndoExecution()
delete the imported shapes from the project.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Shapes".
ShapeList * m_list
List of shapes this workorder added to the project.
QString m_warning
QString of warning text.
bool setupExecution()
Prompt the user for shape files to import and whether to copy DN data in to project.
void postExecution()
Add the imported shapes into the project.
void undoExecution()
delete the imported shapes from the disk.
ShapeList * m_newShapes
List of shapes.
virtual ImportShapesWorkOrder * clone() const
This method clones the current ImportShapesWorkOrder and returns it.
void execute()
Creates a project shape folder and copies the shape cubes into it.
~ImportShapesWorkOrder()
Destructor.
void importConfirmedShapes(QStringList confirmedShapes, bool copyDnData)
Creates a project shape folder and copies the shape cubes into it.
ImportShapesWorkOrder(Project *project)
Creates a work order to import a shape model.
The main project for ipce.
QUndoStack * undoStack()
Returns the Projects stack of QUndoCommands.
void waitForShapeReaderFinished()
Locks program if another spot in code is still running and called this function.
Directory * directory() const
Returns the directory associated with this Project.
void setClean(bool value)
Function to change the clean state of the project.
void addShapes(QStringList shapeFiles)
Read the given shape model cube file names as Images and add them to the project.
QDir addShapeFolder(QString prefix)
Create and return the name of a folder for placing shape models.
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.
This represents a shape in a project-based GUI interface.
Internalizes a list of shapes and allows for operations on the entire list.
void append(Shape *const &value)
Appends an shape to the shape list.
void deleteFromDisk(Project *project)
Delete all of the contained Shapes from disk.
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.
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
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.