1#include "MosaicController.h"
8#include <QFutureWatcher>
9#include <QGraphicsScene>
10#include <QGraphicsView>
11#include <QInputDialog>
14#include <QProgressBar>
15#include <QRegularExpression>
18#include <QtConcurrentMap>
20#include "ControlNet.h"
22#include "DisplayProperties.h"
24#include "IException.h"
25#include "ImageFileListWidget.h"
26#include "ImageReader.h"
27#include "MosaicSceneWidget.h"
28#include "ProgressBar.h"
55 connect(m_imageReader, SIGNAL(imagesReady(
ImageList)),
this, SLOT(imagesReady(
ImageList)));
65 connect(m_scene, SIGNAL(projectionChanged(
Projection *)),
66 m_worldScene, SLOT(setProjection(
Projection *)));
67 connect(m_scene, SIGNAL(visibleRectChanged(QRectF)),
68 m_worldScene, SLOT(setOutlineRect(QRectF)));
70 settings.beginGroup(
"MosaicController");
71 m_maxThreads = settings.value(
"maxThreads", 0).toInt();
74 applyMaxThreadCount();
95 foreach (
QAction * exportAct, exportActions) {
96 fileMenu.addAction(exportAct);
99 exportActions = m_fileList->getExportActions();
101 foreach (
QAction * exportAct, exportActions) {
102 fileMenu.addAction(exportAct);
111 return m_imageReader->progress();
115 void MosaicController::saveProject(QString projFileName) {
118 PvlObject imageProps(
"Images");
120 foreach (Image *image, m_images) {
121 imageProps += image->toPvl();
124 PvlObject qtInfoObject(
"QtInfo");
126 PvlKeyword qtVersionKeyword(
"QtVersion", QString::number(stream.version()));
127 qtVersionKeyword.addCommentWrapped(
"See QDataStream Version for more info on QT version");
128 qtInfoObject += qtVersionKeyword;
129 projFile += qtInfoObject;
130 projFile += imageProps;
131 projFile += m_fileList->toPvl();
132 projFile += m_scene->toPvl();
134 projFile.write(projFileName);
138 QList<QAction *> MosaicController::getSettingsActions() {
139 QList<QAction *> settingsActs;
142 settingsActs.append(m_fileList->actions());
144 QAction *setThreads =
new QAction(
"Set &Thread Limit",
this);
145 connect(setThreads, SIGNAL(triggered(
bool)),
146 this, SLOT(changeMaxThreads()));
147 settingsActs.append(setThreads);
153 void MosaicController::saveSettings(QSettings &settings) {
154 settings.beginGroup(
"MosaicController");
155 settings.setValue(
"maxThreads", m_maxThreads);
165 m_imageReader->read(cubeNames);
169 void MosaicController::openProjectImages(PvlObject projectImages) {
170 m_imageReader->read(projectImages);
174 void MosaicController::imagesReady(ImageList images) {
177 foreach (Image *image, images) {
178 connect(image, SIGNAL(destroyed(
QObject *)),
186 QMutexLocker lock(m_mutex);
191 foreach (openImage, images) {
192 openImage->closeCube();
197 void MosaicController::changeMaxThreads() {
203 options << tr(
"Use all available");
205 for(
int i = 1; i < 24; i++) {
206 QString option = tr(
"Use %1 threads").arg(i + 1);
209 if(m_maxThreads == i + 1)
213 QString res = QInputDialog::getItem(NULL, tr(
"Concurrency"),
214 tr(
"Set the number of threads to use"),
215 options, current,
false, &ok);
218 m_maxThreads = options.indexOf(res) + 1;
220 applyMaxThreadCount();
232 ImageList::iterator foundElement;
233 foundElement = std::find(m_images.begin(), m_images.end(), image);
234 m_images.erase(foundElement);
237 emit allImagesClosed();
242 void MosaicController::readProject(QString filename) {
244 Pvl projectPvl(filename);
247 if (projectPvl.hasObject(
"Cubes")) {
251 PvlKeyword qtVersionKeyword;
252 if (projectPvl.hasObject(
"QtInfo")) {
253 PvlObject &qtInfoObject = projectPvl.findObject(
"QtInfo");
254 qtVersionKeyword = qtInfoObject[
"QtVersion"];
257 qtVersionKeyword = PvlKeyword(
"QtVersion", QString::number(QDataStream::Qt_5_15));
260 PvlObject &projImages(projectPvl.findObject(
"Images"));
262 if (projectPvl.hasObject(
"MosaicScene")) {
263 PvlObject &mosaicScene = projectPvl.findObject(
"MosaicScene");
264 mosaicScene += qtVersionKeyword;
265 m_scene->fromPvl(mosaicScene);
268 if (projectPvl.hasObject(
"ImageFileList"))
269 m_fileList->fromPvl(projectPvl.findObject(
"ImageFileList"));
271 m_imageReader->setQtVersion(
int(qtVersionKeyword));
272 openProjectImages(projImages);
274 catch(IException &e) {
275 throw IException(e, IException::Unknown,
276 "Input file is not a valid qmos project", _FILEINFO_);
281 void MosaicController::saveList() {
283 QFileDialog::getSaveFileName((QWidget *)parent(),
284 "Choose output file",
285 QDir::currentPath() +
"/files.lis",
286 QString(
"List File (*.lis);;Text File (*.txt);;All Files (*.*)"));
287 if(output.isEmpty())
return;
289 TextFile file(output,
"output");
292 foreach (image, m_images) {
293 file.PutLine( image->fileName() );
298 void MosaicController::applyMaxThreadCount() {
299 if (m_maxThreads <= 1) {
300 QThreadPool::globalInstance()->setMaxThreadCount(QThread::idealThreadCount());
303 QThreadPool::globalInstance()->setMaxThreadCount(m_maxThreads - 1);
318 PvlObject &images = project.findObject(
"Cubes");
320 images.setName(
"Images");
324 for (
int imgObjIndex = 0; imgObjIndex < images.objects(); imgObjIndex++) {
325 PvlObject &image = images.object(imgObjIndex);
326 image.setName(
"Image");
329 QBuffer idDataBuffer;
330 idDataBuffer.open(QIODevice::ReadWrite);
332 QDataStream idStream(&idDataBuffer);
334 QUuid newId = QUuid::createUuid();
335 QString fileName = image[
"FileName"][0];
338 idDataBuffer.seek(0);
341 image += PvlKeyword(
"ID", QString(idDataBuffer.data().toHex()));
343 PvlKeyword oldDisplayPropsValues = image[
"Values"];
344 image.deleteKeyword(
"Values");
346 PvlObject displayProps(
"DisplayProperties");
347 displayProps += PvlKeyword(
"DisplayName", FileName(fileName).name());
352 OldDispPropUntransferred1,
355 OldDispPropShowLabel,
356 OldDispPropShowOutline,
357 OldDispPropUntransferred2,
358 OldDispPropUntransferred3
362 QByteArray oldHexValues(oldDisplayPropsValues[0].toLatin1());
363 QDataStream oldValuesStream(QByteArray::fromHex(oldHexValues));
364 oldValuesStream >> oldProps;
368 V2DispPropShowDNs = 4,
369 V2DispPropShowFill = 8,
370 V2DispPropShowLabel = 16,
371 V2DispPropShowOutline = 32
375 newProps[V2DispPropColor] = oldProps[OldDispPropColor];
376 newProps[V2DispPropShowDNs] = oldProps[OldDispPropShowDNs];
377 newProps[V2DispPropShowFill] = oldProps[OldDispPropShowFill];
378 newProps[V2DispPropShowLabel] = oldProps[OldDispPropShowLabel];
379 newProps[V2DispPropShowOutline] = oldProps[OldDispPropShowOutline];
381 QBuffer newPropsDataBuffer;
382 newPropsDataBuffer.open(QIODevice::ReadWrite);
384 QDataStream newPropsStream(&newPropsDataBuffer);
385 newPropsStream << newProps;
386 newPropsDataBuffer.seek(0);
388 displayProps += PvlKeyword(
"Values", newPropsDataBuffer.data().toHex().data());
392 image += displayProps;
394 imageFileToNewId[fileName] = newId.toString().replace(QRegularExpression(
"[{}]"),
"");
397 PvlObject &fileListOpts = project.findObject(
"MosaicFileList");
398 fileListOpts.setName(
"ImageFileList");
400 for (
int fileListIndex = 0; fileListIndex < fileListOpts.objects(); fileListIndex++) {
401 PvlObject &fileListOrderObj = fileListOpts.object(fileListIndex);
403 for (
int i = 0; i < fileListOrderObj.keywords(); i++) {
404 PvlKeyword &key = fileListOrderObj[i];
406 if (key.isNamed(
"Cube")) {
407 key.setName(
"Image");
408 key[0] = imageFileToNewId[key[0]];
413 PvlObject &sceneOpts = project.findObject(
"MosaicScene");
415 if (sceneOpts.hasObject(
"ZOrdering")) {
416 PvlObject &zOrdering = sceneOpts.findObject(
"ZOrdering");
419 for (
int i = 0; i < zOrdering.keywords(); i++) {
420 PvlKeyword &key = zOrdering[i];
422 if (key.isNamed(
"ZValue")) {
423 key[0] = imageFileToNewId[key[0]];
@ FootprintViewProperties
Every display property for footprint views, provided for convenience.
This represents a cube in a project-based GUI interface.
Internalizes a list of images and allows for operations on the entire list.
void append(Image *const &value)
Appends an image to the image list.
void convertV1ToV2(Pvl &project)
This converts qmos project files (no other project files existed) from their original version (file n...
MosaicController(QStatusBar *status, QSettings &settings)
MosaicWidget constructor.
void openImages(QStringList filenames)
Handle opening cubes by filename.
void addExportActions(QMenu &fileMenu)
Add actions that are export-related to the menu.
void imageClosed(QObject *image)
An open image is being deleted.
void imagesAdded(ImageList images)
Emitted when new images are available.
virtual ~MosaicController()
Free the allocated memory by this object.
Base class for Map Projections.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.