RecoveryValve.qml 20 KB

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