Permalink
Browse files

Add arc creation

  • Loading branch information...
feragon committed Jun 16, 2016
1 parent d4340c9 commit 527e009a2bd52a7a6f80f0e9d74b332c936d1534
View
@@ -0,0 +1,93 @@
<?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="arc_center_point_angle.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="g4188">
<path
sodipodi:open="true"
d="m 14.67551,12.417797 a 45.15556,45.15556 0 0 1 45.155559,45.15556"
sodipodi:end="0"
sodipodi:start="4.712389"
sodipodi:ry="45.15556"
sodipodi:rx="45.15556"
sodipodi:cy="57.573357"
sodipodi:cx="14.675509"
sodipodi:type="arc"
id="path4158"
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:1.60000002;stroke-opacity:1" />
<circle
style="opacity:1;fill:#00ff7f;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:1.60000002;stroke-opacity:1"
id="circle4170"
cx="14.675532"
cy="57.573402"
r="5.6444449" />
<path
inkscape:connector-curvature="0"
id="path4184"
d="m 14.675554,20.320003 0,-15.8044472"
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 51.928856,57.5733 15.804441,0"
id="path4186"
inkscape:connector-curvature="0" />
</g>
</svg>
View
@@ -3,5 +3,6 @@
<file alias="linesfree.png">icons/linesfree.png</file>
<file alias="linesnormal.png">icons/linesnormal.png</file>
<file alias="circle.svg">icons/circle.svg</file>
<file alias="arc.svg">icons/arc.svg</file>
</qresource>
</RCC>
@@ -0,0 +1,109 @@
ArcOperations = {}
ArcOperations.__index = ArcOperations
setmetatable(ArcOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function ArcOperations:_init(id)
Operations._init(self, id)
self.center = nil
self.radius = nil
self.beginAngle = nil
self.endAngle = nil
self.arc = nil
self.arc_id = ID():id()
event.register('point', self)
message("Click on center")
end
function ArcOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempArc(...)
end
end
function ArcOperations:newData(point)
if(self.center == nil) then
self.center = point
self.arc = self:getArc(point, 0, 0, 0)
active_widget():tempEntities():addEntity(self.arc)
event.register('mouseMove', self)
event.register('number', self)
message("Click on second point or enter the radius")
elseif(self.radius == nil) then
self.radius = Operations:getDistance(self.center, point)
message("Click on start point or enter the start angle")
elseif(self.beginAngle == nil) then
self.beginAngle = Operations:getAngle(self.center, point)
message("Click on end point or enter the end angle")
else
self.endAngle = Operations:getAngle(self.center, point)
self:createArc()
end
end
function ArcOperations:getArc(center, radius, beginAngle, endAngle)
local d = active_widget():document()
local layer = d:layerByName("0")
local a = Arc(center, radius, beginAngle, endAngle, false, layer)
a:setId(self.arc_id)
return a
end
function ArcOperations:createTempArc(point)
local center = self.center
local radius = self.radius
local beginAngle = self.beginAngle
local endAngle = self.endAngle
if(center == nil) then
center = point
elseif(radius == nil) then
radius = Operations:getDistance(center, point)
elseif(beginAngle == nil) then
beginAngle = Operations:getAngle(center, point)
elseif(endAngle == nil) then
endAngle = Operations:getAngle(center, point)
end
radius = radius or 0
beginAngle = beginAngle or 0
endAngle = endAngle or 0.001
active_widget():tempEntities():removeEntity(self.arc)
self.arc = self:getArc(center, radius, beginAngle, endAngle)
active_widget():tempEntities():addEntity(self.arc)
end
function ArcOperations:createArc()
active_widget():tempEntities():removeEntity(self.arc)
local b = Builder(active_widget():document())
local a = self:getArc(self.center, self.radius, self.beginAngle, self.endAngle)
b:append(a)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
end
@@ -1,6 +1,7 @@
require 'actions.event'
require 'actions.lineoperations'
require 'actions.circleoperations'
require 'actions.arcoperations'
Operations = {}
Operations.__index = Operations
@@ -19,4 +20,20 @@ end
function Operations:forMe()
return active_widget().id == self.id
end
function Operations:getDistance(center, point)
if(type(point) == "userdata") then
return center:distanceTo(point)
else
return point
end
end
function Operations:getAngle(center, point)
if(type(point) == "userdata") then
return center:angleTo(point)
else
return point
end
end
@@ -46,6 +46,7 @@ function add_commandline()
add_command("LINE", create_line)
add_command("CIRCLE", create_circle)
add_command("ARC", create_arc)
event.register("point", setLastPoint)
end
@@ -41,6 +41,7 @@ local function create_menu()
local drawMenu = menuBar:addMenuStr(qt.QString("Draw"))
local lineAction = drawMenu:addActionStr(qt.QString("Line"))
local circleAction = drawMenu:addActionStr(qt.QString("Circle"))
local arcAction = drawMenu:addActionStr(qt.QString("Arc"))
local luaMenu = menuBar:addMenuStr(qt.QString("Lua"))
local luaScriptAction = luaMenu:addActionStr(qt.QString("Run script"))
@@ -52,6 +53,7 @@ local function create_menu()
luaInterface:luaConnect(lineAction, "triggered(bool)", create_line)
luaInterface:luaConnect(circleAction, "triggered(bool)", create_circle)
luaInterface:luaConnect(arcAction, "triggered(bool)", create_arc)
luaInterface:luaConnect(luaScriptAction, "triggered(bool)", open_lua_script)
end
@@ -4,4 +4,8 @@ end
function create_circle()
op[active_widget().id] = CircleOperations(active_widget().id)
end
function create_arc()
op[active_widget().id] = ArcOperations(active_widget().id)
end
View
@@ -27,5 +27,9 @@ function add_toolbar()
quickAccess:addButton(creationGroup, circleButton, 1, 0, 1, 1)
luaInterface:luaConnect(circleButton, "pressed()", create_circle)
local arcButton = create_button("", ":/icons/arc.svg")
quickAccess:addButton(creationGroup, arcButton, 0, 1, 1, 1)
luaInterface:luaConnect(arcButton, "pressed()", create_arc)
toolbar:addTab("Quick Access", quickAccess)
end

0 comments on commit 527e009

Please sign in to comment.