RecoveryValve.qml 20 KB

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