Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

productionroaster.xml 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <window id="basicWindow">
  2. <layout type="vertical">
  3. <splitter type = "vertical" id = "main">
  4. <splitter type = "horizontal" id = "indicators" />
  5. <widget id="widget">
  6. <layout type="horizontal" id="controlpanel">
  7. <button name="Start Batch" type="push" id="startbutton" />
  8. <button name="Stop Batch" type="annotation" id="stopbutton" annotation="End" />
  9. </layout>
  10. </widget>
  11. <splitter type="horizontal" id="logsplit">
  12. <measurementtable id="log" />
  13. <graph id="graph" />
  14. </splitter>
  15. </splitter>
  16. </layout>
  17. <menu name="File">
  18. <item id="open" shortcut="Ctrl+O">Open…</item>
  19. <item id="save" shortcut="Ctrl+S">Save…</item>
  20. <item id="print" shortcut="Ctrl+P">Print…</item>
  21. <item id="export">Export CSV…</item>
  22. <item id="svgexport">Export XHTML+SVG…</item>
  23. <item id="quit" shortcut="Ctrl+Q">Quit</item>
  24. </menu>
  25. <menu name="Batch">
  26. <item id="new" shortcut="Ctrl+N">New Batch…</item>
  27. <item id="compare">Load Additional Profiles...</item>
  28. </menu>
  29. <menu name="Log">
  30. <item id="showC">Display Celsius</item>
  31. <item id="showF">Display Fahrenheit</item>
  32. <item id="setSample">New Sample Parameters</item>
  33. <separator />
  34. <item id="clear" shortcut="Ctrl+L">Clear Log</item>
  35. <separator />
  36. <item id="ms">Millisecond View</item>
  37. <item id="1s">1 Second View</item>
  38. <item id="5s">5 Second View</item>
  39. <item id="10s">10 Second View</item>
  40. <item id="15s">15 Second View</item>
  41. <item id="30s">30 Second View</item>
  42. <item id="1m">1 Minute View</item>
  43. <separator />
  44. <item id="manual" shortcut="Ctrl+E">Manual Entry</item>
  45. </menu>
  46. <menu name="Graph">
  47. <item id="unshift">Reset Translation</item>
  48. </menu>
  49. <program>
  50. <![CDATA[
  51. var window = this;
  52. var targetOffset = 0;
  53. var gtrans = 0;
  54. var targetDetector = new ThresholdDetector;
  55. window.targetcolumnname = "";
  56. var currentDetector = new ThresholdDetector;
  57. var translationChannel = -1;
  58. targetDetector.timeForValue.connect(function(value) {
  59. targetOffset = value;
  60. });
  61. var epoch = new QTime;
  62. epoch = epoch.currentTime;
  63. var translationCurrentColumn = -1;
  64. var configModel = new DeviceTreeModel;
  65. var rootIndex = configModel.index(roasterlist.currentIndex, 0);
  66. var channels = new Array();
  67. var annotationButtons = new Array();
  68. var nidevices = new Array();
  69. var dataqsdkdevices = new Array();
  70. var temperatureDisplays = new Array();
  71. var columnNames = new Array();
  72. var modbusdevices = new Array();
  73. var rateCalculators = new Array();
  74. var rateadapters = new Array();
  75. var rateoffsets = new Array();
  76. var ratezeros = new Array();
  77. var channelType = new Array();
  78. window.scales = new Array();
  79. var indicatorPanel = findChildObject(this, 'indicators');
  80. var annotationPanel = findChildObject(this, 'controlpanel');
  81. var log = findChildObject(this, 'log');
  82. var tabControls = new Array();
  83. var start = findChildObject(this, 'startbutton');
  84. var stop = findChildObject(this, 'stopbutton');
  85. stop.enabled = false;
  86. tabControls.push(start);
  87. tabControls.push(stop);
  88. var nsparam = findChildObject(this, 'setSample');
  89. nsparam.enabled = false;
  90. var graph = findChildObject(this, 'graph');
  91. var hasTranslated = false;
  92. var externtrans = undefined;
  93. window.translateLoadedSeries = function(translation) {
  94. var lc = Number(QSettings.value("liveColumn"));
  95. for(var i = 1; i < lc - 1; i++)
  96. {
  97. graph.setSeriesTranslation(i, translation);
  98. }
  99. };
  100. window.translateCurrentSeries = function(translation) {
  101. var lc = Number(QSettings.value("liveColumn"));
  102. for(var i = 0; i < columnNames.length; i++)
  103. {
  104. graph.setSeriesTranslation(lc + i, translation);
  105. }
  106. };
  107. var selectedRoasterName = configModel.data(rootIndex, 0);
  108. var machineReference = configModel.referenceElement(configModel.data(rootIndex, 32));
  109. var selectedRoasterID = machineReference.databaseid;
  110. if(configModel.hasChildren(rootIndex)) {
  111. for(var i = 0; i < configModel.rowCount(rootIndex); i++) {
  112. var driverIndex = configModel.index(i, 0, rootIndex);
  113. var driverReference = configModel.referenceElement(configModel.data(driverIndex, 32));
  114. if(driverReference.driver == "nidaqmxbase" || driverReference.driver == "nidaqmx") {
  115. if(configModel.hasChildren(driverIndex)) {
  116. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  117. var deviceIndex = configModel.index(j, 0, driverIndex);
  118. var deviceReference = configModel.referenceElement(configModel.data(deviceIndex, 32));
  119. if(deviceReference.driver == "nidaqmxbase9211series" || deviceReference.driver == "nidaqmx9211series") {
  120. var device = new DAQ(deviceReference.deviceID, driverReference.driver);
  121. nidevices.push(device);
  122. var DAQChannels = 0;
  123. if(configModel.hasChildren(deviceIndex)) {
  124. for(var k = 0; k < configModel.rowCount(deviceIndex); k++) {
  125. var channelIndex = configModel.index(k, 0, deviceIndex);
  126. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  127. if(channelReference.driver == "ni9211seriestc") {
  128. var channel;
  129. if(channelReference.type == "J") {
  130. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  131. }
  132. else if(channelReference.type == "K") {
  133. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  134. }
  135. else if(channelReference.type == "T") {
  136. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  137. }
  138. else if(channelReference.type == "B") {
  139. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  140. }
  141. else if(channelReference.type == "E") {
  142. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  143. }
  144. else if(channelReference.type == "N") {
  145. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  146. }
  147. else if(channelReference.type == "R") {
  148. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  149. }
  150. else if(channelReference.type == "S") {
  151. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  152. }
  153. channels.push(channel);
  154. channelType.push("T");
  155. columnNames.push(channelReference.columnname);
  156. DAQChannels++;
  157. var indicator = new TemperatureDisplay;
  158. temperatureDisplays.push(indicator);
  159. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  160. channel.newData.connect(indicator.setValue);
  161. indicatorPanel.addWidget(decorator);
  162. }
  163. }
  164. switch(DAQChannels) {
  165. case 1:
  166. device.setClockRate(4);
  167. break;
  168. case 2:
  169. device.setClockRate(2);
  170. break;
  171. case 3:
  172. device.setClockRate(1.5);
  173. break;
  174. case 4:
  175. device.setClockRate(1);
  176. break;
  177. }
  178. device.start();
  179. }
  180. }
  181. else if(deviceReference.driver == "nidaqmxtc01")
  182. {
  183. var device = new DAQ(deviceReference.deviceID, "nidaqmx");
  184. var channel;
  185. if(deviceReference.type == "J")
  186. {
  187. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  188. }
  189. else if(deviceReference.type == "K")
  190. {
  191. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  192. }
  193. else if(deviceReference.type == "T")
  194. {
  195. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  196. }
  197. else if(deviceReference.type == "B")
  198. {
  199. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  200. }
  201. else if(deviceReference.type == "E")
  202. {
  203. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  204. }
  205. else if(deviceReference.type == "N")
  206. {
  207. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  208. }
  209. else if(deviceReference.type == "R")
  210. {
  211. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  212. }
  213. else if(deviceReference.type == "S")
  214. {
  215. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  216. }
  217. channels.push(channel);
  218. channelType.push("T");
  219. columnNames.push(deviceReference.columnname);
  220. var indicator = new TemperatureDisplay;
  221. temperatureDisplays.push(indicator);
  222. var decorator = new WidgetDecorator(indicator, configModel.data(deviceIndex, 0), 2);
  223. channel.newData.connect(indicator.setValue);
  224. indicatorPanel.addWidget(decorator);
  225. device.start();
  226. nidevices.push(device);
  227. }
  228. }
  229. }
  230. }
  231. else if(driverReference.driver == "dataqsdk") {
  232. var device;
  233. if(driverReference.autoSelect == "true") {
  234. device = new DataqSdkDevice(driverReference.deviceNumber);
  235. }
  236. else {
  237. device = new DataqSdkDevice(driverReference.port);
  238. }
  239. var sampleRate = 6;
  240. if(configModel.hasChildren(driverIndex)) {
  241. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  242. var channelIndex = configModel.index(j, 0, driverIndex);
  243. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  244. var indicator = new TemperatureDisplay;
  245. var unit;
  246. if(channelReference.type == "Temperature") {
  247. unit = Units.Fahrenheit;
  248. channelType.push("T");
  249. temperatureDisplays.push(indicator);
  250. }
  251. else {
  252. unit = Units.Unitless;
  253. indicator.setDisplayUnits(Units.Unitless);
  254. channelType.push("C");
  255. indicator.digitCount = 6;
  256. }
  257. var channel = device.newChannel(unit);
  258. var calibrator = new LinearCalibrator;
  259. calibrator.measuredLower = channelReference.calibrationMeasuredLower;
  260. calibrator.measuredUpper = channelReference.calibrationMeasuredUpper;
  261. calibrator.mappedLower = channelReference.calibrationMappedLower;
  262. calibrator.mappedUpper = channelReference.calibrationMappedUpper;
  263. calibrator.sensitivity = channelReference.calibrationSensitivity;
  264. if(channelReference.calibrationClosedInterval == 'true') {
  265. calibrator.closedRange = true;
  266. }
  267. // device.setSmoothingEnabled(j) = channelReference.smoothing;
  268. channel.newData.connect(calibrator.newMeasurement)
  269. channels.push(calibrator);
  270. columnNames.push(channelReference.column);
  271. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  272. calibrator.newData.connect(indicator.setValue);
  273. indicatorPanel.addWidget(decorator);
  274. }
  275. sampleRate /= configModel.rowCount(driverIndex);
  276. }
  277. device.setClockRate(sampleRate);
  278. device.start();
  279. dataqsdkdevices.push(device);
  280. }
  281. else if(driverReference.driver == "modbusrtu")
  282. {
  283. var device = new ModbusRTUDevice(configModel, driverIndex);
  284. modbusdevices.push(device);
  285. var pvchannel = device.pVChannel();
  286. channels.push(pvchannel);
  287. channelType.push("T");
  288. columnNames.push(driverReference.pvcolname);
  289. var indicator = new TemperatureDisplay;
  290. temperatureDisplays.push(indicator);
  291. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " PV", 2);
  292. pvchannel.newData.connect(indicator.setValue);
  293. indicatorPanel.addWidget(decorator);
  294. if(driverReference.sVEnabled == "true")
  295. {
  296. var svchannel = device.sVChannel();
  297. channels.push(svchannel);
  298. channelType.push("C");
  299. columnNames.push(driverReference.svcolname);
  300. var indicator = new TemperatureDisplay;
  301. temperatureDisplays.push(indicator);
  302. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " SV", 2);
  303. svchannel.newData.connect(indicator.setValue);
  304. indicatorPanel.addWidget(decorator);
  305. }
  306. if(driverReference.sVWritable == "true")
  307. {
  308. var outputControl = new AnnotationSpinBox;
  309. device.SVLowerChanged.connect(function(min) {
  310. outputControl.minimum = min;
  311. });
  312. outputControl.minimum = device.SVLower();
  313. device.SVUpperChanged.connect(function(max) {
  314. outputControl.maximum = max;
  315. });
  316. outputControl.maximum = device.SVUpper();
  317. device.SVDecimalChanged.connect(function(prec) {
  318. outputControl.decimals = prec;
  319. });
  320. outputControl.decimals = device.decimals();
  321. outputControl.editingFinished.connect(function() {
  322. device.outputSV(outputControl.value);
  323. });
  324. var layout = new QBoxLayout;
  325. var label = new QLabel("Change SV");
  326. layout.addWidget(label, 0, 2);
  327. layout.addWidget(outputControl, 0, 1);
  328. annotationPanel.addLayout(layout);
  329. tabControls.push(outputControl);
  330. }
  331. }
  332. else if(driverReference.driver == "annotationbutton")
  333. {
  334. var button = new AnnotationButton(driverReference.buttontext);
  335. button.setAnnotation(driverReference.annotationtext);
  336. annotationButtons.push(button);
  337. annotationPanel.addWidget(button);
  338. tabControls.push(button);
  339. }
  340. else if(driverReference.driver == "reconfigurablebutton")
  341. {
  342. var button = new AnnotationButton(driverReference.buttontext);
  343. button.setAnnotation(driverReference.annotationtext);
  344. annotationButtons.push(button);
  345. annotationPanel.addWidget(button);
  346. tabControls.push(button);
  347. nsparam.enabled = true;
  348. nsparam.triggered.connect(function() {
  349. var setParam = createWindow("sampleParameters");
  350. setParam.windowTitle = "Typica - Set Sample Parameters";
  351. setParam.button = button;
  352. });
  353. }
  354. else if(driverReference.driver == "annotationspinbox")
  355. {
  356. var layout = new QBoxLayout;
  357. var label = new QLabel(driverReference.label);
  358. layout.addWidget(label, 0, 2);
  359. var spinbox = new AnnotationSpinBox;
  360. spinbox.setPretext(driverReference.pretext);
  361. spinbox.setPosttext(driverReference.posttext);
  362. spinbox.minimum = driverReference.minimum;
  363. spinbox.maximum = driverReference.maximum;
  364. spinbox.decimals = driverReference.precision;
  365. layout.addWidget(spinbox, 0, 1);
  366. annotationPanel.addLayout(layout);
  367. annotationButtons.push(spinbox);
  368. tabControls.push(spinbox);
  369. }
  370. else if(driverReference.driver == "freeannotation")
  371. {
  372. var layout = new QBoxLayout;
  373. var label = new QLabel(driverReference.labeltext);
  374. var control = new QLineEdit;
  375. layout.addWidget(label, 0, 2);
  376. layout.addWidget(control, 0, 1);
  377. annotationPanel.addLayout(layout);
  378. tabControls.push(control);
  379. control.returnPressed.connect(function() {
  380. for(var i = window.firstTempColumn; i < window.annotationColumn; i++) {
  381. log.newAnnotation(control.text, i, window.annotationColumn);
  382. }
  383. });
  384. }
  385. else if(driverReference.driver == "linearspline")
  386. {
  387. var colname = driverReference.source;
  388. for(var j = 0; j < columnNames.length; j++)
  389. {
  390. if(columnNames[j] == colname)
  391. {
  392. var calibrator = new LinearSplineInterpolator;
  393. var sv = driverReference.sourcevalues;
  394. var dv = driverReference.destinationvalues;
  395. var sourcevalues = sv.slice(2, sv.length-2).split(",");
  396. var destvalues = dv.slice(2, dv.length-2).split(",");
  397. if(sourcevalues.length > 1 && destvalues.length == sourcevalues.length)
  398. {
  399. for(var k = 0; k < sourcevalues.length; k++)
  400. {
  401. calibrator.add_pair(Number(sourcevalues[k]),Number(destvalues[k]));
  402. }
  403. var indicator = new TemperatureDisplay;
  404. temperatureDisplays.push(indicator);
  405. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  406. channels[j].newData.connect(calibrator.newMeasurement);
  407. calibrator.newData.connect(indicator.setValue);
  408. channels.push(calibrator);
  409. channelType.push(channelType[j]);
  410. columnNames.push(driverReference.destination);
  411. indicatorPanel.addWidget(decorator);
  412. }
  413. break;
  414. }
  415. }
  416. }
  417. else if(driverReference.driver == "translation")
  418. {
  419. var colname = driverReference.column;
  420. window.targetcolumnname = colname;
  421. for(var j = 0; j < columnNames.length; j++)
  422. {
  423. if(columnNames[j] == colname)
  424. {
  425. translationChannel = j;
  426. var indicator = new TemperatureDisplay;
  427. indicator.digitCount = 4;
  428. externtrans = indicator;
  429. indicator.display(0);
  430. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  431. indicatorPanel.addWidget(decorator);
  432. currentDetector.timeForValue.connect(function(value) {
  433. if(!hasTranslated)
  434. {
  435. var currentOffset = value;
  436. if(targetOffset != 0)
  437. {
  438. var translation = currentOffset - targetOffset;
  439. externtrans.display(translation);
  440. gtrans = translation;
  441. if(translation > 0)
  442. {
  443. window.translateLoadedSeries(translation);
  444. }
  445. else
  446. {
  447. window.translateCurrentSeries(-translation);
  448. }
  449. }
  450. }
  451. hasTranslated = true;
  452. });
  453. var resetTranslation = findChildObject(this, 'unshift');
  454. resetTranslation.triggered.connect(function() {
  455. if(gtrans > 0) {
  456. window.translateLoadedSeries(-gtrans);
  457. }
  458. else {
  459. window.translateCurrentSeries(gtrans);
  460. }
  461. gtrans = 0;
  462. indicator.display(0);
  463. });
  464. }
  465. }
  466. targetDetector.setThreshold(driverReference.FValue);
  467. currentDetector.setThreshold(driverReference.FValue);
  468. }
  469. else if(driverReference.driver == "rate")
  470. {
  471. var primaryColumn = driverReference.column;
  472. for(var j = 0; j < columnNames.length; j++)
  473. {
  474. if(columnNames[j] == primaryColumn)
  475. {
  476. var rate = new RateOfChange(driverReference.cache, driverReference.scale);
  477. channels[j].newData.connect(rate.newMeasurement);
  478. var indicator = new TemperatureDisplay;
  479. indicator.setRelativeMode(true);
  480. indicator.display(0);
  481. indicator.digitCount = 9;
  482. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  483. indicatorPanel.addWidget(decorator);
  484. rate.newData.connect(indicator.setValue);
  485. temperatureDisplays.push(indicator);
  486. channels.push(rate);
  487. channelType.push("T");
  488. columnNames.push(configModel.data(driverIndex, 0));
  489. }
  490. }
  491. }
  492. else if(driverReference.driver == "scale")
  493. {
  494. var scale = new SerialScale(driverReference.port);
  495. scale.setDataBits(8);
  496. scale.setBaudRate(driverReference.baudrate);
  497. scale.setParity(driverReference.parity);
  498. scale.setStopBits(driverReference.stopbits);
  499. scale.setFlowControl(driverReference.flowcontrol);
  500. scale.open(3);
  501. window.scales.push(scale);
  502. }
  503. }
  504. }
  505. for(var i = 1; i < tabControls.length; i++)
  506. {
  507. setTabOrder(tabControls[i-1], tabControls[i]);
  508. }
  509. log.setHeaderData(0, "Time");
  510. for(var i = 0; i < columnNames.length; i++) {
  511. log.setHeaderData(i + 1, columnNames[i]);
  512. }
  513. log.setHeaderData(columnNames.length + 1, "Note");
  514. for(var i = 0; i < channels.length; i++) {
  515. log.addToCurrentColumnSet(i + 1);
  516. }
  517. var timer = new TimerDisplay;
  518. timer.displayFormat = "mm:ss";
  519. timer.autoReset = true;
  520. var btdecorator = new WidgetDecorator(timer, "Batch Timer", 2);
  521. indicatorPanel.addWidget(btdecorator);
  522. var vsplit = findChildObject(this, 'main');
  523. var isplit = findChildObject(this, 'indicators');
  524. var lsplit = findChildObject(this, 'logsplit');
  525. window.aboutToClose.connect(function() {
  526. for(var i = 0; i < nidevices.length; i++)
  527. {
  528. nidevices[i].stop();
  529. nidevices[i].deleteLater();
  530. }
  531. for(var i = 0; i < modbusdevices.length; i++)
  532. {
  533. modbusdevices[i].deleteLater();
  534. }
  535. for(var i = 0; i < dataqsdkdevices.length; i++)
  536. {
  537. dataqsdkdevices[i].deleteLater();
  538. }
  539. delete nidevices;
  540. delete modbusdevices;
  541. delete dataqsdkdevices;
  542. window.saveSizeAndPosition("window");
  543. vsplit.saveState("script/mainSplitter");
  544. isplit.saveState("script/instrumentSplitter");
  545. lsplit.saveState("script/logSplitter");
  546. log.saveState("script/log", 7);
  547. window.navigationWindow.loggingWindow = undefined;
  548. });
  549. this.restoreSizeAndPosition('window');
  550. vsplit.restoreState("script/mainSplitter");
  551. isplit.restoreState("script/instrumentSplitter");
  552. lsplit.restoreState("script/logSplitter");
  553. log.restoreState("script/log", 7);
  554. var offsets = new Array();
  555. var zeroemitters = new Array();
  556. var adapters = new Array();
  557. for(var i = 0; i < channels.length; i++) {
  558. var offset = new MeasurementTimeOffset(epoch);
  559. offsets.push(offset);
  560. channels[i].newData.connect(offset.newMeasurement);
  561. var adapter = new MeasurementAdapter(i + 1);
  562. adapters.push(adapter);
  563. offset.measurement.connect(adapter.newMeasurement);
  564. var emitter = new ZeroEmitter(i + 1);
  565. zeroemitters.push(emitter);
  566. channels[i].newData.connect(emitter.newMeasurement);
  567. emitter.measurement.connect(log.newMeasurement);
  568. emitter.measurement.connect(graph.newMeasurement);
  569. }
  570. start.clicked.connect(function() {
  571. start.enabled = false;
  572. hasTranslated = false;
  573. var epoch = new QTime();
  574. epoch = epoch.currentTime();
  575. for(var i = 0; i < offsets.length; i++)
  576. {
  577. offsets[i].setZeroTime(epoch);
  578. zeroemitters[i].emitZero();
  579. adapters[i].measurement.connect(log.newMeasurement);
  580. adapters[i].measurement.connect(graph.newMeasurement);
  581. }
  582. for(var i = 0; i < rateadapters.length; i++)
  583. {
  584. rateoffsets[i].setZeroTime(epoch);
  585. ratezeros[i].emitZero();
  586. rateadapters[i].measurement.connect(graph.newMeasurement);
  587. }
  588. timer.startTimer();
  589. if(typeof(currentBatchInfo) == 'undefined') { } else {
  590. query = new QSqlQuery();
  591. query.exec("SELECT now()::timestamp without time zone");
  592. query.next();
  593. var result = query.value(0);
  594. query = query.invalidate();
  595. var timefield = findChildObject(currentBatchInfo, 'time');
  596. timefield.text = result.replace('T', ' ');
  597. }
  598. if(translationChannel >= 0)
  599. {
  600. offsets[translationChannel].measurement.connect(currentDetector.newMeasurement);
  601. }
  602. if(typeof(externtrans) != 'undefined') {
  603. externtrans.display(0);
  604. }
  605. stop.enabled = true;
  606. window.windowModified = true;
  607. graph.setTimeIndicatorEnabled(true);
  608. });
  609. for(var i = 0; i < annotationButtons.length; i++) {
  610. if(channels.length > 0)
  611. {
  612. annotationButtons[i].annotation.connect(log.newAnnotation);
  613. annotationButtons[i].setTemperatureColumn(1);
  614. annotationButtons[i].setAnnotationColumn(channels.length + 1);
  615. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  616. for(var i = tcol; i < ncol; i++) {
  617. log.newAnnotation(note, i, ncol);
  618. }
  619. });
  620. }
  621. }
  622. start.setFocus();
  623. stop.annotation.connect(log.newAnnotation);
  624. stop.clicked.connect(timer.stopTimer);
  625. stop.setTemperatureColumn(1);
  626. stop.setAnnotationColumn(channels.length + 1);
  627. QSettings.setValue("liveColumn", 1);
  628. var lc = 1;
  629. stop.clicked.connect(function() {
  630. stop.enabled = false;
  631. for(var i = 0; i < adapters.length; i++)
  632. {
  633. adapters[i].measurement.disconnect(log.newMeasurement);
  634. adapters[i].measurement.disconnect(graph.newMeasurement);
  635. }
  636. for(var i = 0; i < rateadapters.length; i++)
  637. {
  638. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  639. }
  640. if(typeof(currentBatchInfo) == 'undefined') { } else {
  641. lc = Number(QSettings.value("liveColumn"));
  642. var duration = log.lastTime(lc);
  643. var durfield = findChildObject(currentBatchInfo, 'duration');
  644. durfield.text = duration;
  645. log.clearOutputColumns();
  646. for(var i = 0; i < channels.length; i++) {
  647. if(channelType[i] == "T") {
  648. log.addOutputTemperatureColumn(lc + i);
  649. }
  650. else {
  651. log.addOutputControlColumn(lc + i);
  652. }
  653. }
  654. log.addOutputAnnotationColumn(lc + channels.length);
  655. var filename = log.saveTemporary();
  656. currentBatchInfo.tempData = filename;
  657. currentBatchInfo.raise();
  658. currentBatchInfo.activateWindow();
  659. }
  660. if(translationChannel >= 0)
  661. {
  662. offsets[translationChannel].measurement.disconnect(currentDetector.newMeasurement);
  663. }
  664. start.enabled = true;
  665. window.windowModified = false;
  666. graph.setTimeIndicatorEnabled(false);
  667. });
  668. stop.annotation.connect(function(note, tcol, ncol) {
  669. for(var i = tcol; i < ncol; i++) {
  670. log.newAnnotation(note, i, ncol);
  671. }
  672. });
  673. var quitMenu = findChildObject(this, 'quit');
  674. quitMenu.triggered.connect(function() {
  675. window.close();
  676. Application.quit();
  677. });
  678. var v1 = findChildObject(this, 'ms');
  679. v1.triggered.connect(log.LOD_ms);
  680. var v2 = findChildObject(this, '1s');
  681. v2.triggered.connect(log.LOD_1s);
  682. var v3 = findChildObject(this, '5s');
  683. v3.triggered.connect(log.LOD_5s);
  684. var v4 = findChildObject(this, '10s');
  685. v4.triggered.connect(log.LOD_10s);
  686. var v5 = findChildObject(this, '15s');
  687. v5.triggered.connect(log.LOD_15s);
  688. var v6 = findChildObject(this, '30s');
  689. v6.triggered.connect(log.LOD_30s);
  690. var v7 = findChildObject(this, '1m');
  691. v7.triggered.connect(log.LOD_1m);
  692. var showC = findChildObject(this, 'showC');
  693. showC.triggered.connect(function() {
  694. for(var i = 0; i < temperatureDisplays.length; i++)
  695. {
  696. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  697. }
  698. log.setDisplayUnits(Units.Celsius);
  699. graph.showC();
  700. });
  701. var showF = findChildObject(this, 'showF');
  702. showF.triggered.connect(function() {
  703. for(var i = 0; i < temperatureDisplays.length; i++)
  704. {
  705. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  706. }
  707. log.setDisplayUnits(Units.Fahrenheit);
  708. graph.showF();
  709. });
  710. var clear = findChildObject(this, 'clear');
  711. clear.triggered.connect(log.clear);
  712. clear.triggered.connect(graph.clear);
  713. clear.triggered.connect(function() {
  714. window.windowTitle = "Typica [*]";
  715. log.setHeaderData(0, "Time");
  716. QSettings.setValue("liveColumn", 1);
  717. window.postLoadColumnSetup(0);
  718. if(typeof(externtrans) != 'undefined') {
  719. externtrans.display(0);
  720. }
  721. });
  722. var openMenu = findChildObject(this, 'open');
  723. var compareMenu = findChildObject(this, 'compare');
  724. compareMenu.triggered.connect(function() {
  725. QSettings.setValue('cseries', lc+1);
  726. var history = createWindow("history");
  727. history.windowTitle = 'Typica - Roasting Log';
  728. });
  729. var printMenu = findChildObject(this, 'print');
  730. printMenu.triggered.connect(function() {
  731. var exportWindow = createWindow("print");
  732. exportWindow.windowTitle = "Typica - Print";
  733. exportWindow.log = log;
  734. });
  735. var svgExportMenu = findChildObject(this, 'svgexport');
  736. svgExportMenu.triggered.connect(function() {
  737. var exportWindow = createWindow("exportWindow");
  738. exportWindow.windowTitle = "Typica - Export XHTML+SVG";
  739. exportWindow.log = log;
  740. });
  741. openMenu.triggered.connect(function() {
  742. var filename = QFileDialog.getOpenFileName(window, 'Open Log…', QSettings.value('script/lastDir', '') + '/');
  743. if(filename != '') {
  744. var file = new QFile(filename);
  745. var input = new XMLInput(file, 1);
  746. targetseries = -1;
  747. input.newTemperatureColumn.connect(log.setHeaderData);
  748. input.newTemperatureColumn.connect(function(col, text) {
  749. if(text == window.targetcolumnname) {
  750. targetseries = col;
  751. }
  752. });
  753. input.newAnnotationColumn.connect(log.setHeaderData);
  754. input.measure.connect(graph.newMeasurement);
  755. input.measure.connect(log.newMeasurement);
  756. input.measure.connect(function(data, series) {
  757. if(series == targetseries) {
  758. targetDetector.newMeasurement(data);
  759. }
  760. });
  761. input.annotation.connect(log.newAnnotation);
  762. input.annotation.connect(function(note, tcol, ncol) {
  763. for(var i = tcol; i < ncol; i++) {
  764. log.newAnnotation(note, i, ncol);
  765. }
  766. });
  767. var lc;
  768. input.lastColumn.connect(function(c) {
  769. lc = c;
  770. QSettings.setValue("liveColumn", c + 1);
  771. window.postLoadColumnSetup(c);
  772. });
  773. input.input();
  774. window.windowTitle = 'Typica - [*]' + baseName(filename);
  775. QSettings.setValue("script/lastDir", dir(filename));
  776. log.newAnnotation("End", 1, lc);
  777. }
  778. });
  779. window.postLoadColumnSetup = function(c) {
  780. for(var i = 0; i < adapters.length; i++)
  781. {
  782. adapters[i].setColumn(c + i + 1);
  783. zeroemitters[i].setColumn(c + i + 1);
  784. log.setHeaderData(c + i + 1, columnNames[i]);
  785. }
  786. log.setHeaderData(c + columnNames.length + 1, "Note");
  787. stop.setTemperatureColumn(c + 1);
  788. stop.setAnnotationColumn(c + columnNames.length + 1);
  789. for(var i = 0; i < annotationButtons.length; i++)
  790. {
  791. annotationButtons[i].setTemperatureColumn(c + 1);
  792. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1);
  793. }
  794. log.clearCurrentColumnSet();
  795. for(var i = 0; i < channels.length; i++) {
  796. log.addToCurrentColumnSet(c + i + 1);
  797. }
  798. window.firstTempColumn = c + 1;
  799. window.annotationColumn = c + columnNames.length + 1;
  800. }
  801. var saveMenu = findChildObject(this, 'save');
  802. saveMenu.triggered.connect(function() {
  803. var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
  804. if(filename != "") {
  805. var lc = Number(QSettings.value("liveColumn"));
  806. var file = new QFile(filename);
  807. log.clearOutputColumns();
  808. for(var i = 0; i < columnNames.length; i++)
  809. {
  810. if(channelType[i] == "T") {
  811. log.addOutputTemperatureColumn(lc + i);
  812. }
  813. else {
  814. log.addOutputControlColumn(lc + i);
  815. }
  816. }
  817. log.addOutputAnnotationColumn(lc + columnNames.length);
  818. log.saveXML(file);
  819. QSettings.setValue("script/lastDir", dir(filename));
  820. }
  821. });
  822. var exportMenu = findChildObject(this, 'export');
  823. exportMenu.triggered.connect(function() {
  824. var filename = QFileDialog.getSaveFileName(window, "Export CSV As…", QSettings.value("script/lastDir", "") + "/");
  825. if(filename != "") {
  826. var lc = Number(QSettings.value("liveColumn"));
  827. var file = new QFile(filename);
  828. log.clearOutputColumns();
  829. for(var i = 0; i < columnNames.length; i++)
  830. {
  831. log.addOutputTemperatureColumn(lc + i);
  832. }
  833. log.addOutputAnnotationColumn(lc + columnNames.length);
  834. log.saveCSV(file);
  835. QSettings.setValue("script/lastDir", dir(filename));
  836. }
  837. });
  838. var manual = findChildObject(this, 'manual');
  839. manual.triggered.connect(function() {
  840. var entry = new LogEditWindow();
  841. entry.show();
  842. });
  843. var newMenu = findChildObject(this, 'new');
  844. newMenu.triggered.connect(function() {
  845. var bwindow = createWindow("batchWindow");
  846. bwindow.windowTitle = "Typica - [*]New Batch";
  847. });
  848. window.postLoadColumnSetup(0);
  849. ]]>
  850. </program>
  851. </window>