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

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