DXF export: colour BYLAYER where QElectroTech sets no colour (#1071)

Most entities were written with colour 0, BYBLOCK. Outside a block that
falls back to the default colour, so it shows black on white or white on
black, and no layer colour could change it: recolouring QET_WIRES in a
CAD program left the wires as they were. Black itself maps to 0 too
(RGBcodeTable[0]).

Colour 0 is now written as 256, BYLAYER. The layers are colour 7, so a
file looks the same on opening, and recolouring a layer now recolours
its contents. Real colours (free texts, terminal markers) are kept.

Checked on the 24 example projects, 133 folios: the only change from
the previous commit is 110,283 colour codes 0 -> 256, no entity is left
on 0, and ezdxf reads all of them with no audit errors. Rendered with
QET_WIRES set to red and QET_SYMBOLS to blue: before, 0 red and 0 blue
pixels; after, the wires and symbols take the layer colours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-09-27 19:32:00 +13:00
parent 20a3e4f636
commit 1d980b164f
+16 -6
View File
@@ -40,6 +40,16 @@ namespace {
text.replace(QLatin1Char('\n'), QLatin1Char(' '));
return text;
}
/// Colour code of an entity. 0 is BYBLOCK, which means nothing outside a
/// block and so fell back to the default colour; it is also what black
/// maps to (RGBcodeTable[0]). BYLAYER (256) looks the same, the layers
/// being colour 7, and lets a CAD user recolour a whole layer at once
/// (discussion #1071). Real colours are kept.
int entityColour(int colour)
{
return colour == 0 ? 256 : colour;
}
}
double Createdxf::yScale = 1;
QString Createdxf::layer = QStringLiteral("0");
@@ -334,7 +344,7 @@ void Createdxf::drawCircle(
To_Dxf << 8 << "\r\n";
To_Dxf << layer << "\r\n"; // Layer name
To_Dxf << 62 << "\r\n";
To_Dxf << colour << "\r\n"; // Colour Code
To_Dxf << entityColour(colour) << "\r\n"; // Colour Code
To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle
To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates
To_Dxf << 20 << "\r\n";
@@ -382,7 +392,7 @@ void Createdxf::drawLine (
To_Dxf << 8 << "\r\n";
To_Dxf << layer << "\r\n"; // Layer name
To_Dxf << 62 << "\r\n";
To_Dxf << colour << "\r\n"; // Colour Code
To_Dxf << entityColour(colour) << "\r\n"; // Colour Code
To_Dxf << 10 << "\r\n";
To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates
To_Dxf << 20 << "\r\n";
@@ -707,7 +717,7 @@ void Createdxf::drawArc(
To_Dxf << 8 << "\r\n";
To_Dxf << layer << "\r\n"; // Layer name
To_Dxf << 62 << "\r\n";
To_Dxf << color << "\r\n"; // Colour Code
To_Dxf << entityColour(color) << "\r\n"; // Colour Code
To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle
To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates
To_Dxf << 20 << "\r\n";
@@ -763,7 +773,7 @@ void Createdxf::drawText(
To_Dxf << 8 << "\r\n";
To_Dxf << layer << "\r\n"; // Layer name
To_Dxf << 62 << "\r\n";
To_Dxf << colour << "\r\n"; // Colour Code
To_Dxf << entityColour(colour) << "\r\n"; // Colour Code
To_Dxf << 10 << "\r\n"; // XYZ
To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates
To_Dxf << 20 << "\r\n";
@@ -816,7 +826,7 @@ void Createdxf::drawTextAligned(
To_Dxf << 8 << "\r\n";
To_Dxf << layer << "\r\n"; // Layer name
To_Dxf << 62 << "\r\n";
To_Dxf << colour << "\r\n"; // Colour Code
To_Dxf << entityColour(colour) << "\r\n"; // Colour Code
To_Dxf << 10 << "\r\n"; // XYZ
To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates
To_Dxf << 20 << "\r\n";
@@ -897,7 +907,7 @@ void Createdxf::drawPolyline(const QString &filepath,
To_Dxf << 8 << "\r\n";
To_Dxf << layer << "\r\n"; // Layer name
To_Dxf << 62 << "\r\n";
To_Dxf << colorcode << "\r\n"; // Colour Code
To_Dxf << entityColour(colorcode) << "\r\n"; // Colour Code
To_Dxf << 66 << "\r\n";
To_Dxf << 1 << "\r\n";
To_Dxf << 70 << "\r\n";