Permalink
Browse files

Create fixed size lines

  • Loading branch information...
feragon committed Jun 16, 2016
1 parent d37ef6d commit b2dc671aeaf7829828fa26b1115a9d354c696b4a
Showing with 21 additions and 2 deletions.
  1. +13 −2 lcUILua/actions/lineoperations.lua
  2. +8 −0 lcadluascript/cad/lualibrecadbridge.cpp
@@ -15,6 +15,7 @@ function LineOperations:_init(id)
self.lastPoint = nil
self.lastLine = nil
self.length = nil
self.line_id = ID():id()
event.register('point', self)
@@ -31,6 +32,8 @@ function LineOperations:onEvent(eventName, ...)
self:newPoint(...)
elseif(eventName == "mouseMove") then
self:createTempLine(...)
elseif(eventName == "number") then
self.length = ...
end
end
@@ -52,7 +55,8 @@ function LineOperations:newPoint(point)
active_widget():tempEntities():addEntity(self.lastLine)
event.register('mouseMove', self)
message("Click on second point")
event.register('number', self)
message("Click on second point or enter line length")
end
end
@@ -66,7 +70,14 @@ end
function LineOperations:createLine(p1, p2)
local d = active_widget():document()
local layer = d:layerByName("0")
local l = Line(Coord(p1:x(), p1:y()), Coord(p2:x(), p2:y()), layer);
local l
if(self.length == nil) then
l = Line(p1, p2, layer)
else
local angle = p1:angleTo(p2)
local relativeCoordinate = Coordinate._fromAngle(angle):mulDouble(self.length)
l = Line(p1, p1:add(relativeCoordinate), layer)
end
l:setId(self.line_id)
return l
@@ -107,9 +107,14 @@ void lua_openlckernel(lua_State* L) {
_opt<double> x,
_opt<double> y,
_opt<double> z))
.addStaticFunction("_fromAngle", [](const double angle) {
return geo::Coordinate(angle);
})
.addFunction("x", &geo::Coordinate::x)
.addFunction("y", &geo::Coordinate::y)
.addFunction("z", &geo::Coordinate::z)
.addFunction("angleTo", &geo::Coordinate::angleTo)
.addFunction("add", [](const geo::Coordinate* c1, const geo::Coordinate c2) {
return *c1 + c2;
@@ -119,6 +124,9 @@ void lua_openlckernel(lua_State* L) {
return *c1 - c2;
})
.addFunction("mulDouble", [](const geo::Coordinate* c1, const double s) {
return *c1 * s;
})
.endClass()
.beginClass<geo::Vector>("Vector")
.addConstructor(LUA_SP(std::shared_ptr<const geo::Vector>), LUA_ARGS(

0 comments on commit b2dc671

Please sign in to comment.