DXF Export: Added some parts of elements:

1. lines
2. rectangles
3. circles
4. polygons

Coordinate accuracy to be checked. More element parts to be added.




git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2732 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
abhishekm71
2014-01-10 18:25:14 +00:00
parent 9f3120e7f1
commit ea953c4c4c
4 changed files with 121 additions and 6 deletions

View File

@@ -406,8 +406,8 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
//Draw elements //Draw elements
foreach(Element *elmt, list_elements) { foreach(Element *elmt, list_elements) {
qreal hot_spot_x = elmt -> pos().x();// + elmt -> hotspot().x(); qreal hot_spot_x = elmt -> pos().x();
qreal hot_spot_y = elmt -> pos().y();// + elmt -> hotspot().y(); qreal hot_spot_y = elmt -> pos().y();// - (diagram -> margin / 2);
QList<ElementTextItem *> elmt_text = elmt -> texts(); QList<ElementTextItem *> elmt_text = elmt -> texts();
foreach(ElementTextItem *dti, elmt_text) { foreach(ElementTextItem *dti, elmt_text) {
@@ -418,9 +418,50 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
qreal x = hot_spot_x + dti -> pos().x(); qreal x = hot_spot_x + dti -> pos().x();
x *= Createdxf::xScale; x *= Createdxf::xScale;
qreal y = hot_spot_y + dti -> pos().y(); qreal y = hot_spot_y + dti -> pos().y();
y = Createdxf::sheetHeight - (y * Createdxf::yScale) - fontSize*1.05; y = Createdxf::sheetHeight - (y * Createdxf::yScale) - fontSize;
Createdxf::drawText(file_path, dti -> toPlainText(), x, y, fontSize, dti -> rotationAngle(), 0 ); Createdxf::drawText(file_path, dti -> toPlainText(), x, y, fontSize, dti -> rotationAngle(), 0 );
} }
QList<QLineF *> elmt_line = elmt -> lines();
foreach(QLineF *line, elmt_line) {
qreal x1 = (hot_spot_x + line -> p1().x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (hot_spot_y + line -> p1().y()) * Createdxf::yScale;
qreal x2 = (hot_spot_x + line -> p2().x()) * Createdxf::xScale;
qreal y2 = Createdxf::sheetHeight - (hot_spot_y + line -> p2().y()) * Createdxf::yScale;
Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
}
QList<QRectF *> elmt_rectangle = elmt -> rectangles();
foreach(QRectF *rect, elmt_rectangle) {
qreal x1 = (hot_spot_x + rect -> bottomLeft().x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (hot_spot_y + rect -> bottomLeft().y()) * Createdxf::yScale;
qreal w = rect -> width() * Createdxf::xScale;
qreal h = rect -> height() * Createdxf::yScale;
Createdxf::drawRectangle(file_path, x1, y1, w, h, 0);
}
QList<QRectF *> elmt_circle = elmt -> circles();
foreach(QRectF *circle_rect, elmt_circle) {
qreal x1 = (hot_spot_x + circle_rect ->center().x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (hot_spot_y + circle_rect -> center().y()) * Createdxf::yScale;
qreal r = circle_rect -> width() * Createdxf::xScale / 2;
Createdxf::drawCircle(file_path, r, x1, y1, 0);
}
QList<QVector<QPointF> *> elmt_polygon = elmt -> polygons();
foreach(QVector<QPointF> *polygon, elmt_polygon) {
if (polygon -> size() == 0)
continue;
qreal x1 = (hot_spot_x + polygon -> at(0).x()) * Createdxf::xScale;
qreal y1 = Createdxf::sheetHeight - (hot_spot_y + polygon -> at(0).y()) * Createdxf::yScale;
for (int i = 1; i < polygon -> size(); ++i ) {
qreal x2 = (hot_spot_x + polygon -> at(i).x()) * Createdxf::xScale;
qreal y2 = Createdxf::sheetHeight - (hot_spot_y + polygon -> at(i).y()) * Createdxf::yScale;
Createdxf::drawLine(file_path, x1, y1, x2, y2, 0);
x1 = x2;
y1 = y2;
}
}
} }
//Draw conductors //Draw conductors

View File

@@ -73,7 +73,13 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg
elmt_state = 3; elmt_state = 3;
return; return;
} }
//Start from empty lists.
list_lines_.clear();
list_rectangles_.clear();
list_circles_.clear();
list_polygons_.clear();
buildFromXml(element_definition -> xml(), &elmt_state); buildFromXml(element_definition -> xml(), &elmt_state);
if (state) *state = elmt_state; if (state) *state = elmt_state;
if (elmt_state) return; if (elmt_state) return;
@@ -219,6 +225,26 @@ QList<ElementTextItem *> CustomElement::texts() const {
return(list_texts_); return(list_texts_);
} }
/// @return the list of lines
QList<QLineF *> CustomElement::lines() const {
return(list_lines_);
}
/// @return the list of rectangles
QList<QRectF *> CustomElement::rectangles() const {
return(list_rectangles_);
}
/// @return the list of bounding rectangles for circles
QList<QRectF *> CustomElement::circles() const {
return(list_circles_);
}
/// @return the list of bounding rectangles for circles
QList<QVector<QPointF> *> CustomElement::polygons() const {
return(list_polygons_);
}
/** /**
@return Le nombre de bornes que l'element possede @return Le nombre de bornes que l'element possede
*/ */
@@ -296,6 +322,11 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp) {
qp.setPen(t); qp.setPen(t);
QLineF line(x1, y1, x2, y2); QLineF line(x1, y1, x2, y2);
//Add line to the list
QLineF *newLine = new QLineF(line);
list_lines_ << newLine;
QPointF point1(line.p1()); QPointF point1(line.p1());
QPointF point2(line.p2()); QPointF point2(line.p2());
@@ -391,6 +422,11 @@ bool CustomElement::parseRect(QDomElement &e, QPainter &qp) {
if (!QET::attributeIsAReal(e, QString("y"), &rect_y)) return(false); if (!QET::attributeIsAReal(e, QString("y"), &rect_y)) return(false);
if (!QET::attributeIsAReal(e, QString("width"), &rect_w)) return(false); if (!QET::attributeIsAReal(e, QString("width"), &rect_w)) return(false);
if (!QET::attributeIsAReal(e, QString("height"), &rect_h)) return(false); if (!QET::attributeIsAReal(e, QString("height"), &rect_h)) return(false);
//Add rectangle to the list
QRectF *rect = new QRectF(rect_x, rect_y, rect_w, rect_h);
list_rectangles_ << rect;
qp.save(); qp.save();
setPainterStyle(e, qp); setPainterStyle(e, qp);
@@ -424,7 +460,13 @@ bool CustomElement::parseCircle(QDomElement &e, QPainter &qp) {
if (!QET::attributeIsAReal(e, QString("diameter"), &cercle_r)) return(false); if (!QET::attributeIsAReal(e, QString("diameter"), &cercle_r)) return(false);
qp.save(); qp.save();
setPainterStyle(e, qp); setPainterStyle(e, qp);
qp.drawEllipse(QRectF(cercle_x, cercle_y, cercle_r, cercle_r)); QRectF circle_bounding_rect(cercle_x, cercle_y, cercle_r, cercle_r);
// Add circle to list
QRectF *circle = new QRectF(circle_bounding_rect);
list_circles_ << circle;
qp.drawEllipse(circle_bounding_rect);
qp.restore(); qp.restore();
return(true); return(true);
} }
@@ -515,10 +557,25 @@ bool CustomElement::parsePolygon(QDomElement &e, QPainter &qp) {
) )
); );
} }
qp.save(); qp.save();
setPainterStyle(e, qp); setPainterStyle(e, qp);
if (e.attribute("closed") == "false") qp.drawPolyline(points.data(), i-1); if (e.attribute("closed") == "false") qp.drawPolyline(points.data(), i-1);
else qp.drawPolygon(points.data(), i-1); else {
qp.drawPolygon(points.data(), i-1);
// insert first point at the end again for DXF export.
points.push_back(
QPointF(
e.attribute(QString("x%1").arg(1)).toDouble(),
e.attribute(QString("y%1").arg(1)).toDouble()
)
);
}
// Add to list of polygons.
QVector<QPointF> *poly = new QVector<QPointF>(points);
list_polygons_ << poly;
qp.restore(); qp.restore();
return(true); return(true);
} }

