[qet] [2733] Bug Fix: Extra line in polygon of elements and arcs and ellipses added.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2733
Author:   abhishekm71
Date:     2014-01-11 09:31:39 +0100 (Sat, 11 Jan 2014)
Log Message:
-----------
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.

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:25:14 UTC (rev 2732)
+++ trunk/sources/exportdialog.cpp	2014-01-11 08:31:39 UTC (rev 2733)
@@ -462,6 +462,26 @@
 				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

Modified: trunk/sources/qetgraphicsitem/customelement.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.cpp	2014-01-10 18:25:14 UTC (rev 2732)
+++ trunk/sources/qetgraphicsitem/customelement.cpp	2014-01-11 08:31:39 UTC (rev 2733)
@@ -79,6 +79,7 @@
 	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 @@
 	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 @@
 	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 @@
 	
 	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 @@
 		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 @@
 	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.

Modified: trunk/sources/qetgraphicsitem/customelement.h
===================================================================
--- trunk/sources/qetgraphicsitem/customelement.h	2014-01-10 18:25:14 UTC (rev 2732)
+++ trunk/sources/qetgraphicsitem/customelement.h	2014-01-11 08:31:39 UTC (rev 2733)
@@ -55,6 +55,7 @@
 	QList<QRectF *> list_rectangles_;
 	QList<QRectF *> list_circles_;
 	QList<QVector<QPointF> *> list_polygons_;
+	QList<QVector<qreal> *> list_arcs_;
 	
 	// methods
 	public:
@@ -65,6 +66,7 @@
 	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;

Modified: trunk/sources/qetgraphicsitem/element.h
===================================================================
--- trunk/sources/qetgraphicsitem/element.h	2014-01-10 18:25:14 UTC (rev 2732)
+++ trunk/sources/qetgraphicsitem/element.h	2014-01-11 08:31:39 UTC (rev 2733)
@@ -88,7 +88,9 @@
 	/// @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;
+	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


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/