Export a symbol's part data as hidden attributes of its DXF block (#1339)

With symbols as blocks, every non-empty information field of a symbol
(label, manufacturer, reference, supplier, quantity...) is written as a
hidden attribute of its INSERT, tagged with the field's name. A CAD
program can then list the parts from the drawing, as with AutoCAD's
attribute extraction; hidden, they change nothing on screen, in any
reader. A field already written as a visible attribute (with
--dxf-attributes) is not repeated. The label formula is left out: it is
how the label is made, not part data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-07 10:04:49 +13:00
parent 9699b314b0
commit aa6abe6e81
3 changed files with 80 additions and 9 deletions
+1
View File
@@ -31,6 +31,7 @@
<inputs/>
<elementInformations>
<elementInformation name="label" show="1">K1</elementInformation>
<elementInformation name="manufacturer" show="1">Schneider</elementInformation>
</elementInformations>
<dynamic_texts>
<dynamic_elmt_text Halignment="AlignLeft" Valignment="AlignTop" font="Liberation Sans,9,-1,5,50,0,0,0,0,0,Regular" frame="false" keep_visual_rotation="false" rotation="0" rotation_point_center="false" text_from="ElementInfo" text_width="-1" uuid="{7d2b8e3f-0c65-4e30-9079-3f0d0f0a7b01}" x="0" y="25">
+35 -9
View File
@@ -22,8 +22,8 @@
/**
--export-dxf --dxf-blocks (issue #1339): a symbol placed twice is one
BLOCK and two INSERTs, the second turned a quarter, and each symbol's
label, with --dxf-attributes, is an attribute of its INSERT;
without the switches there is neither.
information is a hidden attribute of it; with --dxf-attributes its
label is a visible one. Without the switches there is neither.
*/
class tst_dxfblocks : public QObject
{
@@ -88,13 +88,14 @@ private slots:
const auto pairs = exportPairs({QStringLiteral("--dxf-attributes")});
QVERIFY2(!pairs.isEmpty(), "--export-dxf --dxf-attributes failed");
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("2")),
(QStringList{QStringLiteral("LABEL"), QStringLiteral("LABEL")}));
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("1")),
(QStringList{QStringLiteral("K1"), QStringLiteral("K2")}));
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("2"))
.count(QStringLiteral("LABEL")), 2);
const QStringList texts = values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("1"));
QVERIFY(texts.contains(QStringLiteral("K1")));
QVERIFY(texts.contains(QStringLiteral("K2")));
//Defined once in the block, and no longer a loose text
QCOMPARE(values(pairs, QStringLiteral("ATTDEF"), QStringLiteral("2")),
QStringList{QStringLiteral("LABEL")});
QCOMPARE(values(pairs, QStringLiteral("ATTDEF"), QStringLiteral("2"))
.count(QStringLiteral("LABEL")), 1);
QVERIFY(!values(pairs, QStringLiteral("TEXT"), QStringLiteral("1")).contains(QStringLiteral("K1")));
}
@@ -102,10 +103,35 @@ private slots:
{
const auto pairs = exportPairs({QStringLiteral("--dxf-blocks")});
QVERIFY2(!pairs.isEmpty(), "--export-dxf --dxf-blocks failed");
QVERIFY(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("2")).isEmpty());
//Only hidden attributes (70 = 1); the labels are texts
QVERIFY(!values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("70")).contains(QStringLiteral("0")));
QVERIFY(values(pairs, QStringLiteral("TEXT"), QStringLiteral("1")).contains(QStringLiteral("K1")));
}
void dataAsHiddenAttributes()
{
//The label is a text, so it is part data too: K1's label and
//manufacturer, K2's label, all hidden (70 = 1)
auto pairs = exportPairs({QStringLiteral("--dxf-blocks")});
QVERIFY2(!pairs.isEmpty(), "--export-dxf --dxf-blocks failed");
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("2")),
(QStringList{QStringLiteral("LABEL"), QStringLiteral("MANUFACTURER"),
QStringLiteral("LABEL")}));
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("70")),
(QStringList{QStringLiteral("1"), QStringLiteral("1"), QStringLiteral("1")}));
QVERIFY(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("1"))
.contains(QStringLiteral("Schneider")));
//With the labels as attributes, the label is not repeated
pairs = exportPairs({QStringLiteral("--dxf-attributes")});
QVERIFY2(!pairs.isEmpty(), "--export-dxf --dxf-attributes failed");
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("2")),
(QStringList{QStringLiteral("LABEL"), QStringLiteral("MANUFACTURER"),
QStringLiteral("LABEL")}));
QCOMPARE(values(pairs, QStringLiteral("ATTRIB"), QStringLiteral("70")),
(QStringList{QStringLiteral("0"), QStringLiteral("1"), QStringLiteral("0")}));
}
void flatWithoutSwitch()
{
const auto pairs = exportPairs({});