mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-06-13 16:23:14 +02:00
Compare commits
70 Commits
f16cf7dac8
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 918db632ed | |||
| f465b33e2b | |||
| 492528136e | |||
| 564a0e64a4 | |||
| 7f5a42a055 | |||
| 14d4aa772b | |||
| 81419bd27d | |||
| ebefc269af | |||
| c6bfd46981 | |||
| 998c5e8a0d | |||
| ae382f6b12 | |||
| d4061d17fa | |||
| fb8c86ec12 | |||
| d62479e6e4 | |||
| 1a4bb91285 | |||
| aa96d5e7df | |||
| e63c303078 | |||
| a8e408ad39 | |||
| 0eb3e1e436 | |||
| ba6320bff8 | |||
| 86b5d7ac95 | |||
| 19e99aab02 | |||
| 44f0abbb56 | |||
| e7787daa2c | |||
| c7fd3416f6 | |||
| b782a1612a | |||
| 2fdbc3c243 | |||
| a219c3f587 | |||
| 6b3b55b0e1 | |||
| 36d0121038 | |||
| 8235ecdbc9 | |||
| b6e4cd4786 | |||
| fb35027624 | |||
| 08a441d1f6 | |||
| e9840728b4 | |||
| ffbcd12d9b | |||
| 0a124f6695 | |||
| 3f6f99b50f | |||
| 42b64a7f0a | |||
| 361719ca74 | |||
| 181e2b555d | |||
| 420512595d | |||
| 9b4bed361d | |||
| 339bc8700b | |||
| 87d5ae5580 | |||
| 1070179617 | |||
| 6c4711a8d0 | |||
| 8a8a338a2e | |||
| 407cc7a4c2 | |||
| 5cb8930732 | |||
| a24acfac24 | |||
| 8b0b1d10d4 | |||
| 57dfa28674 | |||
| 3848c7821a | |||
| 1572c23d51 | |||
| e234f063f8 | |||
| be21604ad0 | |||
| e1ccc1e568 | |||
| e202b5bc2b | |||
| 2b7e62f901 | |||
| 23e8258ae1 | |||
| 457d265f0a | |||
| cd76b6a1d6 | |||
| b522a94556 | |||
| 399bc0e897 | |||
| de9eeed542 | |||
| c071e92c58 | |||
| d22e4abf96 | |||
| 38b91e8083 | |||
| 19704cf5ca |
@@ -18,7 +18,6 @@ jobs:
|
|||||||
build-msi:
|
build-msi:
|
||||||
name: Build MSI with WiX v7
|
name: Build MSI with WiX v7
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
|
|
||||||
# Only runs if Windows Build succeeded (or triggered manually)
|
# Only runs if Windows Build succeeded (or triggered manually)
|
||||||
if: >
|
if: >
|
||||||
github.event_name == 'workflow_dispatch' ||
|
github.event_name == 'workflow_dispatch' ||
|
||||||
@@ -27,10 +26,9 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: write
|
contents: write
|
||||||
pages: write
|
pages: write
|
||||||
id-token: write
|
id-token: write # Required by SignPath
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 1. Checkout (to retrieve QElectroTech.wxs and sources)
|
# 1. Checkout (to retrieve QElectroTech.wxs and sources)
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
@@ -41,12 +39,16 @@ jobs:
|
|||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 2. Download the portable artifact from the main build
|
# 2. Download the portable artifact from the main build
|
||||||
|
# Requires windows-build.yml to upload an artifact named
|
||||||
|
# "qelectrotech-windows-portable" (fixed name)
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Download portable artifact
|
- name: Download portable artifact
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: qelectrotech-windows-portable
|
name: qelectrotech-windows-portable
|
||||||
path: artifact\files
|
path: artifact\files
|
||||||
|
# workflow_run => use the triggering run's ID
|
||||||
|
# workflow_dispatch => use input run_id if provided, otherwise current run
|
||||||
run-id: ${{ github.event.workflow_run.id || github.event.inputs.run_id || github.run_id }}
|
run-id: ${{ github.event.workflow_run.id || github.event.inputs.run_id || github.run_id }}
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
repository: ${{ github.repository }}
|
repository: ${{ github.repository }}
|
||||||
@@ -58,10 +60,12 @@ jobs:
|
|||||||
id: version
|
id: version
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
|
# Version from qetversion.cpp (same logic as windows-build.yml)
|
||||||
$src = Get-Content "sources\qetversion.cpp" -Raw -ErrorAction SilentlyContinue
|
$src = Get-Content "sources\qetversion.cpp" -Raw -ErrorAction SilentlyContinue
|
||||||
if ($src -match 'return QVersionNumber\{([^}]+)\}') {
|
if ($src -match 'return QVersionNumber\{([^}]+)\}') {
|
||||||
$ver = $Matches[1] -replace '\s','' -replace ',','.'
|
$ver = $Matches[1] -replace '\s','' -replace ',','.'
|
||||||
} else {
|
} else {
|
||||||
|
# Fallback: CMakeLists.txt
|
||||||
$cmake = Get-Content "CMakeLists.txt" -Raw
|
$cmake = Get-Content "CMakeLists.txt" -Raw
|
||||||
if ($cmake -match 'project\s*\([^)]*VERSION\s+([\d]+\.[\d]+\.[\d]+)') {
|
if ($cmake -match 'project\s*\([^)]*VERSION\s+([\d]+\.[\d]+\.[\d]+)') {
|
||||||
$ver = $Matches[1]
|
$ver = $Matches[1]
|
||||||
@@ -69,42 +73,52 @@ jobs:
|
|||||||
$ver = "0.0.0"
|
$ver = "0.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Numeric MSI version: 4 digits required (e.g. 0.100.1.0)
|
||||||
$verMsi = "$ver.0"
|
$verMsi = "$ver.0"
|
||||||
|
|
||||||
|
# Short SHA for the display version
|
||||||
$sha = git rev-parse --short HEAD 2>$null
|
$sha = git rev-parse --short HEAD 2>$null
|
||||||
if (-not $sha) { $sha = "unknown" }
|
if (-not $sha) { $sha = "unknown" }
|
||||||
|
|
||||||
|
# Cumulative revision number (same calculation as windows-build.yml)
|
||||||
$count = git rev-list HEAD --count 2>$null
|
$count = git rev-list HEAD --count 2>$null
|
||||||
$rev = [int]$count + 473
|
$rev = [int]$count + 473
|
||||||
$verDisplay = "${ver}-r${rev}-${sha}_x86_64-win64"
|
|
||||||
# Generate a unique ProductCode GUID from the commit SHA
|
|
||||||
# This ensures MajorUpgrade always triggers, even for same-version builds
|
|
||||||
$fullSha = git rev-parse HEAD 2>$null
|
|
||||||
if (-not $fullSha) { $fullSha = [System.Guid]::NewGuid().ToString() }
|
|
||||||
$bytes = [System.Text.Encoding]::UTF8.GetBytes($fullSha)
|
|
||||||
$md5 = [System.Security.Cryptography.MD5]::Create().ComputeHash($bytes)
|
|
||||||
$guidBytes = [byte[]]$md5[0..15]
|
|
||||||
$productGuid = [System.Guid]::new($guidBytes).ToString().ToUpper()
|
|
||||||
|
|
||||||
echo "VERSION_MSI=$verMsi" >> $env:GITHUB_OUTPUT
|
$verDisplay = "${ver}-r${rev}-${sha}_x86_64-win64"
|
||||||
|
|
||||||
|
echo "VERSION_MSI=$verMsi" >> $env:GITHUB_OUTPUT
|
||||||
echo "VERSION_DISPLAY=$verDisplay" >> $env:GITHUB_OUTPUT
|
echo "VERSION_DISPLAY=$verDisplay" >> $env:GITHUB_OUTPUT
|
||||||
echo "PRODUCT_GUID=$productGuid" >> $env:GITHUB_OUTPUT
|
|
||||||
Write-Host "Version MSI : $verMsi"
|
Write-Host "Version MSI : $verMsi"
|
||||||
Write-Host "Version display : $verDisplay"
|
Write-Host "Version display : $verDisplay"
|
||||||
Write-Host "Product GUID : $productGuid"
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 4. Install WiX v7, accept EULA and install WixUI extension
|
# 4. Install WiX v7, accept EULA and install WixUI extension
|
||||||
|
# All done in one step: PATH is updated within the same step
|
||||||
|
# so wix is immediately available for eula and extension commands
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Install WiX v7
|
- name: Install WiX v7
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
dotnet tool install --global wix --version 7.0.0
|
dotnet tool install --global wix --version 7.0.0
|
||||||
|
|
||||||
|
# Update PATH immediately for the rest of this step
|
||||||
$toolsPath = [System.IO.Path]::Combine($env:USERPROFILE, '.dotnet', 'tools')
|
$toolsPath = [System.IO.Path]::Combine($env:USERPROFILE, '.dotnet', 'tools')
|
||||||
$env:PATH = "$toolsPath;$env:PATH"
|
$env:PATH = "$toolsPath;$env:PATH"
|
||||||
|
|
||||||
|
# Also export for subsequent steps
|
||||||
echo $toolsPath >> $env:GITHUB_PATH
|
echo $toolsPath >> $env:GITHUB_PATH
|
||||||
|
|
||||||
|
# Accept OSMF EULA (official CI/CD method: writes a sentinel file)
|
||||||
wix eula accept wix7
|
wix eula accept wix7
|
||||||
|
|
||||||
|
# Install WixUI extension
|
||||||
wix extension add WixToolset.UI.wixext/7.0.0
|
wix extension add WixToolset.UI.wixext/7.0.0
|
||||||
|
|
||||||
|
# Install WixUtil extension (required for custom actions: Binary:Wix4UtilCA_*)
|
||||||
wix extension add WixToolset.Util.wixext/7.0.0
|
wix extension add WixToolset.Util.wixext/7.0.0
|
||||||
Write-Host "WiX v7 installed, EULA accepted, UI extension added."
|
|
||||||
|
Write-Host "WiX v7 installed, EULA accepted, UI + Util extensions added."
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 5. Check that the WXS file exists in the repository
|
# 5. Check that the WXS file exists in the repository
|
||||||
@@ -115,6 +129,8 @@ jobs:
|
|||||||
$wxs = "build-aux\windows\QElectroTech.wxs"
|
$wxs = "build-aux\windows\QElectroTech.wxs"
|
||||||
if (-not (Test-Path $wxs)) {
|
if (-not (Test-Path $wxs)) {
|
||||||
Write-Error "WXS file not found: $wxs"
|
Write-Error "WXS file not found: $wxs"
|
||||||
|
Write-Host "Contents of build-aux\windows\ :"
|
||||||
|
Get-ChildItem "build-aux\windows\" -ErrorAction SilentlyContinue
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
Write-Host "WXS found: $wxs"
|
Write-Host "WXS found: $wxs"
|
||||||
@@ -129,8 +145,10 @@ jobs:
|
|||||||
Get-ChildItem -Path "artifact\files" -Depth 2 |
|
Get-ChildItem -Path "artifact\files" -Depth 2 |
|
||||||
Select-Object FullName | Format-Table -AutoSize
|
Select-Object FullName | Format-Table -AutoSize
|
||||||
|
|
||||||
|
# Search for qelectrotech.exe in the artifact
|
||||||
$exe = Get-ChildItem -Path "artifact\files" -Filter "qelectrotech.exe" -Recurse | Select-Object -First 1
|
$exe = Get-ChildItem -Path "artifact\files" -Filter "qelectrotech.exe" -Recurse | Select-Object -First 1
|
||||||
if (-not $exe) {
|
if (-not $exe) {
|
||||||
|
# Also try QElectroTech.exe (capital Q)
|
||||||
$exe = Get-ChildItem -Path "artifact\files" -Filter "QElectroTech.exe" -Recurse | Select-Object -First 1
|
$exe = Get-ChildItem -Path "artifact\files" -Filter "QElectroTech.exe" -Recurse | Select-Object -First 1
|
||||||
}
|
}
|
||||||
if (-not $exe) {
|
if (-not $exe) {
|
||||||
@@ -138,30 +156,40 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
Write-Host "Executable: $($exe.FullName) ($([math]::Round($exe.Length/1MB,1)) MB)"
|
Write-Host "Executable: $($exe.FullName) ($([math]::Round($exe.Length/1MB,1)) MB)"
|
||||||
$binDir = $exe.Directory.FullName
|
|
||||||
$filesDir = Split-Path $binDir -Parent
|
# FilesDir = folder containing bin\
|
||||||
|
$binDir = $exe.Directory.FullName
|
||||||
|
$filesDir = Split-Path $binDir -Parent
|
||||||
echo "FILES_DIR=$filesDir" >> $env:GITHUB_ENV
|
echo "FILES_DIR=$filesDir" >> $env:GITHUB_ENV
|
||||||
Write-Host "FILES_DIR: $filesDir"
|
Write-Host "FILES_DIR: $filesDir"
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 7. Convert LICENSE (GPL-2) to RTF for the WixUI licence screen
|
# 7. Convert LICENSE (GPL-2) to RTF for the WixUI licence screen
|
||||||
|
# RTF is the only format accepted by Windows Installer.
|
||||||
|
# The conversion wraps plain text lines in basic RTF markup.
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Convert LICENSE to RTF
|
- name: Convert LICENSE to RTF
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$licSrc = "LICENSE"
|
$licSrc = "LICENSE"
|
||||||
$licRtf = "$env:TEMP\License.rtf"
|
$licRtf = "$env:TEMP\License.rtf"
|
||||||
|
|
||||||
if (-not (Test-Path $licSrc)) {
|
if (-not (Test-Path $licSrc)) {
|
||||||
Write-Error "LICENSE file not found in repository root"
|
Write-Error "LICENSE file not found in repository root"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$lines = Get-Content $licSrc -Encoding UTF8
|
$lines = Get-Content $licSrc -Encoding UTF8
|
||||||
|
|
||||||
|
# RTF header — Courier New, 9pt, black
|
||||||
$rtf = New-Object System.Text.StringBuilder
|
$rtf = New-Object System.Text.StringBuilder
|
||||||
[void]$rtf.AppendLine('{\rtf1\ansi\ansicpg1252\deff0')
|
[void]$rtf.AppendLine('{\rtf1\ansi\ansicpg1252\deff0')
|
||||||
[void]$rtf.AppendLine('{\fonttbl{\f0\fmodern\fprq1\fcharset0 Courier New;}}')
|
[void]$rtf.AppendLine('{\fonttbl{\f0\fmodern\fprq1\fcharset0 Courier New;}}')
|
||||||
[void]$rtf.AppendLine('{\colortbl;\red0\green0\blue0;}')
|
[void]$rtf.AppendLine('{\colortbl;\red0\green0\blue0;}')
|
||||||
[void]$rtf.AppendLine('\f0\fs18\cf1')
|
[void]$rtf.AppendLine('\f0\fs18\cf1')
|
||||||
|
|
||||||
foreach ($line in $lines) {
|
foreach ($line in $lines) {
|
||||||
|
# Escape RTF special characters
|
||||||
$escaped = $line `
|
$escaped = $line `
|
||||||
-replace '\\', '\\\\' `
|
-replace '\\', '\\\\' `
|
||||||
-replace '\{', '\{' `
|
-replace '\{', '\{' `
|
||||||
@@ -169,30 +197,29 @@ jobs:
|
|||||||
[void]$rtf.AppendLine("$escaped\par")
|
[void]$rtf.AppendLine("$escaped\par")
|
||||||
}
|
}
|
||||||
[void]$rtf.AppendLine('}')
|
[void]$rtf.AppendLine('}')
|
||||||
|
|
||||||
[System.IO.File]::WriteAllText($licRtf, $rtf.ToString(), [System.Text.Encoding]::ASCII)
|
[System.IO.File]::WriteAllText($licRtf, $rtf.ToString(), [System.Text.Encoding]::ASCII)
|
||||||
echo "LICENSE_RTF=$licRtf" >> $env:GITHUB_ENV
|
echo "LICENSE_RTF=$licRtf" >> $env:GITHUB_ENV
|
||||||
Write-Host "License.rtf generated: $licRtf ($([math]::Round((Get-Item $licRtf).Length/1KB,1)) KB)"
|
Write-Host "License.rtf generated: $licRtf ($([math]::Round((Get-Item $licRtf).Length/1KB,1)) KB)"
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 8. Remove Lancer QET.bat from the artifact
|
# 8. Replace Lancer QET.bat with the MSI-specific version
|
||||||
# The MSI does not use the .bat: shortcuts point directly to
|
# The portable version uses relative paths suited for the zip.
|
||||||
# qelectrotech.exe, and elements\ is set read-only via a
|
# The MSI version uses %~dp0 to resolve paths relative to
|
||||||
# CustomAction in QElectroTech.wxs.
|
# the installation directory in Program Files.
|
||||||
# The .bat is kept as-is in the ZIP portable build.
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Remove Lancer QET.bat from artifact
|
- name: Replace Lancer QET.bat for MSI
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
$bat = "$env:FILES_DIR\Lancer QET.bat"
|
$bat = "$env:FILES_DIR\Lancer QET.bat"
|
||||||
if (Test-Path $bat) {
|
$content = "@echo off`r`nstart `"`" `"%~dp0bin\qelectrotech.exe`" --common-elements-dir=`"%~dp0elements/`" --common-tbt-dir=`"%~dp0titleblocks/`" --lang-dir=`"%~dp0lang/`" -style windowsvista`r`n"
|
||||||
Remove-Item $bat -Force
|
[System.IO.File]::WriteAllText($bat, $content, [System.Text.Encoding]::ASCII)
|
||||||
Write-Host "Lancer QET.bat removed from artifact (MSI uses direct exe shortcut)."
|
Write-Host "Lancer QET.bat replaced for MSI installation."
|
||||||
} else {
|
Write-Host "=== Content of new Lancer QET.bat ==="
|
||||||
Write-Host "Lancer QET.bat not found in artifact (already absent)."
|
Get-Content $bat
|
||||||
}
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 9. Build the MSI
|
# 9. Build the MSI (unsigned)
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Build MSI
|
- name: Build MSI
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
@@ -204,22 +231,31 @@ jobs:
|
|||||||
$wxs = "build-aux\windows\QElectroTech.wxs"
|
$wxs = "build-aux\windows\QElectroTech.wxs"
|
||||||
$outputName = "QElectroTech-${verDisplay}.msi"
|
$outputName = "QElectroTech-${verDisplay}.msi"
|
||||||
|
|
||||||
|
# Deterministic ProductCode GUID (UUID v5) based on version.
|
||||||
|
# Same version => same GUID (required for MSI repair/uninstall).
|
||||||
|
# Different version => different GUID (triggers a proper upgrade).
|
||||||
|
$seed = "qelectrotech-msi-$version"
|
||||||
|
$sha1 = [System.Security.Cryptography.SHA1]::Create()
|
||||||
|
$hash = $sha1.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($seed))
|
||||||
|
$hash[6] = ($hash[6] -band 0x0F) -bor 0x50 # UUID version 5
|
||||||
|
$hash[8] = ($hash[8] -band 0x3F) -bor 0x80 # RFC4122 variant
|
||||||
|
$productCode = "{$([System.Guid]::new([byte[]]$hash[0..15]).ToString().ToUpper())}"
|
||||||
|
|
||||||
New-Item -ItemType Directory -Force -Path "dist" | Out-Null
|
New-Item -ItemType Directory -Force -Path "dist" | Out-Null
|
||||||
|
|
||||||
Write-Host "=== wix build ==="
|
Write-Host "=== wix build ==="
|
||||||
Write-Host " WXS : $wxs"
|
Write-Host " WXS : $wxs"
|
||||||
Write-Host " Version : $version"
|
Write-Host " Version : $version"
|
||||||
Write-Host " FilesDir : $filesDir"
|
Write-Host " ProductCode : $productCode"
|
||||||
Write-Host " LicenseRtf : $licRtf"
|
Write-Host " FilesDir : $filesDir"
|
||||||
Write-Host " Output : dist\$outputName"
|
Write-Host " LicenseRtf : $licRtf"
|
||||||
|
Write-Host " Output : dist\$outputName"
|
||||||
$productGuid = "${{ steps.version.outputs.PRODUCT_GUID }}"
|
|
||||||
|
|
||||||
wix build $wxs `
|
wix build $wxs `
|
||||||
-arch x64 `
|
-arch x64 `
|
||||||
-d "Version=$version" `
|
-d "Version=$version" `
|
||||||
-d "ProductVersion=$verDisplay" `
|
-d "ProductVersion=$verDisplay" `
|
||||||
-d "ProductCode=$productGuid" `
|
-d "ProductCode=$productCode" `
|
||||||
-d "FilesDir=$filesDir" `
|
-d "FilesDir=$filesDir" `
|
||||||
-d "LicenseRtf=$licRtf" `
|
-d "LicenseRtf=$licRtf" `
|
||||||
-ext WixToolset.UI.wixext `
|
-ext WixToolset.UI.wixext `
|
||||||
@@ -230,40 +266,50 @@ jobs:
|
|||||||
Write-Error "MSI not generated: dist\$outputName"
|
Write-Error "MSI not generated: dist\$outputName"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
$size = [math]::Round((Get-Item "dist\$outputName").Length / 1MB, 1)
|
$size = [math]::Round((Get-Item "dist\$outputName").Length / 1MB, 1)
|
||||||
Write-Host "MSI generated: dist\$outputName ($size MB) ✓"
|
Write-Host "MSI generated: dist\$outputName ($size MB) ✓"
|
||||||
echo "MSI_NAME=$outputName" >> $env:GITHUB_ENV
|
echo "MSI_NAME=$outputName" >> $env:GITHUB_ENV
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 10. Sign the MSI with SignPath
|
# 9b. Upload unsigned MSI as artifact (required by SignPath)
|
||||||
|
# SignPath fetches artifacts directly from GitHub Actions,
|
||||||
|
# so the MSI must be uploaded before the signing request.
|
||||||
|
# We capture the artifact-id output for use by SignPath.
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Install SignPath PowerShell module
|
- name: Upload unsigned MSI artifact (pre-signing)
|
||||||
shell: pwsh
|
id: upload_unsigned
|
||||||
run: |
|
uses: actions/upload-artifact@v4
|
||||||
Install-Module -Name SignPath -Force -Scope CurrentUser
|
with:
|
||||||
|
name: qelectrotech-windows-msi-unsigned
|
||||||
- name: Sign MSI with SignPath
|
path: dist\*.msi
|
||||||
shell: pwsh
|
retention-days: 1
|
||||||
run: |
|
if-no-files-found: error
|
||||||
$msi = Get-ChildItem "$env:GITHUB_WORKSPACE\dist\*.msi" | Select-Object -First 1
|
|
||||||
if (-not $msi) {
|
|
||||||
Write-Error "No .msi found in dist/"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
Write-Host "Signing: $($msi.FullName)"
|
|
||||||
Submit-SigningRequest `
|
|
||||||
-InputArtifactPath $msi.FullName `
|
|
||||||
-ApiToken "${{ secrets.SIGNPATH_API_TOKEN }}" `
|
|
||||||
-OrganizationId "${{ secrets.SIGNPATH_ORGANIZATION_ID }}" `
|
|
||||||
-ProjectSlug "MSI" `
|
|
||||||
-SigningPolicySlug "test-signing" `
|
|
||||||
-OutputArtifactPath $msi.FullName `
|
|
||||||
-Force `
|
|
||||||
-WaitForCompletion
|
|
||||||
Write-Host "Signing complete: $($msi.Name)"
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 11. Upload the MSI artifact
|
# 9c. Submit signing request to SignPath (OSS organization)
|
||||||
|
# Prerequisites:
|
||||||
|
# - SIGNPATH_API_TOKEN : CI user token from the OSS org
|
||||||
|
# - SIGNPATH_ORGANIZATION_ID : Organization ID of the OSS org
|
||||||
|
# (visible in app.signpath.io → Settings after accepting
|
||||||
|
# the OSS invitation)
|
||||||
|
# The action downloads the signed MSI and places it in
|
||||||
|
# dist/ (overwriting the unsigned one).
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
- name: Sign MSI via SignPath
|
||||||
|
uses: signpath/github-action-submit-signing-request@v1
|
||||||
|
with:
|
||||||
|
api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
|
||||||
|
organization-id: ${{ secrets.SIGNPATH_ORGANIZATION_ID }}
|
||||||
|
project-slug: 'qelectrotech-source-mirror'
|
||||||
|
signing-policy-slug: 'test-signing'
|
||||||
|
artifact-configuration-slug: 'MSI'
|
||||||
|
github-artifact-id: ${{ steps.upload_unsigned.outputs.artifact-id }}
|
||||||
|
wait-for-completion: true
|
||||||
|
output-artifact-directory: 'dist\'
|
||||||
|
|
||||||
|
# ----------------------------------------------------------------
|
||||||
|
# 10. Upload the signed MSI artifact
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Upload MSI artifact
|
- name: Upload MSI artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
@@ -284,9 +330,9 @@ jobs:
|
|||||||
gh release view nightly --repo "$REPO" --json assets \
|
gh release view nightly --repo "$REPO" --json assets \
|
||||||
--jq '.assets[] | select(.name | test("\\.msi$")) | .name' \
|
--jq '.assets[] | select(.name | test("\\.msi$")) | .name' \
|
||||||
| while read -r name; do
|
| while read -r name; do
|
||||||
echo "Deleting old asset: $name"
|
echo "Deleting old asset: $name"
|
||||||
gh release delete-asset nightly "$name" --repo "$REPO" --yes
|
gh release delete-asset nightly "$name" --repo "$REPO" --yes
|
||||||
done
|
done
|
||||||
echo "Old .msi assets deleted."
|
echo "Old .msi assets deleted."
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
@@ -307,18 +353,20 @@ jobs:
|
|||||||
shell: pwsh
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
Write-Host "=== MSI build summary ==="
|
Write-Host "=== MSI build summary ==="
|
||||||
Write-Host "Version : ${{ steps.version.outputs.VERSION_DISPLAY }}"
|
Write-Host "Version : ${{ steps.version.outputs.VERSION_DISPLAY }}"
|
||||||
Write-Host "WiX : v7.0.0"
|
Write-Host "WiX : v7.0.0"
|
||||||
Write-Host "Runner image : ${{ runner.os }} / ${{ runner.arch }}"
|
Write-Host "Signing : SignPath OSS"
|
||||||
|
Write-Host "Runner : ${{ runner.os }} / ${{ runner.arch }}"
|
||||||
if (Test-Path "dist\$env:MSI_NAME") {
|
if (Test-Path "dist\$env:MSI_NAME") {
|
||||||
$size = [math]::Round((Get-Item "dist\$env:MSI_NAME").Length / 1MB, 1)
|
$size = [math]::Round((Get-Item "dist\$env:MSI_NAME").Length / 1MB, 1)
|
||||||
Write-Host "MSI : $env:MSI_NAME ($size MB) ✓"
|
Write-Host "MSI : $env:MSI_NAME ($size MB) ✓"
|
||||||
} else {
|
} else {
|
||||||
Write-Host "MSI : FAILED ✗"
|
Write-Host "MSI : FAILED ✗"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
# 13. Generate and deploy the GitHub Pages download page
|
# 13. Generate and deploy the GitHub Pages download page
|
||||||
|
# Toutes les URLs sont connues ici (exe, zip, msi).
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
- name: Checkout (for generate-page.py)
|
- name: Checkout (for generate-page.py)
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -334,23 +382,31 @@ jobs:
|
|||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO="${{ github.repository }}"
|
REPO="${{ github.repository }}"
|
||||||
|
|
||||||
|
# Fetch asset names from the nightly release (source of truth)
|
||||||
ASSETS=$(gh release view nightly --repo "$REPO" --json assets --jq '.assets[].name')
|
ASSETS=$(gh release view nightly --repo "$REPO" --json assets --jq '.assets[].name')
|
||||||
|
|
||||||
EXE_NAME=$(echo "$ASSETS" | grep '\.exe$' | head -1)
|
EXE_NAME=$(echo "$ASSETS" | grep '\.exe$' | head -1)
|
||||||
ZIP_NAME=$(echo "$ASSETS" | grep '\.zip$' | head -1)
|
ZIP_NAME=$(echo "$ASSETS" | grep '\.zip$' | head -1)
|
||||||
MSI_NAME=$(echo "$ASSETS" | grep '\.msi$' | head -1 || echo "")
|
MSI_NAME=$(echo "$ASSETS" | grep '\.msi$' | head -1 || echo "")
|
||||||
|
|
||||||
BASE="https://github.com/$REPO/releases/download/nightly"
|
BASE="https://github.com/$REPO/releases/download/nightly"
|
||||||
INSTALLER_URL="$BASE/$EXE_NAME"
|
INSTALLER_URL="$BASE/$EXE_NAME"
|
||||||
PORTABLE_URL="$BASE/$ZIP_NAME"
|
PORTABLE_URL="$BASE/$ZIP_NAME"
|
||||||
MSI_URL=""
|
MSI_URL=""
|
||||||
[ -n "$MSI_NAME" ] && MSI_URL="$BASE/$MSI_NAME"
|
[ -n "$MSI_NAME" ] && MSI_URL="$BASE/$MSI_NAME"
|
||||||
|
|
||||||
SHA="${{ github.event.workflow_run.head_sha || github.sha }}"
|
SHA="${{ github.event.workflow_run.head_sha || github.sha }}"
|
||||||
SHORT="${SHA:0:7}"
|
SHORT="${SHA:0:7}"
|
||||||
DATE=$(date -u '+%Y-%m-%d %H:%M UTC')
|
DATE=$(date -u '+%Y-%m-%d %H:%M UTC')
|
||||||
RUN_URL="https://github.com/$REPO/actions/runs/${{ github.run_id }}"
|
RUN_URL="https://github.com/$REPO/actions/runs/${{ github.run_id }}"
|
||||||
RUN_NUMBER="${{ github.run_number }}"
|
RUN_NUMBER="${{ github.run_number }}"
|
||||||
|
|
||||||
export DATE SHORT REPO SHA RUN_URL RUN_NUMBER
|
export DATE SHORT REPO SHA RUN_URL RUN_NUMBER
|
||||||
export INSTALLER_URL PORTABLE_URL MSI_URL
|
export INSTALLER_URL PORTABLE_URL MSI_URL
|
||||||
|
|
||||||
python3 source/build-aux/generate-page.py
|
python3 source/build-aux/generate-page.py
|
||||||
|
|
||||||
- name: Add .nojekyll
|
- name: Add .nojekyll
|
||||||
|
|||||||
+2
-1
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
include(cmake/hoto_update_cmake_message.cmake)
|
include(cmake/hoto_update_cmake_message.cmake)
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.14...3.19 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.5...4.2)
|
||||||
|
|
||||||
project(qelectrotech
|
project(qelectrotech
|
||||||
VERSION 0.100.1
|
VERSION 0.100.1
|
||||||
@@ -145,6 +145,7 @@ target_include_directories(
|
|||||||
${QET_DIR}/sources/dataBase/ui
|
${QET_DIR}/sources/dataBase/ui
|
||||||
${QET_DIR}/sources/factory/ui
|
${QET_DIR}/sources/factory/ui
|
||||||
${QET_DIR}/sources/print
|
${QET_DIR}/sources/print
|
||||||
|
${QET_DIR}/sources/svg
|
||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME})
|
install(TARGETS ${PROJECT_NAME})
|
||||||
|
|||||||
+91
-2
@@ -2,13 +2,102 @@
|
|||||||
|
|
||||||
## [Unreleased](https://github.com/qelectrotech/qelectrotech-source-mirror/tree/HEAD)
|
## [Unreleased](https://github.com/qelectrotech/qelectrotech-source-mirror/tree/HEAD)
|
||||||
|
|
||||||
[Full Changelog](https://github.com/qelectrotech/qelectrotech-source-mirror/compare/0.9...HEAD)
|
[Full Changelog](https://github.com/qelectrotech/qelectrotech-source-mirror/compare/nightly...HEAD)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- “Exclude from auto-numbering” and “Potential isolation” tick boxes fault [\#482](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/482)
|
||||||
|
- Add ability to change appearance of multiple lines at once [\#476](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/476)
|
||||||
|
- Save As dialog asks for "element name" but actually requires a file name [\#469](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/469)
|
||||||
|
- Some icons are illegible with dark theme [\#466](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/466)
|
||||||
|
- \[BUG\] Properties to all conductors [\#460](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/460)
|
||||||
|
- Internal links in PDF export [\#417](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/417)
|
||||||
|
- Apple silicon download is not working [\#400](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/400)
|
||||||
|
- Add missing title block variables to 'folio properties' window [\#271](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/271)
|
||||||
|
- Bug: Saving a read-only project doesn't clear the read-only state [\#217](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/217)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- PartText: keep text position stable across save/reopen on font-size change \(\#158\) [\#501](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/501) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Clear read-only state when a project is saved to a writable file [\#497](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/497) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Fix regional system locale loading the wrong translation \(pt\_BR/nl\_BE/nl\_NL\) [\#496](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/496) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Folio properties: auto-add a title block's custom variables [\#495](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/495) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Element editor Save As: label the field as a file name, not 'element name' [\#494](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/494) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- CLI: add --set-titleblock, and fix headless backup crash [\#493](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/493) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Update qet\_zh.ts [\#491](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/491) ([zi-mozhuang](https://github.com/zi-mozhuang))
|
||||||
|
- CLI: clickable cross-reference hyperlinks in PDF export [\#490](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/490) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- CLI: add verification & data-export tools \(info, BOM, nets, links, check-elements, resave\) [\#489](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/489) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Issues 482 [\#488](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/488) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Revert "Update-UI-Chinese-translation" [\#486](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/486) ([scorpio810](https://github.com/scorpio810))
|
||||||
|
- CLI export: don't draw the editor grid in PDF/PNG/SVG output [\#485](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/485) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- Update-UI-Chinese-translation [\#484](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/484) ([zi-mozhuang](https://github.com/zi-mozhuang))
|
||||||
|
- Add headless command-line export \(PDF / PNG / SVG / cable-list / wire-list\) [\#483](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/483) ([ispyisail](https://github.com/ispyisail))
|
||||||
|
- fix possible crashes in crossrefitem [\#479](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/479) ([ChuckNr11](https://github.com/ChuckNr11))
|
||||||
|
- Fix: Dynamic element text shifting/jumping when duplicating diagrams [\#477](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/477) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Update German translations for duplicate diagram feature [\#475](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/475) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Feat: Add ability to duplicate diagrams/folios with all metadata and … [\#473](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/473) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Feature: Allow excluding specific elements from BOM \(Nomenclature\) [\#472](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/472) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Potential Isolation option for terminals [\#471](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/471) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Fix: Wiring list filter and dynamic text timing [\#470](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/470) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- New element: Line definition [\#464](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/464) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Turkish Lang Update [\#463](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/463) ([scorpio810](https://github.com/scorpio810))
|
||||||
|
- follow up: wiring list [\#462](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/462) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Fix and Improve Multi-selection for Diagram Operations [\#459](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/459) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
|
||||||
|
## [nightly](https://github.com/qelectrotech/qelectrotech-source-mirror/tree/nightly) (2026-05-10)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/qelectrotech/qelectrotech-source-mirror/compare/0.100...nightly)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Flatpak runtimes outdated [\#446](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/446)
|
||||||
|
- Move Flemish man pages from man/be/ to man/nl\_BE/ [\#439](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/439)
|
||||||
|
- you could share an PR to fix it? [\#438](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/438)
|
||||||
|
- Diacritics in some filenames can possibly lead to the problems during packaging [\#437](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/437)
|
||||||
|
- שרטוט חשמל [\#435](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/435)
|
||||||
|
- Feature request: add circuit simulation [\#432](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/432)
|
||||||
|
- No usable sources archive for version 0.100 [\#418](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/418)
|
||||||
|
- New release ? [\#411](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/411)
|
||||||
|
- options moving when opening "file", "edition" menus [\#299](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/299)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Try to add Windows build CI workflow [\#457](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/457) ([scorpio810](https://github.com/scorpio810))
|
||||||
|
- Fixed: Prevented the selection in the project tree from jumping to the last page when saving. [\#456](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/456) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Fix Thumbnail in Makrotree [\#455](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/455) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Update German translation for macro feature [\#454](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/454) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Fix losing Focus on moving diagram position with keyboard [\#452](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/452) ([ChuckNr11](https://github.com/ChuckNr11))
|
||||||
|
- Draft: Feature - Introduce User Templates Collection and Dedicated UI Tab [\#451](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/451) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Update translation [\#450](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/450) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Automatic Terminal Numbering Tool [\#449](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/449) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Supplement to pull request \#444 by Kellermorph [\#448](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/448) ([ChuckNr11](https://github.com/ChuckNr11))
|
||||||
|
- Add RAM-based wiring list export [\#447](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/447) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Follow-up: Address review comments for slave limit feature [\#444](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/444) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Feature: Auto-select active diagram in the elements panel tree [\#443](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/443) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Revert "Feature: Implement max\_slaves limit for Master elements" [\#442](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/442) ([scorpio810](https://github.com/scorpio810))
|
||||||
|
- Feature: Implement max\_slaves limit for Master elements [\#441](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/441) ([Kellermorph](https://github.com/Kellermorph))
|
||||||
|
- Update qet\_cs.ts [\#434](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/434) ([pafri](https://github.com/pafri))
|
||||||
|
- Update QCH Help file [\#433](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/433) ([Int-Circuit](https://github.com/Int-Circuit))
|
||||||
|
- Create Korean man page for QElectroTech [\#431](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/431) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Update ELEMENTS.LICENSE [\#430](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/430) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Update CREDIT [\#429](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/429) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Korean comments to QElectroTech XML file [\#428](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/428) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Spanish and Korean summaries to appdata [\#427](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/427) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Korean translations for comments and generic names [\#426](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/426) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Restore copyright and license information in QET64.nsi [\#425](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/425) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Korean language strings to lang\_extra.nsh [\#424](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/424) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Korean translation author to aboutqetdialog [\#423](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/423) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Korean language support in xml element collection [\#422](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/422) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
- Add Korean translation \(ko\) – translated by jkh [\#419](https://github.com/qelectrotech/qelectrotech-source-mirror/pull/419) ([Kyle-Code-CA](https://github.com/Kyle-Code-CA))
|
||||||
|
|
||||||
|
## [0.100](https://github.com/qelectrotech/qelectrotech-source-mirror/tree/0.100) (2026-01-25)
|
||||||
|
|
||||||
|
[Full Changelog](https://github.com/qelectrotech/qelectrotech-source-mirror/compare/0.9...0.100)
|
||||||
|
|
||||||
**Closed issues:**
|
**Closed issues:**
|
||||||
|
|
||||||
- error in doxygen action code [\#414](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/414)
|
- error in doxygen action code [\#414](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/414)
|
||||||
- "NoName" is automatically inserted into empty text cells in title block [\#407](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/407)
|
- "NoName" is automatically inserted into empty text cells in title block [\#407](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/407)
|
||||||
- Apple silicon download is not working [\#400](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/400)
|
|
||||||
- Apple silicon download is not working [\#394](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/394)
|
- Apple silicon download is not working [\#394](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/394)
|
||||||
- Differenciating connector for proper labeling [\#390](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/390)
|
- Differenciating connector for proper labeling [\#390](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/390)
|
||||||
- Non-perpendicular connections [\#368](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/368)
|
- Non-perpendicular connections [\#368](https://github.com/qelectrotech/qelectrotech-source-mirror/issues/368)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ if(BUILD_PUGIXML)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
pugixml
|
pugixml
|
||||||
GIT_REPOSITORY https://github.com/zeux/pugixml.git
|
GIT_REPOSITORY https://github.com/zeux/pugixml.git
|
||||||
GIT_TAG v1.11.4)
|
GIT_TAG v1.15)
|
||||||
|
|
||||||
FetchContent_MakeAvailable(pugixml)
|
FetchContent_MakeAvailable(pugixml)
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ set(QET_COMPONENTS
|
|||||||
set(QET_PRIVATE_LIBRARIES
|
set(QET_PRIVATE_LIBRARIES
|
||||||
Qt::PrintSupport
|
Qt::PrintSupport
|
||||||
Qt::Gui
|
Qt::Gui
|
||||||
|
Qt::GuiPrivate # Required for QPdfEngine::drawHyperlink (PDF internal links)
|
||||||
Qt::Xml
|
Qt::Xml
|
||||||
Qt::Svg
|
Qt::Svg
|
||||||
Qt::Sql
|
Qt::Sql
|
||||||
@@ -106,6 +107,10 @@ set(QET_RES_FILES
|
|||||||
${QET_DIR}/sources/ui/configpage/generalconfigurationpage.ui
|
${QET_DIR}/sources/ui/configpage/generalconfigurationpage.ui
|
||||||
)
|
)
|
||||||
set(QET_SRC_FILES
|
set(QET_SRC_FILES
|
||||||
|
${QET_DIR}/sources/cli_export.cpp
|
||||||
|
${QET_DIR}/sources/cli_export.h
|
||||||
|
${QET_DIR}/sources/pdf_links.cpp
|
||||||
|
${QET_DIR}/sources/pdf_links.h
|
||||||
${QET_DIR}/sources/borderproperties.cpp
|
${QET_DIR}/sources/borderproperties.cpp
|
||||||
${QET_DIR}/sources/borderproperties.h
|
${QET_DIR}/sources/borderproperties.h
|
||||||
${QET_DIR}/sources/bordertitleblock.cpp
|
${QET_DIR}/sources/bordertitleblock.cpp
|
||||||
@@ -499,6 +504,8 @@ set(QET_SRC_FILES
|
|||||||
${QET_DIR}/sources/SearchAndReplace/ui/replacefoliowidget.h
|
${QET_DIR}/sources/SearchAndReplace/ui/replacefoliowidget.h
|
||||||
${QET_DIR}/sources/SearchAndReplace/ui/searchandreplacewidget.cpp
|
${QET_DIR}/sources/SearchAndReplace/ui/searchandreplacewidget.cpp
|
||||||
${QET_DIR}/sources/SearchAndReplace/ui/searchandreplacewidget.h
|
${QET_DIR}/sources/SearchAndReplace/ui/searchandreplacewidget.h
|
||||||
|
${QET_DIR}/sources/svg/qetsvg.cpp
|
||||||
|
${QET_DIR}/sources/svg/qetsvg.h
|
||||||
|
|
||||||
${QET_DIR}/sources/titleblock/dimension.cpp
|
${QET_DIR}/sources/titleblock/dimension.cpp
|
||||||
${QET_DIR}/sources/titleblock/dimension.h
|
${QET_DIR}/sources/titleblock/dimension.h
|
||||||
@@ -713,6 +720,8 @@ set(QET_SRC_FILES
|
|||||||
|
|
||||||
${QET_DIR}/sources/xml/terminalstripitemxml.cpp
|
${QET_DIR}/sources/xml/terminalstripitemxml.cpp
|
||||||
${QET_DIR}/sources/xml/terminalstripitemxml.h
|
${QET_DIR}/sources/xml/terminalstripitemxml.h
|
||||||
|
${QET_DIR}/sources/xml/terminalstriplayoutpatternxml.cpp
|
||||||
|
${QET_DIR}/sources/xml/terminalstriplayoutpatternxml.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TS_FILES
|
set(TS_FILES
|
||||||
|
|||||||
+1
-1
Submodule elements updated: f6a422ab00...3aab395fc4
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+228
-205
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+216
-192
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+214
-191
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+215
-192
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+215
-192
File diff suppressed because it is too large
Load Diff
+215
-192
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+214
-191
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+214
-191
File diff suppressed because it is too large
Load Diff
+217
-194
File diff suppressed because it is too large
Load Diff
+214
-191
File diff suppressed because it is too large
Load Diff
+214
-191
File diff suppressed because it is too large
Load Diff
+214
-191
File diff suppressed because it is too large
Load Diff
+215
-192
File diff suppressed because it is too large
Load Diff
+215
-192
File diff suppressed because it is too large
Load Diff
+215
-192
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+1495
-1444
File diff suppressed because it is too large
Load Diff
+5
-1
@@ -230,7 +230,11 @@ RESOURCES += qelectrotech.qrc
|
|||||||
TRANSLATIONS += lang/*.ts
|
TRANSLATIONS += lang/*.ts
|
||||||
|
|
||||||
# Modules Qt utilises par l'application
|
# Modules Qt utilises par l'application
|
||||||
QT += xml svg network sql widgets printsupport concurrent KWidgetsAddons KCoreAddons
|
QT += xml svg network sql widgets printsupport concurrent KWidgetsAddons KCoreAddons gui-private
|
||||||
|
|
||||||
|
# Private Qt GUI headers (needed for QPdfEngine::drawHyperlink)
|
||||||
|
# gui-private should add this automatically, but some distros need it explicit
|
||||||
|
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtGui/$$[QT_VERSION]/QtGui
|
||||||
|
|
||||||
# UI DESIGNER FILES AND GENERATION SOURCES FILES
|
# UI DESIGNER FILES AND GENERATION SOURCES FILES
|
||||||
FORMS += $$files(sources/richtext/*.ui) \
|
FORMS += $$files(sources/richtext/*.ui) \
|
||||||
|
|||||||
@@ -0,0 +1,825 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2025 The QElectroTech Team
|
||||||
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "cli_export.h"
|
||||||
|
|
||||||
|
#include "bordertitleblock.h"
|
||||||
|
#include "conductornumexport.h"
|
||||||
|
#include "conductorproperties.h"
|
||||||
|
#include "dataBase/projectdatabase.h"
|
||||||
|
#include "diagram.h"
|
||||||
|
#include "diagramcontext.h"
|
||||||
|
#include "pdf_links.h"
|
||||||
|
#include "qetgraphicsitem/conductor.h"
|
||||||
|
#include "qetgraphicsitem/element.h"
|
||||||
|
#include "qetgraphicsitem/terminal.h"
|
||||||
|
#include "qetproject.h"
|
||||||
|
#include "titleblockproperties.h"
|
||||||
|
#include "wiringlistexport.h"
|
||||||
|
|
||||||
|
// Private Qt PDF engine for drawHyperlink() — see pdf_links / projectprintwindow.
|
||||||
|
#include <private/qpdf_p.h>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QDomDocument>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QPageLayout>
|
||||||
|
#include <QPair>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPdfWriter>
|
||||||
|
#include <QSet>
|
||||||
|
#include <QSqlError>
|
||||||
|
#include <QSqlQuery>
|
||||||
|
#include <QSvgGenerator>
|
||||||
|
#include <QTextStream>
|
||||||
|
#include <QTransform>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
QTextStream out(stdout);
|
||||||
|
QTextStream err(stderr);
|
||||||
|
|
||||||
|
/// All CLI option flags, mapped to a short format name.
|
||||||
|
const QHash<QString, QString> &exportFlags()
|
||||||
|
{
|
||||||
|
static const QHash<QString, QString> flags {
|
||||||
|
{"--export-pdf", "pdf"},
|
||||||
|
{"--export-png", "png"},
|
||||||
|
{"--export-svg", "svg"},
|
||||||
|
{"--export-cables", "cables"},
|
||||||
|
{"--export-wires", "wires"},
|
||||||
|
{"--export-bom", "bom"},
|
||||||
|
{"--export-nets", "nets"},
|
||||||
|
{"--export-links", "links"},
|
||||||
|
{"--info", "info"},
|
||||||
|
{"--check-elements", "check"},
|
||||||
|
{"--resave", "resave"},
|
||||||
|
{"--set-titleblock", "settb"},
|
||||||
|
};
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Device tag of an element ("K1", "Q55"), falling back to its name.
|
||||||
|
QString elementLabel(Element *element)
|
||||||
|
{
|
||||||
|
const QString label = element->elementInformations()["label"].toString();
|
||||||
|
return label.isEmpty() ? element->name() : label;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pixel rect of a diagram's border + title block (the printable page area).
|
||||||
|
QRect diagramRect(Diagram *diagram)
|
||||||
|
{
|
||||||
|
QRectF r = diagram->border_and_titleblock.borderAndTitleBlockRect();
|
||||||
|
r.adjust(0, 0, 1, 1); // include the 1px border line
|
||||||
|
return r.toAlignedRect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A filesystem-safe per-diagram file stem: "01_Title".
|
||||||
|
QString diagramStem(Diagram *diagram, int index)
|
||||||
|
{
|
||||||
|
QString title = diagram->title();
|
||||||
|
title.replace(QRegularExpression("[^\\w \\-]"), "_");
|
||||||
|
title = title.simplified();
|
||||||
|
if (title.isEmpty())
|
||||||
|
title = "diagram";
|
||||||
|
return QStringLiteral("%1_%2")
|
||||||
|
.arg(index, 2, 10, QChar('0'))
|
||||||
|
.arg(title);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Render @p diagram into @p painter, fitting @p target to the page rect.
|
||||||
|
void renderDiagram(Diagram *diagram, QPainter &painter, const QRectF &target)
|
||||||
|
{
|
||||||
|
const QRect source = diagramRect(diagram);
|
||||||
|
// Export without the editor grid: drawBackground() only paints it when
|
||||||
|
// draw_grid_ is set (default true), so toggle it off around the render
|
||||||
|
// and restore it afterwards.
|
||||||
|
const bool was_drawing_grid = diagram->displayGrid();
|
||||||
|
diagram->setDisplayGrid(false);
|
||||||
|
diagram->render(&painter, target, source, Qt::KeepAspectRatio);
|
||||||
|
diagram->setDisplayGrid(was_drawing_grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int exportPdf(QETProject &project, const QString &output)
|
||||||
|
{
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
if (diagrams.isEmpty()) {
|
||||||
|
err << "No diagrams to export.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Page numbers (1-based) for cross-reference hyperlink targets: each
|
||||||
|
// diagram is exactly one page in the CLI export (no tiling).
|
||||||
|
QMap<Diagram *, int> pageMap;
|
||||||
|
for (int i = 0; i < diagrams.size(); ++i)
|
||||||
|
pageMap.insert(diagrams.at(i), i + 1);
|
||||||
|
|
||||||
|
QPdfWriter writer(output);
|
||||||
|
writer.setCreator("QElectroTech");
|
||||||
|
writer.setResolution(96);
|
||||||
|
|
||||||
|
QPainter painter;
|
||||||
|
bool first = true;
|
||||||
|
for (Diagram *diagram : diagrams) {
|
||||||
|
const QRect r = diagramRect(diagram);
|
||||||
|
// Match the page to the diagram (in points: 1px @ 96dpi = 0.75pt).
|
||||||
|
const QPageSize page(QSizeF(r.width() * 72.0 / 96.0,
|
||||||
|
r.height() * 72.0 / 96.0),
|
||||||
|
QPageSize::Point);
|
||||||
|
writer.setPageSize(page);
|
||||||
|
writer.setPageMargins(QMarginsF(0, 0, 0, 0));
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
if (!painter.begin(&writer)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
writer.newPage();
|
||||||
|
}
|
||||||
|
const QRectF target(0, 0,
|
||||||
|
writer.width(), writer.height());
|
||||||
|
renderDiagram(diagram, painter, target);
|
||||||
|
|
||||||
|
// Inject clickable cross-reference / folio-report hyperlinks for this
|
||||||
|
// page. The geometry is rebuilt from the QPdfWriter (not a QPrinter):
|
||||||
|
// render() anchors the diagram top-left with KeepAspectRatio, and the
|
||||||
|
// page is sized to the diagram so the scale is ~1.
|
||||||
|
if (auto *engine = dynamic_cast<QPdfEngine *>(painter.paintEngine())) {
|
||||||
|
const QRectF source(r);
|
||||||
|
const qreal s = qMin(target.width() / source.width(),
|
||||||
|
target.height() / source.height());
|
||||||
|
QTransform fit;
|
||||||
|
fit.translate(target.x(), target.y());
|
||||||
|
fit.scale(s, s);
|
||||||
|
fit.translate(-source.x(), -source.y());
|
||||||
|
|
||||||
|
// Device pixels -> PDF points, replicating the engine's page matrix
|
||||||
|
// (72/resolution scale + Y flip; zero margins -> no paint offset).
|
||||||
|
const qreal pt_scale = 72.0 / writer.resolution();
|
||||||
|
const qreal fullH_pt = writer.pageLayout().fullRectPoints().height();
|
||||||
|
const bool fullPageMode =
|
||||||
|
(writer.pageLayout().mode() == QPageLayout::FullPageMode);
|
||||||
|
const QRect paintPx =
|
||||||
|
writer.pageLayout().paintRectPixels(writer.resolution());
|
||||||
|
|
||||||
|
PdfLinks::PageGeometry geom;
|
||||||
|
geom.sceneToDevice = fit;
|
||||||
|
geom.target = target;
|
||||||
|
geom.pageBounds = QRectF(0, 0, target.width(), target.height());
|
||||||
|
geom.devToPdf = [=](const QPointF &d) -> QPointF {
|
||||||
|
qreal dx = d.x(), dy = d.y();
|
||||||
|
if (!fullPageMode) { dx += paintPx.left(); dy += paintPx.top(); }
|
||||||
|
return QPointF(pt_scale * dx, fullH_pt - pt_scale * dy);
|
||||||
|
};
|
||||||
|
geom.sourceRectOf = [](Diagram *dg) {
|
||||||
|
return QRectF(diagramRect(dg));
|
||||||
|
};
|
||||||
|
PdfLinks::injectCrossRefLinks(engine, diagram, geom, pageMap, output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
painter.end();
|
||||||
|
|
||||||
|
// Rewrite the URI link annotations into native internal GoTo actions, so
|
||||||
|
// the cross-references jump inside the document in any PDF viewer.
|
||||||
|
PdfLinks::convertUriToGoTo(output);
|
||||||
|
|
||||||
|
out << "Exported " << diagrams.size() << " page(s) -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exportImages(QETProject &project, const QString &format,
|
||||||
|
const QString &out_dir)
|
||||||
|
{
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
if (diagrams.isEmpty()) {
|
||||||
|
err << "No diagrams to export.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
QDir().mkpath(out_dir);
|
||||||
|
|
||||||
|
int index = 0;
|
||||||
|
for (Diagram *diagram : diagrams) {
|
||||||
|
++index;
|
||||||
|
const QRect r = diagramRect(diagram);
|
||||||
|
const QString path = QDir(out_dir).filePath(
|
||||||
|
diagramStem(diagram, index) + "." + format);
|
||||||
|
|
||||||
|
if (format == "svg") {
|
||||||
|
QSvgGenerator gen;
|
||||||
|
gen.setFileName(path);
|
||||||
|
gen.setSize(r.size());
|
||||||
|
gen.setViewBox(QRect(0, 0, r.width(), r.height()));
|
||||||
|
gen.setTitle(diagram->title());
|
||||||
|
QPainter painter(&gen);
|
||||||
|
renderDiagram(diagram, painter, QRectF(QPointF(0, 0), r.size()));
|
||||||
|
painter.end();
|
||||||
|
} else { // png
|
||||||
|
QImage image(r.size(), QImage::Format_ARGB32);
|
||||||
|
image.fill(Qt::white);
|
||||||
|
QPainter painter(&image);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
renderDiagram(diagram, painter, QRectF(QPointF(0, 0), r.size()));
|
||||||
|
painter.end();
|
||||||
|
if (!image.save(path)) {
|
||||||
|
err << "Failed to write '" << path << "'.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out << " " << path << "\n";
|
||||||
|
}
|
||||||
|
out << "Exported " << diagrams.size() << " diagram(s) -> " << out_dir << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exportCsv(QETProject &project, const QString &format, const QString &output)
|
||||||
|
{
|
||||||
|
QString csv;
|
||||||
|
if (format == "cables") {
|
||||||
|
WiringListExport wle(&project, nullptr);
|
||||||
|
csv = wle.toCsvString();
|
||||||
|
} else { // wires
|
||||||
|
ConductorNumExport cne(&project, nullptr);
|
||||||
|
csv = cne.wiresNum();
|
||||||
|
}
|
||||||
|
if (csv.isEmpty()) {
|
||||||
|
err << "Nothing to export (empty list).\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
QTextStream fout(&file);
|
||||||
|
fout << csv;
|
||||||
|
file.close();
|
||||||
|
out << "Exported " << format << " list -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Quote a field for CSV output (RFC-4180 style, ';' delimiter).
|
||||||
|
QString csvField(const QString &value)
|
||||||
|
{
|
||||||
|
if (value.contains(';') || value.contains('"')
|
||||||
|
|| value.contains('\n') || value.contains('\r')) {
|
||||||
|
QString v = value;
|
||||||
|
v.replace('"', "\"\"");
|
||||||
|
return '"' % v % '"';
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Bill of materials: one row per element, key component-data fields.
|
||||||
|
/// Pulls from QET's own project database (the same source as the GUI BOM
|
||||||
|
/// export), so the output matches what the editor produces.
|
||||||
|
int exportBom(QETProject &project, const QString &output)
|
||||||
|
{
|
||||||
|
// The project database is built lazily; force a (re)build before querying.
|
||||||
|
project.dataBase()->updateDB();
|
||||||
|
|
||||||
|
static const QStringList columns {
|
||||||
|
"label", "designation", "manufacturer", "manufacturer_reference",
|
||||||
|
"quantity", "location", "function", "title", "folio"
|
||||||
|
};
|
||||||
|
|
||||||
|
QSqlQuery query = project.dataBase()->newQuery(
|
||||||
|
"SELECT " % columns.join(", ") %
|
||||||
|
" FROM element_nomenclature_view ORDER BY label");
|
||||||
|
if (!query.exec()) {
|
||||||
|
err << "BOM query failed: " << query.lastError().text() << "\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString csv = columns.join(";") % "\n";
|
||||||
|
int rows = 0;
|
||||||
|
while (query.next()) {
|
||||||
|
QStringList values;
|
||||||
|
for (int i = 0; i < columns.size(); ++i)
|
||||||
|
values << csvField(query.value(i).toString());
|
||||||
|
csv += values.join(";") % "\n";
|
||||||
|
++rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
QTextStream fout(&file);
|
||||||
|
fout << csv;
|
||||||
|
file.close();
|
||||||
|
out << "Exported " << rows << " component(s) -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Count terminals on @p element that no conductor connects to.
|
||||||
|
int freeTerminals(Element *element)
|
||||||
|
{
|
||||||
|
int free = 0;
|
||||||
|
const QList<Terminal *> terminals = element->terminals();
|
||||||
|
for (Terminal *t : terminals)
|
||||||
|
if (t->conductorsCount() == 0)
|
||||||
|
++free;
|
||||||
|
return free;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Structural ground-truth dump of a project, as JSON, to stdout (or a file).
|
||||||
|
/// Uses QET's own loaded model, so it reports what the editor actually sees:
|
||||||
|
/// per-page element / conductor counts and unconnected terminals.
|
||||||
|
int exportInfo(QETProject &project, const QString &output)
|
||||||
|
{
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
|
||||||
|
int total_elements = 0, total_conductors = 0, total_free = 0;
|
||||||
|
QJsonArray pages;
|
||||||
|
int index = 0;
|
||||||
|
for (Diagram *diagram : diagrams) {
|
||||||
|
++index;
|
||||||
|
const QList<Element *> elements = diagram->elements();
|
||||||
|
const int conductors = diagram->conductors().size();
|
||||||
|
int page_free = 0;
|
||||||
|
for (Element *e : elements)
|
||||||
|
page_free += freeTerminals(e);
|
||||||
|
|
||||||
|
const QRect r = diagramRect(diagram);
|
||||||
|
QJsonObject page;
|
||||||
|
page["index"] = index;
|
||||||
|
page["title"] = diagram->title();
|
||||||
|
page["folio"] = QStringLiteral("%1 of %2")
|
||||||
|
.arg(index).arg(diagrams.size());
|
||||||
|
page["width_px"] = r.width();
|
||||||
|
page["height_px"] = r.height();
|
||||||
|
page["elements"] = elements.size();
|
||||||
|
page["conductors"] = conductors;
|
||||||
|
page["free_terminals"] = page_free;
|
||||||
|
pages.append(page);
|
||||||
|
|
||||||
|
total_elements += elements.size();
|
||||||
|
total_conductors += conductors;
|
||||||
|
total_free += page_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject root;
|
||||||
|
root["project"] = project.title();
|
||||||
|
root["diagrams"] = diagrams.size();
|
||||||
|
root["elements"] = total_elements;
|
||||||
|
root["conductors"] = total_conductors;
|
||||||
|
root["free_terminals"] = total_free;
|
||||||
|
root["pages"] = pages;
|
||||||
|
|
||||||
|
const QByteArray json =
|
||||||
|
QJsonDocument(root).toJson(QJsonDocument::Indented);
|
||||||
|
|
||||||
|
if (output.isEmpty()) {
|
||||||
|
out << QString::fromUtf8(json);
|
||||||
|
} else {
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
file.write(json);
|
||||||
|
file.close();
|
||||||
|
out << "Wrote project info -> " << output << "\n";
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate one .elmt file against QET's element schema.
|
||||||
|
/// @return 0 = OK, 1 = warning (loads but suspicious), 2 = failure.
|
||||||
|
int checkOneElement(const QString &path)
|
||||||
|
{
|
||||||
|
QFile file(path);
|
||||||
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
|
out << "FAIL " << path << " (cannot open)\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
QDomDocument doc;
|
||||||
|
QString error;
|
||||||
|
int line = 0;
|
||||||
|
if (!doc.setContent(&file, &error, &line)) {
|
||||||
|
file.close();
|
||||||
|
out << "FAIL " << path << " (XML error line "
|
||||||
|
<< line << ": " << error << ")\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
const QDomElement root = doc.documentElement();
|
||||||
|
if (root.tagName() != "definition" || root.attribute("type") != "element") {
|
||||||
|
out << "FAIL " << path << " (root is not <definition type=\"element\">)\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool w_ok = false, h_ok = false;
|
||||||
|
const double w = root.attribute("width").toDouble(&w_ok);
|
||||||
|
const double h = root.attribute("height").toDouble(&h_ok);
|
||||||
|
if (!w_ok || !h_ok || w == 0 || h == 0) {
|
||||||
|
out << "FAIL " << path << " (missing/zero bounding box "
|
||||||
|
<< root.attribute("width") << "x"
|
||||||
|
<< root.attribute("height") << ")\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int terminals = root.elementsByTagName("terminal").count();
|
||||||
|
|
||||||
|
// Negative dimensions are malformed but QET still loads them; surface as a
|
||||||
|
// warning rather than a failure so this agrees with QET's own loader.
|
||||||
|
if (w < 0 || h < 0) {
|
||||||
|
out << "WARN " << path << " (negative bounding box "
|
||||||
|
<< w << "x" << h << ", " << terminals << " terminals)\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (terminals == 0) {
|
||||||
|
out << "WARN " << path << " (loads, but 0 terminals)\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
out << "OK " << path << " (" << terminals << " terminals)\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Validate a single .elmt file or every .elmt under a directory.
|
||||||
|
int checkElements(const QString &path)
|
||||||
|
{
|
||||||
|
QStringList files;
|
||||||
|
const QFileInfo info(path);
|
||||||
|
if (info.isDir()) {
|
||||||
|
QDirIterator it(path, {"*.elmt"}, QDir::Files,
|
||||||
|
QDirIterator::Subdirectories);
|
||||||
|
while (it.hasNext())
|
||||||
|
files << it.next();
|
||||||
|
files.sort();
|
||||||
|
} else if (info.isFile()) {
|
||||||
|
files << path;
|
||||||
|
} else {
|
||||||
|
err << "Not found: " << path << "\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.isEmpty()) {
|
||||||
|
err << "No .elmt files found under: " << path << "\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int warnings = 0, failures = 0;
|
||||||
|
for (const QString &f : files) {
|
||||||
|
const int r = checkOneElement(f);
|
||||||
|
if (r == 1) ++warnings;
|
||||||
|
else if (r == 2) ++failures;
|
||||||
|
}
|
||||||
|
out << files.size() << " file(s), " << warnings
|
||||||
|
<< " warning(s), " << failures << " failure(s)\n";
|
||||||
|
return failures > 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Map every element in the project to its 1-based folio (page) position.
|
||||||
|
QHash<Element *, int> folioIndex(QETProject &project)
|
||||||
|
{
|
||||||
|
QHash<Element *, int> folio;
|
||||||
|
int index = 0;
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
for (Diagram *diagram : diagrams) {
|
||||||
|
++index;
|
||||||
|
const QList<Element *> elements = diagram->elements();
|
||||||
|
for (Element *e : elements)
|
||||||
|
folio.insert(e, index);
|
||||||
|
}
|
||||||
|
return folio;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Electrical nets: groups of terminals joined into one potential.
|
||||||
|
/// Walks QET's own potential graph, so each net is a connected component
|
||||||
|
/// of terminals across all folios. The ground truth for connectivity.
|
||||||
|
int exportNets(QETProject &project, const QString &output)
|
||||||
|
{
|
||||||
|
const QHash<Element *, int> folio = folioIndex(project);
|
||||||
|
|
||||||
|
QList<Conductor *> all_conductors;
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
for (Diagram *diagram : diagrams)
|
||||||
|
all_conductors << diagram->conductors();
|
||||||
|
|
||||||
|
QSet<Conductor *> visited;
|
||||||
|
QJsonArray nets;
|
||||||
|
int net_no = 0;
|
||||||
|
for (Conductor *c : all_conductors) {
|
||||||
|
if (visited.contains(c))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// The whole potential this conductor belongs to. relatedPotential-
|
||||||
|
// Conductors() also fills t_list with every terminal in the net
|
||||||
|
// (following folio reports and terminal blocks too).
|
||||||
|
QList<Terminal *> t_list;
|
||||||
|
QSet<Conductor *> group = c->relatedPotentialConductors(true, &t_list);
|
||||||
|
group.insert(c);
|
||||||
|
for (Conductor *g : group)
|
||||||
|
visited.insert(g);
|
||||||
|
if (c->terminal1) t_list << c->terminal1;
|
||||||
|
if (c->terminal2) t_list << c->terminal2;
|
||||||
|
|
||||||
|
// Wire number: smallest non-empty conductor text (deterministic).
|
||||||
|
QStringList wire_nos;
|
||||||
|
for (Conductor *g : group)
|
||||||
|
if (!g->properties().text.isEmpty())
|
||||||
|
wire_nos << g->properties().text;
|
||||||
|
wire_nos.sort();
|
||||||
|
|
||||||
|
++net_no;
|
||||||
|
QJsonArray terminals;
|
||||||
|
QSet<Terminal *> seen;
|
||||||
|
for (Terminal *t : t_list) {
|
||||||
|
if (!t || seen.contains(t))
|
||||||
|
continue;
|
||||||
|
seen.insert(t);
|
||||||
|
Element *pe = t->parentElement();
|
||||||
|
QJsonObject to;
|
||||||
|
to["element"] = pe ? elementLabel(pe) : QString();
|
||||||
|
to["terminal"] = t->name();
|
||||||
|
to["folio"] = pe ? folio.value(pe, 0) : 0;
|
||||||
|
terminals.append(to);
|
||||||
|
}
|
||||||
|
QJsonObject net;
|
||||||
|
net["net"] = net_no;
|
||||||
|
net["wire_no"] = wire_nos.value(0);
|
||||||
|
net["terminals"] = terminals;
|
||||||
|
nets.append(net);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject root;
|
||||||
|
root["project"] = project.title();
|
||||||
|
root["nets"] = nets.size();
|
||||||
|
root["list"] = nets;
|
||||||
|
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
file.write(QJsonDocument(root).toJson(QJsonDocument::Indented));
|
||||||
|
file.close();
|
||||||
|
out << "Exported " << nets.size() << " net(s) -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cross-references: each linkable element (coil / contact / report) and the
|
||||||
|
/// elements it links to, flagging masters/slaves with no link as unresolved.
|
||||||
|
int exportLinks(QETProject &project, const QString &output)
|
||||||
|
{
|
||||||
|
const QHash<Element *, int> folio = folioIndex(project);
|
||||||
|
|
||||||
|
QString csv("element;link_type;linked_to;folio;status\n");
|
||||||
|
int linkable = 0, unresolved = 0;
|
||||||
|
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
for (Diagram *diagram : diagrams) {
|
||||||
|
const QList<Element *> elements = diagram->elements();
|
||||||
|
for (Element *e : elements) {
|
||||||
|
if (e->linkType() == Element::Simple)
|
||||||
|
continue;
|
||||||
|
++linkable;
|
||||||
|
|
||||||
|
const QList<Element *> linked = e->linkedElements();
|
||||||
|
QStringList names;
|
||||||
|
for (Element *le : linked)
|
||||||
|
names << elementLabel(le) % "(f"
|
||||||
|
% QString::number(folio.value(le, 0)) % ")";
|
||||||
|
|
||||||
|
QString status = "linked";
|
||||||
|
if ((e->linkType() == Element::Master
|
||||||
|
|| e->linkType() == Element::Slave)
|
||||||
|
&& linked.isEmpty()) {
|
||||||
|
status = "UNRESOLVED";
|
||||||
|
++unresolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
csv += csvField(elementLabel(e)) % ";"
|
||||||
|
% e->linkTypeToString() % ";"
|
||||||
|
% csvField(names.join(", ")) % ";"
|
||||||
|
% QString::number(folio.value(e, 0)) % ";"
|
||||||
|
% status % "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
QTextStream fout(&file);
|
||||||
|
fout << csv;
|
||||||
|
file.close();
|
||||||
|
out << "Exported " << linkable << " linkable element(s), "
|
||||||
|
<< unresolved << " unresolved -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Round-trip: load the project and write its XML back out, so an external
|
||||||
|
/// diff can reveal markup QET silently normalises (tolerated-but-invalid XML).
|
||||||
|
int resaveProject(QETProject &project, const QString &output)
|
||||||
|
{
|
||||||
|
const QDomDocument doc = project.toXml();
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
QTextStream fout(&file);
|
||||||
|
fout << doc.toString(4);
|
||||||
|
file.close();
|
||||||
|
out << "Re-saved project -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stamp title-block fields onto every folio (and the project default), then
|
||||||
|
/// save. Each assignment is "key=value". Standard keys map to the documented
|
||||||
|
/// title-block fields; "date=today" uses the current date; any other key is
|
||||||
|
/// stored as a custom title-block field. Aimed at CI/revision workflows
|
||||||
|
/// (e.g. set revision + date before exporting a new revision).
|
||||||
|
int setTitleBlock(QETProject &project, const QString &output,
|
||||||
|
const QStringList &assignments)
|
||||||
|
{
|
||||||
|
if (assignments.isEmpty()) {
|
||||||
|
err << "No field assignments given (expected key=value).\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse "key=value" assignments up front so a bad one fails before writing.
|
||||||
|
QList<QPair<QString, QString>> fields;
|
||||||
|
for (const QString &a : assignments) {
|
||||||
|
const int eq = a.indexOf('=');
|
||||||
|
if (eq <= 0) {
|
||||||
|
err << "Bad assignment '" << a << "' (expected key=value).\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
const QString key = a.left(eq);
|
||||||
|
const QString val = a.mid(eq + 1);
|
||||||
|
if (key.compare("date", Qt::CaseInsensitive) == 0
|
||||||
|
&& val.compare("today", Qt::CaseInsensitive) != 0
|
||||||
|
&& !QDate::fromString(val, Qt::ISODate).isValid()) {
|
||||||
|
err << "Bad date '" << val << "' (expected YYYY-MM-DD or 'today').\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
fields << qMakePair(key, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto apply = [&](TitleBlockProperties &p) {
|
||||||
|
for (const auto &f : fields) {
|
||||||
|
const QString k = f.first.toLower();
|
||||||
|
const QString &v = f.second;
|
||||||
|
if (k == "title") p.title = v;
|
||||||
|
else if (k == "author") p.author = v;
|
||||||
|
else if (k == "filename") p.filename = v;
|
||||||
|
else if (k == "plant") p.plant = v;
|
||||||
|
else if (k == "location") p.locmach = v;
|
||||||
|
else if (k == "revision") p.indexrev = v;
|
||||||
|
else if (k == "version") p.version = v;
|
||||||
|
else if (k == "date") {
|
||||||
|
p.date = (v.compare("today", Qt::CaseInsensitive) == 0)
|
||||||
|
? QDate::currentDate()
|
||||||
|
: QDate::fromString(v, Qt::ISODate);
|
||||||
|
// An explicit date is only honoured when the folio is in
|
||||||
|
// "use the date value" mode (not "now"/"null").
|
||||||
|
p.useDate = TitleBlockProperties::UseDateValue;
|
||||||
|
}
|
||||||
|
else // unknown key -> custom title-block field
|
||||||
|
p.context.addValue(f.first, v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Project default (the template applied to new folios).
|
||||||
|
TitleBlockProperties def = project.defaultTitleBlockProperties();
|
||||||
|
apply(def);
|
||||||
|
project.setDefaultTitleBlockProperties(def);
|
||||||
|
|
||||||
|
// Every existing folio's own title block.
|
||||||
|
int folios = 0;
|
||||||
|
const QList<Diagram *> diagrams = project.diagrams();
|
||||||
|
for (Diagram *diagram : diagrams) {
|
||||||
|
TitleBlockProperties p =
|
||||||
|
diagram->border_and_titleblock.exportTitleBlock();
|
||||||
|
apply(p);
|
||||||
|
diagram->border_and_titleblock.importTitleBlock(p);
|
||||||
|
++folios;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDomDocument doc = project.toXml();
|
||||||
|
QFile file(output);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
err << "Cannot open '" << output << "' for writing.\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
QTextStream fout(&file);
|
||||||
|
fout << doc.toString(4);
|
||||||
|
file.close();
|
||||||
|
out << "Stamped " << fields.size() << " field(s) on "
|
||||||
|
<< folios << " folio(s) -> " << output << "\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
namespace CLIExport {
|
||||||
|
|
||||||
|
bool isExportRequest(const QStringList &args)
|
||||||
|
{
|
||||||
|
for (const QString &a : args)
|
||||||
|
if (exportFlags().contains(a))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int run(const QStringList &args)
|
||||||
|
{
|
||||||
|
QString flag;
|
||||||
|
QStringList rest;
|
||||||
|
for (int i = 0; i < args.size(); ++i) {
|
||||||
|
if (exportFlags().contains(args.at(i))) {
|
||||||
|
flag = args.at(i);
|
||||||
|
for (int j = i + 1; j < args.size(); ++j)
|
||||||
|
rest << args.at(j);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const QString format = exportFlags().value(flag);
|
||||||
|
|
||||||
|
// --check-elements operates on an element file/directory, not a project.
|
||||||
|
if (format == "check") {
|
||||||
|
if (rest.isEmpty()) {
|
||||||
|
err << "Usage: qelectrotech --check-elements "
|
||||||
|
"<element.elmt | directory>\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
return checkElements(rest.at(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString input = rest.value(0);
|
||||||
|
if (input.isEmpty()) {
|
||||||
|
err << "Usage: qelectrotech " << flag << " <project.qet> <output>\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
if (!QFileInfo::exists(input)) {
|
||||||
|
err << "Project not found: " << input << "\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
QETProject project(input);
|
||||||
|
if (project.state() != QETProject::Ok) {
|
||||||
|
err << "Failed to open project: " << input
|
||||||
|
<< " (state " << project.state() << ")\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --info writes JSON to stdout, or to an optional output file.
|
||||||
|
if (format == "info")
|
||||||
|
return exportInfo(project, rest.value(1));
|
||||||
|
|
||||||
|
const QString output = rest.value(1);
|
||||||
|
if (output.isEmpty()) {
|
||||||
|
err << "Usage: qelectrotech " << flag
|
||||||
|
<< " <project.qet> <output>\n";
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
if (format == "pdf")
|
||||||
|
return exportPdf(project, output);
|
||||||
|
if (format == "cables" || format == "wires")
|
||||||
|
return exportCsv(project, format, output);
|
||||||
|
if (format == "bom")
|
||||||
|
return exportBom(project, output);
|
||||||
|
if (format == "nets")
|
||||||
|
return exportNets(project, output);
|
||||||
|
if (format == "links")
|
||||||
|
return exportLinks(project, output);
|
||||||
|
if (format == "resave")
|
||||||
|
return resaveProject(project, output);
|
||||||
|
if (format == "settb")
|
||||||
|
return setTitleBlock(project, output, rest.mid(2));
|
||||||
|
return exportImages(project, format, output);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace CLIExport
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2025 The QElectroTech Team
|
||||||
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef CLI_EXPORT_H
|
||||||
|
#define CLI_EXPORT_H
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Headless command-line export.
|
||||||
|
|
||||||
|
Implements the long-requested batch/headless export
|
||||||
|
(qelectrotech.org bugtracker #171, GitHub #309): render a project's
|
||||||
|
diagrams to files without opening the GUI.
|
||||||
|
|
||||||
|
Detected and handled in main() before the GUI is created.
|
||||||
|
*/
|
||||||
|
namespace CLIExport {
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief True if @p args request a CLI export
|
||||||
|
(i.e. contain one of the export options).
|
||||||
|
*/
|
||||||
|
bool isExportRequest(const QStringList &args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Run the CLI export described by @p args.
|
||||||
|
@return process exit code (0 on success).
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
qelectrotech --export-pdf <project.qet> <output.pdf>
|
||||||
|
qelectrotech --export-png <project.qet> <output_dir>
|
||||||
|
qelectrotech --export-svg <project.qet> <output_dir>
|
||||||
|
qelectrotech --export-cables <project.qet> <output.csv>
|
||||||
|
qelectrotech --export-wires <project.qet> <output.csv>
|
||||||
|
qelectrotech --export-bom <project.qet> <output.csv>
|
||||||
|
qelectrotech --export-nets <project.qet> <output.json>
|
||||||
|
qelectrotech --export-links <project.qet> <output.csv>
|
||||||
|
qelectrotech --info <project.qet> [output.json]
|
||||||
|
qelectrotech --check-elements <element.elmt | directory>
|
||||||
|
qelectrotech --resave <project.qet> <output.qet>
|
||||||
|
qelectrotech --set-titleblock <project.qet> <output.qet> key=value...
|
||||||
|
|
||||||
|
PDF: one multi-page document (one diagram per page).
|
||||||
|
PNG/SVG: one file per diagram, named <output_dir>/<NN>_<title>.<ext>.
|
||||||
|
cables: wiring list (one row per conductor) as CSV.
|
||||||
|
wires: list of distinct wire numbers as CSV.
|
||||||
|
bom: bill of materials (one row per element) as CSV.
|
||||||
|
nets: electrical nets (connected-terminal groups) as JSON.
|
||||||
|
links: element cross-references (coil/contact) as CSV, with
|
||||||
|
unresolved links flagged.
|
||||||
|
info: structural project summary as JSON (stdout, or a file) —
|
||||||
|
per-page element / conductor counts and unconnected terminals.
|
||||||
|
check-elements: validate .elmt file(s) against the element schema.
|
||||||
|
resave: load and rewrite the project XML (round-trip integrity).
|
||||||
|
set-titleblock: stamp title-block fields onto every folio, then save.
|
||||||
|
Keys: title, author, date (or date=today), plant, location,
|
||||||
|
revision, version, filename; any other key becomes a custom
|
||||||
|
field. E.g. --set-titleblock in.qet out.qet revision=B date=today
|
||||||
|
*/
|
||||||
|
int run(const QStringList &args);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // CLI_EXPORT_H
|
||||||
@@ -383,7 +383,7 @@ void projectDataBase::createElementNomenclatureView()
|
|||||||
"ei.supplier_auxiliary4 AS supplier_auxiliary4,"
|
"ei.supplier_auxiliary4 AS supplier_auxiliary4,"
|
||||||
"ei.quantity_auxiliary4 AS quantity_auxiliary4,"
|
"ei.quantity_auxiliary4 AS quantity_auxiliary4,"
|
||||||
"ei.unity_auxiliary4 AS unity_auxiliary4,"
|
"ei.unity_auxiliary4 AS unity_auxiliary4,"
|
||||||
|
"ei.exclude_from_bom AS exclude_from_bom,"
|
||||||
|
|
||||||
"d.pos AS diagram_position,"
|
"d.pos AS diagram_position,"
|
||||||
"e.type AS element_type,"
|
"e.type AS element_type,"
|
||||||
@@ -392,7 +392,7 @@ void projectDataBase::createElementNomenclatureView()
|
|||||||
"di.folio AS folio,"
|
"di.folio AS folio,"
|
||||||
"e.pos AS position "
|
"e.pos AS position "
|
||||||
" FROM element_info ei, diagram_info di, element e, diagram d"
|
" FROM element_info ei, diagram_info di, element e, diagram d"
|
||||||
" WHERE ei.element_uuid = e.uuid AND e.diagram_uuid = d.uuid AND di.diagram_uuid = d.uuid");
|
" WHERE ei.element_uuid = e.uuid AND e.diagram_uuid = d.uuid AND di.diagram_uuid = d.uuid AND (ei.exclude_from_bom IS NOT 'true')");
|
||||||
|
|
||||||
QSqlQuery query(m_data_base);
|
QSqlQuery query(m_data_base);
|
||||||
if (!query.exec(create_view)) {
|
if (!query.exec(create_view)) {
|
||||||
|
|||||||
@@ -373,6 +373,11 @@ QString ElementQueryWidget::queryStr() const
|
|||||||
where.clear();
|
where.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString exclude_condition = "(exclude_from_bom IS NULL OR exclude_from_bom != '1')";
|
||||||
|
|
||||||
|
filter_ += " AND " + exclude_condition;
|
||||||
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
if (where.isEmpty() && !filter_.isEmpty()) {
|
if (where.isEmpty() && !filter_.isEmpty()) {
|
||||||
filter_.remove(0, 4); //Remove the first " AND" of filter.
|
filter_.remove(0, 4); //Remove the first " AND" of filter.
|
||||||
filter_.prepend( " WHERE");
|
filter_.prepend( " WHERE");
|
||||||
@@ -456,7 +461,7 @@ void ElementQueryWidget::setUpItems()
|
|||||||
{
|
{
|
||||||
for(QString key : QETInformation::elementInfoKeys())
|
for(QString key : QETInformation::elementInfoKeys())
|
||||||
{
|
{
|
||||||
if (key == "formula")
|
if (key == "formula" || key == "exclude_from_bom")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto item = new QListWidgetItem(QETInformation::translatedInfoKey(key), ui->m_var_list);
|
auto item = new QListWidgetItem(QETInformation::translatedInfoKey(key), ui->m_var_list);
|
||||||
|
|||||||
+3
-2
@@ -142,10 +142,11 @@ class Diagram : public QGraphicsScene
|
|||||||
void wheelEvent (QGraphicsSceneWheelEvent *event) override;
|
void wheelEvent (QGraphicsSceneWheelEvent *event) override;
|
||||||
void keyPressEvent (QKeyEvent *event) override;
|
void keyPressEvent (QKeyEvent *event) override;
|
||||||
void keyReleaseEvent (QKeyEvent *) override;
|
void keyReleaseEvent (QKeyEvent *) override;
|
||||||
void correctTextPos(Element* elmt);
|
|
||||||
void restoreText(Element* elmt);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void correctTextPos(Element* elmt);
|
||||||
|
void restoreText(Element* elmt);
|
||||||
QUuid uuid();
|
QUuid uuid();
|
||||||
void setEventInterface (DiagramEventInterface *event_interface);
|
void setEventInterface (DiagramEventInterface *event_interface);
|
||||||
void clearEventInterface();
|
void clearEventInterface();
|
||||||
|
|||||||
@@ -313,6 +313,12 @@ void PartText::setPlainText(const QString &text) {
|
|||||||
void PartText::setFont(const QFont &font) {
|
void PartText::setFont(const QFont &font) {
|
||||||
if (font != this -> font()) {
|
if (font != this -> font()) {
|
||||||
QGraphicsTextItem::setFont(font);
|
QGraphicsTextItem::setFont(font);
|
||||||
|
// Re-anchor: the item's position transform is -margin(), and margin()
|
||||||
|
// depends on the font ascent. Without re-running this on a font change,
|
||||||
|
// the transform keeps the previous font's ascent — so the text renders
|
||||||
|
// at a different spot after save/reopen (the position recomputes from
|
||||||
|
// the saved font on load). See #158.
|
||||||
|
adjustItemPosition();
|
||||||
emit fontChanged(font);
|
emit fontChanged(font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,17 @@ void ElementDialog::setUpWidget()
|
|||||||
} else if (m_mode == SaveTemplate) {
|
} else if (m_mode == SaveTemplate) {
|
||||||
m_text_field->setPlaceholderText(tr("Nom du nouveau template"));
|
m_text_field->setPlaceholderText(tr("Nom du nouveau template"));
|
||||||
} else {
|
} else {
|
||||||
m_text_field->setPlaceholderText(tr("Nom du nouvel élément"));
|
// This is the element's file name, not its display name: the field
|
||||||
|
// only accepts file-name characters (QFileNameEdit). The visible
|
||||||
|
// element name is edited separately in the element properties.
|
||||||
|
m_text_field->setPlaceholderText(
|
||||||
|
tr("Nom de fichier de l'élément",
|
||||||
|
"placeholder: the element's file name, not its display name"));
|
||||||
|
m_text_field->setToolTip(
|
||||||
|
tr("Nom de fichier de l'élément : chiffres, minuscules, « - », "
|
||||||
|
"« _ » et « . » uniquement.\nLe nom affiché de l'élément se "
|
||||||
|
"modifie séparément dans les propriétés de l'élément.",
|
||||||
|
"tooltip for the element file-name field"));
|
||||||
}
|
}
|
||||||
|
|
||||||
layout->addWidget(m_text_field);
|
layout->addWidget(m_text_field);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "elementspanelwidget.h"
|
#include "elementspanelwidget.h"
|
||||||
|
|
||||||
#include "diagram.h"
|
#include "diagram.h"
|
||||||
#include "editor/ui/qetelementeditor.h"
|
#include "editor/ui/qetelementeditor.h"
|
||||||
#include "elementscategoryeditor.h"
|
#include "elementscategoryeditor.h"
|
||||||
@@ -26,6 +25,7 @@
|
|||||||
#include "titleblock/templatedeleter.h"
|
#include "titleblock/templatedeleter.h"
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include "qetgraphicsitem/element.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
When the ENABLE_PANEL_WIDGET_DND_CHECKS flag is set, the panel
|
When the ENABLE_PANEL_WIDGET_DND_CHECKS flag is set, the panel
|
||||||
@@ -59,7 +59,8 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
|
|||||||
prj_close = new QAction(QET::Icons::DocumentClose, tr("Fermer ce projet"), this);
|
prj_close = new QAction(QET::Icons::DocumentClose, tr("Fermer ce projet"), this);
|
||||||
prj_edit_prop = new QAction(QET::Icons::DialogInformation, tr("Propriétés du projet"), this);
|
prj_edit_prop = new QAction(QET::Icons::DialogInformation, tr("Propriétés du projet"), this);
|
||||||
prj_prop_diagram = new QAction(QET::Icons::DialogInformation, tr("Propriétés du folio"), this);
|
prj_prop_diagram = new QAction(QET::Icons::DialogInformation, tr("Propriétés du folio"), this);
|
||||||
prj_add_diagram = new QAction(QET::Icons::DiagramAdd, tr("Ajouter un folio"), this);
|
prj_add_diagram = new QAction(QET::Icons::DiagramAdd, tr("Ajouter un folio"), this);
|
||||||
|
prj_duplicate_diagram = new QAction(QET::Icons::IC_CopyFile, tr("Copier et coller"), this);
|
||||||
prj_del_diagram = new QAction(QET::Icons::DiagramDelete, tr("Supprimer ce folio"), this);
|
prj_del_diagram = new QAction(QET::Icons::DiagramDelete, tr("Supprimer ce folio"), this);
|
||||||
prj_move_diagram_up = new QAction(QET::Icons::GoUp, tr("Remonter ce folio"), this);
|
prj_move_diagram_up = new QAction(QET::Icons::GoUp, tr("Remonter ce folio"), this);
|
||||||
prj_move_diagram_down = new QAction(QET::Icons::GoDown, tr("Abaisser ce folio"), this);
|
prj_move_diagram_down = new QAction(QET::Icons::GoDown, tr("Abaisser ce folio"), this);
|
||||||
@@ -100,6 +101,7 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) {
|
|||||||
connect(prj_prop_diagram, SIGNAL(triggered()), this, SLOT(editDiagramProperties()));
|
connect(prj_prop_diagram, SIGNAL(triggered()), this, SLOT(editDiagramProperties()));
|
||||||
connect(prj_add_diagram, SIGNAL(triggered()), this, SLOT(newDiagram()));
|
connect(prj_add_diagram, SIGNAL(triggered()), this, SLOT(newDiagram()));
|
||||||
connect(prj_del_diagram, SIGNAL(triggered()), this, SLOT(deleteDiagram()));
|
connect(prj_del_diagram, SIGNAL(triggered()), this, SLOT(deleteDiagram()));
|
||||||
|
connect(prj_duplicate_diagram, SIGNAL(triggered()), this, SLOT(duplicateDiagram()));
|
||||||
connect(prj_move_diagram_up, SIGNAL(triggered()), this, SLOT(moveDiagramUp()));
|
connect(prj_move_diagram_up, SIGNAL(triggered()), this, SLOT(moveDiagramUp()));
|
||||||
connect(prj_move_diagram_down, SIGNAL(triggered()), this, SLOT(moveDiagramDown()));
|
connect(prj_move_diagram_down, SIGNAL(triggered()), this, SLOT(moveDiagramDown()));
|
||||||
connect(prj_move_diagram_top, SIGNAL(triggered()), this, SLOT(moveDiagramUpTop()));
|
connect(prj_move_diagram_top, SIGNAL(triggered()), this, SLOT(moveDiagramUpTop()));
|
||||||
@@ -447,7 +449,8 @@ void ElementsPanelWidget::updateButtons()
|
|||||||
}
|
}
|
||||||
|
|
||||||
prj_del_diagram -> setEnabled(is_writable);
|
prj_del_diagram -> setEnabled(is_writable);
|
||||||
prj_move_diagram_up -> setEnabled(is_writable && min_position > 0);
|
prj_duplicate_diagram -> setEnabled(is_writable);
|
||||||
|
prj_move_diagram_up -> setEnabled(is_writable && min_position > 0);
|
||||||
prj_move_diagram_down -> setEnabled(is_writable && max_position < project_diagrams_count - 1);
|
prj_move_diagram_down -> setEnabled(is_writable && max_position < project_diagrams_count - 1);
|
||||||
prj_move_diagram_top -> setEnabled(is_writable && min_position > 0);
|
prj_move_diagram_top -> setEnabled(is_writable && min_position > 0);
|
||||||
|
|
||||||
@@ -501,6 +504,7 @@ void ElementsPanelWidget::handleContextMenu(const QPoint &pos) {
|
|||||||
case QET::Diagram:
|
case QET::Diagram:
|
||||||
context_menu -> addAction(prj_prop_diagram);
|
context_menu -> addAction(prj_prop_diagram);
|
||||||
context_menu -> addAction(prj_del_diagram);
|
context_menu -> addAction(prj_del_diagram);
|
||||||
|
context_menu -> addAction(prj_duplicate_diagram);
|
||||||
context_menu -> addAction(prj_move_diagram_top);
|
context_menu -> addAction(prj_move_diagram_top);
|
||||||
context_menu -> addAction(prj_move_diagram_upx10);
|
context_menu -> addAction(prj_move_diagram_upx10);
|
||||||
context_menu -> addAction(prj_move_diagram_upx100);
|
context_menu -> addAction(prj_move_diagram_upx100);
|
||||||
@@ -593,3 +597,56 @@ void ElementsPanelWidget::keyPressEvent(QKeyEvent *e) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Duplicates the selected folios (pages) along with their content
|
||||||
|
* and properties, and cleanly resolves cross-references.
|
||||||
|
*/
|
||||||
|
void ElementsPanelWidget::duplicateDiagram()
|
||||||
|
{
|
||||||
|
QList<Diagram *> diagrams_to_duplicate = elements_panel->selectedDiagrams();
|
||||||
|
if (diagrams_to_duplicate.isEmpty()) return;
|
||||||
|
|
||||||
|
QETProject *project = diagrams_to_duplicate.first()->project();
|
||||||
|
if (!project || project->isReadOnly()) return;
|
||||||
|
|
||||||
|
for (Diagram *source_diagram : diagrams_to_duplicate) {
|
||||||
|
|
||||||
|
Diagram *new_diagram = project->addNewDiagram();
|
||||||
|
if (!new_diagram) continue;
|
||||||
|
|
||||||
|
QString template_name = source_diagram->border_and_titleblock.titleBlockTemplateName();
|
||||||
|
new_diagram->setTitleBlockTemplate(template_name);
|
||||||
|
|
||||||
|
TitleBlockProperties tbp = source_diagram->border_and_titleblock.exportTitleBlock();
|
||||||
|
new_diagram->border_and_titleblock.importTitleBlock(tbp);
|
||||||
|
|
||||||
|
BorderProperties bp = source_diagram->border_and_titleblock.exportBorder();
|
||||||
|
new_diagram->border_and_titleblock.importBorder(bp);
|
||||||
|
|
||||||
|
for (QGraphicsItem *item : source_diagram->items()) {
|
||||||
|
if (Element *elmt = dynamic_cast<Element *>(item)) {
|
||||||
|
source_diagram->correctTextPos(elmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QDomDocument doc = source_diagram->toXml();
|
||||||
|
QDomElement diagram_elmt = doc.documentElement();
|
||||||
|
|
||||||
|
for (QGraphicsItem *item : source_diagram->items()) {
|
||||||
|
if (Element *elmt = dynamic_cast<Element *>(item)) {
|
||||||
|
source_diagram->restoreText(elmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new_diagram->fromXml(diagram_elmt, QPointF(0, 0), false, nullptr);
|
||||||
|
|
||||||
|
for (QGraphicsItem *item : new_diagram->items()) {
|
||||||
|
if (Element *elmt = dynamic_cast<Element *>(item)) {
|
||||||
|
new_diagram->restoreText(elmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elements_panel->reload();
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class ElementsPanelWidget : public QWidget {
|
|||||||
*prj_prop_diagram,
|
*prj_prop_diagram,
|
||||||
*prj_add_diagram,
|
*prj_add_diagram,
|
||||||
*prj_del_diagram,
|
*prj_del_diagram,
|
||||||
|
*prj_duplicate_diagram,
|
||||||
*prj_move_diagram_up,
|
*prj_move_diagram_up,
|
||||||
*prj_move_diagram_top,
|
*prj_move_diagram_top,
|
||||||
*prj_move_diagram_down,
|
*prj_move_diagram_down,
|
||||||
@@ -88,6 +89,7 @@ class ElementsPanelWidget : public QWidget {
|
|||||||
void editDiagramProperties();
|
void editDiagramProperties();
|
||||||
void newDiagram();
|
void newDiagram();
|
||||||
void deleteDiagram();
|
void deleteDiagram();
|
||||||
|
void duplicateDiagram();
|
||||||
void moveDiagramUp();
|
void moveDiagramUp();
|
||||||
void moveDiagramDown();
|
void moveDiagramDown();
|
||||||
void moveDiagramUpTop();
|
void moveDiagramUpTop();
|
||||||
|
|||||||
@@ -15,13 +15,17 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
#include "cli_export.h"
|
||||||
#include "machine_info.h"
|
#include "machine_info.h"
|
||||||
#include "qet.h"
|
#include "qet.h"
|
||||||
#include "qetapp.h"
|
#include "qetapp.h"
|
||||||
|
#include "qetproject.h"
|
||||||
#include "singleapplication.h"
|
#include "singleapplication.h"
|
||||||
#include "utils/macosxopenevent.h"
|
#include "utils/macosxopenevent.h"
|
||||||
#include "utils/qetsettings.h"
|
#include "utils/qetsettings.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QtConcurrentRun>
|
#include <QtConcurrentRun>
|
||||||
|
|
||||||
@@ -194,6 +198,23 @@ QGuiApplication::setHighDpiScaleFactorRoundingPolicy(QetSettings::hdpiScaleFacto
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Headless command-line export: render a project to PDF/PNG/SVG without
|
||||||
|
// opening the GUI, then exit. Must be handled before SingleApplication
|
||||||
|
// (which would forward the args to an already-running instance).
|
||||||
|
{
|
||||||
|
QStringList raw_args;
|
||||||
|
for (int i = 0; i < argc; ++i)
|
||||||
|
raw_args << QString::fromLocal8Bit(argv[i]);
|
||||||
|
if (CLIExport::isExportRequest(raw_args)) {
|
||||||
|
QApplication export_app(argc, argv);
|
||||||
|
// No crash-recovery backups in one-shot CLI mode: the backup write
|
||||||
|
// runs on a background thread referencing the project and races the
|
||||||
|
// process exit (intermittent segfault in QET::writeToFile).
|
||||||
|
QETProject::setBackupEnabled(false);
|
||||||
|
return CLIExport::run(export_app.arguments());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SingleApplication app(argc, argv, true);
|
SingleApplication app(argc, argv, true);
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
//Handle the opening of QET when user double click on a .qet .elmt .tbt file
|
//Handle the opening of QET when user double click on a .qet .elmt .tbt file
|
||||||
|
|||||||
@@ -0,0 +1,382 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2025 The QElectroTech Team
|
||||||
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "pdf_links.h"
|
||||||
|
|
||||||
|
#include "diagram.h"
|
||||||
|
#include "qetgraphicsitem/crossrefitem.h"
|
||||||
|
#include "qetgraphicsitem/dynamicelementtextitem.h"
|
||||||
|
#include "qetgraphicsitem/element.h"
|
||||||
|
#include "qetgraphicsitem/elementtextitemgroup.h"
|
||||||
|
|
||||||
|
// Private Qt PDF engine for drawHyperlink() — not public API, stable since Qt4.
|
||||||
|
// Requires QT += gui-private in qelectrotech.pro / gui-private in CMake.
|
||||||
|
#include <private/qpdf_p.h>
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QList>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
namespace PdfLinks {
|
||||||
|
|
||||||
|
void injectCrossRefLinks(QPdfEngine *engine, Diagram *diagram,
|
||||||
|
const PageGeometry &geom,
|
||||||
|
const QMap<Diagram *, int> &pageMap,
|
||||||
|
const QString &outputFileName)
|
||||||
|
{
|
||||||
|
if (!engine || !diagram)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QTransform &fit = geom.sceneToDevice;
|
||||||
|
const QRectF &target = geom.target;
|
||||||
|
const QRectF &pageBounds = geom.pageBounds;
|
||||||
|
|
||||||
|
// Compute, in PDF points on its OWN page, the rectangle to frame for a
|
||||||
|
// target element (used as a /FitR destination so the link zooms onto it).
|
||||||
|
auto destRectPdf = [&](Element *tgt) -> QRectF {
|
||||||
|
Diagram *dg = tgt ? tgt->diagram() : nullptr;
|
||||||
|
if (!dg) return QRectF();
|
||||||
|
const QRectF srcT = geom.sourceRectOf(dg);
|
||||||
|
if (srcT.width() <= 0.0 || srcT.height() <= 0.0) return QRectF();
|
||||||
|
const qreal sT = qMin(target.width() / srcT.width(),
|
||||||
|
target.height() / srcT.height());
|
||||||
|
QTransform fitT;
|
||||||
|
fitT.translate(target.x(), target.y());
|
||||||
|
fitT.scale(sT, sT);
|
||||||
|
fitT.translate(-srcT.x(), -srcT.y());
|
||||||
|
|
||||||
|
QRectF elemScene = tgt->mapRectToScene(tgt->boundingRect());
|
||||||
|
// Frame the element with a little context, and enforce a minimum
|
||||||
|
// framed size so tiny contacts don't zoom in extremely.
|
||||||
|
const qreal pad = 25.0;
|
||||||
|
elemScene.adjust(-pad, -pad, pad, pad);
|
||||||
|
const qreal minSide = 160.0;
|
||||||
|
if (elemScene.width() < minSide)
|
||||||
|
elemScene.adjust(-(minSide - elemScene.width()) / 2.0, 0,
|
||||||
|
(minSide - elemScene.width()) / 2.0, 0);
|
||||||
|
if (elemScene.height() < minSide)
|
||||||
|
elemScene.adjust(0, -(minSide - elemScene.height()) / 2.0,
|
||||||
|
0, (minSide - elemScene.height()) / 2.0);
|
||||||
|
|
||||||
|
const QRectF devT = fitT.mapRect(elemScene);
|
||||||
|
const QPointF a = geom.devToPdf(devT.topLeft());
|
||||||
|
const QPointF b = geom.devToPdf(devT.bottomRight());
|
||||||
|
return QRectF(QPointF(qMin(a.x(), b.x()), qMin(a.y(), b.y())),
|
||||||
|
QPointF(qMax(a.x(), b.x()), qMax(a.y(), b.y())));
|
||||||
|
};
|
||||||
|
|
||||||
|
auto injectLink = [&](const QRectF &sceneRect, Element *targetElmt) {
|
||||||
|
if (!targetElmt || !targetElmt->diagram()) return;
|
||||||
|
const int targetPage = pageMap.value(targetElmt->diagram(), -1);
|
||||||
|
if (targetPage < 1) return;
|
||||||
|
const QRectF devRect = fit.mapRect(sceneRect);
|
||||||
|
if (!devRect.isValid() || !pageBounds.intersects(devRect)) return;
|
||||||
|
|
||||||
|
QString frag = QString("page=%1").arg(targetPage);
|
||||||
|
const QRectF d = destRectPdf(targetElmt); // /FitR L_B_R_T
|
||||||
|
if (d.isValid())
|
||||||
|
frag += QString("&fitr=%1_%2_%3_%4")
|
||||||
|
.arg(qRound(d.left())).arg(qRound(d.top()))
|
||||||
|
.arg(qRound(d.right())).arg(qRound(d.bottom()));
|
||||||
|
|
||||||
|
QUrl url = QUrl::fromLocalFile(outputFileName);
|
||||||
|
url.setFragment(frag);
|
||||||
|
engine->drawHyperlink(devRect, url);
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto *item : diagram->items()) {
|
||||||
|
|
||||||
|
// --- CrossRefItem links ---
|
||||||
|
if (auto *xref = dynamic_cast<CrossRefItem*>(item)) {
|
||||||
|
for (auto it = xref->hoveredContactsMap().begin();
|
||||||
|
it != xref->hoveredContactsMap().end(); ++it)
|
||||||
|
{
|
||||||
|
Element *targetElmt = it.key();
|
||||||
|
if (!targetElmt || !targetElmt->diagram()) continue;
|
||||||
|
// it.value() is in the CrossRefItem's LOCAL coords -> scene
|
||||||
|
injectLink(xref->mapRectToScene(it.value()), targetElmt);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Folio report links (DynamicElementTextItem) ---
|
||||||
|
if (auto *deti = dynamic_cast<DynamicElementTextItem*>(item)) {
|
||||||
|
Element *parent = deti->parentElement();
|
||||||
|
if (!parent) continue;
|
||||||
|
|
||||||
|
// (a) Report element : label -> linked report on another folio
|
||||||
|
if (parent->linkType() & Element::AllReport) {
|
||||||
|
if (parent->linkedElements().isEmpty()) continue;
|
||||||
|
|
||||||
|
bool showsLabel =
|
||||||
|
(deti->textFrom() == DynamicElementTextItem::ElementInfo
|
||||||
|
&& deti->infoName() == QLatin1String("label")) ||
|
||||||
|
(deti->textFrom() == DynamicElementTextItem::CompositeText
|
||||||
|
&& deti->compositeText().contains(QStringLiteral("%{label}")));
|
||||||
|
if (!showsLabel) continue;
|
||||||
|
|
||||||
|
Element *targetElmt = parent->linkedElements().first();
|
||||||
|
if (!targetElmt || !targetElmt->diagram()) continue;
|
||||||
|
|
||||||
|
injectLink(deti->mapRectToScene(deti->boundingRect()), targetElmt);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (b) Slave element : the "(folio-pos)" text -> master element
|
||||||
|
if (parent->linkType() == Element::Slave) {
|
||||||
|
QGraphicsTextItem *sx = deti->slaveXrefItem();
|
||||||
|
Element *master = deti->masterElement();
|
||||||
|
if (sx && master && master->diagram()) {
|
||||||
|
injectLink(sx->mapRectToScene(sx->boundingRect()), master);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Slave cross-reference carried by a grouped text ---
|
||||||
|
if (auto *grp = dynamic_cast<ElementTextItemGroup*>(item)) {
|
||||||
|
Element *parent = grp->parentElement();
|
||||||
|
if (!parent || parent->linkType() != Element::Slave) continue;
|
||||||
|
if (parent->linkedElements().isEmpty()) continue;
|
||||||
|
QGraphicsTextItem *sx = grp->slaveXrefItem();
|
||||||
|
if (!sx) continue;
|
||||||
|
Element *master = parent->linkedElements().first();
|
||||||
|
if (!master || !master->diagram()) continue;
|
||||||
|
injectLink(sx->mapRectToScene(sx->boundingRect()), master);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void convertUriToGoTo(const QString &pdfPath)
|
||||||
|
{
|
||||||
|
// --- 1. Read raw bytes ---
|
||||||
|
QFile f(pdfPath);
|
||||||
|
if (!f.open(QIODevice::ReadOnly)) return;
|
||||||
|
QByteArray data = f.readAll();
|
||||||
|
f.close();
|
||||||
|
|
||||||
|
// --- 2. Collect page object numbers in document order ---
|
||||||
|
// Read them from the page tree (/Type /Pages -> /Kids [ N 0 R ... ]).
|
||||||
|
// This is reliable; scanning raw bytes for "/Type /Page" is NOT: that
|
||||||
|
// marker also occurs inside content streams, and a forward lookahead
|
||||||
|
// wrongly tags neighbouring objects (it found 280 "pages" for a 137-page
|
||||||
|
// document). Qt writes a single, flat /Kids array listing every page.
|
||||||
|
QVector<int> pageObjs;
|
||||||
|
{
|
||||||
|
int pagesPos = data.indexOf("/Type /Pages");
|
||||||
|
int kidsPos = (pagesPos == -1) ? -1 : data.indexOf("/Kids", pagesPos);
|
||||||
|
int lb = (kidsPos == -1) ? -1 : data.indexOf('[', kidsPos);
|
||||||
|
int rb = (lb == -1) ? -1 : data.indexOf(']', lb);
|
||||||
|
if (lb != -1 && rb != -1 && rb > lb) {
|
||||||
|
const QString kids =
|
||||||
|
QString::fromLatin1(data.mid(lb + 1, rb - lb - 1));
|
||||||
|
QRegularExpression re(QStringLiteral("(\\d+)\\s+\\d+\\s+R"));
|
||||||
|
auto it = re.globalMatch(kids);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
int objNum = it.next().captured(1).toInt();
|
||||||
|
if (objNum > 0) pageObjs.append(objNum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageObjs.isEmpty()) return; // nothing to do
|
||||||
|
|
||||||
|
// --- 3. Replace URI annotations with GoTo ---
|
||||||
|
// Pattern (Qt always writes exactly this):
|
||||||
|
// /S /URI\n/URI (file:///...<anything>#page=N)\n
|
||||||
|
// or (older patches without file://):
|
||||||
|
// /S /URI\n/URI (page=N)\n
|
||||||
|
bool changed = false;
|
||||||
|
{
|
||||||
|
// We do a manual scan to handle variable-length replacements.
|
||||||
|
QByteArray out;
|
||||||
|
out.reserve(data.size());
|
||||||
|
|
||||||
|
const QByteArray sUri = "/S /URI\n/URI (";
|
||||||
|
const QByteArray sGoTo = "/S /GoTo\n/D [";
|
||||||
|
int pos = 0;
|
||||||
|
|
||||||
|
while (pos < data.size()) {
|
||||||
|
int found = data.indexOf(sUri, pos);
|
||||||
|
if (found == -1) {
|
||||||
|
out.append(data.mid(pos));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy everything up to the match
|
||||||
|
out.append(data.mid(pos, found - pos));
|
||||||
|
|
||||||
|
// Find closing ')' of the URI value
|
||||||
|
int uriStart = found + sUri.size();
|
||||||
|
int closeParen = data.indexOf(')', uriStart);
|
||||||
|
if (closeParen == -1) {
|
||||||
|
// Malformed — copy rest verbatim
|
||||||
|
out.append(data.mid(found));
|
||||||
|
pos = data.size();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray uriVal = data.mid(uriStart, closeParen - uriStart);
|
||||||
|
|
||||||
|
// Extract page number: look for #page=N or bare page=N
|
||||||
|
int pageNum = -1;
|
||||||
|
int hashPos = uriVal.lastIndexOf("#page=");
|
||||||
|
int digitStart = -1;
|
||||||
|
if (hashPos != -1) {
|
||||||
|
digitStart = hashPos + 6;
|
||||||
|
} else if (uriVal.startsWith("page=")) {
|
||||||
|
digitStart = 5;
|
||||||
|
}
|
||||||
|
if (digitStart != -1) {
|
||||||
|
// Take only the leading digits: the fragment may carry extra
|
||||||
|
// parameters after the page number (e.g. "22&fitr=15_489_..."),
|
||||||
|
// and QByteArray::toInt() would fail on the whole remainder.
|
||||||
|
int e = digitStart;
|
||||||
|
while (e < uriVal.size()
|
||||||
|
&& uriVal[e] >= '0' && uriVal[e] <= '9')
|
||||||
|
++e;
|
||||||
|
if (e > digitStart)
|
||||||
|
pageNum = uriVal.mid(digitStart, e - digitStart).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageNum >= 1 && pageNum <= pageObjs.size()) {
|
||||||
|
// Valid page reference — emit GoTo action.
|
||||||
|
int pageObjNum = pageObjs[pageNum - 1];
|
||||||
|
|
||||||
|
// Optional precise destination: &fitr=Left_Bottom_Right_Top
|
||||||
|
// (integer PDF points). If present -> /FitR (frame the element);
|
||||||
|
// otherwise -> /Fit (whole page, top).
|
||||||
|
QByteArray dest = " /Fit]";
|
||||||
|
int fr = uriVal.indexOf("fitr=");
|
||||||
|
if (fr != -1) {
|
||||||
|
QByteArray rest = uriVal.mid(fr + 5);
|
||||||
|
// stop at first char that is not part of the number list
|
||||||
|
int end = 0;
|
||||||
|
while (end < rest.size()
|
||||||
|
&& ((rest[end] >= '0' && rest[end] <= '9')
|
||||||
|
|| rest[end] == '_' || rest[end] == '-'))
|
||||||
|
++end;
|
||||||
|
QList<QByteArray> parts = rest.left(end).split('_');
|
||||||
|
if (parts.size() == 4) {
|
||||||
|
dest = " /FitR " + parts[0] + " " + parts[1] + " "
|
||||||
|
+ parts[2] + " " + parts[3] + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray goTo = sGoTo
|
||||||
|
+ QByteArray::number(pageObjNum)
|
||||||
|
+ " 0 R" + dest;
|
||||||
|
out.append(goTo);
|
||||||
|
changed = true;
|
||||||
|
} else {
|
||||||
|
// Unknown page — keep original URI
|
||||||
|
out.append(sUri);
|
||||||
|
out.append(uriVal);
|
||||||
|
out.append(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = closeParen + 1; // skip past ')'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!changed) return; // nothing was replaced
|
||||||
|
data = out;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 4. Rebuild xref table ---
|
||||||
|
// Find start of existing xref (last occurrence)
|
||||||
|
int xrefStart = data.lastIndexOf("\nxref\n");
|
||||||
|
if (xrefStart == -1) xrefStart = data.lastIndexOf("\nxref ");
|
||||||
|
if (xrefStart == -1) return; // malformed PDF
|
||||||
|
++xrefStart; // skip the leading '\n'
|
||||||
|
|
||||||
|
QByteArray body = data.left(xrefStart);
|
||||||
|
|
||||||
|
// Collect all object offsets from the body
|
||||||
|
QMap<int, int> offsets; // objNum -> byte offset
|
||||||
|
{
|
||||||
|
const QByteArray objMarker = " 0 obj";
|
||||||
|
int pos = 0;
|
||||||
|
while ((pos = body.indexOf(objMarker, pos)) != -1) {
|
||||||
|
int numStart = pos - 1;
|
||||||
|
while (numStart > 0 && body[numStart-1] != '\n' && body[numStart-1] != '\r')
|
||||||
|
--numStart;
|
||||||
|
QByteArray numStr = body.mid(numStart, pos - numStart).trimmed();
|
||||||
|
bool ok = false;
|
||||||
|
int objNum = numStr.toInt(&ok);
|
||||||
|
if (ok && objNum > 0)
|
||||||
|
offsets[objNum] = numStart;
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offsets.isEmpty()) return;
|
||||||
|
|
||||||
|
int maxObj = offsets.lastKey();
|
||||||
|
|
||||||
|
// Build xref table
|
||||||
|
QByteArray xref;
|
||||||
|
xref += "xref\n";
|
||||||
|
xref += "0 " + QByteArray::number(maxObj + 1) + "\n";
|
||||||
|
xref += "0000000000 65535 f \n";
|
||||||
|
for (int i = 1; i <= maxObj; ++i) {
|
||||||
|
if (offsets.contains(i)) {
|
||||||
|
xref += QByteArray::number(offsets[i]).rightJustified(10, '0')
|
||||||
|
+ " 00000 n \n";
|
||||||
|
} else {
|
||||||
|
xref += "0000000000 65535 f \n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find trailer dict from the original xref section
|
||||||
|
int trailerPos = data.indexOf("trailer", xrefStart);
|
||||||
|
int trailerEnd = -1;
|
||||||
|
if (trailerPos != -1) {
|
||||||
|
trailerEnd = data.indexOf("%%EOF", trailerPos);
|
||||||
|
if (trailerEnd != -1) trailerEnd += 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray trailer;
|
||||||
|
if (trailerPos != -1 && trailerEnd != -1)
|
||||||
|
trailer = data.mid(trailerPos, trailerEnd - trailerPos);
|
||||||
|
else
|
||||||
|
trailer = "trailer\n<<>>\n%%EOF";
|
||||||
|
|
||||||
|
int newXrefOffset = body.size();
|
||||||
|
|
||||||
|
QByteArray result;
|
||||||
|
result.reserve(body.size() + xref.size() + trailer.size() + 30);
|
||||||
|
result += body;
|
||||||
|
result += xref;
|
||||||
|
result += trailer;
|
||||||
|
result += "\nstartxref\n";
|
||||||
|
result += QByteArray::number(newXrefOffset);
|
||||||
|
result += "\n%%EOF\n";
|
||||||
|
|
||||||
|
// --- 5. Write back ---
|
||||||
|
QFile out(pdfPath);
|
||||||
|
if (!out.open(QIODevice::WriteOnly | QIODevice::Truncate)) return;
|
||||||
|
out.write(result);
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace PdfLinks
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2006-2025 The QElectroTech Team
|
||||||
|
This file is part of QElectroTech.
|
||||||
|
|
||||||
|
QElectroTech is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
QElectroTech is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef PDF_LINKS_H
|
||||||
|
#define PDF_LINKS_H
|
||||||
|
|
||||||
|
#include <QMap>
|
||||||
|
#include <QPointF>
|
||||||
|
#include <QRectF>
|
||||||
|
#include <QString>
|
||||||
|
#include <QTransform>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
class QPdfEngine;
|
||||||
|
class Diagram;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shared helper that turns a project's cross-references and folio reports
|
||||||
|
into clickable internal hyperlinks in a Qt-generated PDF. Used by both the
|
||||||
|
GUI print path (ProjectPrintWindow) and the headless CLI export, each of
|
||||||
|
which builds its own page geometry and passes it in — this code never
|
||||||
|
computes the scene-to-page mapping itself.
|
||||||
|
*/
|
||||||
|
namespace PdfLinks {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Geometry mapping for one rendered PDF page. Each caller builds this
|
||||||
|
from its OWN page setup (printer page layout vs QPdfWriter), since the
|
||||||
|
device-pixel and point conversions differ between them.
|
||||||
|
*/
|
||||||
|
struct PageGeometry {
|
||||||
|
/// scene coordinates -> device pixels (the same "fit" render() applied)
|
||||||
|
QTransform sceneToDevice;
|
||||||
|
/// device paint rectangle, in pixels (the page area)
|
||||||
|
QRectF target;
|
||||||
|
/// links whose rectangle falls outside this are dropped
|
||||||
|
QRectF pageBounds;
|
||||||
|
/// device pixels -> PDF points (replicates the engine's page matrix)
|
||||||
|
std::function<QPointF(const QPointF &)> devToPdf;
|
||||||
|
/// a diagram -> its source rectangle in scene pixels (for /FitR framing)
|
||||||
|
std::function<QRectF(Diagram *)> sourceRectOf;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Inject clickable cross-reference / folio-report hyperlinks for @p diagram
|
||||||
|
into the current page of @p engine. Each link is emitted as a URI
|
||||||
|
annotation encoding the target page and a /FitR rectangle;
|
||||||
|
convertUriToGoTo() then rewrites those into native internal GoTo actions.
|
||||||
|
*/
|
||||||
|
void injectCrossRefLinks(QPdfEngine *engine, Diagram *diagram,
|
||||||
|
const PageGeometry &geom,
|
||||||
|
const QMap<Diagram *, int> &pageMap,
|
||||||
|
const QString &outputFileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Post-process a Qt-generated PDF file: rewrite every "/S /URI" link
|
||||||
|
annotation into a native internal "/S /GoTo" action (page + /FitR or
|
||||||
|
/Fit destination) and rebuild the xref table. No-op if the file has no
|
||||||
|
such annotations.
|
||||||
|
*/
|
||||||
|
void convertUriToGoTo(const QString &pdfPath);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // PDF_LINKS_H
|
||||||
@@ -18,12 +18,20 @@
|
|||||||
#include "projectprintwindow.h"
|
#include "projectprintwindow.h"
|
||||||
|
|
||||||
#include "../diagram.h"
|
#include "../diagram.h"
|
||||||
|
#include "../pdf_links.h"
|
||||||
#include "../qeticons.h"
|
#include "../qeticons.h"
|
||||||
#include "../qetproject.h"
|
#include "../qetproject.h"
|
||||||
#include "../qetversion.h"
|
#include "../qetversion.h"
|
||||||
|
#include "../qetgraphicsitem/crossrefitem.h"
|
||||||
|
#include "../qetgraphicsitem/dynamicelementtextitem.h"
|
||||||
|
#include "../qetgraphicsitem/elementtextitemgroup.h"
|
||||||
|
|
||||||
#include "ui_projectprintwindow.h"
|
#include "ui_projectprintwindow.h"
|
||||||
|
|
||||||
|
// Private Qt PDF engine for drawHyperlink() — not public API, stable since Qt4
|
||||||
|
// Requires QT += gui-private in qelectrotech.pro
|
||||||
|
#include <private/qpdf_p.h>
|
||||||
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||||
# include <QDesktopWidget>
|
# include <QDesktopWidget>
|
||||||
#else
|
#else
|
||||||
@@ -37,6 +45,11 @@
|
|||||||
#include <QPrintDialog>
|
#include <QPrintDialog>
|
||||||
#include <QPrintPreviewWidget>
|
#include <QPrintPreviewWidget>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ProjectPrintWindow::ProjectPrintWindow
|
* @brief ProjectPrintWindow::ProjectPrintWindow
|
||||||
@@ -214,13 +227,47 @@ void ProjectPrintWindow::requestPaint()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Build diagram -> first physical PDF page number map (1-based)
|
||||||
|
// Must be done before the print loop since page numbers depend on order
|
||||||
|
QMap<Diagram*, int> diagramPageMap;
|
||||||
|
{
|
||||||
|
int pageNum = 1;
|
||||||
|
for (auto diagram : selectedDiagram()) {
|
||||||
|
diagramPageMap.insert(diagram, pageNum);
|
||||||
|
// Each diagram may span multiple pages if not fit_page
|
||||||
|
if (!ui->m_fit_in_page_cb->isChecked()) {
|
||||||
|
auto option = exportProperties();
|
||||||
|
bool full_page = m_printer->fullPage();
|
||||||
|
int h = horizontalPagesCount(diagram, option, full_page);
|
||||||
|
int v = verticalPagesCount(diagram, option, full_page);
|
||||||
|
pageNum += h * v;
|
||||||
|
} else {
|
||||||
|
pageNum += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
QPainter painter(m_printer);
|
QPainter painter(m_printer);
|
||||||
|
|
||||||
|
// A real PDF export uses the QPdfEngine; the on-screen preview uses a
|
||||||
|
// preview paint engine. We only post-process when actually writing a PDF.
|
||||||
|
const bool pdfExport =
|
||||||
|
(m_printer->outputFormat() == QPrinter::PdfFormat)
|
||||||
|
&& (dynamic_cast<QPdfEngine*>(painter.paintEngine()) != nullptr);
|
||||||
|
|
||||||
for (auto diagram : selectedDiagram())
|
for (auto diagram : selectedDiagram())
|
||||||
{
|
{
|
||||||
first ? first = false : m_printer->newPage();
|
first ? first = false : m_printer->newPage();
|
||||||
printDiagram(diagram, ui->m_fit_in_page_cb->isChecked(), &painter, m_printer);
|
printDiagram(diagram, ui->m_fit_in_page_cb->isChecked(), &painter, m_printer, diagramPageMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: do NOT call painter.end() or pdfConvertUriToGoTo() here.
|
||||||
|
// We are inside the paintRequested slot: the QPrintPreviewWidget still
|
||||||
|
// owns the paint cycle. On macOS arm64 (Metal/CALayer compositor),
|
||||||
|
// closing the QPainter manually inside this slot leaves the backing
|
||||||
|
// store in an undefined state, producing a black screen after export.
|
||||||
|
// pdfConvertUriToGoTo() is deferred to print() via QTimer::singleShot(0).
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -230,7 +277,7 @@ void ProjectPrintWindow::requestPaint()
|
|||||||
* @param fit_page
|
* @param fit_page
|
||||||
* @param printer
|
* @param printer
|
||||||
*/
|
*/
|
||||||
void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer)
|
void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer, const QMap<Diagram*, int> &diagramPageMap)
|
||||||
{
|
{
|
||||||
|
|
||||||
////Prepare the print////
|
////Prepare the print////
|
||||||
@@ -317,6 +364,65 @@ void ProjectPrintWindow::printDiagram(Diagram *diagram, bool fit_page, QPainter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////Inject PDF cross-reference links////
|
||||||
|
if (printer->outputFormat() == QPrinter::PdfFormat && fit_page) {
|
||||||
|
auto *pdfEngine = dynamic_cast<QPdfEngine*>(painter->paintEngine());
|
||||||
|
if (pdfEngine) {
|
||||||
|
|
||||||
|
// QGraphicsScene::render() fait save()/restore() : worldTransform()
|
||||||
|
// est revenu a l'identite ici. On reconstruit DONC explicitement la
|
||||||
|
// transform appliquee par :
|
||||||
|
// diagram->render(painter, QRectF(), diagram_rect, KeepAspectRatio)
|
||||||
|
// cible vide => painter->viewport() ; source = diagram_rect ; centre.
|
||||||
|
const QRectF target = QRectF(painter->viewport());
|
||||||
|
const QRectF source = QRectF(diagram_rect); // meme source que render()
|
||||||
|
|
||||||
|
// render() ANCRE en haut-gauche (pas de centrage) :
|
||||||
|
// translate(target.topLeft) . scale(s,s) . translate(-source.topLeft)
|
||||||
|
// On reproduit EXACTEMENT ca — surtout PAS de (target-source*s)/2.
|
||||||
|
const qreal s = qMin(target.width() / source.width(),
|
||||||
|
target.height() / source.height());
|
||||||
|
|
||||||
|
QTransform fit;
|
||||||
|
fit.translate(target.x(), target.y());
|
||||||
|
fit.scale(s, s);
|
||||||
|
fit.translate(-source.x(), -source.y()); // scene -> pixels device
|
||||||
|
|
||||||
|
// IMPORTANT : QPdfEngine::drawHyperlink() applique lui-meme
|
||||||
|
// pageMatrix() (echelle 72/resolution + inversion de Y + marges).
|
||||||
|
// On lui passe donc le rectangle en PIXELS DEVICE, sans aucune
|
||||||
|
// conversion en points ni flip de notre cote.
|
||||||
|
const QRectF pageBounds(0, 0, target.width(), target.height());
|
||||||
|
|
||||||
|
// ---- Device-pixels -> PDF points, replicating QPdfEnginePrivate::pageMatrix()
|
||||||
|
// (same geometry for every page: same printer, page size and margins). ----
|
||||||
|
const qreal pt_scale = 72.0 / printer->resolution();
|
||||||
|
const qreal fullH_pt = printer->pageLayout().fullRectPoints().height();
|
||||||
|
const bool fullPageMode =
|
||||||
|
(printer->pageLayout().mode() == QPageLayout::FullPageMode);
|
||||||
|
const QRect paintPx =
|
||||||
|
printer->pageLayout().paintRectPixels(printer->resolution());
|
||||||
|
auto devToPdf = [=](const QPointF &d) -> QPointF {
|
||||||
|
qreal dx = d.x(), dy = d.y();
|
||||||
|
if (!fullPageMode) { dx += paintPx.left(); dy += paintPx.top(); }
|
||||||
|
return QPointF(pt_scale * dx, fullH_pt - pt_scale * dy);
|
||||||
|
};
|
||||||
|
|
||||||
|
PdfLinks::PageGeometry geom;
|
||||||
|
geom.sceneToDevice = fit;
|
||||||
|
geom.target = target;
|
||||||
|
geom.pageBounds = pageBounds;
|
||||||
|
geom.devToPdf = devToPdf;
|
||||||
|
geom.sourceRectOf = [this](Diagram *dg) {
|
||||||
|
return QRectF(diagramRect(dg, exportProperties()));
|
||||||
|
};
|
||||||
|
PdfLinks::injectCrossRefLinks(
|
||||||
|
pdfEngine, diagram, geom, diagramPageMap,
|
||||||
|
printer->outputFileName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
////PDF links end////
|
||||||
|
|
||||||
////Print is finished, restore diagram and graphics item properties
|
////Print is finished, restore diagram and graphics item properties
|
||||||
for (auto view : diagram->views()) {
|
for (auto view : diagram->views()) {
|
||||||
view->setInteractive(true);
|
view->setInteractive(true);
|
||||||
@@ -772,9 +878,29 @@ void ProjectPrintWindow::on_m_uncheck_all_clicked()
|
|||||||
|
|
||||||
void ProjectPrintWindow::print()
|
void ProjectPrintWindow::print()
|
||||||
{
|
{
|
||||||
m_preview->print();
|
const bool isPdf = (m_printer->outputFormat() == QPrinter::PdfFormat);
|
||||||
|
const QString pdfFile = isPdf ? m_printer->outputFileName() : QString();
|
||||||
|
|
||||||
|
m_preview->print(); // triggers requestPaint() synchronously; painter
|
||||||
|
// is created/destroyed inside that call
|
||||||
|
|
||||||
savePageSetupForCurrentPrinter();
|
savePageSetupForCurrentPrinter();
|
||||||
this->close();
|
|
||||||
|
if (isPdf && !pdfFile.isEmpty()) {
|
||||||
|
// Defer post-processing and window close to the next event-loop
|
||||||
|
// iteration. This lets the macOS arm64 Metal compositor finish
|
||||||
|
// compositing the backing store before the window is destroyed,
|
||||||
|
// which prevents the black screen observed on Apple Silicon under
|
||||||
|
// macOS Sequoia (QPrintPreviewWidget + CALayer timing issue).
|
||||||
|
QTimer::singleShot(0, this, [this, pdfFile]() {
|
||||||
|
// Convert URI link annotations into native internal GoTo/FitR
|
||||||
|
// actions so cross-references jump inside the document.
|
||||||
|
PdfLinks::convertUriToGoTo(pdfFile);
|
||||||
|
this->close();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectPrintWindow::on_m_date_cb_userDateChanged(const QDate &date)
|
void ProjectPrintWindow::on_m_date_cb_userDateChanged(const QDate &date)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include "../exportproperties.h"
|
#include "../exportproperties.h"
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QMap>
|
||||||
#include <QPrinter>
|
#include <QPrinter>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -79,7 +80,7 @@ class ProjectPrintWindow : public QMainWindow
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void requestPaint();
|
void requestPaint();
|
||||||
void printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer);
|
void printDiagram(Diagram *diagram, bool fit_page, QPainter *painter, QPrinter *printer, const QMap<Diagram*, int> &diagramPageMap = {});
|
||||||
QRect diagramRect(Diagram *diagram, const ExportProperties &option) const;
|
QRect diagramRect(Diagram *diagram, const ExportProperties &option) const;
|
||||||
int horizontalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
|
int horizontalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
|
||||||
int verticalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
|
int verticalPagesCount(Diagram *diagram, const ExportProperties &option, bool full_page) const;
|
||||||
|
|||||||
+34
-16
@@ -226,20 +226,20 @@ void QETApp::setLanguage(const QString &desired_language) {
|
|||||||
|
|
||||||
// load translations for the QET application
|
// load translations for the QET application
|
||||||
// charge les traductions pour l'application QET
|
// charge les traductions pour l'application QET
|
||||||
if (!qetTranslator.load("qet_" + desired_language, languages_path)) {
|
// desired_language may be a full locale such as "pt_BR": try that exact
|
||||||
/* in case of failure,
|
// translation, then the base language ("pt"), then fall back to English.
|
||||||
* we fall back on the native channels for French
|
// French is the application's source language and needs no translation.
|
||||||
* en cas d'echec,
|
const QString base_language = desired_language.section('_', 0, 0);
|
||||||
* on retombe sur les chaines natives pour le francais
|
bool loaded = qetTranslator.load("qet_" + desired_language, languages_path);
|
||||||
*/
|
if (!loaded && base_language != desired_language)
|
||||||
if (desired_language != "fr") {
|
loaded = qetTranslator.load("qet_" + base_language, languages_path);
|
||||||
// use of the English version by default
|
if (!loaded && base_language != "fr") {
|
||||||
// utilisation de la version anglaise par defaut
|
// use of the English version by default
|
||||||
if(!qetTranslator.load("qet_en", languages_path))
|
// utilisation de la version anglaise par defaut
|
||||||
qWarning() << "failed to load"
|
if(!qetTranslator.load("qet_en", languages_path))
|
||||||
<< "qet_en" << languages_path << "(" << __FILE__
|
qWarning() << "failed to load"
|
||||||
<< __LINE__ << __FUNCTION__ << ")";
|
<< "qet_en" << languages_path << "(" << __FILE__
|
||||||
}
|
<< __LINE__ << __FUNCTION__ << ")";
|
||||||
}
|
}
|
||||||
qApp->installTranslator(&qetTranslator);
|
qApp->installTranslator(&qetTranslator);
|
||||||
|
|
||||||
@@ -263,7 +263,11 @@ QString QETApp::langFromSetting()
|
|||||||
QSettings settings;
|
QSettings settings;
|
||||||
system_language = settings.value("lang", "system").toString();
|
system_language = settings.value("lang", "system").toString();
|
||||||
if(system_language == "system") {
|
if(system_language == "system") {
|
||||||
system_language = QLocale::system().name().left(2);
|
// Keep the full locale (e.g. "pt_BR"), not just the base language
|
||||||
|
// ("pt"): QET ships regional translations (pt_BR, nl_BE, nl_NL) and
|
||||||
|
// truncating here loaded the wrong one. setLanguage() falls back to
|
||||||
|
// the base language when no regional translation exists.
|
||||||
|
system_language = QLocale::system().name();
|
||||||
}
|
}
|
||||||
lang_is_set = true;
|
lang_is_set = true;
|
||||||
}
|
}
|
||||||
@@ -1228,7 +1232,21 @@ QString QETApp::languagesPath()
|
|||||||
* en l'absence d'option de compilation, on utilise le dossier lang,
|
* en l'absence d'option de compilation, on utilise le dossier lang,
|
||||||
* situe a cote du binaire executable
|
* situe a cote du binaire executable
|
||||||
*/
|
*/
|
||||||
return(QCoreApplication::applicationDirPath() + "/lang/");
|
{
|
||||||
|
const QString bin_dir = QCoreApplication::applicationDirPath();
|
||||||
|
const QString next_to_bin = bin_dir + "/lang/";
|
||||||
|
// Some packagings (notably the Windows installer) put the binary in a
|
||||||
|
// "bin" subfolder while "lang" sits beside it (../lang). Fall back to
|
||||||
|
// that layout when the folder next to the binary is absent, so the
|
||||||
|
// translations are found without a --lang-dir argument. See issue #86.
|
||||||
|
if (!QDir(next_to_bin).exists()) {
|
||||||
|
const QString sibling_of_bin =
|
||||||
|
QDir::cleanPath(bin_dir + "/../lang") + "/";
|
||||||
|
if (QDir(sibling_of_bin).exists())
|
||||||
|
return(sibling_of_bin);
|
||||||
|
}
|
||||||
|
return(next_to_bin);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#ifndef QET_LANG_PATH_RELATIVE_TO_BINARY_PATH
|
#ifndef QET_LANG_PATH_RELATIVE_TO_BINARY_PATH
|
||||||
/* the compilation option represents
|
/* the compilation option represents
|
||||||
|
|||||||
@@ -928,7 +928,7 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt, in
|
|||||||
bounding_rect = bounding_rect.united(text_rect);
|
bounding_rect = bounding_rect.united(text_rect);
|
||||||
|
|
||||||
if (m_update_map)
|
if (m_update_map)
|
||||||
m_hovered_contacts_map.insert(elmt, bounding_rect);
|
m_hovered_contacts_map.insert(elmt, text_rect);
|
||||||
|
|
||||||
++m_drawed_contacts;
|
++m_drawed_contacts;
|
||||||
}
|
}
|
||||||
@@ -961,22 +961,21 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt, in
|
|||||||
painter.drawPolyline(p2, 3);
|
painter.drawPolyline(p2, 3);
|
||||||
|
|
||||||
// Draw terminal names for switch contact (3 terminals)
|
// Draw terminal names for switch contact (3 terminals)
|
||||||
// terminal_names[0] = NO side (top left)
|
// terminal_names[0] = NC (bottom-left)
|
||||||
// terminal_names[1] = NC side (bottom left)
|
// terminal_names[1] = NO (top-left)
|
||||||
// terminal_names[2] = common side (right)
|
// terminal_names[2] = Common (right)
|
||||||
if (!terminal_names.isEmpty() && m_properties.showTerminalName()) {
|
if (!terminal_names.isEmpty() && m_properties.showTerminalName()) {
|
||||||
painter.setFont(QETApp::diagramTextsFont(4));
|
painter.setFont(QETApp::diagramTextsFont(4));
|
||||||
// Sort order from parseTerminal (top->bottom, left->right):
|
// Storage order set above: [0]=NC, [1]=NO, [2]=Common
|
||||||
// [0]=12 (NO, top-left), [1]=14 (common, top-center), [2]=13 (NC, bottom-center)
|
|
||||||
if (terminal_names.size() >= 1)
|
|
||||||
painter.drawText(QRectF(0, offset, 8, 8),
|
|
||||||
Qt::AlignLeft|Qt::AlignTop, terminal_names[1]); // 12 NO left
|
|
||||||
if (terminal_names.size() >= 2)
|
if (terminal_names.size() >= 2)
|
||||||
painter.drawText(QRectF(16, offset+4, 8, 6),
|
painter.drawText(QRectF(0, offset, 8, 8),
|
||||||
Qt::AlignRight|Qt::AlignTop, terminal_names[2]); // 14 common right
|
Qt::AlignLeft|Qt::AlignTop, terminal_names[1]); // NO top-left
|
||||||
if (terminal_names.size() >= 3)
|
if (terminal_names.size() >= 3)
|
||||||
|
painter.drawText(QRectF(16, offset+4, 8, 6),
|
||||||
|
Qt::AlignRight|Qt::AlignTop, terminal_names[2]); // Common right
|
||||||
|
if (terminal_names.size() >= 1)
|
||||||
painter.drawText(QRectF(0, offset+9, 8, 6),
|
painter.drawText(QRectF(0, offset+9, 8, 6),
|
||||||
Qt::AlignLeft|Qt::AlignTop, terminal_names[0]); // 13 NC left-bottom
|
Qt::AlignLeft|Qt::AlignTop, terminal_names[0]); // NC bottom-left
|
||||||
painter.setFont(QETApp::diagramTextsFont(5));
|
painter.setFont(QETApp::diagramTextsFont(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,7 +1011,7 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt, in
|
|||||||
bounding_rect = bounding_rect.united(text_rect);
|
bounding_rect = bounding_rect.united(text_rect);
|
||||||
|
|
||||||
if (m_update_map)
|
if (m_update_map)
|
||||||
m_hovered_contacts_map.insert(elmt, bounding_rect);
|
m_hovered_contacts_map.insert(elmt, text_rect);
|
||||||
|
|
||||||
//a switch contact take place of two normal contact
|
//a switch contact take place of two normal contact
|
||||||
m_drawed_contacts += 2;
|
m_drawed_contacts += 2;
|
||||||
@@ -1044,7 +1043,7 @@ QRectF CrossRefItem::drawContact(QPainter &painter, int flags, Element *elmt, in
|
|||||||
bounding_rect = bounding_rect.united(text_rect);
|
bounding_rect = bounding_rect.united(text_rect);
|
||||||
|
|
||||||
if (m_update_map)
|
if (m_update_map)
|
||||||
m_hovered_contacts_map.insert(elmt, bounding_rect);
|
m_hovered_contacts_map.insert(elmt, text_rect);
|
||||||
++m_drawed_contacts;
|
++m_drawed_contacts;
|
||||||
}
|
}
|
||||||
return bounding_rect;
|
return bounding_rect;
|
||||||
|
|||||||
@@ -126,6 +126,12 @@ class CrossRefItem : public QGraphicsObject
|
|||||||
ElementTextItemGroup *m_group = nullptr;
|
ElementTextItemGroup *m_group = nullptr;
|
||||||
QList <QMetaObject::Connection> m_slave_connection;
|
QList <QMetaObject::Connection> m_slave_connection;
|
||||||
QList <QMetaObject::Connection> m_update_connection;
|
QList <QMetaObject::Connection> m_update_connection;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/// Returns the map of linked elements and their clickable rects (local coords).
|
||||||
|
/// Used by the PDF export to inject hyperlink annotations.
|
||||||
|
const QMultiMap<Element *, QRectF> &hoveredContactsMap() const
|
||||||
|
{ return m_hovered_contacts_map; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CROSSREFITEM_H
|
#endif // CROSSREFITEM_H
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ class DynamicElementTextItem : public DiagramTextItem
|
|||||||
void fromXml(const QDomElement &dom_elmt) override;
|
void fromXml(const QDomElement &dom_elmt) override;
|
||||||
|
|
||||||
Element *parentElement() const;
|
Element *parentElement() const;
|
||||||
|
/// PDF export: slave cross-reference text item ("(folio-pos)") and its master target.
|
||||||
|
QGraphicsTextItem *slaveXrefItem() const { return m_slave_Xref_item; }
|
||||||
|
Element *masterElement() const { return m_master_element.data(); }
|
||||||
ElementTextItemGroup *parentGroup() const;
|
ElementTextItemGroup *parentGroup() const;
|
||||||
Element *elementUseForInfo() const;
|
Element *elementUseForInfo() const;
|
||||||
void refreshLabelConnection();
|
void refreshLabelConnection();
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
|||||||
QList<DynamicElementTextItem *> texts() const;
|
QList<DynamicElementTextItem *> texts() const;
|
||||||
Diagram *diagram() const;
|
Diagram *diagram() const;
|
||||||
Element *parentElement() const;
|
Element *parentElement() const;
|
||||||
|
/// PDF export: slave cross-reference text item of the group, if any.
|
||||||
|
QGraphicsTextItem *slaveXrefItem() const { return m_slave_Xref_item; }
|
||||||
|
|
||||||
QDomElement toXml(QDomDocument &dom_document) const;
|
QDomElement toXml(QDomDocument &dom_document) const;
|
||||||
void fromXml(QDomElement &dom_element);
|
void fromXml(QDomElement &dom_element);
|
||||||
|
|||||||
@@ -788,6 +788,12 @@ QList<Terminal *> relatedPotentialTerminal (
|
|||||||
// If terminal parent element is a Terminal element.
|
// If terminal parent element is a Terminal element.
|
||||||
else if (terminal -> parentElement() -> linkType() & Element::Terminale)
|
else if (terminal -> parentElement() -> linkType() & Element::Terminale)
|
||||||
{
|
{
|
||||||
|
// English: Check if the user activated the potential isolation checkbox for this terminal
|
||||||
|
if (terminal->parentElement()->elementInformations().value(QStringLiteral("potential_isolating")).toString() == QLatin1String("true")) {
|
||||||
|
// English: Potential is isolated. Return an empty list so it does not propagate to the other side.
|
||||||
|
return QList<Terminal *>();
|
||||||
|
}
|
||||||
|
|
||||||
QList <Terminal *> terminals = terminal->parentElement()->terminals();
|
QList <Terminal *> terminals = terminal->parentElement()->terminals();
|
||||||
terminals.removeAll(const_cast<Terminal *>(terminal));
|
terminals.removeAll(const_cast<Terminal *>(terminal));
|
||||||
return terminals;
|
return terminals;
|
||||||
|
|||||||
@@ -189,7 +189,8 @@ QStringList QETInformation::elementInfoKeys()
|
|||||||
ELMT_MACHINE_MANUFACTURER_REF_AUX4,
|
ELMT_MACHINE_MANUFACTURER_REF_AUX4,
|
||||||
ELMT_SUPPLIER_AUX4,
|
ELMT_SUPPLIER_AUX4,
|
||||||
ELMT_QUANTITY_AUX4,
|
ELMT_QUANTITY_AUX4,
|
||||||
ELMT_UNITY_AUX4, };
|
ELMT_UNITY_AUX4,
|
||||||
|
"exclude_from_bom" };
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-4
@@ -43,6 +43,13 @@
|
|||||||
|
|
||||||
static int BACKUP_INTERVAL = 1200000; //interval in ms of backup = 20min
|
static int BACKUP_INTERVAL = 1200000; //interval in ms of backup = 20min
|
||||||
|
|
||||||
|
bool QETProject::m_backup_enabled = true;
|
||||||
|
|
||||||
|
void QETProject::setBackupEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
m_backup_enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief QETProject::QETProject
|
@brief QETProject::QETProject
|
||||||
Create a empty project
|
Create a empty project
|
||||||
@@ -1006,16 +1013,30 @@ QETResult QETProject::write()
|
|||||||
if (m_file_path.isEmpty())
|
if (m_file_path.isEmpty())
|
||||||
return(QString("unable to save project to file: no filepath was specified"));
|
return(QString("unable to save project to file: no filepath was specified"));
|
||||||
|
|
||||||
// if the project was opened read-only
|
// If the project was opened read-only, only refuse when the target
|
||||||
// and the file is still non-writable, do not save the project
|
// really can't be written: an existing file that is not writable, or a
|
||||||
if (isReadOnly() && !QFileInfo(m_file_path).isWritable())
|
// new file (e.g. "Save As" to another location) whose directory is not
|
||||||
return(QString("the file %1 was opened read-only and thus will not be written").arg(m_file_path));
|
// writable. A non-existent file reports isWritable() == false, so the
|
||||||
|
// old check wrongly blocked saving a read-only project elsewhere.
|
||||||
|
if (isReadOnly()) {
|
||||||
|
const QFileInfo file_info(m_file_path);
|
||||||
|
const bool can_write = file_info.exists()
|
||||||
|
? file_info.isWritable()
|
||||||
|
: QFileInfo(file_info.absolutePath()).isWritable();
|
||||||
|
if (!can_write)
|
||||||
|
return(QString("the file %1 was opened read-only and thus will not be written").arg(m_file_path));
|
||||||
|
}
|
||||||
|
|
||||||
QDomDocument xml_project(toXml());
|
QDomDocument xml_project(toXml());
|
||||||
QString error_message;
|
QString error_message;
|
||||||
if (!QET::writeXmlFile(xml_project, m_file_path, &error_message))
|
if (!QET::writeXmlFile(xml_project, m_file_path, &error_message))
|
||||||
return(error_message);
|
return(error_message);
|
||||||
|
|
||||||
|
// The project has just been written to a writable file (e.g. saved to
|
||||||
|
// a new location with "Save As"), so it is no longer read-only.
|
||||||
|
if (isReadOnly())
|
||||||
|
setReadOnly(false);
|
||||||
|
|
||||||
//title block variables should be updated after file save dialog is confirmed, before file is saved.
|
//title block variables should be updated after file save dialog is confirmed, before file is saved.
|
||||||
m_project_properties.addValue("saveddate", QLocale::system().toString(QDate::currentDate(), QLocale::ShortFormat));
|
m_project_properties.addValue("saveddate", QLocale::system().toString(QDate::currentDate(), QLocale::ShortFormat));
|
||||||
m_project_properties.addValue("saveddate-us", QDate::currentDate().toString("yyyy-MM-dd"));
|
m_project_properties.addValue("saveddate-us", QDate::currentDate().toString("yyyy-MM-dd"));
|
||||||
@@ -1783,6 +1804,8 @@ void QETProject::addDiagram(Diagram *diagram, int pos)
|
|||||||
*/
|
*/
|
||||||
void QETProject::writeBackup()
|
void QETProject::writeBackup()
|
||||||
{
|
{
|
||||||
|
if (!m_backup_enabled)
|
||||||
|
return;
|
||||||
#ifdef BUILD_WITHOUT_KF5
|
#ifdef BUILD_WITHOUT_KF5
|
||||||
#else
|
#else
|
||||||
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
|
||||||
|
|||||||
@@ -105,6 +105,12 @@ class QETProject : public QObject
|
|||||||
QVersionNumber declaredQElectroTechVersion();
|
QVersionNumber declaredQElectroTechVersion();
|
||||||
void setTitle(const QString &);
|
void setTitle(const QString &);
|
||||||
|
|
||||||
|
/// Enable/disable the asynchronous crash-recovery backup for all
|
||||||
|
/// projects. Disabled by the headless CLI: the backup write runs on a
|
||||||
|
/// background thread referencing the project, and a short-lived CLI
|
||||||
|
/// process can destroy the project before the write finishes (crash).
|
||||||
|
static void setBackupEnabled(bool enabled);
|
||||||
|
|
||||||
///DEFAULT PROPERTIES
|
///DEFAULT PROPERTIES
|
||||||
BorderProperties defaultBorderProperties() const;
|
BorderProperties defaultBorderProperties() const;
|
||||||
void setDefaultBorderProperties(const BorderProperties &);
|
void setDefaultBorderProperties(const BorderProperties &);
|
||||||
@@ -241,6 +247,8 @@ class QETProject : public QObject
|
|||||||
|
|
||||||
// attributes
|
// attributes
|
||||||
private:
|
private:
|
||||||
|
/// When false, writeBackup() is a no-op (set by the headless CLI)
|
||||||
|
static bool m_backup_enabled;
|
||||||
/// File path this project is saved to
|
/// File path this project is saved to
|
||||||
QString m_file_path;
|
QString m_file_path;
|
||||||
/// Current state of the project
|
/// Current state of the project
|
||||||
|
|||||||
@@ -1756,6 +1756,10 @@ QString TitleBlockTemplate::interpreteVariables(
|
|||||||
QStringList TitleBlockTemplate::listOfVariables()
|
QStringList TitleBlockTemplate::listOfVariables()
|
||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
|
// Match every "%{name}" placeholder. The bare "%name" form can't be
|
||||||
|
// extracted reliably without the variable list, and templates use the
|
||||||
|
// braced form, so only that is collected here.
|
||||||
|
static const QRegularExpression rx(QStringLiteral("%\\{([^}]+)\\}"));
|
||||||
// run through each individual cell
|
// run through each individual cell
|
||||||
for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
|
for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
|
||||||
for (int i = 0 ; i < columns_width_.count() ; ++ i) {
|
for (int i = 0 ; i < columns_width_.count() ; ++ i) {
|
||||||
@@ -1763,14 +1767,15 @@ QStringList TitleBlockTemplate::listOfVariables()
|
|||||||
|| cells_[i][j] -> cell_type
|
|| cells_[i][j] -> cell_type
|
||||||
== TitleBlockCell::EmptyCell)
|
== TitleBlockCell::EmptyCell)
|
||||||
continue;
|
continue;
|
||||||
#if TODO_LIST
|
const QString cell_value = cells_[i][j] -> value.name();
|
||||||
#pragma message("@TODO not works on all cases...")
|
auto it = rx.globalMatch(cell_value);
|
||||||
#endif
|
while (it.hasNext()) {
|
||||||
// TODO: not works on all cases...
|
const QString name = it.next().captured(1);
|
||||||
list << cells_[i][j] -> value.name().replace("%","");
|
if (!name.isEmpty() && !list.contains(name))
|
||||||
|
list << name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << list;
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "elementinfowidget.h"
|
#include "elementinfowidget.h"
|
||||||
|
#include <QCheckBox>
|
||||||
#include "../diagram.h"
|
#include "../diagram.h"
|
||||||
#include "../qetapp.h"
|
#include "../qetapp.h"
|
||||||
#include "../qetgraphicsitem/element.h"
|
#include "../qetgraphicsitem/element.h"
|
||||||
@@ -161,6 +161,13 @@ void ElementInfoWidget::enableLiveEdit()
|
|||||||
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
||||||
connect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
|
connect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
|
||||||
connect(ui->m_auto_num_locked_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
connect(ui->m_auto_num_locked_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
||||||
|
|
||||||
|
if (m_potential_isolating_cb) {
|
||||||
|
connect(m_potential_isolating_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
||||||
|
}
|
||||||
|
if (m_exclude_from_bom_cb) {
|
||||||
|
connect(m_exclude_from_bom_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,6 +179,13 @@ void ElementInfoWidget::disableLiveEdit()
|
|||||||
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
for (ElementInfoPartWidget *eipw : m_eipw_list)
|
||||||
disconnect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
|
disconnect(eipw, &ElementInfoPartWidget::textChanged, this, &ElementInfoWidget::apply);
|
||||||
disconnect(ui->m_auto_num_locked_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
disconnect(ui->m_auto_num_locked_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
||||||
|
|
||||||
|
if (m_potential_isolating_cb) {
|
||||||
|
disconnect(m_potential_isolating_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
||||||
|
}
|
||||||
|
if (m_exclude_from_bom_cb) {
|
||||||
|
disconnect(m_exclude_from_bom_cb, &QCheckBox::clicked, this, &ElementInfoWidget::apply);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,16 +207,34 @@ void ElementInfoWidget::buildInterface()
|
|||||||
ui->scroll_vlayout->addWidget(eipw);
|
ui->scroll_vlayout->addWidget(eipw);
|
||||||
m_eipw_list << eipw;
|
m_eipw_list << eipw;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->scroll_vlayout->addStretch();
|
ui->scroll_vlayout->addStretch();
|
||||||
|
|
||||||
|
// Existing potential isolating checkbox
|
||||||
|
m_potential_isolating_cb = new QCheckBox(tr("Séparation de potentiel"), this);
|
||||||
|
m_potential_isolating_cb->setStyleSheet(QStringLiteral("margin: 5px; font-weight: bold;"));
|
||||||
|
|
||||||
|
// English: Initialize and style the BOM exclusion checkbox
|
||||||
|
m_exclude_from_bom_cb = new QCheckBox(tr("Exclure de la nomenclature"), this);
|
||||||
|
m_exclude_from_bom_cb->setStyleSheet(QStringLiteral("margin: 5px; font-weight: bold;"));
|
||||||
|
|
||||||
|
if (QVBoxLayout *mainLayout = qobject_cast<QVBoxLayout*>(this->layout())) {
|
||||||
|
mainLayout->insertWidget(1, m_potential_isolating_cb);
|
||||||
|
// English: Insert the new checkbox into the main vertical layout
|
||||||
|
mainLayout->insertWidget(2, m_exclude_from_bom_cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// English: BOM exclusion applies to all elements, so it's always visible
|
||||||
|
m_exclude_from_bom_cb->setVisible(true);
|
||||||
|
|
||||||
// Show checkbox only if the element is a terminal
|
// Show checkbox only if the element is a terminal
|
||||||
if (m_element.data()->elementData().m_type == ElementData::Terminal) {
|
if (m_element.data()->elementData().m_type == ElementData::Terminal) {
|
||||||
ui->m_auto_num_locked_cb->setVisible(true);
|
ui->m_auto_num_locked_cb->setVisible(true);
|
||||||
|
m_potential_isolating_cb->setVisible(true);
|
||||||
} else {
|
} else {
|
||||||
ui->m_auto_num_locked_cb->setVisible(false);
|
ui->m_auto_num_locked_cb->setVisible(false);
|
||||||
|
m_potential_isolating_cb->setVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief ElementInfoWidget::infoPartWidgetForKey
|
@brief ElementInfoWidget::infoPartWidgetForKey
|
||||||
@param key
|
@param key
|
||||||
@@ -243,6 +275,17 @@ void ElementInfoWidget::updateUi()
|
|||||||
if (m_element->elementData().m_type == ElementData::Terminal) {
|
if (m_element->elementData().m_type == ElementData::Terminal) {
|
||||||
QString lock_value = element_info.value(QStringLiteral("auto_num_locked")).toString();
|
QString lock_value = element_info.value(QStringLiteral("auto_num_locked")).toString();
|
||||||
ui->m_auto_num_locked_cb->setChecked(lock_value == QLatin1String("true"));
|
ui->m_auto_num_locked_cb->setChecked(lock_value == QLatin1String("true"));
|
||||||
|
|
||||||
|
// English: Load the potential isolating status from the element information mapping
|
||||||
|
if (m_potential_isolating_cb) {
|
||||||
|
QString isolating_value = element_info.value(QStringLiteral("potential_isolating")).toString();
|
||||||
|
m_potential_isolating_cb->setChecked(isolating_value == QLatin1String("true"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// English: Load the BOM exclusion status from the element information mapping
|
||||||
|
if (m_exclude_from_bom_cb) {
|
||||||
|
QString exclude_bom_value = element_info.value(QStringLiteral("exclude_from_bom")).toString();
|
||||||
|
m_exclude_from_bom_cb->setChecked(exclude_bom_value == QLatin1String("true"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_live_edit) {
|
if (m_live_edit) {
|
||||||
@@ -260,12 +303,11 @@ DiagramContext ElementInfoWidget::currentInfo() const
|
|||||||
|
|
||||||
for (const auto &eipw : qAsConst(m_eipw_list))
|
for (const auto &eipw : qAsConst(m_eipw_list))
|
||||||
{
|
{
|
||||||
|
//add value only if they're something to store
|
||||||
//add value only if they're something to store
|
|
||||||
if (!eipw->text().isEmpty())
|
if (!eipw->text().isEmpty())
|
||||||
{
|
{
|
||||||
QString txt{eipw->text()};
|
QString txt{eipw->text()};
|
||||||
//remove line feed and carriage return
|
//remove line feed and carriage return
|
||||||
txt.remove(QStringLiteral("\r"));
|
txt.remove(QStringLiteral("\r"));
|
||||||
txt.remove(QStringLiteral("\n"));
|
txt.remove(QStringLiteral("\n"));
|
||||||
info_.addValue(eipw->key(), txt);
|
info_.addValue(eipw->key(), txt);
|
||||||
@@ -275,10 +317,17 @@ DiagramContext ElementInfoWidget::currentInfo() const
|
|||||||
// Save the auto numbering lock status
|
// Save the auto numbering lock status
|
||||||
if (m_element->elementData().m_type == ElementData::Terminal) {
|
if (m_element->elementData().m_type == ElementData::Terminal) {
|
||||||
info_.addValue(QStringLiteral("auto_num_locked"), ui->m_auto_num_locked_cb->isChecked() ? QStringLiteral("true") : QStringLiteral("false"));
|
info_.addValue(QStringLiteral("auto_num_locked"), ui->m_auto_num_locked_cb->isChecked() ? QStringLiteral("true") : QStringLiteral("false"));
|
||||||
|
|
||||||
|
if (m_potential_isolating_cb) {
|
||||||
|
info_.addValue(QStringLiteral("potential_isolating"), m_potential_isolating_cb->isChecked() ? QStringLiteral("true") : QStringLiteral("false"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_exclude_from_bom_cb) {
|
||||||
|
info_.addValue(QStringLiteral("exclude_from_bom"), m_exclude_from_bom_cb->isChecked() ? QStringLiteral("true") : QStringLiteral("false"));
|
||||||
}
|
}
|
||||||
return info_;
|
return info_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief ElementInfoWidget::firstActivated
|
@brief ElementInfoWidget::firstActivated
|
||||||
Slot activated when this widget is show.
|
Slot activated when this widget is show.
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ class Element;
|
|||||||
class QUndoCommand;
|
class QUndoCommand;
|
||||||
class ElementInfoPartWidget;
|
class ElementInfoPartWidget;
|
||||||
class ChangeElementInformationCommand;
|
class ChangeElementInformationCommand;
|
||||||
|
class QCheckBox;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ElementInfoWidget;
|
class ElementInfoWidget;
|
||||||
@@ -71,6 +72,8 @@ class ElementInfoWidget : public AbstractElementPropertiesEditorWidget
|
|||||||
private:
|
private:
|
||||||
Ui::ElementInfoWidget *ui;
|
Ui::ElementInfoWidget *ui;
|
||||||
QList <ElementInfoPartWidget *> m_eipw_list;
|
QList <ElementInfoPartWidget *> m_eipw_list;
|
||||||
|
QCheckBox *m_potential_isolating_cb = nullptr;
|
||||||
|
QCheckBox *m_exclude_from_bom_cb = nullptr;
|
||||||
bool m_first_activation;
|
bool m_first_activation;
|
||||||
bool m_ui_builded = false;
|
bool m_ui_builded = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#include "ui_titleblockpropertieswidget.h"
|
#include "ui_titleblockpropertieswidget.h"
|
||||||
|
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QSet>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,7 +163,11 @@ void TitleBlockPropertiesWidget::setProperties(
|
|||||||
}
|
}
|
||||||
ui -> m_tbt_cb -> setCurrentIndex(index);
|
ui -> m_tbt_cb -> setCurrentIndex(index);
|
||||||
|
|
||||||
m_dcw -> setContext(properties.context);
|
// Show the saved custom values, plus any of the template's custom variables
|
||||||
|
// that aren't defined yet, so the user only fills in the missing ones (#271).
|
||||||
|
DiagramContext context = properties.context;
|
||||||
|
addTemplateVariables(context, index);
|
||||||
|
m_dcw -> setContext(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -435,12 +440,15 @@ void TitleBlockPropertiesWidget::updateTemplateList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief TitleBlockPropertiesWidget::changeCurrentTitleBlockTemplate
|
@brief TitleBlockPropertiesWidget::templateForIndex
|
||||||
Load the additional field of title block "text"
|
@param index : index in the collection-type map (= the template combo index)
|
||||||
|
@return the TitleBlockTemplate currently selected for that collection, or
|
||||||
|
nullptr.
|
||||||
*/
|
*/
|
||||||
void TitleBlockPropertiesWidget::changeCurrentTitleBlockTemplate(int index)
|
TitleBlockTemplate *TitleBlockPropertiesWidget::templateForIndex(int index) const
|
||||||
{
|
{
|
||||||
m_dcw -> clear();
|
if (index < 0 || index >= m_map_index_to_collection_type.count())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
QET::QetCollection qc = m_map_index_to_collection_type.at(index);
|
QET::QetCollection qc = m_map_index_to_collection_type.at(index);
|
||||||
TitleBlockTemplatesCollection *collection = nullptr;
|
TitleBlockTemplatesCollection *collection = nullptr;
|
||||||
@@ -448,21 +456,55 @@ void TitleBlockPropertiesWidget::changeCurrentTitleBlockTemplate(int index)
|
|||||||
if (c -> collection() == qc)
|
if (c -> collection() == qc)
|
||||||
collection = c;
|
collection = c;
|
||||||
|
|
||||||
if (!collection) return;
|
if (!collection) return nullptr;
|
||||||
|
return collection -> getTemplate(ui -> m_tbt_cb -> currentText());
|
||||||
|
}
|
||||||
|
|
||||||
// get template
|
/**
|
||||||
TitleBlockTemplate *tpl = collection -> getTemplate(ui -> m_tbt_cb -> currentText());
|
@brief TitleBlockPropertiesWidget::addTemplateVariables
|
||||||
if(tpl != nullptr) {
|
Add to @p context every CUSTOM variable used by the currently selected
|
||||||
// get all template fields
|
template that is not already present, with an empty value — so the user
|
||||||
QStringList fields = tpl -> listOfVariables();
|
only has to fill in the values instead of declaring the variables (#271).
|
||||||
// set fields to additional_fields_ widget
|
The standard fields (title, author, date, …) are handled by their own
|
||||||
DiagramContext templateContext;
|
widgets and are skipped. Existing values in @p context are preserved.
|
||||||
for(int i =0; i<fields.count(); i++)
|
*/
|
||||||
templateContext.addValue(fields.at(i), "");
|
void TitleBlockPropertiesWidget::addTemplateVariables(
|
||||||
m_dcw -> setContext(templateContext);
|
DiagramContext &context, int index) const
|
||||||
|
{
|
||||||
|
TitleBlockTemplate *tpl = templateForIndex(index);
|
||||||
|
if (!tpl) return;
|
||||||
|
|
||||||
|
// Variables rendered from the dedicated standard-field widgets; they must
|
||||||
|
// not appear in the "Custom" tab.
|
||||||
|
static const QSet<QString> reserved {
|
||||||
|
QStringLiteral("author"), QStringLiteral("date"),
|
||||||
|
QStringLiteral("title"), QStringLiteral("filename"),
|
||||||
|
QStringLiteral("plant"), QStringLiteral("locmach"),
|
||||||
|
QStringLiteral("indexrev"), QStringLiteral("version"),
|
||||||
|
QStringLiteral("folio"), QStringLiteral("folio-id"),
|
||||||
|
QStringLiteral("folio-total"), QStringLiteral("auto_page_num"),
|
||||||
|
QStringLiteral("previous-folio-num"), QStringLiteral("next-folio-num")
|
||||||
|
};
|
||||||
|
|
||||||
|
const QStringList variables = tpl -> listOfVariables();
|
||||||
|
for (const QString &name : variables) {
|
||||||
|
if (name.isEmpty() || reserved.contains(name)) continue;
|
||||||
|
if (!context.contains(name)) context.addValue(name, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief TitleBlockPropertiesWidget::changeCurrentTitleBlockTemplate
|
||||||
|
When the user picks a template, append its missing custom variables to the
|
||||||
|
"Custom" tab while keeping the values already entered (#271).
|
||||||
|
*/
|
||||||
|
void TitleBlockPropertiesWidget::changeCurrentTitleBlockTemplate(int index)
|
||||||
|
{
|
||||||
|
DiagramContext context = m_dcw -> context();
|
||||||
|
addTemplateVariables(context, index);
|
||||||
|
m_dcw -> setContext(context);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief TitleBlockPropertiesWidget::on_m_date_now_pb_clicked
|
@brief TitleBlockPropertiesWidget::on_m_date_now_pb_clicked
|
||||||
Set the date to current date
|
Set the date to current date
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class NumerotationContext;
|
|||||||
class QETProject;
|
class QETProject;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class TitleBlockTemplatesCollection;
|
class TitleBlockTemplatesCollection;
|
||||||
|
class TitleBlockTemplate;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class TitleBlockPropertiesWidget;
|
class TitleBlockPropertiesWidget;
|
||||||
@@ -77,6 +78,8 @@ class TitleBlockPropertiesWidget : public QWidget
|
|||||||
void initDialog(const bool ¤t_date, QETProject *project);
|
void initDialog(const bool ¤t_date, QETProject *project);
|
||||||
int getIndexFor (const QString &tbt_name,
|
int getIndexFor (const QString &tbt_name,
|
||||||
const QET::QetCollection collection) const;
|
const QET::QetCollection collection) const;
|
||||||
|
TitleBlockTemplate *templateForIndex (int index) const;
|
||||||
|
void addTemplateVariables (DiagramContext &context, int index) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void editCurrentTitleBlockTemplate();
|
void editCurrentTitleBlockTemplate();
|
||||||
|
|||||||
@@ -151,13 +151,39 @@ void WiringListExport::toCsv()
|
|||||||
{
|
{
|
||||||
if (!m_project) return;
|
if (!m_project) return;
|
||||||
|
|
||||||
QDomDocument doc = m_project->toXml();
|
const QString csv = toCsvString();
|
||||||
|
if (csv.isEmpty()) {
|
||||||
if (doc.isNull()) {
|
|
||||||
QMessageBox::warning(m_parent, tr("Erreur"), tr("Impossible de lire la structure en mémoire du projet."));
|
QMessageBox::warning(m_parent, tr("Erreur"), tr("Impossible de lire la structure en mémoire du projet."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QFileDialog dialog(m_parent);
|
||||||
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||||
|
dialog.setWindowTitle(tr("Exporter le plan de câblage"));
|
||||||
|
dialog.setDefaultSuffix("csv");
|
||||||
|
dialog.setNameFilter(tr("Fichiers CSV (*.csv)"));
|
||||||
|
|
||||||
|
if (dialog.exec() != QDialog::Accepted) return;
|
||||||
|
QString fileName = dialog.selectedFiles().first();
|
||||||
|
|
||||||
|
QFile file(fileName);
|
||||||
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QMessageBox::warning(m_parent, tr("Erreur"), tr("Impossible d'ouvrir le fichier pour l'écriture."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QTextStream out(&file);
|
||||||
|
out << csv;
|
||||||
|
file.close();
|
||||||
|
QMessageBox::information(m_parent, tr("Export réussi"), tr("Le plan de câblage a été exporté avec succès !"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString WiringListExport::toCsvString() const
|
||||||
|
{
|
||||||
|
if (!m_project) return QString();
|
||||||
|
|
||||||
|
QDomDocument doc = m_project->toXml();
|
||||||
|
if (doc.isNull()) return QString();
|
||||||
|
|
||||||
QSet<QString> conductorDefinitionTypes;
|
QSet<QString> conductorDefinitionTypes;
|
||||||
QDomElement rootElem = doc.documentElement();
|
QDomElement rootElem = doc.documentElement();
|
||||||
QDomElement collection = rootElem.firstChildElement("collection");
|
QDomElement collection = rootElem.firstChildElement("collection");
|
||||||
@@ -197,21 +223,6 @@ void WiringListExport::toCsv()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileDialog dialog(m_parent);
|
|
||||||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
||||||
dialog.setWindowTitle(tr("Exporter le plan de câblage"));
|
|
||||||
dialog.setDefaultSuffix("csv");
|
|
||||||
dialog.setNameFilter(tr("Fichiers CSV (*.csv)"));
|
|
||||||
|
|
||||||
if (dialog.exec() != QDialog::Accepted) return;
|
|
||||||
QString fileName = dialog.selectedFiles().first();
|
|
||||||
|
|
||||||
QFile file(fileName);
|
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
|
||||||
QMessageBox::warning(m_parent, tr("Erreur"), tr("Impossible d'ouvrir le fichier pour l'écriture."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<QString, ElementInfo> elementsInfo = collectElementsInfo(doc.documentElement());
|
QMap<QString, ElementInfo> elementsInfo = collectElementsInfo(doc.documentElement());
|
||||||
QList<ConductorData> conductors = collectConductors(doc.documentElement());
|
QList<ConductorData> conductors = collectConductors(doc.documentElement());
|
||||||
|
|
||||||
@@ -353,7 +364,8 @@ void WiringListExport::toCsv()
|
|||||||
return a.terminalname2 < b.terminalname2;
|
return a.terminalname2 < b.terminalname2;
|
||||||
});
|
});
|
||||||
|
|
||||||
QTextStream out(&file);
|
QString csv;
|
||||||
|
QTextStream out(&csv);
|
||||||
out << tr("Page", "Wiring list CSV header") << ";"
|
out << tr("Page", "Wiring list CSV header") << ";"
|
||||||
<< tr("Composant 1", "Wiring list CSV header") << ";"
|
<< tr("Composant 1", "Wiring list CSV header") << ";"
|
||||||
<< tr("Borne 1", "Wiring list CSV header") << ";"
|
<< tr("Borne 1", "Wiring list CSV header") << ";"
|
||||||
@@ -376,6 +388,5 @@ void WiringListExport::toCsv()
|
|||||||
<< c.function << "\n";
|
<< c.function << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
return csv;
|
||||||
QMessageBox::information(m_parent, tr("Export réussi"), tr("Le plan de câblage a été exporté avec succès !"));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ class WiringListExport : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit WiringListExport(QETProject *project, QWidget *parent = nullptr);
|
explicit WiringListExport(QETProject *project, QWidget *parent = nullptr);
|
||||||
void toCsv();
|
void toCsv();
|
||||||
|
/**
|
||||||
|
Build the wiring-list CSV and return it as a string (no GUI).
|
||||||
|
Used by toCsv() and by the headless command-line export.
|
||||||
|
*/
|
||||||
|
QString toCsvString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QETProject *m_project;
|
QETProject *m_project;
|
||||||
|
|||||||
Reference in New Issue
Block a user