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 51KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  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="newsample">New Sample Batch...</item>
  28. <item id="compare">Load Additional Profiles...</item>
  29. </menu>
  30. <menu name="Log">
  31. <item id="showC">Display Celsius</item>
  32. <item id="showF">Display Fahrenheit</item>
  33. <item id="setSample">New Sample Parameters</item>
  34. <separator />
  35. <item id="clear" shortcut="Ctrl+L">Clear Log</item>
  36. <separator />
  37. <item id="ms">Millisecond View</item>
  38. <item id="1s">1 Second View</item>
  39. <item id="5s">5 Second View</item>
  40. <item id="10s">10 Second View</item>
  41. <item id="15s">15 Second View</item>
  42. <item id="30s">30 Second View</item>
  43. <item id="1m">1 Minute View</item>
  44. <separator />
  45. <item id="manual" shortcut="Ctrl+E">Manual Entry</item>
  46. </menu>
  47. <menu name="Graph">
  48. <item id="reshift" shortcut="Ctrl+T">Set Translation</item>
  49. <item id="unshift" shortcut="Ctrl+R">Reset Translation</item>
  50. </menu>roaster@wilsonscoffee.com
  51. <program>
  52. <![CDATA[
  53. var window = this;
  54. var targetOffset = 0;
  55. var gtrans = 0;
  56. var oldtrans = 0;
  57. var translationdelay = new Timer;
  58. translationdelay.interval = 0;
  59. translationdelay.singleShot = true;
  60. var targetDetector = new ThresholdDetector;
  61. window.targetcolumnname = "";
  62. var currentDetector = new ThresholdDetector;
  63. var translationChannel = -1;
  64. var resetTranslation = findChildObject(this, 'unshift');
  65. var setTranslation = findChildObject(this, 'reshift');
  66. resetTranslation.enabled = false;
  67. setTranslation.enabled = false;
  68. targetDetector.timeForValue.connect(function(value) {
  69. targetOffset = value;
  70. });
  71. var epoch = new QTime;
  72. epoch = epoch.currentTime;
  73. var translationCurrentColumn = -1;
  74. var configModel = new DeviceTreeModel;
  75. var rootIndex = configModel.index(roasterlist.currentIndex, 0);
  76. var roasterIndex = roasterlist.currentIndex;
  77. var channels = new Array();
  78. var annotationButtons = new Array();
  79. var rangetimers = new Array();
  80. var nidevices = new Array();
  81. var dataqsdkdevices = new Array();
  82. var jsdevices = new Array();
  83. var pdevices = new Array();
  84. var temperatureDisplays = new Array();
  85. var columnNames = new Array();
  86. var modbusdevices = new Array();
  87. var rateCalculators = new Array();
  88. var rateadapters = new Array();
  89. var rateoffsets = new Array();
  90. var ratezeros = new Array();
  91. var channelType = new Array();
  92. window.scales = new Array();
  93. var channelVisibility = new Array();
  94. var indicatorPanel = findChildObject(this, 'indicators');
  95. var annotationPanel = findChildObject(this, 'controlpanel');
  96. var log = findChildObject(this, 'log');
  97. var tabControls = new Array();
  98. var start = findChildObject(this, 'startbutton');
  99. var stop = findChildObject(this, 'stopbutton');
  100. stop.enabled = false;
  101. tabControls.push(start);
  102. tabControls.push(stop);
  103. var nsparam = findChildObject(this, 'setSample');
  104. nsparam.enabled = false;
  105. var graph = findChildObject(this, 'graph');
  106. var hasTranslated = false;
  107. var externtrans = undefined;
  108. window.translateLoadedSeries = function(translation) {
  109. var lc = Number(QSettings.value("liveColumn"));
  110. for(var i = 1; i < lc - 1; i++)
  111. {
  112. graph.setSeriesTranslation(i, translation);
  113. }
  114. };
  115. window.translateCurrentSeries = function(translation) {
  116. var lc = Number(QSettings.value("liveColumn"));
  117. for(var i = 0; i < columnNames.length; i++)
  118. {
  119. graph.setSeriesTranslation(lc + i, translation);
  120. }
  121. };
  122. var selectedRoasterName = configModel.data(rootIndex, 0);
  123. var machineReference = configModel.referenceElement(configModel.data(rootIndex, 32));
  124. var selectedRoasterID = machineReference.databaseid;
  125. var checkCapacity = machineReference.checkcapacity;
  126. var maxCapacity = machineReference.capacity;
  127. var capacityUnit = machineReference.capacityunit;
  128. var poundsCapacity;
  129. var convertToPounds = function(w, u) {
  130. switch(u) {
  131. case "g":
  132. return w * 0.0022;
  133. case "oz":
  134. return w * 0.0625;
  135. case "Kg":
  136. return w * 2.2;
  137. }
  138. return w;
  139. };
  140. if(checkCapacity == "true") {
  141. poundsCapacity = convertToPounds(maxCapacity, capacityUnit);
  142. }
  143. if(configModel.hasChildren(rootIndex)) {
  144. for(var i = 0; i < configModel.rowCount(rootIndex); i++) {
  145. var driverIndex = configModel.index(i, 0, rootIndex);
  146. var driverReference = configModel.referenceElement(configModel.data(driverIndex, 32));
  147. if(driverReference.driver == "nidaqmxbase" || driverReference.driver == "nidaqmx") {
  148. if(configModel.hasChildren(driverIndex)) {
  149. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  150. var deviceIndex = configModel.index(j, 0, driverIndex);
  151. var deviceReference = configModel.referenceElement(configModel.data(deviceIndex, 32));
  152. if(deviceReference.driver == "nidaqmxbase9211series" || deviceReference.driver == "nidaqmx9211series") {
  153. var device = new DAQ(deviceReference.deviceID, driverReference.driver);
  154. nidevices.push(device);
  155. var DAQChannels = 0;
  156. if(configModel.hasChildren(deviceIndex)) {
  157. for(var k = 0; k < configModel.rowCount(deviceIndex); k++) {
  158. var channelIndex = configModel.index(k, 0, deviceIndex);
  159. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  160. if(channelReference.driver == "ni9211seriestc") {
  161. var channel;
  162. if(channelReference.type == "J") {
  163. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  164. }
  165. else if(channelReference.type == "K") {
  166. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  167. }
  168. else if(channelReference.type == "T") {
  169. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  170. }
  171. else if(channelReference.type == "B") {
  172. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  173. }
  174. else if(channelReference.type == "E") {
  175. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  176. }
  177. else if(channelReference.type == "N") {
  178. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  179. }
  180. else if(channelReference.type == "R") {
  181. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  182. }
  183. else if(channelReference.type == "S") {
  184. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  185. }
  186. channels.push(channel);
  187. channelType.push("T");
  188. columnNames.push(channelReference.columnname);
  189. DAQChannels++;
  190. if(channelReference.hidden == "true") {
  191. channelVisibility.push(false);
  192. } else {
  193. channelVisibility.push(true);
  194. var indicator = new TemperatureDisplay;
  195. temperatureDisplays.push(indicator);
  196. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  197. channel.newData.connect(indicator.setValue);
  198. indicatorPanel.addWidget(decorator);
  199. }
  200. }
  201. }
  202. switch(DAQChannels) {
  203. case 1:
  204. device.setClockRate(4);
  205. break;
  206. case 2:
  207. device.setClockRate(2);
  208. break;
  209. case 3:
  210. device.setClockRate(1.5);
  211. break;
  212. case 4:
  213. device.setClockRate(1);
  214. break;
  215. }
  216. device.start();
  217. }
  218. }
  219. else if(deviceReference.driver == "nidaqmxtc01")
  220. {
  221. var device = new DAQ(deviceReference.deviceID, "nidaqmx");
  222. var channel;
  223. if(deviceReference.type == "J")
  224. {
  225. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  226. }
  227. else if(deviceReference.type == "K")
  228. {
  229. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  230. }
  231. else if(deviceReference.type == "T")
  232. {
  233. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  234. }
  235. else if(deviceReference.type == "B")
  236. {
  237. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  238. }
  239. else if(deviceReference.type == "E")
  240. {
  241. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  242. }
  243. else if(deviceReference.type == "N")
  244. {
  245. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  246. }
  247. else if(deviceReference.type == "R")
  248. {
  249. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  250. }
  251. else if(deviceReference.type == "S")
  252. {
  253. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  254. }
  255. channels.push(channel);
  256. channelType.push("T");
  257. columnNames.push(deviceReference.columnname);
  258. if(deviceReference.hidden == "true") {
  259. channelVisibility.push(false);
  260. } else {
  261. channelVisibility.push(true);
  262. var indicator = new TemperatureDisplay;
  263. temperatureDisplays.push(indicator);
  264. var decorator = new WidgetDecorator(indicator, configModel.data(deviceIndex, 0), 2);
  265. channel.newData.connect(indicator.setValue);
  266. indicatorPanel.addWidget(decorator);
  267. }
  268. device.start();
  269. nidevices.push(device);
  270. }
  271. }
  272. }
  273. }
  274. else if(driverReference.driver == "dataqsdk") {
  275. var device;
  276. if(driverReference.autoSelect == "true") {
  277. device = new DataqSdkDevice(driverReference.deviceNumber);
  278. }
  279. else {
  280. device = new DataqSdkDevice(driverReference.port);
  281. }
  282. var sampleRate = 6;
  283. if(configModel.hasChildren(driverIndex)) {
  284. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  285. var channelIndex = configModel.index(j, 0, driverIndex);
  286. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  287. var indicator = new TemperatureDisplay;
  288. var unit;
  289. if(channelReference.type == "Temperature") {
  290. unit = Units.Fahrenheit;
  291. channelType.push("T");
  292. temperatureDisplays.push(indicator);
  293. }
  294. else {
  295. unit = Units.Unitless;
  296. indicator.setDisplayUnits(Units.Unitless);
  297. channelType.push("C");
  298. indicator.digitCount = 6;
  299. }
  300. var channel = device.newChannel(unit);
  301. var calibrator = new LinearCalibrator;
  302. calibrator.measuredLower = channelReference.calibrationMeasuredLower;
  303. calibrator.measuredUpper = channelReference.calibrationMeasuredUpper;
  304. calibrator.mappedLower = channelReference.calibrationMappedLower;
  305. calibrator.mappedUpper = channelReference.calibrationMappedUpper;
  306. calibrator.sensitivity = channelReference.calibrationSensitivity;
  307. if(channelReference.calibrationClosedInterval == 'true') {
  308. calibrator.closedRange = true;
  309. }
  310. // device.setSmoothingEnabled(j) = channelReference.smoothing;
  311. channel.newData.connect(calibrator.newMeasurement)
  312. channels.push(calibrator);
  313. columnNames.push(channelReference.column);
  314. if(channelReference.hidden == "true") {
  315. channelVisibility.push(false);
  316. } else {
  317. channelVisibility.push(true);
  318. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  319. calibrator.newData.connect(indicator.setValue);
  320. indicatorPanel.addWidget(decorator);
  321. }
  322. }
  323. sampleRate /= configModel.rowCount(driverIndex);
  324. }
  325. device.setClockRate(sampleRate);
  326. device.start();
  327. dataqsdkdevices.push(device);
  328. }
  329. else if(driverReference.driver == "modbusrtu")
  330. {
  331. var device = new ModbusRTUDevice(configModel, driverIndex);
  332. modbusdevices.push(device);
  333. var pvchannel = device.pVChannel();
  334. channels.push(pvchannel);
  335. channelType.push("T");
  336. columnNames.push(driverReference.pvcolname);
  337. if(driverReference.pvhidden == "true") {
  338. channelVisibility.push(false);
  339. } else {
  340. channelVisibility.push(true);
  341. var indicator = new TemperatureDisplay;
  342. temperatureDisplays.push(indicator);
  343. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " PV", 2);
  344. pvchannel.newData.connect(indicator.setValue);
  345. indicatorPanel.addWidget(decorator);
  346. }
  347. if(driverReference.sVEnabled == "true")
  348. {
  349. var svchannel = device.sVChannel();
  350. channels.push(svchannel);
  351. channelType.push("C");
  352. columnNames.push(driverReference.svcolname);
  353. if(driverReference.svhidden == "true") {
  354. channelVisibility.push(false);
  355. } else {
  356. channelVisibility.push(true);
  357. var indicator = new TemperatureDisplay;
  358. temperatureDisplays.push(indicator);
  359. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " SV", 2);
  360. svchannel.newData.connect(indicator.setValue);
  361. indicatorPanel.addWidget(decorator);
  362. }
  363. }
  364. if(driverReference.sVWritable == "true")
  365. {
  366. var outputControl = new AnnotationSpinBox;
  367. device.SVLowerChanged.connect(function(min) {
  368. outputControl.minimum = min;
  369. });
  370. outputControl.minimum = device.SVLower();
  371. device.SVUpperChanged.connect(function(max) {
  372. outputControl.maximum = max;
  373. });
  374. outputControl.maximum = device.SVUpper();
  375. device.SVDecimalChanged.connect(function(prec) {
  376. outputControl.decimals = prec;
  377. });
  378. outputControl.decimals = device.decimals();
  379. outputControl.editingFinished.connect(function() {
  380. device.outputSV(outputControl.value);
  381. });
  382. var layout = new QBoxLayout;
  383. var label = new QLabel("Change SV");
  384. layout.addWidget(label, 0, 2);
  385. layout.addWidget(outputControl, 0, 1);
  386. annotationPanel.addLayout(layout);
  387. tabControls.push(outputControl);
  388. }
  389. }
  390. else if(driverReference.driver == "modbusngport")
  391. {
  392. var device = new ModbusNG(configModel, driverIndex);
  393. modbusdevices.push(device);
  394. for(var j = 0; j < device.channelCount(); j++) {
  395. channels.push(device.getChannel(j));
  396. columnNames.push(device.channelColumnName(j));
  397. channelType.push(device.channelType(j));
  398. if(device.isChannelHidden(j)) {
  399. channelVisibility.push(false);
  400. } else {
  401. channelVisibility.push(true);
  402. var indicator = new TemperatureDisplay;
  403. if(device.channelType(j) == "C") {
  404. indicator.setDisplayUnits(Units.Unitless);
  405. indicator.digitCount = 6;
  406. }
  407. temperatureDisplays.push(indicator);
  408. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  409. device.getChannel(j).newData.connect(indicator.setValue);
  410. indicatorPanel.addWidget(decorator);
  411. }
  412. }
  413. }
  414. else if(driverReference.driver == "unsupporteddevice")
  415. {
  416. var device = createDevice(driverIndex);
  417. for(var j = 0; j < device.channelCount(); j++) {
  418. channels.push(device.getChannel(j));
  419. columnNames.push(device.channelColumnName(j));
  420. var unit = device.expectedChannelUnit(j);
  421. if(unit == Units.Fahrenheit) {
  422. channelType.push("T");
  423. } else {
  424. channelType.push("C");
  425. }
  426. if(device.isChannelHidden(j)) {
  427. channelVisibility.push(false);
  428. } else {
  429. channelVisibility.push(true);
  430. var indicator = new TemperatureDisplay;
  431. if(unit == Units.Unitless) {
  432. indicator.setDisplayUnits(Units.Unitless);
  433. indicator.digitCount = 6;
  434. }
  435. temperatureDisplays.push(indicator);
  436. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  437. device.getChannel(j).newData.connect(indicator.setValue);
  438. indicatorPanel.addWidget(decorator);
  439. }
  440. }
  441. device.start();
  442. jsdevices.push(device);
  443. }
  444. else if(driverReference.driver == "phidgets1048")
  445. {
  446. var device = new PhidgetsTemperatureSensor(driverIndex);
  447. for(var j = 0; j < device.channelCount(); j++) {
  448. channels.push(device.getChannel(j));
  449. columnNames.push(device.channelColumnName(j));
  450. channelType.push("T");
  451. if(device.isChannelHidden(j)) {
  452. channelVisibility.push(false);
  453. } else {
  454. channelVisibility.push(true);
  455. var indicator = new TemperatureDisplay;
  456. temperatureDisplays.push(indicator);
  457. var decorator = new WidgetDecorator(indicator, device.channelIndicatorText(j), 2);
  458. device.getChannel(j).newData.connect(indicator.setValue);
  459. indicatorPanel.addWidget(decorator);
  460. }
  461. }
  462. device.start();
  463. pdevices.push(device);
  464. }
  465. else if(driverReference.driver == "annotationbutton")
  466. {
  467. var button = new AnnotationButton(driverReference.buttontext);
  468. button.setAnnotation(driverReference.annotationtext);
  469. annotationButtons.push(button);
  470. annotationPanel.addWidget(button);
  471. tabControls.push(button);
  472. }
  473. else if(driverReference.driver == "thresholdannotation")
  474. {
  475. var noteDetector = new ThresholdDetector();
  476. var noteEmitter = new Annotator(driverReference.annotation);
  477. noteDetector.setThreshold(Number(driverReference.value));
  478. for(var j = 0; j < columnNames.length; j++) {
  479. if(columnNames[j] == driverReference.source) {
  480. channels[j].newData.connect(noteDetector.newMeasurement);
  481. break;
  482. }
  483. }
  484. if(Number(driverReference.direction) == 1) {
  485. noteDetector.setEdgeDirection(ThresholdDetector.Descending);
  486. } else {
  487. noteDetector.setEdgeDirection(ThresholdDetector.Ascending);
  488. }
  489. var scope = new Object;
  490. scope.invoke = function() {
  491. if(timer.running) {
  492. arguments.callee.noteEmitter.annotate();
  493. }
  494. }
  495. scope.invoke.noteEmitter = noteEmitter;
  496. noteDetector.timeForValue.connect(scope.invoke);
  497. annotationButtons.push(noteEmitter);
  498. }
  499. else if(driverReference.driver == "valueannotation")
  500. {
  501. var checker = new ValueAnnotation;
  502. var valuesSetting = driverReference.measuredValues;
  503. var notesSetting = driverReference.annotations;
  504. var valuesList = valuesSetting.slice(2, valuesSetting.length-2).split(",");
  505. var notesList = notesSetting.slice(2, notesSetting.length-2).split(",");
  506. if(valuesList.length > 1 && notesList.length == valuesList.length) {
  507. for(var j = 0; j < valuesList.length; j++) {
  508. checker.setAnnotation(Number(valuesList[j]), notesList[j]);
  509. }
  510. }
  511. if(driverReference.emitOnStart == "true") {
  512. start.clicked.connect(checker.annotate);
  513. }
  514. var colname = driverReference.source;
  515. for(var j = 0; j < columnNames.length; j++) {
  516. if(columnNames[j] == colname) {
  517. channels[j].newData.connect(checker.newMeasurement);
  518. break;
  519. }
  520. }
  521. annotationButtons.push(checker);
  522. }
  523. else if(driverReference.driver == "reconfigurablebutton")
  524. {
  525. var button = new AnnotationButton(driverReference.buttontext);
  526. button.setAnnotation(driverReference.annotationtext);
  527. annotationButtons.push(button);
  528. annotationPanel.addWidget(button);
  529. tabControls.push(button);
  530. nsparam.enabled = true;
  531. nsparam.triggered.connect(function() {
  532. var setParam = createWindow("sampleParameters");
  533. setParam.windowTitle = "Typica - Set Sample Parameters";
  534. setParam.button = button;
  535. });
  536. }
  537. else if(driverReference.driver == "annotationspinbox")
  538. {
  539. var layout = new QBoxLayout;
  540. var label = new QLabel(driverReference.label);
  541. layout.addWidget(label, 0, 2);
  542. var spinbox = new AnnotationSpinBox;
  543. spinbox.setPretext(driverReference.pretext);
  544. spinbox.setPosttext(driverReference.posttext);
  545. spinbox.minimum = driverReference.minimum;
  546. spinbox.maximum = driverReference.maximum;
  547. spinbox.decimals = driverReference.precision;
  548. layout.addWidget(spinbox, 0, 1);
  549. annotationPanel.addLayout(layout);
  550. annotationButtons.push(spinbox);
  551. tabControls.push(spinbox);
  552. }
  553. else if(driverReference.driver == "freeannotation")
  554. {
  555. var layout = new QBoxLayout;
  556. var label = new QLabel(driverReference.labeltext);
  557. var control = new QLineEdit;
  558. layout.addWidget(label, 0, 2);
  559. layout.addWidget(control, 0, 1);
  560. annotationPanel.addLayout(layout);
  561. tabControls.push(control);
  562. control.returnPressed.connect(function() {
  563. for(var i = window.firstTempColumn; i < window.annotationColumn; i++) {
  564. log.newAnnotation(control.text, i, window.annotationColumn);
  565. }
  566. });
  567. }
  568. else if(driverReference.driver == "linearspline")
  569. {
  570. var colname = driverReference.source;
  571. for(var j = 0; j < columnNames.length; j++)
  572. {
  573. if(columnNames[j] == colname)
  574. {
  575. var calibrator = new LinearSplineInterpolator;
  576. var sv = driverReference.sourcevalues;
  577. var dv = driverReference.destinationvalues;
  578. var sourcevalues = sv.slice(2, sv.length-2).split(",");
  579. var destvalues = dv.slice(2, dv.length-2).split(",");
  580. if(sourcevalues.length > 1 && destvalues.length == sourcevalues.length)
  581. {
  582. for(var k = 0; k < sourcevalues.length; k++)
  583. {
  584. calibrator.add_pair(Number(sourcevalues[k]),Number(destvalues[k]));
  585. }
  586. var indicator = new TemperatureDisplay;
  587. temperatureDisplays.push(indicator);
  588. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  589. channels[j].newData.connect(calibrator.newMeasurement);
  590. calibrator.newData.connect(indicator.setValue);
  591. channels.push(calibrator);
  592. // Channel hiding is not yet configurable for this.
  593. // I'm not sure if there's any need to allow this
  594. // to be hidden at present.
  595. channelVisibility.push(true);
  596. channelType.push(channelType[j]);
  597. columnNames.push(driverReference.destination);
  598. indicatorPanel.addWidget(decorator);
  599. }
  600. break;
  601. }
  602. }
  603. }
  604. else if(driverReference.driver == "translation")
  605. {
  606. var colname = driverReference.column;
  607. window.targetcolumnname = colname;
  608. if(driverReference.delay)
  609. {
  610. translationdelay.interval = Number(driverReference.delay) * 1000;
  611. }
  612. for(var j = 0; j < columnNames.length; j++)
  613. {
  614. if(columnNames[j] == colname)
  615. {
  616. translationChannel = j;
  617. var indicator = new TemperatureDisplay;
  618. indicator.digitCount = 4;
  619. externtrans = indicator;
  620. indicator.display(0);
  621. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  622. indicatorPanel.addWidget(decorator);
  623. currentDetector.timeForValue.connect(function(value) {
  624. if(!hasTranslated)
  625. {
  626. var currentOffset = value;
  627. if(targetOffset != 0)
  628. {
  629. var translation = currentOffset - targetOffset;
  630. externtrans.display(translation);
  631. gtrans = translation;
  632. if(translation > 0)
  633. {
  634. window.translateLoadedSeries(translation);
  635. }
  636. else
  637. {
  638. window.translateCurrentSeries(-translation);
  639. }
  640. }
  641. }
  642. hasTranslated = true;
  643. resetTranslation.enabled = true;
  644. });
  645. resetTranslation.triggered.connect(function() {
  646. if(gtrans > 0) {
  647. window.translateLoadedSeries(-gtrans);
  648. }
  649. else {
  650. window.translateCurrentSeries(gtrans);
  651. }
  652. oldtrans = gtrans;
  653. gtrans = 0;
  654. externtrans.display(0);
  655. hasTranslated = false;
  656. setTranslation.enabled = true;
  657. });
  658. setTranslation.triggered.connect(function() {
  659. externtrans.display(oldtrans);
  660. gtrans = oldtrans;
  661. if(gtrans > 0) {
  662. window.translateLoadedSeries(gtrans);
  663. }
  664. else {
  665. window.translateCurrentSeries(-gtrans);
  666. }
  667. hasTranslated = true;
  668. resetTranslation.enabled = true;
  669. setTranslation.enabled = false;
  670. });
  671. }
  672. }
  673. targetDetector.setThreshold(driverReference.FValue);
  674. currentDetector.setThreshold(driverReference.FValue);
  675. }
  676. else if(driverReference.driver == "rate")
  677. {
  678. var primaryColumn = driverReference.column;
  679. for(var j = 0; j < columnNames.length; j++)
  680. {
  681. if(columnNames[j] == primaryColumn)
  682. {
  683. var rate = new RateOfChange(driverReference.cache, driverReference.scale);
  684. channels[j].newData.connect(rate.newMeasurement);
  685. var indicator = new TemperatureDisplay;
  686. indicator.setRelativeMode(true);
  687. indicator.display(0);
  688. indicator.digitCount = 9;
  689. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  690. indicatorPanel.addWidget(decorator);
  691. rate.newData.connect(indicator.setValue);
  692. temperatureDisplays.push(indicator);
  693. channels.push(rate);
  694. // This cannot at present be configured to be
  695. // hidden.
  696. channelVisibility.push(true);
  697. channelType.push("T");
  698. columnNames.push(configModel.data(driverIndex, 0));
  699. }
  700. }
  701. }
  702. else if(driverReference.driver == "scale")
  703. {
  704. var scale = new SerialScale(driverReference.port);
  705. scale.setDataBits(8);
  706. scale.setBaudRate(driverReference.baudrate);
  707. scale.setParity(driverReference.parity);
  708. scale.setStopBits(driverReference.stopbits);
  709. scale.setFlowControl(driverReference.flowcontrol);
  710. scale.setWeighCommand(driverReference.weighcommand);
  711. scale.setCommandTerminator(driverReference.commandterminator);
  712. scale.open(3);
  713. window.scales.push(scale);
  714. }
  715. else if(driverReference.driver == "coolingtimer")
  716. {
  717. var coolingTimer = new TimerDisplay();
  718. coolingTimer.setDisplayFormat("mm:ss");
  719. var decorator = new WidgetDecorator(coolingTimer, configModel.data(driverIndex, 0), 2);
  720. indicatorPanel.addWidget(decorator);
  721. coolingTimer.setTimerMode(1);
  722. coolingTimer.setAutoReset(true);
  723. var timeValue = new QTime();
  724. timeValue = timeValue.fromString(driverReference.reset, "mm:ss");
  725. coolingTimer.setResetValue(timeValue);
  726. stop.clicked.connect(coolingTimer.startTimer);
  727. }
  728. else if(driverReference.driver == "rangetimer")
  729. {
  730. rangetimers.push(new TimerDisplay());
  731. var rangeTimer = rangetimers[rangetimers.length - 1];
  732. rangeTimer.setDisplayFormat("mm:ss");
  733. var decorator = new WidgetDecorator(rangeTimer, configModel.data(driverIndex, 0), 2);
  734. indicatorPanel.addWidget(decorator);
  735. stop.clicked.connect(rangeTimer.stopTimer);
  736. start.clicked.connect(rangeTimer.reset);
  737. if(driverReference.starttrigger == "batch")
  738. {
  739. start.clicked.connect(rangeTimer.startTimer);
  740. }
  741. else if(driverReference.starttrigger == "manual")
  742. {
  743. var startButton = new AnnotationButton(driverReference.startbuttontext);
  744. startButton.clicked.connect(rangeTimer.startTimer);
  745. annotationPanel.addWidget(startButton);
  746. tabControls.push(button);
  747. }
  748. else if(driverReference.starttrigger == "value")
  749. {
  750. var startTrigger = new ThresholdDetector();
  751. startTrigger.setThreshold(Number(driverReference.startvalue));
  752. var scope = new Object;
  753. scope.invoke = function() {
  754. if(timer.running && !(arguments.callee.rangeTimer.running))
  755. {
  756. arguments.callee.rangeTimer.startTimer();
  757. }
  758. };
  759. scope.invoke.rangeTimer = rangeTimer;
  760. startTrigger.timeForValue.connect(scope.invoke);
  761. for(var j = 0; j < columnNames.length; j++)
  762. {
  763. if(columnNames[j] == driverReference.startcolumnname)
  764. {
  765. channels[j].newData.connect(startTrigger.newMeasurement);
  766. }
  767. }
  768. }
  769. stop.clicked.connect(rangeTimer.stopTimer)
  770. if(driverReference.stoptrigger == "manual")
  771. {
  772. var stopButton = new AnnotationButton(driverReference.stopbuttontext);
  773. stopButton.clicked.connect(rangeTimer.stopTimer);
  774. annotationPanel.addWidget(stopButton);
  775. tabControls.push(button);
  776. }
  777. else if(driverReference.stoptrigger == "value")
  778. {
  779. var stopTrigger = new ThresholdDetector();
  780. stopTrigger.setThreshold(Number(driverReference.stopvalue));
  781. stopTrigger.timeForValue.connect(rangeTimer.stopTimer);
  782. for(var j = 0; j < columnNames.length; j++)
  783. {
  784. if(columnNames[j] == driverReference.stopcolumnname)
  785. {
  786. channels[j].newData.connect(stopTrigger.newMeasurement);
  787. }
  788. }
  789. }
  790. rangeTimer.reportingName = configModel.data(driverIndex, 0);
  791. rangeTimer.report = function() {
  792. return "" + this.reportingName + ": " + this.value;
  793. };
  794. }
  795. else if(driverReference.driver = "multirangetimer")
  796. {
  797. var rangeTimer = new TimerDisplay();
  798. rangeTimer.setDisplayFormat("mm:ss");
  799. var decorator = new WidgetDecorator(rangeTimer, configModel.data(driverIndex, 0), 2);
  800. indicatorPanel.addWidget(decorator);
  801. var rangenames = driverReference.rangenames;
  802. var endtemps = driverReference.endtemps;
  803. var names = rangenames.slice(2, rangenames.length - 2).split(", ");
  804. rangeTimer.rangeNames = new Array();
  805. for(var j = 0; j < names.length; j++)
  806. {
  807. var name = names[j].slice(1, names[j].length - 1);
  808. rangeTimer.rangeNames.push(name);
  809. }
  810. rangeTimer.rangeEnds = new Array();
  811. var ends = endtemps.slice(2, endtemps.length - 2).split(", ");
  812. for(var j = 0; j < ends.length; j++)
  813. {
  814. rangeTimer.rangeEnds.push(Number(ends[j]));
  815. }
  816. rangeTimer.currentRange = 0;
  817. rangeTimer.results = new Array();
  818. rangeTimer.trigger = new ThresholdDetector();
  819. for(var j = 0; j < columnNames.length; j++)
  820. {
  821. if(columnNames[j] == driverReference.trigger)
  822. {
  823. channels[j].newData.connect(rangeTimer.trigger.newMeasurement);
  824. }
  825. }
  826. rangeTimer.startRanges = function() {
  827. arguments.callee.timer.currentRange = 0;
  828. arguments.callee.timer.results.splice(0, arguments.callee.timer.results.length);
  829. arguments.callee.timer.trigger.setThreshold(arguments.callee.timer.rangeEnds[0]);
  830. };
  831. rangeTimer.startRanges.timer = rangeTimer;
  832. start.clicked.connect(rangeTimer.startTimer);
  833. start.clicked.connect(rangeTimer.startRanges);
  834. rangeTimer.transition = function() {
  835. arguments.callee.timer.stopTimer();
  836. arguments.callee.timer.results.push(arguments.callee.timer.value);
  837. arguments.callee.timer.reset();
  838. arguments.callee.timer.startTimer();
  839. arguments.callee.timer.currentRange++;
  840. if(arguments.callee.timer.currentRange <= arguments.callee.timer.rangeEnds.length)
  841. {
  842. arguments.callee.timer.trigger.setThreshold(arguments.callee.timer.rangeEnds[arguments.callee.timer.currentRange]);
  843. }
  844. };
  845. rangeTimer.transition.timer = rangeTimer;
  846. rangeTimer.trigger.timeForValue.connect(rangeTimer.transition);
  847. stop.clicked.connect(rangeTimer.transition);
  848. stop.clicked.connect(rangeTimer.stopTimer);
  849. rangeTimer.report = function() {
  850. var retval = "";
  851. for(var j = 0; j < arguments.callee.timer.results.length; j++)
  852. {
  853. retval += arguments.callee.timer.rangeNames[j] + ": " + arguments.callee.timer.results[j] + "\n";
  854. }
  855. return retval;
  856. };
  857. rangeTimer.report.timer = rangeTimer;
  858. rangetimers.push(rangeTimer);
  859. }
  860. }
  861. }
  862. for(var i = 1; i < tabControls.length; i++)
  863. {
  864. setTabOrder(tabControls[i-1], tabControls[i]);
  865. }
  866. log.setHeaderData(0, "Time");
  867. var channelSkip = 0;
  868. for(var i = 0; i < columnNames.length; i++) {
  869. if(channelVisibility[i]) {
  870. log.setHeaderData(i + 1 - channelSkip, columnNames[i]);
  871. log.addToCurrentColumnSet(i + 1 - channelSkip);
  872. }
  873. else {
  874. channelSkip++;
  875. }
  876. }
  877. log.setHeaderData(columnNames.length + 1 - channelSkip, TTR("basicWindow", "Note"));
  878. var timer = new TimerDisplay;
  879. timer.displayFormat = "mm:ss";
  880. timer.autoReset = true;
  881. var btdecorator = new WidgetDecorator(timer, TTR("basicWindow", "Batch Timer"), 2);
  882. indicatorPanel.addWidget(btdecorator);
  883. var vsplit = findChildObject(this, 'main');
  884. var isplit = findChildObject(this, 'indicators');
  885. var lsplit = findChildObject(this, 'logsplit');
  886. window.aboutToClose.connect(function() {
  887. for(var i = 0; i < nidevices.length; i++)
  888. {
  889. nidevices[i].stop();
  890. nidevices[i].deleteLater();
  891. }
  892. for(var i = 0; i < modbusdevices.length; i++)
  893. {
  894. modbusdevices[i].deleteLater();
  895. }
  896. for(var i = 0; i < dataqsdkdevices.length; i++)
  897. {
  898. dataqsdkdevices[i].deleteLater();
  899. }
  900. for(var i = 0; i < jsdevices.length; i++)
  901. {
  902. jsdevices[i].stop();
  903. jsdevices[i].deleteLater();
  904. }
  905. for(var i = 0; i < pdevices.length; i++)
  906. {
  907. pdevices[i].stop();
  908. pdevices[i].deleteLater();
  909. }
  910. delete nidevices;
  911. delete modbusdevices;
  912. delete dataqsdkdevices;
  913. delete jsdevices;
  914. delete pdevices;
  915. window.saveSizeAndPosition("window");
  916. vsplit.saveState("script/loggingView/" + roasterIndex + "/mainSplitter");
  917. QSettings.setValue("script/loggingView/" + roasterIndex + "/instrumentCount", isplit.count());
  918. isplit.saveState("script/loggingView/" + roasterIndex + "/instrumentSplitter");
  919. lsplit.saveState("script/loggingView/" + roasterIndex + "/logSplitter");
  920. log.saveState("script/log", 7);
  921. window.navigationWindow.loggingWindow = undefined;
  922. Windows.loggingWindow = undefined;
  923. });
  924. this.restoreSizeAndPosition('window');
  925. vsplit.restoreState("script/loggingView/" + roasterIndex + "/mainSplitter");
  926. if(QSettings.value("script/loggingView/" + roasterIndex + "/instrumentCount") == isplit.count()) {
  927. isplit.restoreState("script/loggingView/" + roasterIndex + "/instrumentSplitter");
  928. }
  929. lsplit.restoreState("script/loggingView/" + roasterIndex + "/logSplitter");
  930. log.restoreState("script/log", 7);
  931. var offsets = new Array();
  932. var zeroemitters = new Array();
  933. var adapters = new Array();
  934. channelSkip = 0;
  935. for(var i = 0; i < channels.length; i++) {
  936. if(channelVisibility[i]) {
  937. var offset = new MeasurementTimeOffset(epoch);
  938. offsets.push(offset);
  939. channels[i].newData.connect(offset.newMeasurement);
  940. var adapter = new MeasurementAdapter(i + 1 - channelSkip);
  941. adapters.push(adapter);
  942. offset.measurement.connect(adapter.newMeasurement);
  943. var emitter = new ZeroEmitter(i + 1);
  944. zeroemitters.push(emitter);
  945. channels[i].newData.connect(emitter.newMeasurement);
  946. emitter.measurement.connect(log.newMeasurement);
  947. emitter.measurement.connect(graph.newMeasurement);
  948. } else {
  949. channelSkip++;
  950. }
  951. }
  952. var offsetForChannel = function(c) {
  953. var retval = -1;
  954. for(var i = 0; i <= c; i++) {
  955. if(channelVisibility[i]) {
  956. retval++;
  957. }
  958. }
  959. return retval;
  960. };
  961. translationdelay.timeout.connect(function() {
  962. offsets[offsetForChannel(translationChannel)].measurement.connect(currentDetector.newMeasurement);
  963. });
  964. start.clicked.connect(function() {
  965. start.enabled = false;
  966. hasTranslated = false;
  967. resetTranslation.enabled = false;
  968. setTranslation.enabled = false;
  969. var epoch = new QTime();
  970. epoch = epoch.currentTime();
  971. for(var i = 0; i < offsets.length; i++)
  972. {
  973. offsets[i].setZeroTime(epoch);
  974. zeroemitters[i].emitZero();
  975. adapters[i].measurement.connect(log.newMeasurement);
  976. adapters[i].measurement.connect(graph.newMeasurement);
  977. }
  978. for(var i = 0; i < rateadapters.length; i++)
  979. {
  980. rateoffsets[i].setZeroTime(epoch);
  981. ratezeros[i].emitZero();
  982. rateadapters[i].measurement.connect(graph.newMeasurement);
  983. }
  984. timer.startTimer();
  985. if(typeof(currentBatchInfo) == 'undefined') { } else {
  986. query = new QSqlQuery();
  987. query.exec("SELECT now()::timestamp without time zone");
  988. query.next();
  989. var result = query.value(0);
  990. query = query.invalidate();
  991. var timefield = findChildObject(currentBatchInfo, 'time');
  992. timefield.text = result.replace('T', ' ');
  993. }
  994. if(translationChannel >= 0)
  995. {
  996. translationdelay.start();
  997. }
  998. if(typeof(externtrans) != 'undefined') {
  999. externtrans.display(0);
  1000. }
  1001. stop.enabled = true;
  1002. window.windowModified = true;
  1003. graph.setTimeIndicatorEnabled(true);
  1004. });
  1005. for(var i = 0; i < annotationButtons.length; i++) {
  1006. if(channels.length > 0)
  1007. {
  1008. annotationButtons[i].annotation.connect(log.newAnnotation);
  1009. annotationButtons[i].setTemperatureColumn(1);
  1010. annotationButtons[i].setAnnotationColumn(channels.length - channelSkip + 1);
  1011. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  1012. for(var i = tcol; i < ncol; i++) {
  1013. log.newAnnotation(note, i, ncol);
  1014. }
  1015. });
  1016. }
  1017. }
  1018. start.setFocus();
  1019. stop.annotation.connect(log.newAnnotation);
  1020. stop.clicked.connect(timer.stopTimer);
  1021. stop.setTemperatureColumn(1);
  1022. stop.setAnnotationColumn(channels.length - channelSkip + 1);
  1023. QSettings.setValue("liveColumn", 1);
  1024. var lc = 1;
  1025. stop.clicked.connect(function() {
  1026. stop.enabled = false;
  1027. for(var i = 0; i < adapters.length; i++)
  1028. {
  1029. adapters[i].measurement.disconnect(log.newMeasurement);
  1030. adapters[i].measurement.disconnect(graph.newMeasurement);
  1031. }
  1032. for(var i = 0; i < rateadapters.length; i++)
  1033. {
  1034. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  1035. }
  1036. if(typeof(currentBatchInfo) == 'undefined') { } else {
  1037. lc = Number(QSettings.value("liveColumn"));
  1038. var duration = log.lastTime(lc);
  1039. var durfield = findChildObject(currentBatchInfo, 'duration');
  1040. durfield.text = duration;
  1041. log.clearOutputColumns();
  1042. channelSkip = 0;
  1043. for(var i = 0; i < channels.length; i++) {
  1044. if(channelVisibility[i]) {
  1045. if(channelType[i] == "T") {
  1046. log.addOutputTemperatureColumn(lc + i - channelSkip);
  1047. }
  1048. else {
  1049. log.addOutputControlColumn(lc + i - channelSkip);
  1050. }
  1051. } else {
  1052. channelSkip++;
  1053. }
  1054. }
  1055. log.addOutputAnnotationColumn(lc + channels.length - channelSkip);
  1056. var filename = log.saveTemporary();
  1057. currentBatchInfo.tempData = filename;
  1058. currentBatchInfo.endBatch();
  1059. var notes = findChildObject(currentBatchInfo, 'annotation');
  1060. for(var i = 0; i < rangetimers.length; i++)
  1061. {
  1062. notes.append(rangetimers[i].report());
  1063. }
  1064. currentBatchInfo.raise();
  1065. currentBatchInfo.activateWindow();
  1066. }
  1067. if(translationChannel >= 0)
  1068. {
  1069. offsets[offsetForChannel(translationChannel)].measurement.disconnect(currentDetector.newMeasurement);
  1070. }
  1071. start.enabled = true;
  1072. window.windowModified = false;
  1073. graph.setTimeIndicatorEnabled(false);
  1074. });
  1075. stop.annotation.connect(function(note, tcol, ncol) {
  1076. for(var i = tcol; i < ncol; i++) {
  1077. log.newAnnotation(note, i, ncol);
  1078. }
  1079. });
  1080. var quitMenu = findChildObject(this, 'quit');
  1081. quitMenu.triggered.connect(function() {
  1082. window.close();
  1083. Application.quit();
  1084. });
  1085. var v1 = findChildObject(this, 'ms');
  1086. v1.triggered.connect(log.LOD_ms);
  1087. var v2 = findChildObject(this, '1s');
  1088. v2.triggered.connect(log.LOD_1s);
  1089. var v3 = findChildObject(this, '5s');
  1090. v3.triggered.connect(log.LOD_5s);
  1091. var v4 = findChildObject(this, '10s');
  1092. v4.triggered.connect(log.LOD_10s);
  1093. var v5 = findChildObject(this, '15s');
  1094. v5.triggered.connect(log.LOD_15s);
  1095. var v6 = findChildObject(this, '30s');
  1096. v6.triggered.connect(log.LOD_30s);
  1097. var v7 = findChildObject(this, '1m');
  1098. v7.triggered.connect(log.LOD_1m);
  1099. var showC = findChildObject(this, 'showC');
  1100. showC.triggered.connect(function() {
  1101. for(var i = 0; i < temperatureDisplays.length; i++)
  1102. {
  1103. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  1104. }
  1105. log.setDisplayUnits(Units.Celsius);
  1106. graph.showC();
  1107. QSettings.setValue("temperatureUnit", "C");
  1108. });
  1109. var showF = findChildObject(this, 'showF');
  1110. showF.triggered.connect(function() {
  1111. for(var i = 0; i < temperatureDisplays.length; i++)
  1112. {
  1113. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  1114. }
  1115. log.setDisplayUnits(Units.Fahrenheit);
  1116. graph.showF();
  1117. QSettings.setValue("temperatureUnit", "F");
  1118. });
  1119. if(QSettings.value("temperatureUnit", "F") == "C")
  1120. {
  1121. showC.trigger();
  1122. }
  1123. var clear = findChildObject(this, 'clear');
  1124. clear.triggered.connect(log.clear);
  1125. clear.triggered.connect(graph.clear);
  1126. clear.triggered.connect(function() {
  1127. window.windowTitle = "Typica [*]";
  1128. log.setHeaderData(0, "Time");
  1129. QSettings.setValue("liveColumn", 1);
  1130. window.postLoadColumnSetup(0);
  1131. if(typeof(externtrans) != 'undefined') {
  1132. externtrans.display(0);
  1133. }
  1134. resetTranslation.enabled = false;
  1135. setTranslation.enabled = false;
  1136. });
  1137. var openMenu = findChildObject(this, 'open');
  1138. var compareMenu = findChildObject(this, 'compare');
  1139. compareMenu.triggered.connect(function() {
  1140. QSettings.setValue('cseries', lc+1);
  1141. var history = createReport("historyreport.xml");
  1142. history.windowTitle = TTR("basicWindow", "Typica - Roasting Log");
  1143. });
  1144. var printMenu = findChildObject(this, 'print');
  1145. printMenu.triggered.connect(function() {
  1146. var exportWindow = createWindow("print");
  1147. exportWindow.windowTitle = TTR("basicWindow", "Typica - Print");
  1148. exportWindow.log = log;
  1149. });
  1150. var svgExportMenu = findChildObject(this, 'svgexport');
  1151. svgExportMenu.triggered.connect(function() {
  1152. var exportWindow = createWindow("exportWindow");
  1153. exportWindow.windowTitle = TTR("basicWindow", "Typica - Export XHTML+SVG");
  1154. exportWindow.log = log;
  1155. });
  1156. openMenu.triggered.connect(function() {
  1157. var filename = QFileDialog.getOpenFileName(window, TTR("basicWindow", "Open Log..."), QSettings.value('script/lastDir', '') + '/');
  1158. if(filename != '') {
  1159. var file = new QFile(filename);
  1160. var input = new XMLInput(file, 1);
  1161. targetseries = -1;
  1162. input.newTemperatureColumn.connect(log.setHeaderData);
  1163. input.newTemperatureColumn.connect(function(col, text) {
  1164. if(text == window.targetcolumnname) {
  1165. targetseries = col;
  1166. }
  1167. });
  1168. input.newAnnotationColumn.connect(log.setHeaderData);
  1169. input.measure.connect(graph.newMeasurement);
  1170. input.measure.connect(log.newMeasurement);
  1171. input.measure.connect(function(data, series) {
  1172. if(series == targetseries) {
  1173. targetDetector.newMeasurement(data);
  1174. }
  1175. });
  1176. resetTranslation.enabled = false;
  1177. setTranslation.enabled = false;
  1178. input.annotation.connect(log.newAnnotation);
  1179. input.annotation.connect(function(note, tcol, ncol) {
  1180. for(var i = tcol; i < ncol; i++) {
  1181. log.newAnnotation(note, i, ncol);
  1182. }
  1183. });
  1184. var lc;
  1185. input.lastColumn.connect(function(c) {
  1186. lc = c;
  1187. QSettings.setValue("liveColumn", c + 1);
  1188. window.postLoadColumnSetup(c);
  1189. });
  1190. graph.updatesEnabled = false;
  1191. log.updatesEnabled = false;
  1192. input.input();
  1193. log.updatesEnabled = true;
  1194. graph.updatesEnabled = true;
  1195. window.windowTitle = 'Typica - [*]' + baseName(filename);
  1196. QSettings.setValue("script/lastDir", dir(filename));
  1197. log.newAnnotation(TTR("basicWindow", "End"), 1, lc);
  1198. }
  1199. });
  1200. var columnName = function(c) {
  1201. var visibleColumns = 0;
  1202. for(var i = 0; i < channels.length; i++) {
  1203. if(channelVisibility[i]) {
  1204. visibleColumns++;
  1205. }
  1206. if(c == visibleColumns - 1) {
  1207. return columnNames[i];
  1208. }
  1209. }
  1210. return "";
  1211. };
  1212. window.postLoadColumnSetup = function(c) {
  1213. for(var i = 0; i < adapters.length; i++)
  1214. {
  1215. adapters[i].setColumn(c + i + 1);
  1216. zeroemitters[i].setColumn(c + i + 1);
  1217. log.setHeaderData(c + i + 1, columnName(i));
  1218. }
  1219. log.setHeaderData(c + columnNames.length + 1 - channelSkip, TTR("basicWindow", "Note"));
  1220. stop.setTemperatureColumn(c + 1);
  1221. stop.setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  1222. for(var i = 0; i < annotationButtons.length; i++)
  1223. {
  1224. annotationButtons[i].setTemperatureColumn(c + 1);
  1225. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1 - channelSkip);
  1226. }
  1227. log.clearCurrentColumnSet();
  1228. for(var i = 0; i < channels.length - channelSkip; i++) {
  1229. log.addToCurrentColumnSet(c + i + 1);
  1230. }
  1231. window.firstTempColumn = c + 1;
  1232. window.annotationColumn = c + columnNames.length - channelSkip + 1;
  1233. }
  1234. var saveMenu = findChildObject(this, 'save');
  1235. saveMenu.triggered.connect(function() {
  1236. var filename = QFileDialog.getSaveFileName(window, TTR("basicWindow", "Save Log As..."), QSettings.value("script/lastDir", "") + "/");
  1237. if(filename != "") {
  1238. var lc = Number(QSettings.value("liveColumn"));
  1239. var file = new QFile(filename);
  1240. log.clearOutputColumns();
  1241. channelSkip = 0;
  1242. for(var i = 0; i < channels.length; i++)
  1243. {
  1244. if(channelVisibility[i]) {
  1245. if(channelType[i] == "T") {
  1246. log.addOutputTemperatureColumn(lc + i - channelSkip);
  1247. }
  1248. else {
  1249. log.addOutputControlColumn(lc + i - channelSkip);
  1250. }
  1251. } else {
  1252. channelSkip++;
  1253. }
  1254. }
  1255. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  1256. log.saveXML(file);
  1257. QSettings.setValue("script/lastDir", dir(filename));
  1258. }
  1259. });
  1260. var exportMenu = findChildObject(this, 'export');
  1261. exportMenu.triggered.connect(function() {
  1262. var filename = QFileDialog.getSaveFileName(window, TTR("basicWindow", "Export CSV As..."), QSettings.value("script/lastDir", "") + "/");
  1263. if(filename != "") {
  1264. var lc = Number(QSettings.value("liveColumn"));
  1265. var file = new QFile(filename);
  1266. log.clearOutputColumns();
  1267. for(var i = 0; i < columnNames.length - channelSkip; i++)
  1268. {
  1269. log.addOutputTemperatureColumn(lc + i);
  1270. }
  1271. log.addOutputAnnotationColumn(lc + columnNames.length - channelSkip);
  1272. log.saveCSV(file);
  1273. QSettings.setValue("script/lastDir", dir(filename));
  1274. }
  1275. });
  1276. var manual = findChildObject(this, 'manual');
  1277. manual.triggered.connect(function() {
  1278. var entry = new LogEditWindow();
  1279. entry.show();
  1280. });
  1281. var newMenu = findChildObject(this, 'new');
  1282. newMenu.triggered.connect(function() {
  1283. var bwindow = createWindow("batchWindow");
  1284. bwindow.windowTitle = TTR("basicWindow", "Typica - [*]New Batch");
  1285. });
  1286. var newSampleMenu = findChildObject(this, 'newsample');
  1287. newSampleMenu.triggered.connect(function() {
  1288. var bwindow = createWindow("sampleRoastingBatch");
  1289. });
  1290. window.postLoadColumnSetup(0);
  1291. Windows.loggingWindow = window;
  1292. ]]>
  1293. </program>
  1294. </window>