DXF - Simplifying, WIP

This commit is contained in:
David Varley
2020-09-17 21:45:14 +10:00
parent 07df62e362
commit 4d7ece07ab
3 changed files with 46 additions and 69 deletions

View File

@@ -255,6 +255,26 @@ void Createdxf::dxfEnd(const QString& fileName)
} }
} }
/**
@brief Createdxf::drawCircle
draw circle in qt format
@param fileName
@param center
@param radius
@param colour
*/
void Createdxf::drawCircle(
const QString& fileName,
QPointF centre,
double radius,
int colour)
{
qreal x = centre.x() * xScale;
qreal y = sheetHeight - centre.y() * yScale;
qreal r = radius * xScale;
drawCircle(fileName,r,x,y,colour);
}
/** /**
@brief Createdxf::drawCircle @brief Createdxf::drawCircle
draw circle in dxf format draw circle in dxf format
@@ -447,7 +467,7 @@ int Createdxf::dxfColor(QPen pen) {
/** /**
@brief Createdxf::drawLine @brief Createdxf::drawLine
Conveniance function to draw line Convenience function to draw line
@param filepath @param filepath
@param line @param line
@param colorcode @param colorcode

View File

@@ -39,6 +39,13 @@ class Createdxf
double, double,
double, double,
int); int);
static void drawCircle(
const QString& ,
QPointF,
double,
int );
static void drawArc( static void drawArc(
const QString&, const QString&,
double x, double x,

View File

@@ -443,18 +443,10 @@ void ExportDialog::generateDxf(
//Add project elements (lines, rectangles, circles, texts) to dxf file //Add project elements (lines, rectangles, circles, texts) to dxf file
if (epw -> exportProperties().draw_border) { if (epw -> exportProperties().draw_border) {
double bx0 = Diagram::margin * Createdxf::xScale; QRectF rect(Diagram::margin,Diagram::margin,width,height);
double by0 = Diagram::margin * Createdxf::yScale; Createdxf::drawRectangle(file_path,rect,0);
Createdxf::drawRectangle(
file_path,
bx0,
-by0,
double(width)*Createdxf::xScale,
double(height)*Createdxf::yScale,
0);
} }
diagram -> border_and_titleblock.drawDxf(file_path, diagram -> border_and_titleblock.drawDxf(file_path, 0);
0);
// Build the lists of elements. // Build the lists of elements.
QList<Element *> list_elements; QList<Element *> list_elements;
@@ -542,71 +534,32 @@ void ExportDialog::generateDxf(
for (QLineF line : primitives.m_lines) for (QLineF line : primitives.m_lines)
{ {
qreal x1 = (elem_pos_x + line.p1().x()) * Createdxf::xScale; QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle);
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + line.p1().y()) * Createdxf::yScale; QLineF l = t.map(line);
QPointF transformed_point = rotation_transformed(x1, y1, hotspot_x, hotspot_y, rotation_angle); Createdxf::drawLine(file_path, l, 0);
x1 = transformed_point.x();
y1 = transformed_point.y();
qreal x2 = (elem_pos_x + line.p2().x()) * Createdxf::xScale;
qreal y2 = Createdxf::sheetHeight - (elem_pos_y + line.p2().y()) * Createdxf::yScale;
transformed_point = rotation_transformed(x2, y2, hotspot_x, hotspot_y, rotation_angle);
x2 = transformed_point.x();
y2 = transformed_point.y();
Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
} }
for (QRectF rect : primitives.m_rectangles) for (QRectF rect : primitives.m_rectangles)
{ {
qreal x1 = (elem_pos_x + rect.bottomLeft().x()) * Createdxf::xScale; QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle);
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + rect.bottomLeft().y()) * Createdxf::yScale; QRectF r = t.mapRect(rect);
qreal w = rect.width() * Createdxf::xScale; Createdxf::drawRectangle(file_path,r,0);
qreal h = rect.height() * Createdxf::yScale;
// opposite corner
qreal x2 = x1 + w;
qreal y2 = y1 + h;
QPointF transformed_point = rotation_transformed(x1, y1, hotspot_x, hotspot_y, rotation_angle);
x1 = transformed_point.x();
y1 = transformed_point.y();
transformed_point = rotation_transformed(x2, y2, hotspot_x, hotspot_y, rotation_angle);
x2 = transformed_point.x();
y2 = transformed_point.y();
qreal bottom_left_x = (x1 < x2) ? x1 : x2;
qreal bottom_left_y = (y1 < y2) ? y1 : y2;
w = (x1 < x2) ? x2-x1 : x1-x2;
h = (y1 < y2) ? y2-y1 : y1-y2;
Createdxf::drawRectangle(file_path, bottom_left_x, bottom_left_y, w, h, 0);
} }
for (QRectF circle_rect : primitives.m_circles) for (QRectF circle_rect : primitives.m_circles)
{ {
qreal x1 = (elem_pos_x + circle_rect.center().x()) * Createdxf::xScale; QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle);
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + circle_rect.center().y()) * Createdxf::yScale; QPointF c = t.map(QPointF(circle_rect.center().x(),circle_rect.center().y()));
qreal r = circle_rect.width() * Createdxf::xScale / 2; Createdxf::drawCircle(file_path,c,circle_rect.width()/2,0);
QPointF transformed_point = rotation_transformed(x1, y1, hotspot_x, hotspot_y, rotation_angle);
x1 = transformed_point.x();
y1 = transformed_point.y();
Createdxf::drawCircle(file_path, r, x1, y1, 0);
} }
for (QVector<QPointF> polygon : primitives.m_polygons) for (QVector<QPointF> polygon : primitives.m_polygons)
{ {
if (polygon.size() == 0) if (polygon.size() == 0)
continue; continue;
qreal x1 = (elem_pos_x + polygon.at(0).x()) * Createdxf::xScale; QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle);
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + polygon.at(0).y()) * Createdxf::yScale; QPolygonF poly = t.map(polygon);
QPointF transformed_point = rotation_transformed(x1, y1, hotspot_x, hotspot_y, rotation_angle); Createdxf::drawPolygon(file_path,poly,0);
x1 = transformed_point.x();
y1 = transformed_point.y();
for (int i = 1; i < polygon.size(); ++i ) {
qreal x2 = (elem_pos_x + polygon.at(i).x()) * Createdxf::xScale;
qreal y2 = Createdxf::sheetHeight - (elem_pos_y + polygon.at(i).y()) * Createdxf::yScale;
QPointF transformed_point = rotation_transformed(x2, y2, hotspot_x, hotspot_y, rotation_angle);
x2 = transformed_point.x();
y2 = transformed_point.y();
Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
x1 = x2;
y1 = y2;
}
} }
// Draw arcs and ellipses // Draw arcs and ellipses
@@ -626,13 +579,10 @@ void ExportDialog::generateDxf(
// Draw terminals // Draw terminals
QList<Terminal *> list_terminals = elmt->terminals(); QList<Terminal *> list_terminals = elmt->terminals();
QColor col("red"); QColor col("red");
QTransform t = QTransform().translate(elem_pos_x,elem_pos_y).rotate(rotation_angle);
foreach(Terminal *tp, list_terminals) { foreach(Terminal *tp, list_terminals) {
qreal x = (elem_pos_x + tp->dock_elmt_.x()) * Createdxf::xScale; QPointF c = t.map(QPointF(tp->dock_elmt_.x(),tp->dock_elmt_.y()));
qreal y = Createdxf::sheetHeight - (elem_pos_y + tp->dock_elmt_.y()) * Createdxf::yScale; Createdxf::drawCircle(file_path,c,3.0,Createdxf::dxfColor(col));
QPointF transformed_point = rotation_transformed(x, y, hotspot_x, hotspot_y, rotation_angle);
x = transformed_point.x();
y = transformed_point.y();
Createdxf::drawCircle(file_path, 3.0* Createdxf::xScale, x, y, Createdxf::dxfColor(col));
} }
} }
} }