mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-03 01: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:
+19
-1
@@ -81,8 +81,12 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
Createdxf::xScale = Createdxf::sheetWidth / double(width);
|
||||
Createdxf::yScale = Createdxf::sheetHeight / double(height);
|
||||
|
||||
Createdxf::dxfBegin(file_path);
|
||||
Createdxf::dxfBegin(file_path, Layer::all());
|
||||
|
||||
//Each kind of content on its own layer (discussion #1071). The
|
||||
//border's title block switches to Layer::TitleBlock itself, see
|
||||
//BorderTitleBlock::drawDxf().
|
||||
Createdxf::layer = Layer::Border;
|
||||
//Add project elements (lines, rectangles, circles, texts) to dxf file
|
||||
if (properties.draw_border) {
|
||||
QRectF rect(Diagram::margin,Diagram::margin,width,height);
|
||||
@@ -154,9 +158,11 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
}
|
||||
|
||||
// Draw shapes
|
||||
Createdxf::layer = Layer::Shapes;
|
||||
foreach (QetShapeItem *qsi, list_shapes) qsi->toDXF(file_path, qsi->pen());
|
||||
|
||||
// Draw tables
|
||||
Createdxf::layer = Layer::Tables;
|
||||
foreach (QetGraphicsTableItem *gti, list_tables) {
|
||||
gti->toDXF(file_path);
|
||||
}
|
||||
@@ -171,6 +177,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
|
||||
ElementPictureFactory::primitives primitives = ElementPictureFactory::instance()->getPrimitives(elmt->location());
|
||||
|
||||
Createdxf::layer = Layer::SymbolTexts;
|
||||
for(QGraphicsSimpleTextItem *text : primitives.m_texts)
|
||||
{
|
||||
qreal fontSize = text->font().pointSizeF();
|
||||
@@ -200,6 +207,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
}
|
||||
}
|
||||
|
||||
Createdxf::layer = Layer::Symbols;
|
||||
for (QLineF line : primitives.m_lines)
|
||||
{
|
||||
QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle);
|
||||
@@ -249,6 +257,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
Createdxf::drawArcEllipse(file_path, r, startAngle, spanAngle, hotspot, rotation_angle, 0);
|
||||
}
|
||||
if (properties.draw_terminals) {
|
||||
Createdxf::layer = Layer::Terminals;
|
||||
// Draw terminals
|
||||
QList<Terminal *> list_terminals = elmt->terminals();
|
||||
QColor col("red");
|
||||
@@ -272,8 +281,10 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
}
|
||||
poly << cond->pos()+segment->secondPoint();
|
||||
}
|
||||
Createdxf::layer = Layer::Wires;
|
||||
Createdxf::drawPolyline(file_path,poly,0);
|
||||
//Draw conductor text item
|
||||
Createdxf::layer = Layer::WireNumbers;
|
||||
ConductorTextItem *textItem = cond -> textItem();
|
||||
|
||||
if (textItem) {
|
||||
@@ -302,6 +313,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
}
|
||||
|
||||
// Draw the junctions
|
||||
Createdxf::layer = Layer::Junctions;
|
||||
QList<QPointF> junctions_list = cond->junctions();
|
||||
if (!junctions_list.isEmpty()) {
|
||||
foreach(QPointF point, junctions_list) {
|
||||
@@ -312,6 +324,9 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
|
||||
//Draw text items
|
||||
foreach(DiagramTextItem *dti, list_texts) {
|
||||
//A free text, or a symbol's own text (its label and the like)
|
||||
Createdxf::layer = qgraphicsitem_cast<IndependentTextItem *>(dti)
|
||||
? Layer::Texts : Layer::SymbolTexts;
|
||||
qreal fontSize = dti -> font().pointSizeF();
|
||||
if (fontSize < 0)
|
||||
fontSize = dti -> font().pixelSize();
|
||||
@@ -344,6 +359,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
}
|
||||
|
||||
//Draw the slave cross-reference labels
|
||||
Createdxf::layer = Layer::Xrefs;
|
||||
for (QGraphicsTextItem *xref : std::as_const(list_xref_texts))
|
||||
{
|
||||
qreal fontSize = xref->font().pointSizeF();
|
||||
@@ -382,6 +398,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
//Draw the master-side cross-reference items (table/cross), replaying
|
||||
//their existing paint() unmodified through DxfPaintEngine instead of
|
||||
//hand-porting drawAsCross()/drawAsContacts()/drawAsPlcTable().
|
||||
Createdxf::layer = Layer::Xrefs;
|
||||
for (CrossRefItem *xref : std::as_const(list_master_xrefs))
|
||||
{
|
||||
DxfPaintDevice dxf_device(file_path);
|
||||
@@ -401,6 +418,7 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
//actually turns the drawPixmap() call inside paint() into a
|
||||
//placeholder outline, since this DXF dialect has no raster image
|
||||
//entity to draw instead.
|
||||
Createdxf::layer = Layer::Images;
|
||||
for (DiagramImageItem *image : std::as_const(list_images))
|
||||
{
|
||||
DxfPaintDevice dxf_device(file_path);
|
||||
|
||||
Reference in New Issue
Block a user