Files
cavity_LIBS/msvc-deps/patch9.ps1
T
2026-11-06 14:45:09 +08:00

49 lines
2.6 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ===========================================================================
# 补丁 v9:+1/-1/+0.1/-0.1 四个槽改成“先读界面当前值,再加减”
# 避免用户手工输入后被成员变量里的旧值覆盖
# ===========================================================================
$ErrorActionPreference = 'Stop'
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$root = 'D:\Code\cavity_LIBS_system-master'
$cpp = Join-Path $root 'mainwindow.cpp'
$text = [System.IO.File]::ReadAllText($cpp, [System.Text.Encoding]::UTF8)
if ($text.Contains("`r")) { throw '文件含 CR,非预期' }
function Insert-AfterBranch([string]$src, [string]$selector, [string]$var, [string]$widget) {
$pattern = '(?m)^( if \(selectedLineEdit == "' + $selector + '"\)\r?\n \{\r?\n)'
$insert = '$1' + ' // 以界面当前值为基准(支持先手工输入,再用按钮微调)' + "`n" +
' ' + $var + ' = ui->' + $widget + '->text().toDouble();' + "`n"
$matches = [regex]::Matches($src, $pattern)
if ($matches.Count -eq 0) { throw "未找到分支:$selector" }
return @{ Text = [regex]::Replace($src, $pattern, $insert); Count = $matches.Count }
}
$r1 = Insert-AfterBranch $text 'rotation_angle' 'steppingAngle' 'le_rotation_angle'
$r2 = Insert-AfterBranch $r1.Text 'max_angle_depression' 'maxAngleDepression' 'le_max_angle_depression'
$r3 = Insert-AfterBranch $r2.Text 'max_elevation' 'maxElevation' 'le_max_elevation'
Write-Host (" 插入处数:rotation_angle={0} max_angle_depression={1} max_elevation={2}" -f `
$r1.Count, $r2.Count, $r3.Count)
[System.IO.File]::WriteAllText($cpp, $r3.Text, $utf8NoBom)
# ---- 校验 ----
$b = [System.IO.File]::ReadAllBytes($cpp)
$s = [System.Text.Encoding]::UTF8.GetString($b)
Write-Host ''
Write-Host '==== 校验 ===='
Write-Host (" 行数={0} 汉字={1} 非法UTF8={2} {{={3} }}={4}" -f `
($s -split "`n").Count, ([regex]::Matches($s,'[\u4e00-\u9fff]')).Count,
([regex]::Matches($s,[char]0xFFFD)).Count,
([regex]::Matches($s,'\{')).Count, ([regex]::Matches($s,'\}')).Count)
foreach ($w in 'le_rotation_angle','le_max_angle_depression','le_max_elevation') {
Write-Host (" ui->{0}->text().toDouble() 出现 {1} 次" -f $w, ([regex]::Matches($s, [regex]::Escape("ui->$w->text().toDouble()"))).Count)
}
$nl = $s -split "`n"
$fn = 0
for ($i = 1; $i -le $nl.Count; $i++) { if ($nl[$i-1] -match 'void MainWindow::on_but_angle_add_2_clicked') { $fn = $i; break } }
Write-Host ' add_2 片段:'
for ($i = $fn; $i -le $fn + 12; $i++) { Write-Host (" {0,4} {1}" -f $i, $nl[$i-1]) }