1 #include "MosaicController.h"     4 #include <QApplication>     8 #include <QFutureWatcher>     9 #include <QGraphicsScene>    10 #include <QGraphicsView>    11 #include <QInputDialog>    13 #include <QMessageBox>    14 #include <QProgressBar>    17 #include <QtConcurrentMap>    21 #include "DisplayProperties.h"    24 #include "ImageFileListWidget.h"    25 #include "ImageReader.h"    26 #include "MosaicSceneWidget.h"    27 #include "ProgressBar.h"    54     connect(m_imageReader, SIGNAL(imagesReady(
ImageList)), 
this, SLOT(imagesReady(
ImageList)));
    64     connect(m_scene, SIGNAL(projectionChanged(
Projection *)),
    65             m_worldScene, SLOT(setProjection(
Projection *)));
    66     connect(m_scene, SIGNAL(visibleRectChanged(QRectF)),
    67             m_worldScene, SLOT(setOutlineRect(QRectF)));
    69     settings.beginGroup(
"MosaicController");
    70     m_maxThreads = settings.value(
"maxThreads", 0).toInt();
    73     applyMaxThreadCount();
    94     foreach (
QAction * exportAct, exportActions) {
    95       fileMenu.addAction(exportAct);
    98     exportActions = m_fileList->getExportActions();
   100     foreach (
QAction * exportAct, exportActions) {
   101       fileMenu.addAction(exportAct);
   110     return m_imageReader->progress();
   114   void MosaicController::saveProject(QString projFileName) {
   117     PvlObject imageProps(
"Images");
   119     foreach (Image *image, m_images) {
   120       imageProps += image->toPvl();
   123     projFile += imageProps;
   124     projFile += m_fileList->toPvl();
   125     projFile += m_scene->toPvl();
   127     projFile.write(projFileName);
   135     settingsActs.append(m_fileList->actions());
   138     connect(setThreads, SIGNAL(triggered(
bool)),
   139             this, SLOT(changeMaxThreads()));
   140     settingsActs.append(setThreads);
   146   void MosaicController::saveSettings(QSettings &settings) {
   147     settings.beginGroup(
"MosaicController");
   148     settings.setValue(
"maxThreads", m_maxThreads);
   158     m_imageReader->read(cubeNames);
   162   void MosaicController::openProjectImages(
PvlObject projectImages) {
   163     m_imageReader->read(projectImages);
   167   void MosaicController::imagesReady(ImageList images) {
   170     foreach (Image *image, images) {
   171       connect(image, SIGNAL(destroyed(
QObject *)),
   179     QMutexLocker lock(m_mutex);
   184     foreach (openImage, images) {
   185       openImage->closeCube();
   190   void MosaicController::changeMaxThreads() {
   196     options << tr(
"Use all available");
   198     for(
int i = 1; i < 24; i++) {
   199       QString option = tr(
"Use %1 threads").arg(i + 1);
   202       if(m_maxThreads == i + 1)
   206     QString res = QInputDialog::getItem(NULL, tr(
"Concurrency"),
   207         tr(
"Set the number of threads to use"),
   208         options, current, 
false, &ok);
   211       m_maxThreads = options.indexOf(res) + 1;
   213       applyMaxThreadCount();
   225       ImageList::iterator foundElement;
   226       foundElement = qFind(m_images.begin(), m_images.end(), image);
   227       m_images.
erase(foundElement);
   230         emit allImagesClosed();
   235   void MosaicController::readProject(QString filename) {
   237       Pvl projectPvl(filename);
   240       if (projectPvl.hasObject(
"Cubes")) {
   244       PvlObject &projImages(projectPvl.findObject(
"Images"));
   246       if (projectPvl.hasObject(
"MosaicScene"))
   247         m_scene->fromPvl(projectPvl.findObject(
"MosaicScene"));
   249       if (projectPvl.hasObject(
"ImageFileList"))
   250         m_fileList->fromPvl(projectPvl.findObject(
"ImageFileList"));
   252       openProjectImages(projImages);
   254     catch(IException &e) {
   256                        "Input file is not a valid qmos project", 
_FILEINFO_);
   261   void MosaicController::saveList() {
   263         QFileDialog::getSaveFileName((
QWidget *)parent(),
   264           "Choose output file",
   265           QDir::currentPath() + 
"/files.lis",
   266           QString(
"List File (*.lis);;Text File (*.txt);;All Files (*.*)"));
   267     if(output.isEmpty()) 
return;
   269     TextFile file(output, 
"output");
   272     foreach (image, m_images) {
   273       file.PutLine( image->fileName() );
   278   void MosaicController::applyMaxThreadCount() {
   279     if (m_maxThreads <= 1) {
   280       QThreadPool::globalInstance()->setMaxThreadCount(QThread::idealThreadCount());
   283       QThreadPool::globalInstance()->setMaxThreadCount(m_maxThreads - 1);
   304     for (
int imgObjIndex = 0; imgObjIndex < images.
objects(); imgObjIndex++) {
   309       QBuffer idDataBuffer;
   310       idDataBuffer.open(QIODevice::ReadWrite);
   312       QDataStream idStream(&idDataBuffer);
   314       QUuid newId = QUuid::createUuid();
   315       QString fileName = image[
"FileName"][0];
   318       idDataBuffer.seek(0);
   321       image += 
PvlKeyword(
"ID", QString(idDataBuffer.data().toHex()));
   323       PvlKeyword oldDisplayPropsValues = image[
"Values"];
   326       PvlObject displayProps(
"DisplayProperties");
   332         OldDispPropUntransferred1, 
   335         OldDispPropShowLabel,
   336         OldDispPropShowOutline,
   337         OldDispPropUntransferred2, 
   338         OldDispPropUntransferred3  
   342       QByteArray oldHexValues(oldDisplayPropsValues[0].toLatin1());
   343       QDataStream oldValuesStream(QByteArray::fromHex(oldHexValues));
   344       oldValuesStream >> oldProps;
   348         V2DispPropShowDNs = 4,
   349         V2DispPropShowFill = 8,
   350         V2DispPropShowLabel = 16,
   351         V2DispPropShowOutline = 32
   355       newProps[V2DispPropColor] = oldProps[OldDispPropColor];
   356       newProps[V2DispPropShowDNs] = oldProps[OldDispPropShowDNs];
   357       newProps[V2DispPropShowFill] = oldProps[OldDispPropShowFill];
   358       newProps[V2DispPropShowLabel] = oldProps[OldDispPropShowLabel];
   359       newProps[V2DispPropShowOutline] = oldProps[OldDispPropShowOutline];
   361       QBuffer newPropsDataBuffer;
   362       newPropsDataBuffer.open(QIODevice::ReadWrite);
   364       QDataStream newPropsStream(&newPropsDataBuffer);
   365       newPropsStream << newProps;
   366       newPropsDataBuffer.seek(0);
   368       displayProps += 
PvlKeyword(
"Values", newPropsDataBuffer.data().toHex().data());
   372       image += displayProps;
   374       imageFileToNewId[fileName] = newId.toString().replace(QRegExp(
"[{}]"), 
"");
   378     fileListOpts.
setName(
"ImageFileList");
   380     for (
int fileListIndex = 0; fileListIndex < fileListOpts.
objects(); fileListIndex++) {
   383       for (
int i = 0; i < fileListOrderObj.
keywords(); i++) {
   388           key[0] = imageFileToNewId[key[0]];
   399       for (
int i = 0; i < zOrdering.
keywords(); i++) {
   403           key[0] = imageFileToNewId[key[0]];
 PvlObject & object(const int index)
Return the object at the specified index. 
 
int keywords() const
Returns the number of keywords contained in the PvlContainer. 
 
Internalizes a list of images and allows for operations on the entire list. 
 
File name manipulation and expansion. 
 
int objects() const
Returns the number of objects. 
 
void imagesAdded(ImageList images)
Emitted when new images are available. 
 
virtual ~MosaicController()
Free the allocated memory by this object. 
 
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes. 
 
void setName(QString name)
Sets the keyword name. 
 
void setName(const QString &name)
Set the name of the container. 
 
bool isNamed(QString name) const
Determines whether two PvlKeywords have the same name or not. 
 
bool hasObject(const QString &name) const
Returns a boolean value based on whether the object exists in the current PvlObject or not...
 
void imageClosed(QObject *image)
An open image is being deleted. 
 
MosaicController(QStatusBar *status, QSettings &settings)
MosaicWidget constructor. 
 
Base class for Map Projections. 
 
void addExportActions(QMenu &fileMenu)
Add actions that are export-related to the menu. 
 
#define _FILEINFO_
Macro for the filename and line number. 
 
void convertV1ToV2(Pvl &project)
This converts qmos project files (no other project files existed) from their original version (file n...
 
A single keyword-value pair. 
 
A type of error that cannot be classified as any of the other error types. 
 
This represents a cube in a project-based GUI interface. 
 
void append(Image *const &value)
Appends an image to the image list. 
 
Container for cube-like labels. 
 
void openImages(QStringList filenames)
Handle opening cubes by filename. 
 
Every display property for footprint views, provided for convenience. 
 
iterator erase(iterator pos)
Erases a single image from the image list. 
 
Namespace for ISIS/Bullet specific routines. 
 
Contains Pvl Groups and Pvl Objects. 
 
void deleteKeyword(const QString &name)
Remove a specified keyword.