Add an option to export symbols as DXF blocks (#1339)

With "DXF : symboles en blocs" ticked in the export dialog, or
--dxf-blocks on the command line, each symbol definition a folio uses is
written once as a DXF block and every placed symbol as an INSERT of it.
A CAD program then selects, counts and replaces a symbol as one object.

The block is drawn by the same code as a symbol drawn in full, as if
the symbol sat unturned at the folio's origin, which is DXF (0,
sheetHeight): that is the block's base point, so the INSERT carries the
symbol's position and quarter-turn and nothing else. Blocks have to come
before any entity, so the export collects them first and dxfBegin()
writes them in its BLOCKS section. Entities in a block keep their own
layers. Off by default; with it off the file is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-07 09:50:18 +13:00
parent 83f72c95c6
commit c3ed2daca8
12 changed files with 567 additions and 115 deletions
+6 -2
View File
@@ -331,7 +331,8 @@ int exportImages(QETProject &project, const QString &format,
/// One DXF file per diagram, written by the same code as the export dialog
/// (DxfExport) with the dialog's default options -- the export settings of
/// the preferences -- so both give the same file.
int exportDxf(QETProject &project, const QString &out_dir, bool showTerminals)
int exportDxf(QETProject &project, const QString &out_dir, bool showTerminals,
bool dxfBlocks)
{
const QList<Diagram *> diagrams = project.diagrams();
if (diagrams.isEmpty()) {
@@ -344,6 +345,8 @@ int exportDxf(QETProject &project, const QString &out_dir, bool showTerminals)
properties.format = QStringLiteral("DXF");
if (showTerminals)
properties.draw_terminals = true;
if (dxfBlocks)
properties.dxf_blocks = true;
int index = 0;
bool has_images = false;
@@ -982,6 +985,7 @@ int run(const QStringList &args)
// collected below.
QStringList filtered = args;
const bool showTerminals = filtered.removeAll("--show-terminals") > 0;
const bool dxfBlocks = filtered.removeAll("--dxf-blocks") > 0;
// --no-slaves and --no-junctions leave rows out of --export-bom.
const bool includeSlaves = filtered.removeAll("--no-slaves") == 0;
const bool includeJunctions = filtered.removeAll("--no-junctions") == 0;
@@ -1038,7 +1042,7 @@ int run(const QStringList &args)
if (format == "pdf")
return exportPdf(project, output, showTerminals);
if (format == "dxf")
return exportDxf(project, output, showTerminals);
return exportDxf(project, output, showTerminals, dxfBlocks);
if (format == "cables" || format == "wires")
return exportCsv(project, format, output);
if (format == "bom")