Navigation Menu

Skip to content

Commit

Permalink
Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
feragon committed Jun 28, 2016
1 parent b87fb04 commit ab2e308
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 0 deletions.
92 changes: 92 additions & 0 deletions lcUI/ui/icons/move_copy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions lcUI/ui/resource.qrc
Expand Up @@ -17,5 +17,6 @@
<file alias="polylines.svg">icons/polylines.svg</file> <file alias="polylines.svg">icons/polylines.svg</file>
<file alias="modify.svg">icons/modify.svg</file> <file alias="modify.svg">icons/modify.svg</file>
<file alias="modifyrotate.png">icons/modifyrotate.png</file> <file alias="modifyrotate.png">icons/modifyrotate.png</file>
<file alias="move_copy.svg">icons/move_copy.svg</file>
</qresource> </qresource>
</RCC> </RCC>
105 changes: 105 additions & 0 deletions lcUILua/actions/copyoperation.lua
@@ -0,0 +1,105 @@
CopyOperation = {}
CopyOperation.__index = CopyOperation

setmetatable(CopyOperation, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})

function CopyOperation:_init(id)
Operations._init(self, id)

self.selection = active_widget():selection()

message(tostring(#self.selection) .. " items selected")

if(#self.selection > 0) then
self.origin = nil
self.destination = nil

self.tempEntities = {}

event.register('point', self)
event.register('mouseMove', self)

message("Give origin point")
else
self.finished = true
event.trigger('operationFinished')
end
end

function CopyOperation:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end

if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:tempCopy(...)
end
end

function CopyOperation:newData(point)
if(self.origin == nil) then
self.origin = Operations:getCoordinate(point)

message("Give destination point")
elseif(Operations:getCoordinate(point) ~= nil) then
self.destination = Operations:getCoordinate(point)

self:copy()
end
end

function CopyOperation:tempCopy(point)
if(self.origin ~= nil) then
for k, entity in pairs(self.tempEntities) do
active_widget():tempEntities():removeEntity(entity)
end
self.tempEntities = {}

local offset = point:sub(self.origin)

for k, entity in pairs(self.selection) do
local newEntity = entity:copy(offset)
active_widget():tempEntities():addEntity(newEntity)
table.insert(self.tempEntities, newEntity)
end
end
end

function CopyOperation:copy()
local offset = self.destination:sub(self.origin)
local b = Builder(active_widget():document())

for k, entity in pairs(self.selection) do
b:append(entity)
end

b:push()
b:copy(offset)
b:execute()

self:close()
end

function CopyOperation:close()
if(not self.finished) then
self.finished = true

for k, entity in pairs(self.tempEntities) do
active_widget():tempEntities():removeEntity(entity)
end

event.delete('mouseMove', self)
event.delete('point', self)

event.trigger('operationFinished')
end
end
1 change: 1 addition & 0 deletions lcUILua/actions/operations.lua
Expand Up @@ -13,6 +13,7 @@ require 'actions.lwpolylineoperations'


require 'actions.moveoperation' require 'actions.moveoperation'
require 'actions.rotateoperation' require 'actions.rotateoperation'
require 'actions.copyoperation'


Operations = {} Operations = {}
Operations.__index = Operations Operations.__index = Operations
Expand Down
1 change: 1 addition & 0 deletions lcUILua/ui/commandline.lua
Expand Up @@ -66,6 +66,7 @@ function add_commandline()


add_command("MOVE", move_selected_entities) add_command("MOVE", move_selected_entities)
add_command("ROTATE", rotate_selected_entities) add_command("ROTATE", rotate_selected_entities)
add_command("COPY", copy_selected_entities)


event.register("point", setLastPoint) event.register("point", setLastPoint)
end end
5 changes: 5 additions & 0 deletions lcUILua/ui/operations.lua
Expand Up @@ -118,4 +118,9 @@ end
function rotate_selected_entities() function rotate_selected_entities()
new_operation() new_operation()
op[active_widget().id] = RotateOperation(active_widget().id) op[active_widget().id] = RotateOperation(active_widget().id)
end

function copy_selected_entities()
new_operation()
op[active_widget().id] = CopyOperation(active_widget().id)
end end
4 changes: 4 additions & 0 deletions lcUILua/ui/toolbar.lua
Expand Up @@ -104,4 +104,8 @@ function add_toolbar()
local rotateButton = create_button("", ":/icons/modifyrotate.png") local rotateButton = create_button("", ":/icons/modifyrotate.png")
quickAccess:addButton(modifyGroup, rotateButton, 1, 0, 1, 1) quickAccess:addButton(modifyGroup, rotateButton, 1, 0, 1, 1)
luaInterface:luaConnect(rotateButton, "pressed()", rotate_selected_entities) luaInterface:luaConnect(rotateButton, "pressed()", rotate_selected_entities)

local copyButton = create_button("", ":/icons/move_copy.svg")
quickAccess:addButton(modifyGroup, copyButton, 0, 1, 1, 1)
luaInterface:luaConnect(copyButton, "pressed()", copy_selected_entities)
end end
1 change: 1 addition & 0 deletions lcadluascript/cad/lualibrecadbridge.cpp
Expand Up @@ -176,6 +176,7 @@ void lua_openlckernel(lua_State* L) {
.beginExtendClass<entity::CADEntity, ID>("CADEntity") .beginExtendClass<entity::CADEntity, ID>("CADEntity")
.addFunction("move", &entity::CADEntity::move) .addFunction("move", &entity::CADEntity::move)
.addFunction("rotate", &entity::CADEntity::rotate) .addFunction("rotate", &entity::CADEntity::rotate)
.addFunction("copy", &entity::CADEntity::copy)
.endClass() .endClass()
.beginExtendClass<entity::Line, entity::CADEntity>("Line") .beginExtendClass<entity::Line, entity::CADEntity>("Line")
.addConstructor(LUA_SP(entity::Line_SPtr), LUA_ARGS( .addConstructor(LUA_SP(entity::Line_SPtr), LUA_ARGS(
Expand Down

0 comments on commit ab2e308

Please sign in to comment.