[qet] [2732] DXF Export: Added some parts of elements: |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 2732
Author: abhishekm71
Date: 2014-01-10 19:25:14 +0100 (Fri, 10 Jan 2014)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/sources/exportdialog.cpp
trunk/sources/qetgraphicsitem/customelement.cpp
trunk/sources/qetgraphicsitem/customelement.h
trunk/sources/qetgraphicsitem/element.h
Modified: trunk/sources/exportdialog.cpp
===================================================================
--- trunk/sources/exportdialog.cpp 2014-01-10 18:17:21 UTC (rev 2731)
+++ trunk/sources/exportdialog.cpp 2014-01-10 18:25:14 UTC (rev 2732)
@@ -406,8 +406,8 @@
//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<ElementTextItem *> elmt_text = elmt -> texts();
foreach(ElementTextItem *dti, elmt_text) {
@@ -418,9 +418,50 @@
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<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
Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp 2014-01-10 18:17:21 UTC (rev 2731)
+++ trunk/sources/qetgraphicsitem/customelement.cpp 2014-01-10 18:25:14 UTC (rev 2732)
@@ -73,7 +73,13 @@
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 @@
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
*/
@@ -296,6 +322,11 @@
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 @@
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 @@
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 @@
)
);
}
+
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<QPointF> *poly = new QVector<QPointF>(points);
+ list_polygons_ << poly;
+
qp.restore();
return(true);
}
Modified: trunk/sources/qetgraphicsitem/customelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.h 2014-01-10 18:17:21 UTC (rev 2731)
+++ trunk/sources/qetgraphicsitem/customelement.h 2014-01-10 18:25:14 UTC (rev 2732)
@@ -50,12 +50,21 @@
QList<Terminal *> list_terminals;
QList<ElementTextItem *> list_texts_;
bool forbid_antialiasing;
+
+ QList<QLineF *> list_lines_;
+ QList<QRectF *> list_rectangles_;
+ QList<QRectF *> list_circles_;
+ QList<QVector<QPointF> *> list_polygons_;
// methods
public:
virtual QList<Terminal *> terminals() const;
virtual QList<Conductor *> conductors() 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 void paint(QPainter *, const QStyleOptionGraphicsItem *);
QString typeId() const;
Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h 2014-01-10 18:17:21 UTC (rev 2731)
+++ trunk/sources/qetgraphicsitem/element.h 2014-01-10 18:25:14 UTC (rev 2732)
@@ -81,6 +81,14 @@
virtual QList<Conductor *> conductors() const = 0;
/// @return the list of text items attached to this element
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
virtual int terminalsCount() const = 0;
/// @return the minimum number of terminals for this element