From 02afb6c00385dd961641dc56851137d83b9f206e Mon Sep 17 00:00:00 2001 From: David Varley Date: Sat, 15 Aug 2020 22:00:14 +1000 Subject: [PATCH 1/4] Fix dxf export for copied conductors --- sources/exportdialog.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index 759d66531..b5db3ccfa 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -578,12 +578,14 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee } //Draw conductors - foreach(Conductor *cond, list_conductors) { - foreach(ConductorSegment *segment, cond -> segmentsList()) { - qreal x1 = (segment -> firstPoint().x()) * Createdxf::xScale; - qreal y1 = Createdxf::sheetHeight - (segment -> firstPoint().y() * Createdxf::yScale); - qreal x2 = (segment -> secondPoint().x()) * Createdxf::xScale; - qreal y2 = Createdxf::sheetHeight - (segment -> secondPoint().y() * Createdxf::yScale); + foreach(Conductor *cond, list_conductors) { + qreal cx = cond->pos().x(); + qreal cy = cond->pos().y(); + foreach(ConductorSegment *segment, cond -> segmentsList()) { + qreal x1 = (cx + segment -> firstPoint().x()) * Createdxf::xScale; + qreal y1 = Createdxf::sheetHeight - ((cy + segment -> firstPoint().y()) * Createdxf::yScale); + qreal x2 = (cx + segment -> secondPoint().x()) * Createdxf::xScale; + qreal y2 = Createdxf::sheetHeight - ((cy + segment -> secondPoint().y()) * Createdxf::yScale); Createdxf::drawLine(file_path, x1, y1, x2, y2, 0); } //Draw conductor text item From ddc2afa427ab52c6d8656a85b00904aa42416d71 Mon Sep 17 00:00:00 2001 From: David Varley Date: Sun, 16 Aug 2020 15:39:20 +1000 Subject: [PATCH 2/4] Fix dxf export for border --- sources/bordertitleblock.cpp | 24 ++++++++++++------------ sources/exportdialog.cpp | 4 +++- sources/titleblocktemplate.cpp | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index a416140bd..8724bbac2 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -652,11 +652,11 @@ void BorderTitleBlock::drawDxf( if (display_border_ && display_columns_) { for (int i = 1 ; i <= columns_count_ ; ++ i) { - double xCoord = diagram_rect_.topLeft().x() + + double xCoord = diagram_rect_.topLeft().x() * Createdxf::xScale + (rows_header_width_ + ((i - 1) * columns_width_)); double yCoord = Createdxf::sheetHeight - - diagram_rect_.topLeft().y() + - diagram_rect_.topLeft().y()*Createdxf::yScale - columns_header_height_; double recWidth = columns_width_; double recHeight = columns_header_height_; @@ -665,27 +665,27 @@ void BorderTitleBlock::drawDxf( if (settings.value("border-columns_0", true).toBool()){ Createdxf::drawTextAligned(file_path, QString::number(i - 1), - xCoord, - yCoord + recHeight*0.5, + xCoord+recWidth/4, + yCoord + recHeight*0.2, recHeight*0.7, 0, 0, 1, 2, - xCoord+recWidth/2, + xCoord+recWidth/2, color, 0); }else{ Createdxf::drawTextAligned(file_path, QString::number(i), - xCoord, - yCoord + recHeight*0.5, + xCoord+recWidth/4, + yCoord + recHeight*0.2, recHeight*0.7, 0, 0, 1, 2, - xCoord+recWidth/2, + xCoord+recWidth/2, color, 0); } @@ -699,8 +699,8 @@ void BorderTitleBlock::drawDxf( for (int i = 1 ; i <= rows_count_ ; ++ i) { double xCoord = diagram_rect_.topLeft().x() * Createdxf::xScale; - double yCoord = Createdxf::sheetHeight - - diagram_rect_.topLeft().y() + double yCoord = Createdxf::sheetHeight + - diagram_rect_.topLeft().y() *Createdxf::yScale - ( columns_header_height_ @@ -713,8 +713,8 @@ void BorderTitleBlock::drawDxf( recWidth, recHeight, color); Createdxf::drawTextAligned(file_path, row_string, - xCoord, - yCoord + recHeight*0.5, + xCoord+recWidth*0.1, + yCoord + recHeight*0.4, recWidth*0.7, 0, 0, diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index b5db3ccfa..09cfc997e 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -412,7 +412,9 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee //Add project elements (lines, rectangles, circles, texts) to dxf file if (epw -> exportProperties().draw_border) { - Createdxf::drawRectangle(file_path, 0, 0, double(width)*Createdxf::xScale, double(height)*Createdxf::yScale, 0); + double bx0 = Diagram::margin * Createdxf::xScale; + double by0 = Diagram::margin * Createdxf::yScale; + Createdxf::drawRectangle(file_path, bx0, -by0, double(width)*Createdxf::xScale, double(height)*Createdxf::yScale, 0); } diagram -> border_and_titleblock.drawDxf(width, height, keep_aspect_ratio, file_path, 0); diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 85e2f8b86..2117c9e0c 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -1528,7 +1528,7 @@ void TitleBlockTemplate::renderDxf(QRectF &title_block_rect, QList widths = columnsWidth(titleblock_width); // draw the titleblock border - double xCoord = title_block_rect.topLeft().x(); + double xCoord = title_block_rect.topLeft().x()*Createdxf::xScale; double yCoord = Createdxf::sheetHeight - title_block_rect.bottomLeft().y() From 0cb98b2ee1d472c26f0afb04c440db5e9f1cbd91 Mon Sep 17 00:00:00 2001 From: David Varley Date: Mon, 17 Aug 2020 09:13:19 +1000 Subject: [PATCH 3/4] Adjust alignment of titleblock text in DXF export --- sources/titleblocktemplate.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index 2117c9e0c..c3fc83726 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -1850,11 +1850,13 @@ void TitleBlockTemplate::renderTextCellDxf(QString &file_path, textHeight *= ratio; } } - + //TODO DAV 16AUG2020 - x & y offset values bellow (5 & 3) set heuristically for now, as are not exactly Diagram::margin = 5 + // fix when have a chance to work through the preceding scaling logic! + // Also add/fix autosizing font to fit in cell Createdxf::drawTextAligned(file_path, text, - x, - y, + x - 5*Createdxf::xScale, + y - 3*Createdxf::yScale, textHeight*Createdxf::yScale, 0, 0, From 430ec27f365ee70f2be471c7b75012ba1f3f9c35 Mon Sep 17 00:00:00 2001 From: David Varley Date: Mon, 17 Aug 2020 15:38:24 +1000 Subject: [PATCH 4/4] Fix dxf export of autosize text cells in titleblock --- sources/bordertitleblock.cpp | 9 ++++++--- sources/createdxf.cpp | 4 +++- sources/createdxf.h | 2 +- sources/titleblocktemplate.cpp | 26 +++++++++----------------- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/sources/bordertitleblock.cpp b/sources/bordertitleblock.cpp index 8724bbac2..b11d66d30 100644 --- a/sources/bordertitleblock.cpp +++ b/sources/bordertitleblock.cpp @@ -673,7 +673,8 @@ void BorderTitleBlock::drawDxf( 1, 2, xCoord+recWidth/2, - color, + 1, + color, 0); }else{ Createdxf::drawTextAligned(file_path, @@ -686,7 +687,8 @@ void BorderTitleBlock::drawDxf( 1, 2, xCoord+recWidth/2, - color, + 1, + color, 0); } } @@ -721,7 +723,8 @@ void BorderTitleBlock::drawDxf( 1, 2, xCoord+recWidth/2, - color, + 1, + color, 0); row_string = incrementLetters(row_string); } diff --git a/sources/createdxf.cpp b/sources/createdxf.cpp index 5e04ed579..a6f4ac47a 100644 --- a/sources/createdxf.cpp +++ b/sources/createdxf.cpp @@ -744,7 +744,7 @@ void Createdxf::drawText(const QString& fileName, const QString& text,double x, /* draw aligned text in DXF Format */ // leftAlign flag added. If the alignment requested is 'fit to width' and the text length is very small, // then the text is either centered or left-aligned, depnding on the value of leftAlign. -void Createdxf::drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign,int colour, +void Createdxf::drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign, double xScale, int colour, bool leftAlign, float scale) { Q_UNUSED(scale); @@ -774,6 +774,8 @@ void Createdxf::drawTextAligned(const QString& fileName, const QString& text,dou To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates To_Dxf << 40 << "\r\n"; To_Dxf << height << "\r\n"; // Text Height + To_Dxf << 41 << "\r\n"; + To_Dxf << xScale << "\r\n"; // X Scale To_Dxf << 1 << "\r\n"; To_Dxf << text << "\r\n"; // Text Value To_Dxf << 50 << "\r\n"; diff --git a/sources/createdxf.h b/sources/createdxf.h index 328090035..cf64c96c7 100644 --- a/sources/createdxf.h +++ b/sources/createdxf.h @@ -46,7 +46,7 @@ class Createdxf static void drawLine(const QString &filepath, const QLineF &line,const int &colorcode); static void drawText(const QString&,const QString&,double,double,double,double,int); - static void drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign, int colour, bool leftAlign = false, float scale = 0); + static void drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign, double xScale, int colour, bool leftAlign = false, float scale = 0); static int getcolorCode (const long red, const long green, const long blue); diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index c3fc83726..5b2af260f 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -1833,29 +1833,20 @@ void TitleBlockTemplate::renderTextCellDxf(QString &file_path, x2 = x; } else if ( cell.alignment & Qt::AlignBottom ) {} - //painter.setFont(text_font); - + qreal ratio = 1.0; if (cell.hadjust) { - QFontMetricsF font_metrics(text_font); - QRectF font_rect = font_metrics.boundingRect( - QRect(-10000, -10000, 10000, 10000), - cell.alignment, - text); - - if (font_rect.width()*Createdxf::xScale > w) { - qreal ratio = qreal(w) - / qreal(font_rect.width() - *Createdxf::xScale); - textHeight *= ratio; + // Scale font width to fit string in cell width w + QFontMetricsF font_metrics(text_font); + qreal textw = font_metrics.width(text)*Createdxf::xScale; + if (textw > w) { + ratio = (w / textw) * 0.8; // Allow some space around text in cell } } - //TODO DAV 16AUG2020 - x & y offset values bellow (5 & 3) set heuristically for now, as are not exactly Diagram::margin = 5 - // fix when have a chance to work through the preceding scaling logic! - // Also add/fix autosizing font to fit in cell + // x & y offset values below (1 & 3) currently set heuristically based on appearance... Createdxf::drawTextAligned(file_path, text, - x - 5*Createdxf::xScale, + x - 1*Createdxf::xScale, y - 3*Createdxf::yScale, textHeight*Createdxf::yScale, 0, @@ -1863,6 +1854,7 @@ void TitleBlockTemplate::renderTextCellDxf(QString &file_path, hAlign, vAlign, x2, + ratio, color, 0);