Skip to content

Commit

Permalink
Merge pull request #116 from feragon/ellipse_drawing
Browse files Browse the repository at this point in the history
Fix ellipse loading/rendering
  • Loading branch information
feragon committed Aug 4, 2017
2 parents 42476bc + da256b7 commit 6049e12
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 24 deletions.
6 changes: 4 additions & 2 deletions lcDXFDWG/libdxfrw/dxfimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion lcUILua/actions/ellipseoperations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions lckernel/cad/geometry/geoellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
14 changes: 11 additions & 3 deletions lckernel/cad/geometry/geoellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lckernel/cad/primitive/ellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
}


Expand Down
12 changes: 12 additions & 0 deletions lckernel/cad/primitive/ellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lcviewernoqt/drawitems/lcvellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
15 changes: 10 additions & 5 deletions lcviewernoqt/painters/lccairopainter.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 6049e12

Please sign in to comment.