TG-PlatformPlus/qml/debug/hsvp/Steps1.qml

338 lines
13 KiB
QML
Raw Permalink Normal View History

2026-03-02 14:29:58 +08:00
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "./common"
Item {
id: self
property var currentStepIndex: -1
property var currentIndex: 0
property var isStart: curTaskIndex == 0
property var stepInstructId: ""
property var progress: stepModel.count > 0 ? (currentIndex / (stepModel.count)) : 0.0
property var imageNames: ["1-1", "1-2", "1-3","1-4","2-1", "2-2", "2-3","2-4","3-1", "3-2", "3-3","3-4"]
property var imageTexts: ["东北上", "东上南", "东南下","东下北","北上东", "上南东", "南下东","下北东","上东北", "南东上", "下东南","北东下"]
property var lstDetialTexts: ["X [东] Y [北] Z [上]","X [东] Y [上] Z [南]","X [东] Y [南] Z [下]","X [东] Y [下] Z [北]","X [北] Y [上] Z [东]","X [上] Y [南] Z [东]","X [南] Y [下] Z [东]","X [下] Y [北] Z [东]","X [上] Y [东] Z [北]","X [南] Y [东] Z [上]","X [下] Y [ 东] Z [南]","X [北] Y [东] Z [下]"]
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: ""}
ListElement{name:"方位3标定"; tips: "请放置到3方位"; _state: "0"; src: "./step3.png"; endTime: ""}
ListElement{name:"方位4标定"; tips: "请放置到4方位"; _state: "0"; src: "./step4.png"; endTime: ""}
ListElement{name:"方位5标定"; tips: "请放置到5方位"; _state: "0"; src: "./step5.png"; endTime: ""}
ListElement{name:"方位6标定"; tips: "请放置到6方位"; _state: "0"; src: "./step6.png"; endTime: ""}
ListElement{name:"方位7标定"; tips: "请放置到7方位"; _state: "0"; src: "./step7.png"; endTime: ""}
ListElement{name:"方位8标定"; tips: "请放置到8方位"; _state: "0"; src: "./step8.png"; endTime: ""}
ListElement{name:"方位9标定"; tips: "请放置到9方位"; _state: "0"; src: "./step9.png"; endTime: ""}
ListElement{name:"方位10标定"; tips: "请放置到10方位"; _state: "0"; src: "./step10.png"; endTime: ""}
ListElement{name:"方位11标定"; tips: "请放置到11方位"; _state: "0"; src: "./step11.png"; endTime: ""}
ListElement{name:"方位12标定"; tips: "请放置到12方位"; _state: "0"; src: "./step12.png"; endTime: ""}
}
Component.onCompleted: {
stopBd.connect(onStopBd)
taskActuatorManager.executeFinished.connect(onExecuteFinished)
}
onIsStartChanged: {
if (isStart) {
startSteps()
}
}
// 生成数组
function fillDetialTexts() {
for (var i = 0; i < imageTexts.length; ++i) {
var directions = imageTexts[i].split('');
var detialText = "X [" + directions[0] + "] Y [" + directions[1] + "] Z [" + directions[2] + "]";
lstDetialTexts.push(detialText);
}
}
function startSteps()
{
clearSteps()
task1State = "1"
currentStepIndex = 0
a_Digital = []
taskModel.get(curTaskIndex).state = task1State
tipText.visible = true
}
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
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.right: parent.right
anchors.rightMargin: 49
}
}
}
}
Rectangle{
id: stepText
anchors.left: stepLst.right
anchors.leftMargin: 10
anchors.right: parent.right
anchors.top: stepLst.top
anchors.bottom: stepLst.bottom
radius: 9
Image{
anchors.left: parent.left
anchors.leftMargin: 23
anchors.right: parent.right
anchors.rightMargin: 23
anchors.top: parent.top
anchors.topMargin: 24
anchors.bottom: parent.bottom
anchors.bottomMargin: 24
source: currentStepIndex > -1 ? "./resource/step1/"+ imageNames[currentStepIndex]+".JPG" : "./resource/step1/default.jpg"
QxText{
text: currentStepIndex > -1 ? imageTexts[currentStepIndex] : ""
anchors.top: parent.top
anchors.right: parent.right
anchors.rightMargin: 20
anchors.topMargin: 20
font.pixelSize: 25
font.bold: true
color: "#007EFF"
}
}
Rectangle{
id: tipText
width: 315
height: 170
radius: 19
color: "#FFFFFF"
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: "请放置到" + imageNames[currentStepIndex] + " " + imageTexts[currentStepIndex] + "方位"
}
}
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()
}
}
}
}
}
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})
}
function onStopBd(){
if(isStart)
{
stopExecute(stepInstructId)
clearSteps()
}
}
function onExecuteFinished(id)
{
if(id == stepInstructId && isStart)
{
a_Digital.push(common.getG("A_Digital"))
stepModel.get(currentStepIndex)._state = "2"
stepModel.get(currentStepIndex).endTime = Qt.formatDateTime(new Date(), "MM-dd hh:mm:ss")
if(currentStepIndex < stepModel.count-1)
{
tipText.visible = true
currentStepIndex++
currentIndex++
}
else{
writeACsv()
updateDxlsx()
exportFormula()
task1State = "2"
currentIndex = stepModel.count
currentStepIndex = -1
taskModel.get(curTaskIndex).state = task1State
reportJson["a_Digital"] = a_Digital
runNextStep()
skLayout.currentIndex = curTaskIndex
}
}
}
function exportFormula()
{
var ax_values = []
var ay_values = []
var az_values = []
for(var i = 0; i < a_Digital.length; i++)
{
var ax_value = !!a_Digital[i].x_Avalue ? parseFloat(a_Digital[i].x_Avalue) : 0
var ay_value = !!a_Digital[i].y_Avalue ? parseFloat(a_Digital[i].y_Avalue) : 0
var az_value = !!a_Digital[i].z_Avalue ? parseFloat(a_Digital[i].z_Avalue) : 0
ax_values.push(ax_value)
ay_values.push(ay_value)
az_values.push(az_value)
}
a_seri = [
[
parseFloat((ax_values[4] + ax_values[6] + ax_values[9] + ax_values[11]) /4).toFixed(6),
parseFloat((ay_values[0] + ay_values[2] + ay_values[5] + ay_values[7])/4).toFixed(6),
parseFloat((az_values[1] + az_values[3] + az_values[8] + az_values[10])/4).toFixed(6)
],
[
parseFloat((ax_values[7] + ax_values[10] - ax_values[5] - ax_values[8]) /4).toFixed(6),
parseFloat((ay_values[3] + ay_values[6] - ay_values[1] - ay_values[4]) /4).toFixed(6),
parseFloat((az_values[2] + az_values[11] - az_values[0] - az_values[9]) /4).toFixed(6)
]
]
var templateName = "MWD.xlsx"
calibrate.setAModel(firstPath + appPath + "/template/" + templateName,a_Digital)
}
function writeACsv()
{
// 创建CSV表头
const header = "X轴加表输出,X轴加表温度,Y轴加表输出,Y轴加表温度,Z轴加表输出,Z轴加表温度\n";
var csvData = header;
var filename = 'A_' + g_sn + "_" + Qt.formatDateTime(new Date(startTime), "yyyy_MM_dd_hh_mm_ss") + '.csv';
// 遍历a_Digital数组将每条结果写入CSV文件
for(var i = 0; i < a_Digital.length; i++)
{
csvData += a_Digital[i].x_Avalue +","+a_Digital[i].x_Atemp+","+a_Digital[i].y_Avalue+","+a_Digital[i].y_Atemp+","+a_Digital[i].z_Avalue+","+a_Digital[i].z_Atemp+'\n';
}
save_csv(filename, csvData);
}
function updateDxlsx()
{
var filename = "D_"+g_sn+ "_" + Qt.formatDateTime(new Date(startTime), "yyyy-MM-dd_hh-mm-ss") + ".xlsx"
overwrite_xlsx("template.xlsx", filename, templateStr());
}
function templateStr()
{
var data_str = ""
var xTempSum = 0
var yTempSum = 0
var zTempSum = 0
var mTempSum = 0
for( var i = 0; i < a_Digital.length; i++)
{
var ax_value = (a_Digital[i] && a_Digital[i].x_Avalue !== undefined) ? a_Digital[i].x_Avalue : ""
var ay_value = (a_Digital[i] && a_Digital[i].y_Avalue !== undefined) ? a_Digital[i].y_Avalue : ""
var az_value = (a_Digital[i] && a_Digital[i].z_Avalue !== undefined) ? a_Digital[i].z_Avalue : ""
var ax_temp = (a_Digital[i] && a_Digital[i].x_Atemp !== undefined) ? a_Digital[i].x_Atemp : ""
var ay_temp = (a_Digital[i] && a_Digital[i].y_Atemp !== undefined) ? a_Digital[i].y_Atemp : ""
var az_temp = (a_Digital[i] && a_Digital[i].z_Atemp !== undefined) ? a_Digital[i].z_Atemp : ""
var mx_value = (m_Digital[i] && m_Digital[i].x_Mvalue !== undefined) ? m_Digital[i].x_Mvalue : ""
var my_value = (m_Digital[i] && m_Digital[i].y_Mvalue !== undefined) ? m_Digital[i].y_Mvalue : ""
var mz_value = (m_Digital[i] && m_Digital[i].z_Mvalue !== undefined) ? m_Digital[i].z_Mvalue : ""
var mtemp = (m_Digital[i] && m_Digital[i].m_temp !== undefined) ? m_Digital[i].m_temp : ""
data_str += ax_value +","+ ay_value+"," + az_value+',';
data_str += mx_value +","+ my_value+","+ mz_value+'\n';
xTempSum += parseFloat(ax_temp)
yTempSum += parseFloat(ay_temp)
zTempSum += parseFloat(az_temp)
mTempSum += parseFloat(mtemp)
}
data_str += (xTempSum/a_Digital.length)+","+(yTempSum/a_Digital.length)+","+(zTempSum/a_Digital.length)+","+(mTempSum/m_Digital.length);
console.info("data_str",data_str)
return data_str;
}
}