QXRD  0.11.16
qxrdscriptengine.cpp
Go to the documentation of this file.
1 #include "qxrddebug.h"
2 #include "qxrdscriptengine.h"
3 
4 #include "qxrdapplication.h"
5 #include "qxrdwindow.h"
6 #include "qxrdexperiment.h"
7 #include "qxrdacquisition.h"
8 #include "qxrdcenterfinder.h"
9 #include "qxrddataprocessor.h"
10 #include "qxrdcalibrantlibrary.h"
11 #include "qxrdcalibrant.h"
12 #include "qxrdintegrator.h"
13 #include "qcepmutexlocker.h"
14 #include "qxrdgeneratetestimage.h"
18 #include "qcepallocator.h"
19 #include "qxrdserver.h"
20 #include "qxrdsimpleserver.h"
22 #include "qcepdatagroup.h"
23 #include "qcepdatagroup-ptr.h"
24 #include "qcepdataarray.h"
25 #include "qcepdataarray-ptr.h"
26 #include "qcepdatacolumn.h"
27 #include "qcepdatacolumn-ptr.h"
28 #include "qcepdatacolumnscan.h"
29 #include "qcepdatacolumnscan-ptr.h"
30 #include "qcepdatasetmodel.h"
31 #include "qxrddetectorprocessor.h"
32 #include "qxrdroicalculator.h"
33 #include "qxrdroicoordinates.h"
35 
36 #include <QThread>
37 #include <QDir>
38 #include <QScriptValueIterator>
39 #include <QMetaObject>
40 #include <QMetaProperty>
41 #include <QRegExp>
42 
44  : QcepScriptEngine(),
45  m_Mutex(QMutex::Recursive),
46  m_Application(app),
47  m_Experiment(exp),
48  m_Acquisition(),
50  m_Window(),
51  m_ScriptOutput(NULL)
52 {
54  printf("QxrdScriptEngine::QxrdScriptEngine(%p)\n", this);
55  }
56 }
57 
59 {
61  printf("QxrdScriptEngine::~QxrdScriptEngine(%p)\n", this);
62  }
63 
64  if (m_ScriptOutput) {
65  fclose(m_ScriptOutput);
66  }
67 }
68 
70 {
71  return m_Application;
72 }
73 
75 {
76  return m_Experiment;
77 }
78 
80 {
81  return m_Acquisition;
82 }
83 
85 {
86  return m_Window;
87 }
88 
90 {
91  return m_DataProcessor;
92 }
93 
95 {
96  m_Window = win;
97 
99 
100  if (w) {
101  QCEP_DOC_OBJECT("window", "The Experiment Main Window");
102  globalObject().setProperty("window", newQObject(w.data()));
103 
104  QCEP_DOC_OBJECT("imageGraph", "The Image Plot in the Main Experiment Window");
105  globalObject().setProperty("imageGraph", newQObject(w->m_ImagePlot));
106 
107  QCEP_DOC_OBJECT("centeringGraph", "The Center Finder Plot");
108  globalObject().setProperty("centeringGraph", newQObject(w->m_CenterFinderPlot));
109 
110  QCEP_DOC_OBJECT("integratorGraph", "The Integrated Data Plot");
111  globalObject().setProperty("integratorGraph", newQObject(w->m_IntegratorPlot));
112  }
113 }
114 
116 {
117  m_Mutex.lock();
118 }
119 
121 {
122  m_Mutex.unlock();
123 }
124 
126 {
127  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
128 
129  // printf("QxrdScriptingEngine::evaluateAppCommand(%s)\n", qPrintable(expr));
130 
131  INVOKE_CHECK(QMetaObject::invokeMethod(this, "evaluateScript", Qt::QueuedConnection, Q_ARG(int, 0), Q_ARG(QString, expr)));
132 }
133 
135 {
136  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
137 
138  // printf("QxrdScriptingEngine::evaluateServerCommand(%s)\n", qPrintable(expr));
139 
140  INVOKE_CHECK(QMetaObject::invokeMethod(this, "evaluateScript", Qt::QueuedConnection, Q_ARG(int, 1), Q_ARG(QString, expr)));
141 }
142 
144 {
145  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
146 
147  // printf("QxrdScriptingEngine::evaluateSpecCommand(%s)\n", qPrintable(expr));
148 
149  INVOKE_CHECK(QMetaObject::invokeMethod(this, "evaluateScript", Qt::QueuedConnection, Q_ARG(int, 2), Q_ARG(QString, expr)));
150 }
151 
153 {
154  if (QThread::currentThread() != thread()) {
155  INVOKE_CHECK(QMetaObject::invokeMethod(this, "loadScript", Qt::QueuedConnection, Q_ARG(QString, path)));
156  } else {
157  QFile scriptFile(path);
158 
159  if (scriptFile.open(QFile::ReadOnly)) {
160  QTextStream scriptStream(&scriptFile);
161  QString script = scriptStream.readAll();
162 
163  QScriptValue res = QScriptEngine::evaluate(script, path);
164 
166 
167  if (expt) {
168  if (hasUncaughtException()) {
169  expt->printLine(tr("Script error, file %1, line %2 : %3")
170  .arg(path).arg(uncaughtExceptionLineNumber()).arg(uncaughtExceptionString()));
171 
172  QStringList bt = uncaughtExceptionBacktrace();
173 
174  foreach (QString s, bt) {
175  expt->printLine(s);
176  }
177  } else {
178  expt->printLine(tr("= %1").arg(res.toString()));
179  }
180  }
181  }
182  }
183 }
184 
185 QString QxrdScriptEngine::convertToString(QScriptValue result)
186 {
187  if (result.isError()) {
188  return "ERROR : "+result.property("error").toString();
189  } else if (result.isArray()) {
190  int len = result.property("length").toInteger();
191 
192  QString s = "[";
193 
194  for (int i=0; i<len; i++) {
195  s += convertToString(result.property(tr("%1").arg(i)));
196 
197  if (i<len-1) {
198  s += ", ";
199  }
200  }
201 
202  s += "]";
203 
204  return s;
205 
206  } else if (result.isObject()) {
207  QScriptValueIterator it(result);
208 
209  QString s = "{";
210 
211  while(it.hasNext()) {
212  it.next();
213 
214  s += it.name()+":";
215  s += convertToString(it.value());
216 
217  if (it.hasNext()) {
218  s += ", ";
219  }
220  }
221 
222  s += "}";
223 
224  return s;
225 
226  } else {
227  return result.toString();
228  }
229 }
230 
231 void QxrdScriptEngine::evaluateScript(int src, QString expr)
232 {
233  THREAD_CHECK;
234 
235  // printf("QxrdScriptingEngine::evaluateScript(%s)\n", qPrintable(expr));
236 
237  QScriptValue result = QScriptEngine::evaluate(expr);
238 
241 
242  if (exp) {
243  exp->printMessage(tr("Evaluate[%1] %2 = %3").arg(src).arg(expr).arg(result.toString()));
244  }
245  }
246 
247  switch (src) {
248  case 0:
249  emit appResultAvailable(result);
250  break;
251  case 1:
252  emit simpleServerResultAvailable(result);
253  break;
254  case 2:
255  emit specResultAvailable(result);
256  break;
257  }
258 }
259 
261 {
262  abortEvaluation();
263 }
264 
266 {
267  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
268 
269  return QScriptEngine::hasUncaughtException();
270 }
271 
273 {
274  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
275 
276  return QScriptEngine::uncaughtExceptionLineNumber();
277 }
278 
280 {
281  QcepMutexLocker lock(__FILE__, __LINE__, &m_Mutex);
282 
283  return uncaughtException().toString();
284 }
285 
287  "print",
288  "print([value]...)",
289  "Print values to the log file and message window",
290  "<p>The values of the arguments are catenated into a single string which is "
291  "printed to the log file and to the message window</p>\n"
292  "<p>The following is a typical use: print out the names and values of the "
293  "elements of an object:</p>\n"
294  "<code>"
295  "for(i in acquisition) print(i, acquisition[i])"
296  "</code>"
297  )
298 
299 QScriptValue QxrdScriptEngine::printFunc(QScriptContext *context, QScriptEngine *engine, void * /*u*/)
300 {
301  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
302 
303  if (eng) {
304  int nArgs = context->argumentCount();
305  QString msg;
306 
307  for (int i=0; i<nArgs; i++) {
308  if (i != 0) {
309  msg += " ";
310  }
311 
312  msg += context -> argument(i).toString();
313  }
314 
315  QxrdExperimentPtr expt(eng->experiment());
316 
317  if (expt) {
318  expt->printLine(msg);
319  }
320  }
321 
322  return QScriptValue(engine, 1);
323 }
324 
326  "fopen",
327  "fopen(fileName)",
328  "Open a script output file",
329  "<p>The fileName given is opened as the current output file ussed by fprint</p>\n"
330  "<p>Only one script output file may be open at a time</p>\n"
331  )
332 
333 QScriptValue QxrdScriptEngine::fopenFunc(QScriptContext *context, QScriptEngine *engine, void * /*u*/)
334 {
335  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
336 
337  if (eng) {
338  int nArgs = context->argumentCount();
339 
340  if (nArgs >= 1) {
341  eng -> openScriptOutput(context -> argument(0).toString());
342  }
343  }
344 
345  return QScriptValue(engine, 1);
346 }
347 
349  "fprint",
350  "fprint([value]...)",
351  "Print values to the script output file",
352  "<p>The values of the arguments are catenated into a single string which is "
353  "printed to the script output file</p>\n"
354  "<p>The following is a typical use: print out the names and values of the "
355  "elements of an object:</p>\n"
356  "<code>"
357  "for(i in acquisition) fprint(i, acquisition[i])"
358  "</code>"
359  )
360 
361 QScriptValue QxrdScriptEngine::fprintFunc(QScriptContext *context, QScriptEngine *engine, void * /*u*/)
362 {
363  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
364 
365  if (eng) {
366  int nArgs = context->argumentCount();
367  QString msg;
368 
369  for (int i=0; i<nArgs; i++) {
370  if (i != 0) {
371  msg += " ";
372  }
373 
374  msg += context -> argument(i).toString();
375  }
376 
377  eng -> writeScriptOutput(msg);
378  }
379 
380  return QScriptValue(engine, 1);
381 }
382 
384  "fclose",
385  "fclose()",
386  "Closes the script output file",
387  "<p>Note that only one script output file may be open at a time</p>\n"
388  )
389 
390 QScriptValue QxrdScriptEngine::fcloseFunc(QScriptContext * /*context*/, QScriptEngine *engine, void * /*u*/)
391 {
392  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
393 
394  if (eng) {
395  eng -> closeScriptOutput();
396  }
397 
398  return QScriptValue(engine, 1);
399 }
400 
402  "fdelete",
403  "fdelete(path)",
404  "Deletes a file",
405  "<p>If the file does not exist no error occurs</p>"
406  )
407 
408 QScriptValue QxrdScriptEngine::fdeleteFunc(QScriptContext * context, QScriptEngine *engine, void * /*u*/)
409 {
410  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
411 
412  bool res = false;
413 
414  if (eng) {
415  QString path = context -> argument(0).toString();
416 
417  if (path.length() > 0) {
418  res = QFile::remove(path);
419  }
420  }
421 
422  return QScriptValue(engine, res);
423 }
424 
426  "acquire",
427 
428  "acquire([fileName[, exposure[, summedExposures[, postTriggerFiles[, preTriggerFiles[, nPhases]]]]]])",
429  "Start acquisition of a sequence of images",
430 
431  "<p>The arguments are optional and may be successively omitted from the "
432  "right. If <i>preTriggerFiles</i> is omitted, zero is used instead. "
433  "If <i>nPhases</i> is omitted, one is used. "
434  "Any other argument which is omitted will take its value "
435  "instead from the values entered in the acquire dialog. Any "
436  "argument which is given will replace the corresponding value "
437  "in the acquire dialog.</p>\n"
438  "<p>Note that the script function merely starts the acquisition "
439  "- you should use the separate \"status\" function to wait for "
440  "acquisition and processing to be completed.</p>\n"
441  "<p>The following is a typical example of the use of this "
442  "command from spec:</p>\n"
443  "<code>"
444  "def PEexp(filename,exposure,subframes,frames) '{<br/>"
445  "&nbsp;&nbsp;remote_eval(PEHOST,"
446  "sprintf(\"acquire(\\\"%s\\\",%g,%d,%d,0)\",filename,exposure,subframes,frames));<br/>"
447  "&nbsp;&nbsp;<br/> &nbsp;&nbsp;PEwait()<br/> }'<br/>"
448  "</code>"
449  )
450 
451 QScriptValue QxrdScriptEngine::acquireFunc(QScriptContext *context, QScriptEngine *engine)
452 {
453  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
454 
455  if (eng) {
456  QxrdAcquisitionPtr acq(eng->acquisition());
457 
458  if (!acq) return QScriptValue(engine, -1);
459 
460  int nArgs = context->argumentCount();
461 
462  if (nArgs < 6) {
463  acq -> set_PhasesInGroup(1);
464  }
465 
466  if (nArgs < 5) {
467  acq -> set_PreTriggerFiles(0);
468  }
469 
470  switch (nArgs) {
471  default:
472 
473  case 6:
474  acq -> set_PhasesInGroup(context -> argument(5).toUInt32());
475 
476  case 5:
477  acq -> set_PreTriggerFiles(context -> argument(4).toUInt32());
478 
479  case 4:
480  acq -> set_PostTriggerFiles(context -> argument(3).toUInt32());
481 
482  case 3:
483  acq -> set_SummedExposures(context -> argument(2).toUInt32());
484 
485  case 2:
486  acq -> set_ExposureTime(context -> argument(1).toNumber());
487 
488  case 1:
489  acq -> set_FilePattern(context -> argument(0).toString());
490 
491  case 0:
492  acq->acquire();
493  }
494  }
495 
496  return QScriptValue(engine, 1);
497 }
498 
500  "acquireDark",
501  "acquireDark([filename [,exposure [,darkSummedExposures]]])",
502  "Start acquisition of a dark image",
503  "<p>Arguments are optional and, if given, will replace the "
504  "corresponding value in the acquire dialog, if not given the "
505  "dialog values are used.</p>\n"
506  "<p>The following is a typical example of the use of this "
507  "command from spec:</p>\n"
508  "<code>\n"
509  "def PEexpd(filename, exposure, subframes) '{<br/>\n"
510  "&nbsp;&nbsp;remote_eval(PEHOST,"
511  "sprintf(\"acquireDark(\\\"%s\\\",%g,%d)\",filename,exposure,subframes));<br/>\n"
512  "&nbsp;&nbsp;<br/> &nbsp;&nbsp;PEwait()<br/> }'<br/>\n"
513  "</code>\n"
514  )
515 
516 QScriptValue QxrdScriptEngine::acquireDarkFunc(QScriptContext *context, QScriptEngine *engine)
517 {
518  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
519 
520  if (eng) {
521  QxrdAcquisitionPtr acq(eng->acquisition());
522 
523  if (!acq) return QScriptValue(engine, -1);
524 
525  int nArgs = context->argumentCount();
526 
527  switch (nArgs) {
528  default:
529  case 3:
530  acq -> set_DarkSummedExposures(context -> argument(2).toUInt32());
531 
532  case 2:
533  acq -> set_ExposureTime(context -> argument(1).toNumber());
534 
535  case 1:
536  acq -> set_FilePattern(context -> argument(0).toString());
537 
538  case 0:
539  acq -> acquireDark();
540  }
541  }
542 
543  return QScriptValue(engine, 1);
544 }
545 
547  "status",
548  "status([time])",
549  "Test if acquisition and processing have finished",
550  "<p>"
551  "If the argument is given the function will wait up to that "
552  "many seconds - if acquisition and processing finish before "
553  "the time elapsed then <code>status</code> will return at "
554  "that time, otherwise at the end of the timeout period. The "
555  "function returns a non-zero result if acquisition and "
556  "processing are complete, or zero if they are not."
557  "</p>\n"
558  "<p>"
559  "If no argument is given the function tests if acquisition "
560  "and processing are complete and returns the result of the "
561  "test immediately."
562  "</p>\n"
563  "<p>"
564  "The following is a typical use of this command from spec:"
565  "</p>\n"
566  "<code>"
567  "def PEwait() '{<br/>"
568  "&nbsp;&nbsp;while(remote_eval(PEHOST,\"status(1.0)\")==0) {<br/>"
569  "&nbsp;&nbsp;}<br/> }'<br/>"
570  "</code>\n"
571  )
572 
573 QScriptValue QxrdScriptEngine::statusFunc(QScriptContext *context, QScriptEngine *engine)
574 {
575  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
576 
577  if (eng) {
578  QxrdAcquisitionPtr acq(eng->acquisition());
579  QxrdDataProcessorPtr proc(eng->dataProcessor());
580 
581  if (!acq || !proc) return QScriptValue(engine, -1);
582 
583  double time=0;
584  int status=0;
585 
586  if (context->argumentCount() > 0) {
587  time = context->argument(0).toNumber();
588  }
589 
590  status = acq -> acquisitionStatus(time);
591 
592  if (status == 1) {
593  status = proc -> status(time);
594  }
595 
596  return QScriptValue(engine, status);
597  } else {
598  return QScriptValue(engine, -1);
599  }
600 }
601 
603  "acquireStatus",
604  "acquireStatus([time])",
605  "Test if acquisition has finished",
606  "<p>"
607  "Similar to 'status' "
608  "except that it only tests for the acquisition operation being complete."
609  "</p>"
610  )
611 
612 QScriptValue QxrdScriptEngine::acquireStatusFunc(QScriptContext *context, QScriptEngine *engine)
613 {
614  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
615 
616  if (eng) {
617  QxrdAcquisitionPtr acq(eng->acquisition());
618 
619  if (acq) {
620  if (context->argumentCount() == 0) {
621  return QScriptValue(engine, acq -> acquisitionStatus(0));
622  } else {
623  double time = context->argument(0).toNumber();
624  return QScriptValue(engine, acq -> acquisitionStatus(time));
625  }
626  }
627  }
628 
629  return QScriptValue(engine, -1);
630 }
631 
633  "processStatus",
634  "processStatus([time])",
635  "Test if processing has finished",
636  "<p>"
637  "Similar to 'status' "
638  "except that it only tests for the processing operation being complete."
639  "</p>"
640  )
641 
642 QScriptValue QxrdScriptEngine::processStatusFunc(QScriptContext *context, QScriptEngine *engine)
643 {
644  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
645 
646  if (eng) {
647  QxrdDataProcessorPtr proc(eng->dataProcessor());
648 
649  if (proc) {
650  if (context->argumentCount() == 0) {
651  return QScriptValue(engine, proc -> status(0));
652  } else {
653  double time = context->argument(0).toNumber();
654  return QScriptValue(engine, proc -> status(time));
655  }
656  }
657  }
658 
659  return QScriptValue(engine, -1);
660 }
661 
663  "acquireCancel",
664  "acquireCancel()",
665  "Cancel the current acquisition operation",
666  ""
667  )
668 
669 QScriptValue QxrdScriptEngine::acquireCancelFunc(QScriptContext * /*context*/, QScriptEngine *engine)
670 {
671  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
672 
673  if (eng) {
674  QxrdAcquisitionPtr acq(eng->acquisition());
675 
676  if (acq) {
677  acq -> cancel();
678 
679  return QScriptValue(engine, 1);
680  }
681  }
682 
683  return QScriptValue(engine, -1);
684 }
685 
687  "acquireScalers",
688  "vals <- acquireScalers()",
689  "Returns the scaler counts values for the latest acquisition operation",
690  "")
691 
692 QScriptValue QxrdScriptEngine::acquireScalersFunc(QScriptContext *context, QScriptEngine *engine)
693 {
694  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
695 
696  if (eng) {
697  QxrdAcquisitionPtr acq(eng->acquisition());
698 
699  if (acq) {
700  int i = context->argument(0).toInteger();
701 
702  return QScriptValue(eng, acq->scalerValue(i));
703  }
704  }
705 
706  return QScriptValue();
707 }
708 
710  "trigger",
711  "trigger()",
712  "Trigger triggered acquisition",
713  "<p>If 'preTriggerFiles' is greater than zero then acquisition operations proceed in the "
714  "'triggered' mode. This acts much like a digital oscilloscope trigger where a certain number "
715  "('preTriggerFiles') of acquired images are held in the computer RAM until the trigger operation occurs "
716  "and then the most recent acquired images are written to disk, along with a number of post-trigger images</p>"
717  )
718 
719 QScriptValue QxrdScriptEngine::triggerFunc(QScriptContext * /*context*/, QScriptEngine *engine)
720 {
721  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
722 
723  if (eng) {
724  QxrdAcquisitionPtr acq(eng->acquisition());
725 
726  if (acq) {
727  acq -> trigger();
728 
729  return QScriptValue(engine, 1);
730  }
731  }
732 
733  return QScriptValue(engine, -1);
734 }
735 
737  "exposureTime",
738  "exposureTime([time])",
739  "Get or set the acquisition exposure time (also for dark exposures)",
740  "<p>If the time argument is given, set the exposure time, otherwise return the "
741  "current exposure time</p>"
742  "<p>This function provides a convenient method to access the "
743  "<code>acquisition.exposureTime</code> property</p>"
744  )
745 
746 QScriptValue QxrdScriptEngine::exposureTimeFunc(QScriptContext *context, QScriptEngine *engine)
747 {
748  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
749 
750  if (eng) {
751  QxrdAcquisitionPtr acq(eng->acquisition());
752 
753  if (acq) {
754  if (context->argumentCount() != 0) {
755  acq -> set_ExposureTime(context->argument(0).toNumber());
756  }
757 
758  return QScriptValue(engine, acq -> get_ExposureTime());
759  }
760  }
761 
762  return QScriptValue(engine, -1);
763 }
764 
766  "summedExposures",
767  "summedExposures([n])",
768  "Get or set the number of summed exposures for acquisition",
769  "<p>If the n argument is given, set the number of summed exposures, otherwise return the "
770  "current value.</p>"
771  "<p>Easy access to <code>acquisition.summedExposures</code></p>"
772  )
773 
774 QScriptValue QxrdScriptEngine::summedExposuresFunc(QScriptContext *context, QScriptEngine *engine)
775 {
776  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
777 
778  if (eng) {
779  QxrdAcquisitionPtr acq(eng->acquisition());
780 
781  if (acq) {
782  if (context->argumentCount() != 0) {
783  acq -> set_SummedExposures(context->argument(0).toUInt32());
784  }
785 
786  return QScriptValue(engine, acq -> get_SummedExposures());
787  }
788  }
789 
790  return QScriptValue(engine, -1);
791 }
792 
794  "skippedExposures",
795  "skippedExposures([n])",
796  "Get or set the number of skipped exposures for acquisition",
797  "<p>If the n argument is given, set the number of skipped exposures, otherwise return the "
798  "current value.</p>"
799  "<p>Easy access to <code>acquisition.skippedExposures</code></p>"
800  )
801 
802 QScriptValue QxrdScriptEngine::skippedExposuresFunc(QScriptContext *context, QScriptEngine *engine)
803 {
804  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
805 
806  if (eng) {
807  QxrdAcquisitionPtr acq(eng->acquisition());
808 
809  if (acq) {
810  if (context->argumentCount() != 0) {
811  acq -> set_SkippedExposures(context->argument(0).toUInt32());
812  }
813 
814  return QScriptValue(engine, acq -> get_SkippedExposures());
815  }
816  }
817 
818  return QScriptValue(engine, -1);
819 }
820 
822  "darkSummedExposures",
823  "darkSummedExposures([n])",
824  "Get or set the number of summed exposures for dark acquisition",
825  "<p>If the n argument is given, set the number of summed exposures, otherwise return the "
826  "current value.</p>"
827  "<p>Easy access to <code>acquisition.darkSummedExposures</code></p>"
828  )
829 
830 QScriptValue QxrdScriptEngine::darkSummedExposuresFunc(QScriptContext *context, QScriptEngine *engine)
831 {
832  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
833 
834  if (eng) {
835  QxrdAcquisitionPtr acq(eng->acquisition());
836 
837  if (acq) {
838  if (context->argumentCount() != 0) {
839  acq -> set_DarkSummedExposures(context->argument(0).toUInt32());
840  }
841 
842  return QScriptValue(engine, acq -> get_DarkSummedExposures());
843  }
844  }
845 
846  return QScriptValue(engine, -1);
847 }
848 
850  "phasesInGroup",
851  "phasesInGroup([n])",
852  "Get or set the number of phases for synchronized acquisition",
853  "<p>If the n argument is given, set the number of phases, otherwise return the "
854  "current value.</p>"
855  "<p>Easy access to <code>acquisition.phasesInGroup</code></p>"
856  )
857 
858 QScriptValue QxrdScriptEngine::phasesInGroupFunc(QScriptContext *context, QScriptEngine *engine)
859 {
860  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
861 
862  if (eng) {
863  QxrdAcquisitionPtr acq(eng->acquisition());
864 
865  if (acq) {
866  if (context->argumentCount() != 0) {
867  acq -> set_PhasesInGroup(context->argument(0).toUInt32());
868  }
869 
870  return QScriptValue(engine, acq -> get_PhasesInGroup());
871  }
872  }
873 
874  return QScriptValue(engine, -1);
875 }
876 
878  "preTriggerFiles",
879  "preTriggerFiles([n])",
880  "Get or set the number of pre-trigger file groups for triggered acquisition",
881  "<p>If the n argument is given, set the number of pre-trigger file groups, otherwise return the "
882  "current value.</p>"
883  "<p>Easy access to <code>acquisition.preTriggerFiles</code></p>"
884  )
885 
886 QScriptValue QxrdScriptEngine::preTriggerFilesFunc(QScriptContext *context, QScriptEngine *engine)
887 {
888  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
889 
890  if (eng) {
891  QxrdAcquisitionPtr acq(eng->acquisition());
892 
893  if (acq) {
894  if (context->argumentCount() != 0) {
895  acq -> set_PreTriggerFiles(context->argument(0).toUInt32());
896  }
897 
898  return QScriptValue(engine, acq -> get_PreTriggerFiles());
899  }
900  }
901 
902  return QScriptValue(engine, -1);
903 }
904 
906  "postTriggerFiles",
907  "postTriggerFiles([n])",
908  "Get or set the number of post-trigger file groups for triggered acquisition",
909  "<p>If the n argument is given, set the number of post-trigger file groups, otherwise return the "
910  "current value.</p>"
911  "<p>Easy access to <code>acquisition.postTriggerFiles</code></p>"
912  )
913 
914 QScriptValue QxrdScriptEngine::postTriggerFilesFunc(QScriptContext *context, QScriptEngine *engine)
915 {
916  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
917 
918  if (eng) {
919  QxrdAcquisitionPtr acq(eng->acquisition());
920 
921  if (acq) {
922  if (context->argumentCount() != 0) {
923  acq -> set_PostTriggerFiles(context->argument(0).toUInt32());
924  }
925 
926  return QScriptValue(engine, acq -> get_PostTriggerFiles());
927  }
928  }
929 
930  return QScriptValue(engine, -1);
931 }
932 
934  "filePattern",
935  "filePattern([pattern])",
936  "Get or set the acquisition file name pattern",
937  "<p>If the pattern argument is given, set the file name pattern, otherwise return the "
938  "current value.</p>"
939  "<p>Easy access to <code>acquisition.filePattern</code></p>"
940  )
941 
942 QScriptValue QxrdScriptEngine::filePatternFunc(QScriptContext *context, QScriptEngine *engine)
943 {
944  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
945 
946  if (eng) {
947  QxrdAcquisitionPtr acq(eng->acquisition());
948 
949  if (acq) {
950  if (context->argumentCount() != 0) {
951  acq -> set_FilePattern(context->argument(0).toString());
952  }
953 
954  return QScriptValue(engine, acq -> get_FilePattern());
955  }
956  }
957 
958  return QScriptValue(engine, -1);
959 }
960 
962  "outputDirectory",
963  "outputDirectory([dir])",
964  "Get or set the acquisition output directory",
965  "<p>If the dir argument is given, set the output directory, otherwise return the "
966  "current value.</p>"
967  "<p>Easy access to <code>experiment.dataDirectory</code></p>"
968  )
969 
970 QScriptValue QxrdScriptEngine::outputDirectoryFunc(QScriptContext *context, QScriptEngine *engine)
971 {
972  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
973 
974  if (eng) {
975  QxrdExperimentPtr doc(eng->experiment());
976 
977  if (doc) {
978  if (context->argumentCount() != 0) {
979  doc -> set_DataDirectory(context->argument(0).toString());
980  }
981 
982  return QScriptValue(engine, doc -> get_DataDirectory());
983  }
984  }
985 
986  return QScriptValue(engine, -1);
987 }
988 
990  "fileIndex",
991  "fileIndex([n])",
992  "Get or set the acquisition file index",
993  "<p>If the n argument is given, set the file index, otherwise return the "
994  "current value.</p>"
995  "<p>Easy access to <code>acquisition.fileIndex</code></p>"
996  )
997 
998 QScriptValue QxrdScriptEngine::fileIndexFunc(QScriptContext *context, QScriptEngine *engine)
999 {
1000  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1001 
1002  if (eng) {
1003  QxrdAcquisitionPtr acq(eng->acquisition());
1004 
1005  if (acq) {
1006  if (context->argumentCount() != 0) {
1007  acq -> set_FileIndex(context->argument(0).toUInt32());
1008  }
1009 
1010  return QScriptValue(engine, acq -> get_FileIndex());
1011  }
1012  }
1013 
1014  return QScriptValue(engine, -1);
1015 }
1016 
1018  "data",
1019  "data()",
1020  "Get the current image",
1021  "<p>Returns a reference to the most recently acquired or most recently loaded image.</p>"
1022  "<p>The returned object can have its properties queried.</p>"
1023  "<p>Note that the value returned by this function will change as each "
1024  "new image is acquired so be careful if calling this function during acquisition.</p>"
1025  )
1026 
1027 QScriptValue QxrdScriptEngine::dataFunc(QScriptContext * /*context*/, QScriptEngine *engine)
1028 {
1029  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1030 
1031  if (eng) {
1032  QxrdDataProcessorPtr proc(eng->dataProcessor());
1033 
1034  if (proc) {
1035  return engine -> newQObject(proc -> data().data(),QtOwnership, QScriptEngine::AutoCreateDynamicProperties);
1036  }
1037  }
1038 
1039  return QScriptValue(engine, -1);
1040 }
1041 
1043  "dark",
1044  "dark()",
1045  "Get the dark image (or null if none has been taken)",
1046  "<p>Returns a reference to the current dark image.</p>"
1047  "<p>The returned object can have its properties queried.</p>"
1048  "<p>For example, to get the file name of the dark image:</p>"
1049  "<code>print(dark().fileName)</code>"
1050  "<p>Or to show a list of properties of the dark image:</p>"
1051  "<code>for(i in dark()) print(i, dark()[i])</code>"
1052  )
1053 
1054 QScriptValue QxrdScriptEngine::darkFunc(QScriptContext * /*context*/, QScriptEngine *engine)
1055 {
1056  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1057 
1058  if (eng) {
1059  QxrdDataProcessorPtr proc(eng->dataProcessor());
1060 
1061  if (proc) {
1062  return engine -> newQObject(proc -> darkImage().data(), QtOwnership, QScriptEngine::AutoCreateDynamicProperties);
1063  }
1064  }
1065 
1066  return QScriptValue(engine, -1);
1067 }
1068 
1070  "mask",
1071  "mask()",
1072  "Get the top item of the mask stack",
1073  "<p>Returns a reference to the top of the mask stack, or null if the "
1074  "mask stack is empty.</p>"
1075  )
1076 
1077 QScriptValue QxrdScriptEngine::maskFunc(QScriptContext * /*context*/, QScriptEngine *engine)
1078 {
1079  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1080 
1081  if (eng) {
1082  QxrdDataProcessorPtr proc(eng->dataProcessor());
1083 
1084  if (proc) {
1085  return engine -> newQObject(proc -> mask().data(), QtOwnership, QScriptEngine::AutoCreateDynamicProperties);
1086  }
1087  }
1088 
1089  return QScriptValue(engine, -1);
1090 }
1091 
1093  "overflow",
1094  "overflow()",
1095  "Get the overflow pixel map for acquired images",
1096  "<p>Returns the overflow pixels map for the most recently acquired image "
1097  "(if overflow processing is enabled)</p>\n"
1098  "<p>The overflow map is non-zero wherever an image pixel exceeded the overflow "
1099  "threshold during acquisition. Where more than one exposures are summed, the overflow "
1100  "map will count the number of exposures for which the pixel overflowed.</p>"
1101  )
1102 
1103 QScriptValue QxrdScriptEngine::overflowFunc(QScriptContext * /*context*/, QScriptEngine *engine)
1104 {
1105  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1106 
1107  if (eng) {
1108  QxrdDataProcessorPtr proc(eng->dataProcessor());
1109 
1110  if (proc) {
1111  return engine -> newQObject(proc -> overflow().data(), QtOwnership, QScriptEngine::AutoCreateDynamicProperties);
1112  }
1113  }
1114 
1115  return QScriptValue(engine, -1);
1116 }
1117 
1119  "liveData",
1120  "liveData()",
1121  "Get the current live view image",
1122  "<p>Returns a reference to the most recently acquired live view image.</p>"
1123  "<p>The returned object can have its properties queried.</p>"
1124  "<p>Note that the value returned by this function will change as each "
1125  "new live view image is acquired so be careful when calling this function.</p>"
1126  )
1127 
1128 QScriptValue QxrdScriptEngine::liveDataFunc(QScriptContext * /*context*/, QScriptEngine *engine)
1129 {
1130  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1131 
1132  if (eng) {
1133  QxrdDataProcessorPtr proc(eng->dataProcessor());
1134 
1135  if (proc) {
1136  return engine -> newQObject(proc -> liveData().data(), QtOwnership, QScriptEngine::AutoCreateDynamicProperties);
1137  }
1138  }
1139 
1140  return QScriptValue(engine, -1);
1141 }
1142 
1144  "help",
1145  "help([name...])",
1146  "Returns help text for a given name or names",
1147  "<p>Returns a string containing an html representation of the help text "
1148  "for a name or names. If more than one name is given the result is the "
1149  "concatenation of the help for each name in turn</p>"
1150  "<p>The names may contain wildcard characters, the result will contain help "
1151  "for all available matching the wildcard patterns.</p>"
1152  "<p>If no name is given the command returns help for the help command itself.</p>"
1153  "<p>If the command is executed in the QXRD script window the html result will "
1154  "be properly formatted in the message window.</p>"
1155  "<p>For example:</p>"
1156  "<code>help(\"help\")</code>"
1157  )
1158 
1159 QScriptValue QxrdScriptEngine::helpFunc(QScriptContext * context, QScriptEngine * engine)
1160 {
1161  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1162 
1163  if (eng) {
1164  int n=context->argumentCount();
1165  QString res="";
1166 
1167  if (n==0) {
1168  res = eng->documentationText("help");
1169  } else {
1170  for (int i=0; i<n; i++) {
1171  QString name = context->argument(i).toString();
1172 
1173  QRegExp re(name, Qt::CaseInsensitive, QRegExp::Wildcard);
1174 
1175  res.append(eng->documentationText(re));
1176  }
1177  }
1178 
1179  return QScriptValue(engine, res);
1180  } else {
1181  return QScriptValue(engine, QString());
1182  }
1183 }
1184 
1186  "extraChannel",
1187  "extraChannel(n)",
1188  "Access channels for extra inputs",
1189  "<p>Returns a reference to configuration data for an extra input channel.</p>"
1190  "<p>Example: to access the acquired waveform for extra channel 0</p>"
1191  "<code>extraChannel(0).waveform</code>"
1192  )
1193 
1194 QScriptValue QxrdScriptEngine::extraChannelFunc(QScriptContext *context, QScriptEngine *engine)
1195 {
1196  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1197 
1198  if (eng) {
1199  QxrdAcquisitionPtr acq(eng->acquisition());
1200 
1201  if (acq) {
1202  QxrdAcquisitionExtraInputsPtr xtra(acq->acquisitionExtraInputs());
1203 
1204  if (xtra) {
1205  if (context->argumentCount() != 0) {
1206  int channel = context->argument(0).toInteger();
1207 
1208  QxrdAcquisitionExtraInputsChannelPtr chan(xtra->channel(channel));
1209 
1210  return engine->newQObject(chan.data());
1211  }
1212  }
1213  }
1214  }
1215 
1216  return QScriptValue();
1217 }
1218 
1220  "process",
1221  "process(filename [, norm...])",
1222  "Load and process an image file",
1223  "<p>Load and process the file filename. The norm arguments are used as "
1224  "normalization values during processing</p>"
1225  "<p>The function is closely related to</p>"
1226  "<code>processor.processNormalizedFile(QString,QDoubleList)</code>"
1227  )
1228 
1229 QScriptValue QxrdScriptEngine::processFunc(QScriptContext *context, QScriptEngine *engine)
1230 {
1231  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1232 
1233  if (eng) {
1234  QxrdDataProcessorPtr proc(eng->dataProcessor());
1235 
1236  if (proc) {
1237  if (context->argumentCount() >= 1) {
1238  QString file = context->argument(0).toString();
1239  QList<double> normVals;
1240 
1241  for (int i=1; i<context->argumentCount(); i++) {
1242  normVals.append(context->argument(i).toNumber());
1243  }
1244 
1245  proc -> processNormalizedFile(file, normVals);
1246  }
1247 
1248  return QScriptValue(engine, 1);
1249  }
1250  }
1251 
1252  return QScriptValue(engine, -1);
1253 }
1254 
1256  "setFileNormalization",
1257  "setFileNormalization(filename [, norm...])",
1258  "Set the normalization values for an image file",
1259  "<p>Loads the file filename, sets its normalization values and "
1260  "rewrites the metadata file</p>"
1261  "<p>The function is closely related to</p>"
1262  "<code>processor.setFileNormalization(QString,QDoubleList)</code>"
1263  )
1264 
1265 QScriptValue QxrdScriptEngine::setFileNormalizationFunc(QScriptContext *context, QScriptEngine *engine)
1266 {
1267  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1268 
1269  if (eng) {
1270  QxrdDataProcessorPtr proc(eng->dataProcessor());
1271 
1272  if (proc) {
1273  if (context->argumentCount() >= 1) {
1274  QString file = context->argument(0).toString();
1275  QList<double> normVals;
1276 
1277  for (int i=1; i<context->argumentCount(); i++) {
1278  normVals.append(context->argument(i).toNumber());
1279  }
1280 
1281  proc -> setFileNormalization(file, normVals);
1282  }
1283 
1284  return QScriptValue(engine, 1);
1285  }
1286  }
1287 
1288  return QScriptValue(engine, -1);
1289 }
1290 
1292  "matchFiles",
1293  "matchFiles([pattern]...)",
1294  "Return a list of files matching a pattern",
1295  "<p>Returns a list of file names matching the provided pattern(s).</p>"
1296  "<p>The patterns support 'wild card' characters sush as * and ?.</p>"
1297  "<p>Example - to calculate the sum of the pixel intensity of pixel 100,100 in "
1298  "all the TIFF files in the current directory:</p>"
1299  "<code>var sum=0;<br/>\n"
1300  "for(f in matchFiles(\"*.tif\") {<br/>\n"
1301  "&nbsp;&nbsp;processor.loadData(f);<br/>\n"
1302  "&nbsp;&nbsp;sum += data().getImageData(100,100);<br/>\n"
1303  "}<br>"
1304  )
1305 
1306 QScriptValue QxrdScriptEngine::matchFilesFunc(QScriptContext *context, QScriptEngine *engine)
1307 {
1308  QStringList result;
1309 
1310  if (context->argumentCount() >= 1) {
1311  QString dir = context->argument(0).toString();
1312 
1313  if (context->argumentCount() == 1) {
1314  QDir a(dir);
1315  a.setFilter(QDir::Dirs | QDir::Files);
1316 
1317  result.append(a.entryList());
1318  } else {
1319  for (int i=1; i<context->argumentCount(); i++) {
1320  QString patt = context->argument(i).toString();
1321 
1322  // g_Application->printMessage(tr("Matching %1").arg(patt));
1323 
1324  QDir a(dir);
1325 
1326  a.setFilter(QDir::Dirs | QDir::Files);
1327  QStringList patts;
1328  patts<<patt;
1329 
1330  a.setNameFilters(patts);
1331 
1332  QStringList entries = a.entryList();
1333  // int nEntries = entries.length();
1334  // g_Application->printMessage(tr("Matched %1 entries").arg(nEntries));
1335 
1336  result.append(entries);
1337  }
1338  }
1339  }
1340 
1341  return engine->toScriptValue(result);
1342 }
1343 
1345  "mapUserFunction",
1346  "mapUserFunction(functionname)",
1347  "Map a user function over current data",
1348  ""
1349  )
1350 
1351 QScriptValue QxrdScriptEngine::mapUserFunctionFunc(QScriptContext *context, QScriptEngine *engine)
1352 {
1353  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1354 
1355  if (eng) {
1356  QxrdDataProcessorPtr proc(eng->dataProcessor());
1357 
1358  QcepDoubleImageDataPtr d = proc->data();
1359 
1360  if (d) {
1361  int ht = d->get_Height();
1362  int wd = d->get_Width();
1363 
1364  if (context->argumentCount() == 1) {
1365  QScriptValue func = context->argument(0);
1366 
1367  if (!func.isFunction()) {
1368  func = eng->globalObject().property(func.toString());
1369  }
1370 
1371  if (func.isFunction()) {
1372  for (int i=0; i<wd; i++) {
1373  for (int j=0; j<ht; j++) {
1374  d->setValue(i,j, func.call(QScriptValue(), QScriptValueList() << i << j).toNumber());
1375  }
1376  }
1377 
1378  proc->newData(d, QcepMaskDataPtr());
1379  }
1380  }
1381  }
1382  }
1383 
1384  return engine->toScriptValue(0);
1385 }
1386 
1388  "timeStamp",
1389  "timeStamp()",
1390  "Returns system time as seconds since unix epoch",
1391  ""
1392  )
1393 
1394 QScriptValue QxrdScriptEngine::timeStampFunc(QScriptContext * /*context*/, QScriptEngine *engine)
1395 {
1396  double val = QcepImageDataBase::secondsSinceEpoch();
1397 
1398  return engine->toScriptValue(val);
1399 }
1400 
1401 
1403  "newDataGroup",
1404  "newDataGroup(name)",
1405  "Creates a new named data group",
1406  ""
1407  )
1408 
1409 QScriptValue QxrdScriptEngine::newDataGroupFunc(QScriptContext *context, QScriptEngine *engine)
1410 {
1411  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1412 
1413  if (eng) {
1414  QxrdExperimentPtr expt = eng->experiment();
1415 
1416  if (expt) {
1417  QcepDatasetModelPtr dataModel = expt->dataset();
1418 
1419  if (dataModel) {
1420  QString name = context->argument(0).toString();
1421 
1422  return engine->newQObject(
1423  dataModel->newGroup(name).data());
1424  }
1425  }
1426  }
1427 
1428  return QScriptValue();
1429 }
1430 
1432  "newDataArray",
1433  "newDataArray(name,dim1 .. dimn)",
1434  "Creates a new named n-dimensional data array",
1435  ""
1436  )
1437 
1438 QScriptValue QxrdScriptEngine::newDataArrayFunc(QScriptContext *context, QScriptEngine *engine)
1439 {
1440  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1441 
1442  if (eng) {
1443  QxrdExperimentPtr expt = eng->experiment();
1444 
1445  if (expt) {
1446  QcepDatasetModelPtr dataModel = expt->dataset();
1447 
1448  if (dataModel) {
1449  QString name = context->argument(0).toString();
1450 
1451  QVector<int> dims;
1452 
1453  for (int i=1; i<context->argumentCount(); i++) {
1454  dims.append(context->argument(i).toInteger());
1455  }
1456 
1457  return engine->newQObject(
1458  dataModel->newArray(name, dims).data());
1459  }
1460  }
1461  }
1462 
1463  return QScriptValue();
1464 }
1465 
1467  "newDataColumn",
1468  "newDataColumn(name, npts)",
1469  "Creates a new named data column",
1470  ""
1471  )
1472 
1473 QScriptValue QxrdScriptEngine::newDataColumnFunc(QScriptContext *context, QScriptEngine *engine)
1474 {
1475  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1476 
1477  if (eng) {
1478  QxrdExperimentPtr expt = eng->experiment();
1479 
1480  if (expt) {
1481  QcepDatasetModelPtr dataModel = expt->dataset();
1482 
1483  if (dataModel) {
1484  QString name = context->argument(0).toString();
1485  int npts = context->argument(1).toInteger();
1486 
1487  return engine->newQObject(
1488  dataModel->newColumn(name, npts).data());
1489  }
1490  }
1491  }
1492 
1493  return QScriptValue();
1494 }
1495 
1497  "newDataColumnScan",
1498  "newDataColumnScan(name, npts, col1name .. colnname)",
1499  "Creates a new named data column scan",
1500  ""
1501  )
1502 
1503 QScriptValue QxrdScriptEngine::newDataColumnScanFunc(QScriptContext *context, QScriptEngine *engine)
1504 {
1505  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1506 
1507  if (eng) {
1508  QxrdExperimentPtr expt = eng->experiment();
1509 
1510  if (expt) {
1511  QcepDatasetModelPtr dataModel = expt->dataset();
1512 
1513  if (dataModel) {
1514  QString name = context->argument(0).toString();
1515  int npts = context->argument(1).toInteger();
1516 
1517  QStringList cols;
1518 
1519  for (int i=2; i<context->argumentCount(); i++) {
1520  cols.append(context->argument(i).toString());
1521  }
1522 
1523  return engine->newQObject(
1524  dataModel->newColumnScan(name, npts, cols).data());
1525  }
1526  }
1527  }
1528 
1529  return QScriptValue();
1530 }
1531 
1533  "newDataImage",
1534  "newDataImage(name, width, height)",
1535  "Creates a new named data image",
1536  ""
1537  )
1538 
1539 QScriptValue QxrdScriptEngine::newDataImageFunc(QScriptContext *context, QScriptEngine *engine)
1540 {
1541  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1542 
1543  if (eng) {
1544  QxrdExperimentPtr expt = eng->experiment();
1545  QxrdApplicationPtr app(eng->application());
1546 
1547  if (expt && app) {
1548 
1549  QcepDatasetModelPtr dataModel = expt->dataset();
1550 
1551  if (dataModel) {
1552  QString name = context->argument(0).toString();
1553  int width = context->argument(1).toInteger();
1554  int height = context->argument(2).toInteger();
1555 
1556  return engine->newQObject(
1557  dataModel->newImage(name, width, height).data());
1558  }
1559  }
1560  }
1561 
1562  return QScriptValue();
1563 }
1564 
1566  "newIntegratedData",
1567  "newIntegratedData(name, size)",
1568  "Creates a new integrated data object",
1569  ""
1570  )
1571 
1572 QScriptValue QxrdScriptEngine::newIntegratedDataFunc(QScriptContext *context, QScriptEngine *engine)
1573 {
1574  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1575 
1576  if (eng) {
1577  QxrdExperimentPtr expt = eng->experiment();
1578  QxrdApplicationPtr app(eng->application());
1579 
1580  if (expt && app) {
1581  QcepDatasetModelPtr dataModel = expt->dataset();
1582 
1583  if (dataModel) {
1584  QString name = context->argument(0).toString();
1585  int size = context->argument(1).toInteger();
1586 
1587  return engine->newQObject(
1588  dataModel->newIntegratedData(name, size).data());
1589  }
1590  }
1591  }
1592 
1593  return QScriptValue();
1594 }
1595 
1597  "detector",
1598  "detector(n)",
1599  "Returns a reference to the 'n'th detector",
1600  "")
1601 
1602 QScriptValue QxrdScriptEngine::detectorFunc(QScriptContext *context, QScriptEngine *engine)
1603 {
1604  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1605 
1606  if (eng) {
1607  QxrdAcquisitionPtr acq(eng->acquisition());
1608 
1609  if (acq) {
1610  int n = context->argument(0).toInteger();
1611 
1612  return engine->newQObject(acq->detector(n).data());
1613  }
1614  }
1615 
1616  return QScriptValue();
1617 }
1618 
1620  "roi",
1621  "roi(n,m)",
1622  "Returns a reference to the 'm'th ROI of the 'n'th detector",
1623  ""
1624  )
1625 
1626 QScriptValue QxrdScriptEngine::roiFunc(QScriptContext *context, QScriptEngine *engine)
1627 {
1628  QxrdScriptEngine *eng = qobject_cast<QxrdScriptEngine*>(engine);
1629 
1630  if (eng) {
1631  QxrdAcquisitionPtr acq(eng->acquisition());
1632 
1633  if (acq) {
1634  int n = context->argument(0).toInteger();
1635  int m = context->argument(1).toInteger();
1636 
1637  QxrdDetectorPtr d = acq->detector(n);
1638 
1639  if (d) {
1640  return engine->newQObject(d->roi(m).data());
1641  }
1642  }
1643  }
1644 
1645  return QScriptValue();
1646 }
1647 
1649  "JSON",
1650  "Qt Built-in JSON Parser"
1651  )
1652 
1654  "JSON.parse",
1655  "JSON.parse(string)",
1656  "Parse a string as a JSON object",
1657  "<p>A built-in function in the Qt script system</p>"
1658  )
1659 
1661  "JSON.stringify",
1662  "JSON.stringify(object)",
1663  "Produce JSON string representation of an object",
1664  "<p>A built-in function in the Qt script system</p>"
1665  )
1666 
1668  "Math",
1669  "var x = Math.sqrt(2)",
1670  "Qt Built-in Math Module",
1671  "<p>Qt Script mathematical functions module</p>"
1672  "<p>See also: <a href=\"http://www.w3schools.com/jsref/jsref_obj_math.asp\">JavaScript Math Object</a></p>"
1673  )
1674 
1676  "Infinity",
1677  "Qt Script built-in object with infinite value"
1678  )
1679 
1681  "NaN",
1682  "Qt Script built-in object with NaN (Not-a-Number) Value"
1683  )
1684 
1686  "undefined",
1687  "Qt Script built-in object with undefined value"
1688  )
1689 
1690 
1692  "Array",
1693  "var x=Array([value...])",
1694  "Qt Script built in array constructor function (<a href=\"http://www.w3schools.com/jsref/jsref_obj_array.asp\">JavaScript Array Object</a>)",
1695  "<p>Construct a QtScript array containing the indicated elements</p>"
1696  "<p>Example:</p>"
1697  "<code>Array(1,2,3,4)</code>"
1698  )
1699 
1701  "Boolean",
1702  "var bool=Boolean(value)",
1703  "Qt Script built in Boolean constructor function",
1704  "<p>Construct a QtScript boolean with the given value<p>"
1705  "<p>Example:</p>"
1706  "<code>Boolean(0)</code>"
1707  )
1708 
1710  "Date",
1711  "var d=new Date(|msec|string|year,month[,day[,hr[,min[,sec[,msec]]]]])",
1712  "Qt Script built in date object",
1713  "<p>Construct dates given various inputs</p>"
1714  "<code>var d = new Date() // current date<br/>"
1715  "var d = new Date(msec) // Date from millisecs<br/>"
1716  "var d = new Date(\"October 13, 1975 11:13:00\") // Date from a string<br/>"
1717  "var d = new Date(2001,5,24) // Date from numeric values</code>"
1718  "<p>See also: <a href=\"http://www.w3schools.com/jsref/jsref_obj_date.asp\">JavaScript Date Object</a></p>"
1719  )
1720 
1722  "RegExp",
1723  "var patt=new RegExp(pattern,modifiers) or var patt=/pattern/modifiers",
1724  "Qt Script built in Regular Expression Object",
1725  "<p>Construct regular expression matching objects</p>"
1726  "<p>Examples:</p>"
1727  "<code>var p1 = new RegExp(\".*\\.tif\",\"i\")<br/>"
1728  "var p2=/.*\\.tif/i</code>"
1729  "<p>See also: <a href=\"http://www.w3schools.com/jsref/jsref_obj_regexp.asp\">JavaScript RegExp Object</a></p>"
1730  )
1731 
1733  "String",
1734  "var txt = new String(\"string\"); var t2=\"hhh\";",
1735  "Qt Script built in String Object",
1736  "<p>Construct and manipulate string values.</p>"
1737  "<p>See also: <a href=\"http://www.w3schools.com/jsref/jsref_obj_string.asp\">JavaScript String Object</a></p>"
1738  )
1739 
1741  "Number",
1742  "var num = new Number(42)",
1743  "Qt Script Built in Number Object",
1744  "<p>Construct and manipulate numeric values.</p>"
1745  "<p>See also: <a href=\"http://www.w3schools.com/jsref/jsref_obj_number.asp\">JavaScript Number Object</a></p>"
1746  )
1747 
1749 {
1751 
1752  qRegisterMetaType< QVector<int> >("QVector<int>");
1753  qRegisterMetaType< QVector<bool> >("QVector<bool>");
1754  qRegisterMetaType< QVector<double> >("QVector<double>");
1755  qRegisterMetaType< QVector<QString> >("QVector<QString>");
1756 
1757 // qRegisterMetaType< QList<int> >("QList<int>");
1758 // qRegisterMetaType< QList<bool> >("QList<bool>");
1759 // qRegisterMetaType< QList<double> >("QList<double>");
1760  qRegisterMetaType< QList<QString> >("QList<QString>");
1761 
1762  qScriptRegisterSequenceMetaType< QList<int> >(this);
1763  qScriptRegisterSequenceMetaType< QList<bool> >(this);
1764  qScriptRegisterSequenceMetaType< QList<double> >(this);
1765  qScriptRegisterSequenceMetaType< QList<QString> >(this);
1766  // qScriptRegisterSequenceMetaType< QList<QxrdRingFitParameters*> >(this);
1767  qScriptRegisterSequenceMetaType< QVector<int> >(this);
1768  qScriptRegisterSequenceMetaType< QVector<bool> >(this);
1769  qScriptRegisterSequenceMetaType< QVector<double> >(this);
1770  qScriptRegisterSequenceMetaType< QVector<QString> >(this);
1771  // qScriptRegisterSequenceMetaType< QVector<QxrdRingFitParameters*> >(this);
1772 
1773 // qScriptRegisterMetaType(this,
1774 // QxrdPowderPointProperty::toScriptValue,
1775 // QxrdPowderPointProperty::fromScriptValue);
1776 
1777  qRegisterMetaType<QxrdPowderPoint>("QxrdPowderPoint");
1778  qScriptRegisterMetaType(this,
1781 
1782 // qScriptRegisterSequenceMetaType< QVector<QxrdPowderPoint> >(this);
1783  qScriptRegisterMetaType(this,
1786 
1787  qRegisterMetaType<QxrdCalibrantWPtr>("QxrdCalibrantWPtr");
1788  qScriptRegisterMetaType(this,
1791 
1792  qRegisterMetaType<QcepDataObjectPtr>("QcepDataObjectPtr");
1793  qScriptRegisterMetaType(this,
1796 
1797  qRegisterMetaType<QcepDataGroupPtr>("QcepDataGroupPtr");
1798  qScriptRegisterMetaType(this,
1801 
1802  qRegisterMetaType<QcepDataArrayPtr>("QcepDataArrayPtr");
1803  qScriptRegisterMetaType(this,
1806 
1807  qRegisterMetaType<QcepDataColumnPtr>("QcepDataColumnPtr");
1808  qScriptRegisterMetaType(this,
1811 
1812  qRegisterMetaType<QcepIntegratedDataPtr>("QcepIntegratedDataPtr");
1813  qScriptRegisterMetaType(this,
1816 
1817  qRegisterMetaType<QcepDataColumnScanPtr>("QcepDataColumnScanPtr");
1818  qScriptRegisterMetaType(this,
1821 
1822  qRegisterMetaType<QcepImageDataBasePtr>("QcepImageDataBasePtr");
1823  qScriptRegisterMetaType(this,
1826 
1827  qRegisterMetaType<QcepDoubleImageDataPtr>("QcepDoubleImageDataPtr");
1828  qScriptRegisterMetaType(this,
1831 
1832  qRegisterMetaType<QcepInt16ImageDataPtr>("QcepInt16ImageDataPtr");
1833  qScriptRegisterMetaType(this,
1836 
1837  qRegisterMetaType<QcepInt32ImageDataPtr>("QcepInt32ImageDataPtr");
1838  qScriptRegisterMetaType(this,
1841 
1842  qRegisterMetaType<QcepMaskDataPtr>("QcepMaskDataPtr");
1843  qScriptRegisterMetaType(this,
1846 
1847  qRegisterMetaType<QxrdCalibrantDSpacing>("QxrdCalibrantDSpacing");
1848  qScriptRegisterSequenceMetaType<QxrdCalibrantDSpacings>(this);
1849 
1850  qScriptRegisterMetaType(this,
1853 
1854 // qScriptRegisterMetaType(this,
1855 // QxrdCalibrantDSpacingVector::toScriptValue,
1856 // QxrdCalibrantDSpacingVector::fromScriptValue);
1857 
1858  qRegisterMetaType<QxrdDetectorPtr>("QxrdDetectorPtr");
1859  qScriptRegisterMetaType(this,
1862 
1863  qRegisterMetaType<QxrdDetectorProcessorPtr>("QxrdDetectorProcessorPtr");
1864  qScriptRegisterMetaType(this,
1867 
1868  qRegisterMetaType<QxrdCenterFinderPtr>("QxrdCenterFinderPtr");
1869  qScriptRegisterMetaType(this,
1872 
1873  qRegisterMetaType<QxrdIntegratorPtr>("QxrdIntegratorPtr");
1874  qScriptRegisterMetaType(this,
1877 
1878  qRegisterMetaType<QxrdROICalculatorPtr>("QxrdROICalculatorPtr");
1879  qScriptRegisterMetaType(this,
1882 
1883  qRegisterMetaType<QxrdROICoordinatesPtr>("QxrdROICoordinatesPtr");
1884  qScriptRegisterMetaType(this,
1887 
1888  qRegisterMetaType<QxrdROICoordinatesListModelPtr>("QxrdROICoordinatesListModelPtr");
1889  qScriptRegisterMetaType(this,
1892 
1894 
1895  if (app) {
1896  QCEP_DOC_OBJECT("application", "The QXRD Application Object");
1897  globalObject().setProperty("application", newQObject(app.data()));
1898 
1899  QcepAllocatorPtr alloc(app->allocator());
1900 
1901  if (alloc) {
1902  QCEP_DOC_OBJECT("allocator", "The QXRD Memory Allocator");
1903  globalObject().setProperty("allocator", newQObject(alloc.data()));
1904  }
1905  }
1906 
1907  QCEP_DOC_OBJECT("global", "The Global Object");
1908  globalObject().setProperty("global", globalObject());
1909 
1910  QCEP_DOC_OBJECT("scripting", "The Script Engine");
1911  globalObject().setProperty("scripting", newQObject(this));
1912 
1913  globalObject().setProperty("acquire", newFunction(acquireFunc));
1914  globalObject().setProperty("acquireDark", newFunction(acquireDarkFunc));
1915  globalObject().setProperty("status", newFunction(statusFunc));
1916  globalObject().setProperty("acquireStatus", newFunction(acquireStatusFunc));
1917  globalObject().setProperty("processStatus", newFunction(processStatusFunc, 1));
1918  globalObject().setProperty("acquireCancel", newFunction(acquireCancelFunc));
1919  globalObject().setProperty("acquireScalers", newFunction(acquireScalersFunc));
1920  globalObject().setProperty("trigger", newFunction(triggerFunc));
1921  globalObject().setProperty("exposureTime", newFunction(exposureTimeFunc, 1));
1922  globalObject().setProperty("summedExposures", newFunction(summedExposuresFunc, 1));
1923  globalObject().setProperty("skippedExposures", newFunction(skippedExposuresFunc, 1));
1924  globalObject().setProperty("darkSummedExposures", newFunction(darkSummedExposuresFunc, 1));
1925  globalObject().setProperty("phasesInGroup", newFunction(phasesInGroupFunc, 1));
1926  globalObject().setProperty("preTriggerFiles", newFunction(preTriggerFilesFunc, 1));
1927  globalObject().setProperty("postTriggerFiles", newFunction(postTriggerFilesFunc, 1));
1928  globalObject().setProperty("filePattern", newFunction(filePatternFunc, 1));
1929  globalObject().setProperty("outputDirectory", newFunction(outputDirectoryFunc, 1));
1930  globalObject().setProperty("fileIndex", newFunction(fileIndexFunc, 1));
1931  globalObject().setProperty("print", newFunction(printFunc, NULL));
1932  globalObject().setProperty("fopen", newFunction(fopenFunc, NULL));
1933  globalObject().setProperty("fdelete", newFunction(fdeleteFunc, NULL));
1934  globalObject().setProperty("fprint", newFunction(fprintFunc, NULL));
1935  globalObject().setProperty("fclose", newFunction(fcloseFunc, NULL));
1936  globalObject().setProperty("printMessage", newFunction(printFunc, NULL));
1937  globalObject().setProperty("data", newFunction(dataFunc));
1938  globalObject().setProperty("dark", newFunction(darkFunc));
1939  globalObject().setProperty("mask", newFunction(maskFunc));
1940  globalObject().setProperty("overflow", newFunction(overflowFunc));
1941  globalObject().setProperty("liveData", newFunction(liveDataFunc));
1942  globalObject().setProperty("help", newFunction(helpFunc));
1943  globalObject().setProperty("process", newFunction(processFunc));
1944  globalObject().setProperty("setFileNormalization", newFunction(setFileNormalizationFunc));
1945  globalObject().setProperty("matchFiles", newFunction(matchFilesFunc));
1946  globalObject().setProperty("extraChannel", newFunction(extraChannelFunc, 1));
1947  globalObject().setProperty("mapUserFunction", newFunction(mapUserFunctionFunc, 1));
1948  globalObject().setProperty("timeStamp", newFunction(timeStampFunc, 1));
1949 
1950  globalObject().setProperty("detector", newFunction(detectorFunc, 1));
1951  globalObject().setProperty("roi", newFunction(roiFunc, 1));
1952 
1953 // globalObject().setProperty("dataObject", newFunction(dataObjectFunc));
1954  globalObject().setProperty("newDataGroup", newFunction(newDataGroupFunc));
1955  globalObject().setProperty("newDataArray", newFunction(newDataArrayFunc));
1956  globalObject().setProperty("newDataColumn", newFunction(newDataColumnFunc));
1957  globalObject().setProperty("newDataColumnScan", newFunction(newDataColumnScanFunc));
1958  globalObject().setProperty("newDataImage", newFunction(newDataImageFunc));
1959  globalObject().setProperty("newIntegratedData", newFunction(newIntegratedDataFunc));
1960 
1961  if (app) {
1962  QObject *plugin = dynamic_cast<QObject*>(app->nidaqPlugin().data());
1963 
1964  if (plugin) {
1965  QCEP_DOC_OBJECT("nidaq", "NIDAQ Data Acquisition Plugin");
1966  globalObject().setProperty("nidaq", newQObject(plugin));
1967  }
1968  }
1969 
1971 
1972  if (expt) {
1973  QCEP_DOC_OBJECT("experiment", "The current experiment");
1974  globalObject().setProperty("experiment", newQObject(expt.data()));
1975 
1976  m_Acquisition = expt->acquisition();
1977 
1979 
1980  if (acq) {
1981  QCEP_DOC_OBJECT("acquisition", "The Acquisition Object");
1982  globalObject().setProperty("acquisition", newQObject(acq.data(), QtOwnership, QScriptEngine::AutoCreateDynamicProperties));
1983 
1984  QxrdSynchronizedAcquisitionPtr sync(acq->synchronizedAcquisition());
1985 
1986  if (sync) {
1987  QCEP_DOC_OBJECT("synchronization", "Synchronized Acquisition");
1988  globalObject().setProperty("synchronization", newQObject(sync.data()));
1989  }
1990 
1991  QxrdAcquisitionExtraInputsPtr extra(acq->acquisitionExtraInputs());
1992 
1993  if (extra) {
1994  QCEP_DOC_OBJECT("extraInputs", "Extra Inputs during Acquisition");
1995  globalObject().setProperty("extraInputs", newQObject(extra.data()));
1996  }
1997  }
1998 
1999 // QxrdAcquisitionPtr sacq(expt->singleAcquisition());
2000 
2001 // if (sacq) {
2002 // QCEP_DOC_OBJECT("singleAcquisition", "Single Detector Acquisition Object");
2003 // globalObject().setProperty("singleAcquisition", newQObject(sacq.data(), QtOwnership, QScriptEngine::AutoCreateDynamicProperties));
2004 // }
2005 
2006  QxrdSimpleServerPtr ssrv(expt->simpleServer());
2007 
2008  if (ssrv) {
2009  QCEP_DOC_OBJECT("simpleServer", "Remote Control Text Based Socket Server");
2010  globalObject().setProperty("simpleServer", newQObject(ssrv.data()));
2011  }
2012 
2013  QxrdServerPtr srv(expt->specServer());
2014 
2015  if (srv) {
2016  QCEP_DOC_OBJECT("specServer", "Remote Control Server for use with Spec");
2017  globalObject().setProperty("specServer", newQObject(srv.data()));
2018  }
2019 
2020  m_DataProcessor = expt->dataProcessor();
2021 
2023 
2024  if (dp) {
2025  QCEP_DOC_OBJECT("processor", "Control Data Processing Options");
2026  globalObject().setProperty("processor", newQObject(dp.data()));
2027 
2028  QCEP_DOC_OBJECT("centering", "Beam Center and Detector Alignment Options");
2029  globalObject().setProperty("centering", newQObject(dp->centerFinder().data()));
2030 
2031  QCEP_DOC_OBJECT("integrator", "Image Circular Integration Options");
2032  globalObject().setProperty("integrator", newQObject(dp->integrator().data()));
2033 
2034  QCEP_DOC_OBJECT("polarTransform", "Polar Transform Options");
2035  globalObject().setProperty("polarTransform", newQObject(dp->polarTransform().data()));
2036 
2037  QCEP_DOC_OBJECT("polarNormalization", "Polar Normalization Options");
2038  globalObject().setProperty("polarNormalization", newQObject(dp->polarNormalization().data()));
2039 
2040  QxrdGenerateTestImagePtr gti(dp->generateTestImage());
2041 
2042  if (gti) {
2043  QCEP_DOC_OBJECT("testImage", "Object for generating test images");
2044  globalObject().setProperty("testImage", newQObject(gti.data()));
2045  }
2046 
2047  QCEP_DOC_OBJECT("distortion", "Detector distortion correction");
2048  globalObject().setProperty("distortion", newQObject(dp->distortionCorrection().data()));
2049  }
2050 
2051  QxrdCalibrantLibraryPtr cals(expt->calibrantLibrary());
2052 
2053  if (cals) {
2054  QCEP_DOC_OBJECT("calibrants", "Calibrant Library");
2055  globalObject().setProperty("calibrants", newQObject(cals.data()));
2056  }
2057 
2058  QcepDatasetModelPtr ds = expt->dataset();
2059 
2060  if (ds) {
2061  globalObject().setProperty("dataset", newQObject(ds.data()));
2062  }
2063  }
2064 }
2065 
2067 {
2069 }
2070 
2071 QScriptValue QxrdScriptEngine::QPointFToScriptValue(QScriptEngine *engine, const QPointF &in)
2072 {
2073  QScriptValue obj = engine->newArray(2);
2074 
2075  obj.setProperty(0, in.x());
2076  obj.setProperty(1, in.y());
2077 
2078  return obj;
2079 }
2080 
2081 void QxrdScriptEngine::QPointFFromScriptValue(const QScriptValue &object, QPointF &pt)
2082 {
2083  pt.setX(object.property(0).toNumber());
2084  pt.setY(object.property(1).toNumber());
2085 }
2086 
2087 void QxrdScriptEngine::openScriptOutput(const QString& fileName)
2088 {
2090 
2091  m_ScriptOutput = fopen(qPrintable(fileName), "a+");
2092 }
2093 
2094 void QxrdScriptEngine::writeScriptOutput(const QString& outputLine)
2095 {
2096  if (m_ScriptOutput) {
2097  fputs(qPrintable(outputLine), m_ScriptOutput);
2098  }
2099 }
2100 
2102 {
2103  if (m_ScriptOutput) {
2104  fclose(m_ScriptOutput);
2105  m_ScriptOutput = NULL;
2106  }
2107 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QSharedPointer< QxrdWindow > QxrdWindowPtr
Definition: qxrdwindow-ptr.h:6
static QScriptValue triggerFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue fdeleteFunc(QScriptContext *context, QScriptEngine *engine, void *u)
static QScriptValue QPointFToScriptValue(QScriptEngine *engine, const QPointF &in)
static QScriptValue matchFilesFunc(QScriptContext *context, QScriptEngine *engine)
QSharedPointer< QxrdServer > QxrdServerPtr
Definition: qxrdserver-ptr.h:6
virtual ~QxrdScriptEngine()
static QScriptValue roiFunc(QScriptContext *context, QScriptEngine *engine)
QWeakPointer< QxrdDataProcessor > QxrdDataProcessorWPtr
static void fromScriptValue(const QScriptValue &obj, QcepDataObjectPtr &data)
qint64 qcepDebug(int cond)
Definition: qcepdebug.cpp:26
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdDetectorPtr &det)
static void fromScriptValue(const QScriptValue &obj, QxrdDetectorProcessorPtr &proc)
JSON parse(string)"
static QScriptValue newDataArrayFunc(QScriptContext *context, QScriptEngine *engine)
static void fromColumnScanScriptValue(const QScriptValue &obj, QcepDataColumnScanPtr &data)
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
static QScriptValue timeStampFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdROICalculatorPtr &proc)
static QScriptValue setFileNormalizationFunc(QScriptContext *context, QScriptEngine *engine)
static void fromGroupScriptValue(const QScriptValue &obj, QcepDataGroupPtr &data)
static QScriptValue toScriptValue(QScriptEngine *engine, const QcepDataObjectPtr &data)
static QScriptValue newDataImageFunc(QScriptContext *context, QScriptEngine *engine)
void evaluateSimpleServerCommand(QString cmd)
void openScriptOutput(const QString &fileName)
QSharedPointer< QxrdCalibrantLibrary > QxrdCalibrantLibraryPtr
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
static QScriptValue exposureTimeFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue acquireFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue newDataColumnScanFunc(QScriptContext *context, QScriptEngine *engine)
QString documentationText(QString item)
QxrdExperimentWPtr m_Experiment
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdDetectorProcessorPtr &proc)
static QScriptValue processStatusFunc(QScriptContext *context, QScriptEngine *engine)
QxrdScriptEngine(QxrdApplicationWPtr app, QxrdExperimentWPtr exp)
QxrdWindowWPtr m_Window
static void fromScriptValue(const QScriptValue &obj, QxrdIntegratorPtr &proc)
void evaluateSpecCommand(QString cmd)
static QScriptValue helpFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue postTriggerFilesFunc(QScriptContext *context, QScriptEngine *engine)
QSharedPointer< QxrdSimpleServer > QxrdSimpleServerPtr
QWeakPointer< QxrdApplication > QxrdApplicationWPtr
static QScriptValue newDataGroupFunc(QScriptContext *context, QScriptEngine *engine)
static void fromIntegratedDataScriptValue(const QScriptValue &obj, QcepIntegratedDataPtr &data)
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QString uncaughtExceptionString() const
static void dumpLocks()
static void fromScriptValue(const QScriptValue &obj, QxrdCalibrantDSpacing &spc)
static void fromScriptValue(const QScriptValue &obj, QxrdROICalculatorPtr &proc)
void setWindow(QxrdWindowWPtr win)
static void fromScriptValue(const QScriptValue &obj, QSharedPointer< QcepImageData< T > > &data)
QxrdDataProcessorWPtr dataProcessor() const
static QScriptValue liveDataFunc(QScriptContext *context, QScriptEngine *engine)
static void fromArrayScriptValue(const QScriptValue &obj, QcepDataArrayPtr &data)
static QScriptValue toScriptValue(QScriptEngine *engine, const QSharedPointer< QcepImageData< T > > &data)
static QScriptValue statusFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue newDataColumnFunc(QScriptContext *context, QScriptEngine *engine)
static void fromScriptValue(const QScriptValue &obj, QxrdPowderPoint &pt)
static void fromScriptValue(const QScriptValue &obj, QxrdCenterFinderPtr &proc)
QCEP_DOC_OBJECT("JSON","Qt Built-in JSON Parser") QCEP_DOC_FUNCTION("JSON.parse"
QSharedPointer< QxrdSynchronizedAcquisition > QxrdSynchronizedAcquisitionPtr
static QScriptValue extraChannelFunc(QScriptContext *context, QScriptEngine *engine)
static QString convertToString(QScriptValue result)
#define INVOKE_CHECK(res)
Definition: qcepmacros.h:13
QxrdApplicationWPtr m_Application
QSharedPointer< QxrdAcquisitionExtraInputs > QxrdAcquisitionExtraInputsPtr
QxrdWindowWPtr window() const
static void fromScriptValue(const QScriptValue &obj, QxrdDetectorPtr &det)
static QScriptValue skippedExposuresFunc(QScriptContext *context, QScriptEngine *engine)
void evaluateScript(int src, QString cmd)
static QScriptValue acquireStatusFunc(QScriptContext *context, QScriptEngine *engine)
static void fromScriptValue(const QScriptValue &obj, QxrdCalibrantWPtr &cal)
QWeakPointer< QxrdWindow > QxrdWindowWPtr
Definition: qxrdwindow-ptr.h:9
QSharedPointer< QxrdGenerateTestImage > QxrdGenerateTestImagePtr
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdCenterFinderPtr &proc)
static QScriptValue fcloseFunc(QScriptContext *context, QScriptEngine *engine, void *u)
static QScriptValue toColumnScriptValue(QScriptEngine *engine, const QcepDataColumnPtr &data)
static QScriptValue printFunc(QScriptContext *context, QScriptEngine *engine, void *u)
QxrdDataProcessorWPtr m_DataProcessor
QSharedPointer< QxrdAcquisitionExtraInputsChannel > QxrdAcquisitionExtraInputsChannelPtr
static QScriptValue dataFunc(QScriptContext *context, QScriptEngine *engine)
QCEP_DOC_FUNCTION("print","print([value]...)","Print values to the log file and message window","<p>The values of the arguments are catenated into a single string which is ""printed to the log file and to the message window</p>\n""<p>The following is a typical use: print out the names and values of the ""elements of an object:</p>\n""<code>""for(i in acquisition) print(i, acquisition[i])""</code>") QScriptValue QxrdScriptEngine
static void fromScriptValue(const QScriptValue &obj, QxrdROICoordinatesListModelPtr &coords)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdROICoordinatesListModelPtr &coords)
QxrdApplicationWPtr application() const
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdCalibrantWPtr &cal)
static QScriptValue outputDirectoryFunc(QScriptContext *context, QScriptEngine *engine)
void appResultAvailable(QScriptValue res)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdPowderPoint &pt)
static void QPointFFromScriptValue(const QScriptValue &object, QPointF &pt)
static QScriptValue phasesInGroupFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue overflowFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdPowderPointVector &vec)
void evaluateAppCommand(QString cmd)
static QScriptValue detectorFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue filePatternFunc(QScriptContext *context, QScriptEngine *engine)
#define THREAD_CHECK
Definition: qcepmacros.h:11
static QScriptValue toArrayScriptValue(QScriptEngine *engine, const QcepDataArrayPtr &data)
static QScriptValue darkFunc(QScriptContext *context, QScriptEngine *engine)
void closeScriptOutput()
static void fromColumnScriptValue(const QScriptValue &obj, QcepDataColumnPtr &data)
static QScriptValue fopenFunc(QScriptContext *context, QScriptEngine *engine, void *u)
static QScriptValue toGroupScriptValue(QScriptEngine *engine, const QcepDataGroupPtr &data)
static QScriptValue fprintFunc(QScriptContext *context, QScriptEngine *engine, void *u)
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
static QScriptValue mapUserFunctionFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdIntegratorPtr &proc)
static QScriptValue acquireScalersFunc(QScriptContext *context, QScriptEngine *engine)
QSharedPointer< QcepAllocator > QcepAllocatorPtr
void simpleServerResultAvailable(QScriptValue cmd)
static QScriptValue darkSummedExposuresFunc(QScriptContext *context, QScriptEngine *engine)
int uncaughtExceptionLineNumber() const
static QScriptValue processFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue toIntegratedDataScriptValue(QScriptEngine *engine, const QcepIntegratedDataPtr &data)
void writeScriptOutput(const QString &outputLine)
QxrdExperimentWPtr experiment() const
QSharedPointer< QxrdDetector > QxrdDetectorPtr
static QScriptValue newIntegratedDataFunc(QScriptContext *context, QScriptEngine *engine)
static void fromScriptValue(const QScriptValue &obj, QxrdPowderPointVector &vec)
void loadScript(QString path)
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdCalibrantDSpacing &spc)
static QScriptValue summedExposuresFunc(QScriptContext *context, QScriptEngine *engine)
QSharedPointer< QcepMaskData > QcepMaskDataPtr
static QScriptValue maskFunc(QScriptContext *context, QScriptEngine *engine)
QSharedPointer< QxrdApplication > QxrdApplicationPtr
bool hasUncaughtException() const
QxrdAcquisitionWPtr m_Acquisition
QSharedPointer< QcepDatasetModel > QcepDatasetModelPtr
static double secondsSinceEpoch()
static QScriptValue toScriptValue(QScriptEngine *engine, const QxrdROICoordinatesPtr &coords)
static QScriptValue acquireDarkFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue toColumnScanScriptValue(QScriptEngine *engine, const QcepDataColumnScanPtr &data)
void specResultAvailable(QScriptValue cmd)
static QScriptValue fileIndexFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue preTriggerFilesFunc(QScriptContext *context, QScriptEngine *engine)
static QScriptValue acquireCancelFunc(QScriptContext *context, QScriptEngine *engine)
static void fromScriptValue(const QScriptValue &obj, QxrdROICoordinatesPtr &coords)
QxrdAcquisitionWPtr acquisition() const
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr