Official websites use .gov
A .gov website belongs to an official government organization in the United States.

Secure .gov websites use HTTPS
A lock ( ) or https:// means you’ve safely connected to the .gov website. Share sensitive information only on official, secure websites.

Isis 3 Programmer Reference
Gui.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "Gui.h"
8
9#include <clocale>
10
11#include <sstream>
12#include <string>
13
14#include <QApplication>
15#include <QCoreApplication>
16#include <QDesktopWidget>
17#include <QFont>
18#include <QFrame>
19#include <QIcon>
20#include <QLineEdit>
21#include <QMenu>
22#include <QMenuBar>
23#include <QMessageBox>
24#include <QSplitter>
25#include <QScrollArea>
26#include <QStatusBar>
27#include <QToolBar>
28#include <QWhatsThis>
29#include <QWidget>
30
31#include "Application.h"
32#include "FileName.h"
33#include "IException.h"
34#include "IString.h"
35#include "Preference.h"
36#include "ProgramLauncher.h"
37#include "PvlObject.h"
38#include "PvlGroup.h"
39#include "Pvl.h"
40#include "SessionLog.h"
41#include "UserInterface.h"
42
43#ifdef Q_OS_LINUX
44#include <X11/Xlib.h>
45#endif
46
47namespace Isis {
48
50 Gui *Gui::p_gui = NULL;
51
56 // Many users who run xorg compatible servers on windows like to forget to
57 // start their Xhack software before launching X clients.
58 // The standard "cannot connect to X server" message that Qt gives is not
59 // enough to explain what the problem is, because we keep getting bug
60 // reports for this. Hopefully detecting this ourselves and printing the
61 // following message will help. If not then yes, this is the message that
62 // needs changing...
63
64 #ifdef Q_OS_LINUX
65 Display *xDisplay = XOpenDisplay(NULL);
66 if (!xDisplay) {
67 std::cerr << "cannot connect to X server...\n\n"
68 "Do you have an X server running?\n\n"
69 "If yes then...\n\n"
70 " If you are trying to run this program remotely using ssh, then "
71 "did you enable X11 forwarding?\n\n"
72 "If the possible causes cited above have been ruled out and this "
73 "problem persists, then check your X settings or contact your "
74 "system administrator.\n\n";
75
76 abort();
77 }
78 else {
79 XCloseDisplay(xDisplay);
80 }
81 #endif
82 }
83
84 Gui *Gui::Create(Isis::UserInterface &ui, int &argc, char *argv[]) {
85 // Don't recreate
86 if(p_gui != NULL) return p_gui;
87
88 // Get preferences
89 PvlGroup &uiPref = Preference::Preferences().findGroup("UserInterface");
90 // Create the application
91 new QApplication(argc, argv);
92 // When QApplication is initialized, it will reset the locale to the shells locale. As a result
93 // the locale needs to be reset after QApplications initialization.
94 setlocale(LC_ALL, "en_US");
95
96 QApplication::setQuitOnLastWindowClosed(true);
97 QApplication::setApplicationName(FileName(argv[0]).baseName());
98
99
100 // Qt is smart enough to use the style of the system running the program.
101 // However, Isis supports overriding this with a setting in IsisPreferences.
102 // Here we check to see if this has been done and force the style if needed.
103 if(uiPref.hasKeyword("GuiStyle")) {
104 QString style = uiPref["GuiStyle"];
105 QApplication::setStyle(style);
106 }
107
108
109 if (uiPref.hasKeyword("GuiFontName")) {
110 QString fontString = uiPref["GuiFontName"];
111 QFont font = QFont(fontString);
112
113 if (uiPref.hasKeyword("GuiFontSize")) {
114 int pointSize = uiPref["GuiFontSize"];
115 font.setPointSize(pointSize);
116 }
117
118 QApplication::setFont(font);
119 }
120
121
122 // Create the main window
123 p_gui = new Gui(ui);
124 p_gui->show();
125
126 return p_gui;
127 }
128
131 // Create the toolbar and menu and populate them with actions
132 CreateAreas();
133
134 // Set title
135 QWidget::setWindowTitle(QApplication::applicationName());
136
137 // Add parameters to the main area
138 for(int group = 0; group < ui.NumGroups(); group++) {
139 for(int param = 0; param < ui.NumParams(group); param++) {
140 p_parameters.push_back(AddParameter(ui, group, param));
141 }
142 }
143
144 // Load the values from the UI into the GUI
145 for(int p = 0; p < (int)p_parameters.size(); p++) {
146 GuiParameter *param = p_parameters[p];
147 param->Update();
148 connect(param, SIGNAL(ValueChanged()), this, SLOT(UpdateCommandLine()));
149 }
150
151
152 // Make the horizontal direction in the scrolling widget non-stretchable
153 p_scrollLayout->addStretch(1);
154
155 // Setup status bar
156 p_progressBar = new QProgressBar();
157 p_progressBar->setMinimum(0);
158 p_progressBar->setMaximum(100);
159 p_progressBar->setValue(0);
160 p_progressBar->setMinimumWidth(200);
161
162 p_statusText = new QLabel("Ready");
163
164 statusBar()->setSizeGripEnabled(true);
165 statusBar()->addWidget(p_progressBar, 0);
166 statusBar()->addWidget(p_statusText, 3);
167
168 // Setup the current history pointer
169 p_historyEntry = -1;
170
171
172 }
173
176 for(unsigned int i = 0; i < p_parameters.size(); i++) {
177 delete p_parameters[i];
178 }
179
180 p_parameters.clear();
181 }
182
183 // Create the main widget, menus, toolbars, status, actions
184 void Gui::CreateAreas() {
185 // Create the main area
186 QSplitter *split = new QSplitter(Qt::Vertical, this);
187
188 // Add a scrolled area for the parameters to the splitter
189 p_scrollArea = new QScrollArea();
190 p_scrollWidget = new QWidget();
191 p_scrollLayout = new QVBoxLayout;
192 p_scrollWidget->setLayout(p_scrollLayout);
193 p_scrollArea->setWidget(p_scrollWidget);
194 p_scrollArea->setWidgetResizable(true);
195
196 // Set the scroll area size
197 int height = QApplication::desktop()->height();
198
199 // Add the log area to the bottom of the spliter
200 p_log = new GuiLog();
201 p_log->setMinimumHeight(10);
202 p_log->resize(p_log->width(), 250);
203
204 split->addWidget(p_scrollArea);
205 split->addWidget(p_log);
206 split->setChildrenCollapsible(false);
207 split->setStretchFactor(0, 3);
208 split->setStretchFactor(1, 0);
209 setCentralWidget(split);
210 resize(720, (int)(height / 2) + 350);
211
212 // Create all the actions for menus, toolbars...
213 p_processAction = CreateProcessAction();
214 p_stopAction = CreateStopAction();
215 p_exitAction = CreateExitAction();
216
217 p_previousHistoryAction = CreatePreviousHistoryAction();
218 p_nextHistoryAction = CreateNextHistoryAction();
219 p_resetAction = CreateResetAction();
220
221 p_saveLogAction = CreateSaveLogAction();
222 p_clearLogAction = CreateClearLogAction();
223
224 QAction *whatsThisAction = CreateWhatsThisAction();
225
226 // Create the File menu
227 QMenu *fileMenu = menuBar()->addMenu("&File");
228 fileMenu->addAction(p_processAction);
229 fileMenu->addAction(p_stopAction);
230 fileMenu->addAction(p_exitAction);
231
232 // Create the Options menu
233 QMenu *optionsMenu = menuBar()->addMenu("&Options");
234 optionsMenu->addAction(p_resetAction);
235 optionsMenu->addAction(p_previousHistoryAction);
236 optionsMenu->addAction(p_nextHistoryAction);
237 optionsMenu->addAction(p_saveLogAction);
238 optionsMenu->addAction(p_clearLogAction);
239
240 // Create the Controls Toolbar
241 QToolBar *tb = addToolBar("Controls");
242 tb->setIconSize(QSize(22, 22));
243 tb->addAction(p_processAction);
244 tb->addAction(p_stopAction);
245 tb->addAction(p_exitAction);
246 tb->addSeparator();
247
248 tb->addAction(p_previousHistoryAction);
249 tb->addAction(p_nextHistoryAction);
250 tb->addAction(p_resetAction);
251 tb->addSeparator();
252
253 tb->addAction(p_saveLogAction);
254 tb->addAction(p_clearLogAction);
255 tb->addSeparator();
256
257 tb->addAction(whatsThisAction);
258
259 QAction *showControls = new QAction(this);
260 showControls->setText("Controls");
261 showControls->setCheckable(true);
262 connect(showControls, SIGNAL(toggled(bool)), tb, SLOT(setVisible(bool)));
263
264 tb->installEventFilter(this);
265
266 // Create the command line toolbar
267 tb = new QToolBar("Command Line");
268 addToolBar(Qt::BottomToolBarArea, tb);
269 tb->setIconSize(QSize(22, 22));
270 tb->setAllowedAreas(Qt::BottomToolBarArea);
271 p_commandLineEdit = new QLineEdit(tb);
272 p_commandLineEdit->setReadOnly(true);
273 tb->addWidget(p_commandLineEdit);
274 QAction *showCommandLine = new QAction(this);
275 showCommandLine->setText("Command Line");
276 showCommandLine->setCheckable(true);
277 connect(showCommandLine, SIGNAL(toggled(bool)), tb, SLOT(setVisible(bool)));
278 //tb->hide();
279
280 // Create the view menu
281 QMenu *viewMenu = menuBar()->addMenu("&View");
282 viewMenu->addAction(showControls);
283 viewMenu->addAction(showCommandLine);
284 showControls->setChecked(true);
285 showCommandLine->setChecked(true);
286
287 // Create the Help menu
288 QMenu *helpMenu = menuBar()->addMenu("&Help");
289 helpMenu->addAction(whatsThisAction);
290
291 QAction *aboutProgram = new QAction(this);
292 aboutProgram->setMenuRole(QAction::AboutRole);
293 aboutProgram->setText("About this program");
294 aboutProgram->setShortcut(Qt::CTRL + Qt::Key_H);
295 helpMenu->addAction(aboutProgram);
296 connect(aboutProgram, SIGNAL(triggered(bool)), this, SLOT(AboutProgram()));
297
298 QAction *aboutIsis = new QAction(this);
299 aboutIsis->setMenuRole(QAction::NoRole);
300 aboutIsis->setText("About Isis");
301 aboutIsis->setShortcut(Qt::CTRL + Qt::Key_I);
302 helpMenu->addAction(aboutIsis);
303 connect(aboutIsis, SIGNAL(triggered(bool)), this, SLOT(AboutIsis()));
304 }
305
306
307 // Create the "Begin/Start Processing" action
308 QAction *Gui::CreateProcessAction() {
309 QAction *processAction = new QAction(this);
310 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
311 processAction->setIcon(QPixmap(baseDir + "/guiRun.png"));
312 processAction->setText("&Run");
313 processAction->setToolTip("Run");
314 QString processActionWhatsThisText = "<p><b>Function: </b> \
315 Runs the application with the current parameters</p> \
316 <p><b>Shortcut: </b> Ctrl+R</p>";
317 processAction->setShortcut(Qt::CTRL + Qt::Key_R);
318 processAction->setWhatsThis(processActionWhatsThisText);
319
320 connect(processAction, SIGNAL(triggered(bool)), this, SLOT(StartProcess()));
321
322 return processAction;
323 }
324
336 p_processAction->setEnabled(false);
337 ProgressText("Working");
338 Progress(0);
339 p_stop = false;
340
341 Isis::UserInterface &ui = Isis::iApp->GetUserInterface();
342
343 // Pull the values from the parameters and put them into the Aml
344 for(int p = 0; p < (int)p_parameters.size(); p++) {
345 GuiParameter &param = *(p_parameters[p]);
346 ui.Clear(param.Name());
347 if(param.IsEnabled() && param.IsModified()) {
348 QString value = param.Value().simplified().trimmed();
349 if(value.length() > 0) {
350 ui.PutAsString(param.Name(), value);
351 }
352 }
353 }
354
355 // Make sure the parameters were valid
356 // Call the application's main
358 try {
359 ui.VerifyAll();
360 ui.SaveHistory();
361 Isis::SessionLog::TheLog(true);
362 QApplication::setOverrideCursor(Qt::WaitCursor);
363 (*p_funct)(); // Call IsisMain
364 QApplication::restoreOverrideCursor();
365 Isis::iApp->FunctionCleanup();
366
367 // Display the parameters incase the app changed one or more
368 for(int p = 0; p < (int)p_parameters.size(); p++) {
369 GuiParameter &param = *(p_parameters[p]);
370 param.Update();
371 }
372
373 Progress(100);
374 ProgressText("Done");
375 }
376 catch(IException &e) {
377 QApplication::restoreOverrideCursor();
378 if(e.toString() == "") {
379 ProgressText("Stopped");
380 }
381 else {
382 Isis::iApp->FunctionError(e);
383 ProgressText("Error");
384 // When the warning is rejected (i.e. Abort), clean up from within qApp's exec event loop
385 if(ShowWarning()) {
386 qApp->quit();
387 }
388 }
389 }
390
391 p_processAction->setEnabled(true);
392 }
393
394 // Create the "Exit" action
395 QAction *Gui::CreateExitAction() {
396 QAction *exitAction = new QAction(this);
397 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
398 exitAction->setIcon(QPixmap(baseDir + "/guiExit.png"));
399 exitAction->setText("&Exit");
400 exitAction->setToolTip("Exit");
401 QString exitWhatsThisText = "<p><b>Function: </b> \
402 Closes the program window </p> <p><b>Shortcut: </b> Ctrl+Q</p>";
403 exitAction->setWhatsThis(exitWhatsThisText);
404 exitAction->setShortcut(Qt::CTRL + Qt::Key_Q);
405 connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
406 return exitAction;
407 }
408
409 // Create the "Reset" action
410 QAction *Gui::CreateResetAction() {
411 QAction *resetAction = new QAction(this);
412 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
413 resetAction->setIcon(QPixmap(baseDir + "/guiReset.png"));
414 resetAction->setText("&Reset");
415 resetAction->setToolTip("Reset parameters");
416 QString resetWhatsThisText = "<p><b>Function: </b> \
417 Resets the application parameters to their default values</p> \
418 <p><b>Shortcut: </b> F3</p>";
419 resetAction->setWhatsThis(resetWhatsThisText);
420 resetAction->setShortcut(Qt::Key_F3);
421 connect(resetAction, SIGNAL(triggered()), this, SLOT(ResetParameters()));
422
423 return resetAction;
424 }
425
426 // Create the "Stop" action
427 QAction *Gui::CreateStopAction() {
428 QAction *stopAction = new QAction(this);
429 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
430 stopAction->setIcon(QPixmap(baseDir + "/guiStop.png"));
431 stopAction->setText("&Stop");
432 stopAction->setToolTip("Stop");
433 QString stopWhatsThisText = "<p><b>Function: </b> \
434 Stops the application from running</p> \
435 <p><b>Shortcut: </b> Ctrl+E</p>";
436 stopAction->setShortcut(Qt::CTRL + Qt::Key_E);
437 stopAction->setWhatsThis(stopWhatsThisText);
438 connect(stopAction, SIGNAL(triggered()), this, SLOT(StopProcessing()));
439
440 return stopAction;
441 }
442
443 // Create the "SaveLog" action
444 QAction *Gui::CreateSaveLogAction() {
445 QAction *saveLogAction = new QAction(this);
446 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
447 saveLogAction->setIcon(QPixmap(baseDir + "/guiSaveLog.png"));
448 saveLogAction->setText("&Save Log...");
449 saveLogAction->setToolTip("Save log");
450 QString saveWhatsThisText = "<p><b>Function: </b> Saves the information \
451 currently in the log area to a file <p><b>Shortcut: </b> Ctrl+S</p>";
452 saveLogAction->setWhatsThis(saveWhatsThisText);
453 saveLogAction->setShortcut(Qt::CTRL + Qt::Key_S);
454 connect(saveLogAction, SIGNAL(triggered(bool)), p_log, SLOT(Save()));
455
456 return saveLogAction;
457 }
458
459 // Create the "ClearLog" action
460 QAction *Gui::CreateClearLogAction() {
461 QAction *clearlogAction = new QAction(this);
462 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
463 clearlogAction->setIcon(QPixmap(baseDir + "/guiClearLog.png"));
464 clearlogAction->setText("&Clear Log");
465 clearlogAction->setToolTip("Clear log");
466 QString clearWhatsThisText = "<p><b>Function: </b>Clears all information \
467 from the log area at the bottom of the application screen</p> \
468 <p><b>Shortcut: </b> Ctrl+L</p>";
469 clearlogAction->setWhatsThis(clearWhatsThisText);
470 clearlogAction->setShortcut(Qt::CTRL + Qt::Key_L);
471 connect(clearlogAction, SIGNAL(triggered(bool)), p_log, SLOT(Clear()));
472
473 return clearlogAction;
474 }
475
476 // Create the "Previous History" action
477 QAction *Gui::CreatePreviousHistoryAction() {
478 QAction *previousHistoryAction = new QAction(this);
479 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
480 previousHistoryAction->setIcon(QPixmap(baseDir + "/guiPrevHistory.png"));
481 previousHistoryAction->setText("&Previous");
482 previousHistoryAction->setToolTip("Previous parameters");
483 QString previousWhatsThisText = "<p><b>Function: </b>Fills in parameter \
484 values using the previous history entry</p> \
485 <p><b>Shortcut: </b> F5</p>";
486 previousHistoryAction->setWhatsThis(previousWhatsThisText);
487 previousHistoryAction->setShortcut(Qt::Key_F5);
488 connect(previousHistoryAction, SIGNAL(triggered()), this, SLOT(PreviousHistory()));
489
490 return previousHistoryAction;
491 }
492
493 // Create the "Next History" action
494 QAction *Gui::CreateNextHistoryAction() {
495 QAction *nextHistoryAction = new QAction(this);
496 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
497 nextHistoryAction->setIcon(QPixmap(baseDir + "/guiNextHistory.png"));
498 nextHistoryAction->setText("&Next");
499 nextHistoryAction->setToolTip("Next parameters");
500 QString nextWhatsThisText = "<p><b>Function: </b>Fills in parameter \
501 values using the next history entry</p> \
502 <p><b>Shortcut: </b>F6</p>";
503 nextHistoryAction->setWhatsThis(nextWhatsThisText);
504 nextHistoryAction->setShortcut(Qt::Key_F6);
505 connect(nextHistoryAction, SIGNAL(triggered()), this, SLOT(NextHistory()));
506
507 return nextHistoryAction;
508 }
509
510 // Create the Whats Action action
511 QAction *Gui::CreateWhatsThisAction() {
512 QAction *action = new QAction(this);
513 QString baseDir = FileName("$ISISROOT/appdata/images/icons").expanded();
514 action->setIcon(QPixmap(baseDir + "/contexthelp.png"));
515 action->setText("&What's This");
516 action->setToolTip("What's This");
517 QString whatsThisText = "<p><b>Function: </b> Use this to get longer \
518 descriptions of button functions and parameter information</p> \
519 <p><b>Shortcut: </b> Shift+F1</p>";
520 action->setWhatsThis(whatsThisText);
521 action->setShortcut(Qt::SHIFT + Qt::Key_F1);
522 connect(action, SIGNAL(triggered(bool)), this, SLOT(WhatsThis()));
523
524 return action;
525 }
526
527 // Add a new parameter to this main window
528 GuiParameter *Gui::AddParameter(Isis::UserInterface &ui, int group, int param) {
529 // Create the group box if this is the first parameter in the group
530 QGridLayout *gridLayout = NULL;
531 if(!p_grids.contains(ui.GroupName(group))) {
532 // Create a new groupbox and add it to the scroll layout
533 QGroupBox *groupBox = new QGroupBox(ui.GroupName(group));
534 p_scrollLayout->addWidget(groupBox);
535 groupBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
536 groupBox->setAlignment(Qt::AlignHCenter);
537
538 // Create a gridlayout for the new groupbox and save it
539 gridLayout = new QGridLayout;
540 gridLayout->setColumnStretch(0, 0);
541 gridLayout->setColumnStretch(1, 0);
542 gridLayout->setColumnMinimumWidth(1, 10);
543 gridLayout->setColumnStretch(2, 10);
544 groupBox->setLayout(gridLayout);
545 p_grids[ui.GroupName(group)] = gridLayout;
546 }
547 // Find the group box for this parameter
548 else {
549 gridLayout = p_grids[ui.GroupName(group)];
550 }
551
552 GuiParameter *p = GuiParameterFactory::Create(gridLayout, ui, group, param);
553
554 if (p->Type() == GuiParameter::ListWidget || p->Type() == GuiParameter::ComboWidget ||
555 p->Type() == GuiParameter::BooleanWidget) {
556 connect(p, SIGNAL(ValueChanged()), this, SLOT(UpdateExclusions()));
557 }
558
559 connect(p, SIGNAL(HelperTrigger(const QString &)),
560 this, SLOT(InvokeHelper(const QString &)));
561 return p;
562 }
563
565 void Gui::ProgressText(const QString &text) {
566 p_statusText->setText(text);
567 qApp->processEvents(); // Needed when programs run programs
568 }
569
571 void Gui::Progress(int percent) {
572 p_progressBar->setValue(percent);
573 qApp->processEvents(); // Needed when programs run programs
574 }
575
580 int Gui::Exec(void (*funct)()) {
581 p_funct = funct;
582 return qApp->exec();
583 }
584
586 void Gui::LoadMessage(const QString &message) {
587 // Convert newlines to breaks
588 QString m = QString(message).replace("\n", "<br>");
589
590 // If there is a set of "[]" change everything between them to red text
591 if(message.contains("[") &&
592 message.contains("]") &&
593 (message.indexOf("[") < message.indexOf("]"))) {
594
595 int indx = 0;
596 while(m.indexOf("[", indx) != -1) {
597 m.insert(m.indexOf("[", indx) + 1, "<font color=#ff0000>");
598 m.insert(m.indexOf("]", indx), "</font>");
599 indx = m.indexOf("]", indx) + 1;
600 }
601 }
602 p_errorString += m;
603 }
604
607 Isis::UserInterface &ui = Isis::iApp->GetUserInterface();
608 int status = QMessageBox::warning(this,
609 ui.ProgramName(),
610 p_errorString,
611 "Ok", "Abort", "", 0, 1);
612 p_errorString.clear();
613 return status;
614 }
615
617 void Gui::Log(const QString &text) {
618 p_log->Write(text);
619 }
620
622 bool Gui::eventFilter(QObject *o, QEvent *e) {
623 if(e->type() == QEvent::Enter) {
624 if(p_processAction->isEnabled()) {
625 ProgressText("Ready");
626 Progress(0);
627 }
628 }
629 return false;
630 }
631
634 if(p_processAction->isEnabled()) return;
635
637 switch(QMessageBox::information(this,
638 ui.ProgramName(),
639 QString("Program suspended, choose to ") +
640 QString("continue processing, stop ") +
641 QString("processing or exit the program"),
642 "Continue",
643 "Stop",
644 "Exit", 0, 2)) {
645 case 0: // Pressed continue
646 break;
647
648 case 1: // Pressed stop
649 p_stop = true;
650 break;
651
652 case 2: // Pressed exit
653 p_stop = true;
654 qApp->quit();
655 }
656 }
657
662 qApp->processEvents();
663 return p_stop;
664 }
665
668 // Clear the AML to default values
670 for(int p = 0; p < (int)p_parameters.size(); p++) {
671 GuiParameter &param = *(p_parameters[p]);
672 ui.Clear(param.Name());
673 }
674
675 // Display the updated parameters
676 for(int p = 0; p < (int)p_parameters.size(); p++) {
677 GuiParameter &param = *(p_parameters[p]);
678 param.Update();
679 }
680 }
681
684 p_historyEntry--;
686 }
687
690 p_historyEntry++;
692 }
693
694
703 if(p_historyEntry < -1) {
704 p_historyEntry = -1;
705 QApplication::beep();
706 return;
707 }
708
709 if(p_historyEntry == -1) {
711 return;
712 }
713
714 // Find out if this application has a history file
716 Preference &p = Preference::Preferences();
717
718 PvlGroup &grp = p.findGroup("UserInterface", Isis::Pvl::Traverse);
719 Isis::FileName progHist(grp["HistoryPath"][0] + "/" + ui.ProgramName() + ".par");
720
721 if(!progHist.fileExists()) {
722 p_historyEntry = -1;
723 QApplication::beep();
724 return;
725 }
726
727 Isis::Pvl hist;
728
729 try {
730 hist.read(progHist.expanded());
731 }
732 catch(...) {
733 p_historyEntry = -1;
734 QString msg = "A corrupt parameter history file [" + progHist.expanded() +
735 "] has been detected. Please fix or remove this file";
736 LoadMessage(msg);
737 // When the warning is rejected (i.e. Abort), clean up from within qApp's exec event loop
738 if (ShowWarning()) {
739 qApp->quit();
740 }
741 return;
742 }
743
744 int entries = 0;
745 for(int i = 0; i < hist.groups(); i++) {
746 if(hist.group(i).isNamed("UserParameters")) entries++;
747 }
748
749 // If we are past the last entry ring the bell
750 if(p_historyEntry == entries) {
751 p_historyEntry = entries - 1;
752 QApplication::beep();
753 return;
754 }
755
756 int useEntry = entries - p_historyEntry - 1;
757
758 try {
759 //When defaults are used they do not get rewritten because they do not
760 //exist in the history file to be written over. Must reset parameters first.
762 Isis::PvlGroup &up = hist.group(useEntry);
763 for (int k = 0; k < up.keywords(); k++) {
764 QString key = up[k].name();
765 QString val;
766 // If the value has more than one element,
767 // construct a string array of those elements
768 if (up[k].size() > 1) {
769 val = "(";
770 for (int i = 0; i < up[k].size(); i++) {
771 QString newVal = up[k][i];
772 if (newVal.contains(",")) {
773 newVal = '"' + newVal + '"';
774 }
775 if (i == up[k].size() - 1) {
776 val += newVal + ")";
777 }
778 else {
779 val += newVal + ", ";
780 }
781 }
782 }
783 // Else, return the value on its own
784 else {
785 QString newVal = up[k];
786 val = newVal;
787 }
788 ui.Clear(key);
789 ui.PutAsString(key, val);
790 }
791
792 for(unsigned int p = 0; p < p_parameters.size(); p++) {
793 GuiParameter &param = *(p_parameters[p]);
794 param.Update();
795 }
796
797 }
798 catch(IException &e) {
799 p_historyEntry = entries - 1;
800 QApplication::beep();
801 return;
802 }
803 }
804
809 // First enable everything
810 for(unsigned int p = 0; p < p_parameters.size(); p++) {
811 GuiParameter &param = *(p_parameters[p]);
812 param.SetEnabled(true);
813 }
814
815 // Now disable things
816 for(unsigned int p = 0; p < p_parameters.size(); p++) {
817 GuiParameter &param = *(p_parameters[p]);
818 std::vector<QString> excludeList = param.Exclusions();
819 for(int i = 0; i < (int)excludeList.size(); i++) {
820 for(unsigned int e = 0; e < p_parameters.size(); e++) {
821 GuiParameter &exclude = *(p_parameters[e]);
822 if(exclude.Name() != excludeList[i]) continue;
823 exclude.SetEnabled(false, (param.Type()==GuiParameter::ComboWidget));
824 }
825 }
826 }
827 }
828
832 for(int p = 0; p < (int)p_parameters.size(); p++) {
833 GuiParameter &param = *(p_parameters[p]);
834 if(param.IsEnabled() && param.IsModified()) {
835 cline += " ";
836 QString name = param.Name().toLower();
837 cline += name;
838 cline += "=";
839 QString value = param.Value();
840 if(param.Type() == GuiParameter::StringWidget) {
841 if(value.contains(" ")) {
842 cline += "\"" + value + "\"";
843 }
844 else {
845 cline += value;
846 }
847 }
848 else if(param.Type() == GuiParameter::FileNameWidget ||
849 param.Type() == GuiParameter::CubeWidget) {
850 cline += value;
851 }
852 else {
853 value = value.toLower();
854 cline += value;
855 }
856 }
857 }
858 p_commandLineEdit->setText(cline);
859 }
860
863 for(unsigned int p = 0; p < p_parameters.size(); p++) {
864 GuiParameter &param = *(p_parameters[p]);
865 param.Update();
866 }
867 }
868
869 // Enter into what's this mode
870 void Gui::WhatsThis() {
871 QWhatsThis::enterWhatsThisMode();
872 }
873
874 // Show help for Isis
875 void Gui::AboutIsis() {
876 Isis::PvlGroup &uig = Isis::Preference::Preferences().findGroup("UserInterface");
877#if defined(__linux__)
878 QString command = (QString) uig["GuiHelpBrowser"] +
879 " http://isis.astrogeology.usgs.gov >> /dev/null &";
880#elif defined(__APPLE__)
881 QString command = "open -a" + (QString) uig["GuiHelpBrowser"] +
882 " http://isis.astrogeology.usgs.gov >> /dev/null &";
883#endif
885 }
886
887 // Show help for the current app
888 void Gui::AboutProgram() {
889 Isis::PvlGroup &uig = Isis::Preference::Preferences().findGroup("UserInterface");
890#if defined(__linux__)
891 QString command = (QString) uig["GuiHelpBrowser"] +
892 " http://isis.astrogeology.usgs.gov/Application/presentation/Tabbed/" +
895#elif defined(__APPLE__)
896 QString command = "open -a" + (QString) uig["GuiHelpBrowser"] +
897 " http://isis.astrogeology.usgs.gov/Application/presentation/Tabbed/" +
900#endif
902 }
903
905 void Gui::InvokeHelper(const QString &funct) {
906 p_processAction->setEnabled(false);
907 try {
909
910 // Pull the values from the parameters and put them into the Aml
911 for(int p = 0; p < (int)p_parameters.size(); p++) {
912 GuiParameter &param = *(p_parameters[p]);
913 ui.Clear(param.Name());
914 if(param.IsEnabled() && param.IsModified()) {
915 QString value = param.Value().simplified().trimmed();
916 if(value.length() > 0) {
917 ui.PutAsString(param.Name(), value);
918 }
919 }
920 }
921
922 // Get the helper function and run
923 void *ptr = Isis::iApp->GetGuiHelper(funct);
924 void (*helper)();
925 helper = (void ( *)())ptr;
926 helper();
927 }
928 catch(IException &e) {
929 Isis::iApp->GuiReportError(e);
930 }
931
932 // Update parameters in GUI
934 p_processAction->setEnabled(true);
935 }
936
937}
static UserInterface & GetUserInterface()
Returns the UserInterface object.
File name manipulation and expansion.
Definition FileName.h:100
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition FileName.cpp:449
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
Gui for Isis Applications.
Definition Gui.h:73
void StopProcessing()
The user pressed the stop button ... see what they want to do.
Definition Gui.cpp:633
void ResetParameters()
Reset the parameters fields to the defaults.
Definition Gui.cpp:667
~Gui()
Destructor.
Definition Gui.cpp:175
void InvokeHelper(const QString &funct)
Activate helper buttons.
Definition Gui.cpp:905
int Exec(void(*funct)())
Start the Gui and enter the main loop This routine only returns when the program is ready to exit.
Definition Gui.cpp:580
void Log(const QString &text)
Write text to the gui log.
Definition Gui.cpp:617
void ProgressText(const QString &text)
Change progress text.
Definition Gui.cpp:565
int ShowWarning()
Show an error message and return if the user wants to continue/abort.
Definition Gui.cpp:606
void UpdateParameters()
Update Parameters.
Definition Gui.cpp:862
void NextHistory()
Goto the next history entry.
Definition Gui.cpp:683
void UpdateExclusions()
Grey out parameters that should be excluded for radio buttons and checkboxes.
Definition Gui.cpp:808
void PreviousHistory()
Goto the previous history entry.
Definition Gui.cpp:689
void StartProcess()
The user pressed the go button.
Definition Gui.cpp:335
void Progress(int percent)
Update the progress bar.
Definition Gui.cpp:571
void LoadMessage(const QString &message)
Add more information to the error message.
Definition Gui.cpp:586
bool eventFilter(QObject *o, QEvent *e)
Reset the Progress bar when the user moves the mouse onto the toolbar.
Definition Gui.cpp:622
Gui(Isis::UserInterface &ui)
Constructor.
Definition Gui.cpp:130
static Gui * p_gui
Singleton.
Definition Gui.h:101
void UpdateHistory()
Changed the parameters based on the history pointer.
Definition Gui.cpp:702
bool ProcessEvents()
Let the event loop have some time to see if we need to cancel.
Definition Gui.cpp:661
void UpdateCommandLine()
Update the command line toolbar.
Definition Gui.cpp:830
static void checkX11()
check to see if X is available
Definition Gui.cpp:55
void Update()
Update the value on the GUI with the value in the UI.
bool IsEnabled() const
Is the parameter enabled.
virtual bool IsModified()
Return if the parameter value is different from the default value.
virtual std::vector< QString > Exclusions()
Return list of current exclusions.
void SetEnabled(bool enabled, bool isParentCombo=false)
Enable or disable the parameter.
QString Name() const
Return the name of the parameter.
Isis exception class.
Definition IException.h:91
QString toString() const
Returns a string representation of this exception.
Reads user preferences from a data file.
Definition Preference.h:60
static void RunSystemCommand(QString commandLine)
This runs arbitrary system commands.
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
bool isNamed(const QString &match) const
Returns whether the given string is equal to the container name or not.
int keywords() const
Returns the number of keywords contained in the PvlContainer.
QString name() const
Returns the container name.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
void read(const QString &file)
Loads PVL information from a stream.
Definition Pvl.cpp:90
PvlGroup & group(const int index)
Return the group at the specified index.
int groups() const
Returns the number of groups contained.
Definition PvlObject.h:75
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
Command Line and Xml loader, validation, and access.
void SaveHistory()
Saves the user parameter information in the history of the program for later use.
int NumGroups() const
Returns the number of groups found in the XML.
Definition IsisAml.cpp:1164
int NumParams(const int &) const
Returns the number of parameters in a group.
Definition IsisAml.cpp:1349
QString GroupName(const int &group) const
Returns the group name of group[index].
Definition IsisAml.cpp:1176
QString ProgramName() const
Returns the Program name.
Definition IsisAml.cpp:1133
void Clear(const QString &paramName)
Clears the value(s) in the named parameter.
Definition IsisAml.cpp:2037
void VerifyAll()
Verify all parameters.
Definition IsisAml.cpp:2575
void PutAsString(const QString &paramName, const QString &value)
Allows the insertion of a value for any parameter.
Definition IsisAml.cpp:68
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16