Permalink
Browse files

Fix ellipse loading/rendering

  • Loading branch information...
feragon committed Aug 4, 2017
1 parent 42476bc commit da256b760a2003c2e986a85308abc78d24e3b815
@@ -155,9 +155,11 @@ void DXFimpl::addArc(const DRW_Arc& data) {
void DXFimpl::addEllipse(const DRW_Ellipse& data) {
std::shared_ptr<lc::MetaInfo> mf = getMetaInfo(data);
auto layer = _document->layerByName(data.layer);
auto secPoint = coord(data.secPoint);
auto lcEllipse = std::make_shared<lc::entity::Ellipse>(coord(data.basePoint),
coord(data.secPoint),
coord(data.basePoint).distanceTo(coord(data.secPoint)) / data.ratio,
secPoint,
secPoint.magnitude() * data.ratio,
data.staparam,
data.endparam,
data.isccw,
@@ -51,6 +51,9 @@ function EllipseOperations:newData(data)
message("Click on major point")
elseif(self.majorPoint == nil) then
self.majorPoint = Operations:getCoordinate(data)
if(self.majorPoint ~= nil) then
self.majorPoint = self.majorPoint:sub(self.center)
end
message("Give minor radius")
elseif(self.minorRadius == nil) then
@@ -89,7 +92,7 @@ function EllipseOperations:createTempEllipse(point)
if(center == nil) then
center = point
elseif(majorPoint == nil) then
majorPoint = point
majorPoint = point:sub(self.center)
minorRadius = Operations:getDistance(center, majorPoint) / 2
elseif(minorRadius == nil) then
minorRadius = Operations:getDistance(center, point)
@@ -5,17 +5,6 @@
using namespace lc;
using namespace geo;
Ellipse::Ellipse(const Coordinate& center, const Coordinate& majorP, double minorRadius, double startAngle, double endAngle) :
Base(),
_center(center),
_majorP(majorP),
_minorRadius(minorRadius),
_startAngle(startAngle),
_endAngle(endAngle),
_isReversed(false){
}
Ellipse::Ellipse(const Coordinate& center, const Coordinate& majorP, double minorRadius, double startAngle, double endAngle, bool reversed) :
_center(center),
_majorP(majorP),
@@ -13,16 +13,24 @@ namespace lc {
namespace geo {
class Ellipse : public Base, virtual public Visitable {
public:
Ellipse(const Coordinate& center, const Coordinate& majorP, double minorRadius, double startAngle, double endAngle);
Ellipse(const Coordinate& center, const Coordinate& majorP, double minorRadius, double startAngle, double endAngle, bool reversed);
/**
* @brief
* @param center
* @param majorP relative to center
* @param minorRadius
* @param startAngle
* @param endAngle
* @param reversed
*/
Ellipse(const Coordinate& center, const Coordinate& majorP, double minorRadius, double startAngle, double endAngle, bool reversed = false);
/**
* @brief center, Returns Center point of Ellipse
* @return geo::Coordinate center
*/
const Coordinate center() const;
/**
* @brief majorP, Returns major point of the ellipse
* @brief majorP, Returns major point of the ellipse, relative to center
* @return geo::Coordinate majorP
*/
const Coordinate majorP() const;
@@ -19,7 +19,7 @@ Ellipse::Ellipse(const geo::Coordinate& center,
Ellipse::Ellipse(const Ellipse_CSPtr other, bool sameID) :
CADEntity(other, sameID),
geo::Ellipse(other->center(), other->majorP(), other->minorRadius(), other->startAngle(), other->endAngle()) {
geo::Ellipse(other->center(), other->majorP(), other->minorRadius(), other->startAngle(), other->endAngle(), other->isReversed()) {
}
@@ -25,6 +25,18 @@ namespace lc {
*/
class Ellipse : public std::enable_shared_from_this<Ellipse>, public CADEntity, public geo::Ellipse {
public:
/**
* @brief Create ellipse
* @param center
* @param majorP relative to center
* @param minorRadius
* @param startAngle
* @param endAngle
* @param reversed
* @param layer
* @param metaInfo
* @param block
*/
Ellipse(const geo::Coordinate &center,
const geo::Coordinate &majorP,
double minorRadius,
@@ -12,7 +12,7 @@ void LCVEllipse::draw(LcPainter& painter, const LcDrawOptions &options, const lc
if (_ellipse->minorRadius()) {
painter.ellipse(
_ellipse->center().x(), _ellipse->center().y(),
_ellipse->majorRadius(), _ellipse->minorRadius() ,
_ellipse->majorRadius(), _ellipse->minorRadius(),
_ellipse->startAngle(), _ellipse->endAngle(),
_ellipse->getAngle()
);
@@ -351,12 +351,17 @@ public:
}
void ellipse(double cx, double cy, double rx, double ry, double sa, double ea, double ra = 0) {
double cosrotangle = std::cos(ra);
double sinrotangle = std::sin(ra);
cairo_matrix_t transformmatrix;
cairo_matrix_init(&transformmatrix, rx * cosrotangle, rx * sinrotangle, ry * sinrotangle, -ry * cosrotangle, cx, -cy);
if(rx == 0) {
rx = 0.1;
}
if(ry == 0) {
ry = 0.1;
}
cairo_save(_cr);
cairo_transform(_cr, &transformmatrix);
cairo_translate(_cr, cx, - cy);
cairo_rotate(_cr, - ra);
cairo_scale(_cr, rx, ry);
cairo_arc(_cr, 0, 0, 1, sa, ea);
cairo_restore(_cr);
}

0 comments on commit da256b7

Please sign in to comment.