Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrects the ellipse rotation for paste #235

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gui/cadscriptwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void CadScriptWidget::ellipse(qreal x, qreal y, qreal minR,
qreal majR, qreal angle)
{
// creates an ellipse entity in the scene
ellipseItem = new Ellipse(++id, QPointF(x,y), minR, majR, angle);
ellipseItem = new Ellipse(++id, QPointF(x,y), minR, majR, -angle);
currentScene->drawEntity(ellipseItem);
}

Expand Down
8 changes: 3 additions & 5 deletions gui/entities/circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Circle::Circle(QPointF p1, QPointF p2)
/**
* set values of center point, end point
* and calculate radius of circle
*/
*/
centerP = p1;
endP = p2;
radius = qSqrt(qPow((endP.x()-centerP.x()), 2)
Expand All @@ -20,7 +20,7 @@ Circle::Circle(int i, QPointF p1, QPointF p2)
/**
* set values of center point, end point
* and calculate radius of circle
*/
*/
centerP = p1;
endP = p2;
radius = qSqrt(qPow((endP.x()-centerP.x()), 2)
Expand All @@ -35,7 +35,7 @@ Circle::Circle(int i, QPointF p1, qreal rad)
/**
* set values of center point
* and radius of circle
*/
*/
centerP = p1;
radius = rad;
}
Expand Down Expand Up @@ -103,8 +103,6 @@ getEntity *Circle::clone(int i)
{
Circle *c = new Circle;
c->id = i;
c->centerP.x();
c->centerP.y();
c->radius = radius;
return c;
}
Expand Down
48 changes: 34 additions & 14 deletions gui/entities/ellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

Ellipse::Ellipse(QPointF point1, QPointF point2, QPointF point3)
{
/** set values of three points
/**
* set values of three points
* and calculate radii of ellipse
*/
*/
p1 = point1;
p2 = point2;
p3 = point3;
Expand All @@ -17,9 +18,10 @@ Ellipse::Ellipse(int i, QPointF point1, QPointF point2, QPointF point3)
// assigns id
id = i;

/** set values of three points
/**
* set values of three points
* and calculate radii of ellipse
*/
*/
p1 = point1;
p2 = point2;
p3 = point3;
Expand All @@ -35,11 +37,17 @@ Ellipse::Ellipse(int i, QPointF point1, qreal rad, qreal radM, qreal angle)
/**
* set values of center point
* and radii of ellipse
*/
*/
p1 = point1;
minRadius = rad;
majRadius = radM;
theta = angle;

/**
* This is set to false to overcome the problem of rotation after pasting
* or if the ellipse is drawn from script widget.
*/
setOrientation(false);
}

void Ellipse::calculate()
Expand All @@ -60,13 +68,23 @@ void Ellipse::calculate()
theta = atan2((p3.y() - p1.y()), (p3.x() - p1.x())) * (180 / M_PI);
}

// This is set to true to rotate the ellipse
setOrientation(true);
}

void Ellipse::setOrientation(bool b)
{
topLeft.setX(p1.x() - majRadius);
topLeft.setY(p1.y() - minRadius);
bottomRight.setX(p1.x() + majRadius);
bottomRight.setY(p1.y() + minRadius);

setTransformOriginPoint(p1);
setRotation(theta);

if (b)
setRotation(theta);
else
setRotation(-theta);
}

int Ellipse::type() const
Expand All @@ -88,8 +106,16 @@ QPainterPath Ellipse::shape() const
QRectF Ellipse::boundingRect() const
{
// bounding rectangle for ellipse
return QRectF(p1.x() - majRadius, p1.y() - majRadius,
majRadius * 2, majRadius * 2);
qreal rad;
qreal extra = 1.0;

if (majRadius >= minRadius)
rad = majRadius;
else
rad = minRadius;

return QRectF(p1.x() - rad, p1.y() - rad, rad * 2, rad * 2)
.adjusted(-extra, -extra, extra, extra);
}

void Ellipse::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
Expand Down Expand Up @@ -132,12 +158,6 @@ getEntity *Ellipse::clone(int i)
{
Ellipse *e = new Ellipse;
e->id = i;
e->p1.x();
e->p1.y();
e->p2.x();
e->p2.y();
e->p3.x();
e->p3.y();
e->theta = theta;
e->minRadius = minRadius;
e->majRadius = majRadius;
Expand Down
1 change: 1 addition & 0 deletions gui/entities/ellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Ellipse : public getEntity
int type() const;
getEntity *clone(int);
QPointF getCenter();
void setOrientation(bool);

int id;
QPointF p1, p2, p3, topLeft, bottomRight;
Expand Down