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

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