/
commandline.lua
66 lines (53 loc) · 1.88 KB
/
commandline.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local commands = {}
local lastPoint = Coordinate(0,0)
function message(message)
cliCommand:write(tostring(message))
end
function add_command(name, callback)
if(cliCommand:addCommand(name)) then
commands[name] = callback
else
print("Command " .. name .. " is already defined")
end
end
function cli_get_text(getText)
cliCommand:returnText(getText)
end
local function command(command)
commands[command:toStdString()]()
end
local function coordinate(coordinate)
event.trigger("point", coordinate)
end
local function relativeCoordinate(relative)
local absolute = lastPoint:add(relative)
message("-> " .. "x=" .. absolute:x() .. " y=" .. absolute:y() .. " z=" .. absolute:z())
event.trigger("point", absolute)
end
local function number(number)
event.trigger("number", number)
end
local function setLastPoint(point)
lastPoint = point
end
local function text(text)
event.trigger("text", text:toStdString())
end
function add_commandline()
cliCommand = lc.CliCommand(mainWindow)
mainWindow:addDockWidget(8, cliCommand)
luaInterface:luaConnect(cliCommand, "commandEntered(QString)", command)
luaInterface:luaConnect(cliCommand, "coordinateEntered(lc::geo::Coordinate)", coordinate)
luaInterface:luaConnect(cliCommand, "relativeCoordinateEntered(lc::geo::Coordinate)", relativeCoordinate)
luaInterface:luaConnect(cliCommand, "numberEntered(double)", number)
luaInterface:luaConnect(cliCommand, "textEntered(QString)", text)
add_command("LINE", create_line)
add_command("CIRCLE", create_circle)
add_command("ARC", create_arc)
add_command("ELLIPSE", create_ellipse)
add_command("ARCELLIPSE", create_arc_ellipse)
add_command("DIMALIGNED", create_dim_aligned)
add_command("DIMDIAMETRIC", create_dim_diametric)
add_command("DIMLINEAR", create_dim_linear)
event.register("point", setLastPoint)
end