1#include "ProjectionConfigDialog.h"
13#include "IException.h"
14#include "MosaicSceneWidget.h"
15#include "Projection.h"
16#include "ProjectionFactory.h"
19using std::stringstream;
35 QGridLayout *mainLayout =
new QGridLayout;
56 QLabel *headerLabel =
new QLabel(
"<h3>Configure Projection/Mapping Parameters</h3>");
57 mainLayout->addWidget(headerLabel, row, 0);
60 QLabel *descriptionLabel =
new QLabel(
"The projection determines how the footprints will be "
61 "shown on the scene. This projection will be used to convert from latitude/longitude to "
62 "scene coordinates (x, y).<br/><br/>Please keep in mind:<br/><b>Load Map File...</b> will "
63 "read all of the keywords in the mapping group from the input file (unnecessary keywords "
65 "<b>Save Map File...</b> will save what's currently in the display (unnecessary keywords "
67 "<b>Ok and Apply</b> will remove all unnecessary or unknown keywords immediately.<br/>");
68 descriptionLabel->setWordWrap(
true);
69 mainLayout->addWidget(descriptionLabel, row, 0);
72 QHBoxLayout *loadSaveLayout =
new QHBoxLayout;
74 QPushButton *
saveToFile =
new QPushButton(
"&Save Map File...");
84 loadSaveLayout->addStretch();
85 mainLayout->addLayout(loadSaveLayout, row, 0);
88 QFont font(
"Monospace");
89 font.setStyleHint(QFont::TypeWriter);
107 QHBoxLayout *applyButtonsLayout =
new QHBoxLayout;
109 QCheckBox *showErrorsCheckBox =
new QCheckBox(tr(
"Show Errors"));
110 connect(showErrorsCheckBox, SIGNAL(stateChanged(
int)),
113 applyButtonsLayout->addWidget(showErrorsCheckBox);
115 applyButtonsLayout->addStretch();
122 this, SLOT(accept()));
131 QPushButton *cancelButton =
new QPushButton(
"&Cancel");
132 cancelButton->setIcon(QIcon::fromTheme(
"dialog-cancel"));
133 connect(cancelButton, SIGNAL(clicked()),
134 this, SLOT(reject()));
135 applyButtonsLayout->addWidget(cancelButton);
138 applyButtonsWrapper->setLayout(applyButtonsLayout);
139 mainLayout->addWidget(applyButtonsWrapper, row, 0);
142 setLayout(mainLayout);
146 connect(
this, SIGNAL(shown()),
148 Qt::QueuedConnection);
152 ProjectionConfigDialog::~ProjectionConfigDialog() {
192 mapFilePvl +=
m_scene->getProjection()->Mapping();
194 stringstream mapFileStringStream;
195 mapFileStringStream << mapFilePvl;
197 m_mapFileEdit->setText(QString::fromStdString(mapFileStringStream.str()));
207 void ProjectionConfigDialog::showEvent(QShowEvent *event) {
208 QDialog::showEvent(event);
220 if(!mapping.hasKeyword(
"MinimumLatitude"))
221 mapping +=
PvlKeyword(
"MinimumLatitude",
"-90");
223 if(!mapping.hasKeyword(
"MaximumLatitude"))
224 mapping +=
PvlKeyword(
"MaximumLatitude",
"90");
226 if(!mapping.hasKeyword(
"MinimumLongitude")) {
227 if(mapping[
"LongitudeDomain"][0] ==
"360")
228 mapping +=
PvlKeyword(
"MinimumLongitude",
"0");
230 mapping +=
PvlKeyword(
"MinimumLongitude",
"-180");
233 if(!mapping.hasKeyword(
"MaximumLongitude")) {
234 if(mapping[
"LongitudeDomain"][0] ==
"360")
235 mapping +=
PvlKeyword(
"MaximumLongitude",
"360");
237 mapping +=
PvlKeyword(
"MaximumLongitude",
"180");
250 stringstream mapFileStringStream;
251 mapFileStringStream.str(
m_mapFileEdit->toPlainText().toStdString());
254 mapFileStringStream >> mapFilePvl;
278 QString mapFile = QFileDialog::getOpenFileName(
this, tr(
"Select Map File"), QString(
"."),
279 tr(
"Map Files (*.map *.pvl *.cub);;Text Files (*.txt);;All Files (*)"));
281 if (!mapFile.isEmpty()) {
282 bool success =
false;
285 Pvl mapFilePvl(mapFile);
288 Pvl trimmedMapFilePvl;
289 trimmedMapFilePvl += mapping;
291 stringstream trimmedMapFileStringStream;
292 trimmedMapFileStringStream << trimmedMapFilePvl;
293 m_mapFileEdit->setText(QString::fromStdString(trimmedMapFileStringStream.str()));
298 QMessageBox::warning(
this, tr(
"Failed to Load Map File"),
299 tr(
"Failed to load projection from the given file.\n") +
326 QString mapFile = QFileDialog::getSaveFileName(
this, tr(
"Save Map File"), QString(
"."),
327 tr(
"Map Files (*.map *.pvl);;Text Files (*.txt);;All Files (*)"));
329 if (!mapFile.isEmpty()) {
330 QFile outputFile(mapFile);
332 if (outputFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
334 if (outputFile.write(mapFileInfo.toLatin1()) == -1) {
335 QMessageBox::warning(
this, tr(
"Failed to Write Text to File"),
336 tr(
"Failed to write the map file to [%1] due to an I/O failure").arg(mapFile));
340 QMessageBox::warning(
this, tr(
"Failed to Create Output File"),
341 tr(
"Failed to open file [%1] for writing").arg(mapFile));
352 bool projectionIsGood =
true;
355 m_stateLabel->setText(
"<strong>Please load (or type in) a map file</strong>");
357 projectionIsGood =
false;
362 m_stateLabel->setText(
"<strong>The currently displayed text is valid</strong>");
366 m_stateLabel->setText(
"<strong>The currently displayed text is not valid"
369 QString(
"<font color='red'> ") +
370 QString(e.what()).replace(
"\n",
"<br/> ") +
372 projectionIsGood =
false;
void applySettings()
Take the settings that have been configured and apply them to the mosaic scene.
void saveToFile()
Save mapping parameters to the given file.
ProjectionConfigDialog(MosaicSceneWidget *scene, QWidget *parent=NULL)
Create a projection configuration dialog.
void beginQuickLoad()
If using quick load, this will prompt the user for an input file right after the show event.
void showErrors(int)
This is called when "Show Errors" is checked.
bool m_dirty
To reduce redundant computations, keep track of dirty state of the dialog.
QPointer< QTextEdit > m_mapFileEdit
This is the text area that a user can type in for editing the projection.
QPointer< MosaicSceneWidget > m_scene
The mosaic scene we're configuring the projection for.
Projection * createProjection()
Convert the current text in the text edit to a projection.
bool m_quick
Should we minimize the user interaction?
QPointer< QPushButton > m_okayButton
This button applies the current projection to the scene and closes the dialog.
QPointer< QLabel > m_errorsLabel
This shows errors generated by trying to create a projection from the current mapping pvl.
Pvl addMissingKeywords(Pvl mappingPvl)
Get a modified mapping pvl that the mosaic scene will be compatible with.
void setQuickConfig(bool quick)
Enable/disable minimal interaction mode.
void refreshWidgetStates()
Update the enabled/disabled states of the various widgets based on the current user inputs' states.
QPointer< QPushButton > m_readFromFileButton
This button corresponds to 'Load Map File...' and causes a prompt for file input.
QPointer< QLabel > m_stateLabel
This shows a general idea of the current state of the mapping pvl (always shown)
void loadFromFile()
Read mapping parameters from a file (prompts user for the file name).
QPointer< QPushButton > m_applyButton
This button applies the current projection to the scene.
void readSettings()
Update the current widgets' states with the current settings in the mosaic scene.
static Isis::Projection * Create(Isis::Pvl &label, bool allowDefaults=false)
This method returns a pointer to a Projection object.
Base class for Map Projections.
Contains multiple PvlContainers.
Container for cube-like labels.
A single keyword-value pair.
@ Traverse
Search child objects.
This is free and unencumbered software released into the public domain.