1 #define _CRT_SECURE_NO_WARNINGS
39 #ifdef HAVE_PERKIN_ELMER
44 #include <QtConcurrentRun>
45 #include <QFileDialog>
46 #include <QMessageBox>
49 #include <QPluginLoader>
50 #include <QSplashScreen>
51 #include <QDesktopServices>
53 #include <QCoreApplication>
55 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
56 #include <QJsonObject>
61 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
62 QCoreApplication::EventFilter oldEventFilter;
64 static bool myEventFilter(
void *message,
long *result)
69 return oldEventFilter(message, result);
75 QTimer eventCounterTimer;
91 for (
int i=0; i<
argc; i++) {
103 m_RecentExperiments(
m_Saver, this,
"recentExperiments", QStringList(),
"Recent Experiments"),
104 m_RecentExperimentsSize(
m_Saver, this,
"recentExperimentsSize", 8,
"Number of Recent Experiments to Remember"),
105 m_CurrentExperiment(
m_Saver, this,
"currentExperiment",
"",
"Current Experiment"),
106 m_CurrentDirectory(
m_Saver, this,
"currentDirectory", QDir::
homePath(),
"Current Directory"),
108 m_Debug(
m_Saver, this,
"debug", 0,
"Debug Level"),
110 m_FileBrowserLimit(
m_Saver, this,
"fileBrowserLimit", 1000,
"Max Number of Files in Browser Windows (0 = unlimited)"),
111 m_MessageWindowLines(
m_Saver, this,
"messageWindowLines", 1000,
"Number of Lines in Message Window (0 = unlimited)"),
112 m_UpdateIntervalMsec(
m_Saver, this,
"updateIntervalMsec", 1000,
"Time Intervale for Updates (in msec)"),
116 m_StartDetectors(
QcepSettingsSaverPtr(), this,
"startDetectors", 1,
"Start Detectors when opening experiments"),
126 #ifdef HAVE_PERKIN_ELMER
127 m_PerkinElmerPluginInterface(NULL),
134 printf(
"QxrdApplication::QxrdApplication(%p)\n",
this);
157 QDir::setCurrent(QDir::homePath());
159 setOrganizationName(
"cep");
160 setOrganizationDomain(
"xray.aps.anl.gov");
161 setApplicationName(
"qxrd");
163 printMessage(
"------ Starting QXRD Application ------");
165 QString about =
"QXRD Version " STR(QXRD_VERSION);
167 if (
sizeof(
void*) == 4) {
168 about +=
" - 32 Bit";
170 about +=
" - 64 Bit";
182 about +=
" Release\n";
195 for (
int i=1; i<
argc; i++) {
198 if (strcmp(argv[i],
"-fresh") == 0) {
199 set_FreshStart(
true);
200 }
else if (sscanf(argv[i],
"-debug=%d",&dbg)==1) {
202 }
else if (strcmp(argv[i],
"-nogui")==0) {
203 set_GuiWanted(
false);
204 }
else if (strcmp(argv[i],
"-gui")==0) {
206 }
else if (strcmp(argv[i],
"-nostart")==0) {
207 printf(
"Don't start detectors\n");
208 set_StartDetectors(
false);
209 }
else if (strcmp(argv[i],
"-start")==0) {
210 set_StartDetectors(
true);
211 }
else if (strcmp(argv[i],
"-c")==0) {
213 prop_CmdList()->appendValue(argv[i]);
215 }
else if (strcmp(argv[i],
"-s")==0) {
217 prop_CmdList()->appendValue(tr(
"loadScript(\"%1\")").arg(argv[i]));
220 prop_FileList()->appendValue(argv[i]);
224 if (get_GuiWanted() ==
false) {
225 foreach(QString cmd, get_CmdList()) {
226 printf(
"Cmd: %s\n", qPrintable(cmd));
229 foreach(QString file, get_FileList()) {
230 printf(
"File: %s\n", qPrintable(file));
240 printMessage(tr(
"Home Path: %1").arg(QDir::homePath()));
241 printMessage(tr(
"Current Path: %1").arg(QDir::currentPath()));
246 QThread::currentThread()->setObjectName(
"app");
251 printMessage(tr(
"Optimal thread count = %1").arg(QThread::idealThreadCount()));
255 if (get_FreshStart()) {
259 if ( (get_CurrentExperiment().length()>0)) {
273 printf(
"Deleting application\n");
279 printf(
"QxrdApplication::~QxrdApplication(%p)\n",
this);
328 #ifdef HAVE_PERKIN_ELMER
332 return m_PerkinElmerPluginInterface;
342 #define xstr(s) str(s)
347 QList<QDir> pluginsDirList;
349 #ifdef QXRD_PLUGIN_PATH
350 pluginsDirList.append(QDir(
xstr(QXRD_PLUGIN_PATH)));
352 QDir pluginsDir = QDir(qApp->applicationDirPath());
353 pluginsDir.cd(
"plugins");
354 pluginsDirList.append(pluginsDir);
356 foreach (QDir pluginsDir, pluginsDirList) {
358 printf(
"Looking for plugins in directory %s\n", qPrintable(pluginsDir.absolutePath()));
361 foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
362 QString fullPath = pluginsDir.absoluteFilePath(fileName);
365 printf(
"Looking for plugin in file %s\n", qPrintable(fullPath));
368 if (QLibrary::isLibrary(fullPath)) {
369 QPluginLoader loader(fullPath);
371 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
372 QJsonObject meta = loader.metaData();
375 printf(
"Plugin metadata for %s\n", qPrintable(fullPath));
376 foreach(QString key, meta.keys()) {
377 printf(
"Key %s = %s\n", qPrintable(key), qPrintable(meta.value(key).toString()));
382 QObject *plugin = loader.instance();
385 printf(
"Loaded plugin from %s : type %s\n", qPrintable(fullPath), qPrintable(plugin->metaObject()->className()));
388 QString pluginName =
"";
393 pluginName = detector -> name();
399 pluginName = processor -> name();
402 #ifdef HAVE_PERKIN_ELMER
406 pluginName = perkinElmer -> name();
415 pluginName = nidaq -> name();
425 .arg(pluginsDir.absoluteFilePath(fileName)));
428 printf(
"Failed to load plugin from %s : %s\n", qPrintable(fileName), qPrintable(loader.errorString()));
431 if (QLibrary::isLibrary(pluginsDir.absoluteFilePath(fileName))) {
432 QString msg = tr(
"Failed to load plugin %1 : %2")
433 .arg(pluginsDir.absoluteFilePath(fileName))
434 .arg(loader.errorString());
441 printf(
"File %s is not a library\n", qPrintable(fileName));
450 if (QThread::currentThread() != thread()) {
451 QMetaObject::invokeMethod(
this,
"splashMessage", Q_ARG(QString, msg));
455 if (get_GuiWanted()) {
462 QString msgf = tr(
"Qxrd Version " STR(QXRD_VERSION)
"\n")+msg;
464 m_Splash->showMessage(msgf, Qt::AlignBottom|Qt::AlignHCenter);
488 INVOKE_CHECK(QMetaObject::invokeMethod(
experiment(0).data(),
"warningMessage", Qt::BlockingQueuedConnection, Q_ARG(QString, msg)));
496 QString message = ts.toString(
"yyyy.MM.dd : hh:mm:ss.zzz ")+
497 QThread::currentThread()->objectName()+
": "+
500 message = message.replace(
"\n",
" : ");
505 INVOKE_CHECK(QMetaObject::invokeMethod(
experiment(0).data(),
"printMessage", Qt::QueuedConnection, Q_ARG(QString, msg)));
514 QString message = ts.toString(
"yyyy.MM.dd : hh:mm:ss.zzz ")+msg.trimmed();
516 message = message.replace(
"\n",
" : ");
521 INVOKE_CHECK(QMetaObject::invokeMethod(
experiment(0).data(),
"statusMessage", Qt::QueuedConnection, Q_ARG(QString, message)));
528 QString message = ts.toString(
"yyyy.MM.dd : hh:mm:ss.zzz ")+msg.trimmed();
530 message = message.replace(
"\n",
" : ");
535 INVOKE_CHECK(QMetaObject::invokeMethod(
experiment(0).data(),
"criticalMessage", Qt::QueuedConnection, Q_ARG(QString, message)));
541 return QDir::homePath();
546 return QDir::currentPath();
551 return QDir::rootPath();
570 alloc->readSettings(settings,
"allocator");
590 alloc->writeSettings(settings,
"allocator");
596 QString loadPrefsFrom = QFileDialog::getOpenFileName(NULL,
597 "Load QXRD Preferences from...");
599 if (loadPrefsFrom !=
"") {
613 QString savePrefsTo = QFileDialog::getSaveFileName(NULL,
614 "Save QXRD Preferences to...");
616 if (savePrefsTo !=
"") {
623 QFile::remove(path+
".new");
631 QFile::remove(path+
".bak");
632 QFile::rename(path, path+
".bak");
633 QFile::rename(path+
".new", path);
645 return QMessageBox::question(NULL, tr(
"Really Quit?"),
646 tr(
"Do you really want to exit the application?"),
647 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok;
657 QString about =
"QXRD Data Acquisition for PE Area Detectors\nVersion " STR(QXRD_VERSION);
659 if (
sizeof(
void*) == 4) {
660 about +=
" - 32 Bit";
662 about +=
" - 64 Bit";
678 about +=
" Release\n";
683 about += tr(
"Qt Version %1\n").arg(qVersion());
684 about += tr(
"Qceplib Version %1\n").arg(
STR(QCEPLIB_VERSION));
685 about += tr(
"QWT Version %1\n").arg(
STR(QCEPLIB_QWT_VERSION));
686 about += tr(
"Mar345 Version %1\n").arg(
STR(QCEPLIB_MAR345_VERSION));
687 about += tr(
"CBF Version %1\n").arg(
STR(QCEPLIB_CBF_VERSION));
688 about += tr(
"TIFF Version %1\n").arg(
STR(QCEPLIB_TIFF_VERSION));
689 about += tr(
"LevMar Version %1\n").arg(
STR(QCEPLIB_LEVMAR_VERSION));
690 #ifdef QCEPLIB_ZLIB_VERSION
691 about += tr(
"ZLIB Version %1\n").arg(
STR(QCEPLIB_ZLIB_VERSION));
694 #ifdef QCEPLIB_SZIP_VERSION
695 about += tr(
"SZIP Version %1\n").arg(
STR(QCEPLIB_SZIP_VERSION));
698 #ifdef QCEPLIB_HDF5_VERSION
699 about += tr(
"HDF5 Version %1\n").arg(
STR(QCEPLIB_HDF5_VERSION));
701 about += tr(
"Spec Server Version %1\n").arg(
STR(QCEPLIB_SPECSERVER_VERSION));
703 QMessageBox::about(NULL,
"QXRD", about);
708 QDesktopServices::openUrl(QUrl(
"http://qxrd.sourceforge.net/"));
713 QDesktopServices::openUrl(QUrl(url));
745 vsnprintf(msg,
sizeof(msg), fmt, ap);
757 TIFFSetErrorHandlerExt (NULL);
759 TIFFSetWarningHandlerExt (NULL);
767 app->
criticalMessage(tr(
"TIFF Warning from %1 : %2").arg(module).arg(msg));
776 app->
criticalMessage(tr(
"TIFF Error from %1 : %2").arg(module).arg(msg));
785 bool res = QApplication::event(ev);
787 int elapsed = tick.restart();
789 if (elapsed > 1000) {
799 obj->set_Creator(
"QXRD");
800 obj->set_Version(
STR(QXRD_VERSION));
801 obj->set_QtVersion(QT_VERSION_STR);
807 QSettings settings(
"cep.xor.aps.anl.gov",
"qxrd-defaults");
809 set_RecentExperiments(settings.value(
"recentExperiments").toStringList());
810 set_RecentExperimentsSize(settings.value(
"recentExperimentsSize", 8).toInt());
811 set_CurrentExperiment(settings.value(
"currentExperiment").toString());
816 QSettings settings(
"cep.xor.aps.anl.gov",
"qxrd-defaults");
818 settings.setValue(
"recentExperiments", get_RecentExperiments());
819 settings.setValue(
"recentExperimentsSize", get_RecentExperimentsSize());
820 settings.setValue(
"currentExperiment", get_CurrentExperiment());
830 QString res = QFileDialog::getOpenFileName(NULL,
831 "Open an existing experiment...",
832 get_CurrentExperiment(),
833 "QXRD Experiments (*.qxrdp);;Other Files (*)");
835 if (res.length() > 0) {
842 if (path.length() > 0) {
859 printf(
"QxrdApplication::closeExperiment(%p)\n", exp.data());
875 QStringList recent = get_RecentExperiments();
877 recent.prepend(path);
878 recent.removeDuplicates();
880 while(recent.length() > get_RecentExperimentsSize()) {
884 set_RecentExperiments(recent);
889 QFileInfo info(filename);
890 QString exten = info.suffix();
892 if (exten !=
"qxrdp") {
893 return filename+
".qxrdp";
901 QFileInfo info(filename);
902 QString path = info.path();
903 QString base = info.completeBaseName();
905 settings.setValue(
"application/d", type);
906 settings.setValue(
"processor/outputDirectory", path);
907 settings.setValue(
"application/logFileName", base+
".log");
908 settings.setValue(
"processor/integratedFileName", base+
".avg");
909 settings.setValue(
"window/inputFileBrowser/rootDirectory", path);
910 settings.setValue(
"window/outputFileBrowser/rootDirectory", path);
920 settings.setValue(
"application/runSpecServer",
false);
921 settings.setValue(
"application/runSimpleServer",
false);
979 QFileInfo info(path);
984 printMessage(tr(
"Experiment %1 does not exist").arg(path));
996 QString path = expt->experimentFilePath();
997 set_CurrentExperiment(path);
1009 expt->openWindows();
1039 if (exp->experimentFilePath() == path) {
1043 win->activateWindow();
1147 prop_LockerCount()->incValue(1);
1162 printMessage(tr(
"Locker rate %1 locks/sec").arg(rate));
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
void tiffError(const char *module, const char *msg)
QcepAllocatorWPtr m_Allocator
QSharedPointer< QxrdWindow > QxrdWindowPtr
virtual ~QxrdApplication()
void appendRecentExperiment(QString path)
QxrdApplication(int &argc, char **argv)
void activateExperiment(QString path)
void lockerTimerElapsed()
static void readSettings(QObject *object, QSettings *settings, QString section)
qint64 qcepDebug(int cond)
static void registerMetaTypes()
static void registerMetaTypes()
QxrdExperimentPtr experiment(int i)
bool init(QxrdApplicationWPtr app, int &argc, char **argv)
void doOpenURL(QString url)
static void registerMetaTypes()
void savePreferences(QString path)
void chooseExistingExperiment()
QList< QxrdExperimentWPtr > m_Experiments
void writeDefaultSettings()
QSharedPointer< QxrdPerkinElmerPluginInterface > QxrdPerkinElmerPluginInterfacePtr
void debugChanged(qint64 newValue)
static void registerMetaTypes()
QList< QxrdExperimentWPtr > & experiments()
static QxrdExperimentThreadPtr newExperiment(QString path, QxrdApplicationWPtr app, QSettings *settings)
QxrdResponseTimer * m_ResponseTimer
QxrdApplicationWPtr m_Application
void editGlobalPreferences()
QStringList makeStringListFromArgs(int argc, char **argv)
void openedExperiment(QxrdExperimentThreadPtr expthrdw)
void logMessage(QString msg)
QWeakPointer< QxrdApplication > QxrdApplicationWPtr
void tiffWarning(const char *module, const char *msg)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
void openRecentExperiment(QString path)
QxrdWelcomeWindowPtr m_WelcomeWindow
QcepObjectNamer m_ObjectNamer
QSharedPointer< QcepAllocatorThread > QcepAllocatorThreadPtr
QSharedPointer< QxrdExperimentThread > QxrdExperimentThreadPtr
QxrdNIDAQPluginInterfacePtr nidaqPlugin()
#define INVOKE_CHECK(res)
void processEventCounter()
static void qxrdTIFFErrorHandler(const char *module, const char *fmt, va_list ap)
QcepAllocatorThreadPtr m_AllocatorThread
static void writeSettings(QObject *object, QSettings *settings, QString section)
QString normalizeExperimentName(QString filename)
static void registerMetaTypes()
void warningMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
void splashMessage(QString msg)
void setNewExperimentSettings(QSettings &settings, int type, QString filename)
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
void loadPreferences(QString path)
QWeakPointer< QcepAllocator > QcepAllocatorWPtr
QSharedPointer< QcepSettingsSaver > QcepSettingsSaverPtr
void closeWelcomeWindow()
void valueChanged(qint64 val, int index)
QSharedPointer< QxrdNIDAQPluginInterface > QxrdNIDAQPluginInterfacePtr
void chooseNewExperiment()
static void qxrdTIFFWarningHandler(const char *, const char *, va_list)
void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
virtual void setDefaultObjectData(QcepDataObject *obj)
QcepApplication * g_Application
QSharedPointer< QcepDebugDictionary > g_DebugLevel
void closedExperiment(QxrdExperimentThreadPtr expthrdw)
void criticalMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
QSharedPointer< QcepAllocator > QcepAllocatorPtr
QList< QxrdExperimentThreadPtr > m_ExperimentThreads
QSharedPointer< QxrdSplashScreen > QxrdSplashScreenPtr
void readDefaultSettings()
QcepAllocatorWPtr allocator() const
QxrdNIDAQPluginInterfacePtr m_NIDAQPluginInterface
void closeExperiment(QxrdExperimentWPtr exp)
void openExperiment(QString path)
QxrdSplashScreenPtr m_Splash
QcepSettingsSaverPtr m_Saver