Permalink
Browse files

Polyline creation

  • Loading branch information...
feragon committed Jun 24, 2016
1 parent 0e047ba commit a0b0e74616382993ff9d1c77641cb40189863ae4
Showing with 232 additions and 0 deletions.
  1. +83 −0 lcUI/ui/icons/polylines.svg
  2. +149 −0 lcUILua/actions/lwpolylineoperations.lua
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
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.91 r13725"
sodipodi:docname="polylines.svg"
inkscape:export-filename="E:\icons\measure.png"
inkscape:export-xdpi="8.4375"
inkscape:export-ydpi="8.4375">
<metadata
id="metadata4325">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</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="1920"
inkscape:window-height="1176"
id="namedview4321"
showgrid="true"
units="px"
inkscape:snap-grids="true"
inkscape:zoom="3.7226562"
inkscape:cx="128"
inkscape:cy="128"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:current-layer="svg4295"
inkscape:object-nodes="true"
inkscape:snap-object-midpoints="false">
<inkscape:grid
type="xygrid"
id="grid4867" />
</sodipodi:namedview>
<g
id="g4173">
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path4157"
d="m 22.577781,48.542226 40.640001,-10e-7"
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
sodipodi:open="true"
d="m 22.577776,48.542226 a 12.418459,12.417779 0 0 1 -10.754701,-6.20889 12.418459,12.417779 0 0 1 0,-12.417779 12.418459,12.417779 0 0 1 10.754701,-6.208889"
sodipodi:end="4.712389"
sodipodi:start="1.5707963"
sodipodi:ry="12.417779"
sodipodi:rx="12.418459"
sodipodi:cy="36.124447"
sodipodi:cx="22.577776"
sodipodi:type="arc"
id="path4159"
style="opacity:1;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
</g>
</svg>
@@ -0,0 +1,149 @@
LWPolylineOperations = {}
LWPolylineOperations.__index = LWPolylineOperations
setmetatable(LWPolylineOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function LWPolylineOperations:_init(id)
Operations._init(self, id)
self.currentVertex_Bulge = 1
self.currentVertex_StartWidth = 0
self.currentVertex_EndWidth = 0
self.lwVertexes = {}
self.lwPolyline_id = ID():id()
self.lwPolyline = nil
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
event.register('text', self)
message("Choose entity type")
end
function LWPolylineOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempLWPolyline(...)
end
end
function LWPolylineOperations:newData(data)
local point = Operations:getCoordinate(data)
if(point ~= nil) then
if(self.currentVertex == "line") then
table.insert(self.lwVertexes, LWVertex2D(data))
elseif(self.currentVertex == "arc") then
table.insert(self.lwVertexes, LWVertex2D(data, self.currentVertex_Bulge))
end
else
local vertex = self.lwVertexes[#self.lwVertexes]
self.currentVertex_Bulge = math.tan(data / 4)
self.lwVertexes[#self.lwVertexes] = LWVertex2D(vertex:location(), self.currentVertex_Bulge, vertex:startWidth(), vertex:endWidth())
end
end
function LWPolylineOperations:getLWPolyline(vertexes)
if(#vertexes > 1) then
local d = active_widget():document()
local layer = d:layerByName("0")
local lwp = LWPolyline(vertexes, 1, 1, 1, false, Coord(0,0), layer, MetaInfo())
lwp:setId(self.lwPolyline_id)
return lwp
else
return nil
end
end
function LWPolylineOperations:createTempVertex(point)
local location = self.currentVertex_Location
local bulge = self.currentVertex_Bulge
if(location == nil) then
location = Operations:getCoordinate(point)
elseif(bulge == nil) then
bulge = Operations:getDistance(location, point)
end
bulge = bulge or 1
return LWVertex2D(location, bulge)
end
function LWPolylineOperations:createTempLWPolyline(point)
if(self.lwPolyline ~= nil) then
active_widget():tempEntities():removeEntity(self.lwPolyline)
end
local vertexes = {}
for k, v in pairs(self.lwVertexes) do
vertexes[k] = v
end
table.insert(vertexes, self:createTempVertex(point))
self.lwPolyline = self:getLWPolyline(vertexes)
if(self.lwPolyline ~= nil) then
active_widget():tempEntities():addEntity(self.lwPolyline)
end
end
function LWPolylineOperations:createLWPolyline()
local b = Builder(active_widget():document())
local lwp = self:getLWPolyline(self.lwVertexes)
b:append(lwp)
b:execute()
end
function LWPolylineOperations:close()
if(not self.finished) then
active_widget():tempEntities():removeEntity(self.lwPolyline)
self.finished = true
self:createLWPolyline()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
event.trigger('operationFinished')
end
end
function LWPolylineOperations:createArc()
self.currentVertex = "arc"
if(#self.lwVertexes > 0) then
local vertex = self.lwVertexes[#self.lwVertexes]
self.lwVertexes[#self.lwVertexes] = LWVertex2D(vertex:location(), self.currentVertex_Bulge, vertex:startWidth(), vertex:endWidth())
end
message("Give arc angle and coordinates")
end
function LWPolylineOperations:createLine()
self.currentVertex = "line"
if(#self.lwVertexes > 0) then
local vertex = self.lwVertexes[#self.lwVertexes]
self.lwVertexes[#self.lwVertexes] = LWVertex2D(vertex:location(), 0, vertex:startWidth(), vertex:endWidth())
end
message("Give line coordinates")
end

0 comments on commit a0b0e74

Please sign in to comment.