Permalink
Browse files

Add relative coordinate support

  • Loading branch information...
feragon committed Jun 8, 2016
1 parent f596a43 commit aa9fe42b3e50a7535cb1f1001bee69a7c2fbc77b
Showing with 28 additions and 1 deletion.
  1. +13 −1 lcUI/widgets/clicommand.cpp
  2. +1 −0 lcUI/widgets/clicommand.h
  3. +14 −0 lcUILua/ui/commandline.lua
@@ -65,6 +65,7 @@ void CliCommand::onReturnPressed() {
enterCommand(text);
}
_historyIndex = -1;
ui->command->clear();
}
@@ -92,6 +93,12 @@ void CliCommand::enterCommand(QString command) {
void CliCommand::enterCoordinate(QString coordinate) {
lc::geo::Coordinate point;
QStringList numbers;
bool isRelative = false;
if(coordinate.indexOf("@") != -1) {
isRelative = true;
coordinate.remove("@");
}
if(coordinate.indexOf(";") != -1) {
numbers = coordinate.split(";");
@@ -111,7 +118,12 @@ void CliCommand::enterCoordinate(QString coordinate) {
auto message = QString("Coordinate: x=%1; y=%2; z=%3").arg(point.x()).arg(point.y()).arg(point.z());
write(message);
emit coordinateEntered(point);
if(isRelative) {
emit relativeCoordinateEntered(point);
}
else {
emit coordinateEntered(point);
}
}
void CliCommand::enterNumber(double number) {
@@ -35,6 +35,7 @@ class CliCommand : public QDockWidget {
signals:
void commandEntered(QString command);
void coordinateEntered(lc::geo::Coordinate coordinate);
void relativeCoordinateEntered(lc::geo::Coordinate coordinate);
void numberEntered(double number);
private:
View
@@ -1,4 +1,5 @@
local commands = {}
local lastPoint = Coordinate(0,0)
function message(message)
cliCommand:write(tostring(message))
@@ -20,17 +21,30 @@ 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
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)
add_command("LINE", create_line)
event.register("point", setLastPoint)
end

0 comments on commit aa9fe42

Please sign in to comment.