1 #include "ShapeReader.h" 
    4 #include <QApplication> 
    7 #include <QFutureWatcher> 
    8 #include <QInputDialog> 
   10 #include <QProgressBar> 
   13 #include <QtConcurrentMap> 
   16 #include "IException.h" 
   18 #include "ShapeDisplayProperties.h" 
   21 #include "ProgressBar.h" 
   22 #include "PvlObject.h" 
   39     m_cameraMutex = cameraMutex;
 
   40     m_requireFootprints = requireFootprints;
 
   47     connect(m_watcher, SIGNAL(resultReadyAt(
int)),
 
   48             this, SLOT(shapesReady(
int)));
 
   49     connect(m_watcher, SIGNAL(finished()),
 
   50             this, SLOT(mappedFinished()));
 
   52     m_safeFileOpen = 
false;
 
   56     m_mappedRunning = 
false;
 
   70       m_watcher->waitForFinished();
 
   87     if (!m_safeFileOpenAct) {
 
   88       m_safeFileOpenAct = 
new QAction(tr(
"&Safe File Open"), 
this);
 
   89       m_safeFileOpenAct->setCheckable(
true);
 
   90       m_safeFileOpenAct->setChecked(m_safeFileOpen);
 
   91       m_safeFileOpenAct->setWhatsThis(tr(
"This lowers the number of " 
   92           "simulataneously open files drastically in order to stay under the " 
   93           "operating system limit. Only use this if you are having trouble " 
   94           "loading large numbers of shapes."));
 
   95       connect(m_safeFileOpenAct, SIGNAL(toggled(
bool)),
 
   96               this, SLOT(setSafeFileOpen(
bool)));
 
   99     results.append(m_safeFileOpenAct);
 
  110   void ShapeReader::read(PvlObject shapesObject) {
 
  111     read(shapesObject.beginObject(), shapesObject.endObject());
 
  119     read(cubeNames.begin(), cubeNames.end());
 
  123   void ShapeReader::setSafeFileOpen(
bool safeFileOpen) {
 
  124     m_safeFileOpen = safeFileOpen;
 
  125     if (m_safeFileOpen) {
 
  126       m_safeFileOpenAct->setChecked(m_safeFileOpen);
 
  131   void ShapeReader::initProgress() {
 
  132     m_progress->setVisible(
false);
 
  133     m_progress->setRange(0, 0);
 
  134     m_progress->setValue(0);
 
  138   void ShapeReader::start() {
 
  139     if (!m_backlog.isEmpty() && !m_mappedRunning) {
 
  140       m_progress->setVisible(
true);
 
  142       int maxOpenShapes = m_safeFileOpen? 20 : 400;
 
  144       m_backlog = m_backlog.mid(maxOpenShapes);
 
  146       QFuture< Shape * > shapes = QtConcurrent::mapped(
 
  148           VariantToShapeFunctor(m_cameraMutex, m_requireFootprints, QThread::currentThread(),
 
  149             m_openFilled, m_defaultAlpha));
 
  151       m_watcher->setFuture(shapes);
 
  152       m_mappedRunning = 
true;
 
  157   void ShapeReader::readSettings() {
 
  159         FileName(
"$HOME/.Isis/" + QApplication::applicationName() + 
"/Shape Reader.config")
 
  161         QSettings::NativeFormat);
 
  163     m_safeFileOpen = settings.value(
"safeFileOpen", m_safeFileOpen).toBool();
 
  167   void ShapeReader::writeSettings() {
 
  169         FileName(
"$HOME/.Isis/" + QApplication::applicationName() + 
"/Shape Reader.config")
 
  171         QSettings::NativeFormat);
 
  173     settings.setValue(
"safeFileOpen", m_safeFileOpen);
 
  177   void ShapeReader::shapesReady(
int index) {
 
  178     m_progress->setValue(m_progress->value() + 1);
 
  182   void ShapeReader::mappedFinished() {
 
  183     ShapeList shapes(m_watcher->future().results());
 
  188     foreach (Shape *shape, shapes) {
 
  190         shapes.removeAll(shape);
 
  194     emit shapesReady(shapes);
 
  196     m_mappedRunning = 
false;
 
  197     if (!m_backlog.isEmpty()) {
 
  212       QMutex *cameraMutex, 
bool requireFootprints, 
QThread *targetThread, 
bool openFilled,
 
  214     m_mutex = cameraMutex;
 
  215     m_targetThread = targetThread;
 
  216     m_openFilled = openFilled;
 
  217     m_defaultAlpha = defaultAlpha;
 
  218     m_requireFootprints = requireFootprints;
 
  230       const QVariant &shapeData) {
 
  231     Shape *result = NULL;
 
  235       if (shapeData.canConvert<QString>()) {
 
  236         fileName = shapeData.value<QString>();
 
  240       else if (shapeData.canConvert<
PvlObject>()) {
 
  242         fileName = ((
IString)shapeObj[
"FileName"][0]).ToQt();
 
  247       if (m_requireFootprints) {
 
  256       result->moveToThread(m_targetThread);