1 #include "ShapeReader.h" 4 #include <QApplication> 7 #include <QFutureWatcher> 8 #include <QInputDialog> 10 #include <QProgressBar> 13 #include <QtConcurrentMap> 21 #include "ProgressBar.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);
ShapeReader(QMutex *cameraMutex, bool requireFootprints=false, QObject *parent=NULL)
MosaicWidget constructor.
virtual ~ShapeReader()
Free the allocated memory by this object.
File name manipulation and expansion.
bool initFootprint(QMutex *cameraMutex)
Calculate a footprint for this shape.
void fromPvl(const PvlObject &pvl)
Read the shape settings from a Pvl.
void print() const
Prints a string representation of this exception to stderr.
This represents a shape in a project-based GUI interface.
Adds specific functionality to C++ strings.
Namespace for ISIS/Bullet specific routines.
Property
This is a list of properties and actions that are possible.
Contains Pvl Groups and Pvl Objects.
VariantToShapeFunctor(QMutex *cameraMutex, bool requireFootprints, QThread *targetThread, bool openFilled, int defaultAlpha)
Create a functor for converting from QVariant to an Shape *.
Shape * operator()(const QVariant &)
Read the QString filename and make an Shape from it.