|
Isis 3 Programmer Reference
|
Go to the documentation of this file.
24 #include <QFileDialog>
25 #include <QMessageBox>
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");
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()));
void undoExecution()
delete the imported shapes from the disk.
ImportShapesWorkOrder(Project *project)
Creates a work order to import a shape model.
ShapeList * m_list
List of shapes this workorder added to the project.
void setId(QString id)
Override the automatically generated ID with the given ID.
QDir m_destinationFolder
Directory where the DN data is going to be stored.
ShapeDisplayProperties * displayProperties()
Get the display (GUI) properties (information) associated with this shape.
virtual bool setupExecution()
This sets up the state for the work order.
Provide Undo/redo abilities, serialization, and history for an operation.
ProjectItemModel * model()
Gets the ProjectItemModel for this directory.
QString m_warning
QString of warning text.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
void postExecution()
Add the imported shapes into the project.
File name manipulation and expansion.
@ 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.
void closeCube()
Cleans up the Cube *.
Cube * copy(FileName newFile, const CubeAttributeOutput &newFileAttributes)
Copies the cube to the new fileName.
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.
ShapeList * m_newShapes
List of shapes.
QUndoStack * undoStack()
Returns the Projects stack of QUndoCommands.
OriginalFileToProjectCubeFunctor(QThread *guiThread, QDir destinationFolder, bool copyDnData)
OriginalFileToProjectFunctor constructor.
bool m_isSynchronous
This is defaulted to true.
virtual bool isExecutable(ProjectItem *item)
This method returns true if the user clicked on a project tree node with the text "Shapes".
const char * what() const
Returns a string representation of this exception in its current state.
void deleteFromDisk(Project *project)
Delete all of the contained Shapes from disk.
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.
void waitForShapeReaderFinished()
Locks program if another spot in code is still running and called this function.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
QString id() const
Get a unique, identifying string associated with this shape.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
bool m_isUndoable
Set the workorder to be undoable/redoable This is defaulted to true - his will allow the workorder to...
void postUndoExecution()
delete the imported shapes from the project.
QString toString() const
Returns a string representation of this exception.
Cube * operator()(const FileName &original)
Creates ecubs and copies the DN data of the cubes, if m_copyDnData is true.
bool m_copyDnData
Stores if the user wants to copy the DN data or not.
Add shape model cubes to a project.
QThread * m_guiThread
The GUI thread.
This copies the given shape model cube(s) into the project.
This represents a shape in a project-based GUI interface.
Project * project() const
Returns the Project this WorkOrder is attached to.
Internalizes a list of shapes and allows for operations on the entire list.
IO Handler for Isis Cubes.
QDir addShapeFolder(QString prefix)
Create and return the name of a folder for placing shape models.
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 importConfirmedShapes(QStringList confirmedShapes, bool copyDnData)
Creates a project shape folder and copies the shape cubes into it.
void addShapes(QStringList shapeFiles)
Read the given shape model cube file names as Images and add them to the project.
void setProgressRange(int, int)
Sets the progress range of the WorkOrder.
~ImportShapesWorkOrder()
Destructor.
QString extension() const
Returns the last extension of the file name.
IException errors() const
Returns the errors from importing.
bool setupExecution()
Prompt the user for shape files to import and whether to copy DN data in to project.
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
void execute()
Creates a project shape folder and copies the shape cubes into it.
QStringList internalData() const
Gets the internal data for this WorkOrder.
void append(Shape *const &value)
Appends an shape to the shape list.
void setModifiesDiskState(bool changesProjectOnDisk)
~OriginalFileToProjectCubeFunctor()
Destructor.
QString original() const
Returns the full file name including the file path.
FileName setExtension(const QString &extension) const
Sets all current file extensions to a new extension in the file name.
virtual ImportShapesWorkOrder * clone() const
This method clones the current ImportShapesWorkOrder and returns it.
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.
QString path() const
Returns the path of the file name.
This is free and unencumbered software released into the public domain.
void reopen(QString access="r")
This method will reopen an isis sube for reading or reading/writing.
Represents an item of a ProjectItemModel in Qt's model-view framework.