RecoveryValve.qml 19 KB

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