1 #define _CRT_SECURE_NO_WARNINGS
24 #include <QFileDialog>
41 #include <QColorDialog>
70 m_ScanFileExtension(
m_SettingsSaver, this,
"scanFileExtension",
".avg",
"Scan File Extension"),
71 m_ScanDataNegative(
m_SettingsSaver, this,
"scanDataNegative", 0,
"Scan Data Negative Value Handling"),
75 m_CompletionPercentage(
QcepSettingsSaverWPtr(), this,
"completionPercentage", 0,
"Percentage of Work Completed"),
76 m_DefaultScript(
m_SettingsSaver, this,
"defaultScript",
"",
"Default script for experiment"),
77 m_ExtraScriptFiles(
m_SettingsSaver, this,
"extraScriptFiles", QStringList(),
"Additional script files for experiment"),
78 m_FontSize(
m_SettingsSaver, this,
"fontSize", -1,
"Suggested font size"),
79 m_Spacing(
m_SettingsSaver, this,
"spacing", -1,
"Suggested widget spacing")
82 printf(
"QxrdExperiment::QxrdExperiment(%p)\n",
this);
115 saver -> setExperiment(sharedFromThis());
152 acq -> setNIDAQPlugin(app->nidaqPlugin());
163 cols <<
"x" <<
"y" <<
"z" <<
"v" <<
"sdev";
213 connect(srv.data(), &QSpecServer::executeCommand,
217 srv.data(), &QSpecServer::finishedCommand);
237 proc -> loadDefaultImages();
241 QDir::setCurrent(QDir::homePath());
244 printMessage(tr(
"------- Starting new session -------"));
245 printMessage(tr(
"Experiment name: %1").arg(get_ExperimentName()));
246 printMessage(tr(
"Experiment Directory: %1").arg(get_ExperimentDirectory()));
247 printMessage(tr(
"Stored in file: %1").arg(get_ExperimentFileName()));
249 QString about =
STR(QXRD_VERSION);
251 if (
sizeof(
void*) == 4) {
252 about +=
" - 32 Bit";
254 about +=
" - 64 Bit";
272 about +=
" : Macintosh";
273 #elif defined(Q_OS_WIN32)
274 about +=
" : Windows";
275 #elif defined(Q_OS_UNIX)
283 printMessage(tr(
"Mar345 Version %1").arg(
STR(QCEPLIB_MAR345_VERSION)));
286 printMessage(tr(
"LevMar Version %1").arg(
STR(QCEPLIB_LEVMAR_VERSION)));
287 #ifdef QCEPLIB_HDF5_VERSION
290 printMessage(tr(
"Spec Server Version %1").arg(
STR(QCEPLIB_SPECSERVER_VERSION)));
291 printMessage(tr(
"Running on host %1").arg(QHostInfo::localHostName()));
292 printMessage(tr(
"Current directory %1").arg(QDir::currentPath()));
312 if (app && app->get_GuiWanted()) {
321 NULL), &QObject::deleteLater);
354 if (
m_Window && app && app->get_GuiWanted()) {
364 printf(
"Deleting experiment\n");
370 app->printMessage(
"QxrdExperiment::~QxrdExperiment");
374 printf(
"QxrdExperiment::~QxrdExperiment(%p)\n",
this);
388 app->splashMessage(msg);
398 win->displayCriticalMessage(msg);
400 app->criticalMessage(msg);
402 printf(
"%s\n", qPrintable(msg));
412 win->displayStatusMessage(msg);
414 app->statusMessage(msg);
416 printf(
"%s\n", qPrintable(msg));
424 QString message = ts.toString(
"yyyy.MM.dd : hh:mm:ss.zzz ")+
425 QThread::currentThread()->objectName()+
": "+
428 message = message.replace(
"\n",
" : ");
439 win->displayMessage(message);
451 printf(
"%s\n", qPrintable(msg));
457 win->displayMessage(msg);
531 return dp->centerFinder();
542 return dp->integrator();
558 eng->evaluateAppCommand(cmd);
567 process.waitForReadyRead();
569 return process.readAllStandardOutput();
583 set_LogFileName(path);
610 fprintf(
m_LogFile,
"#F %s\n", qPrintable(get_LogFileName()));
611 fprintf(
m_LogFile,
"#E %d\n", QDateTime::currentDateTime().toTime_t());
612 fprintf(
m_LogFile,
"#D %s\n", qPrintable(QDateTime::currentDateTime().toString(
"ddd MMM d hh:mm:ss yyyy")));
625 fseek(logFile, -10000, SEEK_END);
628 fgets(buff, 10000, logFile);
630 while (!feof(logFile)) {
631 fgets(buff, 10000, logFile);
654 fprintf(
m_LogFile,
"#CX %s\n", qPrintable(msg));
664 fprintf(
m_LogFile,
"#CX %s ------- shutdown --------\n",
665 qPrintable(QDateTime::currentDateTime().toString(
"yyyy.MM.dd : hh:mm:ss.zzz ")));
683 set_ScanFileName(path);
696 fprintf(
m_ScanFile,
"#F %s\n", qPrintable(get_LogFileName()));
697 fprintf(
m_ScanFile,
"#E %d\n", QDateTime::currentDateTime().toTime_t());
698 fprintf(
m_ScanFile,
"#D %s\n", qPrintable(QDateTime::currentDateTime().toString(
"ddd MMM d hh:mm:ss yyyy")));
725 if (docPath.length()>0) {
726 QSettings settings(docPath, QSettings::IniFormat);
754 if (settings->contains(
"experiment/detectorType")) {
755 int detType = settings->value(
"experiment/detectorType", -1).toInt();
759 if (acq->get_DetectorCount() == 0) {
760 acq->appendDetector(detType);
790 if (docPath.length()>0) {
791 QFile::remove(docPath+
".new");
794 QSettings settings(docPath+
".new", QSettings::IniFormat);
799 QFile::remove(docPath+
".bak");
800 QFile::rename(docPath, docPath+
".bak");
801 QFile::rename(docPath+
".new", docPath);
860 QDir dir(get_ExperimentDirectory());
862 return dir.filePath(get_ExperimentFileName());
876 win -> updateTitle();
881 printMessage(tr(
" experimentDirectory: %1").arg(get_ExperimentDirectory()));
882 printMessage(tr(
" experimentFileName: %1").arg(get_ExperimentFileName()));
883 printMessage(tr(
" experimentName: %1").arg(get_ExperimentName()));
884 printMessage(tr(
" logFilePath: %1").arg(get_LogFileName()));
885 printMessage(tr(
" scanFilePath: %1").arg(get_ScanFileName()));
894 QDir dir(get_ExperimentDirectory());
896 return dir.filePath(get_LogFileName());
901 QDir dir(get_ExperimentDirectory());
903 return dir.filePath(get_ScanFileName());
922 printMessage(tr(
"Save experiment copy as %1").arg(path));
939 int completed = get_WorkCompleted();
940 int target = get_WorkTarget();
943 set_CompletionPercentage(100.0*completed/target);
945 set_CompletionPercentage(0);
951 prop_WorkCompleted()->incValue(amt);
956 prop_WorkTarget()->incValue(amt);
961 prop_WorkCompleted()->incValue(-amt);
962 prop_WorkTarget()->incValue(-amt);
967 printf(
"About to dump\n");
975 QColor res = QColorDialog::getColor(start);
982 foreach(QString file, files) {
994 eng->loadScript(path);
QxrdCenterFinderWPtr centerFinder() const
QSharedPointer< QxrdWindow > QxrdWindowPtr
void commenceWork(int amt)
QSharedPointer< QxrdServer > QxrdServerPtr
QxrdCalibrantLibraryWPtr calibrantLibrary() const
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
QWeakPointer< QxrdSimpleServerThread > QxrdSimpleServerThreadWPtr
qint64 qcepDebug(int cond)
QScriptEngineDebugger * m_ScriptEngineDebugger
QString defaultScanName(QString path) const
QcepSettingsSaverPtr m_SettingsSaver
void statusMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void executeCommand(QString cmd)
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
void openNewLogFile() const
QSharedPointer< QxrdCalibrantLibraryModel > QxrdCalibrantLibraryModelPtr
virtual void readSettings(QSettings *set, QString section)
QWeakPointer< QxrdCenterFinder > QxrdCenterFinderWPtr
QxrdFileSaverThreadPtr m_FileSaverThread
void readInitialLogFile()
QSharedPointer< QxrdWindowSettings > QxrdWindowSettingsPtr
void evaluateSimpleServerCommand(QString cmd)
QSharedPointer< QxrdCalibrantLibrary > QxrdCalibrantLibraryPtr
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
void finishedCommand(QScriptValue result)
void initialize(QSettings *settings)
QSharedPointer< QxrdScriptEngine > QxrdScriptEnginePtr
QcepDatasetModelPtr m_DatasetModel
void evaluateSpecCommand(QString cmd)
QxrdCalibrantLibraryModelWPtr calibrantLibraryModel() const
void evaluateScriptFiles(QStringList files)
QSharedPointer< QxrdSimpleServer > QxrdSimpleServerPtr
QWeakPointer< QxrdApplication > QxrdApplicationWPtr
QString experimentFilePath() const
QxrdFileSaverWPtr fileSaver() const
void executeCommand(QString cmd)
void executeCommand(QString cmd)
virtual ~QxrdExperiment()
QString scanFilePath() const
QWeakPointer< QxrdCalibrantDSpacings > QxrdCalibrantDSpacingsWPtr
QxrdCalibrantLibraryPtr m_CalibrantLibrary
QSharedPointer< QxrdCalibrantDSpacingsModel > QxrdCalibrantDSpacingsModelPtr
void newScanFile(QString path)
void newLogFile(QString path)
QxrdDataProcessorPtr m_DataProcessor
QSharedPointer< QxrdSimpleServerThread > QxrdSimpleServerThreadPtr
QxrdAcquisitionPtr m_Acquisition
QWeakPointer< QxrdSimpleServer > QxrdSimpleServerWPtr
QxrdServerThreadWPtr specServerThread()
QString defaultExperimentDirectory(QString path) const
QWeakPointer< QxrdCalibrantLibraryModel > QxrdCalibrantLibraryModelWPtr
QxrdAcquisitionWPtr acquisition() const
QString defaultExperimentFileName(QString path) const
QxrdScriptEnginePtr m_ScriptEngine
QString defaultDataDirectory(QString path) const
void printLine(QString msg)
QxrdSimpleServerWPtr simpleServer()
QString defaultLogName(QString path) const
QWeakPointer< QxrdFileSaver > QxrdFileSaverWPtr
QWeakPointer< QxrdExperimentThread > QxrdExperimentThreadWPtr
QWeakPointer< QxrdCalibrantDSpacingsModel > QxrdCalibrantDSpacingsModelWPtr
QxrdSimpleServerWPtr m_SimpleServer
void saveExperimentCopyAs(QString path)
QSharedPointer< QxrdCalibrantDSpacings > QxrdCalibrantDSpacingsPtr
QString defaultExperimentName(QString path) const
QxrdSimpleServerThreadPtr m_SimpleServerThread
QxrdApplicationWPtr m_Application
QxrdExperimentThreadWPtr experimentThread()
void completeWork(int amt)
QxrdServerWPtr specServer()
QxrdCalibrantDSpacingsPtr m_CalibrantDSpacings
QWeakPointer< QxrdCalibrantLibrary > QxrdCalibrantLibraryWPtr
QxrdIntegratorWPtr integrator() const
QxrdWindowSettingsPtr m_WindowSettings
QcepDatasetModelPtr dataset()
void appResultAvailable(QScriptValue res)
QWeakPointer< QxrdServer > QxrdServerWPtr
void evaluateAppCommand(QString cmd)
QString logFilePath() const
void finishedCommand(QScriptValue result)
QxrdExperiment(QxrdExperimentThreadWPtr expthrd, QString path, QxrdApplicationWPtr app)
QSharedPointer< QxrdServerThread > QxrdServerThreadPtr
QMutex m_ExperimentFileMutex
void saveExperimentAs(QString path)
QWeakPointer< QxrdIntegrator > QxrdIntegratorWPtr
QxrdCalibrantDSpacingsModelWPtr calibrantDSpacingsModel() const
void logMessage(QString msg) const
virtual void writeSettings(QSettings *set, QString section)
void updateCompletionPercentage(int, int)
QWeakPointer< QxrdServerThread > QxrdServerThreadWPtr
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QWeakPointer< QxrdScriptEngine > QxrdScriptEngineWPtr
QxrdServerThreadPtr m_ServerThread
QSharedPointer< QxrdFileSaver > QxrdFileSaverPtr
QString systemCommand(QString cmd)
QSharedPointer< QcepDataset > QcepDatasetPtr
void simpleServerResultAvailable(QScriptValue cmd)
void criticalMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
QSharedPointer< QxrdFileSaverThread > QxrdFileSaverThreadPtr
QxrdCalibrantDSpacingsWPtr calibrantDSpacings() const
QxrdScriptEngineWPtr scriptEngine()
void finishedWork(int amt)
QxrdCalibrantDSpacingsModelPtr m_CalibrantDSpacingsModel
void evaluateScriptFile(QString path)
void setExperimentFilePath(QString path)
QxrdDataProcessorWPtr dataProcessor() const
void valueChanged(int val, int index)
QSharedPointer< QxrdApplication > QxrdApplicationPtr
QSharedPointer< QcepDatasetModel > QcepDatasetModelPtr
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime()) const
void splashMessage(QString msg)
QxrdCalibrantLibraryModelPtr m_CalibrantLibraryModel
void closeLogFile() const
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QColor pickColor(QColor start=QColor(Qt::white))
QxrdSimpleServerThreadWPtr simpleServerThread()
QxrdFileSaverWPtr m_FileSaver
void specResultAvailable(QScriptValue cmd)
QxrdExperimentThreadWPtr m_ExperimentThread