Hi Ronny,
in exportdialog you can found functions to export project to DXF :
// Determine les elements a "XMLiser"
foreach(QGraphicsItem *qgi, diagram -> items()) {
if (Element *elmt = qgraphicsitem_cast<Element *>(qgi)) {
list_elements << elmt;
} else if (Conductor *f = qgraphicsitem_cast<Conductor *>(qgi)) {
list_conductors << f;
} else if (IndependentTextItem *iti = qgraphicsitem_cast<IndependentTextItem *>(qgi)) {
list_texts << iti;
} else if (DiagramImageItem *dii = qgraphicsitem_cast<DiagramImageItem *>(qgi)) {
list_images << dii;
} else if (QetShapeItem *dii = qgraphicsitem_cast<QetShapeItem *>(qgi)) {
list_shapes << dii;
} else if (DynamicElementTextItem *deti = qgraphicsitem_cast<DynamicElementTextItem *>(qgi)) {
list_texts << deti;
}
}
}
After for parsing to QTextStream
//Draw elements
foreach(Element *elmt, list_elements)
{
double rotation_angle = elmt -> orientation() * 90;
qreal elem_pos_x = elmt -> pos().x();
qreal elem_pos_y = elmt -> pos().y();// - (diagram -> margin / 2);
qreal hotspot_x = (elem_pos_x) * Createdxf::xScale;
qreal hotspot_y = Createdxf::sheetHeight - (elem_pos_y) * Createdxf::yScale;
ElementPictureFactory::primitives primitives = ElementPictureFactory::instance()->getPrimitives(elmt->location());
for(QGraphicsSimpleTextItem *text : primitives.m_texts)
{
qreal fontSize = text->font().pointSizeF();
if (fontSize < 0)
fontSize = text->font().pixelSize();
fontSize *= Createdxf::yScale;
qreal x = elem_pos_x + text->pos().x();
qreal y = elem_pos_y + text->pos().y();
x *= Createdxf::xScale;
y = Createdxf::sheetHeight - (y * Createdxf::yScale);// - fontSize;
QPointF transformed_point = rotation_transformed(x, y, hotspot_x, hotspot_y, rotation_angle);
x = transformed_point.x();
y = transformed_point.y();
QStringList lines = text->text().split('\n');
y += (fontSize/2) * (lines.count()-1);
for (QString line : lines)
{
qreal angle = 360 - (text->rotation() + rotation_angle);
if (line.size() > 0 && line != "_" ) {
Createdxf::drawText(file_path, line, x, y, fontSize, angle, 0);
}
angle += 1080;
// coordinates for next line
if (int(angle) % 360 == 0) // no rotation
y -= fontSize*1.06;
else if (int(angle - 180) % 360 == 0) // 180 degrees rotation
y += fontSize*1.06;
else if (int(angle - 270) % 360 == 0) // 270 degrees rotation
x -= fontSize*1.06;
else // ((angle - 90) % 360 == 0) 90 degrees rotation
x += fontSize*1.06;
}
}
for (QLineF line : primitives.m_lines)
{
qreal x1 = (elem_pos_x + line.p1().x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + line.p1().y()) * Createdxf::yScale;
QPointF transformed_point = rotation_transformed(x1, y1, hotspot_x, hotspot_y, rotation_angle);
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)
{
qreal x1 = (elem_pos_x + rect.bottomLeft().x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + rect.bottomLeft().y()) * Createdxf::yScale;
qreal w = rect.width() * Createdxf::xScale;
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)
{
qreal x1 = (elem_pos_x + circle_rect.center().x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + circle_rect.center().y()) * Createdxf::yScale;
qreal r = circle_rect.width() * Createdxf::xScale / 2;
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)
{
if (polygon.size() == 0)
continue;
qreal x1 = (elem_pos_x + polygon.at(0).x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (elem_pos_y + polygon.at(0).y()) * Createdxf::yScale;
QPointF transformed_point = rotation_transformed(x1, y1, hotspot_x, hotspot_y, rotation_angle);
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
for (QVector<qreal> arc : primitives.m_arcs)
{
if (arc.size() == 0)
continue;
qreal x = (elem_pos_x + arc.at(0)) * Createdxf::xScale;
qreal y = Createdxf::sheetHeight - (elem_pos_y + arc.at(1)) * Createdxf::yScale;
qreal w = arc.at(2) * Createdxf::xScale;
qreal h = arc.at(3) * Createdxf::yScale;
qreal startAngle = arc.at(4);
qreal spanAngle = arc .at(5);
Createdxf::drawArcEllipse(file_path, x, y, w, h, startAngle, spanAngle, hotspot_x, hotspot_y, rotation_angle, 0);
}
}
//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);
Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
}
//Draw conductor text item
ConductorTextItem *textItem = cond -> textItem();
if (textItem) {
qreal fontSize = textItem -> font().pointSizeF();
if (fontSize < 0)
fontSize = textItem -> font().pixelSize();
fontSize *= Createdxf::yScale;
qreal x = (textItem -> pos().x()) * Createdxf::xScale;
qreal y = Createdxf::sheetHeight - (textItem -> pos().y() * Createdxf::yScale) - fontSize;
QStringList lines = textItem->toPlainText().split('\n');
foreach (QString line, lines) {
qreal angle = 360 - (textItem -> rotation());
if (line.size() > 0 && line != "_" )
Createdxf::drawText(file_path, line, x, y, fontSize, angle, 0 );
angle += 1080;
// coordinates for next line
if (int(angle) % 360 == 0) // no rotation
y -= fontSize*1.06;
else if (int(angle - 180) % 360 == 0) // 180 degrees rotation
y += fontSize*1.06;
else if (int(angle - 270) % 360 == 0) // 270 degrees rotation
x -= fontSize*1.06;
else // ((angle - 90) % 360 == 0) 90 degrees rotation
x += fontSize*1.06;
}
}
}
//Draw text items
foreach(DiagramTextItem *dti, list_texts) {
qreal fontSize = dti -> font().pointSizeF();
if (fontSize < 0)
fontSize = dti -> font().pixelSize();
fontSize *= Createdxf::yScale;
qreal x = (dti->scenePos().x()) * Createdxf::xScale;
qreal y = Createdxf::sheetHeight - (dti->scenePos().y() * Createdxf::yScale) - fontSize*1.05;
QStringList lines = dti -> toPlainText().split('\n');
foreach (QString line, lines) {
qreal angle = 360 - (dti -> rotation());
if (line.size() > 0 && line != "_" )
Createdxf::drawText(file_path, line, x, y, fontSize, angle, 0);
angle += 1080;
// coordinates for next line
if (int(angle) % 360 == 0) // no rotation
y -= fontSize*1.06;
else if (int(angle - 180) % 360 == 0) // 180 degrees rotation
y += fontSize*1.06;
else if (int(angle - 270) % 360 == 0) // 270 degrees rotation
x -= fontSize*1.06;
else // ((angle - 90) % 360 == 0) 90 degrees rotation
x += fontSize*1.06;
}
}
Createdxf::dxfEnd(file_path);
saveReloadDiagramParameters(diagram, false);
}
void ExportDialog::fillRow(const QString& file_path, const QRectF &row_rect, QString author, const QString& title,
QString folio, QString date)
{
qreal x = row_rect.bottomLeft().x();
qreal y = row_rect.bottomLeft().y();
x *= Createdxf::xScale;
y = Createdxf::sheetHeight - y * Createdxf::yScale;
qreal height = row_rect.height() * Createdxf::yScale *0.7;
y += height*0.2;
Createdxf::drawTextAligned(file_path, std::move(folio),
x + 0.02*DiagramFolioList::colWidths[0]*row_rect.width()*Createdxf::xScale, y, height, 0, 0, 5, 0,
x + 0.95*DiagramFolioList::colWidths[0]*row_rect.width()*Createdxf::xScale, 0);
x += DiagramFolioList::colWidths[0]*row_rect.width()*Createdxf::xScale;
QString heading = tr("Titre");
if (title == heading)
Createdxf::drawTextAligned(file_path, title,
x + 0.02*DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale, y, height, 0, 0, 5, 0,
x + 0.02*DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale, 0);
else
Createdxf::drawTextAligned(file_path, title,
x + 0.02*DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale, y, height, 0, 0, 5, 0,
x + 0.02*DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale, 0, true);
x += DiagramFolioList::colWidths[1]*row_rect.width()*Createdxf::xScale;
Createdxf::drawTextAligned(file_path, std::move(author),
x + 0.02*DiagramFolioList::colWidths[2]*row_rect.width()*Createdxf::xScale, y, height, 0, 0, 5, 0,
x + 3.02*DiagramFolioList::colWidths[2]*row_rect.width()*Createdxf::xScale, 0);
x += DiagramFolioList::colWidths[2]*row_rect.width()*Createdxf::xScale;
Createdxf::drawTextAligned(file_path, std::move(date),
x + 0.02*DiagramFolioList::colWidths[3]*row_rect.width()*Createdxf::xScale, y, height, 0, 0, 5, 0,
x + 5.02*DiagramFolioList::colWidths[3]*row_rect.width()*Createdxf::xScale, 0);
}
QPointF ExportDialog::rotation_transformed(qreal px, qreal py , qreal origin_x, qreal origin_y, qreal angle) {
angle *= -3.14159265 / 180;
float s = sin(angle);
float c = cos(angle);
// Vector to rotate:
qreal Vx = px - origin_x;
qreal Vy = py - origin_y;
// rotate vector
float xnew = Vx * c - Vy * s;
float ynew = Vx * s + Vy * c;
return QPointF(xnew + origin_x, ynew + origin_y);
}