diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index 278954ef0..d01c1aedb 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -406,8 +406,8 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee //Draw elements foreach(Element *elmt, list_elements) { - qreal hot_spot_x = elmt -> pos().x();// + elmt -> hotspot().x(); - qreal hot_spot_y = elmt -> pos().y();// + elmt -> hotspot().y(); + qreal hot_spot_x = elmt -> pos().x(); + qreal hot_spot_y = elmt -> pos().y();// - (diagram -> margin / 2); QList elmt_text = elmt -> texts(); 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(); x *= Createdxf::xScale; 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 ); } + + QList 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 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 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 *> elmt_polygon = elmt -> polygons(); + foreach(QVector *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 diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index 122af8607..e93344214 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -73,7 +73,13 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg elmt_state = 3; return; } - + + //Start from empty lists. + list_lines_.clear(); + list_rectangles_.clear(); + list_circles_.clear(); + list_polygons_.clear(); + buildFromXml(element_definition -> xml(), &elmt_state); if (state) *state = elmt_state; if (elmt_state) return; @@ -219,6 +225,26 @@ QList CustomElement::texts() const { return(list_texts_); } +/// @return the list of lines +QList CustomElement::lines() const { + return(list_lines_); +} + +/// @return the list of rectangles +QList CustomElement::rectangles() const { + return(list_rectangles_); +} + +/// @return the list of bounding rectangles for circles +QList CustomElement::circles() const { + return(list_circles_); +} + +/// @return the list of bounding rectangles for circles +QList *> CustomElement::polygons() const { + return(list_polygons_); +} + /** @return Le nombre de bornes que l'element possede */ @@ -296,6 +322,11 @@ bool CustomElement::parseLine(QDomElement &e, QPainter &qp) { qp.setPen(t); QLineF line(x1, y1, x2, y2); + + //Add line to the list + QLineF *newLine = new QLineF(line); + list_lines_ << newLine; + QPointF point1(line.p1()); 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("width"), &rect_w)) 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(); setPainterStyle(e, qp); @@ -424,7 +460,13 @@ bool CustomElement::parseCircle(QDomElement &e, QPainter &qp) { if (!QET::attributeIsAReal(e, QString("diameter"), &cercle_r)) return(false); qp.save(); 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(); return(true); } @@ -515,10 +557,25 @@ bool CustomElement::parsePolygon(QDomElement &e, QPainter &qp) { ) ); } + qp.save(); setPainterStyle(e, qp); 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 *poly = new QVector(points); + list_polygons_ << poly; + qp.restore(); return(true); } diff --git a/sources/qetgraphicsitem/customelement.h b/sources/qetgraphicsitem/customelement.h index 34a061ed7..8445a14b1 100644 --- a/sources/qetgraphicsitem/customelement.h +++ b/sources/qetgraphicsitem/customelement.h @@ -50,12 +50,21 @@ class CustomElement : public FixedElement { QList list_terminals; QList list_texts_; bool forbid_antialiasing; + + QList list_lines_; + QList list_rectangles_; + QList list_circles_; + QList *> list_polygons_; // methods public: virtual QList terminals() const; virtual QList conductors() const; virtual QList texts() const; + virtual QList lines() const; + virtual QList rectangles() const; + virtual QList circles() const; + virtual QList *> polygons() const; virtual int terminalsCount() const; virtual void paint(QPainter *, const QStyleOptionGraphicsItem *); QString typeId() const; diff --git a/sources/qetgraphicsitem/element.h b/sources/qetgraphicsitem/element.h index b90605aac..15b1e1575 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -81,6 +81,14 @@ class Element : public QetGraphicsItem { virtual QList conductors() const = 0; /// @return the list of text items attached to this element virtual QList texts() const = 0; + /// @return the list of lines items in this element + virtual QList lines() const = 0; + /// @return the list of rectangles items in this element + virtual QList rectangles() const = 0; + /// @return the list of bounding rectangles for circles items in this element + virtual QList circles() const = 0; + /// @return the list of polygons in this element + virtual QList *> polygons() const = 0; /// @return the current number of terminals of this element virtual int terminalsCount() const = 0; /// @return the minimum number of terminals for this element