26 #include <QFileDialog>
27 #include <QMessageBox>
28 #include <QtConcurrentMap>
39 ImportShapesWorkOrder::ImportShapesWorkOrder(Project *project) :
43 QAction::setText(tr(
"Import &Shape Models..."));
44 QUndoCommand::setText(tr(
"Import Shape Models"));
49 ImportShapesWorkOrder::ImportShapesWorkOrder(
const ImportShapesWorkOrder &other) :
55 ImportShapesWorkOrder::~ImportShapesWorkOrder() {
61 ImportShapesWorkOrder *ImportShapesWorkOrder::clone()
const {
62 return new ImportShapesWorkOrder(*
this);
69 QStringList fileNames = QFileDialog::getOpenFileNames(
70 qobject_cast<QWidget *>(parent()),
71 tr(
"Import Shape Model Images"),
"",
72 tr(
"Isis cubes and list files (*.cub *.lis);;All Files (*)"));
76 if (!fileNames.isEmpty()) {
77 foreach (
FileName fileName, fileNames) {
78 if (fileName.extension() ==
"lis") {
79 TextFile listFile(fileName.expanded());
80 QString lineOfListFile;
82 while (listFile.GetLine(lineOfListFile)) {
83 stateToSave.append(lineOfListFile);
87 stateToSave.append(fileName.original());
92 QMessageBox::StandardButton copyImagesAnswer = QMessageBox::No;
93 if (!fileNames.isEmpty()) {
94 copyImagesAnswer = QMessageBox::question(qobject_cast<QWidget *>(parent()),
95 tr(
"Copy Shape Model Cubes into Project"),
96 tr(
"Should images (DN data) be copied into project?"),
97 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
101 bool copyDnData = (copyImagesAnswer == QMessageBox::Yes);
103 stateToSave.prepend(copyDnData?
"copy" :
"nocopy");
105 if (fileNames.count() > 1) {
106 QUndoCommand::setText(tr(
"Import %1 Shape Model Images").arg(stateToSave.count() - 1));
108 else if (fileNames.count() == 1) {
109 QUndoCommand::setText(tr(
"Import %1").arg(fileNames.first()));
114 bool doImport = fileNames.count() > 0 && copyImagesAnswer != QMessageBox::Cancel;
122 project()->waitForShapeReaderFinished();
128 QPointer<ShapeList> shapesWeAdded =
project()->shapes().last();
130 foreach (
Shape *shape, *shapesWeAdded) {
133 delete shapesWeAdded;
145 if (!m_newShapes->isEmpty()) {
152 if (m_warning !=
"") {
158 ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::OriginalFileToProjectCubeFunctor(
159 QThread *guiThread, QDir destinationFolder,
bool copyDnData) : m_errors(new
IException),
160 m_numErrors(new int(0)) {
161 m_destinationFolder = destinationFolder;
162 m_copyDnData = copyDnData;
163 m_guiThread = guiThread;
167 ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::OriginalFileToProjectCubeFunctor(
168 const OriginalFileToProjectCubeFunctor &other) : m_errors(other.m_errors),
169 m_numErrors(other.m_numErrors) {
170 m_destinationFolder = other.m_destinationFolder;
171 m_copyDnData = other.m_copyDnData;
172 m_guiThread = other.m_guiThread;
176 ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::~OriginalFileToProjectCubeFunctor() {
177 m_destinationFolder = QDir();
178 m_copyDnData =
false;
183 Cube *ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::operator()(
184 const FileName &original) {
187 if (*m_numErrors < 20) {
189 QString destination = QFileInfo(m_destinationFolder, original.name())
191 Cube *input =
new Cube(original,
"r");
194 Cube *copiedCube = input->copy(destination, CubeAttributeOutput());
199 FileName externalLabelFile(destination);
200 externalLabelFile = externalLabelFile.setExtension(
"ecub");
202 Cube *projectShape = input->copy(externalLabelFile, CubeAttributeOutput(
"+External"));
206 projectShape->relocateDnData(FileName(destination).name());
211 result = projectShape;
213 catch (IException &e) {
219 m_errorsLock.unlock();
227 IException ImportShapesWorkOrder::OriginalFileToProjectCubeFunctor::errors()
const {
230 result.append(*m_errors);
232 if (*m_numErrors >= 20) {
235 tr(
"Aborted import shapes due to a high number of errors"),
261 if (!confirmedShapes.isEmpty()) {
267 m_newShapes->reserve(confirmedShapes.count());
272 foreach (QString confirmedShape, confirmedShapes) {
273 QStringList fileNameAndId = confirmedShape.split(
",");
275 confirmedShapesFileNames.append(fileNameAndId.first());
277 if (fileNameAndId.count() == 2) {
278 confirmedShapesIds.append(fileNameAndId.last());
281 confirmedShapesIds.append(QString());
286 QFuture<Cube *> future = QtConcurrent::mapped(confirmedShapesFileNames, functor);
291 QThreadPool::globalInstance()->releaseThread();
292 for (
int i = 0; i < confirmedShapes.count(); i++) {
295 Cube *cube = future.resultAt(i);
298 Shape *newShape =
new Shape(future.resultAt(i));
300 if (confirmedShapesIds[i].isEmpty()) {
301 confirmedShapesIds[i] = newShape->
id();
304 newShape->
setId(confirmedShapesIds[i]);
308 ShapeInternalData.append(confirmedShapesFileNames[i]);
309 ShapeInternalData.append(confirmedShapesIds[i]);
311 newInternalData.append(ShapeInternalData.join(
","));
313 m_newShapes->append(newShape);
315 newShape->moveToThread(thread());
321 QThreadPool::globalInstance()->reserveThread();
323 m_warning = functor.errors().
toString();
325 m_newShapes->moveToThread(thread());
Internalizes a list of shapes and allows for operations on the entire list.
This copies the given shape model cube(s) into the project.
void postSyncUndo()
This method is designed to be implemented by children work orders.
void setProgressValue(int)
Sets the current progress value for the WorkOrder.
void closeCube()
Cleans up the Cube *.
void postSyncRedo()
This method is designed to be implemented by children work orders.
File name manipulation and expansion.
Project * project() const
Returns the Project this WorkOrder is attached to.
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.
QStringList internalData() const
Gets the internal data for this WorkOrder.
bool execute()
The (child) implementation of this method should prompt the user/gather state by any means necessary...
WorkOrder(Project *project)
Create a work order that will work with the given project.
#define _FILEINFO_
Macro for the filename and line number.
A type of error that cannot be classified as any of the other error types.
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 setProgressRange(int, int)
Sets the progress range of the WorkOrder.
void asyncUndo()
This method is designed to be implemented by children work orders.
QDir addShapeFolder(QString prefix)
Create and return the name of a folder for placing shape models.
void setId(QString id)
Override the automatically generated ID with the given ID.
void setModifiesDiskState(bool changesProjectOnDisk)
.
Provides access to sequential ASCII stream I/O.
This represents a shape in a project-based GUI interface.
QString toString() const
Returns a string representation of this exception.
void asyncRedo()
This method is designed to be implemented by children work orders.
virtual bool execute()
The (child) implementation of this method should prompt the user/gather state by any means necessary...
void setInternalData(QStringList data)
Sets the internal data for this WorkOrder.
IO Handler for Isis Cubes.