Fix DXF export of circles, arcs and the title block at the right (#1339)

Circles and arcs: drawArcEllipse() split each curve into quarters and
fitted a circular ARC through a point half way between the curve and its
chord, so every circle came out as a flattened diamond. A circle or an
arc of one is now one exact CIRCLE or ARC. R10 has no ELLIPSE entity, so
a true ellipse is a polyline through the curve, one point every 5
degrees. The export also used a different scale on each axis, which made
round things oval; it now uses one, the largest that fits the sheet.

Title block at the right: the DXF laid the horizontal template out in
the narrow vertical strip, squashing it into the top corner. It is now
laid out horizontally and turned a quarter, as draw() turns the painter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-07 08:13:52 +13:00
parent 0708338bce
commit 83f72c95c6
11 changed files with 325 additions and 153 deletions
+31 -14
View File
@@ -1646,12 +1646,16 @@ void TitleBlockTemplate::render(QPainter &painter,
Width of the titleblock to render
@param file_path :
@param color :
@param dxf_transform :
Applied to every DXF point after the title block is laid out, as the
QPainter is rotated for a title block at the right of the folio
*/
void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
const DiagramContext &diagram_context,
int titleblock_width,
QString &file_path,
int color) const
int color,
const QTransform &dxf_transform) const
{
QList<int> widths = columnsWidth(titleblock_width);
@@ -1663,12 +1667,13 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
*Createdxf::yScale;
double recWidth = title_block_rect.width() * Createdxf::xScale;
double recHeight = title_block_rect.height() * Createdxf::yScale;
Createdxf::drawRectangle(file_path,
xCoord,
yCoord,
recWidth,
recHeight,
color);
Createdxf::drawPolyline(file_path,
dxf_transform.map(QPolygonF(QRectF(xCoord,
yCoord,
recWidth,
recHeight))),
color,
true);
// run through each individual cell
for (int j = 0 ; j < rows_heights_.count() ; ++ j) {
@@ -1702,7 +1707,10 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
y = yCoord + recHeight - h - y*Createdxf::yScale;
w *= Createdxf::xScale;
Createdxf::drawRectangle(file_path, x, y, w, h, color);
Createdxf::drawPolyline(file_path,
dxf_transform.map(QPolygonF(QRectF(x, y, w, h))),
color,
true);
if (cells_[i][j] -> type() == TitleBlockCell::TextCell)
{
QString final_text =
@@ -1715,7 +1723,8 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect,
y,
w,
h,
color);
color,
dxf_transform);
}
}
}
@@ -1967,6 +1976,7 @@ void TitleBlockTemplate::renderTextCell(QPainter &painter,
@param w
@param h
@param color
@param dxf_transform : see renderDxf()
*/
void TitleBlockTemplate::renderTextCellDxf(
QString &file_path,
@@ -1976,7 +1986,8 @@ void TitleBlockTemplate::renderTextCellDxf(
qreal y,
qreal w,
qreal h,
int color) const
int color,
const QTransform &dxf_transform) const
{
if (text.isEmpty()) return;
QFont text_font = TitleBlockTemplate::fontForCell(cell);
@@ -2038,6 +2049,8 @@ void TitleBlockTemplate::renderTextCellDxf(
const QStringList lines = text.split(QRegularExpression(QStringLiteral("\r\n|\r|\n")));
const qreal line_spacing = textHeight * Createdxf::yScale * 1.6;
const int last = lines.size() - 1;
const qreal rotation = qRadiansToDegrees(
qAtan2(dxf_transform.m12(), dxf_transform.m11()));
for (int i = 0 ; i < lines.size() ; ++i)
{
const QString &line = lines.at(i);
@@ -2064,17 +2077,21 @@ void TitleBlockTemplate::renderTextCellDxf(
}
// x offset value below currently set heuristically based on appearance...
const QPointF insert = dxf_transform.map(
QPointF(x - 2*Createdxf::xScale, y1 + offset));
const QPointF align = dxf_transform.map(QPointF(x2, y1 + offset));
Createdxf::drawTextAligned(
file_path,
line,
x - 2*Createdxf::xScale,
y1 + offset,
insert.x(),
insert.y(),
textHeight*Createdxf::yScale,
0,
rotation,
0,
hAlign,
vAlign,
x2,
align.x(),
align.y(),
ratio,
color);
}