I am trying to generate various gate symbols
( AND,NOT,XNOR,MUX etc) by reading .slib
file.
But I faced a problem while reading an arc
related co-ordinate from .slib
file.
I am not understanding how to use those co-ordinates and draw an arc ?
The format of an arc in .slib file is confusing.
.slib
format for an arc
and for line
line (66 * SCALE, 80 * SCALE, 0 * SCALE, 80 * SCALE);
line (94 * SCALE, 70 * SCALE, 62 * SCALE, 70 * SCALE);
.
.
arc (145 * SCALE, 100 * SCALE, 94 * SCALE, 70 * SCALE,94.9268 * SCALE,126.774 * SCALE);
arc (94 * SCALE, 130 * SCALE, 145 * SCALE, 100 * SCALE,94.9268 * SCALE, 73.2256 * SCALE);
arc (61 * SCALE, 130 * SCALE, 61 * SCALE, 70 * SCALE,8.75 * SCALE, 100 * SCALE);
1st line says draw an arc from O (145,100) to F(94,70)
2nd line says draw an arc from L(94,130) to O(145,100)
3rd line says draw an arc from K(62,30) to E(62,70)
I tried to draw an arc by using 1st 4 co-ordinates from line ( but do not know how to use remaining 2 co-ordinates ? )
QPainterPath path; // arc from L ---> F
path.moveTo(94,70);
QRect bound1 (44,70,102,60);
path.arcTo(bound1,90,-180);
QPainterPath path1; // arc from K ---> E
path1.moveTo(62,70);
QRect bound2 (42,70,40,60);
path1.arcTo(bound2,90,-180);
And I got following output :
But,
Input lines to OR gate are not attached to 1st arc.
I am using only first four co-ordinates. How to use remaining 2 co-ordinates to draw an arc ?
So how to use all given co-ordinates from.slib
to draw an arc
?
Note : SCALE is defined at the start of the file.
CodePudding user response:
It looks like the first two coordinate pairs are two points on an imaginary circle and the third pair is the center of that circle. Together, those describe a circle arc section. For this to work with arcTo
, we construct a QRectF
bounding the circle, ie with the given center and side 2*radius
.
Thus, the following ought to work:
QPointF from, to; // first and second coordinate pair
QPointF center; // third coordinate pair
// Bounding rectangle is a square around center.
QLineF lineFrom{center, from};
QLineF lineTo{center, to};
qreal radius = lineFrom.length();
QRectF bounding{ center - QPointF{radius, radius}, center QPointF{radius, radius}};
// Use QLineF to calculate angles wrt horizontal axis.
qreal startAngle = lineFrom.angle();
qreal sweep = lineFrom.angleTo(lineTo);
QPainterPath path;
path.moveTo(from);
path.arcTo(bounding, startAngle, sweep);