mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-06 03:04:13 +02:00
Put the DXF export on named layers (#1071)
Everything in an exported DXF was on layer 0, and the file had no LAYER table: in a CAD program the border, title block, symbols, wires and texts could not be hidden, printed or recoloured separately. Each kind of content now has its own layer, declared in a LAYER table (white/black, continuous, so the file looks the same on opening): QET_BORDER, QET_TITLEBLOCK, QET_SYMBOLS, QET_SYMBOL_TEXTS, QET_TERMINALS, QET_WIRES, QET_WIRE_NUMBERS, QET_JUNCTIONS, QET_TEXTS, QET_XREFS, QET_SHAPES, QET_TABLES, QET_IMAGES Fixed, untranslated names, so layer filters and scripts work in any language. Createdxf gets a current layer beside its xScale/yScale; DxfExport sets it before each kind of content, and BorderTitleBlock switches to the title block layer itself. No DXF version change: layers exist in R10. Checked on the 24 example projects, 133 folios: with the layer values set back to 0 and the LAYER table removed, every file is byte-identical to before; no entity is on an undeclared layer or left on 0; ezdxf reads all of them with no audit errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
+44
-10
@@ -42,6 +42,7 @@ namespace {
|
||||
}
|
||||
}
|
||||
double Createdxf::yScale = 1;
|
||||
QString Createdxf::layer = QStringLiteral("0");
|
||||
|
||||
Createdxf::Createdxf()
|
||||
{
|
||||
@@ -51,9 +52,12 @@ Createdxf::~Createdxf()
|
||||
{
|
||||
}
|
||||
|
||||
/* Header section of every DXF file.*/
|
||||
void Createdxf::dxfBegin (const QString& fileName)
|
||||
/* Header section of every DXF file.
|
||||
@param layers : the layers the entities will be written on, declared in
|
||||
the LAYER table beside layer "0", which every DXF has. */
|
||||
void Createdxf::dxfBegin (const QString& fileName, const QStringList &layers)
|
||||
{
|
||||
layer = QStringLiteral("0");
|
||||
|
||||
// Creation of an output stream object in text mode.
|
||||
// Header section of every dxf file.
|
||||
@@ -223,6 +227,35 @@ void Createdxf::dxfBegin (const QString& fileName)
|
||||
To_Dxf << 0.00 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n";
|
||||
|
||||
To_Dxf << "ENDTAB" << "\r\n";
|
||||
|
||||
// Layers: "0" plus the ones the entities use, all white/black
|
||||
// (colour 7) and continuous, so a file looks the same as before
|
||||
// until the user changes a layer.
|
||||
QStringList all_layers{QStringLiteral("0")};
|
||||
for (const QString &name : layers) {
|
||||
if (!all_layers.contains(name))
|
||||
all_layers << name;
|
||||
}
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "TABLE" << "\r\n";
|
||||
To_Dxf << 2 << "\r\n";
|
||||
To_Dxf << "LAYER" << "\r\n";
|
||||
To_Dxf << 70 << "\r\n";
|
||||
To_Dxf << all_layers.size() << "\r\n";
|
||||
for (const QString &name : std::as_const(all_layers)) {
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "LAYER" << "\r\n";
|
||||
To_Dxf << 2 << "\r\n";
|
||||
To_Dxf << name << "\r\n";
|
||||
To_Dxf << 70 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << 7 << "\r\n";
|
||||
To_Dxf << 6 << "\r\n";
|
||||
To_Dxf << "CONTINUOUS" << "\r\n";
|
||||
}
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "ENDTAB" << "\r\n";
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "ENDSEC" << "\r\n";
|
||||
@@ -248,6 +281,7 @@ void Createdxf::dxfBegin (const QString& fileName)
|
||||
*/
|
||||
void Createdxf::dxfEnd(const QString& fileName)
|
||||
{
|
||||
layer = QStringLiteral("0");
|
||||
// Creation of an output stream object in text mode.
|
||||
if (!fileName.isEmpty()) {
|
||||
QFile file(fileName);
|
||||
@@ -298,7 +332,7 @@ void Createdxf::drawCircle(
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "CIRCLE" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << colour << "\r\n"; // Colour Code
|
||||
To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle
|
||||
@@ -346,7 +380,7 @@ void Createdxf::drawLine (
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "LINE" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << colour << "\r\n"; // Colour Code
|
||||
To_Dxf << 10 << "\r\n";
|
||||
@@ -671,7 +705,7 @@ void Createdxf::drawArc(
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "ARC" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << color << "\r\n"; // Colour Code
|
||||
To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle
|
||||
@@ -727,7 +761,7 @@ void Createdxf::drawText(
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "TEXT" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << colour << "\r\n"; // Colour Code
|
||||
To_Dxf << 10 << "\r\n"; // XYZ
|
||||
@@ -780,7 +814,7 @@ void Createdxf::drawTextAligned(
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "TEXT" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << colour << "\r\n"; // Colour Code
|
||||
To_Dxf << 10 << "\r\n"; // XYZ
|
||||
@@ -861,7 +895,7 @@ void Createdxf::drawPolyline(const QString &filepath,
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "POLYLINE" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 62 << "\r\n";
|
||||
To_Dxf << colorcode << "\r\n"; // Colour Code
|
||||
To_Dxf << 66 << "\r\n";
|
||||
@@ -887,7 +921,7 @@ void Createdxf::drawPolyline(const QString &filepath,
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "VERTEX" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
To_Dxf << 70 << "\r\n";
|
||||
To_Dxf << 32 << "\r\n";
|
||||
To_Dxf << 10 << "\r\n";
|
||||
@@ -901,7 +935,7 @@ void Createdxf::drawPolyline(const QString &filepath,
|
||||
To_Dxf << 0 << "\r\n";
|
||||
To_Dxf << "SEQEND" << "\r\n";
|
||||
To_Dxf << 8 << "\r\n";
|
||||
To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad)
|
||||
To_Dxf << layer << "\r\n"; // Layer name
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user