From 8c86ced6df15cb4d2b80e6c6c6eb283b961d0f34 Mon Sep 17 00:00:00 2001 From: abhishekm71 Date: Sat, 11 Jan 2014 08:31:39 +0000 Subject: [PATCH] Bug Fix: Extra line in polygon of elements and arcs and ellipses added. Arcs and ellipses are approximated with circles at present. Also, element rotation is not supported right now. Needs to be added. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2733 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/exportdialog.cpp | 20 +++++++++++++ sources/qetgraphicsitem/customelement.cpp | 36 ++++++++++++++++++----- sources/qetgraphicsitem/customelement.h | 2 ++ sources/qetgraphicsitem/element.h | 4 ++- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/sources/exportdialog.cpp b/sources/exportdialog.cpp index d01c1aedb..abf68dad9 100644 --- a/sources/exportdialog.cpp +++ b/sources/exportdialog.cpp @@ -462,6 +462,26 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee y1 = y2; } } + + // Draw arcs and ellipses + QList *> elmt_arc = elmt -> arcs(); + foreach(QVector *arc, elmt_arc) { + if (arc -> size() == 0) + continue; + qreal x = (hot_spot_x + arc -> at(0)) * Createdxf::xScale; + qreal y = Createdxf::sheetHeight - (hot_spot_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); + + // approximate this to center_x, center_y, radius, start angle and end angle. + qreal center_x = x + w/2; + qreal center_y = y - w/2; + qreal radius = (w+h)/4; + qreal endAngle = startAngle + spanAngle; + Createdxf::drawArc(file_path, center_x, center_y, radius, endAngle, startAngle, 0); + } } //Draw conductors diff --git a/sources/qetgraphicsitem/customelement.cpp b/sources/qetgraphicsitem/customelement.cpp index e93344214..2bb659ac9 100644 --- a/sources/qetgraphicsitem/customelement.cpp +++ b/sources/qetgraphicsitem/customelement.cpp @@ -79,6 +79,7 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg list_rectangles_.clear(); list_circles_.clear(); list_polygons_.clear(); + list_arcs_.clear(); buildFromXml(element_definition -> xml(), &elmt_state); if (state) *state = elmt_state; @@ -245,6 +246,11 @@ QList *> CustomElement::polygons() const { return(list_polygons_); } +/// @return the list of arcs +QList *> CustomElement::arcs() const { + return(list_arcs_); +} + /** @return Le nombre de bornes que l'element possede */ @@ -493,6 +499,16 @@ bool CustomElement::parseEllipse(QDomElement &e, QPainter &qp) { if (!QET::attributeIsAReal(e, QString("height"), &ellipse_h)) return(false); qp.save(); setPainterStyle(e, qp); + + QVector *arc = new QVector; + arc -> push_back(ellipse_x); + arc -> push_back(ellipse_y); + arc -> push_back(ellipse_l); + arc -> push_back(ellipse_h); + arc -> push_back(0); + arc -> push_back(360); + list_arcs_ << arc; + qp.drawEllipse(QRectF(ellipse_x, ellipse_y, ellipse_l, ellipse_h)); qp.restore(); return(true); @@ -524,6 +540,16 @@ bool CustomElement::parseArc(QDomElement &e, QPainter &qp) { qp.save(); setPainterStyle(e, qp); + + QVector *arc = new QVector; + arc -> push_back(arc_x); + arc -> push_back(arc_y); + arc -> push_back(arc_l); + arc -> push_back(arc_h); + arc -> push_back(arc_s); + arc -> push_back(arc_a); + list_arcs_ << arc; + qp.drawArc(QRectF(arc_x, arc_y, arc_l, arc_h), (int)(arc_s * 16), (int)(arc_a * 16)); qp.restore(); return(true); @@ -547,7 +573,7 @@ bool CustomElement::parsePolygon(QDomElement &e, QPainter &qp) { else break; } if (i < 3) return(false); - QVector points(i-1); + QVector points; // empty vector created instead of default initialized vector with i-1 elements. for (int j = 1 ; j < i ; ++ j) { points.insert( j - 1, @@ -563,13 +589,9 @@ bool CustomElement::parsePolygon(QDomElement &e, QPainter &qp) { if (e.attribute("closed") == "false") qp.drawPolyline(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() - ) - ); + points.push_back(points[0]); } // Add to list of polygons. diff --git a/sources/qetgraphicsitem/customelement.h b/sources/qetgraphicsitem/customelement.h index 8445a14b1..189e9095c 100644 --- a/sources/qetgraphicsitem/customelement.h +++ b/sources/qetgraphicsitem/customelement.h @@ -55,6 +55,7 @@ class CustomElement : public FixedElement { QList list_rectangles_; QList list_circles_; QList *> list_polygons_; + QList *> list_arcs_; // methods public: @@ -65,6 +66,7 @@ class CustomElement : public FixedElement { virtual QList rectangles() const; virtual QList circles() const; virtual QList *> polygons() const; + virtual QList *> arcs() 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 15b1e1575..b39bff407 100644 --- a/sources/qetgraphicsitem/element.h +++ b/sources/qetgraphicsitem/element.h @@ -88,7 +88,9 @@ class Element : public QetGraphicsItem { /// @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; + virtual QList *> polygons() const = 0; + /// @return the list of arcs in this element + virtual QList *> arcs() 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