CFEL - ASG Software Suite  2.5.0
CASS
jocassview/main.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 Uwe Hoppe
2 // Copyright (C) 2010 Jochen Küpper
3 // Copyright (C) 2010 Nicola Coppola
4 // Copyright (C) 2013,2014 Lutz Foucar
5 
6 /**
7  * @file jocassview/main.cpp the main starter for jocassview
8  *
9  * @author Lutz Foucar
10  */
11 
12 #include <iostream>
13 
14 #include <QtCore/QSettings>
15 #include <QtCore/QFileInfo>
16 
17 #if QT_VERSION >= 0x050000
18 #include <QtWidgets/QApplication>
19 #else
20 #include <QtGui/QApplication>
21 #endif
22 
23 #include "jocassviewer.h"
24 #include "cl_parser.hpp"
25 #include "jocassview_version.h"
26 
27 using namespace jocassview;
28 
29 int main(int argc, char *argv[])
30 {
31  QApplication app(argc, argv);
32  QCoreApplication::setOrganizationName("CFEL-ASG");
33  QCoreApplication::setOrganizationDomain("endstation.asg.cfel.de");
34  QCoreApplication::setApplicationName("jocassview");
35  QSettings::setDefaultFormat(QSettings::IniFormat);
36  QApplication::setWindowIcon(QIcon(":images/mpg.svg"));
37 
38  /** open an instance of the jocassviwer */
39  JoCASSViewer jocassviewer;
40 
41  /** parse command line parameters and if first parameter is given open file */
43  std::string filename("nofile");
44  parser.add("-f","filename of file that one wants to open",filename);
45  std::string key("empty");
46  parser.add("--h5key","key of the datafield in the hdf5 file",key);
47  bool showUsage(false);
48  parser.add("-h","show this help",showUsage);
49  bool showVersion(false);
50  parser.add("--version","display the version of jocassview",showVersion);
51  bool restore(false);
52  parser.add("--restore","restore the previous session",restore);
53 
55 
56  /** show help and exit if requested */
57  if (showUsage)
58  {
59  parser.usage();
60  exit(0);
61  }
62 
63  /** show version and exit if requested */
64  if (showVersion)
65  {
66  std::cout <<VERSION <<std::endl;
67  exit(0);
68  }
69 
70  if (restore)
71  {
72  jocassviewer.refreshDisplayableItemsList();
73  QSettings settings;
74  QStringList viewers(settings.value("OpenedViewers").toStringList());
75  for (QStringList::ConstIterator it = viewers.begin(); it != viewers.end(); ++it)
76  {
77  jocassviewer.setDisplayedItem(*it,true,true);
78  }
79  }
80 
81  if ( filename == "nofile")
82  jocassviewer.startViewer();
83  else
84  {
85  QString fname(QString::fromStdString(filename));
86  QString keyname(QString::fromStdString(key));
87  if (keyname == "empty")
88  keyname = QFileInfo(fname).baseName();
89  /** @todo remove all non alphanumerical characters from the keystring before
90  * calling function
91  */
92  jocassviewer.openFile(fname,keyname);
93  }
94 
95  return app.exec();
96 }
contains the jocassviewer class
void startViewer()
start the viewer
void usage()
output which commandline parameters are available
Definition: cl_parser.hpp:40
setDefaultFormat(Format format)
int main(int argc, char *argv[])
the jocassview class
Definition: jocassviewer.h:41
fromStdString(const std::string &str)
contains a parser for command line parameters
void openFile(QString filename=QString(), QString key=QString())
load data from a file
void setDisplayedItem(QString itemName, bool state, bool simulateClickedSignal=true)
check an item in the list
void add(const std::string &sw, const std::string &desc, bool &val)
add a switch to the switches container
Definition: cl_parser.hpp:122
void refreshDisplayableItemsList()
refresh the items on the displayable list
command line argument parser
Definition: cl_parser.hpp:27
value(const QString &key, const QVariant &defaultValue=QVariant()