Engauge Digitizer  2
main.cpp
1 #include "ColorFilterMode.h"
2 #include <iostream>
3 #include "Logger.h"
4 #include "MainWindow.h"
5 #include <QApplication>
6 #include <QFileInfo>
7 
8 using namespace std;
9 
10 const QString CMD_DEBUG ("debug");
11 const QString CMD_ERROR ("error");
12 const QString CMD_GNUPLOT ("gnuplot");
13 const QString CMD_HELP ("help");
14 const QString DASH ("-");
15 const QString DASH_DEBUG ("-" + CMD_DEBUG);
16 const QString DASH_ERROR ("-" + CMD_ERROR);
17 const QString DASH_GNUPLOT ("-" + CMD_GNUPLOT);
18 const QString DASH_HELP ("-" + CMD_HELP);
19 
20 // Prototypes
21 bool checkFileExists (const QString &file);
22 void parseCmdLine (int argc,
23  char **argv,
24  bool &isDebug,
25  QString &errorReportFile,
26  bool &isGnuplot,
27  QStringList &loadStartupFiles);
28 
29 // Functions
30 bool checkFileExists (const QString &file)
31 {
32  QFileInfo check (file);
33  return check.exists() && check.isFile();
34 }
35 
36 int main(int argc, char *argv[])
37 {
38  qRegisterMetaType<ColorFilterMode> ("ColorFilterMode");
39 
40  QApplication a(argc, argv);
41 
42  bool isDebug, isGnuplot;
43  QString errorReportFile;
44  QStringList loadStartupFiles;
45  parseCmdLine (argc,
46  argv,
47  isDebug,
48  errorReportFile,
49  isGnuplot,
50  loadStartupFiles);
51 
52  initializeLogging ("engauge",
53  "engauge.log",
54  isDebug);
55  LOG4CPP_INFO_S ((*mainCat)) << "main args=" << QApplication::arguments().join (" ").toLatin1().data();
56 
57  MainWindow w (errorReportFile,
58  isGnuplot,
59  loadStartupFiles);
60  w.show();
61 
62  return a.exec();
63 }
64 
65 void parseCmdLine (int argc,
66  char **argv,
67  bool &isDebug,
68  QString &errorReportFile,
69  bool &isGnuplot,
70  QStringList &loadStartupFiles)
71 {
72  const int COLUMN_WIDTH = 20;
73  bool showUsage = false;
74 
75  // State
76  bool nextIsErrorReportFile = false;
77 
78  // Defaults
79  isDebug = false;
80  errorReportFile = "";
81  isGnuplot = false;
82 
83  for (int i = 1; i < argc; i++) {
84 
85  if (nextIsErrorReportFile) {
86  errorReportFile = argv [i];
87  showUsage |= !checkFileExists (errorReportFile);
88  nextIsErrorReportFile = false;
89  } else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
90  isDebug = true;
91  } else if (strcmp (argv [i], DASH_ERROR.toLatin1().data()) == 0) {
92  nextIsErrorReportFile = true;
93  } else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
94  isGnuplot = true;
95  } else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
96  showUsage = true; // User requested help
97  } else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
98  showUsage = true; // User entered an unrecognized token
99  } else {
100  loadStartupFiles << argv [i]; // Save file name
101  }
102  }
103 
104  if (showUsage || nextIsErrorReportFile) {
105 
106  cerr << "Usage: engauge "
107  << "[" << DASH_DEBUG.toLatin1().data() << "] "
108  << "[" << DASH_ERROR.toLatin1().data() << " <file>] "
109  << "[" << DASH_GNUPLOT.toLatin1().data() << "] "
110  << "[" << DASH_HELP.toLatin1().data() << "] "
111  << "[<load_file1>] [<load_file2>] ..." << endl
112  << " " << DASH_DEBUG.leftJustified(COLUMN_WIDTH, ' ').toLatin1().data() << "Enables extra debug information" << endl
113  << " " << DASH_ERROR.leftJustified(COLUMN_WIDTH, ' ').toLatin1().data() << "Specifies an error report fie as input" << endl
114  << " " << DASH_GNUPLOT.leftJustified(COLUMN_WIDTH, ' ').toLatin1().data() << "Output diagnostic gnuplot input files for debugging" << endl
115  << " " << DASH_HELP.leftJustified(COLUMN_WIDTH, ' ').toLatin1().data() << "Show this help information" << endl
116  << " " << QString ("<load file> ").leftJustified(COLUMN_WIDTH, ' ').toLatin1().data() << "File to be imported or opened at startup" << endl;
117 
118  exit (0);
119  }
120 }
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:66