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

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