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

404 lines
14 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 == 2
property var stepInstructId: ""
property var childStepIndex: 0
property var imageSoure: "./resource/step2/default.JPG"
property var imageText: ""
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"]
ListModel{
id: stepModel
}
Component.onCompleted: {
stopBd.connect(onStopBd)
taskActuatorManager.executeFinished.connect(onExecuteFinished)
clearSteps()
}
onIsStartChanged: {
if (isStart) {
startSteps()
}
}
function startSteps()
{
m_Digital = []
clearSteps()
task3State = "1"
currentStepIndex = 0
taskModel.get(curTaskIndex).state = task3State
tipText.visible = true
}
function clearSteps(){
tipText.visible = false
stepModel.clear()
currentStepIndex = -1
imageSoure = "./resource/step2/default.JPG"
imageText = ""
currentIndex = 0
for(var i = 0; i < hmhzModel.count; i++)
{
var handel = hmhzModel.get(i)
var detialText = ""
detialText += "X [" + handel.v2 + "] "
detialText += "Y [" + handel.v3 + "] "
detialText += "Z [" + handel.v4 + "]"
stepModel.append({ "_state": "0","detialText":detialText, "endTime": ""})
}
}
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: index > -1 ? imageNames[index] : ""
}
QxListText{
text: detialText
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: imageSoure
QxText{
text: imageText
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: "设备是否放置就绪?"
}
}
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: {
runHmhz()
}
}
}
}
}
property var tDelay: 6000
Timer {
id: getTimer
interval: tDelay; running: false; repeat: false
onTriggered: {
runStep()
currentStepIndex++
if (currentIndex < stepModel.count-1)
currentIndex++
console.info("currentIndex: " + currentIndex, "currentStepIndex: " + currentStepIndex,"stepModel.count",stepModel.count)
}
}
function makeImageSource(handel)
{
var imageName = ""
if(handel.v2 != "0")
{
imageName += "x"
}
if(handel.v3 != "0")
{
imageName += "y"
}
if(handel.v4 != "0")
{
imageName += "z"
}
imageSoure = "./resource/step2/" + imageName + ".JPG"
imageText = handel.v2 + "nT " + handel.v3 + "nT " + handel.v4 + "nT"
}
function runHmhz()
{
tipText.visible = false
var handel = hmhzModel.get(currentStepIndex)
stepModel.get(currentStepIndex)._state = "1"
makeImageSource(handel)
childStepIndex = 1
stepInstructId = execute("亥姆霍兹线圈设定",{"T":handel.v1,"X":handel.v2,"Y":handel.v3,"Z":handel.v4})
}
function runStep()
{
tipText.visible = false
var handel = taskModel.get(curTaskIndex)
stepModel.get(currentStepIndex)._state = "1"
var group = parseFloat(handel.v1)
var groupcount = parseFloat(handel.v3)
var total = group*groupcount
var firstName = handel.v5 == "数字量" ? "数字" : "模拟"
childStepIndex = 2
stepInstructId = execute(firstName+"加速度计采集",{"total":total})
}
function onStopBd(){
if(isStart)
{
stopExecute(stepInstructId)
clearSteps()
}
}
function onExecuteFinished(id)
{
if(id == stepInstructId && isStart)
{
if(currentStepIndex < stepModel.count)
{
if(childStepIndex == 1)
{
getTimer.start()
}
else
{
m_Digital.push(common.getG("A_Digital"))
stepModel.get(currentStepIndex-1)._state = "2"
stepModel.get(currentStepIndex-1).endTime = Qt.formatDateTime(new Date(), "MM-dd hh:mm:ss")
runHmhz()
}
}
else{
var a_Digital = common.getG("A_Digital")
m_Digital.push(a_Digital)
stepModel.get(currentStepIndex-1)._state = "2"
stepModel.get(currentStepIndex-1).endTime = Qt.formatDateTime(new Date(), "MM-dd hh:mm:ss")
writeMCsv()
updateDxlsx()
exportFormula()
currentIndex = stepModel.count
currentStepIndex = -1
imageSoure = "./resource/step2/default.JPG"
imageText = ""
task3State = "2"
taskModel.get(curTaskIndex).state = task3State
reportJson["m_Digital"] = m_Digital
execute("亥姆霍兹线圈设定",{"T":800,"X":"NAN","Y":"NAN","Z":"NAN"})
runNextStep()
skLayout.currentIndex = curTaskIndex
}
}
}
function writeMCsv()
{
// 创建CSV表头
const header = "X轴磁通门输出,Y轴磁通门输出,Z轴磁通门输出,磁通门温度输出\n";
var csvData = header;
var filename = 'M_' + g_sn + "_" + Qt.formatDateTime(new Date(startTime), "yyyy-MM-dd_hh-mm-ss") + '.csv';
// 遍历m_Digital数组将每条结果写入CSV文件
for(var i = 0; i < m_Digital.length; i++)
{
csvData += m_Digital[i].x_Mvalue +","+m_Digital[i].y_Mvalue+","+m_Digital[i].z_Mvalue+","+m_Digital[i].m_temp+'\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 exportFormula()
{
var filename = "FM_"+g_sn+ "_" + Qt.formatDateTime(new Date(startTime), "yyyy-MM-dd_hh-mm-ss") + ".csv"
var mx_values = []
var my_values = []
var mz_values = []
for(var i = 0; i < m_Digital.length; i++)
{
var mx_value = !!m_Digital[i].x_Mvalue ? parseFloat(m_Digital[i].x_Mvalue) : 0
var my_value = !!m_Digital[i].y_Mvalue ? parseFloat(m_Digital[i].y_Mvalue) : 0
var mz_value = !!m_Digital[i].z_Mvalue ? parseFloat(m_Digital[i].z_Mvalue) : 0
mx_values.push(mx_value)
my_values.push(my_value)
mz_values.push(mz_value)
}
m_seri = [
[
parseFloat((mx_values[0] + mx_values[1] + mx_values[2] + mx_values[3]) /4).toFixed(6),
parseFloat((my_values[8] + my_values[9] + my_values[10] + my_values[11])/4).toFixed(6),
parseFloat((mz_values[4] + mz_values[5] + mz_values[6] + mz_values[7])/4).toFixed(6)
],
[
parseFloat((mx_values[7] + mx_values[10] - mx_values[5] - mx_values[8]) /4).toFixed(6),
parseFloat((my_values[3] + my_values[6] - my_values[1] - my_values[4]) /4).toFixed(6),
parseFloat((mz_values[2] + mz_values[11] - mz_values[0] - mz_values[9]) /4).toFixed(6)
]
]
var templateName = "MWD.xlsx"
calibrate.setMModel(firstPath + appPath + "/template/" + templateName, m_Digital)
var csvData = "模型系数,X轴,Y轴,Z轴\n";
for (var i = 0; i < m_seri.length; i++) {
if(i == 0)
csvData += "零偏,";
else if(i == 1)
csvData += "标度因数,";
csvData += m_seri[i].join(","); // Join the inner array elements with ","
if (i < m_seri.length - 1) {
csvData += "\n"; // Add new line except for the last inner array
}
}
save_csv(filename, csvData);
}
function templateStr()
{
var data_str = ""
var xTempSum = 0
var yTempSum = 0
var zTempSum = 0
var mTempSum = 0
for( var i = 0; i < m_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;
}
}