Permalink
Browse files

Add circle creation

  • Loading branch information...
feragon committed Jun 16, 2016
1 parent b2dc671 commit d4340c9c4ed723eb621569c3fc348d9b42e8ab39
View
@@ -0,0 +1,68 @@
<?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="circle.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>
<circle
cy="36.124447"
cx="36.12439"
id="circle6020"
style="opacity:1;fill:none;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.25777793;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:3.99626684;stroke-opacity:1"
r="25.964447" />
</svg>
View
@@ -2,5 +2,6 @@
<qresource prefix="/icons">
<file alias="linesfree.png">icons/linesfree.png</file>
<file alias="linesnormal.png">icons/linesnormal.png</file>
<file alias="circle.svg">icons/circle.svg</file>
</qresource>
</RCC>
@@ -0,0 +1,87 @@
CircleOperations = {}
CircleOperations.__index = CircleOperations
setmetatable(CircleOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function CircleOperations:_init(id)
Operations._init(self, id)
self.center = nil
self.circle = nil
self.circle_id = ID():id()
event.register('point', self)
message("Click on center")
end
function CircleOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point") then
self:newPoint(...)
elseif(eventName == "mouseMove") then
self:createTempCircle(...)
elseif(eventName == "number") then
self:createCircle(...)
end
end
function CircleOperations:newPoint(point)
if(self.center == nil) then
self.center = point
self.circle = self:getCircle(point, 0)
active_widget():tempEntities():addEntity(self.circle)
event.register('mouseMove', self)
event.register('number', self)
message("Click on second point or enter the radius")
else
self:createCircle(point)
end
end
function CircleOperations:getCircle(center, radius)
if(type(radius) == "userdata") then
radius = center:distanceTo(radius)
end
local d = active_widget():document()
local layer = d:layerByName("0")
local c = Circle(center, radius, layer)
c:setId(self.circle_id)
return c
end
function CircleOperations:createTempCircle(point)
active_widget():tempEntities():removeEntity(self.circle)
self.circle = self:getCircle(self.center, point)
active_widget():tempEntities():addEntity(self.circle)
end
function CircleOperations:createCircle(point)
active_widget():tempEntities():removeEntity(self.circle)
local b = Builder(active_widget():document())
local c = self:getCircle(self.center, point)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
end
@@ -47,6 +47,7 @@ function LineOperations:newPoint(point)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
else
self.lastPoint = point
@@ -1,5 +1,6 @@
require 'actions.event'
require 'actions.lineoperations'
require 'actions.circleoperations'
Operations = {}
Operations.__index = Operations
@@ -45,6 +45,7 @@ function add_commandline()
luaInterface:luaConnect(cliCommand, "numberEntered(double)", number)
add_command("LINE", create_line)
add_command("CIRCLE", create_circle)
event.register("point", setLastPoint)
end
@@ -40,6 +40,7 @@ local function create_menu()
local menuBar = mainWindow:menuBar()
local drawMenu = menuBar:addMenuStr(qt.QString("Draw"))
local lineAction = drawMenu:addActionStr(qt.QString("Line"))
local circleAction = drawMenu:addActionStr(qt.QString("Circle"))
local luaMenu = menuBar:addMenuStr(qt.QString("Lua"))
local luaScriptAction = luaMenu:addActionStr(qt.QString("Run script"))
@@ -50,6 +51,7 @@ local function create_menu()
luaInterface:luaConnect(mainWindow:findChild("actionRedo"), "triggered(bool)", redo)
luaInterface:luaConnect(lineAction, "triggered(bool)", create_line)
luaInterface:luaConnect(circleAction, "triggered(bool)", create_circle)
luaInterface:luaConnect(luaScriptAction, "triggered(bool)", open_lua_script)
end
@@ -1,3 +1,7 @@
function create_line()
op[active_widget().id] = LineOperations(active_widget().id)
end
function create_circle()
op[active_widget().id] = CircleOperations(active_widget().id)
end
View
@@ -1,20 +1,31 @@
local iconSize = qt.QSize(24, 24)
local function create_button(name, icon)
local button = qt.QPushButton(qt.QString(name))
button:setFlat(true)
if(icon ~= nil) then
button:setIcon(qt.QIcon(qt.QString(icon)))
button:setIconSize(iconSize)
end
return button
end
function add_toolbar()
toolbar = lc.Toolbar(mainWindow)
mainWindow:addDockWidget(4, toolbar)
local quickAccess = lc.ToolbarTab()
local testGroup = quickAccess:addGroup("Creation")
local lineButton = qt.QPushButton(qt.QString(""))
lineButton:setFlat(true)
lineButton:setIcon(qt.QIcon(qt.QString(":/icons/linesnormal.png")))
lineButton:setIconSize(iconSize)
quickAccess:addButton(testGroup, lineButton,0,0,1,1)
local creationGroup = quickAccess:addGroup("Creation")
local lineButton = create_button("", ":/icons/linesnormal.png")
quickAccess:addButton(creationGroup, lineButton, 0, 0, 1, 1)
luaInterface:luaConnect(lineButton, "pressed()", create_line)
local circleButton = create_button("", ":/icons/circle.svg")
quickAccess:addButton(creationGroup, circleButton, 1, 0, 1, 1)
luaInterface:luaConnect(circleButton, "pressed()", create_circle)
toolbar:addTab("Quick Access", quickAccess)
end
@@ -115,6 +115,7 @@ void lua_openlckernel(lua_State* L) {
.addFunction("y", &geo::Coordinate::y)
.addFunction("z", &geo::Coordinate::z)
.addFunction("angleTo", &geo::Coordinate::angleTo)
.addFunction("distanceTo", &geo::Coordinate::distanceTo)
.addFunction("add", [](const geo::Coordinate* c1, const geo::Coordinate c2) {
return *c1 + c2;

0 comments on commit d4340c9

Please sign in to comment.