9#include "CnetDisplayProperties.h"
17#include <QFutureWatcher>
19#include <QReadWriteLock>
24#include <QtConcurrentRun>
26#include "ControlNet.h"
28#include "IException.h"
30#include "SerialNumber.h"
34 CnetDisplayProperties *CnetDisplayProperties::m_instance = NULL;
37 CnetDisplayProperties *CnetDisplayProperties::getInstance() {
38 return m_instance ? m_instance : m_instance =
new CnetDisplayProperties;
42 CnetDisplayProperties::CnetDisplayProperties() {
46 m_curComposing =
false;
47 m_showFullPath =
false;
48 m_coordinateDisplayType = LatLonRadius;
50 m_readWriteLock =
new QReadWriteLock;
54 m_composedCount =
new QAtomicInt;
55 m_interruptFlag =
new QAtomicInt;
56 m_interruptFlag->fetchAndStoreRelaxed(0);
58 m_composeStatusPoller =
new QTimer;
59 connect(m_composeStatusPoller, SIGNAL(timeout()),
60 this, SLOT(composeStatusUpdated()));
62 m_composeWatcher =
new QFutureWatcher< QMap< QString, QString > >;
63 connect(m_composeWatcher, SIGNAL(finished()),
64 this, SLOT(serialNumbersComposed()));
85 CnetDisplayProperties::~CnetDisplayProperties() {
86 delete m_serialNumberToFileNameMap;
87 m_serialNumberToFileNameMap = NULL;
89 delete m_composeWatcher;
90 m_composeWatcher = NULL;
92 delete m_composedCount;
93 m_composedCount = NULL;
95 delete m_interruptFlag;
96 m_interruptFlag = NULL;
100 bool CnetDisplayProperties::currentlyComposing()
const {
101 return m_curComposing;
114 QList<QString> results;
116 if (!currentlyComposing()) {
117 foreach (QString serialNumber, cnet->GetCubeSerials()) {
118 QString possibleFileName =
getImageName(serialNumber,
true);
120 if (possibleFileName != serialNumber)
121 results.append(possibleFileName);
129 QString CnetDisplayProperties::getFileName(QString fileName,
130 bool forceFullPaths)
const {
133 if (forceFullPaths || getShowsFullPaths())
136 result = QFileInfo(fileName).fileName();
154 bool forceFullPaths)
const {
156 QString imageName = cubeSerialNumber;
158 m_readWriteLock->lockForRead();
160 if (m_serialNumberToFileNameMap && useFileNames &&
161 m_serialNumberToFileNameMap->contains(cubeSerialNumber)) {
162 QString value = m_serialNumberToFileNameMap->value(cubeSerialNumber);
163 m_readWriteLock->unlock();
165 if (value.toLower() !=
"unknown")
166 imageName = getFileName(value, forceFullPaths);
169 m_readWriteLock->unlock();
176 QString CnetDisplayProperties::getSerialNumber(QString imageId) {
177 QString sn = imageId;
179 if (m_serialNumberToFileNameMap && useFileNames) {
180 m_readWriteLock->lockForRead();
181 QMapIterator< QString, QString > i(*m_serialNumberToFileNameMap);
184 while (!found && i.hasNext()) {
186 if (i.value() == imageId) {
192 m_readWriteLock->unlock();
199 bool CnetDisplayProperties::getShowsFullPaths()
const {
200 return m_showFullPath;
211 return Isis::CnetDisplayProperties::m_coordinateDisplayType;
215 void CnetDisplayProperties::setCubeList(QString fileName) {
216 QFile imageListFile(fileName);
218 if (!imageListFile.exists()) {
219 IString msg =
"The file [";
220 msg += (IString) fileName;
221 msg +=
"] does not exist.\n";
225 if (!imageListFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
226 IString msg =
"The file [";
227 msg += (IString) fileName;
228 msg +=
"] failed to open.\n";
233 QTextStream ts(&imageListFile);
236 imageFileNames << ts.readLine();
238 imageListFile.close();
240 m_curComposing =
true;
242 QFuture< QMap< QString, QString > > future = QtConcurrent::run(
243 this, &CnetDisplayProperties::composeSerialNumbers, imageFileNames);
245 m_composeWatcher->setFuture(future);
249 void CnetDisplayProperties::setFileNameUsage(
bool preferFileNames) {
250 useFileNames = preferFileNames;
267 void CnetDisplayProperties::setShowsFullPaths(
bool newState) {
268 m_showFullPath = newState;
281 m_coordinateDisplayType = coordDisplay;
287 emit composeProgressRangeChanged(0, fileNames.size() - 1);
288 m_composedCount->fetchAndStoreRelaxed(0);
292 for (
int i = 0; *m_interruptFlag == 0 && i < fileNames.size(); i++) {
293 QString fileName = fileNames[i];
300 m_composedCount->fetchAndAddRelaxed(1);
307 void CnetDisplayProperties::nullify() {
308 m_serialNumberToFileNameMap = NULL;
309 m_composeWatcher = NULL;
311 m_composedCount = NULL;
312 m_interruptFlag = NULL;
314 m_readWriteLock = NULL;
318 void CnetDisplayProperties::composeStatusUpdated() {
319 emit composeProgressChanged(*m_composedCount);
323 void CnetDisplayProperties::serialNumbersComposed() {
324 if (*m_interruptFlag) {
325 m_interruptFlag->fetchAndStoreRelaxed(0);
328 m_readWriteLock->lockForWrite();
329 *m_serialNumberToFileNameMap = m_composeWatcher->result();
331 m_readWriteLock->unlock();
334 m_curComposing =
false;
335 m_composeStatusPoller->stop();
336 emit composeProgressRangeChanged(0, 0);
337 emit composeProgressChanged(0);
338 emit compositionFinished();
QList< QString > getCubeList(ControlNet *cnet) const
TODO comment me.
QString getImageName(QString cubeSerialNumber, bool forceFullPaths=false) const
void setCoordinateDisplayType(enum coordinateDisplayType coordDisplay)
Sets the coordinate display type (0 = LatLonRadius, 1 = XYZ).
coordinateDisplayType
Returns coordinate display type (0 = LatLonRadius, 1 = XYZ).
IO Handler for Isis Cubes.
void open(const QString &cfile, QString access="r")
This method will open an existing isis cube for reading or reading/writing.
@ Programmer
This error is for when a programmer made an API call that was illegal.
static QString Compose(Pvl &label, bool def2filename=false)
Compose a SerialNumber from a PVL.
This is free and unencumbered software released into the public domain.