Skip to content

Commit

Permalink
Lua UI + creation unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
feragon committed Jul 5, 2016
1 parent 43dc089 commit 01d7996
Show file tree
Hide file tree
Showing 9 changed files with 839 additions and 48 deletions.
24 changes: 12 additions & 12 deletions lcUI/luainterface.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "luainterface.h"

LuaInterface::LuaInterface() {
_L = luaL_newstate();
_L = LuaIntf::LuaState::newState();

luaL_openlibs(_L);
luaOpenQtBridge(_L);
lua_openlckernel(_L);
Expand All @@ -12,21 +12,14 @@ LuaInterface::LuaInterface() {

LuaInterface::~LuaInterface() {
_luaQObjects.clear();
lua_close(_L);

_L.close();
}

void LuaInterface::initLua() {
std::string out;
QString luaFile = QCoreApplication::applicationDirPath() + "/path.lua";
int s = luaL_dofile(_L, luaFile.toStdString().c_str());

if (s != 0) {
out.append(lua_tostring(_L, -1));
lua_pop(_L, 1);
}

std::cout << out << std::endl;
_L.doFile(luaFile.toStdString().c_str());
}

bool LuaInterface::luaConnect(
Expand Down Expand Up @@ -88,3 +81,10 @@ bool LuaInterface::qtConnect(QObject *sender, std::string signalName, QObject *r
return QMetaObject::connect(sender, signalId, receiver, slotId);
}

void LuaInterface::hideUI(bool hidden) {
LuaIntf::Lua::setGlobal(_L, "hideUI", hidden);
}

LuaIntf::LuaState LuaInterface::luaState() {
return _L;
}
8 changes: 6 additions & 2 deletions lcUI/luainterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class LuaInterface {

static std::shared_ptr<QWidget> loadUiFile(const char* fileName);

private:
lua_State* _L;
void hideUI(bool hidden);

LuaIntf::LuaState luaState();

private:
LuaIntf::LuaState _L;
std::vector<LuaQObject_SPtr> _luaQObjects;
};
12 changes: 11 additions & 1 deletion lcUILua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ file(
"package.path = package.path .. ';${CMAKE_CURRENT_LIST_DIR}/?.lua' \n"
"ui_path='${PROJECT_SOURCE_DIR}/lcUI/ui' \n"
"require 'ui.init'"
)
)

if(WITH_UNITTESTS)
file(
WRITE
"${PROJECT_BINARY_DIR}/unittest/path.lua"
"package.path = package.path .. ';${CMAKE_CURRENT_LIST_DIR}/?.lua' \n"
"ui_path='${PROJECT_SOURCE_DIR}/lcUI/ui' \n"
"require 'ui.init'"
)
endif()
4 changes: 3 additions & 1 deletion lcUILua/actions/lwpolylineoperations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ end

function LWPolylineOperations:close()
if(not self.finished) then
active_widget():tempEntities():removeEntity(self.lwPolyline)
if(self.lwPolyline ~= nil) then
active_widget():tempEntities():removeEntity(self.lwPolyline)
end
self.finished = true

self:createLWPolyline()
Expand Down
10 changes: 5 additions & 5 deletions lcUILua/ui/commandline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ function cli_get_text(getText)
cliCommand:returnText(getText)
end

local function command(command)
function command(command)
commands[command:toStdString()]()
end

local function coordinate(coordinate)
function coordinate(coordinate)
event.trigger("point", coordinate)
end

local function relativeCoordinate(relative)
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)
function number(number)
event.trigger("number", number)
end

local function setLastPoint(point)
lastPoint = point
end

local function text(text)
function text(text)
event.trigger("text", text:toStdString())
end

Expand Down
6 changes: 4 additions & 2 deletions lcUILua/ui/mainwindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ function create_main_window()

add_commandline()

add_toolbar()
if(hideUI ~= true) then
add_toolbar()

mainWindow:showMaximized()
mainWindow:showMaximized()
end

new_file()
end
Expand Down
54 changes: 30 additions & 24 deletions lcUILua/ui/operations.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
local function remove_operation_group()
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
if(group ~= nil) then
tab:removeGroup(group)
if(hideUI ~= true) then
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
if(group ~= nil) then
tab:removeGroup(group)
end
end

active_widget():viewer():setOperationActive(false)
end

local function finish_operation()
function finish_operation()
if(op[active_widget().id] ~= nil) then
op[active_widget().id]:close()
end
end

local function create_cancel_button()
local tab = toolbar:tabByName("Quick Access")
local operationGroup = tab:addGroup("Current operation")
if(hideUI ~= true) then
local tab = toolbar:tabByName("Quick Access")
local operationGroup = tab:addGroup("Current operation")

local cancelButton = create_button("", ":/icons/quit.svg")
tab:addButton(operationGroup, cancelButton, 0, 0, 1, 1)
luaInterface:luaConnect(cancelButton, "pressed()", finish_operation)
local cancelButton = create_button("", ":/icons/quit.svg")
tab:addButton(operationGroup, cancelButton, 0, 0, 1, 1)
luaInterface:luaConnect(cancelButton, "pressed()", finish_operation)
end
end

local function new_operation()
Expand Down Expand Up @@ -92,20 +96,22 @@ function create_lw_polyline()
finish_operation()
create_cancel_button()

local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")

local lineButton = create_button("", ":/icons/linesnormal.png")
tab:addButton(group, lineButton, 0, 1, 1, 1)
luaInterface:luaConnect(lineButton, "pressed()", function()
op[active_widget().id]:createLine()
end)

local arcButton = create_button("", ":/icons/arc.svg")
tab:addButton(group, arcButton, 1, 1, 1, 1)
luaInterface:luaConnect(arcButton, "pressed()", function()
op[active_widget().id]:createArc()
end)
if(hideUI ~= true) then
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")

local lineButton = create_button("", ":/icons/linesnormal.png")
tab:addButton(group, lineButton, 0, 1, 1, 1)
luaInterface:luaConnect(lineButton, "pressed()", function()
op[active_widget().id]:createLine()
end)

local arcButton = create_button("", ":/icons/arc.svg")
tab:addButton(group, arcButton, 1, 1, 1, 1)
luaInterface:luaConnect(arcButton, "pressed()", function()
op[active_widget().id]:createArc()
end)
end

op[active_widget().id] = LWPolylineOperations(active_widget().id)
end
Expand Down
6 changes: 5 additions & 1 deletion unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ if(WITH_QTUI)

set(src
${src}
ui/testtoolbar.cpp)
ui/testtoolbar.cpp
ui/testluaui.cpp)
include_directories("${CMAKE_SOURCE_DIR}/lcUI")
include_directories("${CMAKE_SOURCE_DIR}/lcviewerqt")
endif(WITH_QTUI)

include_directories("${CMAKE_SOURCE_DIR}/lckernel")
include_directories("${CMAKE_SOURCE_DIR}/lcadluascript")
include_directories("${CMAKE_SOURCE_DIR}/lcviewernoqt")
include_directories("${CMAKE_SOURCE_DIR}/lcDXFDWG")
add_executable(lcunittest ${src} ${hdrs})
target_link_libraries(lcunittest lckernel lcviewernoqt gtest ${EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${LOG4CXX_LIBRARIES})
Loading

0 comments on commit 01d7996

Please sign in to comment.