1 #include "ProjectionConfigDialog.h"
10 #include <QPushButton>
13 #include "IException.h"
14 #include "MosaicSceneWidget.h"
15 #include "Projection.h"
16 #include "ProjectionFactory.h"
19 using 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);
221 mapping +=
PvlKeyword(
"MinimumLatitude",
"-90");
224 mapping +=
PvlKeyword(
"MaximumLatitude",
"90");
227 if(mapping[
"LongitudeDomain"][0] ==
"360")
228 mapping +=
PvlKeyword(
"MinimumLongitude",
"0");
230 mapping +=
PvlKeyword(
"MinimumLongitude",
"-180");
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;