TG-PlatformPlus/qml/debug/testfixture/Steps5.qml

441 lines
15 KiB
QML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtCharts
import "./common"
Item {
id: self
property var currentStepIndex: -1
property var currentIndex: 0
property var isStart: curTaskIndex == 4
property var stepInstructId: ""
property var stepIncId: ""
property var targetTemperature: 35
property var currentTemperature: 0
property var progress: stepModel.count > 0 ? (currentIndex / stepModel.count) : 0.0
property var imageNames: ["方位1", "方位2"]
property var lstDetialTexts: ["Inc 126.24° Gtf 45°", "Inc 54.76° Gtf 225°"]
property var g_inc: "0°"
property var g_gtf: "0°"
ListModel{
id: stepModel
ListElement{name:"方位1标定"; tips: "请放置到1方位"; _state: "0"; src: "./step1.png"; endTime: ""}
ListElement{name:"方位2标定"; tips: "请放置到2方位"; _state: "0"; src: "./方位2.png"; endTime: ""}
}
Component.onCompleted: {
stopBd.connect(onStopBd)
taskActuatorManager.executeFinished.connect(onExecuteFinished)
}
onIsStartChanged: {
if (isStart) {
startSteps()
}
}
function startSteps()
{
aw_Digital = []
clearSteps()
task5State = "1"
stepIncId = ""
stepInstructId = ""
currentStepIndex = 0
taskModel.get(curTaskIndex).state = task5State
tipText.visible = true
runIncStep()
}
function clearSteps(){
tipText.visible = false
for(var i = 0; i < stepModel.count; i++)
{
stepModel.get(i)._state = "0"
}
currentStepIndex = -1
currentIndex = 0
}
Rectangle{
id: stepLst
width: parent.width/ 2
anchors.top: parent.top
anchors.bottom: parent.bottom
radius: 9
clip: true
QxText{
id: tTitle
text: "标定进度"
font.pixelSize: 20
anchors.left: parent.left
anchors.leftMargin: 30
anchors.top: parent.top
anchors.topMargin: 18
}
ListView{
id: listView
model: stepModel
boundsBehavior: Flickable.StopAtBounds
anchors.top: tTitle.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.leftMargin: 30
anchors.topMargin: 39
delegate: Item{
id: itemDelegate
width: ListView.view.width
height: 42
Row{
spacing: 10
anchors.verticalCenter: parent.verticalCenter
Image{
source: "./resource/state"+_state+".png"
width: 20
height: 20
}
QxListText{
text: imageNames[index]
}
QxListText{
text: lstDetialTexts[index]
color: "#007EFF"
}
}
QxListText{
text: _state == "0" ? "未完成" :(_state == "2" ? endTime : "进行中")
color: _state == "0" ? "#BFBFBF" :(_state == "2" ? "#007EFF" : "#40A362")
anchors.verticalCenter: parent.verticalCenter
anchors.right: stopButton.left
anchors.rightMargin: 10
}
Rectangle
{
id: stopButton
anchors.right: parent.right
anchors.rightMargin: 49
width: _state == "1" ? 30: 0
height: 30
anchors.verticalCenter: parent.verticalCenter
radius: 5
border.width: 1
border.color: "#e5e5e5"
visible: _state == "1"
Rectangle{
anchors.centerIn: parent
width: 10
height: 10
radius: 2
color: "red"
}
MouseArea{
anchors.fill: parent
onClicked:
{
_state = "2"
endTime = Qt.formatDateTime(new Date(), "MM-dd hh:mm:ss")
var info = common.getG("A_Digital")
if(currentStepIndex < stepModel.count-1)
{
aw_Digital.push(info)
writeACsv(1)
info.x_Atemp = 0
info.y_Atemp = 0
info.z_Atemp = 0
common.setG("A_Digital",JSON.stringify(info))
reportJson["aw_Digital1"] = aw_Digital
aw_Digital = []
stepInstructId = ""
tipText.visible = true
runIncStep() // 调角度
currentStepIndex++
currentIndex++
}
else{
task5State = "2"
currentStepIndex = -1
currentIndex = stepModel.count
aw_Digital.push(common.getG("A_Digital"))
reportJson["aw_Digital2"] = aw_Digital
writeACsv(2)
taskModel.get(curTaskIndex).state = task5State
runNextStep()
skLayout.currentIndex = curTaskIndex
}
}
}
}
}
}
}
Rectangle{
id: tipText
width: 315
height: 170
radius: 19
z:2
color: "#FFFFFF"
border.color: "#e5e5e5"
border.width: 1
anchors.centerIn: parent
visible: false
Row
{
spacing: 4
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 37
Image{
width: 20
height: 20
source: "./resource/tip.png"
}
QxText{
font.pixelSize: 16
text: "当前方位 Inc:" + g_inc + " Gtf:" + g_gtf
}
}
Rectangle{
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 37
width: 129
height: 39
radius: 8
color: "#007EFF"
QxText{
text:"已就绪"
font.pixelSize: 14
anchors.centerIn: parent
color: "#FFFFFF"
}
MouseArea{
anchors.fill: parent
onClicked: {
runStep()
}
}
}
}
property var maxTValue: 0
property var minTValue: 0
property var minTemp: 0
property var maxTemp: 90
Rectangle{
id: chartRect
anchors.left: stepLst.right
anchors.top: stepLst.top
anchors.bottom: stepLst.bottom
anchors.right: parent.right
anchors.leftMargin: 10
radius: 9
ChartView {
id: chartView
// title: "温度"
//![1]
anchors.fill: parent
legend.alignment: Qt.AlignTop
antialiasing: true
ValueAxis {
id: valueAxisX
titleText: "点数/个"
min: 0
max: maxTValue == 0 ? 20 : maxTValue
labelFormat: "%.0f"
tickCount: 10
}
ValueAxis{
id: valueAxisY
min: minTemp > 30 ? minTemp - 30 : 0
max: maxTemp + 10
titleText: "温度/mV"
tickCount: 21
tickInterval: 0.5
labelFormat: "%.0f"
}
ValueAxis{
id: valueAxisY2
min: -1
max: 1
titleText: "姿态/V"
tickCount: 21
tickInterval: 0.5
labelFormat: "%.1f"
}
QxLineSeries {
id: lsAsTemperature
axisX: valueAxisX
axisY: valueAxisY
name: "tempAs"
color: "#de8204"
}
QxLineSeries {
id: lsAbTemperature
axisX: valueAxisX
axisY: valueAxisY
name: "tempAb"
color: "#ce743a"
}
QxLineSeries {
id: lsMTemperature
axisX: valueAxisX
axisY: valueAxisY
name: "tempM"
color: "#316846"
}
QxLineSeries {
id: lsxAValue
axisX: valueAxisX
axisYRight: valueAxisY2
name: "ax"
color: "#2695B4"
}
QxLineSeries {
id: lsyAValue
axisX: valueAxisX
axisYRight: valueAxisY2
name: "ay"
color: "#bf3eff"
}
QxLineSeries {
id: lszAValue
axisX: valueAxisX
axisYRight: valueAxisY2
name: "az"
color: "#ec610a"
}
QxLineSeries {
id: lsxMValue
axisX: valueAxisX
axisYRight: valueAxisY2
name: "mx"
color: "#6016b8"
}
QxLineSeries {
id: lsyMValue
axisX: valueAxisX
axisYRight: valueAxisY2
name: "my"
color: "#76D3D9"
}
QxLineSeries {
id: lszMValue
axisX: valueAxisX
axisYRight: valueAxisY2
name: "mz"
color: "#437b5a"
}
}
}
function runStep()
{
tipText.visible = false
var handel = taskModel.get(curTaskIndex)
stepModel.get(currentStepIndex)._state = "1"
var group = parseInt(handel.v1)
var groupcount = parseInt(handel.v3)
var total = group*groupcount
var firstName = handel.v5 == "数字量" ? "数字" : "模拟"
stepInstructId = execute(firstName+"加速度计采集",{"total":total, "skip": 0})
}
function runIncStep()
{
var handel = taskModel.get(curTaskIndex)
var group = parseInt(handel.v1)
var groupcount = parseInt(handel.v3)
var total = group*groupcount
var firstName = handel.v5 == "数字量" ? "数字" : "模拟"
stepIncId = execute(firstName+"加速度计采集",{"total": 1})
}
function onStopBd(){
if(isStart)
{
stopExecute(stepInstructId)
clearSteps()
}
}
function onExecuteFinished(id)
{
if(id == stepInstructId && isStart)
{
console.info("onExecuteFinished",currentStepIndex)
var info = common.getG("A_Digital")
currentTemperature = info.x_Atemp
lsAsTemperature.append(Number(maxTValue), currentTemperature)
lsAbTemperature.append(Number(maxTValue), info.a_tempb)
lsMTemperature.append(Number(maxTValue), info.m_temp)
lsxAValue.append(Number(maxTValue), info.x_Avalue)
lsyAValue.append(Number(maxTValue), info.y_Avalue)
lszAValue.append(Number(maxTValue), info.z_Avalue)
lsxMValue.append(Number(maxTValue), info.x_Mvalue)
lsyMValue.append(Number(maxTValue), info.y_Mvalue)
lszMValue.append(Number(maxTValue), info.z_Mvalue)
if(maxTValue - minTValue > 20)
minTValue = maxTValue - 20;
maxTValue++
if ( maxTemp < parseFloat(currentTemperature) )
{
maxTemp = parseFloat(currentTemperature)
}
console.info("currentStepIndex:",currentStepIndex,"currentTemperature:" + currentTemperature,"targetTemperature:" + targetTemperature)
if (currentStepIndex >= 0)
{
if(stepModel.get(currentStepIndex)._state == "2")
{
}
else{
aw_Digital.push(info)
runStep()
}
}
}
else if(id == stepIncId && isStart)
{
if(tipText.visible)
{
var a_Digital = common.getG("A_Digital")
var x_value = (a_Digital && a_Digital.x_Avalue !== undefined) ? a_Digital.x_Avalue : ""
var y_value = (a_Digital && a_Digital.y_Avalue !== undefined) ? a_Digital.y_Avalue : ""
var z_value = (a_Digital && a_Digital.z_Avalue !== undefined) ? a_Digital.z_Avalue : ""
var x_temp = (a_Digital && a_Digital.x_Atemp !== undefined) ? a_Digital.x_Atemp : ""
var y_temp = (a_Digital && a_Digital.y_Atemp !== undefined) ? a_Digital.y_Atemp : ""
var z_temp = (a_Digital && a_Digital.z_Atemp !== undefined) ? a_Digital.z_Atemp : ""
var templateName = "MWD.xlsx"
calibrate.setAValue(firstPath + appPath + "/template/" + templateName,{"ax": x_value, "ay": y_value, "az": z_value, "tx": x_temp, "ty": y_temp, "tz": z_temp})
var data = calibrate.getMWD(firstPath + appPath + "/template/" + templateName)
g_inc = parseFloat(data.inc).toFixed(2) + "°"
g_gtf = parseFloat(data.gtf).toFixed(2) + "°"
runIncStep()
}
}
}
function writeACsv(num)
{
// 创建CSV表头
const header = "X轴加表输出,X轴加表温度,Y轴加表输出,Y轴加表温度,Z轴加表输出,Z轴加表温度\n";
var csvData = header;
var filename = 'A_' + g_sn +'-'+num+ "_" + Qt.formatDateTime(new Date(startTime), "yyyy_MM_dd_hh_mm_ss") + '.csv';
// 遍历aw_Digital数组将每条结果写入CSV文件
for(var i = 0; i < aw_Digital.length; i++)
{
csvData += aw_Digital[i].x_Avalue +","+aw_Digital[i].x_Atemp+","+aw_Digital[i].y_Avalue+","+aw_Digital[i].y_Atemp+","+aw_Digital[i].z_Avalue+","+aw_Digital[i].z_Atemp+'\n';
}
save_csv(filename, csvData);
}
}