I'm currently working on rendering unit tests.
I didn't found a framework dedicated to this, so I'll be using GDK-Pixbuf and do a pixel-by-pixel comparison with a tolerance for color
Documentation
I have written some documentation on the basics of Lua scripting in the LibreCAD wiki.
Now I'm going to work on the rendering unit tests
Plugins update
I finished converting all the old plugins to new format.
Now they are all using blocks, but only rectangle is defining his own custom entity
Custom entity load
Currently the custom entities are loaded like blocks, all the Lua functions are not recreated.
I'm currently solving this by adding a manager in lcluascript, it will contain all the Insert which are custom entities.
All the plugins have to declare themselves, they will be warned by the manager and they recreate the CustomEntity and remove the Insert
libdxfrw work
I worked today on libdxfrw, it was missing the save of the group code 102, and the load code was not working.
I also fixed the libdxfrw interface in LibreCAD. Now the custom entity storage is properly saved and loaded
Lua drag points
- I fixed the operations (move,...), they were called from Insert and not keeping the Lua functions.
- I created the functions to manage the drag points. Here is the updated Lua code
lines = {}
function snapPoints(a, b, c, d)
local points = {}
table.insert(points, EntityCoordinate(Coordinate(0, 0, 0), 0))
table.insert(points, EntityCoordinate(Coordinate(100, 0, 0), 1))
table.insert(points, EntityCoordinate(Coordinate(100, 10, 0), 2))
table.insert(points, EntityCoordinate(Coordinate(0, 10, 0), 3))
return points
end
function nearestPointOnPath(coord)
local point
local distance
for i, line in pairs(lines) do
local tmp = line:nearestPointOnPath(coord)
local tmpDistance = coord:distanceTo(tmp)
if(point == nil or tmpDistance < distance) then
point = tmp
distance = tmpDistance
end
end
return point
end
function dragPoints()
local points = {}
points[0] = Coordinate(0, 0, 0)
points[1] = Coordinate(100, 0, 0)
points[2] = Coordinate(100, 10, 0)
points[3] = Coordinate(0, 10, 0)
return points
end
function newDragPoints(dragPoints)
for k, v in pairs(dragPoints) do
print(k .. " -> " .. v:x() .. ";" .. v:y())
end
--Here it should return the same CustomEntity, only the Lines are modified
end
b = Builder(document, "Add Rectangle")
ce = CustomEntityStorage("LC Plugin", "Rectangle", Coordinate(0, 0, 0))
b:append(AddBlock(document, ce))
eb = EntityBuilder(document)
b:append(eb)
lb = LineBuilder()
lb:setLayer(document:layerByName("0"))
lb:setBlock(ce)
lb:setStart(Coordinate(0, 0, 0))
lb:setEnd(Coordinate(100, 0, 0))
lines[1] = lb:build()
eb:appendEntity(lines[1])
lb:setStart(Coordinate(100, 10, 0))
lines[2] = lb:build()
eb:appendEntity(lines[2])
lb:setEnd(Coordinate(0, 10, 0))
lines[3] = lb:build()
eb:appendEntity(lines[3])
lb:setStart(Coordinate(0, 0, 0))
lines[4] = lb:build()
eb:appendEntity(lines[4])
b:execute()
ceb = CustomEntityBuilder()
ceb:setLayer(document:layerByName("0"))
ceb:setCoordinate(Coordinate(0, 0, 0))
ceb:setDocument(document)
ceb:setDisplayBlock(ce)
ceb:setSnapFunction(snapPoints)
ceb:setNearestPointFunction(nearestPointOnPath)
ceb:setDragPointsFunction(dragPoints)
ceb:setNewDragPointsFunction(newDragPoints)
eb = EntityBuilder(document)
eb:appendEntity(ceb:build())
eb:execute()
Lua snap points interaction
Today I worked on implementation of snapPoints and nearestPointOnPath function
Here is the working Lua code
lines = {}
function snapPoints(a, b, c, d)
local points = {}
table.insert(points, EntityCoordinate(Coordinate(0, 0, 0), 0))
table.insert(points, EntityCoordinate(Coordinate(100, 0, 0), 1))
table.insert(points, EntityCoordinate(Coordinate(100, 10, 0), 2))
table.insert(points, EntityCoordinate(Coordinate(0, 10, 0), 3))
return points
end
function nearestPointOnPath(coord)
local point
local distance
for i, line in pairs(lines) do
local tmp = line:nearestPointOnPath(coord)
local tmpDistance = coord:distanceTo(tmp)
if(point == nil or tmpDistance < distance) then
point = tmp
distance = tmpDistance
end
end
return point
end
b = Builder(document, "Add Rectangle")
ce = CustomEntityStorage("LC Plugin", "Rectangle", Coordinate(0, 0, 0))
b:append(AddBlock(document, ce))
eb = EntityBuilder(document)
b:append(eb)
lb = LineBuilder()
lb:setLayer(document:layerByName("0"))
lb:setBlock(ce)
lb:setStart(Coordinate(0, 0, 0))
lb:setEnd(Coordinate(100, 0, 0))
lines[1] = lb:build()
eb:appendEntity(lines[1])
lb:setStart(Coordinate(100, 10, 0))
lines[2] = lb:build()
eb:appendEntity(lines[2])
lb:setEnd(Coordinate(0, 10, 0))
lines[3] = lb:build()
eb:appendEntity(lines[3])
lb:setStart(Coordinate(0, 0, 0))
lines[4] = lb:build()
eb:appendEntity(lines[4])
b:execute()
ceb = CustomEntityBuilder()
ceb:setLayer(document:layerByName("0"))
ceb:setCoordinate(Coordinate(0, 0, 0))
ceb:setDocument(document)
ceb:setDisplayBlock(ce)
ceb:setSnapFunction(snapPoints)
ceb:setNearestPointFunction(nearestPointOnPath)
eb = EntityBuilder(document)
eb:appendEntity(ceb:build())
eb:execute()
Update of all drawables
Today I finished updating all drawables so they are not child of their respective CADEntity anymore, but contains a pointer to it.
It was required as the CustomEntity class was a child of Insert, and LCVInsert was recreating an Insert, and the overridden methods were not used.
The problem with this change is a dependency of EntityContainer on lcviewernoqt, which will be fixed later.
Interaction with custom entities
Today I began working on Snapable property of the custom entities.
Now, I have a CustomEntity class which depends on LuaIntf (obviously in lcadluascript folder), but I'm thinking about creating the abstract class CustomEntity in the kernel. This would be useful if we need custom plugins with other source than Lua, and might be required with file load/save.
Document operations update
Today I worked on the document operations, the actual Builder was renamed to EntityBuilder
The Builder class is now a container for DocumentOperations, which add only one undo cycle for multiple DocumentOperations.
All the document operations are now undoables.
All the operations on EntityBuilder were removed (push, move, ...) and replaced by EntityBuilder::appendOperation(Base_CSPtr); this is more extensible
Unit tests for new Builder were added too.