7 #include "ColorFilterMode.h" 8 #include "FittingCurveCoefficients.h" 9 #include "ImportImageExtensions.h" 11 #include "MainWindow.h" 12 #include <QApplication> 13 #include <QCoreApplication> 17 #include <QMessageBox> 19 #include <QProcessEnvironment> 20 #include <QStyleFactory> 21 #include "TranslatorContainer.h" 22 #include "ZoomFactor.h" 26 const QString CMD_DEBUG (
"debug");
27 const QString CMD_ERROR_REPORT (
"errorreport");
28 const QString CMD_EXPORT_ONLY (
"exportonly");
29 const QString CMD_EXTRACT_IMAGE_ONLY (
"extractimageonly");
30 const QString CMD_FILE_CMD_SCRIPT (
"filecmdscript");
31 const QString CMD_GNUPLOT (
"gnuplot");
32 const QString CMD_HELP (
"help");
33 const QString CMD_REGRESSION (
"regression");
34 const QString CMD_RESET (
"reset");
35 const QString CMD_STYLES (
"styles");
36 const QString DASH (
"-");
37 const QString DASH_DEBUG (
"-" + CMD_DEBUG);
38 const QString DASH_ERROR_REPORT (
"-" + CMD_ERROR_REPORT);
39 const QString DASH_EXTRACT_IMAGE_ONLY (
"-" + CMD_EXTRACT_IMAGE_ONLY);
40 const QString DASH_EXPORT_ONLY (
"-" + CMD_EXPORT_ONLY);
41 const QString DASH_FILE_CMD_SCRIPT (
"-" + CMD_FILE_CMD_SCRIPT);
42 const QString DASH_GNUPLOT (
"-" + CMD_GNUPLOT);
43 const QString DASH_HELP (
"-" + CMD_HELP);
44 const QString DASH_REGRESSION (
"-" + CMD_REGRESSION);
45 const QString DASH_RESET (
"-" + CMD_RESET);
46 const QString DASH_STYLES (
"-" + CMD_STYLES);
47 const QString ENGAUGE_LOG_FILE (
".engauge.log");
50 bool checkFileExists (
const QString &file);
51 QString engaugeLogFilename ();
52 bool engaugeLogFilenameAttempt (
const QString &path,
53 QString &pathAndFile);
54 void parseCmdLine (
int argc,
58 QString &errorReportFile,
59 QString &fileCmdScriptFile,
60 bool &isErrorReportRegressionTest,
63 bool &isExtractImageOnly,
64 QString &extractImageOnlyExtension,
65 QStringList &loadStartupFiles,
66 QStringList &commandLineWithoutLoadStartupFiles);
67 void sanityCheckLoadStartupFiles (
bool isRepeatingFlag,
68 const QString &dashForRepeatingFlag,
69 const QString &errorReportFile,
70 const QString &fileCmdScriptFile,
71 const QStringList &loadStartupFiles);
72 void sanityCheckValue (
bool requiredCondition,
74 const QString &msgUnadorned);
75 void showMessageAndQuit (
const QString &msg);
76 void showStylesAndQuit ();
77 void showUsageAndQuit ();
80 bool checkFileExists (
const QString &file)
82 QFileInfo check (file);
83 return check.exists() && check.isFile();
86 QString engaugeLogFilename()
90 #if !defined(OSX_RELEASE) && !defined(WIN_RELEASE) && !defined(APPIMAGE_RELEASE) 91 QProcessEnvironment env;
94 if (!engaugeLogFilenameAttempt (QCoreApplication::applicationDirPath(), pathAndFile)) {
95 if (!engaugeLogFilenameAttempt (env.value (
"HOME"), pathAndFile)) {
96 if (!engaugeLogFilenameAttempt (env.value (
"TEMP"), pathAndFile)) {
97 pathAndFile = ENGAUGE_LOG_FILE;
106 bool engaugeLogFilenameAttempt (
const QString &path,
107 QString &pathAndFile)
109 bool success =
false;
112 pathAndFile = QString (
"%1%2%3")
114 .arg (QDir::separator())
115 .arg (ENGAUGE_LOG_FILE);
116 QFile file (pathAndFile);
117 if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
127 int main(
int argc,
char *argv[])
129 qRegisterMetaType<ColorFilterMode> (
"ColorFilterMode");
130 qRegisterMetaType<FittingCurveCoefficients> (
"FilterCurveCoefficients");
131 qRegisterMetaType<ZoomFactor> (
"ZoomFactor");
133 QApplication app(argc, argv);
139 bool isDebug, isReset, isGnuplot, isErrorReportRegressionTest, isExportOnly, isExtractImageOnly;
140 QString errorReportFile, extractImageOnlyExtension, fileCmdScriptFile;
141 QStringList loadStartupFiles, commandLineWithoutLoadStartupFiles;
148 isErrorReportRegressionTest,
152 extractImageOnlyExtension,
154 commandLineWithoutLoadStartupFiles);
157 initializeLogging (
"engauge",
158 engaugeLogFilename(),
160 LOG4CPP_INFO_S ((*mainCat)) <<
"main args=" << QApplication::arguments().join (
" ").toLatin1().data();
165 isErrorReportRegressionTest,
170 extractImageOnlyExtension,
172 commandLineWithoutLoadStartupFiles);
179 void parseCmdLine (
int argc,
183 QString &errorReportFile,
184 QString &fileCmdScriptFile,
185 bool &isErrorReportRegressionTest,
188 bool &isExtractImageOnly,
189 QString &extractImageOnlyExtension,
190 QStringList &loadStartupFiles,
191 QStringList &commandLineWithoutLoadStartupFiles)
193 bool showUsage =
false;
198 bool nextIsErrorReportFile =
false;
199 bool nextIsExtractImageOnly =
false;
200 bool nextIsFileCmdScript =
false;
205 errorReportFile =
"";
206 fileCmdScriptFile =
"";
207 isErrorReportRegressionTest =
false;
209 isExportOnly =
false;
210 isExtractImageOnly =
false;
211 extractImageOnlyExtension =
"";
213 for (
int i = 1; i < argc; i++) {
215 bool isLoadStartupFile =
false;
217 if (nextIsErrorReportFile) {
218 sanityCheckValue (checkFileExists (argv [i]),
220 QObject::tr (
"is not a valid file name"));
221 errorReportFile = argv [i];
222 nextIsErrorReportFile =
false;
223 }
else if (nextIsExtractImageOnly) {
224 sanityCheckValue (importImageExtensions.
offers (argv [i]),
226 QObject::tr (
"is not a valid image file extension"));
227 extractImageOnlyExtension = argv [i];
228 nextIsExtractImageOnly =
false;
229 }
else if (nextIsFileCmdScript) {
230 sanityCheckValue (checkFileExists (argv [i]),
232 QObject::tr (
"is not a valid file name"));
233 fileCmdScriptFile = argv [i];
234 nextIsFileCmdScript =
false;
235 }
else if (strcmp (argv [i], DASH_DEBUG.toLatin1().data()) == 0) {
237 }
else if (strcmp (argv [i], DASH_ERROR_REPORT.toLatin1().data()) == 0) {
238 nextIsErrorReportFile =
true;
239 }
else if (strcmp (argv [i], DASH_EXPORT_ONLY.toLatin1().data()) == 0) {
241 }
else if (strcmp (argv [i], DASH_EXTRACT_IMAGE_ONLY.toLatin1().data()) == 0) {
242 isExtractImageOnly =
true;
243 nextIsExtractImageOnly =
true;
244 }
else if (strcmp (argv [i], DASH_FILE_CMD_SCRIPT.toLatin1().data()) == 0) {
245 nextIsFileCmdScript =
true;
246 }
else if (strcmp (argv [i], DASH_GNUPLOT.toLatin1().data()) == 0) {
248 }
else if (strcmp (argv [i], DASH_HELP.toLatin1().data()) == 0) {
250 }
else if (strcmp (argv [i], DASH_REGRESSION.toLatin1().data()) == 0) {
251 isErrorReportRegressionTest =
true;
252 }
else if (strcmp (argv [i], DASH_RESET.toLatin1().data()) == 0) {
254 }
else if (strcmp (argv [i], DASH_STYLES.toLatin1().data()) == 0) {
255 showStylesAndQuit ();
256 }
else if (strncmp (argv [i], DASH.toLatin1().data(), 1) == 0) {
261 QString fileName = argv [i];
262 QFileInfo fInfo (fileName);
263 if (fInfo.isRelative()) {
264 fileName = fInfo.absoluteFilePath();
267 isLoadStartupFile =
true;
268 loadStartupFiles << fileName;
272 if (!isLoadStartupFile) {
273 commandLineWithoutLoadStartupFiles << argv [i];
278 sanityCheckLoadStartupFiles (isExportOnly,
283 sanityCheckLoadStartupFiles (isExtractImageOnly,
284 DASH_EXTRACT_IMAGE_ONLY,
290 if (showUsage || nextIsErrorReportFile || nextIsExtractImageOnly || nextIsFileCmdScript) {
297 void sanityCheckLoadStartupFiles (
bool isRepeatingFlag,
298 const QString &dashForRepeatingFlag,
299 const QString &errorReportFile,
300 const QString &fileCmdScriptFile,
301 const QStringList &loadStartupFiles)
303 if (isRepeatingFlag && (!errorReportFile.isEmpty() ||
304 !fileCmdScriptFile.isEmpty() ||
305 loadStartupFiles.size() == 0)) {
310 QTextStream str (&msg);
311 str << dashForRepeatingFlag.toLatin1().data() <<
" " << QObject::tr (
"is used only with one or more load files");
312 showMessageAndQuit (msg);
316 void sanityCheckValue (
bool requiredCondition,
318 const QString &msgUnadorned)
320 if (!requiredCondition) {
323 QString msg = QString (
"%1 %2")
326 showMessageAndQuit (msg);
330 void showMessageAndQuit (
const QString &msg)
333 QMessageBox::critical (0,
334 QObject::tr (
"Engauge Digitizer"),
339 void showStylesAndQuit ()
342 QTextStream str (&msg);
343 str << QObject::tr (
"Available styles") <<
": " << QStyleFactory::keys ().join (
", ");
344 showMessageAndQuit (msg);
347 void showUsageAndQuit ()
350 QTextStream str (&msg);
351 str <<
"<html>Usage: engauge " 352 <<
"[" << DASH_DEBUG.toLatin1().data() <<
"] " 353 <<
"[" << DASH_ERROR_REPORT.toLatin1().data() <<
" <file>] " 354 <<
"[" << DASH_EXPORT_ONLY.toLatin1().data() <<
"] " 355 <<
"[" << DASH_EXTRACT_IMAGE_ONLY.toLatin1().data() <<
" <extension>] " 356 <<
"[" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
" <file> " 357 <<
"[" << DASH_GNUPLOT.toLatin1().data() <<
"] " 358 <<
"[" << DASH_HELP.toLatin1().data() <<
"] " 359 <<
"[" << DASH_REGRESSION.toLatin1().data() <<
"] " 360 <<
"[" << DASH_RESET.toLatin1().data () <<
"] " 361 <<
"[" << DASH_STYLES.toLatin1().data () <<
"] " 362 <<
"[<load_file1>] [<load_file2>] ..." << endl
365 <<
"<td>" << DASH_DEBUG.toLatin1().data() <<
"</td>" 367 << QObject::tr (
"Enables extra debug information. Used for debugging").toLatin1().data()
371 <<
"<td>" << DASH_ERROR_REPORT.toLatin1().data() <<
"</td>" 373 << QObject::tr (
"Specifies an error report file as input. Used for debugging and testing").toLatin1().data()
377 <<
"<td>" << DASH_EXPORT_ONLY.toLatin1().data() <<
"</td>" 379 << QObject::tr (
"Export each loaded startup file, which must have all axis points defined, then stop").toLatin1().data()
383 <<
"<td>" << DASH_EXTRACT_IMAGE_ONLY.toLatin1().data() <<
"</td>" 385 << QObject::tr (
"Extract image in each loaded startup file to a file with the specified extension, then stop").toLatin1().data()
389 <<
"<td>" << DASH_FILE_CMD_SCRIPT.toLatin1().data() <<
"</td>" 391 << QObject::tr (
"Specifies a file command script file as input. Used for debugging and testing").toLatin1().data()
395 <<
"<td>" << DASH_GNUPLOT.toLatin1().data() <<
"</td>" 397 << QObject::tr (
"Output diagnostic gnuplot input files. Used for debugging").toLatin1().data()
401 <<
"<td>" << DASH_HELP.toLatin1().data() <<
"</td>" 403 << QObject::tr (
"Show this help information").toLatin1().data()
407 <<
"<td>" << DASH_REGRESSION.toLatin1().data() <<
"</td>" 409 << QObject::tr (
"Executes the error report file or file command script. Used for regression testing").toLatin1().data()
413 <<
"<td>" << DASH_RESET.toLatin1().data() <<
"</td>" 415 << QObject::tr (
"Removes all stored settings, including window positions. Used when windows start up offscreen").toLatin1().data()
419 <<
"<td>" << DASH_STYLES.toLatin1().data() <<
"</td>" 421 << QObject::tr (
"Show a list of available styles that can be used with the -style command").toLatin1().data()
425 <<
"<td>" << QString (
"<load file> ").toLatin1().data() <<
"</td>" 427 << QObject::tr (
"File(s) to be imported or opened at startup").toLatin1().data()
430 <<
"</table></html>";
432 showMessageAndQuit (msg);
Provides list of file extensions for import.
bool offers(const QString &fileExtension) const
Return true if specified file extension is supported.
Class that stores QTranslator objects for the duration of application execution.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...