Permalink
Browse files

Copy

  • Loading branch information...
feragon committed Jun 28, 2016
1 parent b87fb04 commit ab2e308fb982f2dec1c77eaaf9b34e8a670daa2a
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:ns="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="256"
viewBox="0 0 72.248892 72.248892"
id="svg4295"
version="1.1"
inkscape:version="0.45.1"
sodipodi:docname="move_copy.svg"
inkscape:export-filename="D:\LC_Recources\icons\redo24.png"
inkscape:export-xdpi="8.4375"
inkscape:export-ydpi="8.4375"
sodipodi:version="0.32"
sodipodi:docbase="/mnt/sdb1/icons"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<metadata
id="metadata4325">
<rdf:RDF>
<ns:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</ns:Work>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4323" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1024"
inkscape:window-height="768"
id="namedview4321"
showgrid="true"
units="px"
inkscape:snap-grids="true"
inkscape:zoom="2.1875"
inkscape:cx="128"
inkscape:cy="128"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg4295"
inkscape:object-nodes="true"
inkscape:snap-object-midpoints="false"
gridempspacing="8">
<inkscape:grid
type="xygrid"
id="grid4867" />
</sodipodi:namedview>
<g
id="g4127">
<path
sodipodi:nodetypes="cccc"
id="path2183"
d="M 10.165534,14.698478 C 10.165534,66.62737 10.16,62.088892 10.16,62.088892 L 37.253335,62.088892 L 10.165534,14.698478 z "
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 39.516648,10.182922 C 39.516648,62.111814 39.511114,57.573336 39.511114,57.573336 L 66.604449,57.573336 L 39.516648,10.182922 z "
id="path3156"
sodipodi:nodetypes="cccc" />
<path
sodipodi:nodetypes="cccccccc"
inkscape:connector-curvature="0"
id="path4194"
d="M 44.030074,40.640003 L 32.73778,33.898923 L 32.73778,37.253336 L 21.44889,37.253336 L 21.44889,44.02667 L 32.73778,44.02667 L 32.73778,47.381083 L 44.030074,40.640003 z "
style="fill:#00ff7f;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>
View
@@ -17,5 +17,6 @@
<file alias="polylines.svg">icons/polylines.svg</file>
<file alias="modify.svg">icons/modify.svg</file>
<file alias="modifyrotate.png">icons/modifyrotate.png</file>
<file alias="move_copy.svg">icons/move_copy.svg</file>
</qresource>
</RCC>
@@ -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
@@ -13,6 +13,7 @@ require 'actions.lwpolylineoperations'
require 'actions.moveoperation'
require 'actions.rotateoperation'
require 'actions.copyoperation'
Operations = {}
Operations.__index = Operations
@@ -66,6 +66,7 @@ function add_commandline()
add_command("MOVE", move_selected_entities)
add_command("ROTATE", rotate_selected_entities)
add_command("COPY", copy_selected_entities)
event.register("point", setLastPoint)
end
@@ -118,4 +118,9 @@ end
function rotate_selected_entities()
new_operation()
op[active_widget().id] = RotateOperation(active_widget().id)
end
function copy_selected_entities()
new_operation()
op[active_widget().id] = CopyOperation(active_widget().id)
end
View
@@ -104,4 +104,8 @@ function add_toolbar()
local rotateButton = create_button("", ":/icons/modifyrotate.png")
quickAccess:addButton(modifyGroup, rotateButton, 1, 0, 1, 1)
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
@@ -176,6 +176,7 @@ void lua_openlckernel(lua_State* L) {
.beginExtendClass<entity::CADEntity, ID>("CADEntity")
.addFunction("move", &entity::CADEntity::move)
.addFunction("rotate", &entity::CADEntity::rotate)
.addFunction("copy", &entity::CADEntity::copy)
.endClass()
.beginExtendClass<entity::Line, entity::CADEntity>("Line")
.addConstructor(LUA_SP(entity::Line_SPtr), LUA_ARGS(

0 comments on commit ab2e308

Please sign in to comment.