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
This commit is contained in:
abhishekm71
2014-01-11 08:31:39 +00:00
parent ea953c4c4c
commit 8c86ced6df
4 changed files with 54 additions and 8 deletions

View File

@@ -462,6 +462,26 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
y1 = y2;
}
}
// Draw arcs and ellipses
QList<QVector<qreal> *> elmt_arc = elmt -> arcs();
foreach(QVector<qreal> *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

View File

@@ -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<QVector<QPointF> *> CustomElement::polygons() const {
return(list_polygons_);
}
/// @return the list of arcs
QList<QVector<qreal> *> 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<qreal> *arc = new QVector<qreal>;
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<qreal> *arc = new QVector<qreal>;
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<QPointF> points(i-1);
QVector<QPointF> 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.

View File

@@ -55,6 +55,7 @@ class CustomElement : public FixedElement {
QList<QRectF *> list_rectangles_;
QList<QRectF *> list_circles_;
QList<QVector<QPointF> *> list_polygons_;
QList<QVector<qreal> *> list_arcs_;
// methods
public:
@@ -65,6 +66,7 @@ class CustomElement : public FixedElement {
virtual QList<QRectF *> rectangles() const;
virtual QList<QRectF *> circles() const;
virtual QList<QVector<QPointF> *> polygons() const;
virtual QList<QVector<qreal> *> arcs() const;
virtual int terminalsCount() const;
virtual void paint(QPainter *, const QStyleOptionGraphicsItem *);
QString typeId() const;

View File

@@ -89,6 +89,8 @@ class Element : public QetGraphicsItem {
virtual QList<QRectF *> circles() const = 0;
/// @return the list of polygons in this element
virtual QList<QVector<QPointF> *> polygons() const = 0;
/// @return the list of arcs in this element
virtual QList<QVector<qreal> *> 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