24 #include <QFileDialog> 25 #include <QMessageBox> 26 #include <QtConcurrentMap> 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");
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());
445 QThreadPool::globalInstance()->reserveThread();
455 QMessageBox::critical(NULL, tr(
"Error"), tr(e.
what()));
Internalizes a list of shapes and allows for operations on the entire list.
This copies the given shape model cube(s) into the project.
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.
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
The main project for ipce.
void closeCube()
Cleans up the Cube *.
File name manipulation and expansion.
void deleteFromDisk(Project *project)
Delete all of the contained Shapes from disk.
Cube * operator()(const FileName &original)
Creates ecubs and copies the DN data of the cubes, if m_copyDnData is true.
virtual bool setupExecution()
This sets up the state for the work order.
Add shape model cubes to a project.
void append(const IException &exceptionSource)
Appends the given exception (and its list of previous exceptions) to this exception's causational exc...
void execute()
Creates a project shape folder and copies the shape cubes into it.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
QUndoStack * undoStack()
Returns the Projects stack of QUndoCommands.
ShapeDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this shape.
void importConfirmedShapes(QStringList confirmedShapes, bool copyDnData)
Creates a project shape folder and copies the shape cubes into it.
void postExecution()
Add the imported shapes into the project.
QThread * m_guiThread
The GUI thread.
virtual ImportShapesWorkOrder * clone() const
This method clones the current ImportShapesWorkOrder and returns it.
QDir m_destinationFolder
Directory where the DN data is going to be stored.
void waitForShapeReaderFinished()
Locks program if another spot in code is still running and called this function.
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...
QString m_warning
QString of warning text.
IException errors() const
Returns the errors from importing.
void undoExecution()
delete the imported shapes from the disk.
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.
ShapeList * m_list
List of shapes this workorder added to the project.
#define _FILEINFO_
Macro for the filename and line number.
void append(Shape *const &value)
Appends an shape to the shape list.
ImportShapesWorkOrder(Project *project)
Creates a work order to import a shape model.
ShapeList * m_newShapes
List of shapes.
Manipulate and parse attributes of output cube filenames.
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.
bool m_isSynchronous
This is defaulted to true.
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
bool setupExecution()
Prompt the user for shape files to import and whether to copy DN data in to project.
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
QString id() const
Get a unique, identifying string associated with this shape.
void addShapes(QStringList shapeFiles)
Read the given shape model cube file names as Images and add them to the project. ...
void postUndoExecution()
delete the imported shapes from the project.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
QDir addShapeFolder(QString prefix)
Create and return the name of a folder for placing shape models.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
void setId(QString id)
Override the automatically generated ID with the given ID.
OriginalFileToProjectCubeFunctor(QThread *guiThread, QDir destinationFolder, bool copyDnData)
OriginalFileToProjectFunctor constructor.
void setModifiesDiskState(bool changesProjectOnDisk)
Provides access to sequential ASCII stream I/O.
QString toString() const
Returns a string representation of this exception.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
This represents a shape in a project-based GUI interface.
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.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Shapes"...
Project * project() const
Returns the Project this WorkOrder is attached to.
~ImportShapesWorkOrder()
Destructor.
QStringList internalData() const
Gets the internal data for this WorkOrder.
bool m_copyDnData
Stores if the user wants to copy the DN data or not.
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
void setClean(bool value)
Function to change the clean state of the project.
IO Handler for Isis Cubes.