View File

@@ -50,12 +50,21 @@ class CustomElement : public FixedElement {
QList<Terminal *> list_terminals; QList<Terminal *> list_terminals;
QList<ElementTextItem *> list_texts_; QList<ElementTextItem *> list_texts_;
bool forbid_antialiasing; bool forbid_antialiasing;
QList<QLineF *> list_lines_;
QList<QRectF *> list_rectangles_;
QList<QRectF *> list_circles_;
QList<QVector<QPointF> *> list_polygons_;
// methods // methods
public: public:
virtual QList<Terminal *> terminals() const; virtual QList<Terminal *> terminals() const;
virtual QList<Conductor *> conductors() const; virtual QList<Conductor *> conductors() const;
virtual QList<ElementTextItem *> texts() const; virtual QList<ElementTextItem *> texts() const;
virtual QList<QLineF *> lines() const;
virtual QList<QRectF *> rectangles() const;
virtual QList<QRectF *> circles() const;
virtual QList<QVector<QPointF> *> polygons() const;
virtual int terminalsCount() const; virtual int terminalsCount() const;
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *); virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
QString typeId() const; QString typeId() const;

View File

@@ -81,6 +81,14 @@ class Element : public QetGraphicsItem {
virtual QList<Conductor *> conductors() const = 0; virtual QList<Conductor *> conductors() const = 0;
/// @return the list of text items attached to this element /// @return the list of text items attached to this element
virtual QList<ElementTextItem *> texts() const = 0; virtual QList<ElementTextItem *> texts() const = 0;
/// @return the list of lines items in this element
virtual QList<QLineF *> lines() const = 0;
/// @return the list of rectangles items in this element
virtual QList<QRectF *> rectangles() const = 0;
/// @return the list of bounding rectangles for circles items in this element
virtual QList<QRectF *> circles() const = 0;
/// @return the list of polygons in this element
virtual QList<QVector<QPointF> *> polygons() const = 0;
/// @return the current number of terminals of this element /// @return the current number of terminals of this element
virtual int terminalsCount() const = 0; virtual int terminalsCount() const = 0;
/// @return the minimum number of terminals for this element /// @return the minimum number of terminals for this element