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