1#include "MosaicMainWindow.h"
10#include <QProgressBar>
20#include "FileDialog.h"
21#include "MosaicController.h"
22#include "ImageFileListWidget.h"
23#include "ImageTreeWidgetItem.h"
25#include "MosaicSceneWidget.h"
26#include "Projection.h"
27#include "ProjectionFactory.h"
33 MosaicMainWindow::MosaicMainWindow(QString title, QWidget *parent) :
35 m_settings(FileName(
"$HOME/.Isis/qmos/qmos.config").expanded(),
36 QSettings::NativeFormat) {
39 m_settingsMenu = NULL;
42 setObjectName(
"MosaicMainWindow");
44 m_controllerVisible =
false;
46 setWindowTitle(title);
48 m_permToolbar =
new QToolBar(
"Standard Tools",
this);
49 m_permToolbar->setObjectName(
"Standard Tools");
50 m_permToolbar->setWhatsThis(
"This area contains options that are always "
51 "present in qmos, regardless of whether or not a project is open. "
52 "These options are also found in the File menu.");
53 addToolBar(m_permToolbar);
55 m_activeToolbar =
new QToolBar(
"Active Tool",
this);
56 m_activeToolbar->setObjectName(
"Active Tool");
57 m_activeToolbar->setWhatsThis(
"The currently selected tool's options will "
58 "show up here. Not all tools have options.");
59 addToolBar(m_activeToolbar);
61 statusBar()->showMessage(
"Ready");
63 m_toolpad =
new ToolPad(
"Tool Pad",
this);
64 m_toolpad->setObjectName(
"Tool Pad");
67 addToolBar(Qt::RightToolBarArea, m_toolpad);
71 m_fileListDock =
new QDockWidget(
"File List",
this, Qt::SubWindow);
72 m_fileListDock->setObjectName(
"FileListDock");
73 m_fileListDock->setFeatures(QDockWidget::DockWidgetFloatable |
74 QDockWidget::DockWidgetMovable |
75 QDockWidget::DockWidgetClosable);
76 m_fileListDock->setWhatsThis(
"This contains the mosaic file list.");
78 m_mosaicPreviewDock =
new QDockWidget(
"Mosaic World View",
80 m_mosaicPreviewDock->setObjectName(
"MosaicPreviewDock");
81 m_mosaicPreviewDock->setFeatures(QDockWidget::DockWidgetFloatable |
82 QDockWidget::DockWidgetMovable |
83 QDockWidget::DockWidgetClosable);
84 m_mosaicPreviewDock->setWhatsThis(
"This contains a zoomed out view of the "
87 addDockWidget(Qt::LeftDockWidgetArea, m_fileListDock);
88 addDockWidget(Qt::LeftDockWidgetArea, m_mosaicPreviewDock);
92 setCentralWidget(
new QWidget());
93 centralWidget()->setLayout(
new QHBoxLayout());
95 m_mosaicController = NULL;
98 installEventFilter(
this);
104 bool projectLoaded =
false;
106 foreach (QString argument, args) {
107 QRegExp cubeName(
".*\\.cub$", Qt::CaseInsensitive);
108 QRegExp cubeListName(
".*\\.(lis|txt)$", Qt::CaseInsensitive);
109 QRegExp projectName(
".*\\.mos$", Qt::CaseInsensitive);
112 if (cubeName.exactMatch(argument)) {
113 filesToOpen.append(argument);
115 else if (cubeListName.exactMatch(argument)) {
116 TextFile fileList(argument);
119 while(fileList.GetLine(line)) {
120 filesToOpen.append(line);
123 else if (projectName.exactMatch(argument)) {
124 if (!projectLoaded) {
125 loadProject(argument);
126 projectLoaded =
true;
129 QMessageBox::warning(
this,
"Multiple Projects Specified",
130 "qmos can only open one project at a time. The first project "
131 "specified is the one that will be used.");
135 catch (IException &e) {
136 QMessageBox::warning(
this,
"Problem Loading File", e.what());
140 m_lastOpenedFile = QFileInfo(
".");
142 if (!filesToOpen.isEmpty())
143 openFiles(filesToOpen);
175 m_fileMenu = menuBar()->addMenu(
"&File");
177 IString iconDir = FileName(
"$ISISROOT/appdata/images/icons").expanded();
180 open->setText(
"Open Cube...");
181 open->setIcon(QPixmap(QString::fromStdString(iconDir.c_str()) +
"/fileopen.png"));
182 connect(
open, SIGNAL(triggered()),
this, SLOT(
open()));
185 openList->setText(
"Open Cube List...");
186 openList->setIcon(QPixmap(QString::fromStdString(iconDir.c_str()) +
"/mActionHelpContents.png"));
192 saveProject->setIcon(QPixmap(QString::fromStdString(iconDir.c_str()) +
"/mActionFileSave.png"));
198 saveProjectAs->setIcon(QPixmap(QString::fromStdString(iconDir.c_str()) +
"/mActionFileSaveAs.png"));
203 loadProject->setText(
"Load Project...");
204 loadProject->setIcon(QPixmap(QString::fromStdString(iconDir.c_str()) +
"/mActionExportMapServer.png"));
205 connect(loadProject, SIGNAL(triggered()),
this, SLOT(loadProject()));
208 closeProject->setText(
"Close Project");
209 m_actionsRequiringOpen.append(closeProject);
210 connect(closeProject, SIGNAL(triggered()),
this, SLOT(closeMosaic()));
213 exit->setText(
"Exit");
214 exit->setIcon(QIcon::fromTheme(
"window-close"));
215 connect(exit, SIGNAL(triggered()),
this, SLOT(close()));
217 QAction *actionRequiringOpen = NULL;
218 foreach(actionRequiringOpen, m_actionsRequiringOpen) {
219 actionRequiringOpen->setEnabled(
false);
222 QAction *actionRequiringClosed = NULL;
223 foreach(actionRequiringClosed, m_actionsRequiringClosed) {
224 actionRequiringClosed->setEnabled(
true);
227 m_fileMenu->addAction(
open);
229 m_fileMenu->addSeparator();
230 m_fileMenu->addAction(loadProject);
233 m_fileMenu->addAction(closeProject);
234 m_fileMenu->addSeparator();
235 m_exportMenu = m_fileMenu->addMenu(
"&Export");
236 m_fileMenu->addAction(exit);
238 permanentToolBar()->addAction(loadProject);
241 permanentToolBar()->addSeparator();
242 permanentToolBar()->addAction(
open);
243 permanentToolBar()->addAction(
openList);
244 permanentToolBar()->addSeparator();
246 m_viewMenu = menuBar()->addMenu(
"&View");
247 m_settingsMenu = menuBar()->addMenu(
"&Settings");
248 QMenu *helpMenu = menuBar()->addMenu(
"&Help");
250 QAction *activateWhatsThisAct =
new QAction(
"&What's This",
this);
251 activateWhatsThisAct->setShortcut(Qt::SHIFT | Qt::Key_F1);
252 activateWhatsThisAct->setIcon(
253 QPixmap(FileName(
"$ISISROOT/appdata/images/icons/contexthelp.png").expanded()));
254 activateWhatsThisAct->setToolTip(
"Activate What's This and click on parts "
255 "this program to see more information about them");
256 connect(activateWhatsThisAct, SIGNAL(triggered()),
257 this, SLOT(enterWhatsThisMode()));
260 showHelpAct->setIcon(QIcon::fromTheme(
"help-contents"));
261 connect(showHelpAct, SIGNAL(triggered()),
262 this, SLOT(showHelp()));
264 helpMenu->addAction(activateWhatsThisAct);
265 helpMenu->addAction(showHelpAct);
267 updateMenuVisibility();
278 filterList.append(
"Isis cubes (*.cub)");
279 filterList.append(
"All Files (*)");
281 QDir directory = m_lastOpenedFile.dir();
282 QStringList selected = QFileDialog::getOpenFileNames(
this,
"Open Cubes",
283 directory.path(), filterList.join(
";;"));
285 if (!selected.empty()) {
286 m_lastOpenedFile = QFileInfo(selected.last());
292 void MosaicMainWindow::enterWhatsThisMode() {
293 QWhatsThis::enterWhatsThisMode();
297 void MosaicMainWindow::showHelp() {
300 QVBoxLayout *mainLayout =
new QVBoxLayout;
301 helpDialog->setLayout(mainLayout);
304 QLabel *qmosTitle =
new QLabel(
"<h1>qmos</h1>");
306 mainLayout->addWidget(qmosTitle);
308 QLabel *qmosSubtitle =
new QLabel(
"A tool for visualizing image "
309 "footprints for a mosaic.");
310 mainLayout->addWidget(qmosSubtitle);
312 QTabWidget *tabArea =
new QTabWidget;
313 mainLayout->addWidget(tabArea);
315 QScrollArea *overviewTab =
new QScrollArea;
319 QVBoxLayout *overviewLayout =
new QVBoxLayout;
320 overviewContainer->setLayout(overviewLayout);
322 QLabel *purposeTitle =
new QLabel(
"<h2>Purpose</h2>");
323 overviewLayout->addWidget(purposeTitle);
325 QLabel *purposeText =
new QLabel(
"<p>qmos is designed "
326 "specifically for visualizing large amounts of images, how images "
327 "overlap, where control points lie on the images, and how jigsaw has "
328 "moved control points.");
329 purposeText->setWordWrap(
true);
330 overviewLayout->addWidget(purposeText);
332 QLabel *shortcomingsTitle =
new QLabel(
"<h2>Known Issues</h2>");
333 overviewLayout->addWidget(shortcomingsTitle);
335 QLabel *shortcomingsText =
new QLabel(
"<p>The known shortcomings of qmos "
337 "<li>All input files are read-only, you cannot edit your input "
339 "<li>Large control networks are slow and memory intensive to load</li>"
340 "<li>Show cube DN data is extremely slow</li>"
341 "<li>Warnings are not displayed graphically</li>"
342 "<li>Zooming in too far causes you to pan off of your data</li></ul>");
343 shortcomingsText->setWordWrap(
true);
344 overviewLayout->addWidget(shortcomingsText);
346 overviewTab->setWidget(overviewContainer);
348 QScrollArea *preparationsTab =
new QScrollArea;
351 QVBoxLayout *preparationsLayout =
new QVBoxLayout;
352 preparationsContainer->setLayout(preparationsLayout);
354 QLabel *preparationTitle =
new QLabel(
"<h2>Before Using qmos</h2>");
355 preparationsLayout->addWidget(preparationTitle);
357 QLabel *preparationText =
new QLabel(
"<p>qmos only supports files which "
358 "have latitude and longitude information associated with them. Global "
359 "projections are also not supported. If your files meet these "
360 "requirements, it is beneficial to run a couple of Isis programs on "
361 "your files before loading them into qmos. The programs you should run "
363 "<li><i>camstats from=future_input_to_qmos.cub attach=true "
364 "sinc=... linc=...</i></li>"
365 " <br>This enables qmos to give you the emission angle, incidence "
366 "angle, phase angle, and resolution in the <b>File List</b>"
367 "<li><i>footprintinit from=future_input_to_qmos.cub "
368 "sinc=... linc=...</i></li>"
369 " <br>Running <i>footprintinit</i> beforehand will significantly speed up loading images "
370 "into qmos.<br/><br/>"
371 "The footprint is created by \"walking\" around the valid image data, and qmos reprojects "
372 "the footprint according to the loaded map file.<br/><br/>"
373 "Qmos displays the footprints, and optionally the image data and map grid to the default "
374 "IAU radius, unless the radius is specified within the loaded map file.<br/><br/>"
375 "For Level1 (raw camera space) images, when calculating the "
376 "footprint polygons, footprintinit refers to the image labels "
377 "and uses the SPICE kernels and the shape model (DEM if one "
378 "exists and is specified, otherwise, the IAU sphere or "
379 "ellipsoid is used). Refer to spiceinit for more information "
380 "on loading SPICE onto Level0 and Level1 images. This enables "
381 "qmos to use the given footprints instead of trying to "
382 "calculate its own. The 'linc' and 'sinc' parameters can have a "
383 "significant effect on your image's footprint. Also, images "
384 "without footprints cannot be opened more than one at a time. "
385 "Running footprintinit will significantly speed up loading "
386 "images into qmos.<br>"
387 "For Level2 images, do not run footprintinit. The footprint "
388 "polygon is created by 'walking' around the valid image data. "
389 "qmos 'reprojects' the footprint polygons according to the "
390 "loaded Map File.<br>"
392 preparationText->setWordWrap(
true);
393 preparationsLayout->addWidget(preparationText);
395 preparationsTab->setWidget(preparationsContainer);
397 QScrollArea *projectsTab =
new QScrollArea;
400 QVBoxLayout *projectsLayout =
new QVBoxLayout;
401 projectsContainer->setLayout(projectsLayout);
403 QLabel *projectsTitle =
new QLabel(
"<h2>Projects</h2>");
404 projectsLayout->addWidget(projectsTitle);
406 QLabel *projectsText =
new QLabel(
"<p>The contents of qmos can be saved as a project file, "
407 "which allows the user to restore back to the previous state at any given time. The stored "
408 "files or qmos project files must have a \".mos\" extension.<br/><br/>"
409 "These project files store the input file location information and their qmos properties "
410 "(color, group information, and other attributes).<br/><br/>"
411 "When you initially open qmos you start with a blank project. "
412 "To load a project, you can specify the project "
413 "file's name on the command line (qmos myProject.mos) or go to "
414 "File -> Load Project after qmos is started. When "
415 "loading a project, all current data in the qmos window is lost (your cubes are closed)."
416 "These project files are relatively small files. You can "
417 "save your current project any time by going to File -> Save Project. ");
418 projectsText->setWordWrap(
true);
419 projectsLayout->addWidget(projectsText);
421 projectsTab->setWidget(projectsContainer);
423 if (m_controllerVisible) {
424 tabArea->addTab(overviewTab,
"&Overview");
425 tabArea->addTab(preparationsTab,
"Preparing &Input Cubes");
427 tabArea->addTab(ImageFileListWidget::getLongHelp(m_fileListDock),
429 tabArea->addTab(MosaicSceneWidget::getLongHelp(centralWidget()),
431 tabArea->addTab(MosaicSceneWidget::getPreviewHelp(m_mosaicPreviewDock),
432 "Mosaic &World View");
434 tabArea->addTab(MosaicSceneWidget::getMapHelp(),
436 tabArea->addTab(projectsTab,
"&Project Files");
438 tabArea->addTab(MosaicSceneWidget::getControlNetHelp(),
439 "&Control Networks");
440 tabArea->addTab(MosaicSceneWidget::getGridHelp(),
444 tabArea->addTab(overviewTab,
"&Overview");
445 tabArea->addTab(preparationsTab,
"Preparing &Input Cubes");
447 tabArea->addTab(ImageFileListWidget::getLongHelp(),
449 tabArea->addTab(MosaicSceneWidget::getLongHelp(),
451 tabArea->addTab(MosaicSceneWidget::getPreviewHelp(),
452 "Mosaic &World View");
454 tabArea->addTab(MosaicSceneWidget::getMapHelp(),
456 tabArea->addTab(projectsTab,
"&Project Files");
458 tabArea->addTab(MosaicSceneWidget::getControlNetHelp(),
459 "&Control Networks");
460 tabArea->addTab(MosaicSceneWidget::getGridHelp(),
466 mainLayout->addWidget(buttonsArea);
468 QHBoxLayout *buttonsLayout =
new QHBoxLayout;
469 buttonsArea->setLayout(buttonsLayout);
472 buttonsLayout->addStretch();
474 QPushButton *closeButton =
new QPushButton(QIcon::fromTheme(
"window-close"),
476 closeButton->setDefault(
true);
477 connect(closeButton, SIGNAL(clicked()),
478 helpDialog, SLOT(close()));
479 buttonsLayout->addWidget(closeButton);
485 void MosaicMainWindow::updateMenuVisibility() {
486 QMenuBar *rootMenu = menuBar();
489 foreach(rootAction, rootMenu->actions()) {
490 QMenu *rootMenu = rootAction->menu();
493 rootAction->setVisible(updateMenuVisibility(rootAction->menu()));
499 void MosaicMainWindow::createController() {
500 if (m_mosaicController == NULL) {
501 m_mosaicController =
new MosaicController(statusBar(), m_settings);
506 foreach(settingsAct, settingsActs) {
507 connect(settingsAct, SIGNAL(destroyed(
QObject *)),
508 this, SLOT(updateMenuVisibility()));
510 m_settingsMenu->addAction(settingsAct);
513 updateMenuVisibility();
518 void MosaicMainWindow::displayController() {
519 if (m_mosaicController && !m_controllerVisible) {
520 m_controllerVisible =
true;
521 m_mosaicController->addExportActions(*m_exportMenu);
523 m_fileListDock->setWidget(m_mosaicController->getImageFileList());
524 m_mosaicPreviewDock->setWidget(m_mosaicController->getMosaicWorldScene());
526 centralWidget()->layout()->addWidget(
527 m_mosaicController->getMosaicScene());
529 QAction *actionRequiringOpen = NULL;
530 foreach(actionRequiringOpen, m_actionsRequiringOpen) {
531 actionRequiringOpen->setEnabled(
true);
534 QAction *actionRequiringClosed = NULL;
535 foreach(actionRequiringClosed, m_actionsRequiringClosed) {
536 actionRequiringClosed->setEnabled(
false);
539 m_mosaicController->getMosaicScene()->addTo(m_toolpad);
540 m_mosaicController->getMosaicScene()->addToPermanent(m_permToolbar);
541 m_mosaicController->getMosaicScene()->addTo(m_activeToolbar);
543 statusBar()->addWidget(m_mosaicController->getProgress());
544 statusBar()->addWidget(
545 m_mosaicController->getMosaicScene()->getProgress());
546 statusBar()->addWidget(
547 m_mosaicController->getMosaicWorldScene()->getProgress());
548 statusBar()->addWidget(
549 m_mosaicController->getImageFileList()->getProgress());
552 m_mosaicController->getMosaicScene()->getViewActions();
554 foreach(
QAction *viewAct, sceneViewActs) {
555 connect(viewAct, SIGNAL(destroyed(
QObject *)),
556 this, SLOT(updateMenuVisibility()));
558 m_viewMenu->addAction(viewAct);
561 m_viewMenu->addSeparator();
565 m_mosaicController->getImageFileList()->getViewActions();
567 foreach(
QAction *viewAct, fileListViewActs) {
568 connect(viewAct, SIGNAL(destroyed(
QObject *)),
569 this, SLOT(updateMenuVisibility()));
571 m_viewMenu->addAction(viewAct);
574 updateMenuVisibility();
579 bool MosaicMainWindow::updateMenuVisibility(
QMenu *menu) {
580 bool anythingVisible =
false;
588 foreach(menuAction, menu->actions()) {
589 bool thisVisible =
true;
591 if (menuAction->menu() != NULL) {
592 thisVisible = updateMenuVisibility(menuAction->menu());
595 thisVisible = menuAction->isVisible();
599 anythingVisible =
true;
602 menu->menuAction()->setVisible(anythingVisible);
605 return anythingVisible;
616 filterList.append(
"List Files (*.lis)");
617 filterList.append(
"Text Files (*.txt)");
618 filterList.append(
"All files (*)");
620 QDir directory = m_lastOpenedFile.dir();
622 QString selected = QFileDialog::getOpenFileName(
this,
"Open Cube List",
623 directory.path(), filterList.join(
";;"));
625 if (selected !=
"") {
626 m_lastOpenedFile = QFileInfo(selected);
627 TextFile fileList((QString) selected);
632 while(fileList.
GetLine(line)) {
633 filesInList.append(line);
636 if (filesInList.empty()) {
637 IString msg =
"No files were found inside the file list";
638 throw IException(IException::Unknown, msg, _FILEINFO_);
641 openFiles(filesInList);
657 void MosaicMainWindow::openFiles(
QStringList cubeNames) {
659 if (!cubeNames.empty()) {
663 if (m_mosaicController)
664 m_mosaicController->openImages(cubeNames);
683 if (m_mosaicController) {
684 QString fn = QFileDialog::getSaveFileName(
this,
"Save Project",
685 QDir::currentPath() +
"/untitled.mos",
687 if (fn.isEmpty())
return;
689 m_mosaicController->saveProject(fn);
700 if (m_filename ==
"") {
704 m_mosaicController->saveProject(m_filename);
714 void MosaicMainWindow::loadProject() {
715 QString fn = QFileDialog::getOpenFileName(
this,
"Load Project",
722 m_lastOpenedFile = QFileInfo(fn);
728 void MosaicMainWindow::loadProject(QString fn) {
733 if (m_mosaicController)
734 m_mosaicController->readProject(fn);
741 void MosaicMainWindow::closeMosaic() {
742 if (m_mosaicController) {
743 QAction *actionRequiringOpen = NULL;
744 foreach(actionRequiringOpen, m_actionsRequiringOpen) {
745 actionRequiringOpen->setEnabled(
false);
748 QAction *actionRequiringClosed = NULL;
749 foreach(actionRequiringClosed, m_actionsRequiringClosed) {
750 actionRequiringClosed->setEnabled(
true);
753 m_mosaicController->saveSettings(m_settings);
754 delete m_mosaicController;
755 m_mosaicController = NULL;
758 m_controllerVisible =
false;
Base class for the Qisis main windows.
virtual void readSettings(QSize defaultSize=QSize())
This method ensure that the settings get written even if the Main window was only hidden,...
void openList()
Opens a list of cube files instead of one at a time.
void setupMenus()
Sets up the menus on the menu bar for the qmos window.
void saveProjectAs()
Allows the user to save a project file.
void open()
Calles MosaicWidget's open method which opens a cube file and displays the footprint in the graphics ...
void readSettings(QSize defaultSize=QSize(800, 600))
This overriden method is called from the constructor so that when the Mosaicmainwindow is created,...
bool eventFilter(QObject *o, QEvent *e)
This event filter is installed in the constructor.
void saveSettings2()
This overriden method is called when the MosaicMainWindow is closed or hidden to write the size and l...
void saveProject()
Called from the file menu to save a project file.
Provides access to sequential ASCII stream I/O.
bool GetLine(QString &line, const bool skipComments=true)
Gets next line from file.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.