mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
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:
@@ -462,6 +462,26 @@ void ExportDialog::generateDxf(Diagram *diagram, int width, int height, bool kee
|
|||||||
y1 = y2;
|
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
|
//Draw conductors
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ CustomElement::CustomElement(const ElementsLocation &location, QGraphicsItem *qg
|
|||||||
list_rectangles_.clear();
|
list_rectangles_.clear();
|
||||||
list_circles_.clear();
|
list_circles_.clear();
|
||||||
list_polygons_.clear();
|
list_polygons_.clear();
|
||||||
|
list_arcs_.clear();
|
||||||
|
|
||||||
buildFromXml(element_definition -> xml(), &elmt_state);
|
buildFromXml(element_definition -> xml(), &elmt_state);
|
||||||
if (state) *state = elmt_state;
|
if (state) *state = elmt_state;
|
||||||
@@ -245,6 +246,11 @@ QList<QVector<QPointF> *> CustomElement::polygons() const {
|
|||||||
return(list_polygons_);
|
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
|
@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);
|
if (!QET::attributeIsAReal(e, QString("height"), &ellipse_h)) return(false);
|
||||||
qp.save();
|
qp.save();
|
||||||
setPainterStyle(e, qp);
|
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.drawEllipse(QRectF(ellipse_x, ellipse_y, ellipse_l, ellipse_h));
|
||||||
qp.restore();
|
qp.restore();
|
||||||
return(true);
|
return(true);
|
||||||
@@ -524,6 +540,16 @@ bool CustomElement::parseArc(QDomElement &e, QPainter &qp) {
|
|||||||
|
|
||||||
qp.save();
|
qp.save();
|
||||||
setPainterStyle(e, qp);
|
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.drawArc(QRectF(arc_x, arc_y, arc_l, arc_h), (int)(arc_s * 16), (int)(arc_a * 16));
|
||||||
qp.restore();
|
qp.restore();
|
||||||
return(true);
|
return(true);
|
||||||
@@ -547,7 +573,7 @@ bool CustomElement::parsePolygon(QDomElement &e, QPainter &qp) {
|
|||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
if (i < 3) return(false);
|
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) {
|
for (int j = 1 ; j < i ; ++ j) {
|
||||||
points.insert(
|
points.insert(
|
||||||
j - 1,
|
j - 1,
|
||||||
@@ -563,13 +589,9 @@ bool CustomElement::parsePolygon(QDomElement &e, QPainter &qp) {
|
|||||||
if (e.attribute("closed") == "false") qp.drawPolyline(points.data(), i-1);
|
if (e.attribute("closed") == "false") qp.drawPolyline(points.data(), i-1);
|
||||||
else {
|
else {
|
||||||
qp.drawPolygon(points.data(), i-1);
|
qp.drawPolygon(points.data(), i-1);
|
||||||
|
|
||||||
// insert first point at the end again for DXF export.
|
// insert first point at the end again for DXF export.
|
||||||
points.push_back(
|
points.push_back(points[0]);
|
||||||
QPointF(
|
|
||||||
e.attribute(QString("x%1").arg(1)).toDouble(),
|
|
||||||
e.attribute(QString("y%1").arg(1)).toDouble()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to list of polygons.
|
// Add to list of polygons.
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class CustomElement : public FixedElement {
|
|||||||
QList<QRectF *> list_rectangles_;
|
QList<QRectF *> list_rectangles_;
|
||||||
QList<QRectF *> list_circles_;
|
QList<QRectF *> list_circles_;
|
||||||
QList<QVector<QPointF> *> list_polygons_;
|
QList<QVector<QPointF> *> list_polygons_;
|
||||||
|
QList<QVector<qreal> *> list_arcs_;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
public:
|
public:
|
||||||
@@ -65,6 +66,7 @@ class CustomElement : public FixedElement {
|
|||||||
virtual QList<QRectF *> rectangles() const;
|
virtual QList<QRectF *> rectangles() const;
|
||||||
virtual QList<QRectF *> circles() const;
|
virtual QList<QRectF *> circles() const;
|
||||||
virtual QList<QVector<QPointF> *> polygons() const;
|
virtual QList<QVector<QPointF> *> polygons() const;
|
||||||
|
virtual QList<QVector<qreal> *> arcs() 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;
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ class Element : public QetGraphicsItem {
|
|||||||
/// @return the list of bounding rectangles for circles items in this element
|
/// @return the list of bounding rectangles for circles items in this element
|
||||||
virtual QList<QRectF *> circles() const = 0;
|
virtual QList<QRectF *> circles() const = 0;
|
||||||
/// @return the list of polygons in this element
|
/// @return the list of polygons in this element
|
||||||
virtual QList<QVector<QPointF> *> polygons() const = 0;
|
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
|
/// @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
|
||||||
|
|||||||
Reference in New Issue
Block a user