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

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