RecoveryValve.qml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. import QtQuick 2.11
  2. //import QtQuick.VirtualKeyboard 2.14
  3. //import QtQuick.VirtualKeyboard.Settings 2.14
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import QtQuick.Layouts 1.3
  7. import QtTest 1.14
  8. //import "modbus.js" as ModbusJs
  9. //import "breatheTest.js" as BreatheTestJs
  10. import Qt.labs.platform 1.1
  11. Item{
  12. id:root
  13. property var pagetype:rootitem.Page_Type_ValveTest
  14. //车辆单位
  15. property string organize
  16. //车牌号
  17. property string carplate
  18. //总容积
  19. property string total_volume
  20. //油仓数量
  21. property string compartment_num
  22. //当前油仓ID
  23. property int compartment_id
  24. //当前油仓体积
  25. property int volume
  26. property int test_direction:0
  27. //
  28. property string state
  29. property string pressure:"0.00"
  30. property int pressureCnt:0
  31. property var syskpArray: []
  32. property var valvekpArray: []
  33. property var allArray: []
  34. property real m_maxY: 0.0
  35. property real m_minY: 0.0
  36. property bool bStart: false;
  37. /*
  38. Loader{
  39. id:loader
  40. anchors.fill: parent
  41. //anchors.margins: 5
  42. sourceComponent: componet
  43. }
  44. */
  45. /*
  46. function show(){
  47. if(loader.sourceComponent === null){
  48. loader.sourceComponent = componet
  49. console.debug("avans 1111")
  50. }
  51. loader.item.show()
  52. }
  53. function exit(){
  54. if(loader.sourceComponent !== null){
  55. loader.item.exit()
  56. }
  57. }
  58. */
  59. function update_pressure(pressure_map){
  60. //textstring += pressure_map.pressure+":"
  61. //textstring += pressure_map.direction.toString()+":"
  62. //textstring += pressure_map.stage.toString()+":"
  63. //textstring += pressure_map.step.toString()+":"
  64. console.debug("avans 1111 update_pressure: ", pressure_map.pressure)
  65. pressure = pressure_map.pressure
  66. add_record(pressure_map.pressure)
  67. pressureDisplayInput(Number(pressure_map.pressure))
  68. if(pressure_map.step === 3){ // keep pressure
  69. if(pressure_map.stage === 0){ //sys test
  70. syskpArray.push(Number(pressure_map.pressure))
  71. //console.debug("avans 1111 sys keep pressure: ", pressure_map.pressure)
  72. }else if(pressure_map.stage === 1){ //valve test
  73. valvekpArray.push(Number(pressure_map.pressure))
  74. }
  75. }
  76. allArray.push(Number(pressure_map.pressure))
  77. }
  78. function add_record(str){
  79. var obj={}
  80. obj.pressure = str
  81. recordtable.modelData.append(obj)
  82. }
  83. function cleardata(){
  84. recordtable.modelData.clear()
  85. allArray = []
  86. syskpArray = []
  87. valvekpArray = []
  88. curveDisplay.spline.clear()
  89. pressureCnt =0
  90. resulttable.systemPressure_delta = " ";
  91. resulttable.systemPressure_fontcolor="black"
  92. resulttable.systemPressure_pass = "未知";
  93. resulttable.valvePressure_delta = " ";
  94. resulttable.valvePressure_fontcolor ="black"
  95. resulttable.valvePressure_pass = "未知";
  96. statetable.state_str1 = " ";
  97. statetable.state_str2 = " ";
  98. }
  99. function pressureDisplayInput(number){
  100. pressureCnt++
  101. m_maxY = (m_maxY < number)? number:m_maxY
  102. m_minY = (m_minY > number)? number:m_minY
  103. curveDisplay.setRange_Y(m_minY-2.0, m_maxY+2.0)
  104. if(pressureCnt <= 180){
  105. //dataArray.push(number)
  106. curveDisplay.spline.append(pressureCnt-1,number)
  107. }
  108. else{
  109. curveDisplay.setRange_X(0, pressureCnt-1)
  110. curveDisplay.spline.append(pressureCnt-1,number)
  111. /*
  112. dataArray.push(number)
  113. dataArray.shift()
  114. curveDisplay.spline.clear()
  115. for(var i=0; i<61; i++){
  116. curveDisplay.spline.append(i,dataArray[i])
  117. }
  118. */
  119. }
  120. //gauge.value = number
  121. }
  122. function show_systemresult(delta, bPassed)
  123. {
  124. if(bPassed){
  125. resulttable.systemPressure_delta = delta;
  126. resulttable.systemPressure_fontcolor="green"
  127. resulttable.systemPressure_pass = "合格";
  128. }else{
  129. resulttable.systemPressure_delta = delta;
  130. resulttable.systemPressure_fontcolor="red"
  131. resulttable.systemPressure_pass = "超标";
  132. }
  133. console.log("sysTestGeneratePicture")
  134. groupbox.sysTestGeneratePicture()
  135. }
  136. function show_valveresult(delta, bPassed)
  137. {
  138. if(bPassed){
  139. resulttable.valvePressure_delta = delta;
  140. resulttable.valvePressure_fontcolor ="green"
  141. resulttable.valvePressure_pass = "合格";
  142. }else{
  143. resulttable.valvePressure_delta = delta;
  144. resulttable.valvePressure_fontcolor="red"
  145. resulttable.valvePressure_pass = "超标";
  146. }
  147. console.log("valveTestGeneratePicture")
  148. groupbox.valveTestGeneratePicture()
  149. }
  150. function update_runstate(str1, str2)
  151. {
  152. statetable.state_str1 = str1;
  153. statetable.state_str2 = str2;
  154. }
  155. function test_stoped(){
  156. startStopButton.running = false;
  157. console.log("allTestGeneratePicture")
  158. groupbox.allTestGeneratePicture()
  159. }
  160. // Component{
  161. // id:componet
  162. DynamicGroupBox{
  163. id:groupbox
  164. //x:width
  165. //x:0
  166. title: "油气回收系统密封检测 第"+compartment_id+"仓: 容积"+volume+"(L)"
  167. //width: 1024
  168. //height: 768
  169. anchors.centerIn: parent
  170. anchors.fill: parent
  171. function show(){
  172. animationShow.running = true
  173. }
  174. function exit(){
  175. //BreatheTestJs.exit = true
  176. animationExit.running = true
  177. //startStopButton.running = false
  178. //stopTimer.start()
  179. }
  180. function allTestGeneratePicture(){
  181. var filename = root.carplate+"_"+root.compartment_id+"_all"
  182. reportPicture_all.delayms = 100
  183. reportPicture_all.generatePicture(filename, allArray)
  184. }
  185. function sysTestGeneratePicture(){
  186. var filename = root.carplate+"_"+root.compartment_id+"_sys"
  187. reportPicture_sys.delayms = 100
  188. reportPicture_sys.generatePicture(filename, syskpArray)
  189. }
  190. function valveTestGeneratePicture(){
  191. var filename = root.carplate+"_"+root.compartment_id+"_valve"
  192. reportPicture_valve.delayms = 100
  193. reportPicture_valve.generatePicture(filename, valvekpArray)
  194. }
  195. /*
  196. //加载任务动画效果
  197. NumberAnimation {
  198. id: animationShow
  199. target: groupbox
  200. property: "x"
  201. from: groupbox.x
  202. to: 0
  203. duration: 500
  204. }
  205. NumberAnimation {
  206. id: animationExit
  207. target: groupbox
  208. property: "x"
  209. from: groupbox.x
  210. to: 1024
  211. duration: 500
  212. }
  213. */
  214. FileDialog {
  215. id: saveWordDialog
  216. title: "保存为"
  217. //nameFilters: [ "Word files (*.doc)"]
  218. //nameFilters: [ "Word files (*.doc)", "Text files (*.pdf)"]
  219. nameFilters: ["Text files (*.pdf)"]
  220. fileMode: FileDialog.SaveFile
  221. onAccepted: {
  222. var savePath = file.toString().substring(8)
  223. console.log("saveWordDialog savePath:")
  224. console.log(savePath)
  225. //reportWord.generateBreatheValveWord(savePath,para,obj1,obj2,obj3)
  226. testService.genReport(savePath, "D:/tmp/")
  227. }
  228. }
  229. Column{
  230. anchors.left: parent.left
  231. anchors.leftMargin: 3
  232. anchors.top: parent.top
  233. anchors.topMargin: 10
  234. spacing: 0
  235. Row{
  236. x:-10
  237. CurveDisplay{
  238. id:curveDisplay
  239. anchors.verticalCenter: parent.verticalCenter
  240. width: 900
  241. height: 460
  242. axisxMax:180
  243. axisxMin:0
  244. axisyMax:14
  245. axisyMin:0
  246. name:"横轴时间(秒) 纵轴压力(kPa)"
  247. }
  248. Item {
  249. id:button_root
  250. width: 360
  251. height: 460
  252. Column{
  253. id:button_column
  254. spacing: 10
  255. Rectangle{
  256. id:buttonWindow
  257. //anchors.fill: parent
  258. width: 350
  259. height: 70
  260. color: "white"
  261. radius: 6
  262. border.color: "black"
  263. Row{
  264. anchors.verticalCenter: parent.verticalCenter
  265. anchors.horizontalCenter: parent.horizontalCenter
  266. spacing: 50
  267. StartStopButton{
  268. id:startStopButton
  269. width: 50
  270. height: 50
  271. anchors.verticalCenter: parent.verticalCenter
  272. onRunningChanged: {
  273. if(running){
  274. //clearCurveDisplay()
  275. cleardata()
  276. bStart = testService.tstart(compartment_id, test_direction)
  277. if(!bStart){
  278. running=false;
  279. }
  280. }else{
  281. if(bStart){
  282. testService.tstop(compartment_id)
  283. bStart=false
  284. }
  285. }
  286. }
  287. }
  288. ReportButton{
  289. id:reportButton
  290. width: 50
  291. height: 50
  292. anchors.verticalCenter: parent.verticalCenter
  293. onUserClicked:{
  294. //if(allArray.length > 0){
  295. //console.log("allTestGeneratePicture")
  296. //groupbox.allTestGeneratePicture()
  297. // }
  298. //if(syskpArray.length > 0){
  299. //console.log("sysTestGeneratePicture")
  300. //groupbox.sysTestGeneratePicture()
  301. // }
  302. // if(valvekpArray.length > 0){
  303. // console.log("valveTestGeneratePicture")
  304. // groupbox.valveTestGeneratePicture()
  305. // }
  306. //testService.reportpic_Ready(compartment_id);
  307. if(testService.check_alltest_ok(1)){
  308. var fileName = root.carplate
  309. var text = getWordSaveFileName(fileName)
  310. console.log(text)
  311. saveWordDialog.currentFile = getWordSaveFileName(fileName)
  312. saveWordDialog.open()
  313. }
  314. }
  315. }
  316. }
  317. }
  318. Rectangle{
  319. id:test_selrect
  320. //anchors.fill: parent
  321. anchors.margins: 10
  322. width: 350
  323. height: 50
  324. color: "white"
  325. radius: 6
  326. border.color: "black"
  327. UserComboBox{
  328. id:test_comboBox
  329. //anchors.fill:parent
  330. implicitWidth:350
  331. implicitHeight:50
  332. bgColor:"#D2D5D9"
  333. model: ["正压密闭性检测","负压密闭性检测"]
  334. onCurrentTextChanged: {
  335. //root.standard_name = currentText
  336. test_direction = currentIndex
  337. console.log("choose test direction : "+test_direction)
  338. if(0 == currentIndex){
  339. resulttable.titlestr = currentText
  340. }else{
  341. resulttable.titlestr = currentText
  342. }
  343. }
  344. }
  345. }
  346. Rectangle{
  347. id:pressureWindow
  348. //anchors.fill: parent
  349. anchors.margins: 10
  350. width: 350
  351. height: 100
  352. color: "white"
  353. radius: 6
  354. border.color: "black"
  355. Text {
  356. id: pressurekpa
  357. anchors.right: pressureWindow.right
  358. anchors.verticalCenter: parent.verticalCenter
  359. text: qsTr("kPa ")
  360. //font: 40
  361. font.bold: true
  362. font.pixelSize: 35
  363. }
  364. Rectangle{
  365. id:pressure_rect
  366. anchors.verticalCenter: parent.verticalCenter
  367. anchors.right: pressurekpa.left;
  368. width: 250
  369. height: 80
  370. LCDNumber{
  371. id:lcd_pressure
  372. anchors.centerIn: parent
  373. text: root.pressure
  374. }
  375. }
  376. }
  377. Rectangle{
  378. id:resultWindow
  379. //anchors.fill: parent
  380. anchors.margins: 5
  381. width: 350
  382. height: 100
  383. color: "white"
  384. radius: 6
  385. border.color: "black"
  386. ResultTable{
  387. id:resulttable
  388. anchors.fill: parent
  389. }
  390. }
  391. Rectangle{
  392. id:stateWindow
  393. //anchors.fill: parent
  394. anchors.margins: 5
  395. width: 350
  396. height: 100
  397. color: "white"
  398. radius: 6
  399. border.color: "black"
  400. StateTable{
  401. id:statetable
  402. anchors.fill: parent
  403. }
  404. }
  405. }
  406. }
  407. }
  408. Row{
  409. id: records
  410. spacing: 10
  411. function dataRandomSet(modelData,max){
  412. for(var i=0;i<max; i++){
  413. //var number= Math.round(Math.random()*10)
  414. var number= Math.random()*10
  415. //number *= 10
  416. var obj={}
  417. obj.pressure= 0 - number.toFixed(3)
  418. modelData.append(obj)
  419. }
  420. }
  421. Rectangle{
  422. width: 1250
  423. height: 240
  424. color: "white"
  425. radius: 6
  426. GroupBox{
  427. id:groupboxrecord
  428. //x:width
  429. //x:0
  430. title: "历史数据"
  431. anchors.fill: parent
  432. anchors.margins: 0
  433. RecordTable{
  434. id:recordtable
  435. Component.onCompleted: {
  436. //records.dataRandomSet(modelData,500)
  437. }
  438. }
  439. }
  440. }
  441. }
  442. }
  443. }
  444. // }
  445. ReportPicture{
  446. id:reportPicture_sys
  447. }
  448. ReportPicture{
  449. id:reportPicture_valve
  450. }
  451. ReportPicture{
  452. id:reportPicture_all
  453. }
  454. function pad_with_zeroes(number, length) {
  455. var my_string = '' + number;
  456. while (my_string.length < length) {
  457. my_string = '0' + my_string;
  458. }
  459. return my_string;
  460. }
  461. function getWordSaveFileName( para){
  462. var date = new Date;
  463. var year = date.getFullYear()
  464. var month = pad_with_zeroes(date.getMonth()+1,2)
  465. var day = pad_with_zeroes(date.getDate(),2)
  466. var hour = pad_with_zeroes(date.getHours(),2)
  467. var minute = pad_with_zeroes(date.getMinutes(),2)
  468. var second = pad_with_zeroes(date.getSeconds(),2)
  469. var time = year+month+day+hour+minute+second
  470. return "file:///"+time+"_"+para
  471. }
  472. Timer {
  473. id: timer;
  474. interval: 300;//设置定时器定时时间为500ms,默认1000ms
  475. repeat: true //是否重复定时,默认为false
  476. running: false //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
  477. triggeredOnStart: false // 是否开启定时就触发onTriggered,一些特殊用户可以用来设置初始值。
  478. onTriggered: {
  479. //qreal y = 12/2 + (12/2.0)*sin(pressureCnt)
  480. pressureDisplayInput(12/2 + (12/2.0)*Math.sin(Math.PI*pressureCnt/60))
  481. }
  482. //restart ,start,stop,定时器的调用方式,顾名思义
  483. }
  484. Component.onCompleted: {
  485. //timer.start()
  486. }
  487. }