mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-14 20:33:05 +02:00
Static text of element are now exported to dxf
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5896 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
571d9fdac5
commit
4cbf103cbc
@ -36,6 +36,8 @@
|
|||||||
#include "element.h"
|
#include "element.h"
|
||||||
#include "dynamicelementtextitem.h"
|
#include "dynamicelementtextitem.h"
|
||||||
|
|
||||||
|
#include <QGraphicsSimpleTextItem>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Constructeur
|
Constructeur
|
||||||
@param project Le projet a exporter
|
@param project Le projet a exporter
|
||||||
@ -499,6 +501,41 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
|
|||||||
|
|
||||||
ElementPictureFactory::primitives primitives = ElementPictureFactory::instance()->getPrimitives(elmt->location());
|
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)
|
for (QLineF line : primitives.m_lines)
|
||||||
{
|
{
|
||||||
qreal x1 = (elem_pos_x + line.p1().x()) * Createdxf::xScale;
|
qreal x1 = (elem_pos_x + line.p1().x()) * Createdxf::xScale;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <QPicture>
|
#include <QPicture>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <QAbstractTextDocumentLayout>
|
#include <QAbstractTextDocumentLayout>
|
||||||
|
#include <QGraphicsSimpleTextItem>
|
||||||
|
|
||||||
ElementPictureFactory* ElementPictureFactory::m_factory = nullptr;
|
ElementPictureFactory* ElementPictureFactory::m_factory = nullptr;
|
||||||
|
|
||||||
@ -124,6 +125,12 @@ ElementPictureFactory::primitives ElementPictureFactory::getPrimitives(const Ele
|
|||||||
return m_primitives_H.value(location.uuid());
|
return m_primitives_H.value(location.uuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ElementPictureFactory::~ElementPictureFactory() {
|
||||||
|
for (primitives p : m_primitives_H.values()) {
|
||||||
|
qDeleteAll(p.m_texts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ElementPictureFactory::build
|
* @brief ElementPictureFactory::build
|
||||||
* Build the picture from location.
|
* Build the picture from location.
|
||||||
@ -523,6 +530,14 @@ void ElementPictureFactory::parseText(const QDomElement &dom, QPainter &painter,
|
|||||||
ctx.palette.setColor(QPalette::Text, text_color);
|
ctx.palette.setColor(QPalette::Text, text_color);
|
||||||
text_document.documentLayout() -> draw(&painter, ctx);
|
text_document.documentLayout() -> draw(&painter, ctx);
|
||||||
|
|
||||||
|
//A very dirty workaround for export this text to dxf
|
||||||
|
QGraphicsSimpleTextItem *qgsti = new QGraphicsSimpleTextItem();
|
||||||
|
qgsti->setText(dom.attribute("text"));
|
||||||
|
qgsti->setFont(font_);
|
||||||
|
qgsti->setPos(dom.attribute("x").toDouble(), dom.attribute("y").toDouble());
|
||||||
|
qgsti->setRotation(dom.attribute("rotation", "0").toDouble());
|
||||||
|
prim.m_texts << qgsti;
|
||||||
|
|
||||||
painter.restore();
|
painter.restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ class QPicture;
|
|||||||
class QUuid;
|
class QUuid;
|
||||||
class QDomElement;
|
class QDomElement;
|
||||||
class QPainter;
|
class QPainter;
|
||||||
|
class QGraphicsSimpleTextItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ElementPictureFactory class
|
* @brief The ElementPictureFactory class
|
||||||
@ -43,6 +44,7 @@ class ElementPictureFactory
|
|||||||
QList<QRectF> m_circles;
|
QList<QRectF> m_circles;
|
||||||
QList<QVector<QPointF>> m_polygons;
|
QList<QVector<QPointF>> m_polygons;
|
||||||
QList<QVector<qreal>> m_arcs;
|
QList<QVector<qreal>> m_arcs;
|
||||||
|
QList<QGraphicsSimpleTextItem*> m_texts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -88,7 +90,7 @@ class ElementPictureFactory
|
|||||||
ElementPictureFactory() {}
|
ElementPictureFactory() {}
|
||||||
ElementPictureFactory (const ElementPictureFactory &);
|
ElementPictureFactory (const ElementPictureFactory &);
|
||||||
ElementPictureFactory operator= (const ElementPictureFactory &);
|
ElementPictureFactory operator= (const ElementPictureFactory &);
|
||||||
~ElementPictureFactory() {}
|
~ElementPictureFactory();
|
||||||
|
|
||||||
bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr);
|
bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr);
|
||||||
void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const;
|
void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user